diff --git a/node_core/src/lib.rs b/node_core/src/lib.rs index 3fced6a..bc42b73 100644 --- a/node_core/src/lib.rs +++ b/node_core/src/lib.rs @@ -398,7 +398,7 @@ impl NodeCore { let accout = acc_map_read_guard.acc_map.get(&utxo.owner).unwrap(); - generate_nullifiers( + let nullifier = generate_nullifiers( &utxo, &accout .key_holder @@ -406,20 +406,19 @@ impl NodeCore { .nullifier_secret_key .to_bytes() .to_vec(), - ) - }; + ); let (resulting_balances, receipt) = prove_send_utxo_deshielded(utxo, receivers); TransactionPayload { tx_kind: TxKind::Deshielded, - execution_input: vec![], - execution_output: serde_json::to_vec(&ActionData::SendMoneyDeshieldedTx( + execution_input: serde_json::to_vec(&ActionData::SendMoneyDeshieldedTx( SendMoneyDeshieldedTx { receiver_data: resulting_balances, }, )) .unwrap(), + execution_output: vec![], utxo_commitments_spent_hashes: vec![commitment_in], utxo_commitments_created_hashes: vec![], nullifier_created_hashes: vec![nullifier.try_into().unwrap()], diff --git a/node_core/src/storage/mod.rs b/node_core/src/storage/mod.rs index 3898932..2fbcbab 100644 --- a/node_core/src/storage/mod.rs +++ b/node_core/src/storage/mod.rs @@ -19,6 +19,8 @@ use storage::{ }; use utxo::utxo_core::UTXO; +use crate::ActionData; + pub mod accounts_store; pub mod block_store; @@ -54,7 +56,37 @@ impl NodeChainStore { pub fn dissect_insert_block(&mut self, block: Block) -> Result<()> { for tx in &block.transactions { - // let public_action = serde_json::from_slice(tx.execution_output); + if !tx.execution_input.is_empty() { + let public_action = serde_json::from_slice::(&tx.execution_input); + + if let Ok(public_action) = public_action { + match public_action { + ActionData::MintMoneyPublicTx(action) => { + let acc_mut = self.acc_map.get_mut(&action.acc); + + if let Some(acc_mut) = acc_mut { + acc_mut.balance += action.amount as u64; + } + }, + ActionData::SendMoneyDeshieldedTx(action) => { + for (balance, acc_addr) in action.receiver_data { + let acc_mut = self.acc_map.get_mut(&acc_addr); + + if let Some(acc_mut) = acc_mut { + acc_mut.balance += balance as u64; + } + } + }, + ActionData::SendMoneyShieldedTx(action) => { + let acc_mut = self.acc_map.get_mut(&action.acc_sender); + + if let Some(acc_mut) = acc_mut { + acc_mut.balance = acc_mut.balance.saturating_sub(action.amount as u64); + } + } + } + } + } self.utxo_commitments_store.add_tx_multiple( tx.utxo_commitments_created_hashes