mirror of
https://github.com/mimblewimble/grin-wallet.git
synced 2025-02-01 17:01:10 +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);
|
# ,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).
|
Networked version of [Foreign::receive_tx](struct.Foreign.html#method.receive_tx).
|
||||||
|
@ -513,7 +513,7 @@ pub trait ForeignRpc {
|
||||||
# ,false, 5, false, true);
|
# ,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>
|
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())
|
Foreign::build_coinbase(self, block_fees).map_err(|e| e.kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_slate_messages(&self, slate: &Slate) -> Result<(), ErrorKind> {
|
fn verify_slate_messages(&self, slate: VersionedSlate) -> Result<(), ErrorKind> {
|
||||||
Foreign::verify_slate_messages(self, slate).map_err(|e| e.kind())
|
Foreign::verify_slate_messages(self, &Slate::from(slate)).map_err(|e| e.kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn receive_tx(
|
fn receive_tx(
|
||||||
&self,
|
&self,
|
||||||
slate: VersionedSlate,
|
in_slate: VersionedSlate,
|
||||||
dest_acct_name: Option<String>,
|
dest_acct_name: Option<String>,
|
||||||
message: Option<String>,
|
message: Option<String>,
|
||||||
) -> Result<VersionedSlate, ErrorKind> {
|
) -> Result<VersionedSlate, ErrorKind> {
|
||||||
let version = slate.version();
|
let version = in_slate.version();
|
||||||
let slate: Slate = slate.into();
|
let out_slate = Foreign::receive_tx(
|
||||||
let slate = Foreign::receive_tx(
|
|
||||||
self,
|
self,
|
||||||
&slate,
|
&Slate::from(in_slate),
|
||||||
dest_acct_name.as_ref().map(String::as_str),
|
dest_acct_name.as_ref().map(String::as_str),
|
||||||
message,
|
message,
|
||||||
)
|
)
|
||||||
.map_err(|e| e.kind())?;
|
.map_err(|e| e.kind())?;
|
||||||
|
Ok(VersionedSlate::into_version(out_slate, version))
|
||||||
Ok(VersionedSlate::into_version(slate, version))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finalize_invoice_tx(&self, slate: &Slate) -> Result<Slate, ErrorKind> {
|
fn finalize_invoice_tx(&self, in_slate: VersionedSlate) -> Result<VersionedSlate, ErrorKind> {
|
||||||
Foreign::finalize_invoice_tx(self, slate).map_err(|e| e.kind())
|
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::core::core::Transaction;
|
||||||
use crate::keychain::{Identifier, Keychain};
|
use crate::keychain::{Identifier, Keychain};
|
||||||
|
use crate::libwallet::slate_versions::v2::TransactionV2;
|
||||||
use crate::libwallet::{
|
use crate::libwallet::{
|
||||||
AcctPathMapping, ErrorKind, InitTxArgs, IssueInvoiceTxArgs, NodeClient, NodeHeightResult,
|
AcctPathMapping, ErrorKind, InitTxArgs, IssueInvoiceTxArgs, NodeClient, NodeHeightResult,
|
||||||
OutputCommitMapping, Slate, SlateVersion, TxLogEntry, VersionedSlate, WalletInfo,
|
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).
|
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);
|
# , 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).
|
Networked version of [Owner::verify_slate_messages](struct.Owner.html#method.verify_slate_messages).
|
||||||
|
@ -1304,19 +1305,18 @@ where
|
||||||
|
|
||||||
fn process_invoice_tx(
|
fn process_invoice_tx(
|
||||||
&self,
|
&self,
|
||||||
slate: VersionedSlate,
|
in_slate: VersionedSlate,
|
||||||
args: InitTxArgs,
|
args: InitTxArgs,
|
||||||
) -> Result<VersionedSlate, ErrorKind> {
|
) -> Result<VersionedSlate, ErrorKind> {
|
||||||
let in_slate = Slate::from(slate);
|
let out_slate = Owner::process_invoice_tx(self, None, &Slate::from(in_slate), args)
|
||||||
let out_slate =
|
.map_err(|e| e.kind())?;
|
||||||
Owner::process_invoice_tx(self, None, &in_slate, args).map_err(|e| e.kind())?;
|
|
||||||
let version = SlateVersion::V2;
|
let version = SlateVersion::V2;
|
||||||
Ok(VersionedSlate::into_version(out_slate, version))
|
Ok(VersionedSlate::into_version(out_slate, version))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finalize_tx(&self, slate: VersionedSlate) -> Result<VersionedSlate, ErrorKind> {
|
fn finalize_tx(&self, in_slate: VersionedSlate) -> Result<VersionedSlate, ErrorKind> {
|
||||||
let in_slate = Slate::from(slate);
|
let out_slate =
|
||||||
let out_slate = Owner::finalize_tx(self, None, &in_slate).map_err(|e| e.kind())?;
|
Owner::finalize_tx(self, None, &Slate::from(in_slate)).map_err(|e| e.kind())?;
|
||||||
let version = SlateVersion::V2;
|
let version = SlateVersion::V2;
|
||||||
Ok(VersionedSlate::into_version(out_slate, version))
|
Ok(VersionedSlate::into_version(out_slate, version))
|
||||||
}
|
}
|
||||||
|
@ -1326,25 +1326,26 @@ where
|
||||||
slate: VersionedSlate,
|
slate: VersionedSlate,
|
||||||
participant_id: usize,
|
participant_id: usize,
|
||||||
) -> Result<(), ErrorKind> {
|
) -> Result<(), ErrorKind> {
|
||||||
let in_slate = Slate::from(slate);
|
Owner::tx_lock_outputs(self, None, &Slate::from(slate), participant_id)
|
||||||
Owner::tx_lock_outputs(self, None, &in_slate, participant_id).map_err(|e| e.kind())
|
.map_err(|e| e.kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cancel_tx(&self, tx_id: Option<u32>, tx_slate_id: Option<Uuid>) -> Result<(), ErrorKind> {
|
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())
|
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> {
|
fn get_stored_tx(&self, tx: &TxLogEntry) -> Result<Option<TransactionV2>, ErrorKind> {
|
||||||
Owner::get_stored_tx(self, None, tx).map_err(|e| e.kind())
|
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> {
|
fn post_tx(&self, tx: TransactionV2, fluff: bool) -> Result<(), ErrorKind> {
|
||||||
Owner::post_tx(self, None, tx, fluff).map_err(|e| e.kind())
|
Owner::post_tx(self, None, &Transaction::from(tx), fluff).map_err(|e| e.kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_slate_messages(&self, slate: VersionedSlate) -> Result<(), ErrorKind> {
|
fn verify_slate_messages(&self, slate: VersionedSlate) -> Result<(), ErrorKind> {
|
||||||
let in_slate = Slate::from(slate);
|
Owner::verify_slate_messages(self, None, &Slate::from(slate)).map_err(|e| e.kind())
|
||||||
Owner::verify_slate_messages(self, None, &in_slate).map_err(|e| e.kind())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn restore(&self) -> Result<(), ErrorKind> {
|
fn restore(&self) -> Result<(), ErrorKind> {
|
||||||
|
|
|
@ -17,6 +17,7 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use crate::core::core::Transaction;
|
use crate::core::core::Transaction;
|
||||||
use crate::keychain::{Identifier, Keychain};
|
use crate::keychain::{Identifier, Keychain};
|
||||||
|
use crate::libwallet::slate_versions::v2::TransactionV2;
|
||||||
use crate::libwallet::{
|
use crate::libwallet::{
|
||||||
AcctPathMapping, ErrorKind, InitTxArgs, IssueInvoiceTxArgs, NodeClient, NodeHeightResult,
|
AcctPathMapping, ErrorKind, InitTxArgs, IssueInvoiceTxArgs, NodeClient, NodeHeightResult,
|
||||||
OutputCommitMapping, Slate, SlateVersion, TxLogEntry, VersionedSlate, WalletInfo,
|
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).
|
Networked version of [Owner::cancel_tx](struct.Owner.html#method.cancel_tx).
|
||||||
|
@ -1125,7 +1126,7 @@ pub trait OwnerRpcS {
|
||||||
&self,
|
&self,
|
||||||
token: Token,
|
token: Token,
|
||||||
tx: &TxLogEntry,
|
tx: &TxLogEntry,
|
||||||
) -> Result<Option<Transaction>, ErrorKind>;
|
) -> Result<Option<TransactionV2>, ErrorKind>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Networked version of [Owner::verify_slate_messages](struct.Owner.html#method.verify_slate_messages).
|
Networked version of [Owner::verify_slate_messages](struct.Owner.html#method.verify_slate_messages).
|
||||||
|
@ -1402,12 +1403,15 @@ where
|
||||||
fn process_invoice_tx(
|
fn process_invoice_tx(
|
||||||
&self,
|
&self,
|
||||||
token: Token,
|
token: Token,
|
||||||
slate: VersionedSlate,
|
in_slate: VersionedSlate,
|
||||||
args: InitTxArgs,
|
args: InitTxArgs,
|
||||||
) -> Result<VersionedSlate, ErrorKind> {
|
) -> Result<VersionedSlate, ErrorKind> {
|
||||||
let in_slate = Slate::from(slate);
|
let out_slate = Owner::process_invoice_tx(
|
||||||
let out_slate =
|
self,
|
||||||
Owner::process_invoice_tx(self, (&token.keychain_mask).as_ref(), &in_slate, args)
|
(&token.keychain_mask).as_ref(),
|
||||||
|
&Slate::from(in_slate),
|
||||||
|
args,
|
||||||
|
)
|
||||||
.map_err(|e| e.kind())?;
|
.map_err(|e| e.kind())?;
|
||||||
let version = SlateVersion::V2;
|
let version = SlateVersion::V2;
|
||||||
Ok(VersionedSlate::into_version(out_slate, version))
|
Ok(VersionedSlate::into_version(out_slate, version))
|
||||||
|
@ -1416,10 +1420,13 @@ where
|
||||||
fn finalize_tx(
|
fn finalize_tx(
|
||||||
&self,
|
&self,
|
||||||
token: Token,
|
token: Token,
|
||||||
slate: VersionedSlate,
|
in_slate: VersionedSlate,
|
||||||
) -> Result<VersionedSlate, ErrorKind> {
|
) -> Result<VersionedSlate, ErrorKind> {
|
||||||
let in_slate = Slate::from(slate);
|
let out_slate = Owner::finalize_tx(
|
||||||
let out_slate = Owner::finalize_tx(self, (&token.keychain_mask).as_ref(), &in_slate)
|
self,
|
||||||
|
(&token.keychain_mask).as_ref(),
|
||||||
|
&Slate::from(in_slate),
|
||||||
|
)
|
||||||
.map_err(|e| e.kind())?;
|
.map_err(|e| e.kind())?;
|
||||||
let version = SlateVersion::V2;
|
let version = SlateVersion::V2;
|
||||||
Ok(VersionedSlate::into_version(out_slate, version))
|
Ok(VersionedSlate::into_version(out_slate, version))
|
||||||
|
@ -1428,14 +1435,13 @@ where
|
||||||
fn tx_lock_outputs(
|
fn tx_lock_outputs(
|
||||||
&self,
|
&self,
|
||||||
token: Token,
|
token: Token,
|
||||||
slate: VersionedSlate,
|
in_slate: VersionedSlate,
|
||||||
participant_id: usize,
|
participant_id: usize,
|
||||||
) -> Result<(), ErrorKind> {
|
) -> Result<(), ErrorKind> {
|
||||||
let in_slate = Slate::from(slate);
|
|
||||||
Owner::tx_lock_outputs(
|
Owner::tx_lock_outputs(
|
||||||
self,
|
self,
|
||||||
(&token.keychain_mask).as_ref(),
|
(&token.keychain_mask).as_ref(),
|
||||||
&in_slate,
|
&Slate::from(in_slate),
|
||||||
participant_id,
|
participant_id,
|
||||||
)
|
)
|
||||||
.map_err(|e| e.kind())
|
.map_err(|e| e.kind())
|
||||||
|
@ -1455,17 +1461,24 @@ where
|
||||||
&self,
|
&self,
|
||||||
token: Token,
|
token: Token,
|
||||||
tx: &TxLogEntry,
|
tx: &TxLogEntry,
|
||||||
) -> Result<Option<Transaction>, ErrorKind> {
|
) -> Result<Option<TransactionV2>, ErrorKind> {
|
||||||
Owner::get_stored_tx(self, (&token.keychain_mask).as_ref(), tx).map_err(|e| e.kind())
|
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> {
|
fn post_tx(&self, token: Token, tx: TransactionV2, fluff: bool) -> Result<(), ErrorKind> {
|
||||||
Owner::post_tx(self, (&token.keychain_mask).as_ref(), tx, fluff).map_err(|e| e.kind())
|
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> {
|
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(), &Slate::from(slate))
|
||||||
Owner::verify_slate_messages(self, (&token.keychain_mask).as_ref(), &in_slate)
|
|
||||||
.map_err(|e| e.kind())
|
.map_err(|e| e.kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ use crate::api;
|
||||||
use crate::chain;
|
use crate::chain;
|
||||||
use crate::chain::Chain;
|
use crate::chain::Chain;
|
||||||
use crate::core;
|
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::core::{consensus, global, pow};
|
||||||
use crate::keychain;
|
use crate::keychain;
|
||||||
use crate::libwallet;
|
use crate::libwallet;
|
||||||
|
@ -82,7 +82,7 @@ pub fn add_block_with_reward(chain: &Chain, txs: Vec<&Transaction>, reward: CbDa
|
||||||
&prev,
|
&prev,
|
||||||
txs.into_iter().cloned().collect(),
|
txs.into_iter().cloned().collect(),
|
||||||
next_header_info.clone().difficulty,
|
next_header_info.clone().difficulty,
|
||||||
(reward.output, reward.kernel),
|
(reward.output, TxKernel::from(&reward.kernel)),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
b.header.timestamp = prev.timestamp + Duration::seconds(60);
|
b.header.timestamp = prev.timestamp + Duration::seconds(60);
|
||||||
|
|
|
@ -14,10 +14,11 @@
|
||||||
|
|
||||||
//! Types specific to the wallet api, mostly argument serialization
|
//! 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_core::libtx::secp_ser;
|
||||||
use crate::grin_keychain::Identifier;
|
use crate::grin_keychain::Identifier;
|
||||||
use crate::grin_util::secp::pedersen;
|
use crate::grin_util::secp::pedersen;
|
||||||
|
use crate::slate_versions::v2::TxKernelV2;
|
||||||
use crate::slate_versions::SlateVersion;
|
use crate::slate_versions::SlateVersion;
|
||||||
use crate::types::OutputData;
|
use crate::types::OutputData;
|
||||||
|
|
||||||
|
@ -185,7 +186,7 @@ pub struct CbData {
|
||||||
/// Output
|
/// Output
|
||||||
pub output: Output,
|
pub output: Output,
|
||||||
/// Kernel
|
/// Kernel
|
||||||
pub kernel: TxKernel,
|
pub kernel: TxKernelV2,
|
||||||
/// Key Id
|
/// Key Id
|
||||||
pub key_id: Option<Identifier>,
|
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::key::SecretKey;
|
||||||
use crate::grin_util::secp::pedersen;
|
use crate::grin_util::secp::pedersen;
|
||||||
use crate::internal::keys;
|
use crate::internal::keys;
|
||||||
|
use crate::slate_versions::v2::TxKernelV2;
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
NodeClient, OutputData, OutputStatus, TxLogEntry, TxLogEntryType, WalletBackend, WalletInfo,
|
NodeClient, OutputData, OutputStatus, TxLogEntry, TxLogEntryType, WalletBackend, WalletInfo,
|
||||||
};
|
};
|
||||||
|
@ -467,7 +468,7 @@ where
|
||||||
|
|
||||||
Ok(CbData {
|
Ok(CbData {
|
||||||
output: out,
|
output: out,
|
||||||
kernel: kern,
|
kernel: TxKernelV2::from(&kern),
|
||||||
key_id: block_fees.key_id,
|
key_id: block_fees.key_id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue