예제 #1
0
파일: wallet.py 프로젝트: carpemer/bitsv
    def send(self,
             outputs,
             fee=None,
             leftover=None,
             combine=True,
             message=None,
             unspents=None,
             custom_pushdata=False):  # pragma: no cover
        """Creates a signed P2PKH transaction and attempts to broadcast it on
        the blockchain. This accepts the same arguments as
        :func:`~bitsv.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
                    BitSV will use a fee of 1 sat/byte.
        :type fee: ``int``
        :param leftover: The destination that will receive any change from the
                         transaction. By default BitSV will send any change to
                         the same address you sent from.
        :type leftover: ``str``
        :param combine: Whether or not BitSV should use all available UTXOs to
                        make future transactions smaller and therefore reduce
                        fees. By default BitSV 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 100kb.
        :type message: ``str`` if custom_pushdata = False; ``list`` of ``tuple`` if custom_pushdata = True
        :param unspents: The UTXOs to use as the inputs. By default BitSV will
                         communicate with the blockchain itself.
        :type unspents: ``list`` of :class:`~bitsv.network.meta.Unspent`
        :param custom_pushdata: Adds control over push_data elements inside of the op_return by adding the
                                "custom_pushdata" = True / False parameter as a "switch" to the
                                :func:`~bitsv.PrivateKey.send` function and the
                                :func:`~bitsv.PrivateKey.create_transaction` functions.
        :type custom_pushdata: ``bool``
        :returns: The transaction ID.
        :rtype: ``str``
        """
        self.get_unspents()
        tx_hex = self.create_transaction(outputs,
                                         fee=fee,
                                         leftover=leftover,
                                         combine=combine,
                                         message=message,
                                         unspents=unspents,
                                         custom_pushdata=custom_pushdata)

        self.network_api.broadcast_tx(tx_hex)

        return calc_txid(tx_hex)
예제 #2
0
    def send(self,
             outputs,
             fee=None,
             leftover=None,
             combine=True,
             message=None,
             unspents=None):
        """Creates a signed P2PKH transaction and attempts to broadcast it on
        the testnet blockchain. This accepts the same arguments as
        :func:`~bitsv.PrivateKeyTestnet.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
                    Bitcash will poll `<https://bitcoincashfees.earn.com>`_ 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 Bitcash will send any change to
                         the same address you sent from.
        :type leftover: ``str``
        :param combine: Whether or not Bitcash should use all available UTXOs to
                        make future transactions smaller and therefore reduce
                        fees. By default Bitcash 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 220 bytes.
        :type message: ``str``
        :param unspents: The UTXOs to use as the inputs. By default Bitcash will
                         communicate with the testnet blockchain itself.
        :type unspents: ``list`` of :class:`~bitsv.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_testnet(tx_hex)

        return calc_txid(tx_hex)
예제 #3
0
파일: wallet.py 프로젝트: carpemer/bitsv
    def send_op_return(self,
                       list_of_pushdata,
                       outputs=None,
                       fee=1,
                       unspents=None,
                       leftover=None,
                       combine=False):
        """Sends a rawtx with OP_RETURN metadata ready for broadcast.

        Parameters
        ----------
        list_of_pushdata : a list of tuples (pushdata, encoding) where encoding is either "hex" or "utf-8"
        fee : sat/byte (defaults to 1 satoshi per byte)

        Returns
        -------
        rawtx

        Examples
        --------

        list_of_pushdata =  [('6d01', 'hex'),
                            ('bitPUSHER', 'utf-8')]

        as per memo.cash protocol @ https://memo.cash/protocol this results in a "Set name" action to "bitPUSHER"
        """

        if not outputs:
            outputs = []

        self.get_unspents()
        pushdata = op_return.create_pushdata(list_of_pushdata)
        tx_hex = self.create_transaction(outputs=outputs,
                                         fee=fee,
                                         message=pushdata,
                                         custom_pushdata=True,
                                         combine=combine,
                                         unspents=unspents,
                                         leftover=leftover)

        self.network_api.broadcast_tx(tx_hex)

        return calc_txid(tx_hex)
예제 #4
0
def test_calc_txid():
    assert calc_txid(
        FINAL_TX_1
    ) == '64637ffb0d36003eccbb0317dee000ac8a2744cbea3b8a4c3a477c132bb8ca69'
예제 #5
0
파일: wallet.py 프로젝트: carpemer/bitsv
    def send_op_return(self,
                       list_of_pushdata,
                       outputs=None,
                       fee=1,
                       unspents=None,
                       leftover=None,
                       combine=False):
        """Sends a rawtx with OP_RETURN metadata ready for broadcast.

        Parameters
        ----------
        list_of_pushdata : a list of tuples (pushdata, encoding) where encoding is either "hex" or "utf-8"
        fee : sat/byte (defaults to 1 satoshi per byte)

        Returns
        -------
        rawtx

        Examples
        --------

        list_of_pushdata =  [('6d01', 'hex'),
                            ('bitPUSHER', 'utf-8')]

        as per memo.cash protocol @ https://memo.cash/protocol this results in a "Set name" action to "bitPUSHER"

        :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
                    BitSV will use a fee of 1 sat/byte
        :type fee: ``int``
        :param leftover: The destination that will receive any change from the
                         transaction. By default BitSV will send any change to
                         the same address you sent from.
        :type leftover: ``str``
        :param combine: Whether or not BitSV should use all available UTXOs to
                        make future transactions smaller and therefore reduce
                        fees. By default BitSV will consolidate UTXOs.
        :type combine: ``bool``
        :param unspents: The UTXOs to use as the inputs. By default BitSV will
                         communicate with the blockchain itself.
        :type unspents: ``list`` of :class:`~bitsv.network.meta.Unspent`
        :param list_of_pushdata: List indicating pushdata to be included in op_return as e.g.:
                                [('6d01', 'hex'),
                                 ('hello', 'utf-8')]
        :type list_of_pushdata:`list` of `tuples`
        """
        if not outputs:
            outputs = []

        self.get_unspents()
        pushdata = op_return.create_pushdata(list_of_pushdata)
        tx_hex = self.create_transaction(outputs=outputs,
                                         fee=fee,
                                         message=pushdata,
                                         custom_pushdata=True,
                                         combine=combine,
                                         unspents=unspents,
                                         leftover=leftover)

        self.network_api.broadcast_tx(tx_hex)

        return calc_txid(tx_hex)