Skip to content

Commit b1e8b76

Browse files
authored
feat: add backup-cli service based on RPCs (#4025)
1 parent d65cfa0 commit b1e8b76

21 files changed

Lines changed: 1974 additions & 130 deletions

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/backup-cli/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@ clap = { workspace = true }
1010
ed25519-dalek = { workspace = true }
1111
mpc-node = { workspace = true }
1212
near-account-id = { workspace = true }
13+
near-kit = { workspace = true }
1314
near-mpc-contract-interface = { workspace = true }
1415
rand = { workspace = true }
1516
rand_core = { workspace = true }
1617
serde = { workspace = true }
1718
serde_json = { workspace = true }
1819
thiserror = { workspace = true }
1920
tokio = { workspace = true }
21+
tokio-util = { workspace = true }
22+
tracing = { workspace = true }
23+
tracing-subscriber = { workspace = true }
2024

2125
[dev-dependencies]
26+
assert_matches = { workspace = true }
2227
mpc-node = { workspace = true, features = ["test-utils"] }
2328
rstest = { workspace = true }
2429
tempfile = { workspace = true }

crates/backup-cli/src/adapters.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
pub mod contract_state_fixture;
2+
pub mod contract_state_polling;
3+
pub mod contract_state_rpc;
24
pub mod keyshare_storage;
35
pub mod p2p_client;
46
pub mod secrets_storage;

crates/backup-cli/src/adapters/contract_state_fixture.rs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::path::{Path, PathBuf};
22

3-
use near_mpc_contract_interface::types::{Keyset, ProtocolContractState};
3+
use near_mpc_contract_interface::types::ProtocolContractState;
44
use tokio::fs::File;
55
use tokio::io::AsyncReadExt;
66

7-
use crate::ports::ContractStateReader;
7+
use crate::ports::ReadContractState;
88

99
const CONTRACT_STATE_FILENAME: &str = "contract_state.json";
1010

@@ -18,9 +18,6 @@ pub enum Error {
1818

1919
#[error("failed to deserialize secrets")]
2020
JsonDeserialization(serde_json::Error),
21-
22-
#[error("incorrect contract state: {0}")]
23-
IncorrectContractState(String),
2421
}
2522

2623
pub struct ContractStateFixture {
@@ -36,7 +33,7 @@ impl ContractStateFixture {
3633
}
3734
}
3835

39-
impl ContractStateReader for ContractStateFixture {
36+
impl ReadContractState for ContractStateFixture {
4037
type Error = Error;
4138

4239
async fn get_contract_state(&self) -> Result<ProtocolContractState, Self::Error> {
@@ -53,33 +50,13 @@ impl ContractStateReader for ContractStateFixture {
5350
}
5451
}
5552

56-
pub fn get_keyset_from_contract_state(
57-
contract_state: &ProtocolContractState,
58-
) -> Result<Keyset, Error> {
59-
match contract_state {
60-
ProtocolContractState::NotInitialized => {
61-
Err(Error::IncorrectContractState("NotInitialized".to_string()))
62-
}
63-
ProtocolContractState::Resharing(_) => {
64-
Err(Error::IncorrectContractState("Resharing".to_string()))
65-
}
66-
ProtocolContractState::Initializing(state) => Ok(Keyset {
67-
epoch_id: state.epoch_id,
68-
domains: state.generated_keys.clone(),
69-
}),
70-
ProtocolContractState::Running(state) => Ok(state.keyset.clone()),
71-
}
72-
}
73-
7453
#[cfg(test)]
7554
mod tests {
7655
use std::path::PathBuf;
7756

7857
use near_mpc_contract_interface::types::{GovernanceThreshold, ProtocolContractState};
7958

80-
use crate::{
81-
adapters::contract_state_fixture::ContractStateFixture, ports::ContractStateReader,
82-
};
59+
use crate::{adapters::contract_state_fixture::ContractStateFixture, ports::ReadContractState};
8360

8461
pub const TEST_CONTRACT_STATE_PATH: &str = "assets/";
8562
#[tokio::test]

0 commit comments

Comments
 (0)