Skip to content

Commit 9bcbdb3

Browse files
committed
Change fee_delta to SignedAmount
fee_delta can be negative. Change it from Amount to SignedAmount and update the test to confirm that a negative value is accepted.
1 parent f626af1 commit 9bcbdb3

4 files changed

Lines changed: 34 additions & 12 deletions

File tree

integration_test/tests/mining.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,28 @@ fn mining__get_network_hash_ps() {
6868
fn mining__get_prioritised_transactions() {
6969
let node = BitcoinD::with_wallet(Wallet::Default, &[]);
7070
node.fund_wallet();
71-
72-
let _ = node.client.get_prioritised_transactions().expect("getprioritisedtransactions");
71+
let (_address, txid) = node.create_mempool_transaction();
72+
73+
let fee_delta = SignedAmount::from_sat(-10_000);
74+
node.client.prioritise_transaction(&txid, fee_delta).expect("prioritisetransaction");
75+
76+
let json: GetPrioritisedTransactions =
77+
node.client.get_prioritised_transactions().expect("getprioritisedtransactions");
78+
let model: Result<mtype::GetPrioritisedTransactions, bitcoin::hex::HexToArrayError> =
79+
json.into_model();
80+
let model = model.unwrap();
81+
82+
let prioritised_tx = model.0.get(&txid).expect("prioritised transaction should be present");
83+
assert_eq!(prioritised_tx.fee_delta, fee_delta);
84+
85+
// modified_fee is only returned in v27 and above
86+
#[cfg(not(feature = "v26_and_below"))]
87+
{
88+
let transaction = node.client.get_transaction(txid).expect("gettransaction");
89+
let transaction = transaction.into_model().unwrap();
90+
let base_fee = -transaction.fee.expect("transaction fee should be present");
91+
assert_eq!(prioritised_tx.modified_fee, Some(base_fee + fee_delta));
92+
}
7393
}
7494

7595
#[test]

types/src/model/mining.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use std::collections::BTreeMap;
99

1010
use bitcoin::{
11-
block, Amount, BlockHash, CompactTarget, FeeRate, SignedAmount, Target, Transaction, Txid,
12-
Weight, Wtxid,
11+
block, BlockHash, CompactTarget, FeeRate, SignedAmount, Target, Transaction, Txid, Weight,
12+
Wtxid,
1313
};
1414
use serde::{Deserialize, Serialize};
1515

@@ -151,9 +151,11 @@ pub struct GetPrioritisedTransactions(pub BTreeMap<Txid, PrioritisedTransaction>
151151
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
152152
pub struct PrioritisedTransaction {
153153
/// Transaction fee delta in satoshis.
154-
pub fee_delta: Amount,
154+
#[serde(with = "bitcoin::amount::serde::as_sat")]
155+
pub fee_delta: SignedAmount,
155156
/// Whether this transaction is currently in mempool.
156157
pub in_mempool: bool,
157158
/// Modified fee in satoshis. Only returned if in_mempool=true.
158-
pub modified_fee: Option<Amount>,
159+
#[serde(with = "bitcoin::amount::serde::as_sat::opt")]
160+
pub modified_fee: Option<SignedAmount>,
159161
}

types/src/v26/mining.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use std::collections::BTreeMap;
88

9-
use bitcoin::{hex, Amount, Txid};
9+
use bitcoin::{hex, SignedAmount, Txid};
1010
use serde::{Deserialize, Serialize};
1111

1212
use crate::model;
@@ -49,7 +49,7 @@ impl PrioritisedTransaction {
4949
/// Converts version specific type to a version nonspecific, more strongly typed type.
5050
pub fn into_model(self) -> model::PrioritisedTransaction {
5151
model::PrioritisedTransaction {
52-
fee_delta: Amount::from_sat(self.fee_delta as u64),
52+
fee_delta: SignedAmount::from_sat(self.fee_delta),
5353
in_mempool: self.in_mempool,
5454
modified_fee: None,
5555
}

types/src/v27/mining.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use std::collections::BTreeMap;
88

9-
use bitcoin::{hex, Amount, Txid};
9+
use bitcoin::{hex, SignedAmount, Txid};
1010
use serde::{Deserialize, Serialize};
1111

1212
use crate::model;
@@ -32,7 +32,7 @@ pub struct PrioritisedTransaction {
3232
/// Whether this transaction is currently in mempool.
3333
pub in_mempool: bool,
3434
/// Modified fee in satoshis. Only returned if in_mempool=true.
35-
pub modified_fee: Option<u64>,
35+
pub modified_fee: Option<i64>,
3636
}
3737

3838
impl GetPrioritisedTransactions {
@@ -51,9 +51,9 @@ impl PrioritisedTransaction {
5151
/// Converts version specific type to a version nonspecific, more strongly typed type.
5252
pub fn into_model(self) -> model::PrioritisedTransaction {
5353
model::PrioritisedTransaction {
54-
fee_delta: Amount::from_sat(self.fee_delta as u64),
54+
fee_delta: SignedAmount::from_sat(self.fee_delta),
5555
in_mempool: self.in_mempool,
56-
modified_fee: self.modified_fee.map(Amount::from_sat),
56+
modified_fee: self.modified_fee.map(SignedAmount::from_sat),
5757
}
5858
}
5959
}

0 commit comments

Comments
 (0)