Skip to content

Commit ab47e49

Browse files
committed
Merge #605: Change fee_delta to SignedAmount
9bcbdb3 Change fee_delta to SignedAmount (Jamil Lambert, PhD) Pull request description: `fee_delta` can be negative. Change it from `Amount` to `SignedAmount` and update the test to confirm that a negative value is accepted. ACKs for top commit: tcharding: ACK 9bcbdb3 Tree-SHA512: 22a5bc004e0f8f4c67d8786754366a3e686a8c4e69c0a57d446d2a0480951a47e36e41f47a2d6d6a94f79c7cc1a70b78fa3c79e03278405a3ac99527930bff8e
2 parents 096c25d + 9bcbdb3 commit ab47e49

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
@@ -71,8 +71,28 @@ fn mining__get_network_hash_ps() {
7171
fn mining__get_prioritised_transactions() {
7272
let node = BitcoinD::with_wallet(Wallet::Default, &[]);
7373
node.fund_wallet();
74-
75-
let _ = node.client.get_prioritised_transactions().expect("getprioritisedtransactions");
74+
let (_address, txid) = node.create_mempool_transaction();
75+
76+
let fee_delta = SignedAmount::from_sat(-10_000);
77+
node.client.prioritise_transaction(&txid, fee_delta).expect("prioritisetransaction");
78+
79+
let json: GetPrioritisedTransactions =
80+
node.client.get_prioritised_transactions().expect("getprioritisedtransactions");
81+
let model: Result<mtype::GetPrioritisedTransactions, bitcoin::hex::HexToArrayError> =
82+
json.into_model();
83+
let model = model.unwrap();
84+
85+
let prioritised_tx = model.0.get(&txid).expect("prioritised transaction should be present");
86+
assert_eq!(prioritised_tx.fee_delta, fee_delta);
87+
88+
// modified_fee is only returned in v27 and above
89+
#[cfg(not(feature = "v26_and_below"))]
90+
{
91+
let transaction = node.client.get_transaction(txid).expect("gettransaction");
92+
let transaction = transaction.into_model().unwrap();
93+
let base_fee = -transaction.fee.expect("transaction fee should be present");
94+
assert_eq!(prioritised_tx.modified_fee, Some(base_fee + fee_delta));
95+
}
7696
}
7797

7898
#[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)