Skip to content
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

Implement submitpackage #8

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion client/examples/test_against_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ async fn main_result() -> Result<(), Error> {

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

Ok(())
Expand Down
32 changes: 32 additions & 0 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ use crate::queryable;
/// crate-specific Error type;
pub type Result<T> = result::Result<T, Error>;

#[derive(Debug, Serialize, Deserialize)]
pub struct PackageSubmissionFees {
pub base: f64,
#[serde(rename = "effective-feerate", skip_serializing_if = "Option::is_none")]
pub effective_feerate: Option<f64>,
#[serde(rename = "effective-includes", skip_serializing_if = "Option::is_none")]
pub effective_includes: Option<Vec<String>>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PackageTransactionResult {
pub txid: String,
#[serde(rename = "other-wtxid", skip_serializing_if = "Option::is_none")]
pub other_wtxid: Option<String>,
pub vsize: u32,
pub fees: PackageSubmissionFees,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PackageSubmissionResult {
#[serde(rename = "tx-results")]
pub tx_results: HashMap<String, PackageTransactionResult>,
#[serde(rename = "replaced-transactions", skip_serializing_if = "Option::is_none")]
pub replaced_transactions: Option<Vec<String>>,
}

/// Outpoint that serializes and deserializes as a map, instead of a string,
/// for use as RPC arguments
#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -916,6 +942,12 @@ pub trait RpcApi: Sized {
self.call("testmempoolaccept", &[hexes.into()]).await
}

async fn submit_package<R: RawTx + Send + Sync>(&self, rawtxs: &[R]) -> Result<PackageSubmissionResult> {
let hexes: Vec<serde_json::Value> =
rawtxs.to_vec().into_iter().map(|r| r.raw_hex().into()).collect();
self.call("submitpackage", &[hexes.into()]).await
}

async fn stop(&self) -> Result<String> {
self.call("stop", &[]).await
}
Expand Down
Loading