bitcoind_request/command/get_mempool_entry.rs
1/*
2getmempoolentry "txid"
3
4Returns mempool data for given transaction
5
6Arguments:
71. txid (string, required) The transaction id (must be in mempool)
8
9Result:
10{ (json object)
11 "vsize" : n, (numeric) virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted.
12 "weight" : n, (numeric) transaction weight as defined in BIP 141.
13 "fee" : n, (numeric) transaction fee in BTC (DEPRECATED)
14 "modifiedfee" : n, (numeric) transaction fee with fee deltas used for mining priority (DEPRECATED)
15 "time" : xxx, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT
16 "height" : n, (numeric) block height when transaction entered pool
17 "descendantcount" : n, (numeric) number of in-mempool descendant transactions (including this one)
18 "descendantsize" : n, (numeric) virtual transaction size of in-mempool descendants (including this one)
19 "descendantfees" : n, (numeric) modified fees (see above) of in-mempool descendants (including this one) (DEPRECATED)
20 "ancestorcount" : n, (numeric) number of in-mempool ancestor transactions (including this one)
21 "ancestorsize" : n, (numeric) virtual transaction size of in-mempool ancestors (including this one)
22 "ancestorfees" : n, (numeric) modified fees (see above) of in-mempool ancestors (including this one) (DEPRECATED)
23 "wtxid" : "hex", (string) hash of serialized transaction, including witness data
24 "fees" : { (json object)
25 "base" : n, (numeric) transaction fee in BTC
26 "modified" : n, (numeric) transaction fee with fee deltas used for mining priority in BTC
27 "ancestor" : n, (numeric) modified fees (see above) of in-mempool ancestors (including this one) in BTC
28 "descendant" : n (numeric) modified fees (see above) of in-mempool descendants (including this one) in BTC
29 },
30 "depends" : [ (json array) unconfirmed transactions used as inputs for this transaction
31 "hex", (string) parent transaction id
32 ...
33 ],
34 "spentby" : [ (json array) unconfirmed transactions spending outputs from this transaction
35 "hex", (string) child transaction id
36 ...
37 ],
38 "bip125-replaceable" : true|false, (boolean) Whether this transaction could be replaced due to BIP125 (replace-by-fee)
39 "unbroadcast" : true|false (boolean) Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by any peers)
40}
41
42Examples:
43> bitcoin-cli getmempoolentry "mytxid"
44> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getmempoolentry", "params": ["mytxid"]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
45*/
46use serde::{Deserialize, Serialize};
47use serde_json::value::to_raw_value;
48
49use crate::client::Client;
50use crate::{command::CallableCommand, Blockhash};
51
52use crate::command::request::request;
53
54type TxId = String;
55pub struct GetMempoolEntryCommand {
56 txid: TxId,
57}
58
59impl GetMempoolEntryCommand {
60 pub fn new(txid: TxId) -> Self {
61 GetMempoolEntryCommand { txid }
62 }
63}
64#[derive(Serialize, Deserialize, Debug)]
65pub struct Fees {
66 pub base: f64,
67 pub modified: f64,
68 pub ancestor: f64,
69 pub descendant: f64,
70}
71
72#[derive(Serialize, Deserialize, Debug)]
73pub struct GetMempoolEntryCommandResponse {
74 pub vsize: u64,
75 pub weight: u64,
76 pub fee: f64,
77 pub modifiedfee: f64,
78 // TODO: represent using unix time
79 pub time: u64,
80 pub height: u64,
81 pub descendantcount: u64,
82 pub descendantsize: u64,
83 pub descendantfees: u64,
84 pub ancestorcount: u64,
85 pub ancestorsize: u64,
86 pub ancestorfees: u64,
87 // TODO: represent using hex
88 pub wtxid: String,
89 pub fees: Fees,
90 pub depends: Vec<String>,
91 pub spentby: Vec<String>,
92 #[serde(alias = "bip125-replaceable")]
93 pub bip125_replaceable: bool,
94 pub unbroadcast: bool,
95}
96
97impl CallableCommand for GetMempoolEntryCommand {
98 type Response = GetMempoolEntryCommandResponse;
99 fn call(&self, client: &Client) -> Result<Self::Response, jsonrpc::Error> {
100 let txid_arg = &self.txid;
101 // TODO: Add blockhas param!
102 //let blockhash_arg = &self.blockhash.0;
103 let txid_arg_raw_value = to_raw_value(&txid_arg).unwrap();
104 let command = "getmempoolentry";
105 let params = vec![txid_arg_raw_value];
106 let r = request(client, command, params);
107 let response: GetMempoolEntryCommandResponse = r.result()?;
108 Ok(response)
109 }
110}