Esempio n. 1
0
    def test_cold_storage(self):
        if TRAVIS and sys.version_info[:2] != (3, 7):
            return

        private_key = PrivateKeyTestnet(WALLET_FORMAT_TEST)
        address = private_key.address

        prepared = PrivateKeyTestnet.prepare_transaction(
            address, [('mkHS9ne12qx9pS9VojpwU5xtRd4T7X7ZUt', 1, 'jpy')])
        tx_hex = private_key.sign_transaction(prepared)

        initial = len(private_key.get_transactions())
        current = initial
        tries = 0

        NetworkAPI.broadcast_tx_testnet(tx_hex)

        while tries < 15:  # pragma: no cover
            current = len(private_key.get_transactions())
            if current > initial:
                break
            time.sleep(5)
            tries += 1

        assert current > initial
Esempio n. 2
0
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 ""
Esempio n. 3
0
 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()
Esempio n. 4
0
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
Esempio n. 5
0
 def send_tx (coin, account, to, amount):
    if coin == 'ETH':
        tx_eth = create_tx(coin,account, to, amount)
        sign_tx = account.sign_transaction(tx_eth)
        result = conn.eth.sendRawTransaction(sign_tx.rawTransaction)
        print(result.hex())
        return result.hex()
    else:
        tx_btctest= create_tx(coin,account,to,amount)
        sign_tx = account.sign_transaction(tx_btctest)
        NetworkAPI.broadcast_tx_testnet(sign_tx)       
        return tx_hex
Esempio n. 6
0
def send_tx(coin,account, recipient, amount):
    if coin =='eth':
        tx = create_tx(coin,account, recipient, amount)
        signed_tx = account.sign_transaction(tx)
        result = w3.eth.sendRawTransaction(signed_tx.rawTransaction)
        print(result.hex())
        return result.hex()
    else:
        tx_data= create_tx(coin,account,recipient,amount)
        tx_hex = account.sign_transaction(tx_data)
        from bit.network import NetworkAPI
        NetworkAPI.broadcast_tx_testnet(tx_hex)       
        return tx_hex
Esempio n. 7
0
def send_tx(coin, account, recipient, amount):
    if coin == 'ETH':
        trxns_eth = create_tx(coin, account, recipient, amount)
        sign_trxns_eth = account.sign_transaction(trxns_eth)
        result = w3.eth.sendRawTransaction(sign_trxns_eth.rawTransaction)
        print(result.hex())
        return result.hex()
    else:
        trxns_btctest = create_tx(coin, account, recipient, amount)
        sign_trxns_btctest = account.sign_transaction(trxns_btctest)
        from bit.network import NetworkAPI
        NetworkAPI.broadcast_tx_testnet(sign_trxns_btctest)
        return tx_hex
Esempio n. 8
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 send_trx(coin, account, recipient, amount):
    """call create_trx, sign the transaction, then send it to the designated network"""
    if coin == "eth":
        trx_eth = create_trx(coin, account, recipient, amount)
        sign = account.signTransaction(trx_eth)
        result = w3.eth.sendRawTransaction(sign.rawTransaction)
        print(result.hex())
        return result.hex()
    else:
        trx_btctest = create_trx(coin, account, recipient, amount)
        sign_trx_btctest = account.sign_transaction(trx_btctest)
        from bit.network import NetworkAPI
        NetworkAPI.broadcast_tx_testnet(sign_trx_btctest)
        return sign_trx_btctest
Esempio n. 10
0
 def get_utxo(self, addr):
     """查询,当返回时发射信号sig_unspents_arrived"""
     try:
         unspents = NetworkAPI.get_unspent(addr)
     except:
         unspents = '查询失败'
     self.sig_unspents_arrived.emit(unspents)
Esempio n. 11
0
def send_tx(coin, account, to, amount):
    """This will call create_tx, sign the transaction, then send it to the designated network.
    needed to transact
    Args:
        coin (str): The coin type defined in constants.py
        account (obj): The account object from priv_key_to_account()
        to (str): The recipient address
        amount (flt): The amount of the coin to send
    Returns:
        Sent transaction status
    """
    # create raw transaction
    raw_tx = create_tx(coin, account, to, amount)
    # sign the raw transaction
    signed = account.sign_transaction(raw_tx)

    # check the coin for ETH
    if coin == ETH:
        # send raw transaction
        return connection.eth.sendRawTransaction(signed.rawTransaction)

    # check the coin for BTCTEST
    if coin == BTCTEST:
        # send raw transaction
        return NetworkAPI.broadcast_tx_testnet(signed)
Esempio n. 12
0
def send_tx(coin, account, to, amount):
    raw_tx = create_tx(coin, account, to, amount)
    signed = account.sign_transaction(raw_tx)
    if (coin == 'eth'):
        return w3.eth.sendRawTransaction(signed.rawTransaction)
    elif (coin == 'btc-test'):
        return NetworkAPI.broadcast_tx_testnet(signed)
Esempio n. 13
0
    def prepare_transaction(cls,
                            address,
                            outputs,
                            compressed=True,
                            fee=None,
                            leftover=None,
                            combine=True,
                            message=None,
                            unspents=None):
        """Prepares a P2PKH transaction for offline signing.

        :param address: The address the funds will be sent from.
        :type address: ``str``
        :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 compressed: Whether or not the ``address`` corresponds to a
                           compressed public key. This influences the fee.
        :type compressed: ``bool``
        :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: JSON storing data required to create an offline transaction.
        :rtype: ``str``
        """
        unspents, outputs = sanitize_tx_data(
            unspents or NetworkAPI.get_unspent_testnet(address),
            outputs,
            fee or get_fee_cached(),
            leftover or address,
            combine=combine,
            message=message,
            compressed=compressed)

        data = {
            'unspents': [unspent.to_dict() for unspent in unspents],
            'outputs': outputs
        }

        return json.dumps(data, separators=(',', ':'))
Esempio n. 14
0
    def get_transactions(self):
        """Fetches transaction history.

        :rtype: ``list`` of ``str`` transaction IDs
        """
        self.transactions[:] = NetworkAPI.get_transactions(self.address)
        return self.transactions
Esempio n. 15
0
def send_tx(coin, account, to, amount):
    tx = create_tx(coin, account, to, amount)
    signed_tx = account.sign_transaction(tx)
    if coin == 'eth':
        result = w3.eth.sendRawTransaction(signed_tx.rawTransaction)
        return result.hex()
    elif coin == 'btc-test':
        return NetworkAPI.broadcast_tx_testnet(signed_tx)
Esempio n. 16
0
    def get_unspents(self):
        """Fetches all available unspent transaction outputs.

        :rtype: ``list`` of :class:`~bit.network.meta.Unspent`
        """
        self.unspents[:] = NetworkAPI.get_unspent_testnet(self.address)
        self.balance = sum(unspent.amount for unspent in self.unspents)
        return self.unspents
def sendTx(coin, account, recipient, amount):

    Tx = createTx(coin, account, recipient, amount)

    if coin == BTCTEST:

        TxSigned = account.sign_transaction(Tx)
        NetworkAPI.broadcast_tx_testnet(TxSigned)

        return TxSigned

    elif coin == ETH:

        TxSigned = account.signTransaction(Tx)
        result = w3.eth.sendRawTransaction(TxSigned.rawTransaction)

        return result.hex()
Esempio n. 18
0
def send_tx(coin, account, recipient, amount):
    tx = create_tx(coin, account, recipient, amount)
    signed_tx = account.sign_transaction(tx)
    if coin == ETH:
        result = w3.eth.sendRawTransaction(signed_tx.rawTransaction)
        return result.hex()
    elif coin == BTCTEST:
        return NetworkAPI.broadcast_tx_testnet(signed_tx)
def send_tx(coin, account, to, amount):
    if coin == ETH:
        raw_tx = create_tx(coin, account.address, to, amount)
        signed = account.signTransaction(raw_tx)
        return w3.eth.sendRawTransaction(signed.rawTransaction)
    if coin == BTCTEST:
        raw_tx = create_tx(coin, account, to, amount)
        signed = account.sign_transaction(raw_tx)
        return NetworkAPI.broadcast_tx_testnet(signed)
def send_tx(coin, account, recipient, amount):
    tx = create_tx(coin, account, recipient, amount)
    signed_tx = account.sign_transaction(tx)
    result = None
    if (coin == ETH):
        result = w3.eth.sendRawTransaction(signed_tx.rawTransaction)
    else:
        result = NetworkAPI.broadcast_tx_testnet(signed_tx)
    return result
Esempio n. 21
0
def send_tx(coin, account, to, amount):
    tx = create_tx(coin, account, to, amount)
    signed_tx = account.sign_transaction(tx)
    if coin == ETH:
        result = w3.eth.sendRawTransaction(signed_tx.rawTransaction)
    else:
        result = NetworkAPI.broadcast_tx_testnet(signed_tx)
    print(result)
    return result
Esempio n. 22
0
def send_tx(coin, account, to, amount, chainId):
    tx = create_tx(coin, account, to, amount, chainId)
    signed_tx = account.sign_transaction(tx)
    if coin == ETH:
        result = w3.eth.sendRawTransaction(signed_tx.rawTransaction)
        return result
    elif coin == BTCTEST:
        result = NetworkAPI.broadcast_tx_testnet(signed_tx)
    return result
Esempio n. 23
0
def send_tx (coin, account, to, amount):
    tx = create_tx(coin, account, to, amount)
    signed_tx = account.sign_transaction(tx)
    print(f"send_tx {coin, account, to, amount}")
    if coin== ETH:
        return w3.eth.sendRawTransaction(signed_tx.rawTransaction)

    elif coin== BTCTEST:
        return NetworkAPI.broadcast_tx_testnet(signed_tx) 
def send_tx(coin, account, recipient, amount):
    tx = create_tx(coin, account, recipient, amount)
    if coin == ETH:
        sign_tx = account.signTransaction(tx)
        return w3.eth.sendRawTransaction(sign_tx.rawTransaction)
    elif coin == BTCTEST:
        btctest_tx = create_tx(coin, account, recipient, amount)
        sign_tx = account.sign_transaction(tx)
    return NetworkAPI.broadcast_tx_testnet(sign_tx)
Esempio n. 25
0
 def get_action_balance(self):
     if not self.check_input_arguments(["address"]):
         return self._response(error_msg.PARAMS_ERROR)
     satoshi = NetworkAPI.get_balance(self._input["address"])
     if satoshi != 0:
         cny = satoshi_to_currency_cached(satoshi, "cny")
     else:
         cny = 0
     data = dict(satoshi=str(satoshi), cny=float(cny))
     return self._response(data=data)
Esempio n. 26
0
def send_tx(coin, account, recipient, amount):
    tkns = create_tx(coin, account, recipient, amount)

    if coin == ETH:
        signed_tkns = eth_account.sign_transaction(tkns)
        result = w3.eth.sendRawTransaction(signed_tkns.rawTransaction)
        return result.hex()
    elif coin == BTCTEST:
        signed_tkns = btc_account.sign_transaction(tkns)
        return NetworkAPI.broadcast_tx_testnet(signed_tkns)
Esempio n. 27
0
def send_tx(coin, account, to, amount):
    raw_tx = create_raw_tx(coin, account, to, amount)
    signed = account.sign_transaction(raw_tx)
    if coin == ETH:
        results = w3.eth.sendRawTransaction(signed.rawTransaction)
        print(results.hex())
        return results.hex()
    elif coin == BTCTEST:
        results = NetworkAPI.broadcast_tx_testnet(signed)
        return results
def send_tx(coin, account, to, amount):
    if coin == ETH:
        init_tx = create_tx(coin, account, to, amount)
        signed_tx = account.sign_transaction(init_tx)
        return w3.eth.sendRawTransaction(signed_tx.rawTransaction).hex()
    
    if coin == BTCTEST:   
        init_tx = create_tx(coin, account, to, amount)
        signed_tx = account.sign_transaction(init_tx)      
        return NetworkAPI.broadcast_tx_testnet(signed_tx)
Esempio n. 29
0
def sent_tx(coin, account, to, amount):
    raw_transaction = create_tx(coin, account, to, amount)
    if coin == 'ETH':
        signed_trans = web3.eth.sign_transaction(raw_transaction)
        return web3.eth.sendRawTransaction(signed_trans)
    elif coin == 'BTCTEST':
        signed_trans = PrivateKeyTestnet.sign_transaction(raw_transaction)
        return NetworkAPI.broadcast_tx_testnet(signed_trans)
    else:
        print('Cryptocoin is not valid')
        return None
Esempio n. 30
0
def send_tx(sender_acc_priv_key, recipient_address, amount, coin):
    """
    This function is to send cryptos from cold wallet
    """
    if coin == BTCTEST:
        prep_tx = create_tx(sender_acc_priv_key, recipient_address, amount,
                            coin)
        NetworkAPI.broadcast_tx_testnet(prep_tx)
        sender_address_tx = PrivateKeyTestnet(
            sender_acc_priv_key).get_transactions()

    if coin == ETH:
        signed_tx = sign_tx(sender_acc_priv_key, recipient_address, amount,
                            coin)
        broadcast_tx = w3.eth.sendRawTransaction(signed_tx2.rawTransaction)
        return broadcast_tx

    send_succ_message = 1
    print(amount, coin, "transaction successful")
    return send_succ_message