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

Commit

Permalink
Add submitpackage call to client
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Aug 30, 2024
1 parent d032ef7 commit 3a3aa71
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ crate::impl_client_check_expected_server_version!({ [270000, 270100] });

// == Rawtransactions ==
crate::impl_client_v17__sendrawtransaction!();
crate::impl_client_v28__submitpackage!();

// == Wallet ==
crate::impl_client_v17__createwallet!();
Expand Down
45 changes: 45 additions & 0 deletions client/src/client_sync/v28/raw_transactions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: CC0-1.0

//! Macros for implementing JSON-RPC methods on a client.
//!
//! Specifically this is methods found under the `== Rawtransactions ==` section of the
//! API docs of `bitcoind v28.0`.
//!
//! All macros require `Client` to be in scope.
//!
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.

/// Implements bitcoind JSON-RPC API method `submitpackage`
#[macro_export]
macro_rules! impl_client_v28__submitpackage {
() => {
impl Client {
/// Submit a package of transactions to local node.
///
/// The package will be validated according to consensus and mempool policy rules. If any transaction passes, it will be accepted to mempool.
///
/// Arguments:
/// 1. package An array of raw transactions.
/// The package must solely consist of a child and its parents. None of the parents may depend on each other.
/// The package must be topologically sorted, with the child being the last element in the array.
/// 2. maxfeerate Reject transactions whose fee rate is higher than the specified value.
/// Fee rates larger than 1BTC/kvB are rejected.
/// Set to 0 to accept any fee rate.
/// If unset, will default to 0.10 BTC/kvb.
/// 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.
/// If burning funds through unspendable outputs is desired, increase this value.
/// This check is based on heuristics and does not guarantee spendability of outputs.
pub fn submit_package(
&self,
package: &[bitcoin::Transaction],
max_fee_rate: Option<bitcoin::FeeRate>,
max_burn_amount: Option<bitcoin::Amount>,
) -> Result<SubmitPackage> {
let package_txs = package.map(|tx| bitcoin::consensus::encode::serialize_hex(tx)).collect();
let max_fee_rate_btc_kvb = max_fee_rate.map(|r| r.to_sat_per_vb_floor() as f64 / 100_000.0);
let max_burn_amount_btc = max_burn_amount.map(|a| a.to_btc());
self.call("submitpackage", &[package_txs.into(), max_fee_rate_btc_kvb.into(), max_burn_amount_btc.into()])
}
}
};
}
1 change: 1 addition & 0 deletions integration_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pub mod v17;
pub mod v19;
pub mod v22;
pub mod v28;

/// Requires `RPC_PORT` to be in scope.
use bitcoind::BitcoinD;
Expand Down
17 changes: 17 additions & 0 deletions integration_test/src/v28/raw_transactions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: CC0-1.0

//! Macros for implementing test methods on a JSON-RPC client.
//!
//! Specifically this is methods found under the `== Rawtransactions ==` section of the
//! API docs of `bitcoind v28.0`.

/// Requires `Client` to be in scope
#[macro_export]
macro_rules! impl_test_v17__sendrawtransaction {
() => {
#[test]
fn submitpackage() {
// TODO
}
};
}
1 change: 1 addition & 0 deletions integration_test/tests/v28_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ mod raw_transactions {
use super::*;

impl_test_v17__sendrawtransaction!();
impl_test_v28__submitpackage!();
}

// == Wallet ==
Expand Down

0 comments on commit 3a3aa71

Please sign in to comment.