本文整理汇总了Python中tools.db_get函数的典型用法代码示例。如果您正苦于以下问题:Python db_get函数的具体用法?Python db_get怎么用?Python db_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_block
def delete_block(DB):
""" Removes the most recent block from the blockchain. """
if DB['length'] < 0:
return
try:
targets.pop(str(DB['length']))
except:
pass
try:
times.pop(str(DB['length']))
except:
pass
block = tools.db_get(DB['length'], DB)
orphans = copy.deepcopy(DB['txs'])
DB['txs'] = []
for tx in block['txs']:
orphans.append(tx)
DB['add_block']=False
transactions.update[tx['type']](tx, DB)
tools.db_delete(DB['length'], DB)
DB['length'] -= 1
if DB['length'] == -1:
DB['diffLength'] = '0'
else:
block = tools.db_get(DB['length'], DB)
DB['diffLength'] = block['diffLength']
for orphan in sorted(orphans, key=lambda x: x['count']):
add_tx(orphan, DB)
示例2: main_once
def main_once(DB):
DB['heart_queue'].put('peers check')
pr=tools.db_get('peers_ranked')
pr=sorted(pr, key=lambda r: r[2])
pr.reverse()
time.sleep(0.05)
if DB['suggested_blocks'].empty() and tools.db_get('length')>3:
time.sleep(10)
i=0
while not DB['suggested_blocks'].empty():
i+=1
time.sleep(0.1)
if i%100==0:
DB['heart_queue'].put('peers check')
DB['heart_queue'].put('peers check')
i=exponential_random(3.0/4)%len(pr)
t1=time.time()
r=peer_check(i, pr, DB)
t2=time.time()
pr[i][1]*=0.8
if r==0:
pr[i][1]+=0.2*(t2-t1)
else:
pr[i][1]+=0.2*30
tools.db_put('peers_ranked', pr)
DB['heart_queue'].put('peers check')
示例3: peer_check
def peer_check(peer, DB):
peers=tools.db_get('peers')
if peers[peer]['length']==0 or random.random()<0.1:
ask_for_count(peer)
out=trade_peers(peer)
if type(out)==dict and 'error' in out:
return 1
peers=tools.db_get('peers')
length = tools.db_get('length')
diffLength= tools.db_get('diffLength')
size = max(len(diffLength), len(peers[peer]['diffLength']))
us = tools.buffer_(diffLength, size)
them = tools.buffer_(peers[peer]['diffLength'], size)
if them < us:
return give_block(peer, DB, peers[peer]['length'])
elif us == them:
try:
ask_for_count(peer)
trade_peers(peer)
return ask_for_txs(peer, DB)
except Exception as exc:
tools.log('ask for tx error')
tools.log(exc)
else:
return download_blocks(peer, DB, peers[peer]['length'], length)
示例4: delete_block
def delete_block(DB):
""" Removes the most recent block from the blockchain. """
length=tools.local_get('length')
if length < 0:
return
try:
ts=tools.local_get('targets')
ts.pop(str(length))
tools.local_put('targets', ts)
except:
pass
try:
ts=tools.local_get('times')
ts.pop(str(length))
tools.local_put('times', ts)
except:
pass
block = tools.db_get(length, DB)
orphans = tools.local_get('txs')
orphans=filter(lambda t: t['type']!='mint', orphans)
tools.local_put('txs', [])
for tx in block['txs']:
orphans.append(tx)
tools.local_put('add_block', False)
transactions.update[tx['type']](tx, DB, False)
tools.db_delete(length, DB)
length-=1
tools.local_put('length', length)
if length>=0:
block=tools.db_get(length)
tools.local_put('height', filter(lambda t: t['type']=='mint', block['txs'])[0]['height'])
else:
tools.local_put('height', -1)
for orphan in orphans:
add_tx(orphan, DB)
示例5: peer_check
def peer_check(i, peers, DB):
peer=peers[i][0]
block_count = cmd(peer, {'type': 'blockCount'})
if not isinstance(block_count, dict):
return
if 'error' in block_count.keys():
return
peers[i][2]=block_count['diffLength']
peers[i][3]=block_count['length']
length = tools.db_get('length')
diffLength= tools.db_get('diffLength')
size = max(len(diffLength), len(block_count['diffLength']))
us = tools.buffer_(diffLength, size)
them = tools.buffer_(block_count['diffLength'], size)
if them < us:
give_block(peer, DB, block_count['length'])
elif us == them:
try:
ask_for_txs(peer, DB)
except Exception as exc:
tools.log('ask for tx error')
tools.log(exc)
else:
download_blocks(peer, DB, block_count, length)
F=False
my_peers=tools.db_get('peers_ranked')
their_peers=cmd(peer, {'type':'peers'})
if type(my_peers)==list:
for p in their_peers:
if p not in my_peers:
F=True
my_peers.append(p)
if F:
tools.db_put('peers_ranked', my_peers)
示例6: create_reward_tx
def create_reward_tx():
tx={}
tx['type']='reward'
length=tools.local_get('length')
tx['on_block']=length-custom.long_time+random.randint(-custom.medium_time/2, custom.medium_time/2)
if tx['on_block']<=0:
time.sleep(1)
return {'error':'no rewards to collect'}
address=tools.local_get('address')
acc=tools.db_get(address)
if str(tx['on_block']) in acc['entropy']:
return {'error':'already collected that reward'}
zeroths=tools.local_get('txs')
zeroths=filter(lambda t: tools.addr(t)==address, zeroths)
zeroths=filter(lambda t: t['type']=='reward', zeroths)
if len(zeroths)>0:
{'error':'already made the tx to collect that reward'}
txs=tools.db_get(tx['on_block'])['txs']
txs=filter(lambda t: t['type']=='sign', txs)
#tools.log('on block: ' +str(tx['on_block']))
#tools.log('txs: ' +str(txs))
sign_tx=filter(lambda t: tools.addr(t)==address, txs)[0]
#tools.log('txs: ' +str(sign_tx))
relative_reward=tools.relative_reward(tx['on_block'], address)
tx['amount']=relative_reward+sign_tx['amount']
tx['reveal']=tools.local_get('secrets')[str(tx['on_block'])]
tx['jackpots']=len(sign_tx['jackpots'])
return tx
示例7: blockCount
def blockCount(dic, DB):
length = tools.db_get('length')
if length >= 0:
return {'length': length,
'diffLength': tools.db_get('diffLength')}
else:
return {'length': -1, 'diffLength': '0'}
示例8: collect_winnings_check
def collect_winnings_check(tx, txs, out, DB):
if not transactions.signature_check(tx):
out[0]+='signature check'
return False
if not E_check(tx, 'address', [str, unicode]):
out[0]+='no address error'
return False
acc=tools.db_get(tx['address'], DB)
if not E_check(tx, 'PM_id', [str, unicode]):
out[0]+='no PM_id error'
return False
if tx['PM_id'] not in acc['shares']:
out[0]+='you do not own any shares for this PM'
return False
if not tx['shares']==acc['shares'][tx['PM_id']]:
out[0]+='that is not how many shares you have error'
return False
pm=tools.db_get(tx['PM_id'], DB)
if 'decisions' not in pm:
out[0]+='that is not a prediction market yet'
return False
for dec in pm['decisions']:
decision = tools.db_get(dec, DB)
if decision['state'] not in ['yes', 'no']:
out[0]+='we have not yet reached consensus on the outcome of this market error'
return False
return True
示例9: my_balance
def my_balance(args, address='default'):
if address == 'default':
address = tools.db_get('address')
try:
return tools.db_get(address)['amount'] - tools.cost_0(tools.db_get('txs'), address)
except:
return 0
示例10: slasher_jury_vote_check
def slasher_jury_vote_check(tx, txs, out, DB):
address=addr(tx)
if tools.reveal_time_p(DB):
out[0]+='reveal time check slasher'
return False
if not transactions.signature_check(tx):
out[0]+='signature check'
return False
if not E_check(tx, 'amount', int):
out[0]+='how many votecoins are we confiscating?'
return False
if not E_check(tx, 'reveal', dict):
out[0]+='no reveal'
return False
if not reveal_jury_vote_check(tx['reveal'], txs, DB):
out[0]+='this is an invalid reveal tx'
return False
victim=tools.db_get(addr(tx['reveal']), DB)
decision=tx['reveal']['decision_id']
decision=tools.db_get(decision, DB)
if victim['votecoin'][tx['reveal']['vote_id']]!=tx['amount']:
out[0]+='that is not how many votecoins they have'
return False
return True
示例11: reveal_jury_vote_check
def reveal_jury_vote_check(tx, txs, out, DB):
if not transactions.signature_check(tx):
out[0]+='signature check'
return False
address=addr(tx)
acc=tools.db_get(address, DB)
if not E_check(tx, 'decision_id', [str, unicode]):
out[0]+='decision id error'
return False
if is_number(tx['decision_id']):
out[0]+='that can not be a number'
return False
decision=tools.db_get(tx['decision_id'], DB)
if decision['state']!='proposed':
out[0]+='this decision has already been decided'
return False
if not E_check(tx, 'old_vote', [str, unicode]): return False
if not E_check(tx, 'secret', [str, unicode]): return False
if not E_check(tx, 'new_vote', [str, unicode]):
out[0]+='new vote error'
return False
if tx['decision_id'] not in acc['votes']:
out[0]+='decision id not in acc[votes] error'
return False
answer_hash=acc['votes'][tx['decision_id']]
if not answer_hash==tools.det_hash([tx['new_vote'], tx['secret']]):
out[0]+='hash does not match'
return False
if not E_check(tx, 'old_vote', [str, unicode]):
out[0]+='old vote does not exist error'
return False
if not txs_tools.fee_check(tx, txs, DB): return False
return True
示例12: delete_block
def delete_block(DB):
""" Removes the most recent block from the blockchain. """
length = tools.db_get('length')
if length < 0:
return
try:
ts = tools.db_get('times')
ts.pop(str(length))
tools.db_put('times', ts)
except:
pass
block = tools.db_get(length, DB)
orphans = tools.db_get('txs')
tools.db_put('txs', [])
for tx in block['txs']:
orphans.append(tx)
tools.db_put('add_block', False)
transactions.update[tx['type']](tx, DB, False)
tools.db_delete(length, DB)
length -= 1
tools.db_put('length', length)
if length == -1:
tools.db_put('diffLength', '0')
else:
block = tools.db_get(length, DB)
for orphan in sorted(orphans, key=lambda x: x['count']):
add_tx(orphan, DB)
示例13: recent_blockthings
def recent_blockthings(key, size, length=0):
# get the storage from DB which was originally recorded as "key"
storage = tools.db_get(key)
def get_val(length):
leng = str(length)
if not leng in storage:
block = tools.db_get(leng)
if block == database.default_entry():
if leng == tools.db_get('length'):
tools.db_put('length', int(leng) - 1)
block = tools.db_get(leng)
# try:
storage[leng] = tools.db_get(leng)[key[:-1]]
tools.db_put(key, storage)
return storage[leng]
# pop from storage till you reach the end
def clean_up(storage, end):
if end < 0: return
if not str(end) in storage:
return
else:
storage.pop(str(end))
return clean_up(storage, end - 1)
# DB returns the blockchain length from 'length' key
if length == 0:
length = tools.db_get('length')
start = max((length - size), 0)
clean_up(storage, length - max(custom.mmm, custom.history_length) - 100)
return map(get_val, range(start, length))
示例14: recent_blockthings
def recent_blockthings(key, size, length=0):
storage = tools.db_get(key)
def get_val(length):
leng = str(length)
if not leng in storage:
block=tools.db_get(leng)
if block==tools.default_entry:
if leng==tools.db_get('length'):
tools.db_put('length', int(leng)-1)
block=tools.db_get(leng)
else:
error()
#try:
storage[leng] = tools.db_get(leng)[key[:-1]]
tools.db_put(key, storage)
return storage[leng]
def clean_up(storage, end):
if end<0: return
if not str(end) in storage: return
else:
storage.pop(str(end))
return clean_up(storage, end-1)
if length == 0:
length = tools.db_get('length')
start = max((length-size), 0)
clean_up(storage, length-max(custom.mmm, custom.history_length)-100)
return map(get_val, range(start, length))
示例15: insert_block
def insert_block(pubkey, rewarded_pubkey):
length = tools.db_get('length')
if length == -1:
# this is the first ever block
candidate_block = genesis(pubkey)
else:
# get the last block
prev_block = tools.db_get(length)
candidate_block = make_block(prev_block, tools.db_get('txs'), pubkey)
txs = copy.deepcopy(candidate_block['txs'])
flag = True
for tx in txs:
if tx['type'] == 'mint':
# no need to add reward
flag = False
if flag:
txs = txs + [make_mint(rewarded_pubkey)]
candidate_block['txs'] = txs
if tools.db_existence('privkey'):
privkey = tools.db_get('privkey')
else:
return 'no private key is known, so the tx cannot be signed. Here is the tx: \n' + str(
tools.package(txs).encode('base64').replace('\n', ''))
candidate_block['auth_sign'] = tools.sign(tools.det_hash(candidate_block), privkey)
candidate_block['auth_pubkey'] = pubkey
if candidate_block is None:
return
else:
custom.queues['suggested_blocks'].put(candidate_block)