本文整理汇总了Python中tools.unpackage函数的典型用法代码示例。如果您正苦于以下问题:Python unpackage函数的具体用法?Python unpackage怎么用?Python unpackage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unpackage函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: genesis
def genesis(pubkey):
out = {'version': custom.version,
'length': 0,
'time': time.time(),
'txs': [make_mint(pubkey)]}
out = tools.unpackage(tools.package(out))
return out
开发者ID:coinami,项目名称:coinami-pro,代码行数:7,代码来源:miner.py
示例2: genesis
def genesis(pubkey, DB):
out={'version':custom.version,
'length':0,
'time':time.time(),
'target':blockchain.target(DB),
'txs':[make_mint(pubkey, DB)]}
out=tools.unpackage(tools.package(out))
return out
开发者ID:aneilbaboo,项目名称:basiccoin,代码行数:8,代码来源:consensus.py
示例3: db_get
def db_get (n, DB):
n=str(n)
if len(n)==130: n=tools.pub2addr(n)
try:
a=DB['db'].Get(n)
except:
error('here')
return tools.unpackage(a)
开发者ID:Fangang,项目名称:basiccoin,代码行数:8,代码来源:blockchain.py
示例4: db_get
def db_get(n, DB):
n = str(n)
try:
return tools.unpackage(DB['db'].Get(n))
except:
db_put(n, {'count': 0, 'amount': 0}, DB) # Everyone defaults with
# having zero money, and having broadcast zero transcations.
return db_get(n, DB)
开发者ID:tubaman,项目名称:basiccoin,代码行数:8,代码来源:blockchain.py
示例5: make_block
def make_block(prev_block, txs, pubkey, DB):
leng=int(prev_block['length'])+1
out={'version':custom.version,
'txs':txs+[make_mint(pubkey, DB)],
'length':leng,
'time':time.time(),
'target':blockchain.target(DB, leng),
'prevHash':tools.det_hash(prev_block)}
out=tools.unpackage(tools.package(out))
return out
开发者ID:aneilbaboo,项目名称:basiccoin,代码行数:10,代码来源:consensus.py
示例6: db_get
def db_get(n, DB):
n=str(n)
if len(n)==130:
n=tools.pub2addr(n)
try:
a=DB['db'].Get(n)
except:
db_put(n, {'count':0, 'amount':0}, DB)#everyone defaults with having zero money, and having broadcast zero transcations.
return db_get(n, DB)
return tools.unpackage(DB['db'].Get(n))
开发者ID:cinquemb,项目名称:basiccoin,代码行数:10,代码来源:blockchain.py
示例7: make_block
def make_block(prev_block, txs, pubkey):
leng = int(prev_block['length']) + 1
out = {'version': custom.version,
'txs': txs, # dont forget to add coinbase transaction ;)
'length': leng,
'time': time.time(),
'prevHash': tools.det_hash(prev_block)}
out = tools.unpackage(tools.package(out))
return out
开发者ID:coinami,项目名称:coinami-pro,代码行数:10,代码来源:miner.py
示例8: genesis
def genesis(pubkey, DB):
target_ = target.target()
out = {'version': custom.version,
'length': 0,
'time': time.time(),
'target': target_,
'diffLength': blockchain.hexInvert(target_),
'txs': [make_mint(pubkey, DB)]}
out = tools.unpackage(tools.package(out))
return out
开发者ID:AltCoinsLand,项目名称:basiccoin,代码行数:10,代码来源:miner.py
示例9: genesis
def genesis(pubkey, DB):
target = blockchain.target(DB)
out = {'version': custom.version,
'length': 0,
'time': time.time(),
'target': target,
'diffLength': blockchain.hexInvert(target),
'txs': [make_mint(pubkey, DB)]}
print('out: ' + str(out))
out = tools.unpackage(tools.package(out))
return out
开发者ID:ashumeow,项目名称:basiccoin,代码行数:11,代码来源:consensus.py
示例10: serve_forever
def serve_forever(message_handler_func, PORT, queue):
server = socket.socket()
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind(("127.0.0.1", PORT))
server.listen(100)
while True:
client, addr = server.accept()
(ip, port) = addr
data = client.recv(MAX_MESSAGE_SIZE)
# we could insert security checks here
data = tools.unpackage(data)
client.send(tools.package(message_handler_func(data, queue)))
开发者ID:Noelkd,项目名称:basiccoin,代码行数:12,代码来源:networking.py
示例11: make_block
def make_block(prev_block, txs, pubkey, DB):
leng=int(prev_block['length'])+1
target=blockchain.target(DB, leng)
diffLength=blockchain.hexSum(prev_block['diffLength'], blockchain.hexInvert(target))
out={'version':custom.version,
'txs':txs+[make_mint(pubkey, DB)],
'length':leng,
'time':time.time(),
'diffLength':diffLength,
'target':target,
'prevHash':tools.det_hash(prev_block)}
out=tools.unpackage(tools.package(out))
return out
开发者ID:Fangang,项目名称:basiccoin,代码行数:13,代码来源:consensus.py
示例12: main
def main():
info=sys.argv
peer=['127.0.0.1', custom.basicd_port]
p={'command':sys.argv[1:]}
if len(p['command'])==0:
p['command'].append(' ')
response=networking.send_command(peer, p, 5)
if tools.can_unpack(response):
response=tools.unpackage(response)
if type(response)==type({'a':1}):
if 'error' in response:
print('basiccoin is probably off. Use command: "python threads.py" to turn it on. (you may need to reboot it a couple times to get it working)')
return(response)
开发者ID:cartercar,项目名称:basiccoin,代码行数:13,代码来源:basicd.py
示例13: create_sign_tx
def create_sign_tx():
on_block=tools.local_get('length')+1
if on_block==0:
time.sleep(1)
return{'error':'not ready'}
r=tools.det_random(on_block)
jackpots=[]
address=tools.local_get('address')
l=max(-1, on_block-1-(custom.long_time*2-custom.medium_time))
election_block=tools.db_get(l+1)
proof=tools.local_get('balance_proofs'+str(l))
if 'root_hash' not in election_block:
return({'error':'database changed'})
a=tools.db_verify(election_block['root_hash'], address, proof)
if a==False:
#tools.log('election block: ' +str(election_block))
#tools.log('proof: ' +str(proof))
return({'error':'not valid proof'})
old_balance=a['amount']
M=custom.all_money
for j in range(custom.jackpot_nonces):
if tools.winner(old_balance, M, r, address, j):
jackpots.append(j)
if len(jackpots)>0:
tx={'on_block':on_block, 'jackpots':jackpots, 'type':'sign', 'amount':M/3000/3}
tx['B']=old_balance
tx['proof']=proof
if proof=='empty':
time.sleep(1)
return {'error':'not ready'}
secrets=tools.local_get('secrets')
if str(on_block) in secrets:
secret=secrets[str(on_block)]
else:
secret=tools.unpackage(tools.package({'salt':str(random.random())+str(random.random()), 'entropy':random.randint(0,1)}))
secrets[str(on_block)]=secret
tools.local_put('secrets', secrets)
tx['secret_hash']=tools.det_hash(secret)
if on_block>0:
block=tools.db_get(on_block-1)
if 'amount' in block and block['amount']==0:
return({'error':'database changed'})
#tools.log('on_block: ' +str(a))
tx['prev']=block['block_hash']
else:
tx= {'error':'no jackpots'}
return tx
开发者ID:BumblebeeBat,项目名称:FlyingFox,代码行数:47,代码来源:auto_signer.py
示例14: buy_block
def buy_block(DB, args):
gap=1#this should be an argument.
#we should also let the user delete as many blocks first as they want, to build a fork from a point in history.
length=tools.local_get('length')
prev_block=tools.db_get(length)
txs=tools.local_get('txs')
privkey=tools.local_get('privkey')
height=tools.local_get('height')
block=default_block(length+1, height+gap, txs+[sign(mint_tx(gap), privkey)])
to_hash=''
if length>-1: to_hash={'prev_hash':prev_block['block_hash'], 'txs':block['txs']}
block['block_hash']=tools.det_hash(to_hash)
block['root_hash']=tools.db_root()
block=sign(block, privkey)
block = tools.unpackage(tools.package(block))
DB['suggested_blocks'].put(block)
return block
开发者ID:appcoreopc,项目名称:slasher,代码行数:17,代码来源:api.py
示例15: connect
def connect(msg, host, port):
if len(msg) < 1 or len(msg) > MAX_MESSAGE_SIZE:
print("wrong sized message")
return
s = socket.socket()
try:
s.settimeout(2)
s.connect((str(host), int(port)))
msg["version"] = custom.version
s.send(tools.package(msg))
response = s.recv(MAX_MESSAGE_SIZE)
# print(response)
return tools.unpackage(response)
except Exception as e:
# print('THE ERROR WAS: ' +str(e))
# print('disconnect')
return {"error": "error"}
开发者ID:Noelkd,项目名称:basiccoin,代码行数:17,代码来源:networking.py
示例16: connect
def connect(msg, host, port):
msg['version'] = custom.version
msg = tools.package(msg)
if len(msg) < 1 or len(msg) > MAX_MESSAGE_SIZE:
print('wrong sized message')
return
s = socket.socket()
try:
s.settimeout(2)
s.connect((str(host), int(port)))
s.sendall(msg)
response = s.recv(MAX_MESSAGE_SIZE)
#print(response)
return tools.unpackage(response)
except Exception as e:
#print('THE ERROR WAS: ' +str(e))
#print('disconnect')
return {'error': e}
开发者ID:JPeroutek,项目名称:mycoin,代码行数:18,代码来源:networking.py
示例17: buy_block
def buy_block(DB, args):
gap = 1 # this should be an argument.
# we should also let the user delete as many blocks first as they want, to build a fork from a point in history.
length = tools.local_get("length")
prev_block = tools.db_get(length)
txs = tools.local_get("txs")
privkey = tools.local_get("privkey")
height = tools.local_get("height")
block = default_block(length + 1, height + gap, txs + [sign(mint_tx(gap), privkey)])
to_hash = ""
if length > -1:
to_hash = {"prev_hash": prev_block["block_hash"], "txs": block["txs"]}
block["block_hash"] = tools.det_hash(to_hash)
block["root_hash"] = tools.db_root()
block = sign(block, privkey)
block = tools.unpackage(tools.package(block))
DB["suggested_blocks"].put(block)
return block
开发者ID:jtremback,项目名称:FlyingFox,代码行数:18,代码来源:api.py
示例18: connect
def connect(msg, host, port, response_time=1):
if len(msg) < 1 or len(msg) > MAX_MESSAGE_SIZE:
tools.log('wrong sized message')
return('wrong size')
s = socket.socket()
s.setblocking(0)
b=connect_socket(s, str(host), int(port))
if not b:
s.close()
return ({'error':'cannot connect: '+str(host)})
msg['version'] = custom.version
sendall(s, tools.package(msg))
response=recvall(s, MAX_MESSAGE_SIZE, response_time)
s.close()
try:
return tools.unpackage(response)
except:
pass
if 'recvall timeout error' in response:
return({'error':'cannot download: '+str(host)})
开发者ID:cartercar,项目名称:basiccoin,代码行数:20,代码来源:networking.py
示例19: build_buy_shares
def build_buy_shares():
tx={'type':'buy_shares', 'PM_id':str(raw_input('What is the unique name for this prediction market?\n>'))}
num_states=int(raw_input('how many states does this pm have?\n>'))
tx['buy']=[]
for i in range(num_states):
tx['buy'].append(int(raw_input('how many shares do you want to buy of state '+str(i)+'? To sell states, use negative numbers.\n>')))
brainwallet=str(raw_input('What is your brainwallet\n>'))
privkey=tools.det_hash(brainwallet)
pubkey=tools.privtopub(privkey)
address=tools.make_address([pubkey], 1)
tx['pubkeys']=[pubkey]
tx['count'] = tools.count(address, {})
cost=txs_tools.cost_to_buy_shares(tx)
tx['price_limit']=int(cost*1.01)
print('now for a little proof of work. This may take several minutes. The purpose of this pow is to make it more difficult for a front runner to steal your trade.')
tx=tools.unpackage(tools.package(tx))
tx=tools.POW(tx)
tx['signatures']=[tools.sign(tools.det_hash(tx), privkey)]
print('tx for copy/pasting into pushtx: '+tools.package(tx).encode('base64'))
return tx
开发者ID:master-zhuang,项目名称:Truthcoin-POW,代码行数:20,代码来源:truth_cli.py
示例20: serve_once
def serve_once(PORT, handler, heart_queue, server):
heart_queue.put('server: '+str(PORT))
time.sleep(0.1)
try:
client, addr = server.accept()
except:
return
(ip, port) = addr
peer=[str(ip), int(port)]
try:
data=recvall(client, MAX_MESSAGE_SIZE)
except:
client.close()
return
if type(data)==type('string'):
data=tools.unpackage(data)
data['peer']=peer
try:
sendall(client, tools.package(handler(data)))
except:
pass
client.close()
开发者ID:truthcoin,项目名称:skunkworks,代码行数:22,代码来源:networking.py
注:本文中的tools.unpackage函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论