mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-12-05 13:23:58 +01:00
View Wallet - fn rewind_hash & scan_rewind_hash (#632)
* fn rewind_hash & scan_rewind_hash * update comments * update doctest
This commit is contained in:
@@ -18,8 +18,10 @@ use uuid::Uuid;
|
||||
|
||||
use crate::grin_core::core::hash::Hashed;
|
||||
use crate::grin_core::core::Transaction;
|
||||
use crate::grin_keychain::ViewKey;
|
||||
use crate::grin_util::secp::key::SecretKey;
|
||||
use crate::grin_util::Mutex;
|
||||
use crate::grin_util::ToHex;
|
||||
use crate::util::{OnionV3Address, OnionV3AddressError};
|
||||
|
||||
use crate::api_impl::owner_updater::StatusMessage;
|
||||
@@ -30,7 +32,7 @@ use crate::types::{AcctPathMapping, NodeClient, TxLogEntry, WalletBackend, Walle
|
||||
use crate::{
|
||||
address, wallet_lock, InitTxArgs, IssueInvoiceTxArgs, NodeHeightResult, OutputCommitMapping,
|
||||
PaymentProof, ScannedBlockInfo, Slatepack, SlatepackAddress, Slatepacker, SlatepackerArgs,
|
||||
TxLogEntryType, WalletInitStatus, WalletInst, WalletLCProvider,
|
||||
TxLogEntryType, ViewWallet, WalletInitStatus, WalletInst, WalletLCProvider,
|
||||
};
|
||||
use crate::{Error, ErrorKind};
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
@@ -75,6 +77,23 @@ where
|
||||
w.set_parent_key_id_by_name(label)
|
||||
}
|
||||
|
||||
/// Hash of the wallet root public key
|
||||
pub fn get_rewind_hash<'a, L, C, K>(
|
||||
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
) -> Result<String, Error>
|
||||
where
|
||||
L: WalletLCProvider<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
{
|
||||
wallet_lock!(wallet_inst, w);
|
||||
let keychain = w.keychain(keychain_mask)?;
|
||||
let root_public_key = keychain.public_root_key();
|
||||
let rewind_hash = ViewKey::rewind_hash(keychain.secp(), root_public_key).to_hex();
|
||||
Ok(rewind_hash)
|
||||
}
|
||||
|
||||
/// Retrieve the slatepack address for the current parent key at
|
||||
/// the given index
|
||||
pub fn get_slatepack_address<'a, L, C, K>(
|
||||
@@ -936,6 +955,46 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Scan outputs with the rewind hash of a third-party wallet.
|
||||
/// Help to retrieve outputs information that belongs it
|
||||
pub fn scan_rewind_hash<'a, L, C, K>(
|
||||
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
||||
rewind_hash: String,
|
||||
start_height: Option<u64>,
|
||||
status_send_channel: &Option<Sender<StatusMessage>>,
|
||||
) -> Result<ViewWallet, Error>
|
||||
where
|
||||
L: WalletLCProvider<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
{
|
||||
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(ErrorKind::RewindHash(msg).into());
|
||||
}
|
||||
|
||||
let tip = {
|
||||
wallet_lock!(wallet_inst, w);
|
||||
w.w2n_client().get_chain_tip()?
|
||||
};
|
||||
|
||||
let start_height = match start_height {
|
||||
Some(h) => h,
|
||||
None => 1,
|
||||
};
|
||||
|
||||
let info = scan::scan_rewind_hash(
|
||||
wallet_inst,
|
||||
rewind_hash,
|
||||
start_height,
|
||||
tip.0,
|
||||
status_send_channel,
|
||||
)?;
|
||||
Ok(info)
|
||||
}
|
||||
|
||||
/// check repair
|
||||
/// Accepts a wallet inst instead of a raw wallet so it can
|
||||
/// lock as little as possible
|
||||
|
||||
Reference in New Issue
Block a user