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


Python CBlock.is_valid方法代碼示例

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


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

示例1: uint256_from_compact

# 需要導入模塊: from bitcoin.core import CBlock [as 別名]
# 或者: from bitcoin.core.CBlock import is_valid [as 別名]
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]
print "Match      : ", "3BA3EDFD7A7B12B27AC72C3E67768F617FC81BC3888A51323A9FB8AA4B1E5E4A"
print "Time stamp: ", genesis[136:144]
print "Match:    : ", "29AB5F49"
print "nBits: ", genesis[144:152]
print "Match: ", "FFFF001D"
print "Nonce: ", genesis[152:160]
print "Match: ", "1DAC2B7C"
print "# transactions: ", genesis[160:162]
print "Match         : ", "01"
print "Version: ", genesis[162:170]
開發者ID:obulpathi,項目名稱:reversecoin,代碼行數:33,代碼來源:genesis.py

示例2: xrange

# 需要導入模塊: from bitcoin.core import CBlock [as 別名]
# 或者: from bitcoin.core.CBlock import is_valid [as 別名]
log = Log.Log(SETTINGS['log'])
mempool = MemPool.MemPool(log)
chaindb = ChainDb.ChainDb(SETTINGS['db'], log, mempool, NETWORKS[MY_NETWORK])

scanned = 0
failures = 0

for height in xrange(chaindb.getheight()):
	heightidx = ChainDb.HeightIdx()
	heightidx.deserialize(chaindb.height[str(height)])

	blkhash = heightidx.blocks[0]
	ser_hash = ser_uint256(blkhash)

	f = cStringIO.StringIO(chaindb.blocks[ser_hash])
	block = CBlock()
	block.deserialize(f)

	if not block.is_valid():
		log.write("block %064x failed" % (blkhash,))
		failures += 1

	scanned += 1
	if (scanned % 1000) == 0:
		log.write("Scanned height %d (%d failures)" % (
			height, failures))


log.write("Scanned %d blocks (%d failures)" % (scanned, failures))

開發者ID:Ademan,項目名稱:pynode,代碼行數:31,代碼來源:dbck.py

示例3: CTxIn

# 需要導入模塊: from bitcoin.core import CBlock [as 別名]
# 或者: from bitcoin.core.CBlock import is_valid [as 別名]
from bitcoin.core import CBlock
from bitcoin.core import CTxIn, CTxOut, CTransaction

txin = CTxIn()
txout = CTxOut()

txin.scriptSig = 0x04FFFF001D0104455468652054696D65732030332F4A616E2F32303039204368616E63656C6C6F72206F6E206272696E6B206F66207365636F6E64206261696C6F757420666F722062616E6B73
txin.prevout = 0x0000000000000000000000000000000000000000000000000000000000000000FFFFFFFF
print txin, txin.is_valid()
tx.vout.nValue = 5000000000
tx.vout.scriptPubKey = 0x5F1DF16B2B704C8A578D0BBAF74D385CDE12C11EE50455F3C438EF4C3FBCF649B6DE611FEAE06279A60939E028A8D65C10B73071A6F16719274855FEB0FD8A6704

tx = CTransaction()
tx.vin = [txin]
tx.vout = [txout]
"""
tx.vout.scriptPubKey = 0x5F1DF16B2B704C8A578D0BBAF74D385CDE12C11EE50455F3C438EF4C3FBCF649B6DE611FEAE06279A60939E028A8D65C10B73071A6F16719274855FEB0FD8A6704 OP_CHECKSIG
"""

block = CBlock()
block.nVersion = 1
block.hashPrevBlock = 0
block.hashMerkleRoot = 0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
block.nTime    = 1231006505
block.nBits    = 0x1d00ffff
block.nNonce   = 2083236893
block.vtx = [tx]
block.sha256 = 0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
print block.is_valid()
開發者ID:obulpathi,項目名稱:bitcointools,代碼行數:31,代碼來源:genesis.py


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