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

Update testmempoolaccept RPC #369

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
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