From cb29fa85d4d90bbb4d5408f316d4dc12e76b5f67 Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Tue, 19 Nov 2024 15:44:53 +0100 Subject: [PATCH 1/5] store unconfirmed change output --- Cargo.lock | 14 +++++++------- mm2src/coins/Cargo.toml | 12 ++++++------ mm2src/coins/z_coin.rs | 10 +++++++++- mm2src/coins/z_coin/storage.rs | 23 +++++++++++++++++++++++ mm2src/coins/z_coin/z_htlc.rs | 8 ++++++++ 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2bc1c3d543..91dc4338fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1826,7 +1826,7 @@ dependencies = [ [[package]] name = "equihash" version = "0.1.0" -source = "git+https://github.com/KomodoPlatform/librustzcash.git?tag=k-1.4.1#e92443a7bbd1c5e92e00e6deb45b5a33af14cea4" +source = "git+https://github.com/KomodoPlatform/librustzcash.git?branch=add-change-to-unspent#d78f4dfd7adaa259af8f37bb1803a7cad7ec6a1d" dependencies = [ "blake2b_simd", "byteorder", @@ -8191,7 +8191,7 @@ checksum = "0f9079049688da5871a7558ddacb7f04958862c703e68258594cb7a862b5e33f" [[package]] name = "zcash_client_backend" version = "0.5.0" -source = "git+https://github.com/KomodoPlatform/librustzcash.git?tag=k-1.4.1#e92443a7bbd1c5e92e00e6deb45b5a33af14cea4" +source = "git+https://github.com/KomodoPlatform/librustzcash.git?branch=add-change-to-unspent#d78f4dfd7adaa259af8f37bb1803a7cad7ec6a1d" dependencies = [ "async-trait", "base64 0.13.0", @@ -8216,7 +8216,7 @@ dependencies = [ [[package]] name = "zcash_client_sqlite" version = "0.3.0" -source = "git+https://github.com/KomodoPlatform/librustzcash.git?tag=k-1.4.1#e92443a7bbd1c5e92e00e6deb45b5a33af14cea4" +source = "git+https://github.com/KomodoPlatform/librustzcash.git?branch=add-change-to-unspent#d78f4dfd7adaa259af8f37bb1803a7cad7ec6a1d" dependencies = [ "async-trait", "bech32", @@ -8238,7 +8238,7 @@ dependencies = [ [[package]] name = "zcash_extras" version = "0.1.0" -source = "git+https://github.com/KomodoPlatform/librustzcash.git?tag=k-1.4.1#e92443a7bbd1c5e92e00e6deb45b5a33af14cea4" +source = "git+https://github.com/KomodoPlatform/librustzcash.git?branch=add-change-to-unspent#d78f4dfd7adaa259af8f37bb1803a7cad7ec6a1d" dependencies = [ "async-trait", "ff 0.8.0", @@ -8254,7 +8254,7 @@ dependencies = [ [[package]] name = "zcash_note_encryption" version = "0.0.0" -source = "git+https://github.com/KomodoPlatform/librustzcash.git?tag=k-1.4.1#e92443a7bbd1c5e92e00e6deb45b5a33af14cea4" +source = "git+https://github.com/KomodoPlatform/librustzcash.git?branch=add-change-to-unspent#d78f4dfd7adaa259af8f37bb1803a7cad7ec6a1d" dependencies = [ "blake2b_simd", "byteorder", @@ -8268,7 +8268,7 @@ dependencies = [ [[package]] name = "zcash_primitives" version = "0.5.0" -source = "git+https://github.com/KomodoPlatform/librustzcash.git?tag=k-1.4.1#e92443a7bbd1c5e92e00e6deb45b5a33af14cea4" +source = "git+https://github.com/KomodoPlatform/librustzcash.git?branch=add-change-to-unspent#d78f4dfd7adaa259af8f37bb1803a7cad7ec6a1d" dependencies = [ "aes 0.8.3", "bitvec 0.18.5", @@ -8298,7 +8298,7 @@ dependencies = [ [[package]] name = "zcash_proofs" version = "0.5.0" -source = "git+https://github.com/KomodoPlatform/librustzcash.git?tag=k-1.4.1#e92443a7bbd1c5e92e00e6deb45b5a33af14cea4" +source = "git+https://github.com/KomodoPlatform/librustzcash.git?branch=add-change-to-unspent#d78f4dfd7adaa259af8f37bb1803a7cad7ec6a1d" dependencies = [ "bellman", "blake2b_simd", diff --git a/mm2src/coins/Cargo.toml b/mm2src/coins/Cargo.toml index 290a0dd7f5..9cf47f7a97 100644 --- a/mm2src/coins/Cargo.toml +++ b/mm2src/coins/Cargo.toml @@ -110,9 +110,9 @@ uuid = { version = "1.2.2", features = ["fast-rng", "serde", "v4"] } # We don't need the default web3 features at all since we added our own web3 transport using shared HYPER instance. web3 = { git = "https://github.com/KomodoPlatform/rust-web3", tag = "v0.20.0", default-features = false } zbase32 = "0.1.2" -zcash_client_backend = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.4.1" } -zcash_extras = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.4.1" } -zcash_primitives = {features = ["transparent-inputs"], git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.4.1" } +zcash_client_backend = { git = "https://github.com/KomodoPlatform/librustzcash.git", branch = "add-change-to-unspent" } +zcash_extras = { git = "https://github.com/KomodoPlatform/librustzcash.git", branch = "add-change-to-unspent" } +zcash_primitives = {features = ["transparent-inputs"], git = "https://github.com/KomodoPlatform/librustzcash.git", branch = "add-change-to-unspent" } [target.'cfg(target_arch = "wasm32")'.dependencies] blake2b_simd = "0.5" @@ -131,7 +131,7 @@ wasm-bindgen = "0.2.86" wasm-bindgen-futures = { version = "0.4.1" } wasm-bindgen-test = { version = "0.3.2" } web-sys = { version = "0.3.55", features = ["console", "Headers", "Request", "RequestInit", "RequestMode", "Response", "Window"] } -zcash_proofs = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.4.1", default-features = false, features = ["local-prover"] } +zcash_proofs = { git = "https://github.com/KomodoPlatform/librustzcash.git", branch = "add-change-to-unspent", default-features = false, features = ["local-prover"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] dirs = { version = "1" } @@ -152,8 +152,8 @@ tokio = { version = "1.20" } tokio-rustls = { version = "0.24" } tonic = { version = "0.10", features = ["tls", "tls-webpki-roots", "gzip"] } webpki-roots = { version = "0.25" } -zcash_client_sqlite = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.4.1" } -zcash_proofs = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.4.1", default-features = false, features = ["local-prover", "multicore"] } +zcash_client_sqlite = { git = "https://github.com/KomodoPlatform/librustzcash.git", branch = "add-change-to-unspent" } +zcash_proofs = { git = "https://github.com/KomodoPlatform/librustzcash.git", branch = "add-change-to-unspent", default-features = false, features = ["local-prover", "multicore"] } [target.'cfg(windows)'.dependencies] winapi = "0.3" diff --git a/mm2src/coins/z_coin.rs b/mm2src/coins/z_coin.rs index b8c7c8c944..484852f9f5 100644 --- a/mm2src/coins/z_coin.rs +++ b/mm2src/coins/z_coin.rs @@ -93,6 +93,8 @@ use zcash_primitives::{constants::mainnet as z_mainnet_constants, sapling::Payme zip32::ExtendedFullViewingKey, zip32::ExtendedSpendingKey}; use zcash_proofs::prover::LocalTxProver; +use self::storage::store_change_output; + cfg_native!( use common::{async_blocking, sha256_digest}; use zcash_client_sqlite::error::SqliteClientError as ZcashClientError; @@ -208,8 +210,8 @@ pub struct ZCoinFields { z_tx_prover: Arc, light_wallet_db: WalletDbShared, consensus_params: ZcoinConsensusParams, - sync_state_connector: AsyncMutex, z_balance_event_handler: Option, + sync_state_connector: AsyncMutex, } impl Transaction for ZTransaction { @@ -474,6 +476,12 @@ impl ZCoin { .await? .tx_result?; + // Store any change outputs we created in this transaction by decrypting them with our keys + // and saving them to the wallet database for future spends + store_change_output(self.consensus_params_ref(), &self.z_fields.light_wallet_db, &zcash_tx) + .await + .error_log(); + let additional_data = AdditionalTxData { received_by_me, spent_by_me: sat_from_big_decimal(&total_input_amount, self.decimals())?, diff --git a/mm2src/coins/z_coin/storage.rs b/mm2src/coins/z_coin/storage.rs index b3c2c108c4..ccf9934f99 100644 --- a/mm2src/coins/z_coin/storage.rs +++ b/mm2src/coins/z_coin/storage.rs @@ -5,10 +5,13 @@ pub use blockdb::*; pub mod walletdb; #[cfg(target_arch = "wasm32")] mod z_params; +use mm2_err_handle::prelude::MapToMmResult; #[cfg(target_arch = "wasm32")] pub(crate) use z_params::ZcashParamsWasmImpl; pub use walletdb::*; +use zcash_extras::wallet::decrypt_and_store_transaction; +use zcash_primitives::transaction::Transaction; use crate::z_coin::z_balance_streaming::ZBalanceEventSender; use mm2_err_handle::mm_error::MmResult; @@ -190,3 +193,23 @@ pub async fn scan_cached_block( // If there are any transactions in the block, return the transaction count Ok(txs.len()) } + +/// Processes and stores any change outputs created in the transaction by: +/// - Decrypting outputs using wallet viewing keys +/// - Adding decrypted change notes to the wallet database +/// - Making change notes available for future spends +pub(crate) async fn store_change_output( + params: &ZcoinConsensusParams, + shared_db: &WalletDbShared, + tx: &Transaction, +) -> MmResult<(), String> { + let mut data = shared_db + .db + .get_update_ops() + .map_to_mm(|err| "WalletDbShared failed unexpectedly".to_string())?; + decrypt_and_store_transaction(params, &mut data, &tx) + .await + .map_to_mm(|err| err.to_string())?; + + Ok(()) +} diff --git a/mm2src/coins/z_coin/z_htlc.rs b/mm2src/coins/z_coin/z_htlc.rs index c2fba37a88..c50d897777 100644 --- a/mm2src/coins/z_coin/z_htlc.rs +++ b/mm2src/coins/z_coin/z_htlc.rs @@ -5,6 +5,7 @@ // taker payment spend - https://zombie.explorer.lordofthechains.com/tx/af6bb0f99f9a5a070a0c1f53d69e4189b0e9b68f9d66e69f201a6b6d9f93897e // maker payment spend - https://rick.explorer.dexstats.info/tx/6a2dcc866ad75cebecb780a02320073a88bcf5e57ddccbe2657494e7747d591e +use super::storage::store_change_output; use super::{GenTxError, ZCoin}; use crate::utxo::rpc_clients::{UtxoRpcClientEnum, UtxoRpcError}; use crate::utxo::utxo_common::payment_script; @@ -14,6 +15,7 @@ use crate::z_coin::{ZOutput, DEX_FEE_OVK}; use crate::NumConversError; use crate::{PrivKeyPolicyNotAllowed, TransactionEnum}; use bitcrypto::dhash160; +use common::log::LogOnError; use derive_more::Display; use futures::compat::Future01CompatExt; use keys::{AddressBuilder, KeyPair, Public}; @@ -190,6 +192,12 @@ pub async fn z_p2sh_spend( let mut tx_buffer = Vec::with_capacity(1024); zcash_tx.write(&mut tx_buffer)?; + // Store any change outputs we created in this transaction by decrypting them with our keys + // and saving them to the wallet database for future spends + store_change_output(coin.consensus_params_ref(), &coin.z_fields.light_wallet_db, &zcash_tx) + .await + .error_log(); + coin.utxo_rpc_client() .send_raw_transaction(tx_buffer.into()) .compat() From 171cefc72facf43b685aee64ee3c1634bef57ece Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Tue, 19 Nov 2024 16:00:54 +0100 Subject: [PATCH 2/5] log on error --- mm2src/coins/z_coin.rs | 3 ++- mm2src/coins/z_coin/storage.rs | 12 +++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/mm2src/coins/z_coin.rs b/mm2src/coins/z_coin.rs index 484852f9f5..cca9712257 100644 --- a/mm2src/coins/z_coin.rs +++ b/mm2src/coins/z_coin.rs @@ -8,6 +8,7 @@ mod z_rpc; mod z_tx_history; use crate::coin_errors::{MyAddressError, ValidatePaymentResult}; +use crate::common::log::LogOnError; use crate::hd_wallet::HDPathAccountToAddressId; use crate::my_tx_history_v2::{MyTxHistoryErrorV2, MyTxHistoryRequestV2, MyTxHistoryResponseV2}; use crate::rpc_command::init_withdraw::{InitWithdrawCoin, WithdrawInProgressStatus, WithdrawTaskHandleShared}; @@ -478,7 +479,7 @@ impl ZCoin { // Store any change outputs we created in this transaction by decrypting them with our keys // and saving them to the wallet database for future spends - store_change_output(self.consensus_params_ref(), &self.z_fields.light_wallet_db, &zcash_tx) + store_change_output(self.consensus_params_ref(), &self.z_fields.light_wallet_db, &tx) .await .error_log(); diff --git a/mm2src/coins/z_coin/storage.rs b/mm2src/coins/z_coin/storage.rs index ccf9934f99..8c29f81f33 100644 --- a/mm2src/coins/z_coin/storage.rs +++ b/mm2src/coins/z_coin/storage.rs @@ -5,7 +5,6 @@ pub use blockdb::*; pub mod walletdb; #[cfg(target_arch = "wasm32")] mod z_params; -use mm2_err_handle::prelude::MapToMmResult; #[cfg(target_arch = "wasm32")] pub(crate) use z_params::ZcashParamsWasmImpl; @@ -202,14 +201,9 @@ pub(crate) async fn store_change_output( params: &ZcoinConsensusParams, shared_db: &WalletDbShared, tx: &Transaction, -) -> MmResult<(), String> { - let mut data = shared_db - .db - .get_update_ops() - .map_to_mm(|err| "WalletDbShared failed unexpectedly".to_string())?; - decrypt_and_store_transaction(params, &mut data, &tx) - .await - .map_to_mm(|err| err.to_string())?; +) -> Result<(), String> { + let mut data = try_s!(shared_db.db.get_update_ops()); + try_s!(decrypt_and_store_transaction(params, &mut data, tx).await); Ok(()) } From 3787b9306433831df9cc594d5b987cbc47407d4a Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Thu, 5 Dec 2024 15:44:36 +0100 Subject: [PATCH 3/5] use MmError and return error if change notes saving changes --- mm2src/coins/z_coin.rs | 3 +-- mm2src/coins/z_coin/storage.rs | 9 ++++++--- mm2src/coins/z_coin/z_coin_errors.rs | 2 -- mm2src/coins/z_coin/z_htlc.rs | 3 +-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/mm2src/coins/z_coin.rs b/mm2src/coins/z_coin.rs index cca9712257..6b539b0680 100644 --- a/mm2src/coins/z_coin.rs +++ b/mm2src/coins/z_coin.rs @@ -8,7 +8,6 @@ mod z_rpc; mod z_tx_history; use crate::coin_errors::{MyAddressError, ValidatePaymentResult}; -use crate::common::log::LogOnError; use crate::hd_wallet::HDPathAccountToAddressId; use crate::my_tx_history_v2::{MyTxHistoryErrorV2, MyTxHistoryRequestV2, MyTxHistoryResponseV2}; use crate::rpc_command::init_withdraw::{InitWithdrawCoin, WithdrawInProgressStatus, WithdrawTaskHandleShared}; @@ -481,7 +480,7 @@ impl ZCoin { // and saving them to the wallet database for future spends store_change_output(self.consensus_params_ref(), &self.z_fields.light_wallet_db, &tx) .await - .error_log(); + .mm_err(GenTxError::Internal)?; let additional_data = AdditionalTxData { received_by_me, diff --git a/mm2src/coins/z_coin/storage.rs b/mm2src/coins/z_coin/storage.rs index 8c29f81f33..5699a86ade 100644 --- a/mm2src/coins/z_coin/storage.rs +++ b/mm2src/coins/z_coin/storage.rs @@ -5,6 +5,7 @@ pub use blockdb::*; pub mod walletdb; #[cfg(target_arch = "wasm32")] mod z_params; +use mm2_err_handle::prelude::MapToMmResult; #[cfg(target_arch = "wasm32")] pub(crate) use z_params::ZcashParamsWasmImpl; @@ -201,9 +202,11 @@ pub(crate) async fn store_change_output( params: &ZcoinConsensusParams, shared_db: &WalletDbShared, tx: &Transaction, -) -> Result<(), String> { - let mut data = try_s!(shared_db.db.get_update_ops()); - try_s!(decrypt_and_store_transaction(params, &mut data, tx).await); +) -> MmResult<(), String> { + let mut data = shared_db.db.get_update_ops().map_to_mm(|err| err.to_string())?; + decrypt_and_store_transaction(params, &mut data, tx) + .await + .map_to_mm(|err| err.to_string())?; Ok(()) } diff --git a/mm2src/coins/z_coin/z_coin_errors.rs b/mm2src/coins/z_coin/z_coin_errors.rs index 7fcf06cb12..4e8fb2c3bf 100644 --- a/mm2src/coins/z_coin/z_coin_errors.rs +++ b/mm2src/coins/z_coin/z_coin_errors.rs @@ -129,7 +129,6 @@ pub enum GenTxError { LightClientErr(String), FailedToCreateNote, SpendableNotesError(String), - #[cfg(target_arch = "wasm32")] Internal(String), } @@ -178,7 +177,6 @@ impl From for WithdrawError { | GenTxError::LightClientErr(_) | GenTxError::SpendableNotesError(_) | GenTxError::FailedToCreateNote => WithdrawError::InternalError(gen_tx.to_string()), - #[cfg(target_arch = "wasm32")] GenTxError::Internal(_) => WithdrawError::InternalError(gen_tx.to_string()), } } diff --git a/mm2src/coins/z_coin/z_htlc.rs b/mm2src/coins/z_coin/z_htlc.rs index c50d897777..dc9b8ba5fd 100644 --- a/mm2src/coins/z_coin/z_htlc.rs +++ b/mm2src/coins/z_coin/z_htlc.rs @@ -15,7 +15,6 @@ use crate::z_coin::{ZOutput, DEX_FEE_OVK}; use crate::NumConversError; use crate::{PrivKeyPolicyNotAllowed, TransactionEnum}; use bitcrypto::dhash160; -use common::log::LogOnError; use derive_more::Display; use futures::compat::Future01CompatExt; use keys::{AddressBuilder, KeyPair, Public}; @@ -196,7 +195,7 @@ pub async fn z_p2sh_spend( // and saving them to the wallet database for future spends store_change_output(coin.consensus_params_ref(), &coin.z_fields.light_wallet_db, &zcash_tx) .await - .error_log(); + .mm_err(|err| ZP2SHSpendError::GenTxError(GenTxError::Internal(err)))?; coin.utxo_rpc_client() .send_raw_transaction(tx_buffer.into()) From 583de6a721feae5ecfc612d8f9b4436ef8b6c8d7 Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Tue, 10 Dec 2024 22:59:53 +0100 Subject: [PATCH 4/5] use better error naming for save change notes --- mm2src/coins/z_coin.rs | 2 +- mm2src/coins/z_coin/z_coin_errors.rs | 6 ++++-- mm2src/coins/z_coin/z_htlc.rs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mm2src/coins/z_coin.rs b/mm2src/coins/z_coin.rs index 6b539b0680..7e3b02ff64 100644 --- a/mm2src/coins/z_coin.rs +++ b/mm2src/coins/z_coin.rs @@ -480,7 +480,7 @@ impl ZCoin { // and saving them to the wallet database for future spends store_change_output(self.consensus_params_ref(), &self.z_fields.light_wallet_db, &tx) .await - .mm_err(GenTxError::Internal)?; + .mm_err(GenTxError::SaveChangeNotesError)?; let additional_data = AdditionalTxData { received_by_me, diff --git a/mm2src/coins/z_coin/z_coin_errors.rs b/mm2src/coins/z_coin/z_coin_errors.rs index 4e8fb2c3bf..ac4aa8d295 100644 --- a/mm2src/coins/z_coin/z_coin_errors.rs +++ b/mm2src/coins/z_coin/z_coin_errors.rs @@ -130,6 +130,7 @@ pub enum GenTxError { FailedToCreateNote, SpendableNotesError(String), Internal(String), + SaveChangeNotesError(String), } impl From for GenTxError { @@ -176,8 +177,9 @@ impl From for WithdrawError { | GenTxError::BlockchainScanStopped | GenTxError::LightClientErr(_) | GenTxError::SpendableNotesError(_) - | GenTxError::FailedToCreateNote => WithdrawError::InternalError(gen_tx.to_string()), - GenTxError::Internal(_) => WithdrawError::InternalError(gen_tx.to_string()), + | GenTxError::FailedToCreateNote + | GenTxError::Internal(_) + | GenTxError::SaveChangeNotesError(_) => WithdrawError::InternalError(gen_tx.to_string()), } } } diff --git a/mm2src/coins/z_coin/z_htlc.rs b/mm2src/coins/z_coin/z_htlc.rs index dc9b8ba5fd..50052424c3 100644 --- a/mm2src/coins/z_coin/z_htlc.rs +++ b/mm2src/coins/z_coin/z_htlc.rs @@ -195,7 +195,7 @@ pub async fn z_p2sh_spend( // and saving them to the wallet database for future spends store_change_output(coin.consensus_params_ref(), &coin.z_fields.light_wallet_db, &zcash_tx) .await - .mm_err(|err| ZP2SHSpendError::GenTxError(GenTxError::Internal(err)))?; + .mm_err(|err| ZP2SHSpendError::GenTxError(GenTxError::SaveChangeNotesError(err)))?; coin.utxo_rpc_client() .send_raw_transaction(tx_buffer.into()) From 00e7148c38794016a0b01f6165ae81aa7a2ad4ea Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Tue, 10 Dec 2024 23:53:41 +0100 Subject: [PATCH 5/5] minor changes to error --- mm2src/coins/z_coin.rs | 2 +- mm2src/coins/z_coin/storage.rs | 9 +++------ mm2src/coins/z_coin/z_htlc.rs | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/mm2src/coins/z_coin.rs b/mm2src/coins/z_coin.rs index 7e3b02ff64..8f52649a3d 100644 --- a/mm2src/coins/z_coin.rs +++ b/mm2src/coins/z_coin.rs @@ -480,7 +480,7 @@ impl ZCoin { // and saving them to the wallet database for future spends store_change_output(self.consensus_params_ref(), &self.z_fields.light_wallet_db, &tx) .await - .mm_err(GenTxError::SaveChangeNotesError)?; + .map_to_mm(GenTxError::SaveChangeNotesError)?; let additional_data = AdditionalTxData { received_by_me, diff --git a/mm2src/coins/z_coin/storage.rs b/mm2src/coins/z_coin/storage.rs index 5699a86ade..8c29f81f33 100644 --- a/mm2src/coins/z_coin/storage.rs +++ b/mm2src/coins/z_coin/storage.rs @@ -5,7 +5,6 @@ pub use blockdb::*; pub mod walletdb; #[cfg(target_arch = "wasm32")] mod z_params; -use mm2_err_handle::prelude::MapToMmResult; #[cfg(target_arch = "wasm32")] pub(crate) use z_params::ZcashParamsWasmImpl; @@ -202,11 +201,9 @@ pub(crate) async fn store_change_output( params: &ZcoinConsensusParams, shared_db: &WalletDbShared, tx: &Transaction, -) -> MmResult<(), String> { - let mut data = shared_db.db.get_update_ops().map_to_mm(|err| err.to_string())?; - decrypt_and_store_transaction(params, &mut data, tx) - .await - .map_to_mm(|err| err.to_string())?; +) -> Result<(), String> { + let mut data = try_s!(shared_db.db.get_update_ops()); + try_s!(decrypt_and_store_transaction(params, &mut data, tx).await); Ok(()) } diff --git a/mm2src/coins/z_coin/z_htlc.rs b/mm2src/coins/z_coin/z_htlc.rs index 50052424c3..bd32389f51 100644 --- a/mm2src/coins/z_coin/z_htlc.rs +++ b/mm2src/coins/z_coin/z_htlc.rs @@ -195,7 +195,7 @@ pub async fn z_p2sh_spend( // and saving them to the wallet database for future spends store_change_output(coin.consensus_params_ref(), &coin.z_fields.light_wallet_db, &zcash_tx) .await - .mm_err(|err| ZP2SHSpendError::GenTxError(GenTxError::SaveChangeNotesError(err)))?; + .map_to_mm(|err| ZP2SHSpendError::GenTxError(GenTxError::SaveChangeNotesError(err)))?; coin.utxo_rpc_client() .send_raw_transaction(tx_buffer.into())