From afbc7e5a7647e49e8c8c73e2c1c1e5a67858cd85 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Mon, 10 Oct 2022 17:42:19 -0700 Subject: [PATCH 01/40] Turn code line into code block --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f7dff2b3..4c811be91 100644 --- a/README.md +++ b/README.md @@ -407,10 +407,18 @@ See [CONTRIBUTING](./CONTRIBUTING.md). To add or edit tables: 1. Ensure that you have `diesel_cli` installed and that it is using the current sqlite - version: `cargo install --git="https://github.com/mobilecoinofficial/diesel" --rev="22a4a4b973db2b7aadaf088b3279dbbe52176896" diesel_cli --no-default-features --features sqlite` + version: + + ``` + cargo install --git="https://github.com/mobilecoinofficial/diesel" --rev="22a4a4b973db2b7aadaf088b3279dbbe52176896" diesel_cli --no-default-features --features sqlite + ``` + 1. `cd full-service` + 1. Create a migration with `diesel migration generate ` + 1. Edit the migrations//up.sql and down.sql. + 1. Run the migration with `diesel migration run --database-url /tmp/db.db`, and test delete with `diesel migration redo --database-url /tmp/db.db` From d61f99fd660b46f4c156e1e8009c862058d4ef40 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Mon, 10 Oct 2022 20:03:15 -0700 Subject: [PATCH 02/40] Explicitly gitignore the sgx libraries downloaded when developing for linux --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fe344c864..4dee8c010 100644 --- a/.gitignore +++ b/.gitignore @@ -78,4 +78,4 @@ dbml-error.log __pycache__ -/tools/*.bin \ No newline at end of file +*sgx_linux_x64_sdk_2.9.101.2.bin \ No newline at end of file From 7df9ac792d2794723737ec26af3963c108704464 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Mon, 10 Oct 2022 22:15:27 -0700 Subject: [PATCH 03/40] First draft of migration --- .../migrations/2022-10-11-050914_drop_txo_from_txos/down.sql | 1 + .../migrations/2022-10-11-050914_drop_txo_from_txos/up.sql | 1 + 2 files changed, 2 insertions(+) create mode 100644 full-service/migrations/2022-10-11-050914_drop_txo_from_txos/down.sql create mode 100644 full-service/migrations/2022-10-11-050914_drop_txo_from_txos/up.sql diff --git a/full-service/migrations/2022-10-11-050914_drop_txo_from_txos/down.sql b/full-service/migrations/2022-10-11-050914_drop_txo_from_txos/down.sql new file mode 100644 index 000000000..9e12eecfa --- /dev/null +++ b/full-service/migrations/2022-10-11-050914_drop_txo_from_txos/down.sql @@ -0,0 +1 @@ +ALTER TABLE txos ADD COLUMN txo BLOB NOT NULL; \ No newline at end of file diff --git a/full-service/migrations/2022-10-11-050914_drop_txo_from_txos/up.sql b/full-service/migrations/2022-10-11-050914_drop_txo_from_txos/up.sql new file mode 100644 index 000000000..87c621e79 --- /dev/null +++ b/full-service/migrations/2022-10-11-050914_drop_txo_from_txos/up.sql @@ -0,0 +1 @@ +ALTER TABLE txos DROP COLUMN txo; \ No newline at end of file From f2fcf0d33b0cb5deeb73e6c3047f97317b425b19 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Mon, 10 Oct 2022 22:27:53 -0700 Subject: [PATCH 04/40] Update README diesel hash to match the one we depend on formally in Cargo.toml --- Cargo.toml | 1 + README.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9821c7567..ea82b1e4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,4 +57,5 @@ x25519-dalek = { git = "https://github.com/mobilecoinfoundation/x25519-dalek.git # Override diesel dependency with our fork, in order to use a version of libsqlite3-sys that has bundled-sqlcipher. This allows us to # statically link SQLite. +# If updating here, also update in README diesel = { git = "https://github.com/mobilecoinofficial/diesel", rev = "026f6379715d27c8be48396e5ca9059f4a263198" } diff --git a/README.md b/README.md index 4c811be91..a06b1968a 100644 --- a/README.md +++ b/README.md @@ -407,10 +407,10 @@ See [CONTRIBUTING](./CONTRIBUTING.md). To add or edit tables: 1. Ensure that you have `diesel_cli` installed and that it is using the current sqlite - version: + version: ``` - cargo install --git="https://github.com/mobilecoinofficial/diesel" --rev="22a4a4b973db2b7aadaf088b3279dbbe52176896" diesel_cli --no-default-features --features sqlite + cargo install --git="https://github.com/mobilecoinofficial/diesel" --rev="026f6379715d27c8be48396e5ca9059f4a263198" diesel_cli --no-default-features --features sqlite ``` 1. `cd full-service` From 4a057f9dfa90c8a27884910202476a13433f516a Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Mon, 17 Oct 2022 12:07:25 -0700 Subject: [PATCH 05/40] Probably don't need the down path --- .../migrations/2022-10-11-050914_drop_txo_from_txos/down.sql | 1 - 1 file changed, 1 deletion(-) delete mode 100644 full-service/migrations/2022-10-11-050914_drop_txo_from_txos/down.sql diff --git a/full-service/migrations/2022-10-11-050914_drop_txo_from_txos/down.sql b/full-service/migrations/2022-10-11-050914_drop_txo_from_txos/down.sql deleted file mode 100644 index 9e12eecfa..000000000 --- a/full-service/migrations/2022-10-11-050914_drop_txo_from_txos/down.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE txos ADD COLUMN txo BLOB NOT NULL; \ No newline at end of file From 796c4bc54968d0e13495c722b3ad84f379ddc487 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Mon, 17 Oct 2022 13:02:30 -0700 Subject: [PATCH 06/40] DOCS: update upgrade scenario notes --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a06b1968a..93ce951c5 100644 --- a/README.md +++ b/README.md @@ -419,8 +419,9 @@ To add or edit tables: 1. Edit the migrations//up.sql and down.sql. -1. Run the migration with `diesel migration run --database-url /tmp/db.db`, and test delete - with `diesel migration redo --database-url /tmp/db.db` +1. Make a copy of db you want to run the migration against for back up (ie. ~/.mobilecoin/test/wallet-db/wallet.db) + +1. Build and run Full Service against network of your choice! Note that full-service/diesel.toml provides the path to the schema.rs which will be updated in a migration. From d3b189b6984fdb600874161793100eb6b1ceb9f9 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Mon, 17 Oct 2022 13:34:13 -0700 Subject: [PATCH 07/40] Revert "Probably don't need the down path" This reverts commit 4a057f9dfa90c8a27884910202476a13433f516a. --- .../migrations/2022-10-11-050914_drop_txo_from_txos/down.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 full-service/migrations/2022-10-11-050914_drop_txo_from_txos/down.sql diff --git a/full-service/migrations/2022-10-11-050914_drop_txo_from_txos/down.sql b/full-service/migrations/2022-10-11-050914_drop_txo_from_txos/down.sql new file mode 100644 index 000000000..9e12eecfa --- /dev/null +++ b/full-service/migrations/2022-10-11-050914_drop_txo_from_txos/down.sql @@ -0,0 +1 @@ +ALTER TABLE txos ADD COLUMN txo BLOB NOT NULL; \ No newline at end of file From d526755dae1d80336e629919dfe78ec0f4caa243 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Mon, 17 Oct 2022 13:48:33 -0700 Subject: [PATCH 08/40] DOCS: update diesel migration instructions --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 93ce951c5..51664f3fc 100644 --- a/README.md +++ b/README.md @@ -415,13 +415,15 @@ To add or edit tables: 1. `cd full-service` +1. Create an empty version of the base db `diesel migration run --database-url $MIGRATION_TEST_DB` + 1. Create a migration with `diesel migration generate ` 1. Edit the migrations//up.sql and down.sql. -1. Make a copy of db you want to run the migration against for back up (ie. ~/.mobilecoin/test/wallet-db/wallet.db) +1. Run the migration with `diesel migration run --database-url $MIGRATION_TEST_DB`, and test the + inverse operation with `diesel migration redo --database-url $MIGRATION_TEST_DB` -1. Build and run Full Service against network of your choice! Note that full-service/diesel.toml provides the path to the schema.rs which will be updated in a migration. From 0f2922f3cff6a161072a2eff941557f15c09c771 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Mon, 17 Oct 2022 13:59:19 -0700 Subject: [PATCH 09/40] WIP: Remove TXO from schema.rs --- full-service/src/db/schema.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/full-service/src/db/schema.rs b/full-service/src/db/schema.rs index accc5b36c..1037be6f8 100644 --- a/full-service/src/db/schema.rs +++ b/full-service/src/db/schema.rs @@ -71,7 +71,6 @@ table! { target_key -> Binary, public_key -> Binary, e_fog_hint -> Binary, - txo -> Binary, subaddress_index -> Nullable, key_image -> Nullable, received_block_index -> Nullable, From aad06853b6c6e95973781c67ba7f9a032ce4982d Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Mon, 17 Oct 2022 14:11:16 -0700 Subject: [PATCH 10/40] WIP: remove txo field from db related structs --- full-service/src/db/models.rs | 3 --- full-service/src/db/txo.rs | 2 -- 2 files changed, 5 deletions(-) diff --git a/full-service/src/db/models.rs b/full-service/src/db/models.rs index 5137522f4..e7f7947eb 100644 --- a/full-service/src/db/models.rs +++ b/full-service/src/db/models.rs @@ -74,8 +74,6 @@ pub struct Txo { pub public_key: Vec, /// The serialized e_fog_hint of the TxOut. pub e_fog_hint: Vec, - /// The serialized TxOut. - pub txo: Vec, /// The receiving subaddress, if known. pub subaddress_index: Option, /// Pre-computed key image for this Txo, or None if the Txo is orphaned. @@ -104,7 +102,6 @@ pub struct NewTxo<'a> { pub target_key: &'a [u8], pub public_key: &'a [u8], pub e_fog_hint: &'a [u8], - pub txo: &'a [u8], pub subaddress_index: Option, pub key_image: Option<&'a [u8]>, pub received_block_index: Option, diff --git a/full-service/src/db/txo.rs b/full-service/src/db/txo.rs index f95668565..9d4495bb9 100644 --- a/full-service/src/db/txo.rs +++ b/full-service/src/db/txo.rs @@ -372,7 +372,6 @@ impl TxoModel for Txo { target_key: &mc_util_serial::encode(&txo.target_key), public_key: &mc_util_serial::encode(&txo.public_key), e_fog_hint: &mc_util_serial::encode(&txo.e_fog_hint), - txo: &mc_util_serial::encode(&txo), subaddress_index: subaddress_index.map(|i| i as i64), key_image: key_image_bytes.as_deref(), received_block_index: Some(received_block_index as i64), @@ -411,7 +410,6 @@ impl TxoModel for Txo { target_key: &mc_util_serial::encode(&output_txo.tx_out.target_key), public_key: &mc_util_serial::encode(&output_txo.tx_out.public_key), e_fog_hint: &mc_util_serial::encode(&output_txo.tx_out.e_fog_hint), - txo: &mc_util_serial::encode(&output_txo.tx_out), subaddress_index: None, key_image: None, received_block_index: None, From ce757ffa24e3195ff3e0e8b436256b2f2e6c23cc Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Mon, 17 Oct 2022 14:41:28 -0700 Subject: [PATCH 11/40] DOCS: update readme --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 51664f3fc..fe49747f3 100644 --- a/README.md +++ b/README.md @@ -424,6 +424,16 @@ To add or edit tables: 1. Run the migration with `diesel migration run --database-url $MIGRATION_TEST_DB`, and test the inverse operation with `diesel migration redo --database-url $MIGRATION_TEST_DB` +Make sure that the following is still present in `schema.rs` before commiting changes. +``` +table! { + __diesel_schema_migrations(version) { + version -> Text, + run_on -> Timestamp, + } +} +``` + Note that full-service/diesel.toml provides the path to the schema.rs which will be updated in a migration. From 1293dd57a57ef8c6f1306faa4e23a76651dde238 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Tue, 18 Oct 2022 10:09:13 -0700 Subject: [PATCH 12/40] WIP: Use the txo id to get the txo from the ledger service --- full-service/src/json_rpc/v2/api/wallet.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/full-service/src/json_rpc/v2/api/wallet.rs b/full-service/src/json_rpc/v2/api/wallet.rs index cec768ed5..eed1117b9 100644 --- a/full-service/src/json_rpc/v2/api/wallet.rs +++ b/full-service/src/json_rpc/v2/api/wallet.rs @@ -442,9 +442,19 @@ where ) .map_err(format_error)?; - let unverified_txos_encoded: Vec = unverified_txos + + let unverified_tx_results : Result, JsonRPCError>= unverified_txos + .iter() + .map(|(txo, _)| -> Result{ + service.get_txo_object(&txo.id).map_err(format_error) + }) + .collect::, JsonRPCError>>(); + + unverified_tx_results?; + + let unverified_txos_encoded : Vec= unverified_tx_results.unwrap() .iter() - .map(|(txo, _)| hex::encode(&txo.txo)) + .map(|txo_obj| hex::encode(&mc_util_serial::encode(txo_obj))) .collect(); JsonCommandResponse::create_view_only_account_sync_request { From c8da0c056e13d2cabda072067f424b2c8b5ae577 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Tue, 18 Oct 2022 11:00:49 -0700 Subject: [PATCH 13/40] WIP:get ledger.rs to get a txo from the txo id --- full-service/src/service/ledger.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/full-service/src/service/ledger.rs b/full-service/src/service/ledger.rs index 509f21031..6ee79ce24 100644 --- a/full-service/src/service/ledger.rs +++ b/full-service/src/service/ledger.rs @@ -176,8 +176,9 @@ where fn get_txo_object(&self, txo_id_hex: &str) -> Result { let conn = self.get_conn()?; let txo_details = Txo::get(txo_id_hex, &conn)?; - - let txo: TxOut = mc_util_serial::decode(&txo_details.txo)?; + let cristretto = txo_details.public_key()?; + let txo_i = self.ledger_db.get_tx_out_index_by_public_key(&cristretto)?; + let txo = self.ledger_db.get_tx_out_by_index(txo_i)?; Ok(txo) } From 2a40b698cb374e82a97d22113bcf0df8a77bc33c Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Tue, 18 Oct 2022 11:14:55 -0700 Subject: [PATCH 14/40] WIP: use ledger to get the txo --- full-service/src/service/transaction_builder.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/full-service/src/service/transaction_builder.rs b/full-service/src/service/transaction_builder.rs index 7f76e420f..9bbfd5d18 100644 --- a/full-service/src/service/transaction_builder.rs +++ b/full-service/src/service/transaction_builder.rs @@ -277,7 +277,9 @@ impl WalletTransactionBuilder { .inputs .iter() .map(|utxo| { - let txo: TxOut = mc_util_serial::decode(&utxo.txo)?; + let cristretto = utxo.public_key()?; + let txo_i = self.ledger_db.get_tx_out_index_by_public_key(&cristretto)?; + let txo = self.ledger_db.get_tx_out_by_index(txo_i)?; self.ledger_db.get_tx_out_index_by_hash(&txo.hash()) }) .collect::, mc_ledger_db::Error>>()?; @@ -293,7 +295,9 @@ impl WalletTransactionBuilder { let excluded_tx_out_indices: Vec = inputs_and_proofs .iter() .map(|(utxo, _membership_proof)| { - let txo: TxOut = mc_util_serial::decode(&utxo.txo)?; + let cristretto = utxo.public_key()?; + let txo_i = self.ledger_db.get_tx_out_index_by_public_key(&cristretto)?; + let txo = self.ledger_db.get_tx_out_by_index(txo_i)?; self.ledger_db .get_tx_out_index_by_hash(&txo.hash()) .map_err(WalletTransactionBuilderError::LedgerDB) @@ -321,8 +325,9 @@ impl WalletTransactionBuilder { let subaddress_index = utxo.subaddress_index.ok_or_else(|| { WalletTransactionBuilderError::CannotUseOrphanedTxoAsInput(utxo.id.clone()) })?; - - let db_tx_out: TxOut = mc_util_serial::decode(&utxo.txo)?; + let cristretto = utxo.public_key()?; + let txo_i = self.ledger_db.get_tx_out_index_by_public_key(&cristretto)?; + let db_tx_out = self.ledger_db.get_tx_out_by_index(txo_i)?; let (mut ring, mut membership_proofs) = rings_and_proofs .pop() From c40e690abd91d9f5ed004ad86f44bd3202133e8d Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Tue, 18 Oct 2022 11:15:26 -0700 Subject: [PATCH 15/40] Fix some unwrapping issues --- full-service/src/json_rpc/v2/api/wallet.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/full-service/src/json_rpc/v2/api/wallet.rs b/full-service/src/json_rpc/v2/api/wallet.rs index eed1117b9..2016d2d15 100644 --- a/full-service/src/json_rpc/v2/api/wallet.rs +++ b/full-service/src/json_rpc/v2/api/wallet.rs @@ -450,9 +450,9 @@ where }) .collect::, JsonRPCError>>(); - unverified_tx_results?; + let unverified_tx_results = unverified_tx_results?; - let unverified_txos_encoded : Vec= unverified_tx_results.unwrap() + let unverified_txos_encoded : Vec= unverified_tx_results .iter() .map(|txo_obj| hex::encode(&mc_util_serial::encode(txo_obj))) .collect(); From 09b43d23d4aebf4d252474f3f362df3789fdb216 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Tue, 18 Oct 2022 12:46:02 -0700 Subject: [PATCH 16/40] REFACTOR: inline variables --- full-service/src/service/ledger.rs | 4 +--- full-service/src/service/transaction_builder.rs | 12 +++--------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/full-service/src/service/ledger.rs b/full-service/src/service/ledger.rs index 6ee79ce24..a85db6ea0 100644 --- a/full-service/src/service/ledger.rs +++ b/full-service/src/service/ledger.rs @@ -176,9 +176,7 @@ where fn get_txo_object(&self, txo_id_hex: &str) -> Result { let conn = self.get_conn()?; let txo_details = Txo::get(txo_id_hex, &conn)?; - let cristretto = txo_details.public_key()?; - let txo_i = self.ledger_db.get_tx_out_index_by_public_key(&cristretto)?; - let txo = self.ledger_db.get_tx_out_by_index(txo_i)?; + let txo = self.ledger_db.get_tx_out_by_index(self.ledger_db.get_tx_out_index_by_public_key(&txo_details.public_key()?)?)?; Ok(txo) } diff --git a/full-service/src/service/transaction_builder.rs b/full-service/src/service/transaction_builder.rs index 9bbfd5d18..34695ad8a 100644 --- a/full-service/src/service/transaction_builder.rs +++ b/full-service/src/service/transaction_builder.rs @@ -277,9 +277,7 @@ impl WalletTransactionBuilder { .inputs .iter() .map(|utxo| { - let cristretto = utxo.public_key()?; - let txo_i = self.ledger_db.get_tx_out_index_by_public_key(&cristretto)?; - let txo = self.ledger_db.get_tx_out_by_index(txo_i)?; + let txo = self.ledger_db.get_tx_out_by_index(self.ledger_db.get_tx_out_index_by_public_key(&utxo.public_key()?)?)?; self.ledger_db.get_tx_out_index_by_hash(&txo.hash()) }) .collect::, mc_ledger_db::Error>>()?; @@ -295,9 +293,7 @@ impl WalletTransactionBuilder { let excluded_tx_out_indices: Vec = inputs_and_proofs .iter() .map(|(utxo, _membership_proof)| { - let cristretto = utxo.public_key()?; - let txo_i = self.ledger_db.get_tx_out_index_by_public_key(&cristretto)?; - let txo = self.ledger_db.get_tx_out_by_index(txo_i)?; + let txo = self.ledger_db.get_tx_out_by_index(self.ledger_db.get_tx_out_index_by_public_key(&utxo.public_key()?)?)?; self.ledger_db .get_tx_out_index_by_hash(&txo.hash()) .map_err(WalletTransactionBuilderError::LedgerDB) @@ -325,9 +321,7 @@ impl WalletTransactionBuilder { let subaddress_index = utxo.subaddress_index.ok_or_else(|| { WalletTransactionBuilderError::CannotUseOrphanedTxoAsInput(utxo.id.clone()) })?; - let cristretto = utxo.public_key()?; - let txo_i = self.ledger_db.get_tx_out_index_by_public_key(&cristretto)?; - let db_tx_out = self.ledger_db.get_tx_out_by_index(txo_i)?; + let db_tx_out = self.ledger_db.get_tx_out_by_index(self.ledger_db.get_tx_out_index_by_public_key(&utxo.public_key()?)?)?; let (mut ring, mut membership_proofs) = rings_and_proofs .pop() From f3e9535a260733ae9c683924ae3fa8a21ae056d3 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Tue, 18 Oct 2022 14:03:50 -0700 Subject: [PATCH 17/40] Fix compiler errors for tests --- full-service/src/db/transaction_log.rs | 11 ++++++----- full-service/src/db/txo.rs | 1 - full-service/src/service/receipt.rs | 8 ++++---- full-service/src/test_utils.rs | 23 +++++++++++++++-------- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/full-service/src/db/transaction_log.rs b/full-service/src/db/transaction_log.rs index 6e7cabc7c..e1d6e8429 100644 --- a/full-service/src/db/transaction_log.rs +++ b/full-service/src/db/transaction_log.rs @@ -589,7 +589,7 @@ mod tests { }, test_utils::{ add_block_from_transaction_log, add_block_with_tx_outs, builder_for_random_recipient, - get_resolver_factory, get_test_ledger, manually_sync_account, + get_resolver_factory, get_test_ledger, get_tx_out_by_public_key,manually_sync_account, random_account_with_seed_values, WalletDbTestContext, MOB, }, util::b58::b58_encode_public_address, @@ -1123,14 +1123,15 @@ mod tests { assert_eq!(change_details.value as u64, 3 * MOB - Mob::MINIMUM_FEE); assert_eq!(change_details.subaddress_index, None); + let txos = [ + get_tx_out_by_public_key(&ledger_db, &change_details.public_key().unwrap()), + get_tx_out_by_public_key(&ledger_db, &output_details.public_key().unwrap()) + ]; // Now - we will add the spent Txos, outputs, and change to the ledger, so we // can scan and verify add_block_with_tx_outs( &mut ledger_db, - &[ - mc_util_serial::decode(&change_details.txo).unwrap(), - mc_util_serial::decode(&output_details.txo).unwrap(), - ], + &txos, &[ mc_util_serial::decode(&input_details0.key_image.unwrap()).unwrap(), mc_util_serial::decode(&input_details1.key_image.unwrap()).unwrap(), diff --git a/full-service/src/db/txo.rs b/full-service/src/db/txo.rs index 9d4495bb9..ac459506a 100644 --- a/full-service/src/db/txo.rs +++ b/full-service/src/db/txo.rs @@ -1507,7 +1507,6 @@ mod tests { target_key: mc_util_serial::encode(&for_alice_txo.target_key), public_key: mc_util_serial::encode(&for_alice_txo.public_key), e_fog_hint: mc_util_serial::encode(&for_alice_txo.e_fog_hint), - txo: mc_util_serial::encode(&for_alice_txo), subaddress_index: Some(0), key_image: Some(mc_util_serial::encode(&for_alice_key_image)), received_block_index: Some(12), diff --git a/full-service/src/service/receipt.rs b/full-service/src/service/receipt.rs index 4ab431eef..d0a91ff01 100644 --- a/full-service/src/service/receipt.rs +++ b/full-service/src/service/receipt.rs @@ -296,8 +296,8 @@ mod tests { txo::TxoService, }, test_utils::{ - add_block_to_ledger_db, add_block_with_tx, get_test_ledger, manually_sync_account, - setup_wallet_service, MOB, + add_block_to_ledger_db, add_block_with_tx, get_test_ledger, get_tx_out_by_public_key, + manually_sync_account, setup_wallet_service, MOB, }, util::b58::b58_encode_public_address, }; @@ -477,8 +477,8 @@ mod tests { .expect("Could not decode pubkey"); assert_eq!(receipt.public_key, txo_pubkey); assert_eq!(receipt.tombstone_block, 23); // Ledger seeded with 12 blocks at tx construction, then one appended + 10 - let txo: TxOut = - mc_util_serial::decode(&txos_and_statuses[0].0.txo).expect("Could not decode txo"); + let public_key = txos_and_statuses[0].0.public_key().expect("Could not get CompressedRistrettoPublic from txo"); + let txo: TxOut = get_tx_out_by_public_key(&ledger_db, &public_key); assert_eq!(&receipt.amount, txo.get_masked_amount().unwrap()); assert_eq!(receipt.confirmation, confirmations[0].confirmation); } diff --git a/full-service/src/test_utils.rs b/full-service/src/test_utils.rs index 31d81b4ae..51771a1d4 100644 --- a/full-service/src/test_utils.rs +++ b/full-service/src/test_utils.rs @@ -29,7 +29,7 @@ use mc_connection::{Connection, ConnectionManager, HardcodedCredentialsProvider, use mc_connection_test_utils::{test_client_uri, MockBlockchainConnection}; use mc_consensus_enclave_api::FeeMap; use mc_consensus_scp::QuorumSet; -use mc_crypto_keys::{RistrettoPrivate, RistrettoPublic}; +use mc_crypto_keys::{CompressedRistrettoPublic, RistrettoPrivate, RistrettoPublic}; use mc_crypto_rand::{CryptoRng, RngCore}; use mc_fog_report_validation::{FullyValidatedFogPubkey, MockFogPubkeyResolver}; use mc_ledger_db::{Ledger, LedgerDB}; @@ -257,6 +257,14 @@ pub fn add_block_with_tx( append_test_block(ledger_db, block_contents, rng) } +pub fn get_tx_out_by_public_key( + ledger_db: &LedgerDB, + public_key : &CompressedRistrettoPublic, + +) -> TxOut{ + ledger_db.get_tx_out_by_index(ledger_db.get_tx_out_index_by_public_key(public_key).unwrap()).unwrap() +} + pub fn add_block_from_transaction_log( ledger_db: &mut LedgerDB, conn: &PooledConnection>, @@ -269,7 +277,9 @@ pub fn add_block_from_transaction_log( output_txos.append(&mut associated_txos.change.clone()); let outputs: Vec = output_txos .iter() - .map(|(txo, _)| mc_util_serial::decode(&txo.txo).unwrap()) + .map(|(txo, _)| { + get_tx_out_by_public_key(ledger_db, &txo.public_key().unwrap()) + }) .collect(); let input_txos: Vec = associated_txos.inputs.clone(); @@ -365,12 +375,9 @@ pub fn add_block_with_db_txos( let outputs: Vec = output_txo_ids .iter() .map(|txo_id_hex| { - mc_util_serial::decode( - &Txo::get(&txo_id_hex.to_string(), &wallet_db.get_conn().unwrap()) - .unwrap() - .txo, - ) - .unwrap() + let txo = &Txo::get(&txo_id_hex.to_string(), &wallet_db.get_conn().unwrap()) + .unwrap(); + ledger_db.get_tx_out_by_index(ledger_db.get_tx_out_index_by_public_key(&txo.public_key().unwrap()).unwrap()).unwrap() }) .collect(); From c77e65e6a2180f10fc34cf1bc9a10e21eddbd318 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 10:53:25 -0700 Subject: [PATCH 18/40] Fix one test --- full-service/src/db/transaction_log.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/full-service/src/db/transaction_log.rs b/full-service/src/db/transaction_log.rs index e1d6e8429..ee9910511 100644 --- a/full-service/src/db/transaction_log.rs +++ b/full-service/src/db/transaction_log.rs @@ -1123,15 +1123,14 @@ mod tests { assert_eq!(change_details.value as u64, 3 * MOB - Mob::MINIMUM_FEE); assert_eq!(change_details.subaddress_index, None); - let txos = [ - get_tx_out_by_public_key(&ledger_db, &change_details.public_key().unwrap()), - get_tx_out_by_public_key(&ledger_db, &output_details.public_key().unwrap()) - ]; // Now - we will add the spent Txos, outputs, and change to the ledger, so we // can scan and verify add_block_with_tx_outs( &mut ledger_db, - &txos, + &[ + tx_proposal.change_txos[0].tx_out.clone(), + tx_proposal.payload_txos[0].tx_out.clone(), + ], &[ mc_util_serial::decode(&input_details0.key_image.unwrap()).unwrap(), mc_util_serial::decode(&input_details1.key_image.unwrap()).unwrap(), From cd64faed937a01e53a6757cf0a420aa327104bf1 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 14:50:31 -0700 Subject: [PATCH 19/40] Move get_tx_out_by_public_key to ledger.rs --- full-service/src/service/ledger.rs | 9 ++++++++- full-service/src/service/transaction_builder.rs | 1 + full-service/src/test_utils.rs | 9 +-------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/full-service/src/service/ledger.rs b/full-service/src/service/ledger.rs index a85db6ea0..d5dddcec2 100644 --- a/full-service/src/service/ledger.rs +++ b/full-service/src/service/ledger.rs @@ -17,7 +17,7 @@ use mc_connection::{ }; use mc_crypto_keys::CompressedRistrettoPublic; use mc_fog_report_validation::FogPubkeyResolver; -use mc_ledger_db::Ledger; +use mc_ledger_db::{Ledger, LedgerDB}; use mc_ledger_sync::NetworkState; use mc_transaction_core::{ ring_signature::KeyImage, @@ -294,3 +294,10 @@ where Ok(self.ledger_db.get_block_index_by_tx_out_index(index)?) } } + +pub fn get_tx_out_by_public_key( + ledger_db: &LedgerDB, + public_key : &CompressedRistrettoPublic, +) -> TxOut{ + ledger_db.get_tx_out_by_index(ledger_db.get_tx_out_index_by_public_key(public_key).unwrap()).unwrap() +} diff --git a/full-service/src/service/transaction_builder.rs b/full-service/src/service/transaction_builder.rs index 34695ad8a..ddaec77e3 100644 --- a/full-service/src/service/transaction_builder.rs +++ b/full-service/src/service/transaction_builder.rs @@ -18,6 +18,7 @@ use crate::{ }, error::WalletTransactionBuilderError, service::transaction::TransactionMemo, + service::ledger::get_tx_out_by_public_key, }; use mc_account_keys::PublicAddress; use mc_common::HashSet; diff --git a/full-service/src/test_utils.rs b/full-service/src/test_utils.rs index 51771a1d4..1a1aca89b 100644 --- a/full-service/src/test_utils.rs +++ b/full-service/src/test_utils.rs @@ -12,6 +12,7 @@ use crate::{ service::{ sync::sync_account, transaction::TransactionMemo, transaction_builder::WalletTransactionBuilder, + ledger::get_tx_out_by_public_key, }, WalletService, }; @@ -257,14 +258,6 @@ pub fn add_block_with_tx( append_test_block(ledger_db, block_contents, rng) } -pub fn get_tx_out_by_public_key( - ledger_db: &LedgerDB, - public_key : &CompressedRistrettoPublic, - -) -> TxOut{ - ledger_db.get_tx_out_by_index(ledger_db.get_tx_out_index_by_public_key(public_key).unwrap()).unwrap() -} - pub fn add_block_from_transaction_log( ledger_db: &mut LedgerDB, conn: &PooledConnection>, From a4fb22319ca340a50e9d3c696a6b21a023cbc5f5 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 14:59:32 -0700 Subject: [PATCH 20/40] Update helper function uses --- full-service/src/db/transaction_log.rs | 2 +- full-service/src/service/receipt.rs | 3 ++- full-service/src/service/transaction_builder.rs | 1 - full-service/src/test_utils.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/full-service/src/db/transaction_log.rs b/full-service/src/db/transaction_log.rs index ee9910511..de56e8c09 100644 --- a/full-service/src/db/transaction_log.rs +++ b/full-service/src/db/transaction_log.rs @@ -589,7 +589,7 @@ mod tests { }, test_utils::{ add_block_from_transaction_log, add_block_with_tx_outs, builder_for_random_recipient, - get_resolver_factory, get_test_ledger, get_tx_out_by_public_key,manually_sync_account, + get_resolver_factory, get_test_ledger, manually_sync_account, random_account_with_seed_values, WalletDbTestContext, MOB, }, util::b58::b58_encode_public_address, diff --git a/full-service/src/service/receipt.rs b/full-service/src/service/receipt.rs index d0a91ff01..cb2fb932a 100644 --- a/full-service/src/service/receipt.rs +++ b/full-service/src/service/receipt.rs @@ -291,12 +291,13 @@ mod tests { account::AccountService, address::AddressService, confirmation_number::ConfirmationService, + ledger::get_tx_out_by_public_key, transaction::{TransactionMemo, TransactionService}, transaction_log::TransactionLogService, txo::TxoService, }, test_utils::{ - add_block_to_ledger_db, add_block_with_tx, get_test_ledger, get_tx_out_by_public_key, + add_block_to_ledger_db, add_block_with_tx, get_test_ledger, manually_sync_account, setup_wallet_service, MOB, }, util::b58::b58_encode_public_address, diff --git a/full-service/src/service/transaction_builder.rs b/full-service/src/service/transaction_builder.rs index ddaec77e3..34695ad8a 100644 --- a/full-service/src/service/transaction_builder.rs +++ b/full-service/src/service/transaction_builder.rs @@ -18,7 +18,6 @@ use crate::{ }, error::WalletTransactionBuilderError, service::transaction::TransactionMemo, - service::ledger::get_tx_out_by_public_key, }; use mc_account_keys::PublicAddress; use mc_common::HashSet; diff --git a/full-service/src/test_utils.rs b/full-service/src/test_utils.rs index 1a1aca89b..84a3dd105 100644 --- a/full-service/src/test_utils.rs +++ b/full-service/src/test_utils.rs @@ -30,7 +30,7 @@ use mc_connection::{Connection, ConnectionManager, HardcodedCredentialsProvider, use mc_connection_test_utils::{test_client_uri, MockBlockchainConnection}; use mc_consensus_enclave_api::FeeMap; use mc_consensus_scp::QuorumSet; -use mc_crypto_keys::{CompressedRistrettoPublic, RistrettoPrivate, RistrettoPublic}; +use mc_crypto_keys::{RistrettoPrivate, RistrettoPublic}; use mc_crypto_rand::{CryptoRng, RngCore}; use mc_fog_report_validation::{FullyValidatedFogPubkey, MockFogPubkeyResolver}; use mc_ledger_db::{Ledger, LedgerDB}; From 28118973cb963c52f1837d88ccd261cc20e02590 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 15:46:10 -0700 Subject: [PATCH 21/40] Make get_tx_out_by_index return a result instead of using a bunch of unwraps --- full-service/src/service/ledger.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/full-service/src/service/ledger.rs b/full-service/src/service/ledger.rs index d5dddcec2..abc9befb7 100644 --- a/full-service/src/service/ledger.rs +++ b/full-service/src/service/ledger.rs @@ -298,6 +298,8 @@ where pub fn get_tx_out_by_public_key( ledger_db: &LedgerDB, public_key : &CompressedRistrettoPublic, -) -> TxOut{ - ledger_db.get_tx_out_by_index(ledger_db.get_tx_out_index_by_public_key(public_key).unwrap()).unwrap() +) -> Result { + let txo_index = ledger_db.get_tx_out_index_by_public_key(public_key)?; + let txo = ledger_db.get_tx_out_by_index(txo_index)?; + Ok(txo) } From d9aee34e4a493a926c88103c5f3552abc434513c Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 15:46:38 -0700 Subject: [PATCH 22/40] Unwrap the txout from receipt --- full-service/src/service/receipt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/full-service/src/service/receipt.rs b/full-service/src/service/receipt.rs index cb2fb932a..970ed4062 100644 --- a/full-service/src/service/receipt.rs +++ b/full-service/src/service/receipt.rs @@ -479,7 +479,7 @@ mod tests { assert_eq!(receipt.public_key, txo_pubkey); assert_eq!(receipt.tombstone_block, 23); // Ledger seeded with 12 blocks at tx construction, then one appended + 10 let public_key = txos_and_statuses[0].0.public_key().expect("Could not get CompressedRistrettoPublic from txo"); - let txo: TxOut = get_tx_out_by_public_key(&ledger_db, &public_key); + let txo: TxOut = get_tx_out_by_public_key(&ledger_db, &public_key).expect("Could not get the txo from the ledger."); assert_eq!(&receipt.amount, txo.get_masked_amount().unwrap()); assert_eq!(receipt.confirmation, confirmations[0].confirmation); } From e082b9c91a367159c60ca08b152d950db4466a3a Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 16:09:06 -0700 Subject: [PATCH 23/40] Remove uneeded function --- full-service/src/test_utils.rs | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/full-service/src/test_utils.rs b/full-service/src/test_utils.rs index 84a3dd105..afab3a4b6 100644 --- a/full-service/src/test_utils.rs +++ b/full-service/src/test_utils.rs @@ -258,40 +258,6 @@ pub fn add_block_with_tx( append_test_block(ledger_db, block_contents, rng) } -pub fn add_block_from_transaction_log( - ledger_db: &mut LedgerDB, - conn: &PooledConnection>, - transaction_log: &TransactionLog, - rng: &mut (impl CryptoRng + RngCore), -) -> u64 { - let associated_txos = transaction_log.get_associated_txos(conn).unwrap(); - - let mut output_txos = associated_txos.outputs.clone(); - output_txos.append(&mut associated_txos.change.clone()); - let outputs: Vec = output_txos - .iter() - .map(|(txo, _)| { - get_tx_out_by_public_key(ledger_db, &txo.public_key().unwrap()) - }) - .collect(); - - let input_txos: Vec = associated_txos.inputs.clone(); - let key_images: Vec = input_txos - .iter() - .map(|txo| mc_util_serial::decode(&txo.key_image.clone().unwrap()).unwrap()) - .collect(); - - // Note: This block doesn't contain the fee output. - let block_contents = BlockContents { - key_images, - outputs, - validated_mint_config_txs: Vec::new(), - mint_txs: Vec::new(), - }; - - append_test_block(ledger_db, block_contents, rng) -} - pub fn add_block_with_tx_outs( ledger_db: &mut LedgerDB, outputs: &[TxOut], From 43e7c348758502708fc251eafc340e3771a38e67 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 16:12:50 -0700 Subject: [PATCH 24/40] Update db::transaction_log::tests::test_log_submitted to use the tx_proposal instead of the transactin log when writing to the ledger --- full-service/src/db/transaction_log.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/full-service/src/db/transaction_log.rs b/full-service/src/db/transaction_log.rs index de56e8c09..e887bdc9e 100644 --- a/full-service/src/db/transaction_log.rs +++ b/full-service/src/db/transaction_log.rs @@ -588,7 +588,7 @@ mod tests { transaction_builder::WalletTransactionBuilder, }, test_utils::{ - add_block_from_transaction_log, add_block_with_tx_outs, builder_for_random_recipient, + add_block_with_tx_outs, builder_for_random_recipient, get_resolver_factory, get_test_ledger, manually_sync_account, random_account_with_seed_values, WalletDbTestContext, MOB, }, @@ -719,11 +719,20 @@ mod tests { // The subaddress will also be set once received. assert_eq!(change_details.subaddress_index, None,); - add_block_from_transaction_log( + let key_images: Vec = input_txos + .iter() + .map(|txo| mc_util_serial::decode(&txo.key_image.clone().unwrap()).unwrap()) + .collect(); + + // Note: This block doesn't contain the fee output. + add_block_with_tx_outs( &mut ledger_db, - &wallet_db.get_conn().unwrap(), - &tx_log, - &mut rng, + &[ + tx_proposal.change_txos[0].tx_out.clone(), + tx_proposal.payload_txos[0].tx_out.clone(), + ], + &key_images, + &mut rng ); assert_eq!(ledger_db.num_blocks().unwrap(), 14); @@ -750,7 +759,7 @@ mod tests { .unwrap(); assert_eq!( - updated_change_details.status(&conn).unwrap(), + updated_change_details.status(&conn).unwrap() TxoStatus::Unspent ); assert_eq!( From da2791f4f524db1e9f571a061872968094ccd5e2 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 16:19:01 -0700 Subject: [PATCH 25/40] Update service::transaction::tests::test_send_transaction to use the tx_proposal instead of the transactin log when writing to the ledger --- full-service/src/service/transaction.rs | 37 ++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/full-service/src/service/transaction.rs b/full-service/src/service/transaction.rs index e230554ca..6e5067363 100644 --- a/full-service/src/service/transaction.rs +++ b/full-service/src/service/transaction.rs @@ -538,7 +538,7 @@ mod tests { transaction_log::TransactionLogService, }, test_utils::{ - add_block_from_transaction_log, add_block_to_ledger_db, get_test_ledger, + add_block_with_tx_outs, add_block_to_ledger_db, get_test_ledger, manually_sync_account, setup_wallet_service, MOB, }, util::b58::b58_encode_public_address, @@ -794,7 +794,21 @@ mod tests { { log::info!(logger, "Adding block from transaction log"); let conn = service.get_conn().unwrap(); - add_block_from_transaction_log(&mut ledger_db, &conn, &transaction_log, &mut rng); + let key_images: Vec = input_txos + .iter() + .map(|txo| mc_util_serial::decode(&txo.key_image.clone().unwrap()).unwrap()) + .collect(); + + // Note: This block doesn't contain the fee output. + add_block_with_tx_outs( + &mut ledger_db, + &[ + tx_proposal.change_txos[0].tx_out.clone(), + tx_proposal.payload_txos[0].tx_out.clone(), + ], + &key_images, + &mut rng + ); } manually_sync_account( @@ -875,9 +889,24 @@ mod tests { // workaround. { - log::info!(logger, "Adding block from transaction log"); + log::info!(logger, "Adding block from transaction proposal"); let conn = service.get_conn().unwrap(); - add_block_from_transaction_log(&mut ledger_db, &conn, &transaction_log, &mut rng); + let key_images: Vec = input_txos + .iter() + .map(|txo| mc_util_serial::decode(&txo.key_image.clone().unwrap()).unwrap()) + .collect(); + + // Note: This block doesn't contain the fee output. + add_block_with_tx_outs( + &mut ledger_db, + &[ + tx_proposal.change_txos[0].tx_out.clone(), + tx_proposal.payload_txos[0].tx_out.clone(), + ], + &key_images, + &mut rng + ); + } manually_sync_account( From 1c6ad09e86d4ae500c9aaae46636ff77b47e78dd Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 16:33:34 -0700 Subject: [PATCH 26/40] oops: make sure we get the input_txos from the proposal --- full-service/src/service/transaction.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/full-service/src/service/transaction.rs b/full-service/src/service/transaction.rs index 6e5067363..eb94b41bd 100644 --- a/full-service/src/service/transaction.rs +++ b/full-service/src/service/transaction.rs @@ -770,7 +770,7 @@ mod tests { .unwrap(); // Send a transaction from Alice to Bob - let (transaction_log, _associated_txos, _value_map, _tx_proposal) = service + let (_transaction_log, _associated_txos, _value_map, tx_proposal) = service .build_sign_and_submit_transaction( &alice.id, &[( @@ -794,7 +794,7 @@ mod tests { { log::info!(logger, "Adding block from transaction log"); let conn = service.get_conn().unwrap(); - let key_images: Vec = input_txos + let key_images: Vec = tx_proposal.input_txos .iter() .map(|txo| mc_util_serial::decode(&txo.key_image.clone().unwrap()).unwrap()) .collect(); @@ -867,7 +867,7 @@ mod tests { assert_eq!(bob_balance_pmob.unspent, 42000000000000); // Bob should now be able to send to Alice - let (transaction_log, _associated_txos, _value_map, _tx_proposal) = service + let (_transaction_log, _associated_txos, _value_map, tx_proposal) = service .build_sign_and_submit_transaction( &bob.id, &[( @@ -891,7 +891,7 @@ mod tests { { log::info!(logger, "Adding block from transaction proposal"); let conn = service.get_conn().unwrap(); - let key_images: Vec = input_txos + let key_images: Vec = tx_proposal.input_txos .iter() .map(|txo| mc_util_serial::decode(&txo.key_image.clone().unwrap()).unwrap()) .collect(); From 40aae238f6c9bb4bff2793ea487f2d2b8d7ea260 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 16:34:21 -0700 Subject: [PATCH 27/40] Update test_list_transaction_logs_for_account_with_min_and_max_block_index to use the tx_proposal instead of the transactin log when writing to the ledger --- full-service/src/service/transaction_log.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/full-service/src/service/transaction_log.rs b/full-service/src/service/transaction_log.rs index 10c25174a..97ba6da05 100644 --- a/full-service/src/service/transaction_log.rs +++ b/full-service/src/service/transaction_log.rs @@ -152,7 +152,7 @@ mod tests { transaction_log::TransactionLogService, }, test_utils::{ - add_block_from_transaction_log, add_block_to_ledger_db, get_test_ledger, + add_block_with_tx_outs, add_block_to_ledger_db, get_test_ledger, manually_sync_account, setup_wallet_service, MOB, }, }; @@ -214,7 +214,7 @@ mod tests { .unwrap(); for _ in 0..5 { - let (transaction_log, _, _, _) = service + let (_, _, _, tx_proposal) = service .build_sign_and_submit_transaction( &alice_account_id.to_string(), &[( @@ -233,7 +233,21 @@ mod tests { { let conn = service.get_conn().unwrap(); - add_block_from_transaction_log(&mut ledger_db, &conn, &transaction_log, &mut rng); + let key_images: Vec = tx_proposal.input_txos + .iter() + .map(|txo| mc_util_serial::decode(&txo.key_image.clone().unwrap()).unwrap()) + .collect(); + + // Note: This block doesn't contain the fee output. + add_block_with_tx_outs( + &mut ledger_db, + &[ + tx_proposal.change_txos[0].tx_out.clone(), + tx_proposal.payload_txos[0].tx_out.clone(), + ], + &key_images, + &mut rng + ); } manually_sync_account( From 463f069dde9db29fb4b07c0b7b9e7123204acddf Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 16:36:05 -0700 Subject: [PATCH 28/40] Remove unused import --- full-service/src/test_utils.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/full-service/src/test_utils.rs b/full-service/src/test_utils.rs index afab3a4b6..54f3bce40 100644 --- a/full-service/src/test_utils.rs +++ b/full-service/src/test_utils.rs @@ -12,7 +12,6 @@ use crate::{ service::{ sync::sync_account, transaction::TransactionMemo, transaction_builder::WalletTransactionBuilder, - ledger::get_tx_out_by_public_key, }, WalletService, }; From 8e1e4a327bfe753a182237210e60a5930b017aa7 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 16:41:32 -0700 Subject: [PATCH 29/40] fix typos --- full-service/src/db/transaction_log.rs | 6 +++--- full-service/src/service/receipt.rs | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/full-service/src/db/transaction_log.rs b/full-service/src/db/transaction_log.rs index e887bdc9e..041840244 100644 --- a/full-service/src/db/transaction_log.rs +++ b/full-service/src/db/transaction_log.rs @@ -5,7 +5,7 @@ use diesel::prelude::*; use mc_common::HashMap; use mc_crypto_digestible::{Digestible, MerlinTranscript}; -use mc_transaction_core::{tx::Tx, Amount, TokenId}; +use mc_transaction_core::{tx::Tx, Amount, KeyImage, TokenId}; use std::fmt; use crate::{ @@ -719,7 +719,7 @@ mod tests { // The subaddress will also be set once received. assert_eq!(change_details.subaddress_index, None,); - let key_images: Vec = input_txos + let key_images: Vec = tx_proposal.input_txos .iter() .map(|txo| mc_util_serial::decode(&txo.key_image.clone().unwrap()).unwrap()) .collect(); @@ -759,7 +759,7 @@ mod tests { .unwrap(); assert_eq!( - updated_change_details.status(&conn).unwrap() + updated_change_details.status(&conn).unwrap(), TxoStatus::Unspent ); assert_eq!( diff --git a/full-service/src/service/receipt.rs b/full-service/src/service/receipt.rs index 970ed4062..48c4fe038 100644 --- a/full-service/src/service/receipt.rs +++ b/full-service/src/service/receipt.rs @@ -291,7 +291,6 @@ mod tests { account::AccountService, address::AddressService, confirmation_number::ConfirmationService, - ledger::get_tx_out_by_public_key, transaction::{TransactionMemo, TransactionService}, transaction_log::TransactionLogService, txo::TxoService, From 2ce7e955949241be1b81d603e04829f6a44a50bc Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 17:07:39 -0700 Subject: [PATCH 30/40] Don't need to decode the keyimage --- full-service/src/db/transaction_log.rs | 6 +++--- full-service/src/service/receipt.rs | 1 + full-service/src/service/transaction.rs | 8 ++++---- full-service/src/service/transaction_log.rs | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/full-service/src/db/transaction_log.rs b/full-service/src/db/transaction_log.rs index 041840244..b356a311b 100644 --- a/full-service/src/db/transaction_log.rs +++ b/full-service/src/db/transaction_log.rs @@ -5,7 +5,7 @@ use diesel::prelude::*; use mc_common::HashMap; use mc_crypto_digestible::{Digestible, MerlinTranscript}; -use mc_transaction_core::{tx::Tx, Amount, KeyImage, TokenId}; +use mc_transaction_core::{tx::Tx, Amount, TokenId}; use std::fmt; use crate::{ @@ -578,7 +578,7 @@ mod tests { use mc_account_keys::{PublicAddress, CHANGE_SUBADDRESS_INDEX}; use mc_common::logger::{test_with_logger, Logger}; use mc_ledger_db::Ledger; - use mc_transaction_core::{tokens::Mob, Token}; + use mc_transaction_core::{ring_signature::KeyImage, tokens::Mob, Token}; use rand::{rngs::StdRng, SeedableRng}; use crate::{ @@ -721,7 +721,7 @@ mod tests { let key_images: Vec = tx_proposal.input_txos .iter() - .map(|txo| mc_util_serial::decode(&txo.key_image.clone().unwrap()).unwrap()) + .map(|txo| txo.key_image.clone()) .collect(); // Note: This block doesn't contain the fee output. diff --git a/full-service/src/service/receipt.rs b/full-service/src/service/receipt.rs index 48c4fe038..d9cf01b98 100644 --- a/full-service/src/service/receipt.rs +++ b/full-service/src/service/receipt.rs @@ -294,6 +294,7 @@ mod tests { transaction::{TransactionMemo, TransactionService}, transaction_log::TransactionLogService, txo::TxoService, + ledger::get_tx_out_by_public_key, }, test_utils::{ add_block_to_ledger_db, add_block_with_tx, get_test_ledger, diff --git a/full-service/src/service/transaction.rs b/full-service/src/service/transaction.rs index eb94b41bd..3ca16ec77 100644 --- a/full-service/src/service/transaction.rs +++ b/full-service/src/service/transaction.rs @@ -770,7 +770,7 @@ mod tests { .unwrap(); // Send a transaction from Alice to Bob - let (_transaction_log, _associated_txos, _value_map, tx_proposal) = service + let (transaction_log, _associated_txos, _value_map, tx_proposal) = service .build_sign_and_submit_transaction( &alice.id, &[( @@ -796,7 +796,7 @@ mod tests { let conn = service.get_conn().unwrap(); let key_images: Vec = tx_proposal.input_txos .iter() - .map(|txo| mc_util_serial::decode(&txo.key_image.clone().unwrap()).unwrap()) + .map(|txo| txo.key_image.clone()) .collect(); // Note: This block doesn't contain the fee output. @@ -867,7 +867,7 @@ mod tests { assert_eq!(bob_balance_pmob.unspent, 42000000000000); // Bob should now be able to send to Alice - let (_transaction_log, _associated_txos, _value_map, tx_proposal) = service + let (_, _, _, tx_proposal) = service .build_sign_and_submit_transaction( &bob.id, &[( @@ -893,7 +893,7 @@ mod tests { let conn = service.get_conn().unwrap(); let key_images: Vec = tx_proposal.input_txos .iter() - .map(|txo| mc_util_serial::decode(&txo.key_image.clone().unwrap()).unwrap()) + .map(|txo| txo.key_image.clone()) .collect(); // Note: This block doesn't contain the fee output. diff --git a/full-service/src/service/transaction_log.rs b/full-service/src/service/transaction_log.rs index 97ba6da05..1418d5c72 100644 --- a/full-service/src/service/transaction_log.rs +++ b/full-service/src/service/transaction_log.rs @@ -235,7 +235,7 @@ mod tests { let conn = service.get_conn().unwrap(); let key_images: Vec = tx_proposal.input_txos .iter() - .map(|txo| mc_util_serial::decode(&txo.key_image.clone().unwrap()).unwrap()) + .map(|txo| txo.key_image.clone()) .collect(); // Note: This block doesn't contain the fee output. From 9044fabc378e232399b539a031c7e9604331da0e Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 17:19:09 -0700 Subject: [PATCH 31/40] refactor: rename --- full-service/src/db/txo.rs | 8 ++++---- full-service/src/test_utils.rs | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/full-service/src/db/txo.rs b/full-service/src/db/txo.rs index ac459506a..2d5b40efb 100644 --- a/full-service/src/db/txo.rs +++ b/full-service/src/db/txo.rs @@ -1429,7 +1429,7 @@ mod tests { }, test_utils::{ add_block_with_db_txos, add_block_with_tx, add_block_with_tx_outs, - create_test_minted_and_change_txos, create_test_received_txo, + transaction_log_from_create_test_minted_and_change_txos, create_test_received_txo, create_test_txo_for_recipient, get_resolver_factory, get_test_ledger, manually_sync_account, random_account_with_seed_values, WalletDbTestContext, MOB, }, @@ -1535,7 +1535,7 @@ mod tests { // have not yet assigned. At the DB layer, we accomplish this by // constructing the output txos, then logging sent and received for this // account. - let transaction_log = create_test_minted_and_change_txos( + let transaction_log = transaction_log_from_create_test_minted_and_change_txos( alice_account_key.clone(), alice_account_key.subaddress(4), 33 * MOB, @@ -1751,7 +1751,7 @@ mod tests { ) .unwrap(); - let transaction_log = create_test_minted_and_change_txos( + let transaction_log = transaction_log_from_create_test_minted_and_change_txos( alice_account_key.clone(), bob_account_key.subaddress(0), 72 * MOB, @@ -2090,7 +2090,7 @@ mod tests { assert_eq!(txos.len(), 12); - let transaction_log = create_test_minted_and_change_txos( + let transaction_log = transaction_log_from_create_test_minted_and_change_txos( src_account.clone(), recipient, 1 * MOB, diff --git a/full-service/src/test_utils.rs b/full-service/src/test_utils.rs index 54f3bce40..5f75489fc 100644 --- a/full-service/src/test_utils.rs +++ b/full-service/src/test_utils.rs @@ -476,13 +476,14 @@ pub fn create_test_received_txo( /// Creates a test minted and change txo. /// /// Returns ((output_txo_id, value), (change_txo_id, value)) -pub fn create_test_minted_and_change_txos( +pub fn transaction_log_from_create_test_minted_and_change_txos( src_account_key: AccountKey, recipient: PublicAddress, value: u64, wallet_db: WalletDb, ledger_db: LedgerDB, -) -> TransactionLog { +) -> TransactionLog +{ let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); // Use the builder to create valid TxOuts for this account From 1f19758fc0efae8d73d0053a33491bd6969e87d9 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 17:24:21 -0700 Subject: [PATCH 32/40] Change signature --- full-service/src/test_utils.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/full-service/src/test_utils.rs b/full-service/src/test_utils.rs index 5f75489fc..7c7ed047d 100644 --- a/full-service/src/test_utils.rs +++ b/full-service/src/test_utils.rs @@ -12,6 +12,7 @@ use crate::{ service::{ sync::sync_account, transaction::TransactionMemo, transaction_builder::WalletTransactionBuilder, + models::tx_proposal::TxProposal, }, WalletService, }; @@ -484,6 +485,11 @@ pub fn transaction_log_from_create_test_minted_and_change_txos( ledger_db: LedgerDB, ) -> TransactionLog { + (tl, txp) = create_test_minted_and_change_txos(&src_account_key, recipient, value, wallet_db, ledger_db); + tl +} + +pub fn create_test_minted_and_change_txos(src_account_key: &AccountKey, recipient: PublicAddress, value: u64, wallet_db: WalletDb, ledger_db: LedgerDB) -> (TransactionLog, TxProposal) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); // Use the builder to create valid TxOuts for this account @@ -503,14 +509,15 @@ pub fn transaction_log_from_create_test_minted_and_change_txos( // There should be 2 outputs, one to dest and one change assert_eq!(tx_proposal.tx.prefix.outputs.len(), 2); - TransactionLog::log_submitted( + (TransactionLog::log_submitted( &tx_proposal, 10, "".to_string(), &AccountID::from(&src_account_key).to_string(), &conn, ) - .unwrap() + .unwrap(), + tx_proposal) } // Seed a local account with some Txos in the ledger From 478d604030f31e95c0c056afa8c79fb00b5e27cd Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 17:48:48 -0700 Subject: [PATCH 33/40] Remove because our db no loner has the actual txos in it --- full-service/src/test_utils.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/full-service/src/test_utils.rs b/full-service/src/test_utils.rs index 7c7ed047d..3df49fa2d 100644 --- a/full-service/src/test_utils.rs +++ b/full-service/src/test_utils.rs @@ -474,9 +474,6 @@ pub fn create_test_received_txo( (txo_id_hex, txo, key_image) } -/// Creates a test minted and change txo. -/// -/// Returns ((output_txo_id, value), (change_txo_id, value)) pub fn transaction_log_from_create_test_minted_and_change_txos( src_account_key: AccountKey, recipient: PublicAddress, @@ -485,11 +482,26 @@ pub fn transaction_log_from_create_test_minted_and_change_txos( ledger_db: LedgerDB, ) -> TransactionLog { - (tl, txp) = create_test_minted_and_change_txos(&src_account_key, recipient, value, wallet_db, ledger_db); + let (tl, _) = create_test_minted_and_change_txos(src_account_key, recipient, value, wallet_db, ledger_db); tl } -pub fn create_test_minted_and_change_txos(src_account_key: &AccountKey, recipient: PublicAddress, value: u64, wallet_db: WalletDb, ledger_db: LedgerDB) -> (TransactionLog, TxProposal) { +pub fn tx_proposal_from_create_test_minted_and_change_txos( + src_account_key: AccountKey, + recipient: PublicAddress, + value: u64, + wallet_db: WalletDb, + ledger_db: LedgerDB, +) -> TxProposal +{ + let (_, txp) = create_test_minted_and_change_txos(src_account_key, recipient, value, wallet_db, ledger_db); + txp +} + +/// Creates a test minted and change txo. +/// +/// Returns (txproposal, ((output_txo_id, value), (change_txo_id, value))) +pub fn create_test_minted_and_change_txos(src_account_key: AccountKey, recipient: PublicAddress, value: u64, wallet_db: WalletDb, ledger_db: LedgerDB) -> (TransactionLog, TxProposal) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); // Use the builder to create valid TxOuts for this account From 0e248e9e32422e858fb695774d864e96e162c4dd Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 17:49:46 -0700 Subject: [PATCH 34/40] remove unused var --- full-service/src/service/transaction.rs | 1 - full-service/src/service/transaction_log.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/full-service/src/service/transaction.rs b/full-service/src/service/transaction.rs index 3ca16ec77..272521936 100644 --- a/full-service/src/service/transaction.rs +++ b/full-service/src/service/transaction.rs @@ -793,7 +793,6 @@ mod tests { // workaround. { log::info!(logger, "Adding block from transaction log"); - let conn = service.get_conn().unwrap(); let key_images: Vec = tx_proposal.input_txos .iter() .map(|txo| txo.key_image.clone()) diff --git a/full-service/src/service/transaction_log.rs b/full-service/src/service/transaction_log.rs index 1418d5c72..57d8617e4 100644 --- a/full-service/src/service/transaction_log.rs +++ b/full-service/src/service/transaction_log.rs @@ -232,7 +232,6 @@ mod tests { .unwrap(); { - let conn = service.get_conn().unwrap(); let key_images: Vec = tx_proposal.input_txos .iter() .map(|txo| txo.key_image.clone()) From 5d7df6d6dc9adedb47c11c95563c1aa5700d6ebb Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 18:19:44 -0700 Subject: [PATCH 35/40] Finish fixing tests --- full-service/src/db/txo.rs | 21 ++++++++++++--------- full-service/src/service/transaction.rs | 1 - 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/full-service/src/db/txo.rs b/full-service/src/db/txo.rs index 2d5b40efb..243ab3c19 100644 --- a/full-service/src/db/txo.rs +++ b/full-service/src/db/txo.rs @@ -1429,7 +1429,8 @@ mod tests { }, test_utils::{ add_block_with_db_txos, add_block_with_tx, add_block_with_tx_outs, - transaction_log_from_create_test_minted_and_change_txos, create_test_received_txo, + create_test_minted_and_change_txos, create_test_received_txo, + transaction_log_from_create_test_minted_and_change_txos, create_test_txo_for_recipient, get_resolver_factory, get_test_ledger, manually_sync_account, random_account_with_seed_values, WalletDbTestContext, MOB, }, @@ -1535,7 +1536,7 @@ mod tests { // have not yet assigned. At the DB layer, we accomplish this by // constructing the output txos, then logging sent and received for this // account. - let transaction_log = transaction_log_from_create_test_minted_and_change_txos( + let (transaction_log, tx_proposal) = create_test_minted_and_change_txos( alice_account_key.clone(), alice_account_key.subaddress(4), 33 * MOB, @@ -1553,10 +1554,11 @@ mod tests { assert_eq!(minted_txo.value as u64, 33 * MOB); assert_eq!(change_txo.value as u64, 967 * MOB - Mob::MINIMUM_FEE); - add_block_with_db_txos( + add_block_with_tx_outs( &mut ledger_db, - &wallet_db, - &[minted_txo.id.clone(), change_txo.id.clone()], + &[ tx_proposal.change_txos[0].tx_out.clone(), + tx_proposal.payload_txos[0].tx_out.clone(), + ], &[KeyImage::from(for_alice_key_image)], &mut rng, ); @@ -1751,7 +1753,7 @@ mod tests { ) .unwrap(); - let transaction_log = transaction_log_from_create_test_minted_and_change_txos( + let (transaction_log, tx_proposal) = create_test_minted_and_change_txos( alice_account_key.clone(), bob_account_key.subaddress(0), 72 * MOB, @@ -1770,10 +1772,11 @@ mod tests { assert_eq!(change_txo.value as u64, 928 * MOB - (2 * Mob::MINIMUM_FEE)); // Add the minted Txos to the ledger - add_block_with_db_txos( + add_block_with_tx_outs( &mut ledger_db, - &wallet_db, - &[minted_txo.id.clone(), change_txo.id.clone()], + &[ tx_proposal.change_txos[0].tx_out.clone(), + tx_proposal.payload_txos[0].tx_out.clone(), + ], &[KeyImage::from(for_bob_key_image)], &mut rng, ); diff --git a/full-service/src/service/transaction.rs b/full-service/src/service/transaction.rs index 272521936..f1a0d5ea6 100644 --- a/full-service/src/service/transaction.rs +++ b/full-service/src/service/transaction.rs @@ -889,7 +889,6 @@ mod tests { { log::info!(logger, "Adding block from transaction proposal"); - let conn = service.get_conn().unwrap(); let key_images: Vec = tx_proposal.input_txos .iter() .map(|txo| txo.key_image.clone()) From 709339dc8ee7464fb89b15b7591ff1822faa1bed Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Thu, 20 Oct 2022 18:22:40 -0700 Subject: [PATCH 36/40] cargo fmt --- full-service/src/db/transaction_log.rs | 11 ++-- full-service/src/db/txo.rs | 10 ++-- full-service/src/json_rpc/v2/api/wallet.rs | 18 ++++--- full-service/src/service/ledger.rs | 7 ++- full-service/src/service/receipt.rs | 14 +++-- full-service/src/service/transaction.rs | 15 +++--- .../src/service/transaction_builder.rs | 15 ++++-- full-service/src/service/transaction_log.rs | 9 ++-- full-service/src/test_utils.rs | 52 ++++++++++++------- 9 files changed, 93 insertions(+), 58 deletions(-) diff --git a/full-service/src/db/transaction_log.rs b/full-service/src/db/transaction_log.rs index b356a311b..d66ef93ff 100644 --- a/full-service/src/db/transaction_log.rs +++ b/full-service/src/db/transaction_log.rs @@ -588,9 +588,9 @@ mod tests { transaction_builder::WalletTransactionBuilder, }, test_utils::{ - add_block_with_tx_outs, builder_for_random_recipient, - get_resolver_factory, get_test_ledger, manually_sync_account, - random_account_with_seed_values, WalletDbTestContext, MOB, + add_block_with_tx_outs, builder_for_random_recipient, get_resolver_factory, + get_test_ledger, manually_sync_account, random_account_with_seed_values, + WalletDbTestContext, MOB, }, util::b58::b58_encode_public_address, }; @@ -719,7 +719,8 @@ mod tests { // The subaddress will also be set once received. assert_eq!(change_details.subaddress_index, None,); - let key_images: Vec = tx_proposal.input_txos + let key_images: Vec = tx_proposal + .input_txos .iter() .map(|txo| txo.key_image.clone()) .collect(); @@ -732,7 +733,7 @@ mod tests { tx_proposal.payload_txos[0].tx_out.clone(), ], &key_images, - &mut rng + &mut rng, ); assert_eq!(ledger_db.num_blocks().unwrap(), 14); diff --git a/full-service/src/db/txo.rs b/full-service/src/db/txo.rs index 243ab3c19..ee2cae1c1 100644 --- a/full-service/src/db/txo.rs +++ b/full-service/src/db/txo.rs @@ -1430,9 +1430,9 @@ mod tests { test_utils::{ add_block_with_db_txos, add_block_with_tx, add_block_with_tx_outs, create_test_minted_and_change_txos, create_test_received_txo, - transaction_log_from_create_test_minted_and_change_txos, create_test_txo_for_recipient, get_resolver_factory, get_test_ledger, - manually_sync_account, random_account_with_seed_values, WalletDbTestContext, MOB, + manually_sync_account, random_account_with_seed_values, + transaction_log_from_create_test_minted_and_change_txos, WalletDbTestContext, MOB, }, WalletDb, }; @@ -1556,7 +1556,8 @@ mod tests { add_block_with_tx_outs( &mut ledger_db, - &[ tx_proposal.change_txos[0].tx_out.clone(), + &[ + tx_proposal.change_txos[0].tx_out.clone(), tx_proposal.payload_txos[0].tx_out.clone(), ], &[KeyImage::from(for_alice_key_image)], @@ -1774,7 +1775,8 @@ mod tests { // Add the minted Txos to the ledger add_block_with_tx_outs( &mut ledger_db, - &[ tx_proposal.change_txos[0].tx_out.clone(), + &[ + tx_proposal.change_txos[0].tx_out.clone(), tx_proposal.payload_txos[0].tx_out.clone(), ], &[KeyImage::from(for_bob_key_image)], diff --git a/full-service/src/json_rpc/v2/api/wallet.rs b/full-service/src/json_rpc/v2/api/wallet.rs index 2016d2d15..7a319120f 100644 --- a/full-service/src/json_rpc/v2/api/wallet.rs +++ b/full-service/src/json_rpc/v2/api/wallet.rs @@ -442,17 +442,19 @@ where ) .map_err(format_error)?; - - let unverified_tx_results : Result, JsonRPCError>= unverified_txos - .iter() - .map(|(txo, _)| -> Result{ - service.get_txo_object(&txo.id).map_err(format_error) - }) - .collect::, JsonRPCError>>(); + let unverified_tx_results: Result, JsonRPCError> = + unverified_txos + .iter() + .map( + |(txo, _)| -> Result { + service.get_txo_object(&txo.id).map_err(format_error) + }, + ) + .collect::, JsonRPCError>>(); let unverified_tx_results = unverified_tx_results?; - let unverified_txos_encoded : Vec= unverified_tx_results + let unverified_txos_encoded: Vec = unverified_tx_results .iter() .map(|txo_obj| hex::encode(&mc_util_serial::encode(txo_obj))) .collect(); diff --git a/full-service/src/service/ledger.rs b/full-service/src/service/ledger.rs index abc9befb7..2adea2df1 100644 --- a/full-service/src/service/ledger.rs +++ b/full-service/src/service/ledger.rs @@ -176,7 +176,10 @@ where fn get_txo_object(&self, txo_id_hex: &str) -> Result { let conn = self.get_conn()?; let txo_details = Txo::get(txo_id_hex, &conn)?; - let txo = self.ledger_db.get_tx_out_by_index(self.ledger_db.get_tx_out_index_by_public_key(&txo_details.public_key()?)?)?; + let txo = self.ledger_db.get_tx_out_by_index( + self.ledger_db + .get_tx_out_index_by_public_key(&txo_details.public_key()?)?, + )?; Ok(txo) } @@ -297,7 +300,7 @@ where pub fn get_tx_out_by_public_key( ledger_db: &LedgerDB, - public_key : &CompressedRistrettoPublic, + public_key: &CompressedRistrettoPublic, ) -> Result { let txo_index = ledger_db.get_tx_out_index_by_public_key(public_key)?; let txo = ledger_db.get_tx_out_by_index(txo_index)?; diff --git a/full-service/src/service/receipt.rs b/full-service/src/service/receipt.rs index d9cf01b98..911f146ad 100644 --- a/full-service/src/service/receipt.rs +++ b/full-service/src/service/receipt.rs @@ -291,14 +291,14 @@ mod tests { account::AccountService, address::AddressService, confirmation_number::ConfirmationService, + ledger::get_tx_out_by_public_key, transaction::{TransactionMemo, TransactionService}, transaction_log::TransactionLogService, txo::TxoService, - ledger::get_tx_out_by_public_key, }, test_utils::{ - add_block_to_ledger_db, add_block_with_tx, get_test_ledger, - manually_sync_account, setup_wallet_service, MOB, + add_block_to_ledger_db, add_block_with_tx, get_test_ledger, manually_sync_account, + setup_wallet_service, MOB, }, util::b58::b58_encode_public_address, }; @@ -478,8 +478,12 @@ mod tests { .expect("Could not decode pubkey"); assert_eq!(receipt.public_key, txo_pubkey); assert_eq!(receipt.tombstone_block, 23); // Ledger seeded with 12 blocks at tx construction, then one appended + 10 - let public_key = txos_and_statuses[0].0.public_key().expect("Could not get CompressedRistrettoPublic from txo"); - let txo: TxOut = get_tx_out_by_public_key(&ledger_db, &public_key).expect("Could not get the txo from the ledger."); + let public_key = txos_and_statuses[0] + .0 + .public_key() + .expect("Could not get CompressedRistrettoPublic from txo"); + let txo: TxOut = get_tx_out_by_public_key(&ledger_db, &public_key) + .expect("Could not get the txo from the ledger."); assert_eq!(&receipt.amount, txo.get_masked_amount().unwrap()); assert_eq!(receipt.confirmation, confirmations[0].confirmation); } diff --git a/full-service/src/service/transaction.rs b/full-service/src/service/transaction.rs index f1a0d5ea6..366eb1a88 100644 --- a/full-service/src/service/transaction.rs +++ b/full-service/src/service/transaction.rs @@ -538,8 +538,8 @@ mod tests { transaction_log::TransactionLogService, }, test_utils::{ - add_block_with_tx_outs, add_block_to_ledger_db, get_test_ledger, - manually_sync_account, setup_wallet_service, MOB, + add_block_to_ledger_db, add_block_with_tx_outs, get_test_ledger, manually_sync_account, + setup_wallet_service, MOB, }, util::b58::b58_encode_public_address, }; @@ -793,7 +793,8 @@ mod tests { // workaround. { log::info!(logger, "Adding block from transaction log"); - let key_images: Vec = tx_proposal.input_txos + let key_images: Vec = tx_proposal + .input_txos .iter() .map(|txo| txo.key_image.clone()) .collect(); @@ -806,7 +807,7 @@ mod tests { tx_proposal.payload_txos[0].tx_out.clone(), ], &key_images, - &mut rng + &mut rng, ); } @@ -889,7 +890,8 @@ mod tests { { log::info!(logger, "Adding block from transaction proposal"); - let key_images: Vec = tx_proposal.input_txos + let key_images: Vec = tx_proposal + .input_txos .iter() .map(|txo| txo.key_image.clone()) .collect(); @@ -902,9 +904,8 @@ mod tests { tx_proposal.payload_txos[0].tx_out.clone(), ], &key_images, - &mut rng + &mut rng, ); - } manually_sync_account( diff --git a/full-service/src/service/transaction_builder.rs b/full-service/src/service/transaction_builder.rs index 34695ad8a..0c8b273d0 100644 --- a/full-service/src/service/transaction_builder.rs +++ b/full-service/src/service/transaction_builder.rs @@ -277,7 +277,10 @@ impl WalletTransactionBuilder { .inputs .iter() .map(|utxo| { - let txo = self.ledger_db.get_tx_out_by_index(self.ledger_db.get_tx_out_index_by_public_key(&utxo.public_key()?)?)?; + let txo = self.ledger_db.get_tx_out_by_index( + self.ledger_db + .get_tx_out_index_by_public_key(&utxo.public_key()?)?, + )?; self.ledger_db.get_tx_out_index_by_hash(&txo.hash()) }) .collect::, mc_ledger_db::Error>>()?; @@ -293,7 +296,10 @@ impl WalletTransactionBuilder { let excluded_tx_out_indices: Vec = inputs_and_proofs .iter() .map(|(utxo, _membership_proof)| { - let txo = self.ledger_db.get_tx_out_by_index(self.ledger_db.get_tx_out_index_by_public_key(&utxo.public_key()?)?)?; + let txo = self.ledger_db.get_tx_out_by_index( + self.ledger_db + .get_tx_out_index_by_public_key(&utxo.public_key()?)?, + )?; self.ledger_db .get_tx_out_index_by_hash(&txo.hash()) .map_err(WalletTransactionBuilderError::LedgerDB) @@ -321,7 +327,10 @@ impl WalletTransactionBuilder { let subaddress_index = utxo.subaddress_index.ok_or_else(|| { WalletTransactionBuilderError::CannotUseOrphanedTxoAsInput(utxo.id.clone()) })?; - let db_tx_out = self.ledger_db.get_tx_out_by_index(self.ledger_db.get_tx_out_index_by_public_key(&utxo.public_key()?)?)?; + let db_tx_out = self.ledger_db.get_tx_out_by_index( + self.ledger_db + .get_tx_out_index_by_public_key(&utxo.public_key()?)?, + )?; let (mut ring, mut membership_proofs) = rings_and_proofs .pop() diff --git a/full-service/src/service/transaction_log.rs b/full-service/src/service/transaction_log.rs index 57d8617e4..8af351e28 100644 --- a/full-service/src/service/transaction_log.rs +++ b/full-service/src/service/transaction_log.rs @@ -152,8 +152,8 @@ mod tests { transaction_log::TransactionLogService, }, test_utils::{ - add_block_with_tx_outs, add_block_to_ledger_db, get_test_ledger, - manually_sync_account, setup_wallet_service, MOB, + add_block_to_ledger_db, add_block_with_tx_outs, get_test_ledger, manually_sync_account, + setup_wallet_service, MOB, }, }; use mc_account_keys::{AccountKey, PublicAddress}; @@ -232,7 +232,8 @@ mod tests { .unwrap(); { - let key_images: Vec = tx_proposal.input_txos + let key_images: Vec = tx_proposal + .input_txos .iter() .map(|txo| txo.key_image.clone()) .collect(); @@ -245,7 +246,7 @@ mod tests { tx_proposal.payload_txos[0].tx_out.clone(), ], &key_images, - &mut rng + &mut rng, ); } diff --git a/full-service/src/test_utils.rs b/full-service/src/test_utils.rs index 3df49fa2d..cb76cc5dd 100644 --- a/full-service/src/test_utils.rs +++ b/full-service/src/test_utils.rs @@ -10,9 +10,8 @@ use crate::{ }, error::SyncError, service::{ - sync::sync_account, transaction::TransactionMemo, + models::tx_proposal::TxProposal, sync::sync_account, transaction::TransactionMemo, transaction_builder::WalletTransactionBuilder, - models::tx_proposal::TxProposal, }, WalletService, }; @@ -334,9 +333,14 @@ pub fn add_block_with_db_txos( let outputs: Vec = output_txo_ids .iter() .map(|txo_id_hex| { - let txo = &Txo::get(&txo_id_hex.to_string(), &wallet_db.get_conn().unwrap()) - .unwrap(); - ledger_db.get_tx_out_by_index(ledger_db.get_tx_out_index_by_public_key(&txo.public_key().unwrap()).unwrap()).unwrap() + let txo = &Txo::get(&txo_id_hex.to_string(), &wallet_db.get_conn().unwrap()).unwrap(); + ledger_db + .get_tx_out_by_index( + ledger_db + .get_tx_out_index_by_public_key(&txo.public_key().unwrap()) + .unwrap(), + ) + .unwrap() }) .collect(); @@ -480,9 +484,9 @@ pub fn transaction_log_from_create_test_minted_and_change_txos( value: u64, wallet_db: WalletDb, ledger_db: LedgerDB, -) -> TransactionLog -{ - let (tl, _) = create_test_minted_and_change_txos(src_account_key, recipient, value, wallet_db, ledger_db); +) -> TransactionLog { + let (tl, _) = + create_test_minted_and_change_txos(src_account_key, recipient, value, wallet_db, ledger_db); tl } @@ -492,16 +496,22 @@ pub fn tx_proposal_from_create_test_minted_and_change_txos( value: u64, wallet_db: WalletDb, ledger_db: LedgerDB, -) -> TxProposal -{ - let (_, txp) = create_test_minted_and_change_txos(src_account_key, recipient, value, wallet_db, ledger_db); +) -> TxProposal { + let (_, txp) = + create_test_minted_and_change_txos(src_account_key, recipient, value, wallet_db, ledger_db); txp } /// Creates a test minted and change txo. /// /// Returns (txproposal, ((output_txo_id, value), (change_txo_id, value))) -pub fn create_test_minted_and_change_txos(src_account_key: AccountKey, recipient: PublicAddress, value: u64, wallet_db: WalletDb, ledger_db: LedgerDB) -> (TransactionLog, TxProposal) { +pub fn create_test_minted_and_change_txos( + src_account_key: AccountKey, + recipient: PublicAddress, + value: u64, + wallet_db: WalletDb, + ledger_db: LedgerDB, +) -> (TransactionLog, TxProposal) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); // Use the builder to create valid TxOuts for this account @@ -521,15 +531,17 @@ pub fn create_test_minted_and_change_txos(src_account_key: AccountKey, recipient // There should be 2 outputs, one to dest and one change assert_eq!(tx_proposal.tx.prefix.outputs.len(), 2); - (TransactionLog::log_submitted( - &tx_proposal, - 10, - "".to_string(), - &AccountID::from(&src_account_key).to_string(), - &conn, - ) + ( + TransactionLog::log_submitted( + &tx_proposal, + 10, + "".to_string(), + &AccountID::from(&src_account_key).to_string(), + &conn, + ) .unwrap(), - tx_proposal) + tx_proposal, + ) } // Seed a local account with some Txos in the ledger From 1e7ed64a5b06307758b383071be3272f24ada6a0 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Fri, 21 Oct 2022 08:41:34 -0700 Subject: [PATCH 37/40] Remove transaction_log version of the create_test_minted_and_change_txos --- full-service/src/db/txo.rs | 11 +++-------- full-service/src/test_utils.rs | 12 ------------ 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/full-service/src/db/txo.rs b/full-service/src/db/txo.rs index ee2cae1c1..3ecdd57ab 100644 --- a/full-service/src/db/txo.rs +++ b/full-service/src/db/txo.rs @@ -1432,7 +1432,7 @@ mod tests { create_test_minted_and_change_txos, create_test_received_txo, create_test_txo_for_recipient, get_resolver_factory, get_test_ledger, manually_sync_account, random_account_with_seed_values, - transaction_log_from_create_test_minted_and_change_txos, WalletDbTestContext, MOB, + WalletDbTestContext, MOB, }, WalletDb, }; @@ -2095,13 +2095,8 @@ mod tests { assert_eq!(txos.len(), 12); - let transaction_log = transaction_log_from_create_test_minted_and_change_txos( - src_account.clone(), - recipient, - 1 * MOB, - wallet_db.clone(), - ledger_db, - ); + let (transaction_log, _) = + create_test_minted_and_change_txos(src_account.clone(), recipient, 1 * MOB, wallet_db.clone(), ledger_db); let associated_txos = transaction_log .get_associated_txos(&wallet_db.get_conn().unwrap()) diff --git a/full-service/src/test_utils.rs b/full-service/src/test_utils.rs index cb76cc5dd..6103cfec0 100644 --- a/full-service/src/test_utils.rs +++ b/full-service/src/test_utils.rs @@ -478,18 +478,6 @@ pub fn create_test_received_txo( (txo_id_hex, txo, key_image) } -pub fn transaction_log_from_create_test_minted_and_change_txos( - src_account_key: AccountKey, - recipient: PublicAddress, - value: u64, - wallet_db: WalletDb, - ledger_db: LedgerDB, -) -> TransactionLog { - let (tl, _) = - create_test_minted_and_change_txos(src_account_key, recipient, value, wallet_db, ledger_db); - tl -} - pub fn tx_proposal_from_create_test_minted_and_change_txos( src_account_key: AccountKey, recipient: PublicAddress, From 9a72b697519a3978f22da7d2fa26c9246b14a013 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Fri, 21 Oct 2022 08:42:16 -0700 Subject: [PATCH 38/40] Remove tx_proposal version of the create_test_minted_and_change_txos --- full-service/src/test_utils.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/full-service/src/test_utils.rs b/full-service/src/test_utils.rs index 6103cfec0..b5da43e16 100644 --- a/full-service/src/test_utils.rs +++ b/full-service/src/test_utils.rs @@ -478,18 +478,6 @@ pub fn create_test_received_txo( (txo_id_hex, txo, key_image) } -pub fn tx_proposal_from_create_test_minted_and_change_txos( - src_account_key: AccountKey, - recipient: PublicAddress, - value: u64, - wallet_db: WalletDb, - ledger_db: LedgerDB, -) -> TxProposal { - let (_, txp) = - create_test_minted_and_change_txos(src_account_key, recipient, value, wallet_db, ledger_db); - txp -} - /// Creates a test minted and change txo. /// /// Returns (txproposal, ((output_txo_id, value), (change_txo_id, value))) From ca094336ea5693ba3c3e535025ae3023775c7be3 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Fri, 21 Oct 2022 08:46:57 -0700 Subject: [PATCH 39/40] Remove unused test helper --- full-service/src/db/txo.rs | 2 +- full-service/src/test_utils.rs | 24 ------------------------ 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/full-service/src/db/txo.rs b/full-service/src/db/txo.rs index 3ecdd57ab..36648dc26 100644 --- a/full-service/src/db/txo.rs +++ b/full-service/src/db/txo.rs @@ -1428,7 +1428,7 @@ mod tests { transaction_builder::WalletTransactionBuilder, }, test_utils::{ - add_block_with_db_txos, add_block_with_tx, add_block_with_tx_outs, + add_block_with_tx, add_block_with_tx_outs, create_test_minted_and_change_txos, create_test_received_txo, create_test_txo_for_recipient, get_resolver_factory, get_test_ledger, manually_sync_account, random_account_with_seed_values, diff --git a/full-service/src/test_utils.rs b/full-service/src/test_utils.rs index b5da43e16..cd9dde483 100644 --- a/full-service/src/test_utils.rs +++ b/full-service/src/test_utils.rs @@ -323,30 +323,6 @@ pub fn setup_peer_manager_and_network_state( (peer_manager, network_state) } -pub fn add_block_with_db_txos( - ledger_db: &mut LedgerDB, - wallet_db: &WalletDb, - output_txo_ids: &[String], - key_images: &[KeyImage], - rng: &mut (impl CryptoRng + RngCore), -) -> u64 { - let outputs: Vec = output_txo_ids - .iter() - .map(|txo_id_hex| { - let txo = &Txo::get(&txo_id_hex.to_string(), &wallet_db.get_conn().unwrap()).unwrap(); - ledger_db - .get_tx_out_by_index( - ledger_db - .get_tx_out_index_by_public_key(&txo.public_key().unwrap()) - .unwrap(), - ) - .unwrap() - }) - .collect(); - - add_block_with_tx_outs(ledger_db, &outputs, key_images, rng) -} - // Sync account to most recent block pub fn manually_sync_account( ledger_db: &LedgerDB, From 8c6d7891a7a39763f2809abe82f3ef9bf1f15cd1 Mon Sep 17 00:00:00 2001 From: Pouneh Aghababazadeh Date: Fri, 21 Oct 2022 08:47:44 -0700 Subject: [PATCH 40/40] reformat: rustfmt --- full-service/src/db/txo.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/full-service/src/db/txo.rs b/full-service/src/db/txo.rs index 36648dc26..f03f7828c 100644 --- a/full-service/src/db/txo.rs +++ b/full-service/src/db/txo.rs @@ -1428,10 +1428,9 @@ mod tests { transaction_builder::WalletTransactionBuilder, }, test_utils::{ - add_block_with_tx, add_block_with_tx_outs, - create_test_minted_and_change_txos, create_test_received_txo, - create_test_txo_for_recipient, get_resolver_factory, get_test_ledger, - manually_sync_account, random_account_with_seed_values, + add_block_with_tx, add_block_with_tx_outs, create_test_minted_and_change_txos, + create_test_received_txo, create_test_txo_for_recipient, get_resolver_factory, + get_test_ledger, manually_sync_account, random_account_with_seed_values, WalletDbTestContext, MOB, }, WalletDb, @@ -2095,8 +2094,13 @@ mod tests { assert_eq!(txos.len(), 12); - let (transaction_log, _) = - create_test_minted_and_change_txos(src_account.clone(), recipient, 1 * MOB, wallet_db.clone(), ledger_db); + let (transaction_log, _) = create_test_minted_and_change_txos( + src_account.clone(), + recipient, + 1 * MOB, + wallet_db.clone(), + ledger_db, + ); let associated_txos = transaction_log .get_associated_txos(&wallet_db.get_conn().unwrap())