From 3cf46338ee6fca4a7a3f7fcb4733852fe14f3d7f Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Tue, 12 Dec 2023 01:05:44 -0500 Subject: [PATCH] Have Bitcoin's send_raw_transaction considered succeeded if already sent --- coins/bitcoin/src/rpc.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/coins/bitcoin/src/rpc.rs b/coins/bitcoin/src/rpc.rs index 687b6eea..38b53cc7 100644 --- a/coins/bitcoin/src/rpc.rs +++ b/coins/bitcoin/src/rpc.rs @@ -187,7 +187,20 @@ impl Rpc { /// Publish a transaction. pub async fn send_raw_transaction(&self, tx: &Transaction) -> Result { - let txid = self.rpc_call("sendrawtransaction", json!([encode::serialize_hex(tx)])).await?; + let txid = match self.rpc_call("sendrawtransaction", json!([encode::serialize_hex(tx)])).await { + Ok(txid) => txid, + Err(e) => { + // A const from Bitcoin's bitcoin/src/rpc/protocol.h + const RPC_VERIFY_ALREADY_IN_CHAIN: isize = -27; + // If this was already successfully published, consider this having succeeded + if let RpcError::RequestError(Error { code, .. }) = e { + if code == RPC_VERIFY_ALREADY_IN_CHAIN { + return Ok(tx.txid()); + } + } + Err(e)? + } + }; if txid != tx.txid() { Err(RpcError::InvalidResponse("returned TX ID inequals calculated TX ID"))?; }