本文整理汇总了Python中BCDataStream.write_string方法的典型用法代码示例。如果您正苦于以下问题:Python BCDataStream.write_string方法的具体用法?Python BCDataStream.write_string怎么用?Python BCDataStream.write_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BCDataStream
的用法示例。
在下文中一共展示了BCDataStream.write_string方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_wallet
# 需要导入模块: import BCDataStream [as 别名]
# 或者: from BCDataStream import write_string [as 别名]
def update_wallet(db, type, data):
"""Write a single item to the wallet.
db must be open with writable=True.
type and data are the type code and data dictionary as parse_wallet would
give to item_callback.
data's __key__, __value__ and __type__ are ignored; only the primary data
fields are used.
"""
d = data
kds = BCDataStream()
vds = BCDataStream()
# Write the type code to the key
kds.write_string(type)
vds.write("") # Ensure there is something
try:
if type == "tx":
raise NotImplementedError("Writing items of type 'tx'")
kds.write(d['tx_id'])
#d.update(parse_WalletTx(vds))
elif type == "name":
kds.write(d['hash'])
vds.write(d['name'])
elif type == "version":
vds.write_uint32(d['version'])
elif type == "setting":
raise NotImplementedError("Writing items of type 'setting'")
kds.write_string(d['setting'])
#d['value'] = parse_setting(d['setting'], vds)
elif type == "key":
kds.write_string(d['public_key'])
vds.write_string(d['private_key'])
elif type == "wkey":
kds.write_string(d['public_key'])
vds.write_string(d['private_key'])
vds.write_int64(d['created'])
vds.write_int64(d['expires'])
vds.write_string(d['comment'])
elif type == "ckey":
kds.write_string(d['public_key'])
kds.write_string(d['crypted_key'])
elif type == "mkey":
kds.write_int32(d['nID'])
vds.write_string(d['crypted_key'])
vds.write_string(d['salt'])
vds.write_int32(d['nDeriveIterations'])
vds.write_int32(d['nDerivationMethod'])
vds.write_string(d['vchOtherDerivationParameters'])
elif type == "defaultkey":
vds.write_string(d['key'])
elif type == "pool":
kds.write_int64(d['n'])
vds.write_int32(d['nVersion'])
vds.write_int64(d['nTime'])
vds.write_string(d['public_key'])
elif type == "acc":
kds.write_string(d['account'])
vds.write_int32(d['nVersion'])
vds.write_string(d['public_key'])
elif type == "acentry":
kds.write_string(d['account'])
kds.write_uint64(d['n'])
vds.write_int32(d['nVersion'])
vds.write_int64(d['nCreditDebit'])
vds.write_int64(d['nTime'])
vds.write_string(d['otherAccount'])
vds.write_string(d['comment'])
elif type == "bestblock":
vds.write_int32(d['nVersion'])
vds.write_compact_size(len(d['hashes']))
for h in d['hashes']:
vds.write(h)
else:
print "Unknown key type: "+type
# Write the key/value pair to the database
db.put(kds.input, vds.input)
except Exception, e:
print("ERROR writing to wallet.dat, type %s"%type)
print("data dictionary: %r"%data)