2

I try to concurrently monitor a bunch of signed but non published transactions. I want to detect asap if any of the inputs into these bond transactions have been used in another transaction in my mempool. Available for use is the bitcoin core rpc and bdk/rust bitcoin. IIUC testmempoolaccept only detects if the inputs already have been confirmed in another TX.

The straightforward way i can think of is calling getrawmempool and then getmempoolentry on each transaction, iterating trough the inputs. This can get heavy for a larger mempool.

My question is if there is another possible way to do this in a more (time) efficient manner using either the core rpc or functionality of bdk/rust bitcoin/another rust crate?

1 Answer 1

3

Using a wallet would allow you to do this, whether you choose to use BDK or Bitcoin Core's watchonly wallet. But since you are only interested in mempool transactions spending a specific output you can use the RPC command gettxspendingprevout:

gettxspendingprevout [{"txid":"hex","vout":n},...]

Scans the mempool to find transactions spending any of the given
outputs

Arguments:
1. outputs                 (json array, required) The transaction outputs that we want to check, and within each, the txid (string) vout
(numeric).
     [
       {                   (json object)
         "txid": "hex",    (string, required) The transaction id
         "vout": n,        (numeric, required) The output number
       },
       ...
     ]

Result: [                      (json array)   
  {                              (json object)
      "txid" : "hex",            (string) the transaction id of the checked output
      "vout" : n,                (numeric) the vout value of the checked output
      "spendingtxid" : "hex"     (string, optional) the transaction id of the mempool transaction spending this output (omitted if unspent)  
  },
  ...
]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.