Skip to content

Commit 54f2392

Browse files
committed
Impl. submitpackage
1 parent c863fd0 commit 54f2392

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

client/examples/test_against_node.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ async fn main_result() -> Result<(), Error> {
3737

3838
let bitcoin_block: bitcoin::Block = rpc.get_by_id(&best_block_hash).await?;
3939
println!("best block hash by `get`: {}", bitcoin_block.header.prev_blockhash);
40-
let bitcoin_tx: bitcoin::Transaction = rpc.get_by_id(&bitcoin_block.txdata[0].compute_txid()).await?;
40+
let bitcoin_tx: bitcoin::Transaction =
41+
rpc.get_by_id(&bitcoin_block.txdata[0].compute_txid()).await?;
4142
println!("tx by `get`: {}", bitcoin_tx.compute_txid());
4243

4344
Ok(())

client/src/client.rs

+35
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,32 @@ use crate::queryable;
3939
/// crate-specific Error type;
4040
pub type Result<T> = result::Result<T, Error>;
4141

42+
#[derive(Debug, Serialize, Deserialize)]
43+
pub struct PackageSubmissionFees {
44+
pub base: f64,
45+
#[serde(rename = "effective-feerate", skip_serializing_if = "Option::is_none")]
46+
pub effective_feerate: Option<f64>,
47+
#[serde(rename = "effective-includes", skip_serializing_if = "Option::is_none")]
48+
pub effective_includes: Option<Vec<String>>,
49+
}
50+
51+
#[derive(Debug, Serialize, Deserialize)]
52+
pub struct PackageTransactionResult {
53+
pub txid: String,
54+
#[serde(rename = "other-wtxid", skip_serializing_if = "Option::is_none")]
55+
pub other_wtxid: Option<String>,
56+
pub vsize: u32,
57+
pub fees: PackageSubmissionFees,
58+
}
59+
60+
#[derive(Debug, Serialize, Deserialize)]
61+
pub struct PackageSubmissionResult {
62+
#[serde(rename = "tx-results")]
63+
pub tx_results: HashMap<String, PackageTransactionResult>,
64+
#[serde(rename = "replaced-transactions", skip_serializing_if = "Option::is_none")]
65+
pub replaced_transactions: Option<Vec<String>>,
66+
}
67+
4268
/// Outpoint that serializes and deserializes as a map, instead of a string,
4369
/// for use as RPC arguments
4470
#[derive(Clone, Debug, Serialize, Deserialize)]
@@ -1140,6 +1166,15 @@ pub trait RpcApi: Sized {
11401166
self.call("sendrawtransaction", &[tx.raw_hex().into()]).await
11411167
}
11421168

1169+
/// Implement submitpackage here
1170+
async fn submit_package<R: RawTx>(&self, raw_txs: Vec<R>) -> Result<PackageSubmissionResult> {
1171+
// Convert the raw transactions to their hex representations
1172+
let hex_txs: Vec<String> = raw_txs.into_iter().map(|tx| tx.raw_hex().into()).collect();
1173+
1174+
// Make the RPC call with the array of hex-encoded transactions
1175+
self.call("submitpackage", &[hex_txs.into()]).await
1176+
}
1177+
11431178
async fn estimate_smart_fee(
11441179
&self,
11451180
conf_target: u16,

0 commit comments

Comments
 (0)