Skip to content

Commit

Permalink
testmempoolaccept add maxfeerate param
Browse files Browse the repository at this point in the history
  • Loading branch information
mononaut committed Mar 24, 2024
1 parent 055ac9f commit 946ea71
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,16 @@ impl Daemon {
.chain_err(|| "failed to parse txid")
}

pub fn test_mempool_accept(&self, txhex: Vec<String>) -> Result<Vec<MempoolAcceptResult>> {
let result = self.request("testmempoolaccept", json!([txhex]))?;
pub fn test_mempool_accept(
&self,
txhex: Vec<String>,
maxfeerate: Option<f32>,
) -> Result<Vec<MempoolAcceptResult>> {
let params = match maxfeerate {
Some(rate) => json!([txhex, format!("{:.8}", rate)]),
None => json!([txhex]),
};
let result = self.request("testmempoolaccept", params)?;
serde_json::from_value::<Vec<MempoolAcceptResult>>(result)
.chain_err(|| "invalid testmempoolaccept reply")
}
Expand Down
8 changes: 6 additions & 2 deletions src/new_index/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ impl Query {
Ok(txid)
}

pub fn test_mempool_accept(&self, txhex: Vec<String>) -> Result<Vec<MempoolAcceptResult>> {
self.daemon.test_mempool_accept(txhex)
pub fn test_mempool_accept(
&self,
txhex: Vec<String>,
maxfeerate: Option<f32>,
) -> Result<Vec<MempoolAcceptResult>> {
self.daemon.test_mempool_accept(txhex, maxfeerate)
}

pub fn utxo(&self, scripthash: &[u8]) -> Result<Vec<Utxo>> {
Expand Down
9 changes: 8 additions & 1 deletion src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,9 +1207,16 @@ fn handle_request(
.split(',')
.map(|s| s.to_string())
.collect();
let maxfeerate = query_params
.get("maxfeerate")
.map(|s| {
s.parse::<f32>()
.map_err(|_| HttpError::from("Invalid maxfeerate".to_string()))
})
.transpose()?;

let result = query
.test_mempool_accept(txhexes)
.test_mempool_accept(txhexes, maxfeerate)
.map_err(|err| HttpError::from(err.description().to_string()))?;

json_response(result, TTL_SHORT)
Expand Down

0 comments on commit 946ea71

Please sign in to comment.