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

WIP - fee rate support in transaction Generator + RBF utils for PendingTransaction #552

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
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
7 changes: 5 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,6 +295,7 @@ impl Account {
start + count,
window,
sweep,
fee_rate,
&abortable,
Some(Arc::new(move |processed: usize, _, balance, txid| {
if let Some(txid) = txid {
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
25 changes: 20 additions & 5 deletions wallet/core/src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -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))?;

Expand All @@ -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))?;
Expand Down Expand Up @@ -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>,
Expand All @@ -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,
)?
Expand All @@ -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))?;

Expand Down Expand Up @@ -531,6 +544,7 @@ pub trait DerivationCapableAccount: Account {
extent: usize,
window: usize,
sweep: bool,
fee_rate: Option<f64>,
abortable: &Abortable,
notifier: Option<ScanNotifier>,
) -> Result<()> {
Expand Down Expand Up @@ -605,6 +619,7 @@ pub trait DerivationCapableAccount: Account {
1,
1,
PaymentDestination::Change,
fee_rate,
Fees::None,
None,
None,
Expand Down
1 change: 1 addition & 0 deletions wallet/core/src/account/pskb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,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,
Expand Down
3 changes: 3 additions & 0 deletions wallet/core/src/api/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ pub struct AccountsSendRequest {
pub wallet_secret: Secret,
pub payment_secret: Option<Secret>,
pub destination: PaymentDestination,
pub fee_rate: Option<f64>,
pub priority_fee_sompi: Fees,
pub payload: Option<Vec<u8>>,
}
Expand All @@ -509,6 +510,7 @@ pub struct AccountsTransferRequest {
pub wallet_secret: Secret,
pub payment_secret: Option<Secret>,
pub transfer_amount_sompi: u64,
pub fee_rate: Option<f64>,
pub priority_fee_sompi: Option<Fees>,
// pub priority_fee_sompi: Fees,
}
Expand All @@ -527,6 +529,7 @@ pub struct AccountsTransferResponse {
pub struct AccountsEstimateRequest {
pub account_id: AccountId,
pub destination: PaymentDestination,
pub fee_rate: Option<f64>,
pub priority_fee_sompi: Fees,
pub payload: Option<Vec<u8>>,
}
Expand Down
3 changes: 3 additions & 0 deletions wallet/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ pub enum Error {
#[error("Mass calculation error")]
MassCalculationError,

#[error("Transaction fees are too high")]
TransactionFeesAreTooHigh,

#[error("Invalid argument: {0}")]
InvalidArgument(String),

Expand Down
Loading
Loading