mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-08-25 06:41:13 +00:00
Merge branch 'main' into schouhy/add-clippy-to-ci
This commit is contained in:
@@ -126,8 +126,9 @@ impl NodeChainStore {
|
||||
let block_id = block.block_id;
|
||||
|
||||
for tx in &block.transactions {
|
||||
if !tx.execution_input.is_empty() {
|
||||
let public_action = serde_json::from_slice::<ActionData>(&tx.execution_input);
|
||||
if !tx.body().execution_input.is_empty() {
|
||||
let public_action =
|
||||
serde_json::from_slice::<ActionData>(&tx.body().execution_input);
|
||||
|
||||
if let Ok(public_action) = public_action {
|
||||
match public_action {
|
||||
@@ -161,24 +162,25 @@ impl NodeChainStore {
|
||||
}
|
||||
|
||||
self.utxo_commitments_store.add_tx_multiple(
|
||||
tx.utxo_commitments_created_hashes
|
||||
tx.body()
|
||||
.utxo_commitments_created_hashes
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|hash| UTXOCommitment { hash })
|
||||
.collect(),
|
||||
);
|
||||
|
||||
for nullifier in tx.nullifier_created_hashes.iter() {
|
||||
for nullifier in tx.body().nullifier_created_hashes.iter() {
|
||||
self.nullifier_store.insert(UTXONullifier {
|
||||
utxo_hash: *nullifier,
|
||||
});
|
||||
}
|
||||
|
||||
if !tx.encoded_data.is_empty() {
|
||||
if !tx.body().encoded_data.is_empty() {
|
||||
let ephemeral_public_key_sender =
|
||||
serde_json::from_slice::<AffinePoint>(&tx.ephemeral_pub_key)?;
|
||||
serde_json::from_slice::<AffinePoint>(&tx.body().ephemeral_pub_key)?;
|
||||
|
||||
for (ciphertext, nonce, tag) in tx.encoded_data.clone() {
|
||||
for (ciphertext, nonce, tag) in tx.body().encoded_data.clone() {
|
||||
let slice = nonce.as_slice();
|
||||
let nonce =
|
||||
accounts::key_management::constants_types::Nonce::clone_from_slice(slice);
|
||||
@@ -203,7 +205,7 @@ impl NodeChainStore {
|
||||
}
|
||||
}
|
||||
|
||||
self.pub_tx_store.add_tx(tx.clone());
|
||||
self.pub_tx_store.add_tx(tx);
|
||||
}
|
||||
|
||||
self.block_store.put_block_at_id(block)?;
|
||||
@@ -282,7 +284,7 @@ mod tests {
|
||||
use accounts::account_core::Account;
|
||||
use common::block::{Block, Data};
|
||||
use common::merkle_tree_public::TreeHashType;
|
||||
use common::transaction::{Transaction, TxKind};
|
||||
use common::transaction::{SignaturePrivateKey, Transaction, TransactionBody, TxKind};
|
||||
use secp256k1_zkp::Tweak;
|
||||
use std::path::PathBuf;
|
||||
use tempfile::tempdir;
|
||||
@@ -299,14 +301,13 @@ mod tests {
|
||||
}
|
||||
|
||||
fn create_dummy_transaction(
|
||||
// execution_input: Vec<u8>,
|
||||
nullifier_created_hashes: Vec<[u8; 32]>,
|
||||
utxo_commitments_spent_hashes: Vec<[u8; 32]>,
|
||||
utxo_commitments_created_hashes: Vec<[u8; 32]>,
|
||||
) -> Transaction {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
Transaction {
|
||||
let body = TransactionBody {
|
||||
tx_kind: TxKind::Private,
|
||||
execution_input: vec![],
|
||||
execution_output: vec![],
|
||||
@@ -321,7 +322,8 @@ mod tests {
|
||||
secret_r: [0; 32],
|
||||
sc_addr: "sc_addr".to_string(),
|
||||
state_changes: (serde_json::Value::Null, 0),
|
||||
}
|
||||
};
|
||||
Transaction::new(body, SignaturePrivateKey::random(&mut rng))
|
||||
}
|
||||
|
||||
fn create_sample_block(block_id: u64, prev_block_id: u64) -> Block {
|
||||
@@ -417,7 +419,7 @@ mod tests {
|
||||
store
|
||||
.utxo_commitments_store
|
||||
.add_tx_multiple(vec![UTXOCommitment { hash: [3u8; 32] }]);
|
||||
store.pub_tx_store.add_tx(create_dummy_transaction(
|
||||
store.pub_tx_store.add_tx(&create_dummy_transaction(
|
||||
vec![[9; 32]],
|
||||
vec![[7; 32]],
|
||||
vec![[8; 32]],
|
||||
|
||||
+251
-263
@@ -3,7 +3,7 @@ use std::sync::{
|
||||
Arc,
|
||||
};
|
||||
|
||||
use common::ExecutionFailureKind;
|
||||
use common::{transaction::Transaction, ExecutionFailureKind};
|
||||
|
||||
use accounts::{
|
||||
account_core::{Account, AccountAddress},
|
||||
@@ -11,7 +11,7 @@ use accounts::{
|
||||
};
|
||||
use anyhow::Result;
|
||||
use chain_storage::NodeChainStore;
|
||||
use common::transaction::{Transaction, TxKind};
|
||||
use common::transaction::{TransactionBody, TxKind};
|
||||
use config::NodeConfig;
|
||||
use log::info;
|
||||
use sc_core::proofs_circuits::{
|
||||
@@ -246,30 +246,30 @@ impl NodeCore {
|
||||
let vec_public_info: Vec<u64> = vec_values_u64.into_iter().flatten().collect();
|
||||
|
||||
let (tweak, secret_r, commitment) = pedersen_commitment_vec(vec_public_info);
|
||||
let transaction_body = TransactionBody {
|
||||
tx_kind: TxKind::Private,
|
||||
execution_input: vec![],
|
||||
execution_output: vec![],
|
||||
utxo_commitments_spent_hashes: vec![],
|
||||
utxo_commitments_created_hashes: comm
|
||||
.into_iter()
|
||||
.map(|hash_data| hash_data.try_into().unwrap())
|
||||
.collect(),
|
||||
nullifier_created_hashes: vec![],
|
||||
execution_proof_private: sc_core::transaction_payloads_tools::encode_receipt(receipt)
|
||||
.unwrap(),
|
||||
encoded_data: vec![(encoded_data.0, encoded_data.1.to_vec(), tag)],
|
||||
ephemeral_pub_key: eph_pub_key.to_vec(),
|
||||
commitment,
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
};
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
|
||||
Ok((
|
||||
Transaction {
|
||||
tx_kind: TxKind::Private,
|
||||
execution_input: vec![],
|
||||
execution_output: vec![],
|
||||
utxo_commitments_spent_hashes: vec![],
|
||||
utxo_commitments_created_hashes: comm
|
||||
.into_iter()
|
||||
.map(|hash_data| hash_data.try_into().unwrap())
|
||||
.collect(),
|
||||
nullifier_created_hashes: vec![],
|
||||
execution_proof_private: sc_core::transaction_payloads_tools::encode_receipt(
|
||||
receipt,
|
||||
)
|
||||
.unwrap(),
|
||||
encoded_data: vec![(encoded_data.0, encoded_data.1.to_vec(), tag)],
|
||||
ephemeral_pub_key: eph_pub_key.to_vec(),
|
||||
commitment,
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
},
|
||||
Transaction::new(transaction_body, key_to_sign_transaction),
|
||||
result_hash,
|
||||
))
|
||||
}
|
||||
@@ -342,29 +342,30 @@ impl NodeCore {
|
||||
|
||||
let (tweak, secret_r, commitment) = pedersen_commitment_vec(vec_public_info);
|
||||
|
||||
Ok((
|
||||
Transaction {
|
||||
tx_kind: TxKind::Private,
|
||||
execution_input: vec![],
|
||||
execution_output: vec![],
|
||||
utxo_commitments_spent_hashes: vec![],
|
||||
utxo_commitments_created_hashes: comm
|
||||
.into_iter()
|
||||
.map(|hash_data| hash_data.try_into().unwrap())
|
||||
.collect(),
|
||||
nullifier_created_hashes: vec![],
|
||||
execution_proof_private: sc_core::transaction_payloads_tools::encode_receipt(
|
||||
receipt,
|
||||
)
|
||||
let transaction_body = TransactionBody {
|
||||
tx_kind: TxKind::Private,
|
||||
execution_input: vec![],
|
||||
execution_output: vec![],
|
||||
utxo_commitments_spent_hashes: vec![],
|
||||
utxo_commitments_created_hashes: comm
|
||||
.into_iter()
|
||||
.map(|hash_data| hash_data.try_into().unwrap())
|
||||
.collect(),
|
||||
nullifier_created_hashes: vec![],
|
||||
execution_proof_private: sc_core::transaction_payloads_tools::encode_receipt(receipt)
|
||||
.unwrap(),
|
||||
encoded_data,
|
||||
ephemeral_pub_key: eph_pub_key.to_vec(),
|
||||
commitment,
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
},
|
||||
encoded_data,
|
||||
ephemeral_pub_key: eph_pub_key.to_vec(),
|
||||
commitment,
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
};
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
|
||||
Ok((
|
||||
Transaction::new(transaction_body, key_to_sign_transaction),
|
||||
result_hashes,
|
||||
))
|
||||
}
|
||||
@@ -455,29 +456,31 @@ impl NodeCore {
|
||||
|
||||
let (tweak, secret_r, commitment) = pedersen_commitment_vec(vec_public_info);
|
||||
|
||||
Ok((
|
||||
Transaction {
|
||||
tx_kind: TxKind::Private,
|
||||
execution_input: vec![],
|
||||
execution_output: vec![],
|
||||
utxo_commitments_spent_hashes: vec![commitment_in],
|
||||
utxo_commitments_created_hashes: commitments
|
||||
.into_iter()
|
||||
.map(|hash_data| hash_data.try_into().unwrap())
|
||||
.collect(),
|
||||
nullifier_created_hashes: vec![nullifier.try_into().unwrap()],
|
||||
execution_proof_private: sc_core::transaction_payloads_tools::encode_receipt(
|
||||
receipt,
|
||||
)
|
||||
let transaction_body = TransactionBody {
|
||||
tx_kind: TxKind::Private,
|
||||
execution_input: vec![],
|
||||
execution_output: vec![],
|
||||
utxo_commitments_spent_hashes: vec![commitment_in],
|
||||
utxo_commitments_created_hashes: commitments
|
||||
.into_iter()
|
||||
.map(|hash_data| hash_data.try_into().unwrap())
|
||||
.collect(),
|
||||
nullifier_created_hashes: vec![nullifier.try_into().unwrap()],
|
||||
execution_proof_private: sc_core::transaction_payloads_tools::encode_receipt(receipt)
|
||||
.unwrap(),
|
||||
encoded_data,
|
||||
ephemeral_pub_key: eph_pub_key.to_vec(),
|
||||
commitment,
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
},
|
||||
encoded_data,
|
||||
ephemeral_pub_key: eph_pub_key.to_vec(),
|
||||
commitment,
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
};
|
||||
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
|
||||
Ok((
|
||||
Transaction::new(transaction_body, key_to_sign_transaction),
|
||||
utxo_hashes,
|
||||
))
|
||||
}
|
||||
@@ -598,29 +601,31 @@ impl NodeCore {
|
||||
|
||||
let (tweak, secret_r, commitment) = pedersen_commitment_vec(vec_public_info);
|
||||
|
||||
Ok((
|
||||
Transaction {
|
||||
tx_kind: TxKind::Private,
|
||||
execution_input: vec![],
|
||||
execution_output: vec![],
|
||||
utxo_commitments_spent_hashes: commitments_in,
|
||||
utxo_commitments_created_hashes: commitments
|
||||
.into_iter()
|
||||
.map(|hash_data| hash_data.try_into().unwrap())
|
||||
.collect(),
|
||||
nullifier_created_hashes: nullifiers,
|
||||
execution_proof_private: sc_core::transaction_payloads_tools::encode_receipt(
|
||||
receipt,
|
||||
)
|
||||
let transaction_body = TransactionBody {
|
||||
tx_kind: TxKind::Private,
|
||||
execution_input: vec![],
|
||||
execution_output: vec![],
|
||||
utxo_commitments_spent_hashes: commitments_in,
|
||||
utxo_commitments_created_hashes: commitments
|
||||
.into_iter()
|
||||
.map(|hash_data| hash_data.try_into().unwrap())
|
||||
.collect(),
|
||||
nullifier_created_hashes: nullifiers,
|
||||
execution_proof_private: sc_core::transaction_payloads_tools::encode_receipt(receipt)
|
||||
.unwrap(),
|
||||
encoded_data,
|
||||
ephemeral_pub_key: eph_pub_key.to_vec(),
|
||||
commitment,
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
},
|
||||
encoded_data,
|
||||
ephemeral_pub_key: eph_pub_key.to_vec(),
|
||||
commitment,
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
};
|
||||
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
|
||||
Ok((
|
||||
Transaction::new(transaction_body, key_to_sign_transaction),
|
||||
utxo_hashes_receiver,
|
||||
utxo_hashes_not_spent,
|
||||
))
|
||||
@@ -718,35 +723,37 @@ impl NodeCore {
|
||||
|
||||
let (tweak, secret_r, commitment) = pedersen_commitment_vec(vec_public_info);
|
||||
|
||||
let transaction_body = TransactionBody {
|
||||
tx_kind: TxKind::Shielded,
|
||||
execution_input: serde_json::to_vec(&ActionData::SendMoneyShieldedTx(
|
||||
SendMoneyShieldedTx {
|
||||
acc_sender: acc,
|
||||
amount: balance as u128,
|
||||
},
|
||||
))
|
||||
.unwrap(),
|
||||
execution_output: vec![],
|
||||
utxo_commitments_spent_hashes: vec![],
|
||||
utxo_commitments_created_hashes: commitments
|
||||
.into_iter()
|
||||
.map(|hash_data| hash_data.try_into().unwrap())
|
||||
.collect(),
|
||||
nullifier_created_hashes: vec![nullifier.try_into().unwrap()],
|
||||
execution_proof_private: sc_core::transaction_payloads_tools::encode_receipt(receipt)
|
||||
.unwrap(),
|
||||
encoded_data,
|
||||
ephemeral_pub_key: eph_pub_key.to_vec(),
|
||||
commitment,
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
};
|
||||
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
|
||||
Ok((
|
||||
Transaction {
|
||||
tx_kind: TxKind::Shielded,
|
||||
execution_input: serde_json::to_vec(&ActionData::SendMoneyShieldedTx(
|
||||
SendMoneyShieldedTx {
|
||||
acc_sender: acc,
|
||||
amount: balance as u128,
|
||||
},
|
||||
))
|
||||
.unwrap(),
|
||||
execution_output: vec![],
|
||||
utxo_commitments_spent_hashes: vec![],
|
||||
utxo_commitments_created_hashes: commitments
|
||||
.into_iter()
|
||||
.map(|hash_data| hash_data.try_into().unwrap())
|
||||
.collect(),
|
||||
nullifier_created_hashes: vec![nullifier.try_into().unwrap()],
|
||||
execution_proof_private: sc_core::transaction_payloads_tools::encode_receipt(
|
||||
receipt,
|
||||
)
|
||||
.unwrap(),
|
||||
encoded_data,
|
||||
ephemeral_pub_key: eph_pub_key.to_vec(),
|
||||
commitment,
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
},
|
||||
Transaction::new(transaction_body, key_to_sign_transaction),
|
||||
utxo_hashes,
|
||||
))
|
||||
}
|
||||
@@ -809,7 +816,7 @@ impl NodeCore {
|
||||
|
||||
let (tweak, secret_r, commitment) = pedersen_commitment_vec(vec_public_info);
|
||||
|
||||
Ok(Transaction {
|
||||
let transaction_body = TransactionBody {
|
||||
tx_kind: TxKind::Deshielded,
|
||||
execution_input: serde_json::to_vec(&ActionData::SendMoneyDeshieldedTx(
|
||||
SendMoneyDeshieldedTx {
|
||||
@@ -830,7 +837,11 @@ impl NodeCore {
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
})
|
||||
};
|
||||
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
|
||||
Ok(Transaction::new(transaction_body, key_to_sign_transaction))
|
||||
}
|
||||
|
||||
pub async fn send_private_mint_tx(
|
||||
@@ -843,10 +854,10 @@ impl NodeCore {
|
||||
|
||||
let point_before_prove = std::time::Instant::now();
|
||||
let (tx, utxo_hash) = self.mint_utxo_private(acc, amount).await?;
|
||||
tx.log();
|
||||
tx.body().log();
|
||||
let point_after_prove = std::time::Instant::now();
|
||||
|
||||
let commitment_generated_hash = tx.utxo_commitments_created_hashes[0];
|
||||
let commitment_generated_hash = tx.body().utxo_commitments_created_hashes[0];
|
||||
|
||||
let timedelta = (point_after_prove - point_before_prove).as_millis();
|
||||
info!("Mint utxo proof spent {timedelta:?} milliseconds");
|
||||
@@ -871,10 +882,10 @@ impl NodeCore {
|
||||
let (tx, utxo_hashes) = self
|
||||
.mint_utxo_multiple_assets_private(acc, amount, number_of_assets)
|
||||
.await?;
|
||||
tx.log();
|
||||
tx.body().log();
|
||||
let point_after_prove = std::time::Instant::now();
|
||||
|
||||
let commitment_generated_hashes = tx.utxo_commitments_created_hashes.clone();
|
||||
let commitment_generated_hashes = tx.body().utxo_commitments_created_hashes.clone();
|
||||
|
||||
let timedelta = (point_after_prove - point_before_prove).as_millis();
|
||||
info!("Mint utxo proof spent {timedelta:?} milliseconds");
|
||||
@@ -886,49 +897,50 @@ impl NodeCore {
|
||||
))
|
||||
}
|
||||
|
||||
pub async fn send_public_deposit(
|
||||
&self,
|
||||
acc: AccountAddress,
|
||||
amount: u128,
|
||||
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
||||
//Considering proof time, needs to be done before proof
|
||||
let tx_roots = self.get_roots().await;
|
||||
|
||||
let public_context = {
|
||||
let read_guard = self.storage.read().await;
|
||||
|
||||
read_guard.produce_context(acc)
|
||||
};
|
||||
|
||||
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]);
|
||||
|
||||
//Sc 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(&ActionData::MintMoneyPublicTx(MintMoneyPublicTx {
|
||||
acc,
|
||||
amount,
|
||||
}))
|
||||
.unwrap(),
|
||||
commitment,
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
);
|
||||
tx.log();
|
||||
|
||||
Ok(self.sequencer_client.send_tx(tx, tx_roots).await?)
|
||||
}
|
||||
// pub async fn send_public_deposit(
|
||||
// &self,
|
||||
// acc: AccountAddress,
|
||||
// amount: u128,
|
||||
// ) -> Result<SendTxResponse, ExecutionFailureKind> {
|
||||
// //Considering proof time, needs to be done before proof
|
||||
// let tx_roots = self.get_roots().await;
|
||||
//
|
||||
// let public_context = {
|
||||
// let read_guard = self.storage.read().await;
|
||||
//
|
||||
// read_guard.produce_context(acc)
|
||||
// };
|
||||
//
|
||||
// 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]);
|
||||
//
|
||||
// //Sc 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: TransactionBody =
|
||||
// sc_core::transaction_payloads_tools::create_public_transaction_payload(
|
||||
// serde_json::to_vec(&ActionData::MintMoneyPublicTx(MintMoneyPublicTx {
|
||||
// acc,
|
||||
// amount,
|
||||
// }))
|
||||
// .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,
|
||||
@@ -943,7 +955,7 @@ impl NodeCore {
|
||||
let (tx, utxo_hashes) = self
|
||||
.transfer_utxo_private(utxo, comm_hash, receivers)
|
||||
.await?;
|
||||
tx.log();
|
||||
tx.body().log();
|
||||
let point_after_prove = std::time::Instant::now();
|
||||
|
||||
let timedelta = (point_after_prove - point_before_prove).as_millis();
|
||||
@@ -969,7 +981,7 @@ impl NodeCore {
|
||||
let (tx, utxo_hashes_received, utxo_hashes_not_spent) = self
|
||||
.transfer_utxo_multiple_assets_private(utxos, comm_hashes, number_to_send, receiver)
|
||||
.await?;
|
||||
tx.log();
|
||||
tx.body().log();
|
||||
let point_after_prove = std::time::Instant::now();
|
||||
|
||||
let timedelta = (point_after_prove - point_before_prove).as_millis();
|
||||
@@ -995,7 +1007,7 @@ impl NodeCore {
|
||||
let (tx, utxo_hashes) = self
|
||||
.transfer_balance_shielded(acc, amount, receivers)
|
||||
.await?;
|
||||
tx.log();
|
||||
tx.body().log();
|
||||
let point_after_prove = std::time::Instant::now();
|
||||
|
||||
let timedelta = (point_after_prove - point_before_prove).as_millis();
|
||||
@@ -1020,7 +1032,7 @@ impl NodeCore {
|
||||
let tx = self
|
||||
.transfer_utxo_deshielded(utxo, comm_gen_hash, receivers)
|
||||
.await?;
|
||||
tx.log();
|
||||
tx.body().log();
|
||||
let point_after_prove = std::time::Instant::now();
|
||||
|
||||
let timedelta = (point_after_prove - point_before_prove).as_millis();
|
||||
@@ -1154,46 +1166,46 @@ impl NodeCore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn operate_account_deposit_public(
|
||||
&mut self,
|
||||
acc_addr: AccountAddress,
|
||||
amount: u128,
|
||||
) -> Result<(), ExecutionFailureKind> {
|
||||
let old_balance = {
|
||||
let acc_map_read_guard = self.storage.read().await;
|
||||
|
||||
let acc = acc_map_read_guard.acc_map.get(&acc_addr).unwrap();
|
||||
|
||||
acc.balance
|
||||
};
|
||||
|
||||
info!(
|
||||
"Balance of {:?} now is {old_balance:?}",
|
||||
hex::encode(acc_addr)
|
||||
);
|
||||
|
||||
let resp = self.send_public_deposit(acc_addr, amount).await?;
|
||||
info!("Response for public deposit is {resp:?}");
|
||||
|
||||
info!("Awaiting new blocks");
|
||||
tokio::time::sleep(std::time::Duration::from_secs(BLOCK_GEN_DELAY_SECS)).await;
|
||||
|
||||
let new_balance = {
|
||||
let acc_map_read_guard = self.storage.read().await;
|
||||
|
||||
let acc = acc_map_read_guard.acc_map.get(&acc_addr).unwrap();
|
||||
|
||||
acc.balance
|
||||
};
|
||||
|
||||
info!(
|
||||
"Balance of {:?} now is {new_balance:?}, delta is {:?}",
|
||||
hex::encode(acc_addr),
|
||||
new_balance - old_balance
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
// pub async fn operate_account_deposit_public(
|
||||
// &mut self,
|
||||
// acc_addr: AccountAddress,
|
||||
// amount: u128,
|
||||
// ) -> Result<(), ExecutionFailureKind> {
|
||||
// let old_balance = {
|
||||
// let acc_map_read_guard = self.storage.read().await;
|
||||
//
|
||||
// let acc = acc_map_read_guard.acc_map.get(&acc_addr).unwrap();
|
||||
//
|
||||
// acc.balance
|
||||
// };
|
||||
//
|
||||
// info!(
|
||||
// "Balance of {:?} now is {old_balance:?}",
|
||||
// hex::encode(acc_addr)
|
||||
// );
|
||||
//
|
||||
// let resp = self.send_public_deposit(acc_addr, amount).await?;
|
||||
// info!("Response for public deposit is {resp:?}");
|
||||
//
|
||||
// info!("Awaiting new blocks");
|
||||
// tokio::time::sleep(std::time::Duration::from_secs(BLOCK_GEN_DELAY_SECS)).await;
|
||||
//
|
||||
// let new_balance = {
|
||||
// let acc_map_read_guard = self.storage.read().await;
|
||||
//
|
||||
// let acc = acc_map_read_guard.acc_map.get(&acc_addr).unwrap();
|
||||
//
|
||||
// acc.balance
|
||||
// };
|
||||
//
|
||||
// info!(
|
||||
// "Balance of {:?} now is {new_balance:?}, delta is {:?}",
|
||||
// hex::encode(acc_addr),
|
||||
// new_balance - old_balance
|
||||
// );
|
||||
//
|
||||
// Ok(())
|
||||
// }
|
||||
|
||||
pub async fn operate_account_send_shielded_one_receiver(
|
||||
&mut self,
|
||||
@@ -1443,30 +1455,31 @@ impl NodeCore {
|
||||
|
||||
let (tweak, secret_r, commitment) = pedersen_commitment_vec(vec_public_info);
|
||||
|
||||
Ok((
|
||||
Transaction {
|
||||
tx_kind: TxKind::Shielded,
|
||||
execution_input: vec![],
|
||||
execution_output: serde_json::to_vec(&publication).unwrap(),
|
||||
utxo_commitments_spent_hashes: vec![commitment_in],
|
||||
utxo_commitments_created_hashes: commitments
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|hash_data| hash_data.try_into().unwrap())
|
||||
.collect(),
|
||||
nullifier_created_hashes: vec![nullifier.try_into().unwrap()],
|
||||
execution_proof_private: sc_core::transaction_payloads_tools::encode_receipt(
|
||||
receipt,
|
||||
)
|
||||
let transaction_body = TransactionBody {
|
||||
tx_kind: TxKind::Shielded,
|
||||
execution_input: vec![],
|
||||
execution_output: serde_json::to_vec(&publication).unwrap(),
|
||||
utxo_commitments_spent_hashes: vec![commitment_in],
|
||||
utxo_commitments_created_hashes: commitments
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|hash_data| hash_data.try_into().unwrap())
|
||||
.collect(),
|
||||
nullifier_created_hashes: vec![nullifier.try_into().unwrap()],
|
||||
execution_proof_private: sc_core::transaction_payloads_tools::encode_receipt(receipt)
|
||||
.unwrap(),
|
||||
encoded_data,
|
||||
ephemeral_pub_key: eph_pub_key.to_vec(),
|
||||
commitment,
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
},
|
||||
encoded_data,
|
||||
ephemeral_pub_key: eph_pub_key.to_vec(),
|
||||
commitment,
|
||||
tweak,
|
||||
secret_r,
|
||||
sc_addr,
|
||||
state_changes,
|
||||
};
|
||||
let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key();
|
||||
|
||||
Ok((
|
||||
Transaction::new(transaction_body, key_to_sign_transaction),
|
||||
utxo_hashes,
|
||||
))
|
||||
}
|
||||
@@ -1486,13 +1499,13 @@ impl NodeCore {
|
||||
let (tx, utxo_hashes) = self
|
||||
.split_utxo(utxo, comm_hash, receivers, visibility_list)
|
||||
.await?;
|
||||
tx.log();
|
||||
tx.body().log();
|
||||
let point_after_prove = std::time::Instant::now();
|
||||
|
||||
let timedelta = (point_after_prove - point_before_prove).as_millis();
|
||||
info!("Send private utxo proof spent {timedelta:?} milliseconds");
|
||||
|
||||
let commitments = tx.utxo_commitments_created_hashes.clone();
|
||||
let commitments = tx.body().utxo_commitments_created_hashes.clone();
|
||||
|
||||
Ok((
|
||||
self.sequencer_client.send_tx(tx, tx_roots).await?,
|
||||
@@ -1563,20 +1576,8 @@ impl NodeCore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///Deposit balance, make it private
|
||||
pub async fn subscenario_2(&mut self) -> Result<(), ExecutionFailureKind> {
|
||||
let acc_addr = self.create_new_account().await;
|
||||
|
||||
self.operate_account_deposit_public(acc_addr, 100).await?;
|
||||
|
||||
self.operate_account_send_shielded_one_receiver(acc_addr, acc_addr, 100)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///Mint utxo, privately send it to another user
|
||||
pub async fn subscenario_3(&mut self) -> Result<(), ExecutionFailureKind> {
|
||||
pub async fn subscenario_2(&mut self) -> Result<(), ExecutionFailureKind> {
|
||||
let acc_addr = self.create_new_account().await;
|
||||
let acc_addr_rec = self.create_new_account().await;
|
||||
|
||||
@@ -1588,21 +1589,8 @@ impl NodeCore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///Deposit balance, shielded send it to another user
|
||||
pub async fn subscenario_4(&mut self) -> Result<(), ExecutionFailureKind> {
|
||||
let acc_addr = self.create_new_account().await;
|
||||
let acc_addr_rec = self.create_new_account().await;
|
||||
|
||||
self.operate_account_deposit_public(acc_addr, 100).await?;
|
||||
|
||||
self.operate_account_send_shielded_one_receiver(acc_addr, acc_addr_rec, 100)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///Mint utxo, deshielded send it to another user
|
||||
pub async fn subscenario_5(&mut self) -> Result<(), ExecutionFailureKind> {
|
||||
pub async fn subscenario_3(&mut self) -> Result<(), ExecutionFailureKind> {
|
||||
let acc_addr = self.create_new_account().await;
|
||||
let acc_addr_rec = self.create_new_account().await;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user