Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit ec80919

Browse files
committed
Add submitpackage call to client
1 parent 8a1748a commit ec80919

File tree

6 files changed

+78
-0
lines changed

6 files changed

+78
-0
lines changed

client/src/client_sync/v28.rs renamed to client/src/client_sync/v28/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//!
55
//! We ignore option arguments unless they effect the shape of the returned JSON data.
66
7+
mod raw_transactions;
8+
79
use bitcoin::address::{Address, NetworkChecked};
810
use bitcoin::{Amount, Block, BlockHash, Txid};
911

@@ -30,6 +32,7 @@ crate::impl_client_check_expected_server_version!({ [280000] });
3032

3133
// == Rawtransactions ==
3234
crate::impl_client_v17__sendrawtransaction!();
35+
crate::impl_client_v28__submitpackage!();
3336

3437
// == Wallet ==
3538
crate::impl_client_v17__createwallet!();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! Macros for implementing JSON-RPC methods on a client.
4+
//!
5+
//! Specifically this is methods found under the `== Rawtransactions ==` section of the
6+
//! API docs of `bitcoind v28.0`.
7+
//!
8+
//! All macros require `Client` to be in scope.
9+
//!
10+
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
11+
12+
/// Implements bitcoind JSON-RPC API method `submitpackage`
13+
#[macro_export]
14+
macro_rules! impl_client_v28__submitpackage {
15+
() => {
16+
impl Client {
17+
/// Submit a package of transactions to local node.
18+
///
19+
/// The package will be validated according to consensus and mempool policy rules. If any transaction passes, it will be accepted to mempool.
20+
///
21+
/// ## Arguments:
22+
/// 1. `package`: An array of raw transactions.
23+
/// The package must solely consist of a child and its parents. None of the parents may depend on each other.
24+
/// The package must be topologically sorted, with the child being the last element in the array.
25+
/// 2. `maxfeerate`: Reject transactions whose fee rate is higher than the specified value.
26+
/// Fee rates larger than 1BTC/kvB are rejected.
27+
/// Set to 0 to accept any fee rate.
28+
/// If unset, will default to 0.10 BTC/kvb.
29+
/// 3. `maxburnamount` If set, reject transactions with provably unspendable outputs (e.g. 'datacarrier' outputs that use the OP_RETURN opcode) greater than the specified value.
30+
/// If burning funds through unspendable outputs is desired, increase this value.
31+
/// This check is based on heuristics and does not guarantee spendability of outputs.
32+
pub fn submit_package(
33+
&self,
34+
package: &[bitcoin::Transaction],
35+
max_fee_rate: Option<bitcoin::FeeRate>,
36+
max_burn_amount: Option<bitcoin::Amount>,
37+
) -> Result<SubmitPackage> {
38+
let package_txs = package
39+
.into_iter()
40+
.map(|tx| bitcoin::consensus::encode::serialize_hex(tx))
41+
.collect::<Vec<_>>();
42+
let max_fee_rate_btc_kvb =
43+
max_fee_rate.map(|r| r.to_sat_per_vb_floor() as f64 / 100_000.0);
44+
let max_burn_amount_btc = max_burn_amount.map(|a| a.to_btc());
45+
self.call(
46+
"submitpackage",
47+
&[package_txs.into(), max_fee_rate_btc_kvb.into(), max_burn_amount_btc.into()],
48+
)
49+
}
50+
}
51+
};
52+
}

integration_test/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
pub mod v17;
44
pub mod v19;
55
pub mod v22;
6+
pub mod v28;
67

78
/// Requires `RPC_PORT` to be in scope.
89
use bitcoind::BitcoinD;

integration_test/src/v28/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! Macros for implementing test methods on a JSON-RPC client for `bitcoind v28.0`.
4+
5+
pub mod raw_transactions;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! Macros for implementing test methods on a JSON-RPC client.
4+
//!
5+
//! Specifically this is methods found under the `== Rawtransactions ==` section of the
6+
//! API docs of `bitcoind v28.0`.
7+
8+
/// Requires `Client` to be in scope
9+
#[macro_export] macro_rules! impl_test_v28__submitpackage {
10+
() => {
11+
#[test]
12+
fn submitpackage() {
13+
// TODO
14+
}
15+
};
16+
}

integration_test/tests/v28_api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ mod raw_transactions {
4040
use super::*;
4141

4242
impl_test_v17__sendrawtransaction!();
43+
impl_test_v28__submitpackage!();
4344
}
4445

4546
// == Wallet ==

0 commit comments

Comments
 (0)