mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-05-14 03:59:30 +00:00
addressed more comments
This commit is contained in:
parent
b396756e8d
commit
27905d94d6
@ -56,9 +56,9 @@ impl WalletChainStore {
|
||||
.expect("Malformed persistent account data, must have private root");
|
||||
|
||||
let mut public_tree = KeyTreePublic::new_from_root(match public_root {
|
||||
PersistentAccountData::Public(data) => {
|
||||
data.data.expect("Expect valid public account keys")
|
||||
}
|
||||
PersistentAccountData::Public(data) => data
|
||||
.data
|
||||
.expect("public tree in persistent_accounts failed to return a valid KeyTree."),
|
||||
_ => unreachable!(),
|
||||
});
|
||||
let mut private_tree = KeyTreePrivate::new_from_root(match private_root {
|
||||
|
||||
@ -548,14 +548,14 @@ impl WalletCore {
|
||||
}
|
||||
|
||||
pub fn sign_public_message(
|
||||
wallet: &Self,
|
||||
&self,
|
||||
message: &nssa::public_transaction::Message,
|
||||
account_ids: &[AccountId],
|
||||
) -> Result<nssa::public_transaction::WitnessSet, ExecutionFailureKind> {
|
||||
let mut private_keys = Vec::new();
|
||||
|
||||
for &account_id in account_ids {
|
||||
let key = wallet
|
||||
let key = self
|
||||
.storage
|
||||
.user_data
|
||||
.get_pub_account_signing_key(account_id)
|
||||
@ -569,16 +569,25 @@ impl WalletCore {
|
||||
))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn sign_privacy_message(
|
||||
message: &nssa::privacy_preserving_transaction::Message,
|
||||
proof: &Proof,
|
||||
acc_manager: &privacy_preserving_tx::AccountManager,
|
||||
) -> nssa::privacy_preserving_transaction::witness_set::WitnessSet
|
||||
{
|
||||
) -> nssa::privacy_preserving_transaction::witness_set::WitnessSet {
|
||||
nssa::privacy_preserving_transaction::witness_set::WitnessSet::for_message(
|
||||
message,
|
||||
proof.clone(),
|
||||
&acc_manager.public_account_auth())
|
||||
message,
|
||||
proof.clone(),
|
||||
&acc_manager.public_account_auth(),
|
||||
)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn filter_owned_accounts(&self, account_ids: &[nssa::AccountId]) -> Vec<nssa::AccountId> {
|
||||
account_ids
|
||||
.iter()
|
||||
.filter(|&&account_id| self.get_account_public_signing_key(account_id).is_some())
|
||||
.copied()
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,49 +22,35 @@ impl NativeTokenTransfer<'_> {
|
||||
.await
|
||||
.map_err(ExecutionFailureKind::SequencerError)?;
|
||||
|
||||
if balance >= balance_to_move {
|
||||
let account_ids = vec![from, to];
|
||||
let program_id = Program::authenticated_transfer_program().id();
|
||||
|
||||
let mut sign_ids = Vec::new();
|
||||
sign_ids.push(from);
|
||||
|
||||
let mut nonces = self
|
||||
.0
|
||||
.get_accounts_nonces(vec![from])
|
||||
.await
|
||||
.map_err(ExecutionFailureKind::SequencerError)?;
|
||||
let to_signing_key = self.0.storage.user_data.get_pub_account_signing_key(to);
|
||||
if let Some(_to_signing_key) = to_signing_key {
|
||||
sign_ids.push(to);
|
||||
let to_nonces = self
|
||||
.0
|
||||
.get_accounts_nonces(vec![to])
|
||||
.await
|
||||
.map_err(ExecutionFailureKind::SequencerError)?;
|
||||
nonces.extend(to_nonces);
|
||||
} else {
|
||||
println!(
|
||||
"Receiver's account ({to}) private key not found in wallet. Proceeding with only sender's key."
|
||||
);
|
||||
}
|
||||
|
||||
let message =
|
||||
Message::try_new(program_id, account_ids, nonces, balance_to_move).unwrap();
|
||||
|
||||
let witness_set = WalletCore::sign_public_message(self.0, &message, &sign_ids)
|
||||
.expect("Expect a valid signature");
|
||||
|
||||
let tx = PublicTransaction::new(message, witness_set);
|
||||
|
||||
Ok(self
|
||||
.0
|
||||
.sequencer_client
|
||||
.send_transaction(NSSATransaction::Public(tx))
|
||||
.await?)
|
||||
} else {
|
||||
Err(ExecutionFailureKind::InsufficientFundsError)
|
||||
if balance < balance_to_move {
|
||||
return Err(ExecutionFailureKind::InsufficientFundsError);
|
||||
}
|
||||
|
||||
let account_ids = vec![from, to];
|
||||
let program_id = Program::authenticated_transfer_program().id();
|
||||
|
||||
let sign_ids = self.0.filter_owned_accounts(&[from, to]);
|
||||
|
||||
// Fetch nonces for both accounts unconditionally
|
||||
let nonces = self
|
||||
.0
|
||||
.get_accounts_nonces(account_ids.clone())
|
||||
.await
|
||||
.map_err(ExecutionFailureKind::SequencerError)?;
|
||||
|
||||
let message = Message::try_new(program_id, account_ids, nonces, balance_to_move).unwrap();
|
||||
|
||||
// Assumes this now silently skips accounts without signing keys
|
||||
let witness_set = WalletCore::sign_public_message(self.0, &message, &sign_ids)
|
||||
.expect("`WalletCore::sign_public_message() failed to produce a signature for a NativeTokenTransfer.");
|
||||
|
||||
let tx = PublicTransaction::new(message, witness_set);
|
||||
|
||||
Ok(self
|
||||
.0
|
||||
.sequencer_client
|
||||
.send_transaction(NSSATransaction::Public(tx))
|
||||
.await?)
|
||||
}
|
||||
|
||||
pub async fn register_account(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user