Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
1bananagirl committed Jan 8, 2025
2 parents 05f5263 + b8d09db commit dddd101
Show file tree
Hide file tree
Showing 51 changed files with 1,754 additions and 129 deletions.
2 changes: 2 additions & 0 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,14 @@ impl KaspaCli {

if let Ok(msg) = msg {
match *msg {
Events::WalletList { .. } => {},
Events::WalletPing => {
// log_info!("Kaspa NG - received wallet ping");
},
Events::Metrics { network_id : _, metrics : _ } => {
// log_info!("Kaspa NG - received metrics event {metrics:?}")
}
Events::FeeRate { .. } => {},
Events::Error { message } => { terrorln!(this,"{message}"); },
Events::UtxoProcStart => {},
Events::UtxoProcStop => {},
Expand Down
8 changes: 6 additions & 2 deletions cli/src/modules/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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?;
Expand All @@ -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!(
Expand Down
5 changes: 4 additions & 1 deletion cli/src/modules/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");

Expand Down
5 changes: 5 additions & 0 deletions cli/src/modules/pskb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 3 additions & 0 deletions cli/src/modules/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -27,6 +29,7 @@ impl Send {
let (summary, _ids) = account
.send(
outputs.into(),
fee_rate,
priority_fee_sompi.into(),
None,
wallet_secret,
Expand Down
3 changes: 3 additions & 0 deletions cli/src/modules/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions cli/src/modules/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand All @@ -32,6 +34,7 @@ impl Transfer {
let (summary, _ids) = account
.send(
outputs.into(),
fee_rate,
priority_fee_sompi.into(),
None,
wallet_secret,
Expand Down
2 changes: 1 addition & 1 deletion crypto/txscript/src/opcodes/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ macro_rules! opcode_list {
}
}
else if let Some(Ok(value)) = token.strip_prefix("0x").and_then(|trimmed| Some(hex::decode(trimmed))) {
builder.extend(&value);
builder.script_mut().extend(&value);
}
else if token.len() >= 2 && token.chars().nth(0) == Some('\'') && token.chars().last() == Some('\'') {
builder.add_data(token[1..token.len()-1].as_bytes())?;
Expand Down
10 changes: 7 additions & 3 deletions crypto/txscript/src/script_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ impl ScriptBuilder {
&self.script
}

#[cfg(any(test, target_arch = "wasm32"))]
pub fn extend(&mut self, data: &[u8]) {
self.script.extend(data);
pub fn script_mut(&mut self) -> &mut Vec<u8> {
&mut self.script
}

// #[cfg(any(test, target_arch = "wasm32"))]
// pub fn extend(&mut self, data: &[u8]) {
// self.script.extend(data);
// }

pub fn drain(&mut self) -> Vec<u8> {
// Note that the internal script, when taken, is replaced by
// vector with no predefined capacity because the script
Expand Down
2 changes: 1 addition & 1 deletion crypto/txscript/src/wasm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl ScriptBuilder {
pub fn from_script(script: BinaryT) -> Result<ScriptBuilder> {
let builder = ScriptBuilder::default();
let script = script.try_as_vec_u8()?;
builder.inner_mut().extend(&script);
builder.inner_mut().script_mut().extend(&script);

Ok(builder)
}
Expand Down
9 changes: 8 additions & 1 deletion rpc/wrpc/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 2 additions & 2 deletions rpc/wrpc/wasm/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down
5 changes: 5 additions & 0 deletions wallet/bip32/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions wallet/core/src/account/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct AccountDescriptor {
pub prv_key_data_ids: AssocPrvKeyDataIds,
pub receive_address: Option<Address>,
pub change_address: Option<Address>,
pub addresses: Option<Vec<Address>>,

pub properties: BTreeMap<AccountDescriptorProperty, AccountDescriptorValue>,
}
Expand All @@ -39,6 +40,7 @@ impl AccountDescriptor {
prv_key_data_ids: AssocPrvKeyDataIds,
receive_address: Option<Address>,
change_address: Option<Address>,
addresses: Option<Vec<Address>>,
) -> Self {
Self {
kind,
Expand All @@ -48,6 +50,7 @@ impl AccountDescriptor {
prv_key_data_ids,
receive_address,
change_address,
addresses,
properties: BTreeMap::default(),
}
}
Expand Down Expand Up @@ -241,6 +244,7 @@ declare! {
accountName? : string,
receiveAddress? : Address,
changeAddress? : Address,
addresses? : Address[],
prvKeyDataIds : HexString[],
// balance? : Balance,
[key: string]: any
Expand All @@ -259,6 +263,9 @@ impl TryFrom<AccountDescriptor> for IAccountDescriptor {
object.set("receiveAddress", &descriptor.receive_address.into())?;
object.set("changeAddress", &descriptor.change_address.into())?;

let addresses = js_sys::Array::from_iter(descriptor.addresses.into_iter().map(JsValue::from));
object.set("addresses", &addresses)?;

let prv_key_data_ids = js_sys::Array::from_iter(descriptor.prv_key_data_ids.into_iter().map(JsValue::from));
object.set("prvKeyDataIds", &prv_key_data_ids)?;

Expand Down
Loading

0 comments on commit dddd101

Please sign in to comment.