corepc_client/client_sync/v28/
raw_transactions.rs

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 Bitcoin Core `v28`.
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 Bitcoin Core JSON-RPC API method `submitpackage`
13#[macro_export]
14macro_rules! impl_client_v28__submitpackage {
15    () => {
16        impl Client {
17            pub fn submit_package(
18                &self,
19                package: &[bitcoin::Transaction],
20                max_fee_rate: Option<bitcoin::FeeRate>,
21                max_burn_amount: Option<bitcoin::Amount>,
22            ) -> Result<SubmitPackage> {
23                let package_txs = package
24                    .into_iter()
25                    .map(|tx| bitcoin::consensus::encode::serialize_hex(tx))
26                    .collect::<Vec<_>>();
27                let max_fee_rate_btc_kvb =
28                    max_fee_rate.map(|r| r.to_sat_per_vb_floor() as f64 / 100_000.0);
29                let max_burn_amount_btc = max_burn_amount.map(|a| a.to_btc());
30                self.call(
31                    "submitpackage",
32                    &[package_txs.into(), max_fee_rate_btc_kvb.into(), max_burn_amount_btc.into()],
33                )
34            }
35        }
36    };
37}