本文整理汇总了Python中BCDataStream.read_uint32方法的典型用法代码示例。如果您正苦于以下问题:Python BCDataStream.read_uint32方法的具体用法?Python BCDataStream.read_uint32怎么用?Python BCDataStream.read_uint32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BCDataStream
的用法示例。
在下文中一共展示了BCDataStream.read_uint32方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dump_transaction
# 需要导入模块: import BCDataStream [as 别名]
# 或者: from BCDataStream import read_uint32 [as 别名]
def dump_transaction(datadir, db_env, tx_id):
""" Dump a transaction, given hexadecimal tx_id-- either the full ID
OR a short_hex version of the id.
"""
db = DB(db_env)
try:
r = db.open("blkindex.dat", "main", DB_BTREE, DB_THREAD | DB_RDONLY)
except DBError:
r = True
if r is not None:
logging.error("Couldn't open blkindex.dat/main. Try quitting any running Bitcoin apps.")
sys.exit(1)
kds = BCDataStream()
vds = BCDataStream()
n_tx = 0
n_blockindex = 0
key_prefix = "\x02tx" + (tx_id[-4:].decode("hex_codec")[::-1])
cursor = db.cursor()
(key, value) = cursor.set_range(key_prefix)
while key.startswith(key_prefix):
kds.clear()
kds.write(key)
vds.clear()
vds.write(value)
type = kds.read_string()
hash256 = kds.read_bytes(32)
hash_hex = long_hex(hash256[::-1])
version = vds.read_uint32()
tx_pos = _read_CDiskTxPos(vds)
if hash_hex.startswith(tx_id) or short_hex(hash256[::-1]).startswith(tx_id):
_dump_tx(datadir, hash256, tx_pos)
(key, value) = cursor.next()
db.close()
示例2: dump_blockindex
# 需要导入模块: import BCDataStream [as 别名]
# 或者: from BCDataStream import read_uint32 [as 别名]
def dump_blockindex(db_env, owner=None, n_to_dump=1000):
db = DB(db_env)
r = db.open("blkindex.dat", "main", DB_BTREE, DB_THREAD|DB_RDONLY)
if r is not None:
logging.error("Couldn't open blkindex.dat/main")
sys.exit(1)
kds = BCDataStream()
vds = BCDataStream()
wallet_transactions = []
for (i, (key, value)) in enumerate(db.items()):
if i > n_to_dump:
break
kds.clear(); kds.write(key)
vds.clear(); vds.write(value)
type = kds.read_string()
if type == "tx":
hash256 = kds.read_bytes(32)
version = vds.read_uint32()
tx_pos = _read_CDiskTxPos(vds)
print("Tx(%s:%d %d %d)"%((short_hex(hash256),)+tx_pos))
n_tx_out = vds.read_compact_size()
for i in range(0,n_tx_out):
tx_out = _read_CDiskTxPos(vds)
if tx_out[0] != 0xffffffffL: # UINT_MAX means no TxOuts (unspent)
print(" ==> TxOut(%d %d %d)"%tx_out)
else:
logging.warn("blkindex: type %s"%(type,))
continue
db.close()
示例3: parse_wallet
# 需要导入模块: import BCDataStream [as 别名]
# 或者: from BCDataStream import read_uint32 [as 别名]
def parse_wallet(db, item_callback):
kds = BCDataStream()
vds = BCDataStream()
for (key, value) in db.items():
d = { }
kds.clear(); kds.write(key)
vds.clear(); vds.write(value)
try:
type = kds.read_string()
d["__key__"] = key
d["__value__"] = value
d["__type__"] = type
except Exception, e:
print("ERROR attempting to read data from wallet.dat, type %s"%type)
continue
try:
if type == "tx":
d["tx_id"] = kds.read_bytes(32)
d.update(parse_WalletTx(vds))
elif type == "name":
d['hash'] = kds.read_string()
d['name'] = vds.read_string()
elif type == "version":
d['version'] = vds.read_uint32()
elif type == "setting":
d['setting'] = kds.read_string()
d['value'] = parse_setting(d['setting'], vds)
elif type == "key":
d['public_key'] = kds.read_bytes(kds.read_compact_size())
d['private_key'] = vds.read_bytes(vds.read_compact_size())
elif type == "wkey":
d['public_key'] = kds.read_bytes(kds.read_compact_size())
d['private_key'] = vds.read_bytes(vds.read_compact_size())
d['created'] = vds.read_int64()
d['expires'] = vds.read_int64()
d['comment'] = vds.read_string()
elif type == "ckey":
d['public_key'] = kds.read_bytes(kds.read_compact_size())
d['crypted_key'] = vds.read_bytes(vds.read_compact_size())
elif type == "mkey":
d['nID'] = kds.read_int32()
d['crypted_key'] = vds.read_bytes(vds.read_compact_size())
d['salt'] = vds.read_bytes(vds.read_compact_size())
d['nDerivationMethod'] = vds.read_int32()
d['nDeriveIterations'] = vds.read_int32()
d['vchOtherDerivationParameters'] = vds.read_bytes(vds.read_compact_size())
elif type == "defaultkey":
d['key'] = vds.read_bytes(vds.read_compact_size())
elif type == "pool":
d['n'] = kds.read_int64()
d['nVersion'] = vds.read_int32()
d['nTime'] = vds.read_int64()
d['public_key'] = vds.read_bytes(vds.read_compact_size())
elif type == "acc":
d['account'] = kds.read_string()
d['nVersion'] = vds.read_int32()
d['public_key'] = vds.read_bytes(vds.read_compact_size())
elif type == "acentry":
d['account'] = kds.read_string()
d['n'] = kds.read_uint64()
d['nVersion'] = vds.read_int32()
d['nCreditDebit'] = vds.read_int64()
d['nTime'] = vds.read_int64()
d['otherAccount'] = vds.read_string()
d['comment'] = vds.read_string()
elif type == "bestblock":
d['nVersion'] = vds.read_int32()
d.update(parse_BlockLocator(vds))
elif type == "cscript":
d['scriptHash'] = kds.read_bytes(20)
d['script'] = vds.read_bytes(vds.read_compact_size())
else:
print "Skipping item of type "+type
continue
item_callback(type, d)
except Exception, e:
print("ERROR parsing wallet.dat, type %s"%type)
print("key data in hex: %s"%key.encode('hex_codec'))
print("value data in hex: %s"%value.encode('hex_codec'))
示例4: parse_wallet
# 需要导入模块: import BCDataStream [as 别名]
# 或者: from BCDataStream import read_uint32 [as 别名]
def parse_wallet(db, item_callback):
kds = BCDataStream()
vds = BCDataStream()
for (key, value) in db.items():
d = { }
kds.clear(); kds.write(key)
vds.clear(); vds.write(value)
type = kds.read_string()
d["__key__"] = key
d["__value__"] = value
d["__type__"] = type
try:
if type == "tx":
d["tx_id"] = kds.read_bytes(32)
d.update(parse_WalletTx(vds))
elif type == "name":
d['hash'] = kds.read_string()
d['name'] = vds.read_string()
elif type == "version":
d['version'] = vds.read_uint32()
elif type == "setting":
d['setting'] = kds.read_string()
d['value'] = parse_setting(d['setting'], vds)
elif type == "key":
d['public_key'] = kds.read_bytes(kds.read_compact_size())
d['private_key'] = vds.read_bytes(vds.read_compact_size())
elif type == "wkey":
d['public_key'] = kds.read_bytes(kds.read_compact_size())
d['private_key'] = vds.read_bytes(vds.read_compact_size())
d['created'] = vds.read_int64()
d['expires'] = vds.read_int64()
d['comment'] = vds.read_string()
elif type == "defaultkey":
d['key'] = vds.read_bytes(vds.read_compact_size())
elif type == "pool":
d['n'] = kds.read_int64()
d['nVersion'] = vds.read_int32()
d['nTime'] = vds.read_int64()
d['public_key'] = vds.read_bytes(vds.read_compact_size())
elif type == "acc":
d['account'] = kds.read_string()
d['nVersion'] = vds.read_int32()
d['public_key'] = vds.read_bytes(vds.read_compact_size())
elif type == "acentry":
d['account'] = kds.read_string()
d['n'] = kds.read_uint64()
d['nVersion'] = vds.read_int32()
d['nCreditDebit'] = vds.read_int64()
d['nTime'] = vds.read_int64()
d['otherAccount'] = vds.read_string()
d['comment'] = vds.read_string()
else:
print "Unknown key type: "+type
item_callback(type, d)
except Exception, e:
print("ERROR parsing wallet.dat, type %s"%type)
print("key data in hex: %s"%key.encode('hex_codec'))
print("value data in hex: %s"%value.encode('hex_codec'))