Skip to content
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
9 changes: 9 additions & 0 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ impl Daemon {
.context("failed to broadcast transaction")
}

pub(crate) fn test_mempool_accept(
&self,
txs: &[&Transaction],
) -> Result<Vec<json::TestMempoolAcceptResult>> {
self.rpc
.test_mempool_accept(txs)
.context("failed to broadcast transaction")
}

pub(crate) fn get_transaction_info(
&self,
txid: &Txid,
Expand Down
25 changes: 24 additions & 1 deletion src/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
types::ScriptHash,
};

const PROTOCOL_VERSION: &str = "1.4";
const PROTOCOL_VERSION: &str = "1.5";
const UNKNOWN_FEE: isize = -1; // (allowed by Electrum protocol)

const UNSUBSCRIBED_QUERY_MESSAGE: &str = "your wallet uses less efficient method of querying electrs, consider contacting the developer of your wallet. Reason:";
Expand Down Expand Up @@ -364,6 +364,26 @@ impl Rpc {
Ok(json!(txid))
}

fn testmempoolaccept(&self, (txs_hex,): &(String,)) -> Result<Value> {
let tx_hex_vec: Vec<String> = txs_hex.split(',').map(|s| s.trim().to_string()).collect();

let txs = tx_hex_vec
.iter()
.map(|tx_hex| {
let tx_bytes = Vec::from_hex(tx_hex).context("non-hex transaction")?;
let tx = deserialize(&tx_bytes).context("invalid transaction")?;
Ok(tx)
})
.collect::<Result<Vec<bitcoin::Transaction>>>()?;

let txs_ref: Vec<&bitcoin::Transaction> = txs.iter().collect();
let txs_arr = txs_ref.as_slice();

let result = self.daemon.test_mempool_accept(txs_arr).unwrap();

Ok(json!(result))
}

fn transaction_get(&self, args: &TxGetArgs) -> Result<Value> {
let (txid, verbose) = args.into();
if verbose {
Expand Down Expand Up @@ -557,6 +577,7 @@ impl Rpc {
Params::ScriptHashSubscribe(args) => self.scripthash_subscribe(client, args),
Params::ScriptHashUnsubscribe(args) => self.scripthash_unsubscribe(client, args),
Params::TransactionBroadcast(args) => self.transaction_broadcast(args),
Params::TestMempoolAccept(args) => self.testmempoolaccept(args),
Params::TransactionGet(args) => self.transaction_get(args),
Params::TransactionGetMerkle(args) => self.transaction_get_merkle(args),
Params::TransactionFromPosition(args) => self.transaction_from_pos(*args),
Expand All @@ -573,6 +594,7 @@ enum Params {
BlockHeader((usize,)),
BlockHeaders((usize, usize)),
TransactionBroadcast((String,)),
TestMempoolAccept((String,)),
Donation,
EstimateFee((u16,)),
Features,
Expand Down Expand Up @@ -606,6 +628,7 @@ impl Params {
"blockchain.scripthash.subscribe" => Params::ScriptHashSubscribe(convert(params)?),
"blockchain.scripthash.unsubscribe" => Params::ScriptHashUnsubscribe(convert(params)?),
"blockchain.transaction.broadcast" => Params::TransactionBroadcast(convert(params)?),
"blockchain.mempool.testmempoolaccept" => Params::TestMempoolAccept(convert(params)?),
"blockchain.transaction.get" => Params::TransactionGet(convert(params)?),
"blockchain.transaction.get_merkle" => Params::TransactionGetMerkle(convert(params)?),
"blockchain.transaction.id_from_pos" => {
Expand Down