当前位置: 首页>>代码示例>>Python>>正文


Python Transaction.from_db方法代码示例

本文整理汇总了Python中bigchaindb.models.Transaction.from_db方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction.from_db方法的具体用法?Python Transaction.from_db怎么用?Python Transaction.from_db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bigchaindb.models.Transaction的用法示例。


在下文中一共展示了Transaction.from_db方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_spent

# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import from_db [as 别名]
    def get_spent(self, txid, output, current_transactions=[]):
        transactions = backend.query.get_spent(self.connection, txid,
                                               output)
        transactions = list(transactions) if transactions else []
        if len(transactions) > 1:
            raise core_exceptions.CriticalDoubleSpend(
                '`{}` was spent more than once. There is a problem'
                ' with the chain'.format(txid))

        current_spent_transactions = []
        for ctxn in current_transactions:
            for ctxn_input in ctxn.inputs:
                if ctxn_input.fulfills and\
                   ctxn_input.fulfills.txid == txid and\
                   ctxn_input.fulfills.output == output:
                    current_spent_transactions.append(ctxn)

        transaction = None
        if len(transactions) + len(current_spent_transactions) > 1:
            raise DoubleSpend('tx "{}" spends inputs twice'.format(txid))
        elif transactions:
            transaction = Transaction.from_db(self, transactions[0])
        elif current_spent_transactions:
            transaction = current_spent_transactions[0]

        return transaction
开发者ID:roderik,项目名称:bigchaindb,代码行数:28,代码来源:lib.py

示例2: get_block

# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import from_db [as 别名]
    def get_block(self, block_id):
        """Get the block with the specified `block_id`.

        Returns the block corresponding to `block_id` or None if no match is
        found.

        Args:
            block_id (int): block id of the block to get.
        """

        block = backend.query.get_block(self.connection, block_id)
        latest_block = self.get_latest_block()
        latest_block_height = latest_block['height'] if latest_block else 0

        if not block and block_id > latest_block_height:
            return

        result = {'height': block_id,
                  'transactions': []}

        if block:
            transactions = backend.query.get_transactions(self.connection, block['transactions'])
            result['transactions'] = [t.to_dict() for t in Transaction.from_db(self, transactions)]

        return result
开发者ID:roderik,项目名称:bigchaindb,代码行数:27,代码来源:lib.py

示例3: get_transaction

# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import from_db [as 别名]
    def get_transaction(self, txid, include_status=False):
        """Get the transaction with the specified `txid` (and optionally its status)

        This query begins by looking in the bigchain table for all blocks containing
        a transaction with the specified `txid`. If one of those blocks is valid, it
        returns the matching transaction from that block. Else if some of those
        blocks are undecided, it returns a matching transaction from one of them. If
        the transaction was found in invalid blocks only, or in no blocks, then this
        query looks for a matching transaction in the backlog table, and if it finds
        one there, it returns that.

        Args:
            txid (str): transaction id of the transaction to get
            include_status (bool): also return the status of the transaction
                                   the return value is then a tuple: (tx, status)

        Returns:
            A :class:`~.models.Transaction` instance if the transaction
            was found in a valid block, an undecided block, or the backlog table,
            otherwise ``None``.
            If :attr:`include_status` is ``True``, also returns the
            transaction's status if the transaction was found.
        """

        response, tx_status = None, None

        blocks_validity_status = self.get_blocks_status_containing_tx(txid)
        check_backlog = True

        if blocks_validity_status:
            # Disregard invalid blocks, and return if there are no valid or undecided blocks
            blocks_validity_status = {
                _id: status for _id, status in blocks_validity_status.items()
                if status != Bigchain.BLOCK_INVALID
            }
            if blocks_validity_status:

                # The transaction _was_ found in an undecided or valid block,
                # so there's no need to look in the backlog table
                check_backlog = False

                tx_status = self.TX_UNDECIDED
                # If the transaction is in a valid or any undecided block, return it. Does not check
                # if transactions in undecided blocks are consistent, but selects the valid block
                # before undecided ones
                for target_block_id in blocks_validity_status:
                    if blocks_validity_status[target_block_id] == Bigchain.BLOCK_VALID:
                        tx_status = self.TX_VALID
                        break

                # Query the transaction in the target block and return
                response = backend.query.get_transaction_from_block(self.connection, txid, target_block_id)

        if check_backlog:
            response = backend.query.get_transaction_from_backlog(self.connection, txid)

            if response:
                tx_status = self.TX_IN_BACKLOG

        if response:
            if tx_status == self.TX_IN_BACKLOG:
                response = Transaction.from_dict(response)
            else:
                # If we are reading from the bigchain collection the asset is
                # not in the transaction so we need to fetch the asset and
                # reconstruct the transaction.
                response = Transaction.from_db(self, response)

        if include_status:
            return response, tx_status
        else:
            return response
开发者ID:r-marques,项目名称:bigchaindb,代码行数:74,代码来源:core.py


注:本文中的bigchaindb.models.Transaction.from_db方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。