Exemplo n.º 1
0
    def add_tx(self, tx: BaseTransaction) -> None:
        """ Checks if this tx has mint or melt inputs/outputs and adds to tokens index
        """
        for tx_input in tx.inputs:
            spent_tx = tx.get_spent_tx(tx_input)
            self._remove_from_index(spent_tx, tx_input.index)

        for index in range(len(tx.outputs)):
            self._add_to_index(tx, index)

        # if it's a TokenCreationTransaction, update name and symbol
        if tx.version == TxVersion.TOKEN_CREATION_TRANSACTION:
            from hathor.transaction.token_creation_tx import TokenCreationTransaction
            tx = cast(TokenCreationTransaction, tx)
            assert tx.hash is not None
            status = self.tokens[tx.hash]
            status.name = tx.token_name
            status.symbol = tx.token_symbol

        if tx.is_transaction:
            # Adding this tx to the transactions key list
            assert isinstance(tx, Transaction)
            for token_uid in tx.tokens:
                transactions = self.tokens[token_uid].transactions
                # It is safe to use the in operator because it is O(log(n)).
                # http://www.grantjenks.com/docs/sortedcontainers/sortedlist.html#sortedcontainers.SortedList.__contains__
                assert tx.hash is not None
                element = TransactionIndexElement(tx.timestamp, tx.hash)
                if element in transactions:
                    return
                transactions.add(element)
    def add_tx(self, tx: BaseTransaction) -> None:
        # if it's a TokenCreationTransaction, update name and symbol
        self.log.debug('add_tx', tx=tx.hash_hex, ver=tx.version)
        if tx.version == TxVersion.TOKEN_CREATION_TRANSACTION:
            from hathor.transaction.token_creation_tx import TokenCreationTransaction
            tx = cast(TokenCreationTransaction, tx)
            assert tx.hash is not None
            self.log.debug('create_token_info',
                           tx=tx.hash_hex,
                           name=tx.token_name,
                           symb=tx.token_symbol)
            self._create_token_info(tx.hash, tx.token_name, tx.token_symbol)

        if tx.is_transaction:
            # Adding this tx to the transactions key list
            assert isinstance(tx, Transaction)
            for token_uid in tx.tokens:
                assert tx.hash is not None
                self._add_transaction(token_uid, tx.timestamp, tx.hash)

        for tx_input in tx.inputs:
            spent_tx = tx.get_spent_tx(tx_input)
            self._remove_utxo(spent_tx, tx_input.index)

        for index in range(len(tx.outputs)):
            self.log.debug('add utxo', tx=tx.hash_hex, index=index)
            self._add_utxo(tx, index)
    def del_tx(self, tx: BaseTransaction) -> None:
        for tx_input in tx.inputs:
            spent_tx = tx.get_spent_tx(tx_input)
            self._add_utxo(spent_tx, tx_input.index)

        for index in range(len(tx.outputs)):
            self._remove_utxo(tx, index)

        if tx.is_transaction:
            # Removing this tx from the transactions key list
            assert isinstance(tx, Transaction)
            for token_uid in tx.tokens:
                assert tx.hash is not None
                self._remove_transaction(token_uid, tx.timestamp, tx.hash)

        # if it's a TokenCreationTransaction, remove it from index
        if tx.version == TxVersion.TOKEN_CREATION_TRANSACTION:
            assert tx.hash is not None
            self._destroy_token(tx.hash)
Exemplo n.º 4
0
    def del_tx(self, tx: BaseTransaction) -> None:
        for tx_input in tx.inputs:
            spent_tx = tx.get_spent_tx(tx_input)
            self._add_to_index(spent_tx, tx_input.index)

        for index in range(len(tx.outputs)):
            self._remove_from_index(tx, index)

        if tx.is_transaction:
            # Removing this tx from the transactions key list
            assert isinstance(tx, Transaction)
            for token_uid in tx.tokens:
                transactions = self._tokens[token_uid]._transactions
                idx = transactions.bisect_key_left((tx.timestamp, tx.hash))
                if idx < len(transactions) and transactions[idx].hash == tx.hash:
                    transactions.pop(idx)

        # if it's a TokenCreationTransaction, remove it from index
        if tx.version == TxVersion.TOKEN_CREATION_TRANSACTION:
            assert tx.hash is not None
            del self._tokens[tx.hash]