def post_action_broadcast(self): if not self.check_input_arguments(["tx_hex"]): return self._response(error_msg.PARAMS_ERROR) try: NetworkAPI.broadcast_tx(self._input.get("tx_hex", None)) except Exception as e: logger.error("broadcast_tx error tx:{0}. error:{1}".format( self._input.get("tx_hex"), e)) return self._response(error_msg.SERVER_ERROR) return self._response()
def send(self, outputs, fee=None, leftover=None, combine=True, message=None, unspents=None): # pragma: no cover """Creates a signed P2PKH transaction and attempts to broadcast it on the blockchain. This accepts the same arguments as :func:`~bit.PrivateKey.create_transaction`. :param outputs: A sequence of outputs you wish to send in the form ``(destination, amount, currency)``. The amount can be either an int, float, or string as long as it is a valid input to ``decimal.Decimal``. The currency must be :ref:`supported <supported currencies>`. :type outputs: ``list`` of ``tuple`` :param fee: The number of satoshi per byte to pay to miners. By default Bit will poll `<https://bitcoinfees.21.co>`_ and use a fee that will allow your transaction to be confirmed as soon as possible. :type fee: ``int`` :param leftover: The destination that will receive any change from the transaction. By default Bit will send any change to the same address you sent from. :type leftover: ``str`` :param combine: Whether or not Bit should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bit will consolidate UTXOs. :type combine: ``bool`` :param message: A message to include in the transaction. This will be stored in the blockchain forever. Due to size limits, each message will be stored in chunks of 40 bytes. :type message: ``str`` :param unspents: The UTXOs to use as the inputs. By default Bit will communicate with the blockchain itself. :type unspents: ``list`` of :class:`~bit.network.meta.Unspent` :returns: The transaction ID. :rtype: ``str`` """ tx_hex = self.create_transaction(outputs, fee=fee, leftover=leftover, combine=combine, message=message, unspents=unspents) NetworkAPI.broadcast_tx(tx_hex) return calc_txid(tx_hex)
def send_tx(coin, account, to, amount): """ Send transaction --- Parameter: coin - coin type (defined in `constants.py`) account - eth_account Account object to - recipient wallet address amount - amount to send """ tx = create_tx(coin, account, to, amount) if (tx == ""): print(f"Unable to process {coin}") return "" signed_tx = account.sign_transaction(tx) if (coin == ETH): return w3.eth.sendRawTransaction(signed_tx.rawTransaction) elif (coin == BTCTEST): return NetworkAPI.broadcast_tx_testnet(signed_tx) elif (coin == BTC): return NetworkAPI.broadcast_tx(signed_tx) else: print(f"Unable to process {coin}") return ""
def send_tx(coin, account, to, amount): raw_tx = create_tx(coin, account, to, amount) signed_tx = account.sign_transaction(raw_tx) if coin is ETH: return w3.eth.sendRawTransaction(signed_tx.rawTransaction) elif coin is BTCTEST: return NetworkAPI.broadcast_tx_testnet(signed_tx) elif coin is BTC: return NetworkAPI.broadcast_tx(signed_tx) else: return None
def post_transaction_to_bitcoin_network(tx): NetworkAPI.broadcast_tx(tx.serialize())