From c6a4a00fdaa90dc1f9e1760ab5372a8944126d0d Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Fri, 16 May 2025 20:25:23 -0300 Subject: [PATCH] remove utxo tree --- accounts/src/account_core/mod.rs | 5 ++--- node_core/src/chain_storage/mod.rs | 2 +- node_core/src/lib.rs | 16 +++++++--------- node_rpc/src/process.rs | 20 ++++---------------- 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/accounts/src/account_core/mod.rs b/accounts/src/account_core/mod.rs index 6498597..0c7bbdd 100644 --- a/accounts/src/account_core/mod.rs +++ b/accounts/src/account_core/mod.rs @@ -198,7 +198,6 @@ mod tests { let result = account.mark_spent_utxo(utxo_nullifier_map); assert!(result.is_ok()); - assert!(account.utxos.get(&account.address).is_none()); } #[test] @@ -210,7 +209,7 @@ mod tests { let result = account.add_new_utxo_outputs(vec![utxo1.clone(), utxo2.clone()]); assert!(result.is_ok()); - assert_eq!(account.utxos.store.len(), 2); + assert_eq!(account.utxos.len(), 2); } #[test] @@ -230,6 +229,6 @@ mod tests { let result = account.add_asset(asset, amount, false); assert!(result.is_ok()); - assert_eq!(account.utxos.store.len(), 1); + assert_eq!(account.utxos.len(), 1); } } diff --git a/node_core/src/chain_storage/mod.rs b/node_core/src/chain_storage/mod.rs index cfa80b0..3abe0b1 100644 --- a/node_core/src/chain_storage/mod.rs +++ b/node_core/src/chain_storage/mod.rs @@ -125,7 +125,7 @@ impl NodeChainStore { serde_json::from_slice::(&decoded_data_curr_acc); if let Ok(utxo) = decoded_utxo_try { if &utxo.owner == acc_id { - acc.utxos.insert_item(utxo)?; + acc.utxos.insert(utxo.hash, utxo); } } } diff --git a/node_core/src/lib.rs b/node_core/src/lib.rs index 4442112..25be979 100644 --- a/node_core/src/lib.rs +++ b/node_core/src/lib.rs @@ -1062,7 +1062,7 @@ impl NodeCore { let acc = write_guard.acc_map.get_mut(&acc_addr).unwrap(); - acc.utxos.get_item(new_utxo_hash)?.unwrap().clone() + acc.utxos.get(&new_utxo_hash).unwrap().clone() }; new_utxo.log(); @@ -1103,8 +1103,7 @@ impl NodeCore { let new_utxo = acc .utxos - .get_item(new_utxo_hash) - .unwrap() + .get(&new_utxo_hash) .unwrap() .clone(); @@ -1238,7 +1237,7 @@ impl NodeCore { let acc = write_guard.acc_map.get_mut(&acc_addr_rec).unwrap(); acc.log(); - acc.utxos.get_item(new_utxo_hash)?.unwrap().clone() + acc.utxos.get(&new_utxo_hash).unwrap().clone() }; new_utxo.log(); info!( @@ -1278,7 +1277,7 @@ impl NodeCore { let acc = write_guard.acc_map.get_mut(&acc_addr_rec).unwrap(); acc.log(); - acc.utxos.get_item(new_utxo_hash)?.unwrap().clone() + acc.utxos.get(&new_utxo_hash).unwrap().clone() }; new_utxo.log(); info!( @@ -1323,7 +1322,7 @@ impl NodeCore { let acc = write_guard.acc_map.get_mut(&acc_addr_rec).unwrap(); acc.log(); - let new_utxo = acc.utxos.get_item(new_utxo_hash)?.unwrap().clone(); + let new_utxo = acc.utxos.get(&new_utxo_hash).unwrap().clone(); new_utxo.log(); info!( @@ -1343,7 +1342,7 @@ impl NodeCore { let acc = write_guard.acc_map.get_mut(&acc_addr).unwrap(); acc.log(); - let new_utxo = acc.utxos.get_item(new_utxo_hash)?.unwrap().clone(); + let new_utxo = acc.utxos.get(&new_utxo_hash).unwrap().clone(); new_utxo.log(); info!( @@ -1558,8 +1557,7 @@ impl NodeCore { let new_utxo = acc .utxos - .get_item(new_utxo_hash) - .unwrap() + .get(&new_utxo_hash) .unwrap() .clone(); new_utxo.log(); diff --git a/node_rpc/src/process.rs b/node_rpc/src/process.rs index 59837ad..f4937e9 100644 --- a/node_rpc/src/process.rs +++ b/node_rpc/src/process.rs @@ -269,10 +269,7 @@ impl JsonHandler { let utxo = acc .utxos - .get_item(utxo_hash) - .map_err(|err| { - RpcError::new_internal_error(None, &format!("DB fetch failure {err:?}")) - })? + .get(&utxo_hash) .ok_or(RpcError::new_internal_error( None, "UTXO does not exist in the tree", @@ -513,10 +510,7 @@ impl JsonHandler { .ok_or(RpcError::new_internal_error(None, ACCOUNT_NOT_FOUND))?; acc.utxos - .get_item(utxo_hash) - .map_err(|err| { - RpcError::new_internal_error(None, &format!("DB fetch failure {err:?}")) - })? + .get(&utxo_hash) .ok_or(RpcError::new_internal_error( None, "UTXO does not exist in tree", @@ -648,10 +642,7 @@ impl JsonHandler { .ok_or(RpcError::new_internal_error(None, ACCOUNT_NOT_FOUND))?; acc.utxos - .get_item(utxo_hash) - .map_err(|err| { - RpcError::new_internal_error(None, &format!("DB fetch failure {err:?}")) - })? + .get(&utxo_hash) .ok_or(RpcError::new_internal_error( None, "UTXO does not exist in tree", @@ -736,10 +727,7 @@ impl JsonHandler { .ok_or(RpcError::new_internal_error(None, ACCOUNT_NOT_FOUND))?; acc.utxos - .get_item(utxo_hash) - .map_err(|err| { - RpcError::new_internal_error(None, &format!("DB fetch failure {err:?}")) - })? + .get(&utxo_hash) .ok_or(RpcError::new_internal_error( None, "UTXO does not exist in tree",