Fix Scan TAddrs
This commit is contained in:
parent
09f2c10930
commit
ee76725695
|
@ -271,7 +271,9 @@ struct CResult_____c_char shield_taddr(uint8_t coin,
|
||||||
uint64_t amount,
|
uint64_t amount,
|
||||||
uint32_t confirmations);
|
uint32_t confirmations);
|
||||||
|
|
||||||
struct CResult______u8 scan_transparent_accounts(uint32_t gap_limit);
|
struct CResult______u8 scan_transparent_accounts(uint8_t coin,
|
||||||
|
uint32_t account,
|
||||||
|
uint32_t gap_limit);
|
||||||
|
|
||||||
struct CResult_____c_char prepare_multi_payment(uint8_t coin,
|
struct CResult_____c_char prepare_multi_payment(uint8_t coin,
|
||||||
uint32_t account,
|
uint32_t account,
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use crate::coinconfig::CoinConfig;
|
use crate::coinconfig::CoinConfig;
|
||||||
use crate::db::data_generated::fb::{
|
use crate::db::data_generated::fb::{
|
||||||
AddressBalance, AddressBalanceArgs, AddressBalanceVec, AddressBalanceVecArgs, BackupT, KeyPackT,
|
BackupT, KeyPackT, AddressBalanceVecT, AddressBalanceT,
|
||||||
};
|
};
|
||||||
use crate::db::AccountData;
|
use crate::db::AccountData;
|
||||||
use crate::key2::decode_key;
|
use crate::key2::decode_key;
|
||||||
|
@ -265,35 +265,24 @@ pub async fn get_taddr_balance(coin: u8, id_account: u32) -> anyhow::Result<u64>
|
||||||
/// is exceeded and no balance was found
|
/// is exceeded and no balance was found
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
/// * `gap_limit`: number of accounts with 0 balance before the scan stops
|
/// * `gap_limit`: number of accounts with 0 balance before the scan stops
|
||||||
pub async fn scan_transparent_accounts(gap_limit: usize) -> anyhow::Result<Vec<u8>> {
|
pub async fn scan_transparent_accounts(coin: u8, account: u32, gap_limit: usize) -> anyhow::Result<AddressBalanceVecT> {
|
||||||
let c = CoinConfig::get_active();
|
let c = CoinConfig::get(coin);
|
||||||
|
let db = c.db()?;
|
||||||
|
let account_data = db.get_account_info(account)?;
|
||||||
|
let AccountData {
|
||||||
|
seed, aindex, ..
|
||||||
|
} = account_data;
|
||||||
|
let mut addresses = vec![];
|
||||||
|
if let Some(seed) = seed {
|
||||||
let mut client = c.connect_lwd().await?;
|
let mut client = c.connect_lwd().await?;
|
||||||
let addresses =
|
addresses.extend(crate::taddr::scan_transparent_accounts(c.chain.network(), &mut client, &seed, aindex, gap_limit).await?);
|
||||||
crate::taddr::scan_transparent_accounts(c.chain.network(), &mut client, gap_limit).await?;
|
|
||||||
let mut builder = flatbuffers::FlatBufferBuilder::new();
|
|
||||||
let mut addrs = vec![];
|
|
||||||
for a in addresses {
|
|
||||||
let address = builder.create_string(&a.address);
|
|
||||||
let ab = AddressBalance::create(
|
|
||||||
&mut builder,
|
|
||||||
&AddressBalanceArgs {
|
|
||||||
index: a.index,
|
|
||||||
address: Some(address),
|
|
||||||
balance: a.balance,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
addrs.push(ab);
|
|
||||||
}
|
}
|
||||||
let addrs = builder.create_vector(&addrs);
|
let addresses: Vec<_> = addresses.iter().map(|a| AddressBalanceT { index: a.index,
|
||||||
let addrs = AddressBalanceVec::create(
|
address: Some(a.address.clone()), balance: a.balance }).collect();
|
||||||
&mut builder,
|
let addresses = AddressBalanceVecT {
|
||||||
&AddressBalanceVecArgs {
|
values: Some(addresses)
|
||||||
values: Some(addrs),
|
};
|
||||||
},
|
Ok(addresses)
|
||||||
);
|
|
||||||
builder.finish(addrs, None);
|
|
||||||
let data = builder.finished_data().to_vec();
|
|
||||||
Ok(data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the backup string. It is either the passphrase, the secret key or the viewing key
|
/// Get the backup string. It is either the passphrase, the secret key or the viewing key
|
||||||
|
|
|
@ -507,9 +507,15 @@ pub async unsafe extern "C" fn shield_taddr(
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub async unsafe extern "C" fn scan_transparent_accounts(gap_limit: u32) -> CResult<*const u8> {
|
pub async unsafe extern "C" fn scan_transparent_accounts(coin: u8, account: u32, gap_limit: u32) -> CResult<*const u8> {
|
||||||
let res = crate::api::account::scan_transparent_accounts(gap_limit as usize).await;
|
let res = async {
|
||||||
to_cresult_bytes(res)
|
let addresses = crate::api::account::scan_transparent_accounts(coin, account, gap_limit as usize).await?;
|
||||||
|
let mut builder = FlatBufferBuilder::new();
|
||||||
|
let root = addresses.pack(&mut builder);
|
||||||
|
builder.finish(root, None);
|
||||||
|
Ok(builder.finished_data().to_vec())
|
||||||
|
};
|
||||||
|
to_cresult_bytes(res.await)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|
28
src/taddr.rs
28
src/taddr.rs
|
@ -1,6 +1,6 @@
|
||||||
use crate::api::payment_v2::build_tx_plan_with_utxos;
|
use crate::api::payment_v2::build_tx_plan_with_utxos;
|
||||||
use crate::api::recipient::RecipientMemo;
|
use crate::api::recipient::RecipientMemo;
|
||||||
use crate::chain::{get_checkpoint_height, EXPIRY_HEIGHT_OFFSET};
|
use crate::chain::{get_checkpoint_height, EXPIRY_HEIGHT_OFFSET, get_latest_height};
|
||||||
use crate::coinconfig::CoinConfig;
|
use crate::coinconfig::CoinConfig;
|
||||||
use crate::db::AccountData;
|
use crate::db::AccountData;
|
||||||
use crate::key2::split_key;
|
use crate::key2::split_key;
|
||||||
|
@ -8,7 +8,7 @@ use crate::note_selection::{SecretKeys, Source, UTXO};
|
||||||
use crate::unified::orchard_as_unified;
|
use crate::unified::orchard_as_unified;
|
||||||
use crate::{
|
use crate::{
|
||||||
broadcast_tx, build_tx, AddressList, BlockId, CompactTxStreamerClient, GetAddressUtxosArg,
|
broadcast_tx, build_tx, AddressList, BlockId, CompactTxStreamerClient, GetAddressUtxosArg,
|
||||||
GetAddressUtxosReply, Hash, TransparentAddressBlockFilter, TxFilter,
|
GetAddressUtxosReply, Hash, TransparentAddressBlockFilter, TxFilter, BlockRange,
|
||||||
};
|
};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use base58check::FromBase58Check;
|
use base58check::FromBase58Check;
|
||||||
|
@ -25,7 +25,7 @@ use tonic::transport::Channel;
|
||||||
use tonic::Request;
|
use tonic::Request;
|
||||||
use zcash_client_backend::encoding::encode_transparent_address;
|
use zcash_client_backend::encoding::encode_transparent_address;
|
||||||
use zcash_params::coin::get_branch;
|
use zcash_params::coin::get_branch;
|
||||||
use zcash_primitives::consensus::{Network, Parameters};
|
use zcash_primitives::consensus::{Network, Parameters, NetworkUpgrade};
|
||||||
use zcash_primitives::legacy::TransparentAddress;
|
use zcash_primitives::legacy::TransparentAddress;
|
||||||
use zcash_primitives::memo::Memo;
|
use zcash_primitives::memo::Memo;
|
||||||
use zcash_primitives::transaction::components::OutPoint;
|
use zcash_primitives::transaction::components::OutPoint;
|
||||||
|
@ -141,10 +141,11 @@ pub async fn get_ttx_history(
|
||||||
pub async fn get_taddr_tx_count(
|
pub async fn get_taddr_tx_count(
|
||||||
client: &mut CompactTxStreamerClient<Channel>,
|
client: &mut CompactTxStreamerClient<Channel>,
|
||||||
address: &str,
|
address: &str,
|
||||||
|
range: &BlockRange,
|
||||||
) -> anyhow::Result<u32> {
|
) -> anyhow::Result<u32> {
|
||||||
let req = TransparentAddressBlockFilter {
|
let req = TransparentAddressBlockFilter {
|
||||||
address: address.to_string(),
|
address: address.to_string(),
|
||||||
range: None,
|
range: Some(range.clone()),
|
||||||
};
|
};
|
||||||
let rep = client
|
let rep = client
|
||||||
.get_taddress_txids(Request::new(req))
|
.get_taddress_txids(Request::new(req))
|
||||||
|
@ -173,16 +174,18 @@ pub async fn get_utxos(
|
||||||
pub async fn scan_transparent_accounts(
|
pub async fn scan_transparent_accounts(
|
||||||
network: &Network,
|
network: &Network,
|
||||||
client: &mut CompactTxStreamerClient<Channel>,
|
client: &mut CompactTxStreamerClient<Channel>,
|
||||||
|
seed: &str,
|
||||||
|
mut aindex: u32,
|
||||||
gap_limit: usize,
|
gap_limit: usize,
|
||||||
) -> anyhow::Result<Vec<TBalance>> {
|
) -> anyhow::Result<Vec<TBalance>> {
|
||||||
let c = CoinConfig::get_active();
|
let start: u32 = network.activation_height(NetworkUpgrade::Sapling).unwrap().into();
|
||||||
|
let end = get_latest_height(client).await?;
|
||||||
|
|
||||||
|
let range = BlockRange {
|
||||||
|
start: Some(BlockId { height: start as u64, hash: vec![] }),
|
||||||
|
end: Some(BlockId { height: end as u64, hash: vec![] }), spam_filter_threshold: 0 };
|
||||||
|
|
||||||
let mut addresses = vec![];
|
let mut addresses = vec![];
|
||||||
let db = c.db()?;
|
|
||||||
let account_data = db.get_account_info(c.id_account)?;
|
|
||||||
let AccountData {
|
|
||||||
seed, mut aindex, ..
|
|
||||||
} = account_data;
|
|
||||||
if let Some(seed) = seed {
|
|
||||||
let mut gap = 0;
|
let mut gap = 0;
|
||||||
while gap < gap_limit {
|
while gap < gap_limit {
|
||||||
let bip44_path = format!("m/44'/{}'/0'/0/{}", network.coin_type(), aindex);
|
let bip44_path = format!("m/44'/{}'/0'/0/{}", network.coin_type(), aindex);
|
||||||
|
@ -197,7 +200,7 @@ pub async fn scan_transparent_accounts(
|
||||||
});
|
});
|
||||||
gap = 0;
|
gap = 0;
|
||||||
} else {
|
} else {
|
||||||
let tx_count = get_taddr_tx_count(client, &address).await?;
|
let tx_count = get_taddr_tx_count(client, &address, &range).await?;
|
||||||
if tx_count != 0 {
|
if tx_count != 0 {
|
||||||
gap = 0;
|
gap = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -206,7 +209,6 @@ pub async fn scan_transparent_accounts(
|
||||||
}
|
}
|
||||||
aindex += 1;
|
aindex += 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(addresses)
|
Ok(addresses)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue