feat: general initial state

This commit is contained in:
Pravdyvy 2026-03-13 18:23:39 +02:00
parent 3464d15d89
commit 02953999aa
16 changed files with 473 additions and 678 deletions

3
Cargo.lock generated
View File

@ -3749,6 +3749,7 @@ dependencies = [
"common",
"futures",
"humantime-serde",
"key_protocol",
"log",
"logos-blockchain-core",
"nssa",
@ -7462,6 +7463,7 @@ dependencies = [
"futures",
"humantime-serde",
"jsonrpsee",
"key_protocol",
"log",
"logos-blockchain-core",
"logos-blockchain-key-management-system-service",
@ -7493,6 +7495,7 @@ dependencies = [
"futures",
"hex",
"itertools 0.14.0",
"key_protocol",
"log",
"mempool",
"nssa",

View File

@ -1,6 +1,4 @@
use borsh::{BorshDeserialize, BorshSerialize};
use nssa::AccountId;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256, digest::FixedOutput};
use crate::{HashType, transaction::NSSATransaction};
@ -109,20 +107,6 @@ impl From<Block> for HashableBlockData {
}
}
/// Helper struct for account (de-)serialization
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AccountInitialData {
pub account_id: AccountId,
pub balance: u128,
}
/// Helper struct to (de-)serialize initial commitments
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommitmentsInitialData {
pub npk: nssa_core::NullifierPublicKey,
pub account: nssa_core::account::Account,
}
#[cfg(test)]
mod tests {
use crate::{HashType, block::HashableBlockData, test_utils};

View File

@ -10,6 +10,7 @@ bedrock_client.workspace = true
nssa.workspace = true
nssa_core.workspace = true
storage.workspace = true
key_protocol.workspace = true
anyhow.workspace = true
log.workspace = true

View File

@ -7,10 +7,7 @@ use std::{
use anyhow::{Context as _, Result};
pub use bedrock_client::BackoffConfig;
use common::{
block::{AccountInitialData, CommitmentsInitialData},
config::BasicAuth,
};
use common::config::BasicAuth;
use humantime_serde;
pub use logos_blockchain_core::mantle::ops::channel::ChannelId;
use serde::{Deserialize, Serialize};
@ -29,10 +26,6 @@ pub struct ClientConfig {
pub struct IndexerConfig {
/// Home dir of sequencer storage
pub home: PathBuf,
/// List of initial accounts data
pub initial_accounts: Vec<AccountInitialData>,
/// List of initial commitments
pub initial_commitments: Vec<CommitmentsInitialData>,
/// Sequencers signing key
pub signing_key: [u8; 32],
#[serde(with = "humantime_serde")]

View File

@ -2,9 +2,11 @@ use std::collections::VecDeque;
use anyhow::Result;
use bedrock_client::{BedrockClient, HeaderId};
use common::block::{Block, HashableBlockData};
// ToDo: Remove after testnet
use common::{HashType, PINATA_BASE58};
use common::{
HashType,
block::{Block, HashableBlockData},
};
use key_protocol::initial_state::initial_state_testnet;
use log::{debug, error, info};
use logos_blockchain_core::mantle::{
Op, SignedMantleTx,
@ -54,36 +56,8 @@ impl IndexerCore {
let channel_genesis_msg_id = [0; 32];
let start_block = hashable_data.into_pending_block(&signing_key, channel_genesis_msg_id);
// This is a troubling moment, because changes in key protocol can
// affect this. And indexer can not reliably ask this data from sequencer
// because indexer must be independent from it.
// ToDo: move initial state generation into common and use the same method
// for indexer and sequencer. This way both services buit at same version
// could be in sync.
let initial_commitments: Vec<nssa_core::Commitment> = config
.initial_commitments
.iter()
.map(|init_comm_data| {
let npk = &init_comm_data.npk;
let mut acc = init_comm_data.account.clone();
acc.program_owner = nssa::program::Program::authenticated_transfer_program().id();
nssa_core::Commitment::new(npk, &acc)
})
.collect();
let init_accs: Vec<(nssa::AccountId, u128)> = config
.initial_accounts
.iter()
.map(|acc_data| (acc_data.account_id, acc_data.balance))
.collect();
let mut state = nssa::V02State::new_with_genesis_accounts(&init_accs, &initial_commitments);
// ToDo: Remove after testnet
state.add_pinata_program(PINATA_BASE58.parse().unwrap());
// ToDo: replace with `initial_state()` after testnet
let state = initial_state_testnet();
let home = config.home.join("rocksdb");

View File

@ -0,0 +1,363 @@
use common::PINATA_BASE58;
use nssa::{Account, AccountId, Data, PrivateKey, PublicKey, V02State};
use nssa_core::{NullifierPublicKey, encryption::shared_key_derivation::Secp256k1Point};
use serde::{Deserialize, Serialize};
use crate::key_management::{
KeyChain,
secret_holders::{PrivateKeyHolder, SecretSpendingKey},
};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct PublicAccountPublicInitialData {
pub account_id: AccountId,
pub balance: u128,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct PrivateAccountPublicInitialData {
pub npk: nssa_core::NullifierPublicKey,
pub account: nssa_core::account::Account,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct PublicAccountPrivateInitialData {
pub account_id: nssa::AccountId,
pub pub_sign_key: nssa::PrivateKey,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PrivateAccountPrivateInitialData {
pub account_id: nssa::AccountId,
pub account: nssa_core::account::Account,
pub key_chain: KeyChain,
}
pub fn initial_pub_accounts_private_keys() -> Vec<PublicAccountPrivateInitialData> {
let acc1_pub_sign_key = PrivateKey::try_new([
16, 162, 106, 154, 236, 125, 52, 184, 35, 100, 238, 174, 69, 197, 41, 77, 187, 10, 118, 75,
0, 11, 148, 238, 185, 181, 133, 17, 220, 72, 124, 77,
])
.unwrap();
let acc2_pub_sign_key = PrivateKey::try_new([
113, 121, 64, 177, 204, 85, 229, 214, 178, 6, 109, 191, 29, 154, 63, 38, 242, 18, 244, 219,
8, 208, 35, 136, 23, 127, 207, 237, 216, 169, 190, 27,
])
.unwrap();
vec![
PublicAccountPrivateInitialData {
account_id: AccountId::from(&PublicKey::new_from_private_key(&acc1_pub_sign_key)),
pub_sign_key: acc1_pub_sign_key,
},
PublicAccountPrivateInitialData {
account_id: AccountId::from(&PublicKey::new_from_private_key(&acc2_pub_sign_key)),
pub_sign_key: acc2_pub_sign_key,
},
]
}
pub fn initial_priv_accounts_private_keys() -> Vec<PrivateAccountPrivateInitialData> {
let key_chain_1 = KeyChain {
secret_spending_key: SecretSpendingKey([
93, 13, 190, 240, 250, 33, 108, 195, 176, 40, 144, 61, 4, 28, 58, 112, 53, 161, 42,
238, 155, 27, 23, 176, 208, 121, 15, 229, 165, 180, 99, 143,
]),
private_key_holder: PrivateKeyHolder {
nullifier_secret_key: [
25, 21, 186, 59, 180, 224, 101, 64, 163, 208, 228, 43, 13, 185, 100, 123, 156, 47,
80, 179, 72, 51, 115, 11, 180, 99, 21, 201, 48, 194, 118, 144,
],
viewing_secret_key: [
5, 85, 114, 119, 141, 187, 202, 170, 122, 253, 198, 81, 150, 8, 155, 21, 192, 65,
24, 124, 116, 98, 110, 106, 137, 90, 165, 239, 80, 13, 222, 30,
],
},
nullifer_public_key: NullifierPublicKey([
167, 108, 50, 153, 74, 47, 151, 188, 140, 79, 195, 31, 181, 9, 40, 167, 201, 32, 175,
129, 45, 245, 223, 193, 210, 170, 247, 128, 167, 140, 155, 129,
]),
viewing_public_key: Secp256k1Point(vec![
2, 210, 206, 38, 213, 4, 182, 198, 220, 47, 93, 148, 61, 84, 148, 250, 158, 45, 8, 81,
48, 80, 46, 230, 87, 210, 47, 204, 76, 58, 214, 167, 81,
]),
};
let key_chain_2 = KeyChain {
secret_spending_key: SecretSpendingKey([
48, 175, 124, 10, 230, 240, 166, 14, 249, 254, 157, 226, 208, 124, 122, 177, 203, 139,
192, 180, 43, 120, 55, 151, 50, 21, 113, 22, 254, 83, 148, 56,
]),
private_key_holder: PrivateKeyHolder {
nullifier_secret_key: [
99, 82, 190, 140, 234, 10, 61, 163, 15, 211, 179, 54, 70, 166, 87, 5, 182, 68, 117,
244, 217, 23, 99, 9, 4, 177, 230, 125, 109, 91, 160, 30,
],
viewing_secret_key: [
205, 32, 76, 251, 255, 236, 96, 119, 61, 111, 65, 100, 75, 218, 12, 22, 17, 170,
55, 226, 21, 154, 161, 34, 208, 74, 27, 1, 119, 13, 88, 128,
],
},
nullifer_public_key: NullifierPublicKey([
32, 67, 72, 164, 106, 53, 66, 239, 141, 15, 52, 230, 136, 177, 2, 236, 207, 243, 134,
135, 210, 143, 87, 232, 215, 128, 194, 120, 113, 224, 4, 165,
]),
viewing_public_key: Secp256k1Point(vec![
2, 79, 110, 46, 203, 29, 206, 205, 18, 86, 27, 189, 104, 103, 113, 181, 110, 53, 78,
172, 11, 171, 190, 18, 126, 214, 81, 77, 192, 154, 58, 195, 238,
]),
};
vec![
PrivateAccountPrivateInitialData {
account_id: AccountId::from(&key_chain_1.nullifer_public_key),
account: Account {
program_owner: [0, 0, 0, 0, 0, 0, 0, 0],
balance: 10000,
data: Data::default(),
nonce: 0,
},
key_chain: key_chain_1,
},
PrivateAccountPrivateInitialData {
account_id: AccountId::from(&key_chain_2.nullifer_public_key),
account: Account {
program_owner: [0, 0, 0, 0, 0, 0, 0, 0],
balance: 20000,
data: Data::default(),
nonce: 0,
},
key_chain: key_chain_2,
},
]
}
pub fn initial_commitments() -> Vec<PrivateAccountPublicInitialData> {
initial_priv_accounts_private_keys()
.into_iter()
.map(|data| PrivateAccountPublicInitialData {
npk: data.key_chain.nullifer_public_key.clone(),
account: data.account.clone(),
})
.collect()
}
pub fn initial_accounts() -> Vec<PublicAccountPublicInitialData> {
let initial_account_ids = initial_pub_accounts_private_keys()
.into_iter()
.map(|data| data.account_id)
.collect::<Vec<_>>();
vec![
PublicAccountPublicInitialData {
account_id: initial_account_ids[0],
balance: 10000,
},
PublicAccountPublicInitialData {
account_id: initial_account_ids[1],
balance: 20000,
},
]
}
pub fn initial_state() -> V02State {
let initial_commitments: Vec<nssa_core::Commitment> = initial_commitments()
.iter()
.map(|init_comm_data| {
let npk = &init_comm_data.npk;
let mut acc = init_comm_data.account.clone();
acc.program_owner = nssa::program::Program::authenticated_transfer_program().id();
nssa_core::Commitment::new(npk, &acc)
})
.collect();
let init_accs: Vec<(nssa::AccountId, u128)> = initial_accounts()
.iter()
.map(|acc_data| (acc_data.account_id, acc_data.balance))
.collect();
nssa::V02State::new_with_genesis_accounts(&init_accs, &initial_commitments)
}
pub fn initial_state_testnet() -> V02State {
let mut state = initial_state();
state.add_pinata_program(PINATA_BASE58.parse().unwrap());
state
}
#[cfg(test)]
mod tests {
use std::str::FromStr;
use super::*;
#[test]
fn test_pub_state_consistency() {
let init_accs_private_data = initial_pub_accounts_private_keys();
let init_accs_pub_data = initial_accounts();
assert_eq!(
init_accs_private_data[0].account_id,
init_accs_pub_data[0].account_id
);
assert_eq!(
init_accs_private_data[1].account_id,
init_accs_pub_data[1].account_id
);
assert_eq!(
init_accs_pub_data[0],
PublicAccountPublicInitialData {
account_id: AccountId::from_str("6iArKUXxhUJqS7kCaPNhwMWt3ro71PDyBj7jwAyE2VQV")
.unwrap(),
balance: 10000,
}
);
assert_eq!(
init_accs_pub_data[1],
PublicAccountPublicInitialData {
account_id: AccountId::from_str("7wHg9sbJwc6h3NP1S9bekfAzB8CHifEcxKswCKUt3YQo")
.unwrap(),
balance: 20000,
}
)
}
#[test]
fn test_private_state_consistency() {
let init_private_accs_keys = initial_priv_accounts_private_keys();
let init_comms = initial_commitments();
assert_eq!(
init_private_accs_keys[0]
.key_chain
.secret_spending_key
.produce_private_key_holder(None)
.nullifier_secret_key,
init_private_accs_keys[0]
.key_chain
.private_key_holder
.nullifier_secret_key
);
assert_eq!(
init_private_accs_keys[0]
.key_chain
.secret_spending_key
.produce_private_key_holder(None)
.viewing_secret_key,
init_private_accs_keys[0]
.key_chain
.private_key_holder
.viewing_secret_key
);
assert_eq!(
init_private_accs_keys[0]
.key_chain
.private_key_holder
.generate_nullifier_public_key(),
init_private_accs_keys[0].key_chain.nullifer_public_key
);
assert_eq!(
init_private_accs_keys[0]
.key_chain
.private_key_holder
.generate_viewing_public_key(),
init_private_accs_keys[0].key_chain.viewing_public_key
);
assert_eq!(
init_private_accs_keys[1]
.key_chain
.secret_spending_key
.produce_private_key_holder(None)
.nullifier_secret_key,
init_private_accs_keys[1]
.key_chain
.private_key_holder
.nullifier_secret_key
);
assert_eq!(
init_private_accs_keys[1]
.key_chain
.secret_spending_key
.produce_private_key_holder(None)
.viewing_secret_key,
init_private_accs_keys[1]
.key_chain
.private_key_holder
.viewing_secret_key
);
assert_eq!(
init_private_accs_keys[1]
.key_chain
.private_key_holder
.generate_nullifier_public_key(),
init_private_accs_keys[1].key_chain.nullifer_public_key
);
assert_eq!(
init_private_accs_keys[1]
.key_chain
.private_key_holder
.generate_viewing_public_key(),
init_private_accs_keys[1].key_chain.viewing_public_key
);
assert_eq!(
init_private_accs_keys[0].account_id.to_string(),
"5ya25h4Xc9GAmrGB2WrTEnEWtQKJwRwQx3Xfo2tucNcE"
);
assert_eq!(
init_private_accs_keys[1].account_id.to_string(),
"E8HwiTyQe4H9HK7icTvn95HQMnzx49mP9A2ddtMLpNaN"
);
assert_eq!(
init_private_accs_keys[0].key_chain.nullifer_public_key,
init_comms[0].npk
);
assert_eq!(
init_private_accs_keys[1].key_chain.nullifer_public_key,
init_comms[1].npk
);
assert_eq!(
init_comms[0],
PrivateAccountPublicInitialData {
npk: NullifierPublicKey([
167, 108, 50, 153, 74, 47, 151, 188, 140, 79, 195, 31, 181, 9, 40, 167, 201,
32, 175, 129, 45, 245, 223, 193, 210, 170, 247, 128, 167, 140, 155, 129,
]),
account: Account {
program_owner: [0, 0, 0, 0, 0, 0, 0, 0],
balance: 10000,
data: Data::default(),
nonce: 0,
},
}
);
assert_eq!(
init_comms[1],
PrivateAccountPublicInitialData {
npk: NullifierPublicKey([
32, 67, 72, 164, 106, 53, 66, 239, 141, 15, 52, 230, 136, 177, 2, 236, 207,
243, 134, 135, 210, 143, 87, 232, 215, 128, 194, 120, 113, 224, 4, 165,
]),
account: Account {
program_owner: [0, 0, 0, 0, 0, 0, 0, 0],
balance: 20000,
data: Data::default(),
nonce: 0,
},
}
)
}
}

View File

@ -1,2 +1,3 @@
pub mod initial_state;
pub mod key_management;
pub mod key_protocol_core;

View File

@ -11,6 +11,7 @@ common.workspace = true
storage.workspace = true
mempool.workspace = true
bedrock_client.workspace = true
key_protocol.workspace = true
base58.workspace = true
anyhow.workspace = true

View File

@ -8,10 +8,7 @@ use std::{
use anyhow::Result;
use bedrock_client::BackoffConfig;
use bytesize::ByteSize;
use common::{
block::{AccountInitialData, CommitmentsInitialData},
config::BasicAuth,
};
use common::config::BasicAuth;
use humantime_serde;
use logos_blockchain_core::mantle::ops::channel::ChannelId;
use serde::{Deserialize, Serialize};
@ -43,10 +40,6 @@ pub struct SequencerConfig {
pub retry_pending_blocks_timeout: Duration,
/// Port to listen
pub port: u16,
/// List of initial accounts data
pub initial_accounts: Vec<AccountInitialData>,
/// List of initial commitments
pub initial_commitments: Vec<CommitmentsInitialData>,
/// Sequencer own signing key
pub signing_key: [u8; 32],
/// Bedrock configuration options

View File

@ -10,6 +10,7 @@ use common::{
transaction::NSSATransaction,
};
use config::SequencerConfig;
use key_protocol::initial_state::initial_state;
use log::{error, info, warn};
use logos_blockchain_key_management_system_service::keys::{ED25519_SECRET_KEY_SIZE, Ed25519Key};
use mempool::{MemPool, MemPoolHandle};
@ -98,30 +99,9 @@ impl<BC: BlockSettlementClientTrait, IC: IndexerClientTrait> SequencerCore<BC, I
}
None => {
info!(
"No database found when starting the sequencer. Creating a fresh new with the initial data in config"
"No database found when starting the sequencer. Creating a fresh new with the initial data"
);
let initial_commitments: Vec<nssa_core::Commitment> = config
.initial_commitments
.iter()
.map(|init_comm_data| {
let npk = &init_comm_data.npk;
let mut acc = init_comm_data.account.clone();
acc.program_owner =
nssa::program::Program::authenticated_transfer_program().id();
nssa_core::Commitment::new(npk, &acc)
})
.collect();
let init_accs: Vec<(nssa::AccountId, u128)> = config
.initial_accounts
.iter()
.map(|acc_data| (acc_data.account_id, acc_data.balance))
.collect();
nssa::V02State::new_with_genesis_accounts(&init_accs, &initial_commitments)
initial_state()
}
};
@ -360,26 +340,20 @@ fn load_or_create_signing_key(path: &Path) -> Result<Ed25519Key> {
#[cfg(all(test, feature = "mock"))]
mod tests {
use std::{pin::pin, str::FromStr as _, time::Duration};
use std::{pin::pin, time::Duration};
use base58::ToBase58;
use bedrock_client::BackoffConfig;
use common::{
block::AccountInitialData, test_utils::sequencer_sign_key_for_testing,
transaction::NSSATransaction,
};
use common::{test_utils::sequencer_sign_key_for_testing, transaction::NSSATransaction};
use key_protocol::initial_state::{initial_accounts, initial_pub_accounts_private_keys};
use logos_blockchain_core::mantle::ops::channel::ChannelId;
use mempool::MemPoolHandle;
use nssa::{AccountId, PrivateKey};
use crate::{
config::{BedrockConfig, SequencerConfig},
mock::SequencerCoreWithMockClients,
};
fn setup_sequencer_config_variable_initial_accounts(
initial_accounts: Vec<AccountInitialData>,
) -> SequencerConfig {
fn setup_sequencer_config() -> SequencerConfig {
let tempdir = tempfile::tempdir().unwrap();
let home = tempdir.path().to_path_buf();
@ -393,8 +367,6 @@ mod tests {
mempool_max_size: 10000,
block_create_timeout: Duration::from_secs(1),
port: 8080,
initial_accounts,
initial_commitments: vec![],
signing_key: *sequencer_sign_key_for_testing().value(),
bedrock_config: BedrockConfig {
backoff: BackoffConfig {
@ -410,38 +382,12 @@ mod tests {
}
}
fn setup_sequencer_config() -> SequencerConfig {
let acc1_account_id: Vec<u8> = vec![
148, 179, 206, 253, 199, 51, 82, 86, 232, 2, 152, 122, 80, 243, 54, 207, 237, 112, 83,
153, 44, 59, 204, 49, 128, 84, 160, 227, 216, 149, 97, 102,
];
let acc2_account_id: Vec<u8> = vec![
30, 145, 107, 3, 207, 73, 192, 230, 160, 63, 238, 207, 18, 69, 54, 216, 103, 244, 92,
94, 124, 248, 42, 16, 141, 19, 119, 18, 14, 226, 140, 204,
];
let initial_acc1 = AccountInitialData {
account_id: AccountId::from_str(&acc1_account_id.to_base58()).unwrap(),
balance: 10000,
};
let initial_acc2 = AccountInitialData {
account_id: AccountId::from_str(&acc2_account_id.to_base58()).unwrap(),
balance: 20000,
};
let initial_accounts = vec![initial_acc1, initial_acc2];
setup_sequencer_config_variable_initial_accounts(initial_accounts)
}
fn create_signing_key_for_account1() -> nssa::PrivateKey {
nssa::PrivateKey::try_new([1; 32]).unwrap()
initial_pub_accounts_private_keys()[0].pub_sign_key.clone()
}
fn create_signing_key_for_account2() -> nssa::PrivateKey {
nssa::PrivateKey::try_new([2; 32]).unwrap()
initial_pub_accounts_private_keys()[1].pub_sign_key.clone()
}
async fn common_setup() -> (SequencerCoreWithMockClients, MemPoolHandle<NSSATransaction>) {
@ -475,8 +421,8 @@ mod tests {
assert_eq!(sequencer.sequencer_config.max_num_tx_in_block, 10);
assert_eq!(sequencer.sequencer_config.port, 8080);
let acc1_account_id = config.initial_accounts[0].account_id;
let acc2_account_id = config.initial_accounts[1].account_id;
let acc1_account_id = initial_accounts()[0].account_id;
let acc2_account_id = initial_accounts()[1].account_id;
let balance_acc_1 = sequencer.state.get_account_by_id(acc1_account_id).balance;
let balance_acc_2 = sequencer.state.get_account_by_id(acc2_account_id).balance;
@ -485,47 +431,6 @@ mod tests {
assert_eq!(20000, balance_acc_2);
}
#[tokio::test]
async fn test_start_different_intial_accounts_balances() {
let acc1_account_id: Vec<u8> = vec![
27, 132, 197, 86, 123, 18, 100, 64, 153, 93, 62, 213, 170, 186, 5, 101, 215, 30, 24,
52, 96, 72, 25, 255, 156, 23, 245, 233, 213, 221, 7, 143,
];
let acc2_account_id: Vec<u8> = vec![
77, 75, 108, 209, 54, 16, 50, 202, 155, 210, 174, 185, 217, 0, 170, 77, 69, 217, 234,
216, 10, 201, 66, 51, 116, 196, 81, 167, 37, 77, 7, 102,
];
let initial_acc1 = AccountInitialData {
account_id: AccountId::from_str(&acc1_account_id.to_base58()).unwrap(),
balance: 10000,
};
let initial_acc2 = AccountInitialData {
account_id: AccountId::from_str(&acc2_account_id.to_base58()).unwrap(),
balance: 20000,
};
let initial_accounts = vec![initial_acc1, initial_acc2];
let config = setup_sequencer_config_variable_initial_accounts(initial_accounts);
let (sequencer, _mempool_handle) =
SequencerCoreWithMockClients::start_from_config(config.clone()).await;
let acc1_account_id = config.initial_accounts[0].account_id;
let acc2_account_id = config.initial_accounts[1].account_id;
assert_eq!(
10000,
sequencer.state.get_account_by_id(acc1_account_id).balance
);
assert_eq!(
20000,
sequencer.state.get_account_by_id(acc2_account_id).balance
);
}
#[test]
fn test_transaction_pre_check_pass() {
let tx = common::test_utils::produce_dummy_empty_transaction();
@ -536,10 +441,10 @@ mod tests {
#[tokio::test]
async fn test_transaction_pre_check_native_transfer_valid() {
let (sequencer, _mempool_handle) = common_setup().await;
let (_sequencer, _mempool_handle) = common_setup().await;
let acc1 = sequencer.sequencer_config.initial_accounts[0].account_id;
let acc2 = sequencer.sequencer_config.initial_accounts[1].account_id;
let acc1 = initial_accounts()[0].account_id;
let acc2 = initial_accounts()[1].account_id;
let sign_key1 = create_signing_key_for_account1();
@ -555,8 +460,8 @@ mod tests {
async fn test_transaction_pre_check_native_transfer_other_signature() {
let (mut sequencer, _mempool_handle) = common_setup().await;
let acc1 = sequencer.sequencer_config.initial_accounts[0].account_id;
let acc2 = sequencer.sequencer_config.initial_accounts[1].account_id;
let acc1 = initial_accounts()[0].account_id;
let acc2 = initial_accounts()[1].account_id;
let sign_key2 = create_signing_key_for_account2();
@ -580,8 +485,8 @@ mod tests {
async fn test_transaction_pre_check_native_transfer_sent_too_much() {
let (mut sequencer, _mempool_handle) = common_setup().await;
let acc1 = sequencer.sequencer_config.initial_accounts[0].account_id;
let acc2 = sequencer.sequencer_config.initial_accounts[1].account_id;
let acc1 = initial_accounts()[0].account_id;
let acc2 = initial_accounts()[1].account_id;
let sign_key1 = create_signing_key_for_account1();
@ -607,8 +512,8 @@ mod tests {
async fn test_transaction_execute_native_transfer() {
let (mut sequencer, _mempool_handle) = common_setup().await;
let acc1 = sequencer.sequencer_config.initial_accounts[0].account_id;
let acc2 = sequencer.sequencer_config.initial_accounts[1].account_id;
let acc1 = initial_accounts()[0].account_id;
let acc2 = initial_accounts()[1].account_id;
let sign_key1 = create_signing_key_for_account1();
@ -669,8 +574,8 @@ mod tests {
async fn test_replay_transactions_are_rejected_in_the_same_block() {
let (mut sequencer, mempool_handle) = common_setup().await;
let acc1 = sequencer.sequencer_config.initial_accounts[0].account_id;
let acc2 = sequencer.sequencer_config.initial_accounts[1].account_id;
let acc1 = initial_accounts()[0].account_id;
let acc2 = initial_accounts()[1].account_id;
let sign_key1 = create_signing_key_for_account1();
@ -701,8 +606,8 @@ mod tests {
async fn test_replay_transactions_are_rejected_in_different_blocks() {
let (mut sequencer, mempool_handle) = common_setup().await;
let acc1 = sequencer.sequencer_config.initial_accounts[0].account_id;
let acc2 = sequencer.sequencer_config.initial_accounts[1].account_id;
let acc1 = initial_accounts()[0].account_id;
let acc2 = initial_accounts()[1].account_id;
let sign_key1 = create_signing_key_for_account1();
@ -736,8 +641,8 @@ mod tests {
#[tokio::test]
async fn test_restart_from_storage() {
let config = setup_sequencer_config();
let acc1_account_id = config.initial_accounts[0].account_id;
let acc2_account_id = config.initial_accounts[1].account_id;
let acc1_account_id = initial_accounts()[0].account_id;
let acc2_account_id = initial_accounts()[1].account_id;
let balance_to_move = 13;
// In the following code block a transaction will be processed that moves `balance_to_move`
@ -746,7 +651,7 @@ mod tests {
{
let (mut sequencer, mempool_handle) =
SequencerCoreWithMockClients::start_from_config(config.clone()).await;
let signing_key = PrivateKey::try_new([1; 32]).unwrap();
let signing_key = create_signing_key_for_account1();
let tx = common::test_utils::create_transaction_native_token_transfer(
acc1_account_id,
@ -777,11 +682,11 @@ mod tests {
// Balances should be consistent with the stored block
assert_eq!(
balance_acc_1,
config.initial_accounts[0].balance - balance_to_move
initial_accounts()[0].balance - balance_to_move
);
assert_eq!(
balance_acc_2,
config.initial_accounts[1].balance + balance_to_move
initial_accounts()[1].balance + balance_to_move
);
}
@ -828,15 +733,15 @@ mod tests {
#[tokio::test]
async fn test_produce_block_with_correct_prev_meta_after_restart() {
let config = setup_sequencer_config();
let acc1_account_id = config.initial_accounts[0].account_id;
let acc2_account_id = config.initial_accounts[1].account_id;
let acc1_account_id = initial_accounts()[0].account_id;
let acc2_account_id = initial_accounts()[1].account_id;
// Step 1: Create initial database with some block metadata
let expected_prev_meta = {
let (mut sequencer, mempool_handle) =
SequencerCoreWithMockClients::start_from_config(config.clone()).await;
let signing_key = PrivateKey::try_new([1; 32]).unwrap();
let signing_key = create_signing_key_for_account1();
// Add a transaction and produce a block to set up block metadata
let tx = common::test_utils::create_transaction_native_token_transfer(
@ -861,7 +766,7 @@ mod tests {
SequencerCoreWithMockClients::start_from_config(config.clone()).await;
// Step 3: Submit a new transaction
let signing_key = PrivateKey::try_new([1; 32]).unwrap();
let signing_key = create_signing_key_for_account1();
let tx = common::test_utils::create_transaction_native_token_transfer(
acc1_account_id,
1, // Next nonce

View File

@ -10,6 +10,7 @@ common.workspace = true
mempool.workspace = true
sequencer_core = { workspace = true }
bedrock_client.workspace = true
key_protocol.workspace = true
anyhow.workspace = true
serde_json.workspace = true

View File

@ -3,7 +3,7 @@ use std::collections::HashMap;
use actix_web::Error as HttpError;
use base64::{Engine, engine::general_purpose};
use common::{
block::{AccountInitialData, HashableBlockData},
block::HashableBlockData,
rpc_primitives::{
errors::RpcError,
message::{Message, Request},
@ -23,6 +23,7 @@ use common::{
transaction::{NSSATransaction, TransactionMalformationError},
};
use itertools::Itertools as _;
use key_protocol::initial_state::initial_accounts;
use log::warn;
use nssa::{self, program::Program};
use sequencer_core::{
@ -201,13 +202,7 @@ impl<BC: BlockSettlementClientTrait, IC: IndexerClientTrait> JsonHandler<BC, IC>
let _get_initial_testnet_accounts_request =
GetInitialTestnetAccountsRequest::parse(Some(request.params))?;
let initial_accounts: Vec<AccountInitialData> = {
let state = self.sequencer_state.lock().await;
state.sequencer_config().initial_accounts.clone()
};
respond(initial_accounts)
respond(initial_accounts())
}
/// Returns the balance of the account at the given account_id.
@ -340,16 +335,14 @@ impl<BC: BlockSettlementClientTrait, IC: IndexerClientTrait> JsonHandler<BC, IC>
#[cfg(test)]
mod tests {
use std::{str::FromStr as _, sync::Arc, time::Duration};
use std::{sync::Arc, time::Duration};
use base58::ToBase58;
use base64::{Engine, engine::general_purpose};
use bedrock_client::BackoffConfig;
use common::{
block::AccountInitialData, config::BasicAuth, test_utils::sequencer_sign_key_for_testing,
transaction::NSSATransaction,
config::BasicAuth, test_utils::sequencer_sign_key_for_testing, transaction::NSSATransaction,
};
use nssa::AccountId;
use key_protocol::initial_state::{initial_accounts, initial_pub_accounts_private_keys};
use sequencer_core::{
config::{BedrockConfig, SequencerConfig},
mock::{MockBlockSettlementClient, MockIndexerClient, SequencerCoreWithMockClients},
@ -366,27 +359,6 @@ mod tests {
fn sequencer_config_for_tests() -> SequencerConfig {
let tempdir = tempdir().unwrap();
let home = tempdir.path().to_path_buf();
let acc1_id: Vec<u8> = vec![
148, 179, 206, 253, 199, 51, 82, 86, 232, 2, 152, 122, 80, 243, 54, 207, 237, 112, 83,
153, 44, 59, 204, 49, 128, 84, 160, 227, 216, 149, 97, 102,
];
let acc2_id: Vec<u8> = vec![
30, 145, 107, 3, 207, 73, 192, 230, 160, 63, 238, 207, 18, 69, 54, 216, 103, 244, 92,
94, 124, 248, 42, 16, 141, 19, 119, 18, 14, 226, 140, 204,
];
let initial_acc1 = AccountInitialData {
account_id: AccountId::from_str(&acc1_id.to_base58()).unwrap(),
balance: 10000,
};
let initial_acc2 = AccountInitialData {
account_id: AccountId::from_str(&acc2_id.to_base58()).unwrap(),
balance: 20000,
};
let initial_accounts = vec![initial_acc1, initial_acc2];
SequencerConfig {
home,
@ -398,8 +370,6 @@ mod tests {
mempool_max_size: 1000,
block_create_timeout: Duration::from_secs(1),
port: 8080,
initial_accounts,
initial_commitments: vec![],
signing_key: *sequencer_sign_key_for_testing().value(),
retry_pending_blocks_timeout: Duration::from_secs(60 * 4),
bedrock_config: BedrockConfig {
@ -418,30 +388,18 @@ mod tests {
}
}
async fn components_for_tests() -> (
JsonHandlerWithMockClients,
Vec<AccountInitialData>,
NSSATransaction,
) {
async fn components_for_tests() -> (JsonHandlerWithMockClients, NSSATransaction) {
let config = sequencer_config_for_tests();
let (mut sequencer_core, mempool_handle) =
SequencerCoreWithMockClients::start_from_config(config).await;
let initial_accounts = sequencer_core.sequencer_config().initial_accounts.clone();
let signing_key = nssa::PrivateKey::try_new([1; 32]).unwrap();
let signing_key = initial_pub_accounts_private_keys()[0].pub_sign_key.clone();
let balance_to_move = 10;
let tx = common::test_utils::create_transaction_native_token_transfer(
AccountId::from_str(
&[
148, 179, 206, 253, 199, 51, 82, 86, 232, 2, 152, 122, 80, 243, 54, 207, 237,
112, 83, 153, 44, 59, 204, 49, 128, 84, 160, 227, 216, 149, 97, 102,
]
.to_base58(),
)
.unwrap(),
initial_accounts()[0].account_id,
0,
AccountId::from_str(&[2; 32].to_base58()).unwrap(),
initial_accounts()[1].account_id,
balance_to_move,
signing_key,
);
@ -464,7 +422,6 @@ mod tests {
mempool_handle,
max_block_size,
},
initial_accounts,
tx,
)
}
@ -494,7 +451,7 @@ mod tests {
#[actix_web::test]
async fn test_get_account_balance_for_non_existent_account() {
let (json_handler, _, _) = components_for_tests().await;
let (json_handler, _) = components_for_tests().await;
let request = serde_json::json!({
"jsonrpc": "2.0",
"method": "get_account_balance",
@ -516,7 +473,7 @@ mod tests {
#[actix_web::test]
async fn test_get_account_balance_for_invalid_base58() {
let (json_handler, _, _) = components_for_tests().await;
let (json_handler, _) = components_for_tests().await;
let request = serde_json::json!({
"jsonrpc": "2.0",
"method": "get_account_balance",
@ -546,7 +503,7 @@ mod tests {
#[actix_web::test]
async fn test_get_account_balance_for_invalid_length() {
let (json_handler, _, _) = components_for_tests().await;
let (json_handler, _) = components_for_tests().await;
let request = serde_json::json!({
"jsonrpc": "2.0",
"method": "get_account_balance",
@ -576,9 +533,9 @@ mod tests {
#[actix_web::test]
async fn test_get_account_balance_for_existing_account() {
let (json_handler, initial_accounts, _) = components_for_tests().await;
let (json_handler, _) = components_for_tests().await;
let acc1_id = initial_accounts[0].account_id;
let acc1_id = initial_accounts()[0].account_id;
let request = serde_json::json!({
"jsonrpc": "2.0",
@ -601,7 +558,7 @@ mod tests {
#[actix_web::test]
async fn test_get_accounts_nonces_for_non_existent_account() {
let (json_handler, _, _) = components_for_tests().await;
let (json_handler, _) = components_for_tests().await;
let request = serde_json::json!({
"jsonrpc": "2.0",
"method": "get_accounts_nonces",
@ -623,10 +580,10 @@ mod tests {
#[actix_web::test]
async fn test_get_accounts_nonces_for_existent_account() {
let (json_handler, initial_accounts, _) = components_for_tests().await;
let (json_handler, _) = components_for_tests().await;
let acc1_id = initial_accounts[0].account_id;
let acc2_id = initial_accounts[1].account_id;
let acc1_id = initial_accounts()[0].account_id;
let acc2_id = initial_accounts()[1].account_id;
let request = serde_json::json!({
"jsonrpc": "2.0",
@ -649,7 +606,7 @@ mod tests {
#[actix_web::test]
async fn test_get_account_data_for_non_existent_account() {
let (json_handler, _, _) = components_for_tests().await;
let (json_handler, _) = components_for_tests().await;
let request = serde_json::json!({
"jsonrpc": "2.0",
"method": "get_account",
@ -676,7 +633,7 @@ mod tests {
#[actix_web::test]
async fn test_get_transaction_by_hash_for_non_existent_hash() {
let (json_handler, _, _) = components_for_tests().await;
let (json_handler, _) = components_for_tests().await;
let request = serde_json::json!({
"jsonrpc": "2.0",
"method": "get_transaction_by_hash",
@ -698,7 +655,7 @@ mod tests {
#[actix_web::test]
async fn test_get_transaction_by_hash_for_invalid_hex() {
let (json_handler, _, _) = components_for_tests().await;
let (json_handler, _) = components_for_tests().await;
let request = serde_json::json!({
"jsonrpc": "2.0",
"method": "get_transaction_by_hash",
@ -729,7 +686,7 @@ mod tests {
#[actix_web::test]
async fn test_get_transaction_by_hash_for_invalid_length() {
let (json_handler, _, _) = components_for_tests().await;
let (json_handler, _) = components_for_tests().await;
let request = serde_json::json!({
"jsonrpc": "2.0",
"method": "get_transaction_by_hash",
@ -760,7 +717,7 @@ mod tests {
#[actix_web::test]
async fn test_get_transaction_by_hash_for_existing_transaction() {
let (json_handler, _, tx) = components_for_tests().await;
let (json_handler, tx) = components_for_tests().await;
let tx_hash_hex = hex::encode(tx.hash());
let expected_base64_encoded = general_purpose::STANDARD.encode(borsh::to_vec(&tx).unwrap());

View File

@ -95,7 +95,7 @@ impl WalletChainStore {
let mut public_init_acc_map = BTreeMap::new();
let mut private_init_acc_map = BTreeMap::new();
for init_acc_data in config.initial_accounts.clone() {
for init_acc_data in InitialAccountData::create_initial_accounts_data() {
match init_acc_data {
InitialAccountData::Public(data) => {
public_init_acc_map.insert(data.account_id, data.pub_sign_key);
@ -162,101 +162,7 @@ mod tests {
};
use super::*;
use crate::config::{
InitialAccountData, PersistentAccountDataPrivate, PersistentAccountDataPublic,
};
fn create_initial_accounts() -> Vec<InitialAccountData> {
let initial_acc1 = serde_json::from_str(
r#"{
"Public": {
"account_id": "6iArKUXxhUJqS7kCaPNhwMWt3ro71PDyBj7jwAyE2VQV",
"pub_sign_key": [
16,
162,
106,
154,
236,
125,
52,
184,
35,
100,
238,
174,
69,
197,
41,
77,
187,
10,
118,
75,
0,
11,
148,
238,
185,
181,
133,
17,
220,
72,
124,
77
]
}
}"#,
)
.unwrap();
let initial_acc2 = serde_json::from_str(
r#"{
"Public": {
"account_id": "7wHg9sbJwc6h3NP1S9bekfAzB8CHifEcxKswCKUt3YQo",
"pub_sign_key": [
113,
121,
64,
177,
204,
85,
229,
214,
178,
6,
109,
191,
29,
154,
63,
38,
242,
18,
244,
219,
8,
208,
35,
136,
23,
127,
207,
237,
216,
169,
190,
27
]
}
}"#,
)
.unwrap();
let initial_accounts = vec![initial_acc1, initial_acc2];
initial_accounts
}
use crate::config::{PersistentAccountDataPrivate, PersistentAccountDataPublic};
fn create_sample_wallet_config() -> WalletConfig {
WalletConfig {
@ -266,7 +172,6 @@ mod tests {
seq_tx_poll_max_blocks: 5,
seq_poll_max_retries: 10,
seq_block_poll_max_amount: 100,
initial_accounts: create_initial_accounts(),
basic_auth: None,
}
}

View File

@ -4,6 +4,7 @@ use clap::Subcommand;
use crate::{
WalletCore,
cli::{SubcommandReturnValue, WalletSubcommand},
config::InitialAccountData,
};
/// Represents generic config CLI subcommand
@ -68,7 +69,7 @@ impl WalletSubcommand for ConfigSubcommand {
);
}
"initial_accounts" => {
println!("{:#?}", wallet_core.storage.wallet_config.initial_accounts);
println!("{:#?}", InitialAccountData::create_initial_accounts_data());
}
"basic_auth" => {
if let Some(basic_auth) = &wallet_core.storage.wallet_config.basic_auth

View File

@ -8,9 +8,12 @@ use std::{
use anyhow::{Context as _, Result};
use common::config::BasicAuth;
use humantime_serde;
use key_protocol::key_management::{
KeyChain,
key_tree::{
use key_protocol::{
initial_state::{
PrivateAccountPrivateInitialData, PublicAccountPrivateInitialData,
initial_priv_accounts_private_keys, initial_pub_accounts_private_keys,
},
key_management::key_tree::{
chain_index::ChainIndex, keys_private::ChildKeysPrivate, keys_public::ChildKeysPublic,
},
};
@ -18,12 +21,6 @@ use log::warn;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InitialAccountDataPublic {
pub account_id: nssa::AccountId,
pub pub_sign_key: nssa::PrivateKey,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PersistentAccountDataPublic {
pub account_id: nssa::AccountId,
@ -31,13 +28,6 @@ pub struct PersistentAccountDataPublic {
pub data: ChildKeysPublic,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InitialAccountDataPrivate {
pub account_id: nssa::AccountId,
pub account: nssa_core::account::Account,
pub key_chain: KeyChain,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PersistentAccountDataPrivate {
pub account_id: nssa::AccountId,
@ -51,8 +41,21 @@ pub struct PersistentAccountDataPrivate {
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum InitialAccountData {
Public(InitialAccountDataPublic),
Private(InitialAccountDataPrivate),
Public(PublicAccountPrivateInitialData),
Private(PrivateAccountPrivateInitialData),
}
impl InitialAccountData {
pub(crate) fn create_initial_accounts_data() -> Vec<Self> {
let pub_data = initial_pub_accounts_private_keys();
let priv_data = initial_priv_accounts_private_keys();
pub_data
.into_iter()
.map(Into::into)
.chain(priv_data.into_iter().map(Into::into))
.collect()
}
}
// Big difference in enum variants sizes
@ -130,14 +133,14 @@ impl PersistentAccountData {
}
}
impl From<InitialAccountDataPublic> for InitialAccountData {
fn from(value: InitialAccountDataPublic) -> Self {
impl From<PublicAccountPrivateInitialData> for InitialAccountData {
fn from(value: PublicAccountPrivateInitialData) -> Self {
Self::Public(value)
}
}
impl From<InitialAccountDataPrivate> for InitialAccountData {
fn from(value: InitialAccountDataPrivate) -> Self {
impl From<PrivateAccountPrivateInitialData> for InitialAccountData {
fn from(value: PrivateAccountPrivateInitialData) -> Self {
Self::Private(value)
}
}
@ -195,8 +198,6 @@ pub struct WalletConfig {
pub seq_poll_max_retries: u64,
/// Max amount of blocks to poll in one request
pub seq_block_poll_max_amount: u64,
/// Initial accounts for wallet
pub initial_accounts: Vec<InitialAccountData>,
/// Basic authentication credentials
#[serde(skip_serializing_if = "Option::is_none")]
pub basic_auth: Option<BasicAuth>,
@ -212,291 +213,6 @@ impl Default for WalletConfig {
seq_poll_max_retries: 5,
seq_block_poll_max_amount: 100,
basic_auth: None,
initial_accounts: {
let init_acc_json = r#"
[
{
"Public": {
"account_id": "6iArKUXxhUJqS7kCaPNhwMWt3ro71PDyBj7jwAyE2VQV",
"pub_sign_key": [
16,
162,
106,
154,
236,
125,
52,
184,
35,
100,
238,
174,
69,
197,
41,
77,
187,
10,
118,
75,
0,
11,
148,
238,
185,
181,
133,
17,
220,
72,
124,
77
]
}
},
{
"Public": {
"account_id": "7wHg9sbJwc6h3NP1S9bekfAzB8CHifEcxKswCKUt3YQo",
"pub_sign_key": [
113,
121,
64,
177,
204,
85,
229,
214,
178,
6,
109,
191,
29,
154,
63,
38,
242,
18,
244,
219,
8,
208,
35,
136,
23,
127,
207,
237,
216,
169,
190,
27
]
}
},
{
"Private": {
"account_id": "FpdcxBrMkHWqXCBQ6FG98eYfWGY6jWZRsKNSi1FwDMxy",
"account": {
"program_owner": [
0,
0,
0,
0,
0,
0,
0,
0
],
"balance": 10000,
"data": [],
"nonce": 0
},
"key_chain": {
"secret_spending_key": [
239,
27,
159,
83,
199,
194,
132,
33,
20,
28,
217,
103,
101,
57,
27,
125,
84,
57,
19,
86,
98,
135,
161,
221,
108,
125,
152,
174,
161,
64,
16,
200
],
"private_key_holder": {
"nullifier_secret_key": [
71,
195,
16,
119,
0,
98,
35,
106,
139,
82,
145,
50,
27,
140,
206,
19,
53,
122,
166,
76,
195,
0,
16,
19,
21,
143,
155,
119,
9,
200,
81,
105
],
"viewing_secret_key": [
5,
117,
221,
27,
236,
199,
53,
22,
249,
231,
98,
147,
213,
116,
191,
82,
188,
148,
175,
98,
139,
52,
232,
249,
220,
217,
83,
58,
112,
155,
197,
196
]
},
"nullifer_public_key": [
177,
64,
1,
11,
87,
38,
254,
159,
231,
165,
1,
94,
64,
137,
243,
76,
249,
101,
251,
129,
33,
101,
189,
30,
42,
11,
191,
34,
103,
186,
227,
230
],
"viewing_public_key": [
2, 69, 126, 43, 158, 209, 172, 144, 23, 185, 208, 25, 163, 166, 176, 200, 225, 251, 106, 211, 4, 199, 112, 243, 207, 144, 135, 56, 157, 167, 32, 219, 38]
}
}
},
{
"Private": {
"account_id": "E8HwiTyQe4H9HK7icTvn95HQMnzx49mP9A2ddtMLpNaN",
"account": {
"program_owner": [
0,
0,
0,
0,
0,
0,
0,
0
],
"balance": 20000,
"data": [],
"nonce": 0
},
"key_chain": {
"secret_spending_key": [
48, 175, 124, 10, 230, 240, 166, 14, 249, 254, 157, 226, 208, 124, 122, 177, 203, 139, 192, 180, 43, 120, 55, 151, 50, 21, 113, 22, 254, 83, 148, 56],
"private_key_holder": {
"nullifier_secret_key": [
99, 82, 190, 140, 234, 10, 61, 163, 15, 211, 179, 54, 70, 166, 87, 5, 182, 68, 117, 244, 217, 23, 99, 9, 4, 177, 230, 125, 109, 91, 160, 30
],
"viewing_secret_key": [
205, 32, 76, 251, 255, 236, 96, 119, 61, 111, 65, 100, 75, 218, 12, 22, 17, 170, 55, 226, 21, 154, 161, 34, 208, 74, 27, 1, 119, 13, 88, 128
]
},
"nullifer_public_key": [
32, 67, 72, 164, 106, 53, 66, 239, 141, 15, 52, 230, 136, 177, 2, 236, 207, 243, 134, 135, 210, 143, 87, 232, 215, 128, 194, 120, 113, 224, 4, 165
],
"viewing_public_key": [
2, 79, 110, 46, 203, 29, 206, 205, 18, 86, 27, 189, 104, 103, 113, 181, 110, 53, 78, 172, 11, 171, 190, 18, 126, 214, 81, 77, 192, 154, 58, 195, 238
]
}
}
}
]
"#;
serde_json::from_str(init_acc_json).unwrap()
},
}
}
}
@ -546,7 +262,6 @@ impl WalletConfig {
seq_tx_poll_max_blocks,
seq_poll_max_retries,
seq_block_poll_max_amount,
initial_accounts,
basic_auth,
} = self;
@ -557,7 +272,6 @@ impl WalletConfig {
seq_tx_poll_max_blocks: o_seq_tx_poll_max_blocks,
seq_poll_max_retries: o_seq_poll_max_retries,
seq_block_poll_max_amount: o_seq_block_poll_max_amount,
initial_accounts: o_initial_accounts,
basic_auth: o_basic_auth,
} = overrides;
@ -585,10 +299,6 @@ impl WalletConfig {
warn!("Overriding wallet config 'seq_block_poll_max_amount' to {v}");
*seq_block_poll_max_amount = v;
}
if let Some(v) = o_initial_accounts {
warn!("Overriding wallet config 'initial_accounts' to {v:#?}");
*initial_accounts = v;
}
if let Some(v) = o_basic_auth {
warn!("Overriding wallet config 'basic_auth' to {v:#?}");
*basic_auth = v;

View File

@ -2,7 +2,10 @@ use std::{collections::HashMap, path::PathBuf, str::FromStr};
use anyhow::Result;
use base64::{Engine, engine::general_purpose::STANDARD as BASE64};
use key_protocol::key_protocol_core::NSSAUserData;
use key_protocol::{
initial_state::{PrivateAccountPrivateInitialData, PublicAccountPrivateInitialData},
key_protocol_core::NSSAUserData,
};
use nssa::Account;
use nssa_core::account::Nonce;
use rand::{RngCore, rngs::OsRng};
@ -11,8 +14,8 @@ use serde::Serialize;
use crate::{
HOME_DIR_ENV_VAR,
config::{
InitialAccountData, InitialAccountDataPrivate, InitialAccountDataPublic, Label,
PersistentAccountDataPrivate, PersistentAccountDataPublic, PersistentStorage,
InitialAccountData, Label, PersistentAccountDataPrivate, PersistentAccountDataPublic,
PersistentStorage,
},
};
@ -89,7 +92,7 @@ pub fn produce_data_for_storage(
for (account_id, key) in &user_data.default_pub_account_signing_keys {
vec_for_storage.push(
InitialAccountData::Public(InitialAccountDataPublic {
InitialAccountData::Public(PublicAccountPrivateInitialData {
account_id: *account_id,
pub_sign_key: key.clone(),
})
@ -99,7 +102,7 @@ pub fn produce_data_for_storage(
for (account_id, (key_chain, account)) in &user_data.default_user_private_accounts {
vec_for_storage.push(
InitialAccountData::Private(InitialAccountDataPrivate {
InitialAccountData::Private(PrivateAccountPrivateInitialData {
account_id: *account_id,
account: account.clone(),
key_chain: key_chain.clone(),