Skip to content

Add submitpackage #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,17 @@ pub trait RpcApi: Sized {
self.call("sendrawtransaction", &[tx.raw_hex().into()])
}

/// Submit a package of raw transactions to the node. The package will be
/// validated according to consensus and mempool policy rules. If all
/// transactions pass, they will be accepted to mempool.
///
/// This RPC is experimental and the interface may be unstable.
fn submit_package<R: RawTx>(&self, rawtxs: &[R]) -> Result<json::SubmitPackageResult> {
let hexes: Vec<serde_json::Value> =
rawtxs.to_vec().into_iter().map(|r| r.raw_hex().into()).collect();
self.call("submitpackage", &[hexes.into()])
}

fn estimate_smart_fee(
&self,
conf_target: u16,
Expand Down
45 changes: 45 additions & 0 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,51 @@ pub struct TestMempoolAcceptResult {
pub fees: Option<TestMempoolAcceptResultFees>,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct Fees {
/// Transaction fee.
#[serde(with = "bitcoin::amount::serde::as_btc")]
pub base: Amount,

/// If the transaction was not already in the mempool, the effective feerate
/// in BTC per KvB. For example, the package feerate and/or feerate with
/// modified fees from prioritisetransaction.
#[serde(default, rename = "effective-feerate", with = "bitcoin::amount::serde::as_btc::opt")]
pub effective_feerate: Option<Amount>,

/// If effective-feerate is provided, the wtxids of the transactions whose
/// fees and vsizes are included in effective-feerate.
#[serde(rename = "effective-includes")]
pub effective_includes: Option<Vec<bitcoin::Wtxid>>,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct TxResult {
pub txid: bitcoin::Txid,

/// The wtxid of a different transaction with the same txid but different
/// witness found in the mempool. This means the submitted transaction was
/// ignored.
#[serde(rename = "other-wtxid")]
pub other_wtxid: Option<bitcoin::Wtxid>,

/// Virtual transaction size as defined in BIP 141.
pub vsize: u64,

pub fees: Fees,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct SubmitPackageResult {
/// Transaction results keyed by wtxid.
#[serde(rename = "tx-results")]
pub tx_results: HashMap<bitcoin::Wtxid, TxResult>,

/// List of txids of replaced transactions.
#[serde(rename = "replaced-transactions")]
pub replaced_transactions: Vec<bitcoin::Txid>,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct TestMempoolAcceptResultFees {
/// Transaction fee in BTC
Expand Down