mirror of
https://github.com/mimblewimble/grin-wallet.git
synced 2025-02-01 08:51:09 +03:00
translate to/from TransactionV2 correctly in owner api and foreign api
This commit is contained in:
parent
3c45dad846
commit
ec3d08a710
6 changed files with 72 additions and 55 deletions
|
@ -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<Slate, ErrorKind>;
|
||||
fn finalize_invoice_tx(&self, slate: VersionedSlate) -> Result<VersionedSlate, ErrorKind>;
|
||||
}
|
||||
|
||||
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<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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<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).
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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> {
|
||||
|
|
|
@ -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<Option<Transaction>, ErrorKind>;
|
||||
) -> Result<Option<TransactionV2>, 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<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))
|
||||
}
|
||||
|
@ -1416,11 +1420,14 @@ where
|
|||
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))
|
||||
}
|
||||
|
@ -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<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())
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<Identifier>,
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue