Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ rust_decimal = "1.36"
# Pin wasm-bindgen/js-sys to avoid version mismatch with rusty-kaspa transitive deps (ENG-746)
wasm-bindgen = "=0.2.100"
js-sys = "=0.3.70"
criterion = "0.5.1"
56 changes: 56 additions & 0 deletions common/src/addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ pub fn multisig_address(
) -> WalletResult<Address> {
let mut sorted_extended_public_keys = extended_public_keys.as_ref().clone();
sorted_extended_public_keys.sort();
multisig_address_from_sorted_keys(
&sorted_extended_public_keys,
minimum_signatures,
prefix,
derivation_path,
)
}

pub fn multisig_address_from_sorted_keys(
sorted_extended_public_keys: &[ExtendedPublicKey<PublicKey>],
minimum_signatures: usize,
prefix: Prefix,
derivation_path: &DerivationPath,
) -> WalletResult<Address> {
let mut signing_public_keys = Vec::with_capacity(sorted_extended_public_keys.len());
for x_public_key in sorted_extended_public_keys.iter() {
let derived_key = x_public_key
Expand All @@ -46,3 +59,46 @@ pub fn multisig_address(
.to_wallet_result_internal()?;
Ok(address)
}

#[cfg(test)]
mod tests {
use super::{multisig_address, multisig_address_from_sorted_keys};
use crate::keys::master_key_path;
use kaspa_addresses::Prefix;
use kaspa_bip32::secp256k1::SecretKey;
use kaspa_bip32::{DerivationPath, ExtendedPrivateKey, Language, Mnemonic};
use std::sync::Arc;

fn xpub_from_mnemonic(
phrase: &str,
) -> kaspa_bip32::ExtendedPublicKey<kaspa_bip32::secp256k1::PublicKey> {
let mnemonic = Mnemonic::new(phrase, Language::English).unwrap();
let seed = mnemonic.to_seed("");
let xprv = ExtendedPrivateKey::<SecretKey>::new(seed).unwrap();
let xprv = xprv.derive_path(&master_key_path(true)).unwrap();
xprv.public_key()
}

#[test]
fn multisig_address_sorted_helper_matches_existing_function() {
let xpub1 = xpub_from_mnemonic(
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about",
);
let xpub2 = xpub_from_mnemonic(
"legal winner thank year wave sausage worth useful legal winner thank yellow",
);

let derivation_path: DerivationPath = "m/0/0/0".parse().unwrap();
let unsorted = Arc::new(vec![xpub2.clone(), xpub1.clone()]);

let expected = multisig_address(unsorted, 2, Prefix::Devnet, &derivation_path).unwrap();

let mut sorted = vec![xpub2, xpub1];
sorted.sort();
let actual =
multisig_address_from_sorted_keys(&sorted, 2, Prefix::Devnet, &derivation_path)
.unwrap();

assert_eq!(expected.to_string(), actual.to_string());
}
}
2 changes: 1 addition & 1 deletion common/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl WalletAddress {
}
}

#[derive(Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct WalletOutpoint {
pub transaction_id: Hash,
pub index: u32,
Expand Down
23 changes: 23 additions & 0 deletions common/src/proto_convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ impl From<WalletUtxoEntry> for ProtoUtxoEntry {
}
}

impl From<&WalletUtxoEntry> for ProtoUtxoEntry {
fn from(value: &WalletUtxoEntry) -> ProtoUtxoEntry {
ProtoUtxoEntry {
amount: value.amount,
script_public_key: Some(ProtoScriptPublicKey {
version: value.script_public_key.version as u32,
script_public_key: hex::encode(value.script_public_key.script()),
}),
block_daa_score: value.block_daa_score,
is_coinbase: value.is_coinbase,
}
}
}

pub fn utxo_entry_to_proto(value: UtxoEntry) -> ProtoUtxoEntry {
ProtoUtxoEntry {
amount: value.amount,
Expand All @@ -148,6 +162,15 @@ pub fn utxo_entry_from_proto(value: ProtoUtxoEntry) -> UtxoEntry {
}

impl WalletUtxo {
pub fn to_proto(&self, is_pending: bool, is_dust: bool) -> ProtoUtxo {
ProtoUtxo {
outpoint: Some(self.outpoint.clone().into()),
utxo_entry: Some(ProtoUtxoEntry::from(&self.utxo_entry)),
is_pending,
is_dust,
}
}

pub fn into_proto(self, is_pending: bool, is_dust: bool) -> ProtoUtxo {
ProtoUtxo {
outpoint: Some(self.outpoint.into()),
Expand Down
31 changes: 30 additions & 1 deletion daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ repository.workspace = true
name = "kaswallet-daemon"
path = "src/main.rs"

[[bin]]
name = "kaswallet-stress-bench"
path = "src/bin/kaswallet_stress_bench.rs"
required-features = ["bench"]

[dependencies]
kaswallet-common.workspace = true
kaswallet-proto.workspace = true
Expand All @@ -36,7 +41,31 @@ thiserror.workspace = true
wasm-bindgen.workspace = true
js-sys.workspace = true

[features]
bench = []

[dev-dependencies]
kaspa-consensus.workspace = true
kaspa-hashes.workspace = true
rstest.workspace = true
rstest.workspace = true
criterion.workspace = true

[[bench]]
name = "address_scaling"
harness = false
required-features = ["bench"]

[[bench]]
name = "utxo_scaling"
harness = false
required-features = ["bench"]

[[bench]]
name = "from_addresses_filter"
harness = false
required-features = ["bench"]

[[bench]]
name = "utxo_contention"
harness = false
required-features = ["bench"]
Loading
Loading