base.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:indiechain 作者: asutoshpalai 项目源码 文件源码
def createSummary(self, blocks):
        if all(isinstance(block, Block) for block in blocks):
            utxos = []
            for blk in blocks:
                for transaction in blk.transactions:
                    utxos += transaction.utxos
            outgoing = [(utxo.sender, utxo.value) for utxo in utxos]
            incoming = [(utxo.receiver, utxo.value) for utxo in utxos]
            senders = set([utxo.sender for utxo in utxos])
            receivers = set([utxo.receiver for utxo in utxos])
            for wallet in list(senders) + list(receivers):
                self.changes[wallet] = 0
            for sender in senders:
                self.changes[sender] = -sum(map(lambda v: v[1], filter(lambda u: u[0] == sender, outgoing)))
            for receiver in receivers:
                self.changes[receiver] += sum(map(lambda v: v[1], filter(lambda u: u[0] == receiver, incoming)))
        elif all(isinstance(block, SummaryBlock) for block in blocks):
            all_keys = reduce(operator.add,[list(block.changes.keys()) for block in blocks])
            for key in all_keys:
                self.changes[key] = 0
            for block in blocks:
                for key, value in block.changes.items():
                    self.changes[key] += value
        else:
            raise TypeError('Invalid typing of blocks')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号