mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-12-03 20:33:59 +01:00
Update lmdb (#755)
* wallet: update lmdb from store crate, migrate single backend from trait to struct, update tests cargo deps and design doc * backend: do not panic on iter and directory creation * return iterator errors * build: update to last node revision * fix: height selection for scan, remove unused mutability for wallet * wallet: remove unused mutability conversion * tx: store slate state at database * build: cargo fmt * fix: do not return error when slate not found on tx slate state update * lmdb: do not collect all tx log records at iterator, show read errors at log * fix: save slate state, return error if slate not found * tx: specify amount of bad txs on slate state update error --------- Co-authored-by: Joerg <wiesche89@googlemail.com>
This commit is contained in:
committed by
wiesche
co-authored by
Joerg
parent
15833b23c0
commit
308f0a8458
@@ -13,9 +13,13 @@
|
||||
// limitations under the License.
|
||||
|
||||
//! Generic implementation of owner API functions
|
||||
|
||||
use grin_keychain::Identifier;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use super::owner::tx_lock_outputs;
|
||||
use crate::api_impl::owner::{check_ttl, post_tx};
|
||||
use crate::backend::WalletBackend;
|
||||
use crate::grin_core::core::FeeFields;
|
||||
use crate::grin_keychain::Keychain;
|
||||
use crate::grin_util::secp::key::SecretKey;
|
||||
@@ -23,11 +27,8 @@ use crate::internal::{selection, tx, updater};
|
||||
use crate::slate_versions::SlateVersion;
|
||||
use crate::{
|
||||
address, BlockFees, CbData, Error, NodeClient, Slate, SlateState, TxLogEntryType, VersionInfo,
|
||||
WalletBackend,
|
||||
};
|
||||
|
||||
use super::owner::tx_lock_outputs;
|
||||
|
||||
const FOREIGN_API_VERSION: u16 = 2;
|
||||
|
||||
/// Return the version info
|
||||
@@ -39,32 +40,30 @@ pub fn check_version() -> VersionInfo {
|
||||
}
|
||||
|
||||
/// Build a coinbase transaction
|
||||
pub fn build_coinbase<'a, T: ?Sized, C, K>(
|
||||
w: &mut T,
|
||||
pub fn build_coinbase<C, K>(
|
||||
w: &mut WalletBackend<C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
block_fees: &BlockFees,
|
||||
test_mode: bool,
|
||||
) -> Result<CbData, Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
updater::build_coinbase(&mut *w, keychain_mask, block_fees, test_mode)
|
||||
updater::build_coinbase(w, keychain_mask, block_fees, test_mode)
|
||||
}
|
||||
|
||||
/// Receive a tx as recipient
|
||||
pub fn receive_tx<'a, T: ?Sized, C, K>(
|
||||
w: &mut T,
|
||||
pub fn receive_tx<C, K>(
|
||||
w: &mut WalletBackend<C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
slate: &Slate,
|
||||
dest_acct_name: Option<&str>,
|
||||
use_test_rng: bool,
|
||||
) -> Result<Slate, Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
let mut ret_slate = slate.clone();
|
||||
check_ttl(w, &ret_slate)?;
|
||||
@@ -80,7 +79,7 @@ where
|
||||
};
|
||||
// Don't do this multiple times
|
||||
let tx = updater::retrieve_txs(
|
||||
&mut *w,
|
||||
w,
|
||||
None,
|
||||
Some(ret_slate.id),
|
||||
None,
|
||||
@@ -99,7 +98,7 @@ where
|
||||
let keychain = w.keychain(keychain_mask)?;
|
||||
|
||||
let context = tx::add_output_to_slate(
|
||||
&mut *w,
|
||||
w,
|
||||
keychain_mask,
|
||||
&mut ret_slate,
|
||||
height,
|
||||
@@ -127,22 +126,23 @@ where
|
||||
ret_slate.amount = 0;
|
||||
ret_slate.fee_fields = FeeFields::zero();
|
||||
ret_slate.remove_other_sigdata(&keychain, &context.sec_nonce, &context.sec_key)?;
|
||||
|
||||
ret_slate.state = SlateState::Standard2;
|
||||
update_tx_slate_state(w, keychain_mask, &parent_key_id, &ret_slate)?;
|
||||
|
||||
Ok(ret_slate)
|
||||
}
|
||||
|
||||
/// Receive a tx that this wallet has issued
|
||||
pub fn finalize_tx<'a, T: ?Sized, C, K>(
|
||||
w: &mut T,
|
||||
pub fn finalize_tx<C, K>(
|
||||
w: &mut WalletBackend<C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
slate: &Slate,
|
||||
post_automatically: bool,
|
||||
) -> Result<Slate, Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
let mut sl = slate.clone();
|
||||
let mut context = w.get_private_context(keychain_mask, sl.id.as_bytes())?;
|
||||
@@ -154,10 +154,10 @@ where
|
||||
let mut temp_ctx = context.clone();
|
||||
temp_ctx.sec_key = context.initial_sec_key.clone();
|
||||
temp_ctx.sec_nonce = context.initial_sec_nonce.clone();
|
||||
selection::repopulate_tx(&mut *w, keychain_mask, &mut sl, &temp_ctx, false)?;
|
||||
selection::repopulate_tx(w, keychain_mask, &mut sl, &temp_ctx, false)?;
|
||||
|
||||
tx::complete_tx(&mut *w, keychain_mask, &mut sl, &context)?;
|
||||
tx::update_stored_tx(&mut *w, keychain_mask, &context, &mut sl, true)?;
|
||||
tx::complete_tx(w, keychain_mask, &mut sl, &context)?;
|
||||
tx::update_stored_tx(w, keychain_mask, &context, &mut sl, true)?;
|
||||
{
|
||||
let mut batch = w.batch(keychain_mask)?;
|
||||
batch.delete_private_context(sl.id.as_bytes())?;
|
||||
@@ -165,6 +165,9 @@ where
|
||||
}
|
||||
sl.state = SlateState::Invoice3;
|
||||
sl.amount = 0;
|
||||
|
||||
let parent_key_id = w.parent_key_id();
|
||||
update_tx_slate_state(w, keychain_mask, &parent_key_id, &sl)?;
|
||||
} else if sl.state == SlateState::Standard2 {
|
||||
let keychain = w.keychain(keychain_mask)?;
|
||||
let parent_key_id = w.parent_key_id();
|
||||
@@ -175,7 +178,7 @@ where
|
||||
|
||||
let current_height = w.w2n_client().get_chain_tip()?.0;
|
||||
let mut temp_sl =
|
||||
tx::new_tx_slate(&mut *w, context.amount, false, 2, false, args.ttl_blocks)?;
|
||||
tx::new_tx_slate(w, context.amount, false, 2, false, args.ttl_blocks)?;
|
||||
let temp_context = selection::build_send_tx(
|
||||
w,
|
||||
&keychain,
|
||||
@@ -211,11 +214,11 @@ where
|
||||
// Add our contribution to the offset
|
||||
sl.adjust_offset(&keychain, &context)?;
|
||||
|
||||
selection::repopulate_tx(&mut *w, keychain_mask, &mut sl, &context, true)?;
|
||||
selection::repopulate_tx(w, keychain_mask, &mut sl, &context, true)?;
|
||||
|
||||
tx::complete_tx(&mut *w, keychain_mask, &mut sl, &context)?;
|
||||
tx::verify_slate_payment_proof(&mut *w, keychain_mask, &parent_key_id, &context, &sl)?;
|
||||
tx::update_stored_tx(&mut *w, keychain_mask, &context, &sl, false)?;
|
||||
tx::complete_tx(w, keychain_mask, &mut sl, &context)?;
|
||||
tx::verify_slate_payment_proof(w, keychain_mask, &parent_key_id, &context, &sl)?;
|
||||
tx::update_stored_tx(w, keychain_mask, &context, &sl, false)?;
|
||||
{
|
||||
let mut batch = w.batch(keychain_mask)?;
|
||||
batch.delete_private_context(sl.id.as_bytes())?;
|
||||
@@ -223,6 +226,8 @@ where
|
||||
}
|
||||
sl.state = SlateState::Standard3;
|
||||
sl.amount = 0;
|
||||
|
||||
update_tx_slate_state(w, keychain_mask, &parent_key_id, &sl)?;
|
||||
} else {
|
||||
return Err(Error::SlateState);
|
||||
}
|
||||
@@ -231,3 +236,39 @@ where
|
||||
}
|
||||
Ok(sl)
|
||||
}
|
||||
|
||||
/// Update transaction slate state.
|
||||
fn update_tx_slate_state<C, K>(
|
||||
wallet: &mut WalletBackend<C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
parent_key_id: &Identifier,
|
||||
slate: &Slate,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
let mut bad_records = 0;
|
||||
let tx = wallet
|
||||
.tx_log_iter()?
|
||||
.filter(|tx| {
|
||||
if tx.is_err() {
|
||||
bad_records += 1;
|
||||
}
|
||||
tx.is_ok()
|
||||
})
|
||||
.map(|tx| tx.unwrap())
|
||||
.find(|tx| tx.tx_slate_id == Some(slate.id));
|
||||
if let Some(mut tx) = tx {
|
||||
let mut batch = wallet.batch(keychain_mask)?;
|
||||
tx.tx_slate_state = Some(slate.state.clone());
|
||||
batch.save_tx_log_entry(tx.clone(), parent_key_id)?;
|
||||
batch.commit()?;
|
||||
} else {
|
||||
return Err(Error::Backend(format!(
|
||||
"Tx log entry with slate id {} not found, there are {} bad tx log records",
|
||||
slate.id, bad_records
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+95
-126
@@ -31,15 +31,14 @@ use crate::api_impl::owner_updater::StatusMessage;
|
||||
use crate::grin_keychain::{BlindingFactor, Identifier, Keychain, SwitchCommitmentType};
|
||||
use crate::internal::{keys, scan, selection, tx, updater};
|
||||
use crate::slate::{PaymentInfo, Slate, SlateState};
|
||||
use crate::types::{AcctPathMapping, NodeClient, TxLogEntry, WalletBackend, WalletInfo};
|
||||
use crate::Error;
|
||||
use crate::types::{AcctPathMapping, NodeClient, TxLogEntry, WalletInfo};
|
||||
use crate::{
|
||||
address,
|
||||
mwixnet::{create_onion, ComSignature, Hop, MixnetReqCreationParams, SwapReq},
|
||||
wallet_lock, BuiltOutput, InitTxArgs, IssueInvoiceTxArgs, NodeHeightResult,
|
||||
wallet_lock, BuiltOutput, Error, InitTxArgs, IssueInvoiceTxArgs, NodeHeightResult,
|
||||
OutputCommitMapping, PaymentProof, RetrieveTxQueryArgs, ScannedBlockInfo, Slatepack,
|
||||
SlatepackAddress, Slatepacker, SlatepackerArgs, TxLogEntryType, ViewWallet, WalletInitStatus,
|
||||
WalletInst, WalletLCProvider,
|
||||
SlatepackAddress, Slatepacker, SlatepackerArgs, TxLogEntryType, ViewWallet, WalletBackend,
|
||||
WalletInitStatus, WalletInst, WalletLCProvider,
|
||||
};
|
||||
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
@@ -52,35 +51,32 @@ use std::sync::mpsc::Sender;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// List of accounts
|
||||
pub fn accounts<'a, T: ?Sized, C, K>(w: &mut T) -> Result<Vec<AcctPathMapping>, Error>
|
||||
pub fn accounts<C, K>(w: &mut WalletBackend<C, K>) -> Result<Vec<AcctPathMapping>, Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
keys::accounts(&mut *w)
|
||||
keys::accounts(w)
|
||||
}
|
||||
|
||||
/// new account path
|
||||
pub fn create_account_path<'a, T: ?Sized, C, K>(
|
||||
w: &mut T,
|
||||
pub fn create_account_path<C, K>(
|
||||
w: &mut WalletBackend<C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
label: &str,
|
||||
) -> Result<Identifier, Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
keys::new_acct_path(&mut *w, keychain_mask, label)
|
||||
keys::new_acct_path(w, keychain_mask, label)
|
||||
}
|
||||
|
||||
/// set active account
|
||||
pub fn set_active_account<'a, T: ?Sized, C, K>(w: &mut T, label: &str) -> Result<(), Error>
|
||||
pub fn set_active_account<C, K>(w: &mut WalletBackend<C, K>, label: &str) -> Result<(), Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
w.set_parent_key_id_by_name(label)
|
||||
}
|
||||
@@ -196,7 +192,7 @@ where
|
||||
dec_key: None,
|
||||
});
|
||||
let slatepack = packer.deser_slatepack(slatepack.as_bytes(), true)?;
|
||||
return packer.get_slate(&slatepack);
|
||||
packer.get_slate(&slatepack)
|
||||
} else {
|
||||
for index in secret_indices {
|
||||
let dec_key = Some(get_slatepack_secret_key(
|
||||
@@ -218,11 +214,11 @@ where
|
||||
};
|
||||
return packer.get_slate(&slatepack);
|
||||
}
|
||||
return Err(Error::SlatepackDecryption(
|
||||
Err(Error::SlatepackDecryption(
|
||||
"Could not decrypt slatepack with any provided index on the address derivation path"
|
||||
.to_owned(),
|
||||
)
|
||||
.into());
|
||||
.into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,13 +298,7 @@ where
|
||||
|
||||
Ok((
|
||||
validated,
|
||||
updater::retrieve_outputs(
|
||||
&mut **w,
|
||||
keychain_mask,
|
||||
include_spent,
|
||||
tx_id,
|
||||
Some(&parent_key_id),
|
||||
)?,
|
||||
updater::retrieve_outputs(w, keychain_mask, include_spent, tx_id, Some(&parent_key_id))?,
|
||||
))
|
||||
}
|
||||
|
||||
@@ -341,7 +331,7 @@ where
|
||||
wallet_lock!(wallet_inst, w);
|
||||
let parent_key_id = w.parent_key_id();
|
||||
let txs = updater::retrieve_txs(
|
||||
&mut **w,
|
||||
w,
|
||||
tx_id,
|
||||
tx_slate_id,
|
||||
query_args,
|
||||
@@ -378,7 +368,7 @@ where
|
||||
|
||||
wallet_lock!(wallet_inst, w);
|
||||
let parent_key_id = w.parent_key_id();
|
||||
let wallet_info = updater::retrieve_info(&mut **w, &parent_key_id, minimum_confirmations)?;
|
||||
let wallet_info = updater::retrieve_info(w, &parent_key_id, minimum_confirmations)?;
|
||||
Ok((validated, wallet_info))
|
||||
}
|
||||
|
||||
@@ -469,8 +459,8 @@ where
|
||||
}
|
||||
};
|
||||
Ok(PaymentProof {
|
||||
amount: amount,
|
||||
excess: excess,
|
||||
amount,
|
||||
excess,
|
||||
recipient_address: SlatepackAddress::new(&proof.receiver_address),
|
||||
recipient_sig: r_sig,
|
||||
sender_address: SlatepackAddress::new(&proof.sender_address),
|
||||
@@ -479,16 +469,15 @@ where
|
||||
}
|
||||
|
||||
/// Initiate tx as sender
|
||||
pub fn init_send_tx<'a, T: ?Sized, C, K>(
|
||||
w: &mut T,
|
||||
pub fn init_send_tx<C, K>(
|
||||
w: &mut WalletBackend<C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
args: InitTxArgs,
|
||||
use_test_rng: bool,
|
||||
) -> Result<Slate, Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
let parent_key_id = match &args.src_acct_name {
|
||||
Some(d) => {
|
||||
@@ -501,14 +490,7 @@ where
|
||||
None => w.parent_key_id(),
|
||||
};
|
||||
|
||||
let mut slate = tx::new_tx_slate(
|
||||
&mut *w,
|
||||
args.amount,
|
||||
false,
|
||||
2,
|
||||
use_test_rng,
|
||||
args.ttl_blocks,
|
||||
)?;
|
||||
let mut slate = tx::new_tx_slate(w, args.amount, false, 2, use_test_rng, args.ttl_blocks)?;
|
||||
|
||||
if let Some(v) = args.target_slate_version {
|
||||
slate.version_info.version = v;
|
||||
@@ -518,7 +500,7 @@ where
|
||||
// back
|
||||
if let Some(true) = args.estimate_only {
|
||||
let (total, fee) = tx::estimate_send_tx(
|
||||
&mut *w,
|
||||
w,
|
||||
keychain_mask,
|
||||
args.amount,
|
||||
args.amount_includes_fee.unwrap_or(false),
|
||||
@@ -536,7 +518,7 @@ where
|
||||
let height = w.w2n_client().get_chain_tip()?.0;
|
||||
let mut context = if args.late_lock.unwrap_or(false) {
|
||||
tx::create_late_lock_context(
|
||||
&mut *w,
|
||||
w,
|
||||
keychain_mask,
|
||||
&mut slate,
|
||||
height,
|
||||
@@ -546,7 +528,7 @@ where
|
||||
)?
|
||||
} else {
|
||||
tx::add_inputs_to_slate(
|
||||
&mut *w,
|
||||
w,
|
||||
keychain_mask,
|
||||
&mut slate,
|
||||
height,
|
||||
@@ -595,16 +577,15 @@ where
|
||||
}
|
||||
|
||||
/// Initiate a transaction as the recipient (invoicing)
|
||||
pub fn issue_invoice_tx<'a, T: ?Sized, C, K>(
|
||||
w: &mut T,
|
||||
pub fn issue_invoice_tx<C, K>(
|
||||
w: &mut WalletBackend<C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
args: IssueInvoiceTxArgs,
|
||||
use_test_rng: bool,
|
||||
) -> Result<Slate, Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
let parent_key_id = match args.dest_acct_name {
|
||||
Some(d) => {
|
||||
@@ -617,10 +598,10 @@ where
|
||||
None => w.parent_key_id(),
|
||||
};
|
||||
|
||||
let mut slate = tx::new_tx_slate(&mut *w, args.amount, true, 2, use_test_rng, None)?;
|
||||
let mut slate = tx::new_tx_slate(w, args.amount, true, 2, use_test_rng, None)?;
|
||||
let height = w.w2n_client().get_chain_tip()?.0;
|
||||
let context = tx::add_output_to_slate(
|
||||
&mut *w,
|
||||
w,
|
||||
keychain_mask,
|
||||
&mut slate,
|
||||
height,
|
||||
@@ -648,17 +629,16 @@ where
|
||||
|
||||
/// Receive an invoice tx, essentially adding inputs to whatever
|
||||
/// output was specified
|
||||
pub fn process_invoice_tx<'a, T: ?Sized, C, K>(
|
||||
w: &mut T,
|
||||
pub fn process_invoice_tx<C, K>(
|
||||
w: &mut WalletBackend<C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
slate: &Slate,
|
||||
args: InitTxArgs,
|
||||
use_test_rng: bool,
|
||||
) -> Result<Slate, Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
let mut ret_slate = slate.clone();
|
||||
check_ttl(w, &ret_slate)?;
|
||||
@@ -674,7 +654,7 @@ where
|
||||
};
|
||||
// Don't do this multiple times
|
||||
let tx = updater::retrieve_txs(
|
||||
&mut *w,
|
||||
w,
|
||||
None,
|
||||
Some(ret_slate.id),
|
||||
None,
|
||||
@@ -704,7 +684,7 @@ where
|
||||
let context_res = w.get_private_context(keychain_mask, slate.id.as_bytes());
|
||||
|
||||
let mut context = tx::add_inputs_to_slate(
|
||||
&mut *w,
|
||||
w,
|
||||
keychain_mask,
|
||||
&mut ret_slate,
|
||||
height,
|
||||
@@ -750,7 +730,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
selection::repopulate_tx(&mut *w, keychain_mask, &mut ret_slate, &context, false)?;
|
||||
selection::repopulate_tx(w, keychain_mask, &mut ret_slate, &context, false)?;
|
||||
|
||||
// Save the aggsig context in our DB for when we
|
||||
// recieve the transaction back
|
||||
@@ -769,15 +749,14 @@ where
|
||||
}
|
||||
|
||||
/// Lock sender outputs
|
||||
pub fn tx_lock_outputs<'a, T: ?Sized, C, K>(
|
||||
w: &mut T,
|
||||
pub fn tx_lock_outputs<C, K>(
|
||||
w: &mut WalletBackend<C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
slate: &Slate,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
let context = w.get_private_context(keychain_mask, slate.id.as_bytes())?;
|
||||
let mut excess_override = None;
|
||||
@@ -786,7 +765,7 @@ where
|
||||
|
||||
if sl.tx == None {
|
||||
sl.tx = Some(Slate::empty_transaction());
|
||||
selection::repopulate_tx(&mut *w, keychain_mask, &mut sl, &context, true)?;
|
||||
selection::repopulate_tx(w, keychain_mask, &mut sl, &context, true)?;
|
||||
}
|
||||
|
||||
if slate.participant_data.len() == 1 {
|
||||
@@ -795,26 +774,18 @@ where
|
||||
}
|
||||
|
||||
let height = w.w2n_client().get_chain_tip()?.0;
|
||||
selection::lock_tx_context(
|
||||
&mut *w,
|
||||
keychain_mask,
|
||||
&sl,
|
||||
height,
|
||||
&context,
|
||||
excess_override,
|
||||
)
|
||||
selection::lock_tx_context(w, keychain_mask, &sl, height, &context, excess_override)
|
||||
}
|
||||
|
||||
/// Finalize slate
|
||||
pub fn finalize_tx<'a, T: ?Sized, C, K>(
|
||||
w: &mut T,
|
||||
pub fn finalize_tx<C, K>(
|
||||
w: &mut WalletBackend<C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
slate: &Slate,
|
||||
) -> Result<Slate, Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
foreign_finalize(w, keychain_mask, slate, false)
|
||||
}
|
||||
@@ -844,24 +815,27 @@ where
|
||||
}
|
||||
wallet_lock!(wallet_inst, w);
|
||||
let parent_key_id = w.parent_key_id();
|
||||
tx::cancel_tx(&mut **w, keychain_mask, &parent_key_id, tx_id, tx_slate_id)
|
||||
tx::cancel_tx(w, keychain_mask, &parent_key_id, tx_id, tx_slate_id)
|
||||
}
|
||||
|
||||
/// get stored tx
|
||||
/// crashes if stored tx has total fees exceeding 2^40 nanogrin
|
||||
pub fn get_stored_tx<'a, T: ?Sized, C, K>(
|
||||
w: &T,
|
||||
pub fn get_stored_tx<C, K>(
|
||||
w: &WalletBackend<C, K>,
|
||||
tx_id: Option<u32>,
|
||||
slate_id: Option<&Uuid>,
|
||||
) -> Result<Option<Slate>, Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
let mut uuid = None;
|
||||
if let Some(i) = tx_id {
|
||||
let tx = w.tx_log_iter().find(|t| t.id == i);
|
||||
let tx = w
|
||||
.tx_log_iter()?
|
||||
.filter(|tx| tx.is_ok())
|
||||
.map(|tx| tx.unwrap())
|
||||
.find(|t| t.id == i);
|
||||
if let Some(t) = tx {
|
||||
uuid = t.tx_slate_id;
|
||||
}
|
||||
@@ -896,9 +870,9 @@ where
|
||||
|
||||
/// Posts a transaction to the chain
|
||||
/// take a client impl instead of wallet so as not to have to lock the wallet
|
||||
pub fn post_tx<'a, C>(client: &C, tx: &Transaction, fluff: bool) -> Result<(), Error>
|
||||
pub fn post_tx<C>(client: &C, tx: &Transaction, fluff: bool) -> Result<(), Error>
|
||||
where
|
||||
C: NodeClient + 'a,
|
||||
C: NodeClient,
|
||||
{
|
||||
let res = client.post_tx(tx, fluff);
|
||||
if let Err(e) = res {
|
||||
@@ -930,8 +904,7 @@ where
|
||||
let is_hex = rewind_hash.chars().all(|c| c.is_ascii_hexdigit());
|
||||
let rewind_hash = rewind_hash.to_lowercase();
|
||||
if !(is_hex && rewind_hash.len() == 64) {
|
||||
let msg = format!("Invalid Rewind Hash");
|
||||
return Err(Error::RewindHash(msg));
|
||||
return Err(Error::RewindHash("Invalid Rewind Hash".to_string()));
|
||||
}
|
||||
|
||||
let tip = {
|
||||
@@ -939,10 +912,7 @@ where
|
||||
w.w2n_client().get_chain_tip()?
|
||||
};
|
||||
|
||||
let start_height = match start_height {
|
||||
Some(h) => h,
|
||||
None => 1,
|
||||
};
|
||||
let start_height = start_height.unwrap_or_else(|| 1);
|
||||
|
||||
let info = scan::scan_rewind_hash(
|
||||
wallet_inst,
|
||||
@@ -979,7 +949,7 @@ where
|
||||
|
||||
// Scan every 10k heights to save data between batches in case of interruption.
|
||||
let mut total_pmmr_range = None;
|
||||
for h in (start_height..tip.0).step_by(10001) {
|
||||
for h in (start_height..tip.0 + 1).step_by(10001) {
|
||||
let batch_end_height = cmp::min(tip.0, h + 10000);
|
||||
let (mut info, range) = scan::scan(
|
||||
wallet_inst.clone(),
|
||||
@@ -1030,10 +1000,12 @@ where
|
||||
}),
|
||||
Err(_) => {
|
||||
let outputs = retrieve_outputs(wallet_inst, keychain_mask, &None, true, false, None)?;
|
||||
let height = match outputs.1.iter().map(|m| m.output.height).max() {
|
||||
Some(height) => height,
|
||||
None => 0,
|
||||
};
|
||||
let height = outputs
|
||||
.1
|
||||
.iter()
|
||||
.map(|m| m.output.height)
|
||||
.max()
|
||||
.unwrap_or_else(|| 0);
|
||||
Ok(NodeHeightResult {
|
||||
height,
|
||||
header_hash: "".to_owned(),
|
||||
@@ -1093,7 +1065,7 @@ where
|
||||
// Step 2: Update outstanding transactions with no change outputs by kernel
|
||||
let mut txs = {
|
||||
wallet_lock!(wallet_inst, w);
|
||||
updater::retrieve_txs(&mut **w, None, None, None, Some(&parent_key_id), true)?
|
||||
updater::retrieve_txs(w, None, None, None, Some(&parent_key_id), true)?
|
||||
};
|
||||
result = update_txs_via_kernel(wallet_inst.clone(), keychain_mask, &mut txs)?;
|
||||
if !result {
|
||||
@@ -1152,7 +1124,7 @@ where
|
||||
|
||||
// Scan every 10k heights to save data between batches in case of interruption.
|
||||
let mut total_pmmr_range = None;
|
||||
for h in (start_height..tip.0).step_by(10001) {
|
||||
for h in (start_height..tip.0 + 1).step_by(10001) {
|
||||
let batch_end_height = cmp::min(tip.0, h + 10000);
|
||||
let (mut info, range) = scan::scan(
|
||||
wallet_inst.clone(),
|
||||
@@ -1186,7 +1158,7 @@ where
|
||||
if tip.0 >= e {
|
||||
wallet_lock!(wallet_inst, w);
|
||||
let parent_key_id = w.parent_key_id();
|
||||
tx::cancel_tx(&mut **w, keychain_mask, &parent_key_id, Some(tx.id), None)?;
|
||||
tx::cancel_tx(w, keychain_mask, &parent_key_id, Some(tx.id), None)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1195,11 +1167,10 @@ where
|
||||
}
|
||||
|
||||
/// Check TTL
|
||||
pub fn check_ttl<'a, T: ?Sized, C, K>(w: &mut T, slate: &Slate) -> Result<(), Error>
|
||||
pub fn check_ttl<C, K>(w: &mut WalletBackend<C, K>, slate: &Slate) -> Result<(), Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
// Refuse if TTL is expired
|
||||
let last_confirmed_height = w.last_confirmed_height()?;
|
||||
@@ -1265,7 +1236,7 @@ where
|
||||
return Err(Error::PaymentProof("Invalid sender signature".to_owned()));
|
||||
};
|
||||
|
||||
// for now, simple test as to whether one of the addresses belongs to this wallet
|
||||
// for now, simple test whether one of the addresses belongs to this wallet
|
||||
let sec_key = address::address_from_derivation_path(&keychain, &parent_key_id, 0)?;
|
||||
let d_skey = match DalekSecretKey::from_bytes(&sec_key.0) {
|
||||
Ok(k) => k,
|
||||
@@ -1294,7 +1265,7 @@ where
|
||||
{
|
||||
wallet_lock!(wallet_inst, w);
|
||||
let parent_key_id = w.parent_key_id();
|
||||
match updater::refresh_outputs(&mut **w, keychain_mask, &parent_key_id, update_all) {
|
||||
match updater::refresh_outputs(w, keychain_mask, &parent_key_id, update_all) {
|
||||
Ok(_) => Ok(true),
|
||||
Err(e) => {
|
||||
if let Error::InvalidKeychainMask = e {
|
||||
@@ -1361,20 +1332,19 @@ where
|
||||
}
|
||||
|
||||
/// Builds an output for the wallet's next available key
|
||||
pub fn build_output<'a, T: ?Sized, C, K>(
|
||||
w: &mut T,
|
||||
pub fn build_output<C, K>(
|
||||
w: &mut WalletBackend<C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
features: OutputFeatures,
|
||||
amount: u64,
|
||||
) -> Result<BuiltOutput, Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
let k = w.keychain(keychain_mask)?;
|
||||
|
||||
let key_id = keys::next_available_key(&mut *w, keychain_mask)?;
|
||||
let key_id = keys::next_available_key(w, keychain_mask)?;
|
||||
|
||||
let blind = k.derive_key(amount, &key_id, SwitchCommitmentType::Regular)?;
|
||||
let commit = k.secp().commit(amount, blind.clone())?;
|
||||
@@ -1394,14 +1364,14 @@ where
|
||||
|
||||
Ok(BuiltOutput {
|
||||
blind: BlindingFactor::from_secret_key(blind),
|
||||
key_id: key_id,
|
||||
output: output,
|
||||
key_id,
|
||||
output,
|
||||
})
|
||||
}
|
||||
|
||||
/// Create MXMixnet request
|
||||
pub fn create_mwixnet_req<'a, T: ?Sized, C, K>(
|
||||
w: &mut T,
|
||||
pub fn create_mwixnet_req<C, K>(
|
||||
w: &mut WalletBackend<C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
params: &MixnetReqCreationParams,
|
||||
commitment: &Commitment,
|
||||
@@ -1409,9 +1379,8 @@ pub fn create_mwixnet_req<'a, T: ?Sized, C, K>(
|
||||
use_test_rng: bool,
|
||||
) -> Result<SwapReq, Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
C: NodeClient,
|
||||
K: Keychain,
|
||||
{
|
||||
let parent_key_id = w.parent_key_id();
|
||||
let keychain = w.keychain(keychain_mask)?;
|
||||
|
||||
Reference in New Issue
Block a user