@@ -1888,6 +1888,37 @@ async def package_broadcast(self, tx_package: Sequence[str], verbose: bool = Fal
18881888 response ['errors' ] = errors
18891889 return response
18901890
1891+ async def transaction_testmempoolaccept (self , raw_txs : Sequence [str ]) -> Sequence [dict ]:
1892+ """Returns result of mempool acceptance tests indicating if txs would be accepted by mempool.
1893+
1894+ raw_txs: a list of raw transactions as hexadecimal strings
1895+ """
1896+ assert_list_or_tuple (raw_txs )
1897+ for raw_tx in raw_txs :
1898+ assert_hex_str (raw_tx )
1899+ self .bump_cost (0.25 + sum (len (tx ) / 5000 for tx in raw_txs ))
1900+ daemon_result = await self .daemon_request ("testmempoolaccept" , raw_txs )
1901+
1902+ response : list [dict ] = []
1903+ for orig_item in daemon_result : # one item for each tx
1904+ new_item = {
1905+ "txid" : orig_item ["txid" ],
1906+ "wtxid" : orig_item ["wtxid" ],
1907+ }
1908+ # optional: "allowed" field
1909+ if orig_item .get ("allowed" ) in (True , False ):
1910+ new_item ["allowed" ] = orig_item ["allowed" ]
1911+ # optional: "reason" field
1912+ reason_str = (
1913+ orig_item .get ("package-error" )
1914+ or orig_item .get ("reject-details" )
1915+ or orig_item .get ("reject-reason" )
1916+ or None )
1917+ if reason_str is not None :
1918+ new_item ["reason" ] = reason_str
1919+ response .append (new_item )
1920+ return response
1921+
18911922 async def transaction_get (self , tx_hash : str , verbose = False ):
18921923 '''Return the serialized raw transaction given its hash
18931924
@@ -2048,6 +2079,7 @@ def set_request_handlers(self, ptuple):
20482079
20492080 # experimental:
20502081 if ptuple >= (1 , 7 ):
2082+ handlers ['blockchain.transaction.testmempoolaccept' ] = self .transaction_testmempoolaccept
20512083 handlers ['blockchain.outpoint.subscribe' ] = self .txoutpoint_subscribe
20522084 handlers ['blockchain.outpoint.get_status' ] = self .txoutpoint_get_status
20532085 handlers ['blockchain.outpoint.unsubscribe' ] = self .txoutpoint_unsubscribe
0 commit comments