Skip to content

Commit 4406eca

Browse files
committed
Add submitpackage
1 parent 7bd815f commit 4406eca

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

client/src/client.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,18 @@ pub trait RpcApi: Sized {
10811081
self.call("sendrawtransaction", &[tx.raw_hex().into()])
10821082
}
10831083

1084+
/// Submit a package of raw transactions to the node. The package will be
1085+
/// validated according to consensus and mempool policy rules. If all
1086+
/// transactions pass, they will be accepted to mempool.
1087+
///
1088+
/// This RPC is experimental and the interface may be unstable.
1089+
fn submit_package<R: RawTx>(&self, rawtxs: &[R],
1090+
) -> Result<json::SubmitPackageResult> {
1091+
let hexes: Vec<serde_json::Value> =
1092+
rawtxs.to_vec().into_iter().map(|r| r.raw_hex().into()).collect();
1093+
self.call("submitpackage", &[hexes.into()])
1094+
}
1095+
10841096
fn estimate_smart_fee(
10851097
&self,
10861098
conf_target: u16,

json/src/lib.rs

+45
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,51 @@ pub struct TestMempoolAcceptResult {
845845
pub fees: Option<TestMempoolAcceptResultFees>,
846846
}
847847

848+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
849+
pub struct SubmitPackageResult {
850+
/// Transaction results keyed by wtxid.
851+
#[serde(rename = "tx-results")]
852+
pub tx_results: HashMap<bitcoin::Wtxid, TxResult>,
853+
854+
/// List of txids of replaced transactions.
855+
#[serde(rename = "replaced-transactions")]
856+
pub replaced_transactions: Vec<bitcoin::Txid>,
857+
}
858+
859+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
860+
pub struct TxResult{
861+
pub txid: bitcoin::Txid,
862+
863+
/// The wtxid of a different transaction with the same txid but different
864+
/// witness found in the mempool. This means the submitted transaction was
865+
/// ignored.
866+
#[serde(rename = "other-wtxid")]
867+
pub other_wtxid: Option<bitcoin::Wtxid>,
868+
869+
/// Virtual transaction size as defined in BIP 141.
870+
pub vsize: u64,
871+
872+
pub fees: Fees,
873+
}
874+
875+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
876+
pub struct Fees{
877+
/// Transaction fee.
878+
#[serde(with = "bitcoin::amount::serde::as_btc")]
879+
pub base: Amount,
880+
881+
/// If the transaction was not already in the mempool, the effective feerate
882+
/// in BTC per KvB. For example, the package feerate and/or feerate with
883+
/// modified fees from prioritisetransaction.
884+
#[serde(default, rename = "effective-feerate", with = "bitcoin::amount::serde::as_btc::opt")]
885+
pub effective_feerate: Option<Amount>,
886+
887+
/// If effective-feerate is provided, the wtxids of the transactions whose
888+
/// fees and vsizes are included in effective-feerate.
889+
#[serde(rename = "effective-includes")]
890+
pub effective_includes: Option<Vec<bitcoin::Wtxid>>,
891+
}
892+
848893
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
849894
pub struct TestMempoolAcceptResultFees {
850895
/// Transaction fee in BTC

0 commit comments

Comments
 (0)