Skip to content

Commit

Permalink
translate to/from TransactionV2 correctly in owner api and foreign api
Browse files Browse the repository at this point in the history
  • Loading branch information
antiochp committed Aug 19, 2019
1 parent 3c45dad commit ec3d08a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 55 deletions.
27 changes: 14 additions & 13 deletions api/src/foreign_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -513,7 +513,7 @@ pub trait ForeignRpc {
# ,false, 5, false, true);
```
*/
fn finalize_invoice_tx(&self, slate: &Slate) -> Result<Slate, ErrorKind>;
fn finalize_invoice_tx(&self, slate: VersionedSlate) -> Result<VersionedSlate, ErrorKind>;
}

impl<'a, L, C, K> ForeignRpc for Foreign<'a, L, C, K>
Expand All @@ -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<String>,
message: Option<String>,
) -> Result<VersionedSlate, ErrorKind> {
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<Slate, ErrorKind> {
Foreign::finalize_invoice_tx(self, slate).map_err(|e| e.kind())
fn finalize_invoice_tx(&self, in_slate: VersionedSlate) -> Result<VersionedSlate, ErrorKind> {
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))
}
}

Expand Down
35 changes: 18 additions & 17 deletions api/src/owner_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -1073,7 +1074,7 @@ pub trait OwnerRpc: Sync + Send {
# , false, 5, true, true, false);
```
*/
fn get_stored_tx(&self, tx: &TxLogEntry) -> Result<Option<Transaction>, ErrorKind>;
fn get_stored_tx(&self, tx: &TxLogEntry) -> Result<Option<TransactionV2>, ErrorKind>;

/**
Networked version of [Owner::verify_slate_messages](struct.Owner.html#method.verify_slate_messages).
Expand Down Expand Up @@ -1304,19 +1305,18 @@ where

fn process_invoice_tx(
&self,
slate: VersionedSlate,
in_slate: VersionedSlate,
args: InitTxArgs,
) -> Result<VersionedSlate, ErrorKind> {
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<VersionedSlate, ErrorKind> {
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<VersionedSlate, ErrorKind> {
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))
}
Expand All @@ -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<u32>, tx_slate_id: Option<Uuid>) -> 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<Option<Transaction>, ErrorKind> {
Owner::get_stored_tx(self, None, tx).map_err(|e| e.kind())
fn get_stored_tx(&self, tx: &TxLogEntry) -> Result<Option<TransactionV2>, 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> {
Expand Down
53 changes: 33 additions & 20 deletions api/src/owner_rpc_s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -1125,7 +1126,7 @@ pub trait OwnerRpcS {
&self,
token: Token,
tx: &TxLogEntry,
) -> Result<Option<Transaction>, ErrorKind>;
) -> Result<Option<TransactionV2>, ErrorKind>;

/**
Networked version of [Owner::verify_slate_messages](struct.Owner.html#method.verify_slate_messages).
Expand Down Expand Up @@ -1402,40 +1403,45 @@ where
fn process_invoice_tx(
&self,
token: Token,
slate: VersionedSlate,
in_slate: VersionedSlate,
args: InitTxArgs,
) -> Result<VersionedSlate, ErrorKind> {
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))
}

fn finalize_tx(
&self,
token: Token,
slate: VersionedSlate,
in_slate: VersionedSlate,
) -> Result<VersionedSlate, ErrorKind> {
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))
}

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())
Expand All @@ -1455,17 +1461,24 @@ where
&self,
token: Token,
tx: &TxLogEntry,
) -> Result<Option<Transaction>, ErrorKind> {
Owner::get_stored_tx(self, (&token.keychain_mask).as_ref(), tx).map_err(|e| e.kind())
) -> Result<Option<TransactionV2>, 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())
}

Expand Down
4 changes: 2 additions & 2 deletions impls/src/test_framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions libwallet/src/api_impl/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -185,7 +186,7 @@ pub struct CbData {
/// Output
pub output: Output,
/// Kernel
pub kernel: TxKernel,
pub kernel: TxKernelV2,
/// Key Id
pub key_id: Option<Identifier>,
}
Expand Down
3 changes: 2 additions & 1 deletion libwallet/src/internal/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -467,7 +468,7 @@ where

Ok(CbData {
output: out,
kernel: kern,
kernel: TxKernelV2::from(&kern),
key_id: block_fees.key_id,
})
}
Expand Down

0 comments on commit ec3d08a

Please sign in to comment.