當前位置: 首頁>>代碼示例>>Python>>正文


Python CBlock.hashMerkleRoot方法代碼示例

本文整理匯總了Python中bitcoin.core.CBlock.hashMerkleRoot方法的典型用法代碼示例。如果您正苦於以下問題:Python CBlock.hashMerkleRoot方法的具體用法?Python CBlock.hashMerkleRoot怎麽用?Python CBlock.hashMerkleRoot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bitcoin.core.CBlock的用法示例。


在下文中一共展示了CBlock.hashMerkleRoot方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: CTransaction

# 需要導入模塊: from bitcoin.core import CBlock [as 別名]
# 或者: from bitcoin.core.CBlock import hashMerkleRoot [as 別名]
txout.scriptPubKey = binascii.unhexlify(scriptPubKeyHex)

# create transaction
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]
開發者ID:obulpathi,項目名稱:bitcoinpy,代碼行數:33,代碼來源:bitcoin_genesis.py


注:本文中的bitcoin.core.CBlock.hashMerkleRoot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。