async def transaction_get(self, writer, query): # pylint: disable=W0613 """Method: blockchain.transaction.get Return a raw transaction. """ if "params" not in query or len(query["params"]) < 1: return JsonRPCError.invalidparams() tx_hash = query["params"][0] verbose = query["params"][1] if len(query["params"]) > 1 else False if not is_hex_str(tx_hash): return JsonRPCError.invalidparams() # _ec, rawtx = await self.bx.fetch_blockchain_transaction(tx_hash) _ec, rawtx = await self.bx.fetch_mempool_transaction(tx_hash) if _ec and _ec != ZMQError.success and _ec != ZMQError.not_found: self.log.error("fetch_mempool_transaction: %s", _ec.name) return JsonRPCError.internalerror() # Behaviour is undefined in spec if not rawtx: return JsonRPCError.internalerror() # return {"result": None} if verbose: # TODO: Help needed return JsonRPCError.invalidrequest() return {"result": bh2u(rawtx)}
async def blockchain_transaction_broadcast(self, writer, query): # pylint: disable=W0613 """Method: blockchain.transaction.broadcast Broadcast a transaction to the network. """ # Note: Not yet implemented in bs v4 if "params" not in query or len(query["params"]) != 1: return JsonRPCError.invalidparams() hextx = query["params"][0] if not is_hex_str(hextx): return JsonRPCError.invalidparams() _ec, _ = await self.bx.broadcast_transaction(unhexlify(hextx)[::-1]) if _ec and _ec != 0: self.log.debug("Got error: %s", repr(_ec)) return JsonRPCError.internalerror() rawtx = unhexlify(hextx) txid = double_sha256(rawtx) return {"result": hash_to_hex_str(txid)}