From ec3d08a710688eab3fa81a0d8b4bc6d3d98124ab Mon Sep 17 00:00:00 2001 From: antiochp <30642645+antiochp@users.noreply.github.com> Date: Mon, 19 Aug 2019 16:35:05 +0100 Subject: [PATCH] translate to/from TransactionV2 correctly in owner api and foreign api --- api/src/foreign_rpc.rs | 27 ++++++++-------- api/src/owner_rpc.rs | 35 ++++++++++---------- api/src/owner_rpc_s.rs | 53 +++++++++++++++++++------------ impls/src/test_framework/mod.rs | 4 +-- libwallet/src/api_impl/types.rs | 5 +-- libwallet/src/internal/updater.rs | 3 +- 6 files changed, 72 insertions(+), 55 deletions(-) diff --git a/api/src/foreign_rpc.rs b/api/src/foreign_rpc.rs index a71cc6db5..2028c11ba 100644 --- a/api/src/foreign_rpc.rs +++ b/api/src/foreign_rpc.rs @@ -192,7 +192,7 @@ pub trait ForeignRpc { # ,false, 1 ,false, false); ``` */ - fn verify_slate_messages(&self, slate: &Slate) -> Result<(), ErrorKind>; + fn verify_slate_messages(&self, slate: VersionedSlate) -> Result<(), ErrorKind>; /** Networked version of [Foreign::receive_tx](struct.Foreign.html#method.receive_tx). @@ -513,7 +513,7 @@ pub trait ForeignRpc { # ,false, 5, false, true); ``` */ - fn finalize_invoice_tx(&self, slate: &Slate) -> Result; + fn finalize_invoice_tx(&self, slate: VersionedSlate) -> Result; } impl<'a, L, C, K> ForeignRpc for Foreign<'a, L, C, K> @@ -530,31 +530,32 @@ where Foreign::build_coinbase(self, block_fees).map_err(|e| e.kind()) } - fn verify_slate_messages(&self, slate: &Slate) -> Result<(), ErrorKind> { - Foreign::verify_slate_messages(self, slate).map_err(|e| e.kind()) + fn verify_slate_messages(&self, slate: VersionedSlate) -> Result<(), ErrorKind> { + Foreign::verify_slate_messages(self, &Slate::from(slate)).map_err(|e| e.kind()) } fn receive_tx( &self, - slate: VersionedSlate, + in_slate: VersionedSlate, dest_acct_name: Option, message: Option, ) -> Result { - let version = slate.version(); - let slate: Slate = slate.into(); - let slate = Foreign::receive_tx( + let version = in_slate.version(); + let out_slate = Foreign::receive_tx( self, - &slate, + &Slate::from(in_slate), dest_acct_name.as_ref().map(String::as_str), message, ) .map_err(|e| e.kind())?; - - Ok(VersionedSlate::into_version(slate, version)) + Ok(VersionedSlate::into_version(out_slate, version)) } - fn finalize_invoice_tx(&self, slate: &Slate) -> Result { - Foreign::finalize_invoice_tx(self, slate).map_err(|e| e.kind()) + fn finalize_invoice_tx(&self, in_slate: VersionedSlate) -> Result { + let version = in_slate.version(); + let out_slate = + Foreign::finalize_invoice_tx(self, &Slate::from(in_slate)).map_err(|e| e.kind())?; + Ok(VersionedSlate::into_version(out_slate, version)) } } diff --git a/api/src/owner_rpc.rs b/api/src/owner_rpc.rs index 5ec3be385..b7a42568d 100644 --- a/api/src/owner_rpc.rs +++ b/api/src/owner_rpc.rs @@ -17,6 +17,7 @@ use uuid::Uuid; use crate::core::core::Transaction; use crate::keychain::{Identifier, Keychain}; +use crate::libwallet::slate_versions::v2::TransactionV2; use crate::libwallet::{ AcctPathMapping, ErrorKind, InitTxArgs, IssueInvoiceTxArgs, NodeClient, NodeHeightResult, OutputCommitMapping, Slate, SlateVersion, TxLogEntry, VersionedSlate, WalletInfo, @@ -949,7 +950,7 @@ pub trait OwnerRpc: Sync + Send { ``` */ - fn post_tx(&self, tx: &Transaction, fluff: bool) -> Result<(), ErrorKind>; + fn post_tx(&self, tx: TransactionV2, fluff: bool) -> Result<(), ErrorKind>; /** Networked version of [Owner::cancel_tx](struct.Owner.html#method.cancel_tx). @@ -1073,7 +1074,7 @@ pub trait OwnerRpc: Sync + Send { # , false, 5, true, true, false); ``` */ - fn get_stored_tx(&self, tx: &TxLogEntry) -> Result, ErrorKind>; + fn get_stored_tx(&self, tx: &TxLogEntry) -> Result, ErrorKind>; /** Networked version of [Owner::verify_slate_messages](struct.Owner.html#method.verify_slate_messages). @@ -1304,19 +1305,18 @@ where fn process_invoice_tx( &self, - slate: VersionedSlate, + in_slate: VersionedSlate, args: InitTxArgs, ) -> Result { - let in_slate = Slate::from(slate); - let out_slate = - Owner::process_invoice_tx(self, None, &in_slate, args).map_err(|e| e.kind())?; + let out_slate = Owner::process_invoice_tx(self, None, &Slate::from(in_slate), args) + .map_err(|e| e.kind())?; let version = SlateVersion::V2; Ok(VersionedSlate::into_version(out_slate, version)) } - fn finalize_tx(&self, slate: VersionedSlate) -> Result { - let in_slate = Slate::from(slate); - let out_slate = Owner::finalize_tx(self, None, &in_slate).map_err(|e| e.kind())?; + fn finalize_tx(&self, in_slate: VersionedSlate) -> Result { + let out_slate = + Owner::finalize_tx(self, None, &Slate::from(in_slate)).map_err(|e| e.kind())?; let version = SlateVersion::V2; Ok(VersionedSlate::into_version(out_slate, version)) } @@ -1326,25 +1326,26 @@ where slate: VersionedSlate, participant_id: usize, ) -> Result<(), ErrorKind> { - let in_slate = Slate::from(slate); - Owner::tx_lock_outputs(self, None, &in_slate, participant_id).map_err(|e| e.kind()) + Owner::tx_lock_outputs(self, None, &Slate::from(slate), participant_id) + .map_err(|e| e.kind()) } fn cancel_tx(&self, tx_id: Option, tx_slate_id: Option) -> Result<(), ErrorKind> { Owner::cancel_tx(self, None, tx_id, tx_slate_id).map_err(|e| e.kind()) } - fn get_stored_tx(&self, tx: &TxLogEntry) -> Result, ErrorKind> { - Owner::get_stored_tx(self, None, tx).map_err(|e| e.kind()) + fn get_stored_tx(&self, tx: &TxLogEntry) -> Result, ErrorKind> { + Owner::get_stored_tx(self, None, tx) + .map(|x| x.map(|y| TransactionV2::from(y))) + .map_err(|e| e.kind()) } - fn post_tx(&self, tx: &Transaction, fluff: bool) -> Result<(), ErrorKind> { - Owner::post_tx(self, None, tx, fluff).map_err(|e| e.kind()) + fn post_tx(&self, tx: TransactionV2, fluff: bool) -> Result<(), ErrorKind> { + Owner::post_tx(self, None, &Transaction::from(tx), fluff).map_err(|e| e.kind()) } fn verify_slate_messages(&self, slate: VersionedSlate) -> Result<(), ErrorKind> { - let in_slate = Slate::from(slate); - Owner::verify_slate_messages(self, None, &in_slate).map_err(|e| e.kind()) + Owner::verify_slate_messages(self, None, &Slate::from(slate)).map_err(|e| e.kind()) } fn restore(&self) -> Result<(), ErrorKind> { diff --git a/api/src/owner_rpc_s.rs b/api/src/owner_rpc_s.rs index 2861ee686..8ee4fb710 100644 --- a/api/src/owner_rpc_s.rs +++ b/api/src/owner_rpc_s.rs @@ -17,6 +17,7 @@ use uuid::Uuid; use crate::core::core::Transaction; use crate::keychain::{Identifier, Keychain}; +use crate::libwallet::slate_versions::v2::TransactionV2; use crate::libwallet::{ AcctPathMapping, ErrorKind, InitTxArgs, IssueInvoiceTxArgs, NodeClient, NodeHeightResult, OutputCommitMapping, Slate, SlateVersion, TxLogEntry, VersionedSlate, WalletInfo, @@ -987,7 +988,7 @@ pub trait OwnerRpcS { ``` */ - fn post_tx(&self, token: Token, tx: &Transaction, fluff: bool) -> Result<(), ErrorKind>; + fn post_tx(&self, token: Token, tx: TransactionV2, fluff: bool) -> Result<(), ErrorKind>; /** Networked version of [Owner::cancel_tx](struct.Owner.html#method.cancel_tx). @@ -1125,7 +1126,7 @@ pub trait OwnerRpcS { &self, token: Token, tx: &TxLogEntry, - ) -> Result, ErrorKind>; + ) -> Result, ErrorKind>; /** Networked version of [Owner::verify_slate_messages](struct.Owner.html#method.verify_slate_messages). @@ -1402,13 +1403,16 @@ where fn process_invoice_tx( &self, token: Token, - slate: VersionedSlate, + in_slate: VersionedSlate, args: InitTxArgs, ) -> Result { - let in_slate = Slate::from(slate); - let out_slate = - Owner::process_invoice_tx(self, (&token.keychain_mask).as_ref(), &in_slate, args) - .map_err(|e| e.kind())?; + let out_slate = Owner::process_invoice_tx( + self, + (&token.keychain_mask).as_ref(), + &Slate::from(in_slate), + args, + ) + .map_err(|e| e.kind())?; let version = SlateVersion::V2; Ok(VersionedSlate::into_version(out_slate, version)) } @@ -1416,11 +1420,14 @@ where fn finalize_tx( &self, token: Token, - slate: VersionedSlate, + in_slate: VersionedSlate, ) -> Result { - let in_slate = Slate::from(slate); - let out_slate = Owner::finalize_tx(self, (&token.keychain_mask).as_ref(), &in_slate) - .map_err(|e| e.kind())?; + let out_slate = Owner::finalize_tx( + self, + (&token.keychain_mask).as_ref(), + &Slate::from(in_slate), + ) + .map_err(|e| e.kind())?; let version = SlateVersion::V2; Ok(VersionedSlate::into_version(out_slate, version)) } @@ -1428,14 +1435,13 @@ where fn tx_lock_outputs( &self, token: Token, - slate: VersionedSlate, + in_slate: VersionedSlate, participant_id: usize, ) -> Result<(), ErrorKind> { - let in_slate = Slate::from(slate); Owner::tx_lock_outputs( self, (&token.keychain_mask).as_ref(), - &in_slate, + &Slate::from(in_slate), participant_id, ) .map_err(|e| e.kind()) @@ -1455,17 +1461,24 @@ where &self, token: Token, tx: &TxLogEntry, - ) -> Result, ErrorKind> { - Owner::get_stored_tx(self, (&token.keychain_mask).as_ref(), tx).map_err(|e| e.kind()) + ) -> Result, ErrorKind> { + Owner::get_stored_tx(self, (&token.keychain_mask).as_ref(), tx) + .map(|x| x.map(|y| TransactionV2::from(y))) + .map_err(|e| e.kind()) } - fn post_tx(&self, token: Token, tx: &Transaction, fluff: bool) -> Result<(), ErrorKind> { - Owner::post_tx(self, (&token.keychain_mask).as_ref(), tx, fluff).map_err(|e| e.kind()) + fn post_tx(&self, token: Token, tx: TransactionV2, fluff: bool) -> Result<(), ErrorKind> { + Owner::post_tx( + self, + (&token.keychain_mask).as_ref(), + &Transaction::from(tx), + fluff, + ) + .map_err(|e| e.kind()) } fn verify_slate_messages(&self, token: Token, slate: VersionedSlate) -> Result<(), ErrorKind> { - let in_slate = Slate::from(slate); - Owner::verify_slate_messages(self, (&token.keychain_mask).as_ref(), &in_slate) + Owner::verify_slate_messages(self, (&token.keychain_mask).as_ref(), &Slate::from(slate)) .map_err(|e| e.kind()) } diff --git a/impls/src/test_framework/mod.rs b/impls/src/test_framework/mod.rs index 3e8a8b593..08fe970e2 100644 --- a/impls/src/test_framework/mod.rs +++ b/impls/src/test_framework/mod.rs @@ -16,7 +16,7 @@ use crate::api; use crate::chain; use crate::chain::Chain; use crate::core; -use crate::core::core::{OutputFeatures, OutputIdentifier, Transaction}; +use crate::core::core::{OutputFeatures, OutputIdentifier, Transaction, TxKernel}; use crate::core::{consensus, global, pow}; use crate::keychain; use crate::libwallet; @@ -82,7 +82,7 @@ pub fn add_block_with_reward(chain: &Chain, txs: Vec<&Transaction>, reward: CbDa &prev, txs.into_iter().cloned().collect(), next_header_info.clone().difficulty, - (reward.output, reward.kernel), + (reward.output, TxKernel::from(&reward.kernel)), ) .unwrap(); b.header.timestamp = prev.timestamp + Duration::seconds(60); diff --git a/libwallet/src/api_impl/types.rs b/libwallet/src/api_impl/types.rs index 07e7f0afe..d74aa65d5 100644 --- a/libwallet/src/api_impl/types.rs +++ b/libwallet/src/api_impl/types.rs @@ -14,10 +14,11 @@ //! Types specific to the wallet api, mostly argument serialization -use crate::grin_core::core::{Output, TxKernel}; +use crate::grin_core::core::Output; use crate::grin_core::libtx::secp_ser; use crate::grin_keychain::Identifier; use crate::grin_util::secp::pedersen; +use crate::slate_versions::v2::TxKernelV2; use crate::slate_versions::SlateVersion; use crate::types::OutputData; @@ -185,7 +186,7 @@ pub struct CbData { /// Output pub output: Output, /// Kernel - pub kernel: TxKernel, + pub kernel: TxKernelV2, /// Key Id pub key_id: Option, } diff --git a/libwallet/src/internal/updater.rs b/libwallet/src/internal/updater.rs index 3306afc6c..b9525151c 100644 --- a/libwallet/src/internal/updater.rs +++ b/libwallet/src/internal/updater.rs @@ -29,6 +29,7 @@ use crate::grin_util as util; use crate::grin_util::secp::key::SecretKey; use crate::grin_util::secp::pedersen; use crate::internal::keys; +use crate::slate_versions::v2::TxKernelV2; use crate::types::{ NodeClient, OutputData, OutputStatus, TxLogEntry, TxLogEntryType, WalletBackend, WalletInfo, }; @@ -467,7 +468,7 @@ where Ok(CbData { output: out, - kernel: kern, + kernel: TxKernelV2::from(&kern), key_id: block_fees.key_id, }) }