mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-03 22:03:06 +00:00
feat: node side of public native token transfer 1
This commit is contained in:
parent
14b35a93c0
commit
9097762a53
@ -7,6 +7,7 @@ use common::{
|
||||
block::Block,
|
||||
merkle_tree_public::merkle_tree::{PublicTransactionMerkleTree, UTXOCommitmentsMerkleTree},
|
||||
nullifier::UTXONullifier,
|
||||
public_transfer_receipts::PublicNativeTokenSend,
|
||||
utxo_commitment::UTXOCommitment,
|
||||
};
|
||||
use k256::AffinePoint;
|
||||
@ -158,6 +159,20 @@ impl NodeChainStore {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} else {
|
||||
let native_transfer =
|
||||
serde_json::from_slice::<PublicNativeTokenSend>(&tx.execution_input);
|
||||
|
||||
if let Ok(transfer) = native_transfer {
|
||||
if let Some(acc_sender) = self.acc_map.get_mut(&transfer.from) {
|
||||
//Can panic, we depend on sequencer maintaining chain consistency here
|
||||
acc_sender.balance -= transfer.moved_balance;
|
||||
|
||||
if let Some(acc_rec) = self.acc_map.get_mut(&transfer.to) {
|
||||
acc_rec.balance += transfer.moved_balance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ use std::sync::{
|
||||
Arc,
|
||||
};
|
||||
|
||||
use common::ExecutionFailureKind;
|
||||
use common::{public_transfer_receipts::PublicNativeTokenSend, ExecutionFailureKind};
|
||||
|
||||
use accounts::account_core::{Account, AccountAddress};
|
||||
use anyhow::Result;
|
||||
@ -943,6 +943,52 @@ impl NodeCore {
|
||||
Ok(self.sequencer_client.send_tx(tx, tx_roots).await?)
|
||||
}
|
||||
|
||||
pub async fn send_public_native_token_transfer(
|
||||
&self,
|
||||
from: AccountAddress,
|
||||
to: AccountAddress,
|
||||
moved_balance: u64,
|
||||
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
||||
let tx_roots = self.get_roots().await;
|
||||
|
||||
let public_context = {
|
||||
let read_guard = self.storage.read().await;
|
||||
|
||||
read_guard.produce_context(from)
|
||||
};
|
||||
|
||||
let (tweak, secret_r, commitment) = pedersen_commitment_vec(
|
||||
//Will not panic, as public context is serializable
|
||||
public_context.produce_u64_list_from_context().unwrap(),
|
||||
);
|
||||
|
||||
let sc_addr = hex::encode([0; 32]);
|
||||
|
||||
//Native does not change its state
|
||||
let state_changes: Vec<DataBlobChangeVariant> = vec![];
|
||||
let new_len = 0;
|
||||
let state_changes = (serde_json::to_value(state_changes).unwrap(), new_len);
|
||||
|
||||
let tx: Transaction =
|
||||
sc_core::transaction_payloads_tools::create_public_transaction_payload(
|
||||
serde_json::to_vec(&PublicNativeTokenSend {
|
||||
from,
|
||||
to,
|
||||
moved_balance,
|
||||
})
|
||||
.unwrap(),
|
||||
commitment,
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
)
|
||||
.into();
|
||||
tx.log();
|
||||
|
||||
Ok(self.sequencer_client.send_tx(tx, tx_roots).await?)
|
||||
}
|
||||
|
||||
pub async fn send_private_send_tx(
|
||||
&self,
|
||||
utxo: UTXO,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user