mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-03 22:03:06 +00:00
fix: lints and merge fixes
This commit is contained in:
parent
494cc7fb1e
commit
a9d81b19ed
@ -21,7 +21,6 @@ pub struct Account {
|
||||
pub key_holder: AddressKeyHolder,
|
||||
pub address: Address,
|
||||
pub balance: u64,
|
||||
pub nonce: u64,
|
||||
pub utxos: HashMap<TreeHashType, UTXO>,
|
||||
}
|
||||
|
||||
@ -30,7 +29,6 @@ pub struct AccountForSerialization {
|
||||
pub key_holder: AddressKeyHolder,
|
||||
pub address: Address,
|
||||
pub balance: u64,
|
||||
pub nonce: u64,
|
||||
pub utxos: HashMap<String, UTXO>,
|
||||
}
|
||||
|
||||
@ -40,7 +38,6 @@ impl From<Account> for AccountForSerialization {
|
||||
key_holder: value.key_holder,
|
||||
address: value.address,
|
||||
balance: value.balance,
|
||||
nonce: value.nonce,
|
||||
utxos: value
|
||||
.utxos
|
||||
.into_iter()
|
||||
@ -56,7 +53,6 @@ impl From<AccountForSerialization> for Account {
|
||||
key_holder: value.key_holder,
|
||||
address: value.address,
|
||||
balance: value.balance,
|
||||
nonce: value.nonce,
|
||||
utxos: value
|
||||
.utxos
|
||||
.into_iter()
|
||||
@ -121,14 +117,12 @@ impl Account {
|
||||
nssa::PublicKey::new_from_private_key(key_holder.get_pub_account_signing_key());
|
||||
let address = nssa::Address::from(&public_key);
|
||||
let balance = 0;
|
||||
let nonce = 0;
|
||||
let utxos = HashMap::new();
|
||||
|
||||
Self {
|
||||
key_holder,
|
||||
address,
|
||||
balance,
|
||||
nonce,
|
||||
utxos,
|
||||
}
|
||||
}
|
||||
@ -144,7 +138,6 @@ impl Account {
|
||||
key_holder,
|
||||
address,
|
||||
balance,
|
||||
nonce,
|
||||
utxos,
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,4 +18,3 @@ serde_json.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
test-program-methods = { path = "test_program_methods" }
|
||||
|
||||
|
||||
@ -118,7 +118,7 @@ impl<'de> Deserialize<'de> for HexString {
|
||||
let str_cand = deserializer.deserialize_string(HexStringVisitor)?;
|
||||
|
||||
let hex_string =
|
||||
HexString::try_from(str_cand.as_str()).map_err(|err| serde::de::Error::custom(err))?;
|
||||
HexString::try_from(str_cand.as_str()).map_err(serde::de::Error::custom)?;
|
||||
|
||||
Ok(hex_string)
|
||||
}
|
||||
@ -224,9 +224,7 @@ mod tests {
|
||||
|
||||
let addr_for_tests = Address::new([42; 32]);
|
||||
|
||||
let ser2_str = Ser3 {
|
||||
f1: addr_for_tests,
|
||||
};
|
||||
let ser2_str = Ser3 { f1: addr_for_tests };
|
||||
|
||||
let ser1_str: Ser3 = serde_json::from_str(raw_json).unwrap();
|
||||
|
||||
|
||||
@ -224,7 +224,7 @@ pub mod tests {
|
||||
let instruction = 1337;
|
||||
let message = Message::try_new(
|
||||
Program::authenticated_transfer_program().id(),
|
||||
vec![addr1.clone(), addr1],
|
||||
vec![addr1, addr1],
|
||||
nonces,
|
||||
instruction,
|
||||
)
|
||||
|
||||
@ -197,7 +197,7 @@ mod tests {
|
||||
assert_eq!(state.get_account_by_address(&to), Account::default());
|
||||
let balance_to_move = 5;
|
||||
|
||||
let tx = transfer_transaction(from.clone(), key, 0, to.clone(), balance_to_move);
|
||||
let tx = transfer_transaction(from, key, 0, to, balance_to_move);
|
||||
state.transition_from_public_transaction(&tx).unwrap();
|
||||
|
||||
assert_eq!(state.get_account_by_address(&from).balance, 95);
|
||||
@ -218,7 +218,7 @@ mod tests {
|
||||
let balance_to_move = 101;
|
||||
assert!(state.get_account_by_address(&from).balance < balance_to_move);
|
||||
|
||||
let tx = transfer_transaction(from.clone(), from_key, 0, to.clone(), balance_to_move);
|
||||
let tx = transfer_transaction(from, from_key, 0, to, balance_to_move);
|
||||
let result = state.transition_from_public_transaction(&tx);
|
||||
|
||||
assert!(matches!(result, Err(NssaError::ProgramExecutionFailed(_))));
|
||||
@ -242,7 +242,7 @@ mod tests {
|
||||
assert_ne!(state.get_account_by_address(&to), Account::default());
|
||||
let balance_to_move = 8;
|
||||
|
||||
let tx = transfer_transaction(from.clone(), from_key, 0, to.clone(), balance_to_move);
|
||||
let tx = transfer_transaction(from, from_key, 0, to, balance_to_move);
|
||||
state.transition_from_public_transaction(&tx).unwrap();
|
||||
|
||||
assert_eq!(state.get_account_by_address(&from).balance, 192);
|
||||
@ -262,10 +262,10 @@ mod tests {
|
||||
let address3 = Address::new([3; 32]);
|
||||
let balance_to_move = 5;
|
||||
|
||||
let tx = transfer_transaction(address1.clone(), key1, 0, address2.clone(), balance_to_move);
|
||||
let tx = transfer_transaction(address1, key1, 0, address2, balance_to_move);
|
||||
state.transition_from_public_transaction(&tx).unwrap();
|
||||
let balance_to_move = 3;
|
||||
let tx = transfer_transaction(address2.clone(), key2, 0, address3.clone(), balance_to_move);
|
||||
let tx = transfer_transaction(address2, key2, 0, address3, balance_to_move);
|
||||
state.transition_from_public_transaction(&tx).unwrap();
|
||||
|
||||
assert_eq!(state.get_account_by_address(&address1).balance, 95);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
use std::{fs::File, io::BufReader, path::PathBuf, str::FromStr};
|
||||
|
||||
use accounts::account_core::Account;
|
||||
use anyhow::Result;
|
||||
use nssa::{address::HexString, Address};
|
||||
|
||||
|
||||
@ -11,7 +11,6 @@ use chain_storage::WalletChainStore;
|
||||
use config::WalletConfig;
|
||||
use log::info;
|
||||
use nssa::Address;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
@ -43,6 +42,9 @@ impl WalletCore {
|
||||
|
||||
//Persistent accounts take precedence for initial accounts
|
||||
let persistent_accounts = fetch_persistent_accounts()?;
|
||||
|
||||
info!("Fetched persistent accoounts {persistent_accounts:#?}");
|
||||
|
||||
for acc in persistent_accounts {
|
||||
storage.acc_map.insert(acc.address, acc);
|
||||
}
|
||||
@ -72,34 +74,29 @@ impl WalletCore {
|
||||
to: Address,
|
||||
balance_to_move: u128,
|
||||
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
||||
{
|
||||
let read_guard = self.storage.read().await;
|
||||
let account = self.storage.acc_map.get(&from);
|
||||
|
||||
if let Some(account) = account {
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
let addresses = vec![from, to];
|
||||
let nonces = vec![nonce];
|
||||
let program_id = nssa::program::Program::authenticated_transfer_program().id();
|
||||
let message = nssa::public_transaction::Message::try_new(
|
||||
program_id,
|
||||
addresses,
|
||||
nonces,
|
||||
balance_to_move,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
if let Some(account) = account {
|
||||
let addresses = vec![from, to];
|
||||
let nonces = vec![nonce];
|
||||
let program_id = nssa::program::Program::authenticated_transfer_program().id();
|
||||
let message = nssa::public_transaction::Message::try_new(
|
||||
program_id,
|
||||
addresses,
|
||||
nonces,
|
||||
balance_to_move,
|
||||
)
|
||||
.unwrap();
|
||||
let signing_key = account.key_holder.get_pub_account_signing_key();
|
||||
let witness_set =
|
||||
nssa::public_transaction::WitnessSet::for_message(&message, &[signing_key]);
|
||||
|
||||
let signing_key = account.key_holder.get_pub_account_signing_key();
|
||||
let witness_set =
|
||||
nssa::public_transaction::WitnessSet::for_message(&message, &[signing_key]);
|
||||
let tx = nssa::PublicTransaction::new(message, witness_set);
|
||||
|
||||
let tx = nssa::PublicTransaction::new(message, witness_set);
|
||||
|
||||
Ok(self.sequencer_client.send_tx(tx).await?)
|
||||
} else {
|
||||
Err(ExecutionFailureKind::AmountMismatchError)
|
||||
}
|
||||
Ok(self.sequencer_client.send_tx(tx).await?)
|
||||
} else {
|
||||
Err(ExecutionFailureKind::AmountMismatchError)
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,7 +177,7 @@ pub async fn execute_subcommand(command: Command) -> Result<()> {
|
||||
let from = produce_account_addr_from_hex(from)?;
|
||||
let to = produce_account_addr_from_hex(to)?;
|
||||
|
||||
let mut wallet_core = WalletCore::start_from_config_update_chain(wallet_config).await?;
|
||||
let wallet_core = WalletCore::start_from_config_update_chain(wallet_config).await?;
|
||||
|
||||
let res = wallet_core
|
||||
.send_public_native_token_transfer(from, nonce, to, amount)
|
||||
@ -189,7 +186,6 @@ pub async fn execute_subcommand(command: Command) -> Result<()> {
|
||||
info!("Results of tx send is {res:#?}");
|
||||
|
||||
//ToDo: Insert transaction polling logic here
|
||||
wallet_core.increment_nonces(&[from, to]);
|
||||
|
||||
let acc_storage_path = wallet_core.store_present_accounts_at_home()?;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user