コード例 #1
0
ファイル: test_wallet.py プロジェクト: starkovalera/lit
    def test_cold_storage(self):
        if TRAVIS and sys.version_info[:2] != (3, 6):
            return

        private_key = PrivateKeyTestnet(WALLET_FORMAT_TEST)
        address = private_key.address

        prepared = PrivateKeyTestnet.prepare_transaction(
            address, [('n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi', 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
コード例 #2
0
    def send(self,
             outputs,
             fee=None,
             leftover=None,
             combine=True,
             message=None,
             unspents=None,
             token=None):  # pragma: no cover
        """Creates a signed P2PKH transaction and attempts to broadcast it on
        the blockchain. This accepts the same arguments as
        :func:`~lit.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.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 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:`~lit.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, token)

        return calc_txid(tx_hex)
コード例 #3
0
    def get_transactions(self, token=None):
        """Fetches transaction history.

        :rtype: ``list`` of ``str`` transaction IDs
        """
        self.transactions[:] = NetworkAPI.get_transactions(self.address, token)
        return self.transactions
コード例 #4
0
    def get_unspents(self, token=None):
        """Fetches all available unspent transaction outputs.

        :rtype: ``list`` of :class:`~lit.network.meta.Unspent`
        """
        self.unspents[:] = NetworkAPI.get_unspent(self.address, token)
        return self.unspents
コード例 #5
0
ファイル: wallet.py プロジェクト: starkovalera/lit
    def get_transactions(self):
        """Fetches transaction history.

        :rtype: ``list`` of ``str`` transaction IDs
        """
        self.transactions[:] = NetworkAPI.get_transactions_testnet(self.address)
        return self.transactions
コード例 #6
0
ファイル: public_information.py プロジェクト: Ganjineh/lit
def get_transactions(address, token):
    transactions = []
    """Fetches transaction history.

    :rtype: ``list`` of ``str`` transaction IDs
    """
    transactions[:] = NetworkAPI.get_transactions(address, token)
    return transactions
コード例 #7
0
ファイル: wallet.py プロジェクト: starkovalera/lit
    def get_unspents(self):
        """Fetches all available unspent transaction outputs.

        :rtype: ``list`` of :class:`~lit.network.meta.Unspent`
        """
        self.unspents[:] = NetworkAPI.get_unspent_testnet(self.address)
        self.balance = sum(unspent.amount for unspent in self.unspents)
        return self.unspents
コード例 #8
0
ファイル: wallet.py プロジェクト: starkovalera/lit
    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
                    Lit will poll `<https://bitcoinfees.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 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 Lit will
                         communicate with the blockchain itself.
        :type unspents: ``list`` of :class:`~lit.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=(',', ':'))
コード例 #9
0
    def get_balance(self, currency='ltc', token=None):
        """Fetches the current balance by calling
        :func:`~lit.PrivateKey.get_unspents` and returns it using
        :func:`~lit.PrivateKey.balance_as`.

        :param currency: One of the :ref:`supported currencies`.
        :type currency: ``str``
        :rtype: ``str``
        """
        # self.get_unspents()
        self.balance = NetworkAPI.get_balance(self.address, token)
        return self.balance_as(currency)
コード例 #10
0
ファイル: public_information.py プロジェクト: Ganjineh/lit
def get_balance(address, token, currency='LTC'):
    return NetworkAPI.get_balance(address, token)
コード例 #11
0
ファイル: public_information.py プロジェクト: Ganjineh/lit
def get_last_block(token):
    block_number = NetworkAPI.get_last_block(token)
    return block_number
コード例 #12
0
ファイル: public_information.py プロジェクト: Ganjineh/lit
def get_transaction(hash_, token):
    transaction = NetworkAPI.get_transaction(hash_, token)
    return transaction
コード例 #13
0
ファイル: public_information.py プロジェクト: Ganjineh/lit
def check_in_mempool(tx_id, token):
    return NetworkAPI.check_in_mempool(tx_id, token)