本文整理汇总了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
示例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