Skip to content

Commit

Permalink
Update testmempoolaccept RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
jlest01 committed Sep 19, 2024
1 parent 06a6c15 commit ec3637e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
5 changes: 4 additions & 1 deletion client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,10 +862,13 @@ pub trait RpcApi: Sized {
fn test_mempool_accept<R: RawTx>(
&self,
rawtxs: &[R],
maxfeerate: Option<f64>,
) -> Result<Vec<json::TestMempoolAcceptResult>> {
let hexes: Vec<serde_json::Value> =
rawtxs.to_vec().into_iter().map(|r| r.raw_hex().into()).collect();
self.call("testmempoolaccept", &[hexes.into()])
let mut args = [hexes.into(), opt_into_json(maxfeerate)?];
let defaults = [null()];
self.call("testmempoolaccept", handle_defaults(&mut args, &defaults))
}

fn stop(&self) -> Result<String> {
Expand Down
8 changes: 4 additions & 4 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,13 +761,13 @@ fn test_test_mempool_accept(cl: &Client) {

let tx =
cl.create_raw_transaction(&[input.clone()], &output, Some(500_000), Some(false)).unwrap();
let res = cl.test_mempool_accept(&[&tx]).unwrap();
assert!(!res[0].allowed);
let res = cl.test_mempool_accept(&[&tx], None).unwrap();
assert!(res[0].allowed.is_some() && !res[0].allowed.unwrap());
assert!(res[0].reject_reason.is_some());
let signed =
cl.sign_raw_transaction_with_wallet(&tx, None, None).unwrap().transaction().unwrap();
let res = cl.test_mempool_accept(&[&signed]).unwrap();
assert!(res[0].allowed, "not allowed: {:?}", res[0].reject_reason);
let res = cl.test_mempool_accept(&[&signed], None).unwrap();
assert!(res[0].allowed.unwrap(), "not allowed: {:?}", res[0].reject_reason);
}

fn test_wallet_create_funded_psbt(cl: &Client) {
Expand Down
15 changes: 11 additions & 4 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,23 +833,30 @@ impl SignRawTransactionResult {
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct TestMempoolAcceptResult {
pub txid: bitcoin::Txid,
pub allowed: bool,
#[serde(rename = "reject-reason")]
pub reject_reason: Option<String>,
pub wtxid: bitcoin::Txid,
#[serde(rename = "package-error")]
pub package_error: Option<String>,
pub allowed: Option<bool>,
/// Virtual transaction size as defined in BIP 141 (only present when 'allowed' is true)
/// Added in Bitcoin Core v0.21
pub vsize: Option<u64>,
/// Transaction fees (only present if 'allowed' is true)
/// Added in Bitcoin Core v0.21
pub fees: Option<TestMempoolAcceptResultFees>,
#[serde(rename = "reject-reason")]
pub reject_reason: Option<String>,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct TestMempoolAcceptResultFees {
/// Transaction fee in BTC
#[serde(with = "bitcoin::amount::serde::as_btc")]
pub base: Amount,
// unlike GetMempoolEntryResultFees, this only has the `base` fee
/// The effective feerate per KvB
#[serde(rename = "effective-feerate", with = "bitcoin::amount::serde::as_btc")]
pub effective_feerate: Amount,
#[serde(rename = "effective-includes")]
pub effective_includes: Vec<String>,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
Expand Down

0 comments on commit ec3637e

Please sign in to comment.