• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tools.db_get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tools.db_get函数的典型用法代码示例。如果您正苦于以下问题:Python db_get函数的具体用法?Python db_get怎么用?Python db_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了db_get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:cartercar,项目名称:basiccoin,代码行数:28,代码来源:blockchain.py


示例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')
开发者ID:master-zhuang,项目名称:Truthcoin-POW,代码行数:26,代码来源:peers_check.py


示例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)
开发者ID:Feretrius,项目名称:augur-core,代码行数:25,代码来源:peers_check.py


示例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)
开发者ID:appcoreopc,项目名称:slasher,代码行数:35,代码来源:blockchain.py


示例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)
开发者ID:master-zhuang,项目名称:Truthcoin-POW,代码行数:34,代码来源:peers_check.py


示例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
开发者ID:BumblebeeBat,项目名称:FlyingFox,代码行数:28,代码来源:reward_collector.py


示例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'}
开发者ID:master-zhuang,项目名称:Truthcoin-POW,代码行数:7,代码来源:peer_recieve.py


示例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
开发者ID:decisions,项目名称:Truthcoin-POW,代码行数:27,代码来源:txs_truthcoin.py


示例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
开发者ID:coinami,项目名称:coinami-pro,代码行数:7,代码来源:api.py


示例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
开发者ID:decisions,项目名称:Truthcoin-POW,代码行数:25,代码来源:txs_truthcoin.py


示例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
开发者ID:decisions,项目名称:Truthcoin-POW,代码行数:33,代码来源:txs_truthcoin.py


示例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)
开发者ID:coinami,项目名称:coinami-pro,代码行数:28,代码来源:blockchain.py


示例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))
开发者ID:coinami,项目名称:coinami-pro,代码行数:34,代码来源:blockchain.py


示例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))
开发者ID:decisions,项目名称:Truthcoin-POW,代码行数:27,代码来源:blockchain.py


示例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)
开发者ID:coinami,项目名称:coinami-pro,代码行数:34,代码来源:miner.py


示例16: give_block

def give_block(peer, DB, block_count_peer):
    blocks=[]
    b=[max(block_count_peer-5, 0), min(tools.db_get('length'), block_count_peer+custom.download_many)]
    for i in range(b[0], b[1]+1):
        blocks.append(tools.db_get(i, DB))
    cmd(peer, {'type': 'pushblock',
               'blocks': blocks})
    return 0
开发者ID:Feretrius,项目名称:augur-core,代码行数:8,代码来源:peers_check.py


示例17: info

def info(DB, args): 
    if len(args)<1:
        return ('not enough inputs')
    if args[0]=='my_address':
        address=tools.db_get('address')
    else:
        address=args[0]
    return(tools.db_get(address, DB))
开发者ID:AltCoinsLand,项目名称:basiccoin,代码行数:8,代码来源:api.py


示例18: info

def info(args):
    if len(args) < 1:
        return 'not enough inputs'
    if args[0] == 'my_address':
        address = tools.db_get('address')
    else:
        address = args[0]
    return tools.db_get(address)
开发者ID:coinami,项目名称:coinami-pro,代码行数:8,代码来源:api.py


示例19: sign_verify

def sign_verify(tx, txs, out, DB):#check the validity of a transaction of type sign.
    a=tools.addr(tx)
    B=tx['B']#verify a proof that addr(tx) actually owned that much money long*2-medium ago.
    M=custom.all_money
    address=tools.addr(tx)
    block=tools.db_get(tx['on_block'])
    num=max(0,tx['on_block']-(custom.long_time*2-custom.medium_time))
    election_block=tools.db_get(num)
    if not signature_check(tx):
        out[0]+='signature check'
        return False
    if 'root_hash' not in election_block:
        out[0]+='no root hash'
        return False
    v=tools.db_verify(election_block['root_hash'], address, tx['proof'])
    if v==False:
        tools.log('your address did not exist that long ago.')
        return False
    if v['amount']!=tx['B']:
        tools.log('that is not how much money you had that long ago')
        return False
    if 'secret_hash' not in tx:
        tools.log('need the hash of a secret')
        return False
    for t in txs:
        if tools.addr(t)==address and t['type']=='sign':
            #tools.log('can only have one sign tx per block')
            return False
    if len(tx['jackpots'])<1: 
        tools.log('insufficient jackpots')
        return False
    if not signature_check(tx):
        out[0]+='signature check'
        return False
    length=tools.local_get('length')
    if int(tx['on_block'])!=int(length+1):
        out[0]+='this tx is for the wrong block. have '+str(length+1) +' need: ' +str(tx['on_block'])
        return False
    if tx['on_block']>0:
        if not tx['prev']==tools.db_get(length)['block_hash']:
            tools.log('must give hash of previous block')
            return False
    ran=tools.det_random(tx['on_block'])
    for j in tx['jackpots']:
        if type(j)!=int or j not in range(200):
               tools.log('bad jackpot')
               return False
        if len(filter(lambda x: x==j, tx['jackpots']))!=1:
               tools.log('no repeated jackpots')
               return False
        if not tools.winner(B, M, ran, address, j):
            tools.log('that jackpot is not valid: '+str(j))
            return False
    if tx['amount']<custom.minimum_deposit:
        tools.log('you have to deposit more than that')
        return False
    return True
开发者ID:appcoreopc,项目名称:slasher,代码行数:57,代码来源:transactions.py


示例20: collect_winnings

def collect_winnings(DB, args):
    if len(args)<1:
        return ('not enough arguments')
    tools.log('collect_winnings 1')
    add=tools.db_get('address')
    acc=tools.db_get(add, DB)
    tx={'type':'collect_winnings', 'PM_id':args[0], 'address':add}
    tx['shares']=acc['shares'][tx['PM_id']]
    tools.log('collect_winnings 2')
    return easy_add_transaction(tx, DB)
开发者ID:decisions,项目名称:Truthcoin-POW,代码行数:10,代码来源:truthcoin_api.py



注:本文中的tools.db_get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tools.debug函数代码示例发布时间:2022-05-27
下一篇:
Python tools.create_mock_json函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap