本文整理汇总了Python中bitcoin.core.CBlock.nNonce方法的典型用法代码示例。如果您正苦于以下问题:Python CBlock.nNonce方法的具体用法?Python CBlock.nNonce怎么用?Python CBlock.nNonce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitcoin.core.CBlock
的用法示例。
在下文中一共展示了CBlock.nNonce方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CTransaction
# 需要导入模块: from bitcoin.core import CBlock [as 别名]
# 或者: from bitcoin.core.CBlock import nNonce [as 别名]
tx = CTransaction()
tx.vin.append(txin)
tx.vout.append(txout)
tx.calc_sha256()
print tx
print "Transaction: ", tx.is_valid()
print "hash: ", hex(tx.sha256)
print "Hash: ", "0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
block = CBlock()
block.nVersion = 1
block.hashPrevBlock = 0
block.hashMerkleRoot = 0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
block.nTime = 1231006505
block.nBits = 486604799 # 0x1d00ffff
block.nNonce = 2083236893
block.vtx = [tx]
block.calc_sha256()
print "Calculated hash: ", hex(block.sha256)
print " >>>>>>>>>>>>>>: ", "0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
#
#print block.is_valid()
genesis = binascii.hexlify(block.serialize())
print "Version: ", genesis[:8]
print "Previous block: ", genesis[8:72]
print "Merkle root: ", genesis[72:136]
print "Match : ", "3BA3EDFD7A7B12B27AC72C3E67768F617FC81BC3888A51323A9FB8AA4B1E5E4A"
print "Time stamp: ", genesis[136:144]
print "Match: : ", "29AB5F49"
示例2: CBlock
# 需要导入模块: from bitcoin.core import CBlock [as 别名]
# 或者: from bitcoin.core.CBlock import nNonce [as 别名]
block = CBlock()
block.nVersion = 1
block.hashPrevBlock = 0
block.hashMerkleRoot = 0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
block.nTime = 1231006505
block.nBits = 0x1f00ffff
block.vtx = [tx]
i = 0
#target = 6901641034498895230248057944249341782018790077074986006051269912821760
target = uint256_from_compact(block.nBits)
print "Target: \t%064x" % target
for i in xrange(1000000000000000):
block.nNonce = i
block.sha256 = None
block.calc_sha256()
calculated_hash = block.sha256
# print calculated_hash
# time.sleep(1)
if calculated_hash < target:
print "Calculated hash: ", hex(block.sha256)
break
print "Valid: ", block.is_valid()
genesis = binascii.hexlify(block.serialize())
print "Version: ", genesis[:8]
print "Previous block: ", genesis[8:72]
print "Merkle root: ", genesis[72:136]