Example #1
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:`~bit.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
                    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 testnet 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_testnet(tx_hex)

        return calc_txid(tx_hex)
 def get_parent_psts(cls, inputs_per_broadcast_group, all_PSTs):
     parent_psts = []
     for inputs in inputs_per_broadcast_group:
         psts = set([])
         for input in inputs:
             if input.txid not in all_PSTs:
                 continue
             if input.txid == calc_txid(all_PSTs[input.txid]):
                 psts.add(all_PSTs[input.txid])
             else:
                 raise Exception(
                     "TxID provided doesn't match raw transaction! txid=" +
                     input.txid)
         if len(psts) == 0:
             raise Exception(
                 'Referenced pre-signed transaction(s) not found!')
         parent_psts.append(psts)
     return parent_psts
def test_calc_txid():
    assert calc_txid(
        FINAL_TX_1
    ) == 'e6922a6e3f1ff422113f15543fbe1340a727441202f55519640a70ac4636c16f'
Example #4
0
 def test_calc_txid_segwit(self):
     assert calc_txid(SEGWIT_TX_1) == 'a103ed36e9afee8b4001b1c3970ba8cd9839ff95e8b8af3fbe6016f6287bf9c6'
Example #5
0
 def test_get_transaction_by_id_test_valid(self):
     tx = SmartbitAPI.get_transaction_by_id_testnet(TEST_TX_VALID)
     assert calc_txid(tx) == TEST_TX_VALID
Example #6
0
 def test_get_transaction_by_id_valid(self):
     tx = SmartbitAPI.get_transaction_by_id(MAIN_TX_VALID)
     assert calc_txid(tx) == MAIN_TX_VALID
Example #7
0
 def test_get_transaction_by_id_test_valid(self):
     tx = BlockstreamAPI.get_transaction_by_id_testnet(TEST_TX_VALID)
     assert calc_txid(tx) == TEST_TX_VALID
Example #8
0
 def test_get_transaction_by_id_valid(self):
     tx = BlockstreamAPI.get_transaction_by_id(MAIN_TX_VALID)
     assert calc_txid(tx) == MAIN_TX_VALID
Example #9
0
 def test_get_transaction_by_id_test_equal(self):
     results = check_not_all_raise_errors(
         NetworkAPI.GET_TRANSACTION_BY_ID_TEST,
         NetworkAPI.IGNORED_ERRORS)(TEST_TX_VALID)
     assert all_items_equal([calc_txid(r) for r in results])
Example #10
0
 def test_get_transaction_by_id_test_equal(self):
     results = [calc_txid(call(TEST_TX_VALID)) for call in NetworkAPI.GET_TRANSACTION_BY_ID_TEST]
     assert all_items_equal(results)
Example #11
0
 def test_get_transaction_by_id_valid(self):
     tx = PeercoinNet.get_transaction_by_id(MAIN_TX_VALID)
     assert calc_txid(tx) == MAIN_TX_VALID