Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for update_address_indexes parameter in derivation_scan() #129

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d004d89
pending tx (WIP)
aspect Sep 2, 2024
8ccf8a4
Merge branch 'dev' of https://github.com/kaspanet/rusty-kaspa into rb…
aspect Sep 2, 2024
db21255
wip
aspect Sep 5, 2024
8d06a34
WIP fee_rate
aspect Sep 9, 2024
0ccad51
WIP
aspect Sep 9, 2024
db1ec4f
Merge branch 'dev' of https://github.com/kaspanet/rusty-kaspa into rb…
aspect Sep 9, 2024
bc254da
fee rate propagation
aspect Sep 9, 2024
e8cbe86
propagate fee_rate in generator tests
aspect Sep 9, 2024
c9e9247
WIP
aspect Sep 9, 2024
0fff1ef
change fee_rate combining to use max()
aspect Sep 9, 2024
be33081
update max() handling
aspect Sep 9, 2024
bf434fd
Merge branch 'dev' of https://github.com/kaspanet/rusty-kaspa into rb…
aspect Sep 10, 2024
4cf3d52
Generator summary aggregate_mass
aspect Sep 10, 2024
9314168
Merge branch 'dev' of https://github.com/kaspanet/rusty-kaspa into rb…
aspect Sep 10, 2024
b910457
generator summary number_of_stages
aspect Sep 11, 2024
d82b2c2
Merge branch 'master' of https://github.com/kaspanet/rusty-kaspa into…
aspect Sep 11, 2024
458354b
WIP
aspect Sep 12, 2024
bc583a5
Merge branch 'kaspanet:master' into rbf-utils
KaffinPX Sep 13, 2024
29e32c9
Merge branch 'gamma-dev' of github.com:aspectron/rusty-kaspa into rbf…
aspect Sep 13, 2024
4a1e5ef
calculateStorageMass
aspect Sep 26, 2024
5993abb
Merge branch 'gamma-dev' of github.com:aspectron/rusty-kaspa into gen…
aspect Sep 26, 2024
c8d829c
cleanup
aspect Sep 26, 2024
aaf66d4
cleanup tests
aspect Sep 26, 2024
350bd39
fix wasm imports
aspect Sep 27, 2024
8d47393
Merge branch 'master' of github.com:aspectron/rusty-kaspa into gamma-dev
aspect Sep 28, 2024
53c4bbe
update wrpc/client/Cargo.toml to include Resolvers.toml config file
aspect Sep 28, 2024
65a6967
Merge branch 'master' into gamma-dev
surinder83singh Oct 9, 2024
8147bdd
accounts_import api impl (#107)
surinder83singh Oct 10, 2024
158d4be
add missing setNetworkId to wasm Wallet()
aspect Oct 20, 2024
79cebc0
rust 1.82 updates
aspect Oct 20, 2024
c54e83d
Merge branch 'kaspanet:master' into gamma-dev
KaffinPX Oct 25, 2024
8112be1
Merge branch 'master' into gamma-dev
surinder83singh Dec 9, 2024
36d3ea2
Merge branch 'gamma' into gamma-dev
surinder83singh Dec 9, 2024
ef92116
Merge branch 'master' into gamma-dev
surinder83singh Dec 9, 2024
53fd7f8
Remove KIP9 Alpha version references
surinder83singh Dec 9, 2024
e0dc85f
Add support for `update_address_indexes` parameter in `derivation_sca…
surinder83singh Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cli/src/modules/account.rs
Original file line number Diff line number Diff line change
@@ -234,8 +234,9 @@ impl Account {
count = count.max(1);

let sweep = action.eq("sweep");

self.derivation_scan(&ctx, start, count, window, sweep).await?;
// TODO fee_rate
let fee_rate = None;
self.derivation_scan(&ctx, start, count, window, sweep, fee_rate).await?;
}
v => {
tprintln!(ctx, "unknown command: '{v}'\r\n");
@@ -276,6 +277,7 @@ impl Account {
count: usize,
window: usize,
sweep: bool,
fee_rate: Option<f64>,
) -> Result<()> {
let account = ctx.account().await?;
let (wallet_secret, payment_secret) = ctx.ask_wallet_secret(Some(&account)).await?;
@@ -293,7 +295,9 @@ impl Account {
start + count,
window,
sweep,
fee_rate,
&abortable,
true,
Some(Arc::new(move |processed: usize, _, balance, txid| {
if let Some(txid) = txid {
tprintln!(
5 changes: 4 additions & 1 deletion cli/src/modules/estimate.rs
Original file line number Diff line number Diff line change
@@ -17,13 +17,16 @@ impl Estimate {
}

let amount_sompi = try_parse_required_nonzero_kaspa_as_sompi_u64(argv.first())?;
// TODO fee_rate
let fee_rate = None;
let priority_fee_sompi = try_parse_optional_kaspa_as_sompi_i64(argv.get(1))?.unwrap_or(0);
let abortable = Abortable::default();

// just use any address for an estimate (change address)
let change_address = account.change_address()?;
let destination = PaymentDestination::PaymentOutputs(PaymentOutputs::from((change_address.clone(), amount_sompi)));
let estimate = account.estimate(destination, priority_fee_sompi.into(), None, &abortable).await?;
// TODO fee_rate
let estimate = account.estimate(destination, fee_rate, priority_fee_sompi.into(), None, &abortable).await?;

tprintln!(ctx, "Estimate - {estimate}");

5 changes: 5 additions & 0 deletions cli/src/modules/pskb.rs
Original file line number Diff line number Diff line change
@@ -45,6 +45,8 @@ impl Pskb {
let signer = account
.pskb_from_send_generator(
outputs.into(),
// fee_rate
None,
priority_fee_sompi.into(),
None,
wallet_secret.clone(),
@@ -89,12 +91,15 @@ impl Pskb {
"lock" => {
let amount_sompi = try_parse_required_nonzero_kaspa_as_sompi_u64(argv.first())?;
let outputs = PaymentOutputs::from((script_p2sh, amount_sompi));
// TODO fee_rate
let fee_rate = None;
let priority_fee_sompi = try_parse_optional_kaspa_as_sompi_i64(argv.get(1))?.unwrap_or(0);
let abortable = Abortable::default();

let signer = account
.pskb_from_send_generator(
outputs.into(),
fee_rate,
priority_fee_sompi.into(),
None,
wallet_secret.clone(),
3 changes: 3 additions & 0 deletions cli/src/modules/send.rs
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@ impl Send {

let address = Address::try_from(argv.first().unwrap().as_str())?;
let amount_sompi = try_parse_required_nonzero_kaspa_as_sompi_u64(argv.get(1))?;
// TODO fee_rate
let fee_rate = None;
let priority_fee_sompi = try_parse_optional_kaspa_as_sompi_i64(argv.get(2))?.unwrap_or(0);
let outputs = PaymentOutputs::from((address.clone(), amount_sompi));
let abortable = Abortable::default();
@@ -27,6 +29,7 @@ impl Send {
let (summary, _ids) = account
.send(
outputs.into(),
fee_rate,
priority_fee_sompi.into(),
None,
wallet_secret,
3 changes: 3 additions & 0 deletions cli/src/modules/sweep.rs
Original file line number Diff line number Diff line change
@@ -10,12 +10,15 @@ impl Sweep {

let account = ctx.wallet().account()?;
let (wallet_secret, payment_secret) = ctx.ask_wallet_secret(Some(&account)).await?;
// TODO fee_rate
let fee_rate = None;
let abortable = Abortable::default();
// let ctx_ = ctx.clone();
let (summary, _ids) = account
.sweep(
wallet_secret,
payment_secret,
fee_rate,
&abortable,
Some(Arc::new(move |_ptx| {
// tprintln!(ctx_, "Sending transaction: {}", ptx.id());
3 changes: 3 additions & 0 deletions cli/src/modules/transfer.rs
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@ impl Transfer {
return Err("Cannot transfer to the same account".into());
}
let amount_sompi = try_parse_required_nonzero_kaspa_as_sompi_u64(argv.get(1))?;
// TODO fee_rate
let fee_rate = None;
let priority_fee_sompi = try_parse_optional_kaspa_as_sompi_i64(argv.get(2))?.unwrap_or(0);
let target_address = target_account.receive_address()?;
let (wallet_secret, payment_secret) = ctx.ask_wallet_secret(Some(&account)).await?;
@@ -32,6 +34,7 @@ impl Transfer {
let (summary, _ids) = account
.send(
outputs.into(),
fee_rate,
priority_fee_sompi.into(),
None,
wallet_secret,
9 changes: 8 additions & 1 deletion rpc/wrpc/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -5,9 +5,16 @@ rust-version.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
include.workspace = true
license.workspace = true
repository.workspace = true
include = [
"src/**/*.rs",
"benches/**/*.rs",
"build.rs",
"Cargo.toml",
"Cargo.lock",
"Resolvers.toml",
]

[features]
wasm32-sdk = ["kaspa-consensus-wasm/wasm32-sdk","kaspa-rpc-core/wasm32-sdk","workflow-rpc/wasm32-sdk"]
4 changes: 2 additions & 2 deletions rpc/wrpc/wasm/src/client.rs
Original file line number Diff line number Diff line change
@@ -351,8 +351,8 @@ impl RpcClient {
/// Set the network id for the RPC client.
/// This setting will take effect on the next connection.
#[wasm_bindgen(js_name = setNetworkId)]
pub fn set_network_id(&self, network_id: &NetworkId) -> Result<()> {
self.inner.client.set_network_id(network_id)?;
pub fn set_network_id(&self, network_id: &NetworkIdT) -> Result<()> {
self.inner.client.set_network_id(&network_id.try_into_owned()?)?;
Ok(())
}

5 changes: 5 additions & 0 deletions wallet/bip32/src/lib.rs
Original file line number Diff line number Diff line change
@@ -19,6 +19,11 @@ mod prefix;
mod result;
pub mod types;

pub mod wasm {
//! WASM bindings for the `bip32` module.
pub use crate::mnemonic::{Language, Mnemonic, WordCount};
}

pub use address_type::AddressType;
pub use attrs::ExtendedKeyAttrs;
pub use child_number::ChildNumber;
75 changes: 62 additions & 13 deletions wallet/core/src/account/mod.rs
Original file line number Diff line number Diff line change
@@ -305,13 +305,19 @@ pub trait Account: AnySync + Send + Sync + 'static {
self: Arc<Self>,
wallet_secret: Secret,
payment_secret: Option<Secret>,
fee_rate: Option<f64>,
abortable: &Abortable,
notifier: Option<GenerationNotifier>,
) -> Result<(GeneratorSummary, Vec<kaspa_hashes::Hash>)> {
let keydata = self.prv_key_data(wallet_secret).await?;
let signer = Arc::new(Signer::new(self.clone().as_dyn_arc(), keydata, payment_secret));
let settings =
GeneratorSettings::try_new_with_account(self.clone().as_dyn_arc(), PaymentDestination::Change, Fees::None, None)?;
let settings = GeneratorSettings::try_new_with_account(
self.clone().as_dyn_arc(),
PaymentDestination::Change,
fee_rate,
Fees::None,
None,
)?;
let generator = Generator::try_new(settings, Some(signer), Some(abortable))?;

let mut stream = generator.stream();
@@ -334,6 +340,7 @@ pub trait Account: AnySync + Send + Sync + 'static {
async fn send(
self: Arc<Self>,
destination: PaymentDestination,
fee_rate: Option<f64>,
priority_fee_sompi: Fees,
payload: Option<Vec<u8>>,
wallet_secret: Secret,
@@ -344,7 +351,8 @@ pub trait Account: AnySync + Send + Sync + 'static {
let keydata = self.prv_key_data(wallet_secret).await?;
let signer = Arc::new(Signer::new(self.clone().as_dyn_arc(), keydata, payment_secret));

let settings = GeneratorSettings::try_new_with_account(self.clone().as_dyn_arc(), destination, priority_fee_sompi, payload)?;
let settings =
GeneratorSettings::try_new_with_account(self.clone().as_dyn_arc(), destination, fee_rate, priority_fee_sompi, payload)?;

let generator = Generator::try_new(settings, Some(signer), Some(abortable))?;

@@ -366,13 +374,15 @@ pub trait Account: AnySync + Send + Sync + 'static {
async fn pskb_from_send_generator(
self: Arc<Self>,
destination: PaymentDestination,
fee_rate: Option<f64>,
priority_fee_sompi: Fees,
payload: Option<Vec<u8>>,
wallet_secret: Secret,
payment_secret: Option<Secret>,
abortable: &Abortable,
) -> Result<Bundle, Error> {
let settings = GeneratorSettings::try_new_with_account(self.clone().as_dyn_arc(), destination, priority_fee_sompi, payload)?;
let settings =
GeneratorSettings::try_new_with_account(self.clone().as_dyn_arc(), destination, fee_rate, priority_fee_sompi, payload)?;
let keydata = self.prv_key_data(wallet_secret).await?;
let signer = Arc::new(PSKBSigner::new(self.clone().as_dyn_arc(), keydata, payment_secret));
let generator = Generator::try_new(settings, None, Some(abortable))?;
@@ -428,6 +438,7 @@ pub trait Account: AnySync + Send + Sync + 'static {
self: Arc<Self>,
destination_account_id: AccountId,
transfer_amount_sompi: u64,
fee_rate: Option<f64>,
priority_fee_sompi: Fees,
wallet_secret: Secret,
payment_secret: Option<Secret>,
@@ -451,6 +462,7 @@ pub trait Account: AnySync + Send + Sync + 'static {
let settings = GeneratorSettings::try_new_with_account(
self.clone().as_dyn_arc(),
final_transaction_destination,
fee_rate,
priority_fee_sompi,
final_transaction_payload,
)?
@@ -476,11 +488,12 @@ pub trait Account: AnySync + Send + Sync + 'static {
async fn estimate(
self: Arc<Self>,
destination: PaymentDestination,
fee_rate: Option<f64>,
priority_fee_sompi: Fees,
payload: Option<Vec<u8>>,
abortable: &Abortable,
) -> Result<GeneratorSummary> {
let settings = GeneratorSettings::try_new_with_account(self.as_dyn_arc(), destination, priority_fee_sompi, payload)?;
let settings = GeneratorSettings::try_new_with_account(self.as_dyn_arc(), destination, fee_rate, priority_fee_sompi, payload)?;

let generator = Generator::try_new(settings, None, Some(abortable))?;

@@ -517,6 +530,7 @@ pub trait AsLegacyAccount: Account {
}

/// Account trait used by derivation capable account types (BIP32, MultiSig, etc.)
#[allow(clippy::too_many_arguments)]
#[async_trait]
pub trait DerivationCapableAccount: Account {
fn derivation(&self) -> Arc<dyn AddressDerivationManagerTrait>;
@@ -531,7 +545,9 @@ pub trait DerivationCapableAccount: Account {
extent: usize,
window: usize,
sweep: bool,
fee_rate: Option<f64>,
abortable: &Abortable,
update_address_indexes: bool,
notifier: Option<ScanNotifier>,
) -> Result<()> {
if let Ok(legacy_account) = self.clone().as_legacy_account() {
@@ -558,6 +574,8 @@ pub trait DerivationCapableAccount: Account {
let mut last_notification = 0;
let mut aggregate_balance = 0;
let mut aggregate_utxo_count = 0;
let mut last_change_address_index = change_address_index;
let mut last_receive_address_index = receive_address_manager.index();

let change_address = change_address_keypair[0].0.clone();

@@ -567,8 +585,8 @@ pub trait DerivationCapableAccount: Account {
index = last as usize;

let (mut keys, addresses) = if sweep {
let mut keypairs = derivation.get_range_with_keys(false, first..last, false, &xkey).await?;
let change_keypairs = derivation.get_range_with_keys(true, first..last, false, &xkey).await?;
let mut keypairs = derivation.get_range_with_keys(false, first..last, true, &xkey).await?;
let change_keypairs = derivation.get_range_with_keys(true, first..last, true, &xkey).await?;
keypairs.extend(change_keypairs);
let mut keys = vec![];
let addresses = keypairs
@@ -581,22 +599,40 @@ pub trait DerivationCapableAccount: Account {
keys.push(change_address_keypair[0].1.to_bytes());
(keys, addresses)
} else {
let mut addresses = receive_address_manager.get_range_with_args(first..last, false)?;
let change_addresses = change_address_manager.get_range_with_args(first..last, false)?;
let mut addresses = receive_address_manager.get_range_with_args(first..last, true)?;
let change_addresses = change_address_manager.get_range_with_args(first..last, true)?;
addresses.extend(change_addresses);
(vec![], addresses)
};

let utxos = rpc.get_utxos_by_addresses(addresses.clone()).await?;
let balance = utxos.iter().map(|utxo| utxo.utxo_entry.amount).sum::<u64>();
let mut balance = 0;
let utxos = utxos
.iter()
.map(|utxo| {
let utxo_ref = UtxoEntryReference::from(utxo);
if let Some(address) = utxo_ref.utxo.address.as_ref() {
if let Some(address_index) = receive_address_manager.inner().address_to_index_map.get(address) {
if last_receive_address_index < *address_index {
last_receive_address_index = *address_index;
}
} else if let Some(address_index) = change_address_manager.inner().address_to_index_map.get(address) {
if last_change_address_index < *address_index {
last_change_address_index = *address_index;
}
} else {
panic!("Account::derivation_scan() has received an unknown address: `{address}`");
}
}
balance += utxo_ref.utxo.amount;
utxo_ref
})
.collect::<Vec<_>>();
aggregate_utxo_count += utxos.len();

if balance > 0 {
aggregate_balance += balance;

if sweep {
let utxos = utxos.into_iter().map(UtxoEntryReference::from).collect::<Vec<_>>();

let settings = GeneratorSettings::try_new_with_iterator(
self.wallet().network_id()?,
Box::new(utxos.into_iter()),
@@ -605,6 +641,7 @@ pub trait DerivationCapableAccount: Account {
1,
1,
PaymentDestination::Change,
fee_rate,
Fees::None,
None,
None,
@@ -646,6 +683,18 @@ pub trait DerivationCapableAccount: Account {
}
}

// update address manager with the last used index
if update_address_indexes {
receive_address_manager.set_index(last_receive_address_index)?;
change_address_manager.set_index(last_change_address_index)?;

let metadata = self.metadata()?.expect("derivation accounts must provide metadata");
let store = self.wallet().store().as_account_store()?;
store.update_metadata(vec![metadata]).await?;
self.clone().scan(None, None).await?;
self.wallet().notify(Events::AccountUpdate { account_descriptor: self.descriptor()? }).await?;
}

if let Ok(legacy_account) = self.as_legacy_account() {
legacy_account.clear_private_context().await?;
}
1 change: 1 addition & 0 deletions wallet/core/src/account/pskb.rs
Original file line number Diff line number Diff line change
@@ -338,6 +338,7 @@ pub fn pskt_to_pending_transaction(
priority_utxo_entries: None,
source_utxo_context: None,
destination_utxo_context: None,
fee_rate: None,
final_transaction_priority_fee: fee_u.into(),
final_transaction_destination,
final_transaction_payload: None,
Loading