当前位置: 首页>>代码示例>>Python>>正文


Python tools.package函数代码示例

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


在下文中一共展示了package函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main(c=0):
    if type(c)==int:
        p={'command':sys.argv[1:]}
    else:
        p={'command':c}
    if len(p['command'])==0:
        p['command'].append(' ')
    c=p['command']
    if c[0]=='make_PM':
        tx=build_pm()
        return run_command({'command':['pushtx', tools.package(tx).encode('base64')]})
    elif c[0]=='buy_shares':
        tx=build_buy_shares()
        return run_command({'command':['pushtx', tools.package(tx).encode('base64')]})
    elif c[0]=='start':
        r=connect({'command':'blockcount'})
        if is_off(r):
            p=raw_input('what is your password?\n')
            daemonize(lambda: threads.main(p))
        else:
            print('blockchain is already running')
    elif c[0]=='new_address':
        if len(c)<2:
            print('what is your brain wallet? not enough inputs.')
        else:
            privkey=tools.det_hash(c[1])
            pubkey=tools.privtopub(privkey)
            address=tools.make_address([pubkey], 1)
            return({'brain':str(c[1]),
                    'privkey':str(privkey),
                    'pubkey':str(pubkey),
                    'address':str(address)})
    else:
        return run_command(p)
开发者ID:BumblebeeBat,项目名称:FlyingFox,代码行数:34,代码来源:cli.py

示例2: build_pm

def build_pm():
    tx={'type':'prediction_market', 'fees':0}
    pubkey=str(raw_input('What is the address or pubkey of the owner of the PM?\n>'))
    if len(pubkey)>40:
        tx['owner']=tools.make_address([pubkey], 1)
    else:
        tx['owner']=pubkey
    tx['PM_id']=str(raw_input('What is the unique name for this new prediction market?\n>'))
    tx['B']=int(raw_input('how big should B be? Initial investment is B*ln(n) where n is the number of states\n>'))
    num_decisions=int(raw_input('how many decisions is this prediction market to be based upon?\n>'))
    tx['decisions']=[]
    for i in range(num_decisions):
        tx['decisions'].append(str(raw_input('What is the unique name of the '+str(i)+' decision?\n>')))
    num_states=int(raw_input('how many states can this PM result in?\n>'))
    if num_states>2**num_decisions: 
        print('too many states')
        return False
    tx['states_combinatory']=[]
    tx['states']=[]
    for i in range(num_states):
        tx['states'].append(str(raw_input('what is the text title of the '+str(i)+' state?\n>')))
        if i!=num_states-1:
            next_comb=(str(raw_input('how does the '+str(i)+' state depend upon the outcome of the decisions? For example: if there are 2 decisions, and this market only comes true when the first is "yes" and the second is "no", then you would put: "1 0" here.\n>')))
            tx['states_combinatory'].append(map(int, next_comb.split(' ')))
    print('tx for copy/pasting into pushtx: '+tools.package(tx).encode('base64'))
    return tx
开发者ID:master-zhuang,项目名称:Truthcoin-POW,代码行数:26,代码来源:truth_cli.py

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: rangeRequest

 def rangeRequest(dic, DB):
     ran = dic['range']
     out = []
     counter = 0
     while len(tools.package(out)) < 50000 and ran[0] + counter <= ran[1]:
         block = blockchain.db_get(ran[0] + counter, DB)
         if 'length' in block:
             out.append(block)
         counter += 1
     return out
开发者ID:wassname,项目名称:basiccoin,代码行数:10,代码来源:listener.py

示例8: 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

示例9: 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

示例10: 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

示例11: send_msg

def send_msg(data, sock):
    data=tools.package(data)
    data=tools.buffer_(str(len(data)), 5)+data
    while data:
        time.sleep(0.0001)
        try:
            sent = sock.send(data)
        except:
            return 'peer died'
        data = data[sent:]
    return 0
开发者ID:AltCoinsLand,项目名称:basiccoin,代码行数:11,代码来源:networking.py

示例12: rangeRequest

def rangeRequest(dic):
    ran = dic['range']
    out = []
    counter = 0
    while (len(tools.package(out)) < custom.max_download
           and ran[0] + counter <= ran[1]):
        block = tools.db_get(ran[0] + counter, custom.queues)
        if 'length' in block:
            out.append(block)
        counter += 1
    return out
开发者ID:coinami,项目名称:coinami-pro,代码行数:11,代码来源:peer_recieve.py

示例13: 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

示例14: 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

示例15: 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


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