From 5cdd4122050f21bc47a3a0707958fcd82cefa746 Mon Sep 17 00:00:00 2001 From: Antioch Peverell Date: Tue, 6 Aug 2019 11:34:59 +0100 Subject: [PATCH] use VersionedSlate for the owner_rpc api (#202) --- api/src/owner_rpc.rs | 67 +++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/api/src/owner_rpc.rs b/api/src/owner_rpc.rs index 05c283708..f8134630b 100644 --- a/api/src/owner_rpc.rs +++ b/api/src/owner_rpc.rs @@ -19,7 +19,8 @@ use crate::core::core::Transaction; use crate::keychain::{Identifier, Keychain}; use crate::libwallet::{ AcctPathMapping, ErrorKind, InitTxArgs, IssueInvoiceTxArgs, NodeClient, NodeHeightResult, - OutputCommitMapping, Slate, TxLogEntry, WalletInfo, WalletLCProvider, + OutputCommitMapping, Slate, SlateVersion, TxLogEntry, VersionedSlate, WalletInfo, + WalletLCProvider, }; use crate::util::Mutex; use crate::Owner; @@ -403,7 +404,7 @@ pub trait OwnerRpc { ``` */ - fn init_send_tx(&self, args: InitTxArgs) -> Result; + fn init_send_tx(&self, args: InitTxArgs) -> Result; /** Networked version of [Owner::issue_invoice_tx](struct.Owner.html#method.issue_invoice_tx). @@ -483,7 +484,7 @@ pub trait OwnerRpc { ``` */ - fn issue_invoice_tx(&self, args: IssueInvoiceTxArgs) -> Result; + fn issue_invoice_tx(&self, args: IssueInvoiceTxArgs) -> Result; /** Networked version of [Owner::process_invoice_tx](struct.Owner.html#method.process_invoice_tx). @@ -631,7 +632,11 @@ pub trait OwnerRpc { ``` */ - fn process_invoice_tx(&self, slate: &Slate, args: InitTxArgs) -> Result; + fn process_invoice_tx( + &self, + slate: VersionedSlate, + args: InitTxArgs, + ) -> Result; /** Networked version of [Owner::tx_lock_outputs](struct.Owner.html#method.tx_lock_outputs). @@ -711,7 +716,11 @@ pub trait OwnerRpc { ``` */ - fn tx_lock_outputs(&self, slate: Slate, participant_id: usize) -> Result<(), ErrorKind>; + fn tx_lock_outputs( + &self, + slate: VersionedSlate, + participant_id: usize, + ) -> Result<(), ErrorKind>; /** Networked version of [Owner::finalize_tx](struct.Owner.html#method.finalize_tx). @@ -873,7 +882,7 @@ pub trait OwnerRpc { # , 5, true, true, false); ``` */ - fn finalize_tx(&self, slate: Slate) -> Result; + fn finalize_tx(&self, slate: VersionedSlate) -> Result; /** Networked version of [Owner::post_tx](struct.Owner.html#method.post_tx). @@ -1142,7 +1151,7 @@ pub trait OwnerRpc { # ,5 ,true, false, false); ``` */ - fn verify_slate_messages(&self, slate: &Slate) -> Result<(), ErrorKind>; + fn verify_slate_messages(&self, slate: VersionedSlate) -> Result<(), ErrorKind>; /** Networked version of [Owner::restore](struct.Owner.html#method.restore). @@ -1280,24 +1289,43 @@ where .map_err(|e| e.kind()) } - fn init_send_tx(&self, args: InitTxArgs) -> Result { - Owner::init_send_tx(self, args).map_err(|e| e.kind()) + fn init_send_tx(&self, args: InitTxArgs) -> Result { + let slate = Owner::init_send_tx(self, args).map_err(|e| e.kind())?; + let version = SlateVersion::V2; + Ok(VersionedSlate::into_version(slate, version)) } - fn issue_invoice_tx(&self, args: IssueInvoiceTxArgs) -> Result { - Owner::issue_invoice_tx(self, args).map_err(|e| e.kind()) + fn issue_invoice_tx(&self, args: IssueInvoiceTxArgs) -> Result { + let slate = Owner::issue_invoice_tx(self, args).map_err(|e| e.kind())?; + let version = SlateVersion::V2; + Ok(VersionedSlate::into_version(slate, version)) } - fn process_invoice_tx(&self, slate: &Slate, args: InitTxArgs) -> Result { - Owner::process_invoice_tx(self, slate, args).map_err(|e| e.kind()) + fn process_invoice_tx( + &self, + slate: VersionedSlate, + args: InitTxArgs, + ) -> Result { + let in_slate = Slate::from(slate); + let out_slate = Owner::process_invoice_tx(self, &in_slate, args).map_err(|e| e.kind())?; + let version = SlateVersion::V2; + Ok(VersionedSlate::into_version(out_slate, version)) } - fn finalize_tx(&self, mut slate: Slate) -> Result { - Owner::finalize_tx(self, &mut slate).map_err(|e| e.kind()) + fn finalize_tx(&self, slate: VersionedSlate) -> Result { + let in_slate = Slate::from(slate); + let out_slate = Owner::finalize_tx(self, &in_slate).map_err(|e| e.kind())?; + let version = SlateVersion::V2; + Ok(VersionedSlate::into_version(out_slate, version)) } - fn tx_lock_outputs(&self, mut slate: Slate, participant_id: usize) -> Result<(), ErrorKind> { - Owner::tx_lock_outputs(self, &mut slate, participant_id).map_err(|e| e.kind()) + fn tx_lock_outputs( + &self, + slate: VersionedSlate, + participant_id: usize, + ) -> Result<(), ErrorKind> { + let in_slate = Slate::from(slate); + Owner::tx_lock_outputs(self, &in_slate, participant_id).map_err(|e| e.kind()) } fn cancel_tx(&self, tx_id: Option, tx_slate_id: Option) -> Result<(), ErrorKind> { @@ -1312,8 +1340,9 @@ where Owner::post_tx(self, tx, fluff).map_err(|e| e.kind()) } - fn verify_slate_messages(&self, slate: &Slate) -> Result<(), ErrorKind> { - Owner::verify_slate_messages(self, slate).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, &in_slate).map_err(|e| e.kind()) } fn restore(&self) -> Result<(), ErrorKind> {