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


Python CTransaction.stream_deserialize方法代码示例

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


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

示例1: broadcast_tx

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import stream_deserialize [as 别名]
    def broadcast_tx(self, tx):
        """
        Sends the tx to half our peers and waits for half of the remainder to
        announce it via inv packets before calling back.
        """
        def on_peer_anncounce(txid):
            self.subscriptions[txhash]["announced"] += 1
            if self.subscriptions[txhash]["announced"] >= self.subscriptions[txhash]["ann_threshold"]:
                if self.subscriptions[txid]["timeout"].active():
                    self.subscriptions[txid]["timeout"].cancel()
                    self.subscriptions[txid]["deferred"].callback(True)

        d = defer.Deferred()
        transaction = CTransaction.stream_deserialize(BytesIO(unhexlify(tx)))
        txhash = transaction.GetHash()
        self.inventory[txhash] = transaction

        cinv = CInv()
        cinv.type = 1
        cinv.hash = txhash

        inv_packet = msg_inv()
        inv_packet.inv.append(cinv)

        self.bloom_filter.insert(txhash)
        self.subscriptions[txhash] = {
            "announced": 0,
            "ann_threshold": len(self.peers)/4,
            "callback": on_peer_anncounce,
            "confirmations": 0,
            "in_blocks": [],
            "deferred": d,
            "timeout": reactor.callLater(10, d.callback, False)
        }

        for peer in self.peers[len(self.peers)/2:]:
            peer.protocol.load_filter()
        for peer in self.peers[:len(self.peers)/2]:
            peer.protocol.send_message(inv_packet)

        return d
开发者ID:cpacia,项目名称:pybitcoin,代码行数:43,代码来源:client.py

示例2: msg_deser

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import stream_deserialize [as 别名]
 def msg_deser(cls, f, protover=PROTO_VERSION):
     c = cls()
     c.tx = CTransaction.stream_deserialize(f)
     return c
开发者ID:ghtdak,项目名称:python-bitcoinlib,代码行数:6,代码来源:messages.py


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