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

Python utils.decode_int函数代码示例

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

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



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

示例1: to_dict

    def to_dict(self):
        state = self.state.to_dict(True)
        nstate = {}
        for s in state:
            t = Trie(STATEDB_DIR, state[s][STORAGE_INDEX])
            o = [0] * ACCT_RLP_LENGTH
            o[NONCE_INDEX] = decode_int(state[s][NONCE_INDEX])
            o[BALANCE_INDEX] = decode_int(state[s][BALANCE_INDEX])
            o[CODE_INDEX] = state[s][CODE_INDEX]
            td = t.to_dict(True)
            o[STORAGE_INDEX] = {decode_int(k): decode_int(td[k]) for k in td}
            nstate[s.encode('hex')] = o

        return {
            "number": self.number,
            "prevhash": self.prevhash,
            "uncles_root": self.uncles_root,
            "coinbase": self.coinbase,
            "state": nstate,
            "transactions_root": self.transactions_root,
            "difficulty": self.difficulty,
            "timestamp": self.timestamp,
            "extradata": self.extradata,
            "nonce": self.nonce
        }
开发者ID:jo,项目名称:pyethereum,代码行数:25,代码来源:blocks.py


示例2: create_contract

def create_contract(block,tx,msg):
    oldroot = block.state.root
    senderstate = block.state.get(msg.sender) or ['','','','']
    recvstate = ['','',sha3(msg.data),'']
    recvaddr = sha3(rlp.encode([msg.sender,senderstate[NONCE_INDEX]]))[12:]
    code = msg.data
    statedb.put(sha3(msg.data),msg.data)
    compustate = Compustate(gas=msg.gas)
    # Not enough vaue to send, instaquit
    if decode_int(senderstate[BALANCE_INDEX]) < msg.value:
        recvstate[2] = []
        block.state.update(recvaddr,recvstate)
        return recvaddr, compustate.gas
    # Transfer value and update nonce
    senderstate[BALANCE_INDEX] = encode_int(decode_int(senderstate[BALANCE_INDEX])-msg.value)
    senderstate[NONCE_INDEX] = encode_int(decode_int(senderstate[NONCE_INDEX])+1)
    recvstate[BALANCE_INDEX] = encode_int(decode_int(senderstate[BALANCE_INDEX])+msg.value)
    block.state.update(msg.sender.decode('hex'),senderstate)
    block.state.update(recvaddr,recvstate)
    # Temporary pre-POC5: don't do the code/init thing
    return recvaddr, compustate.gas
    # Main loop
    while 1:
        o = apply_op(block,tx,msg,msg.data,compustate.op)
        if o is not None:
            if o == OUT_OF_GAS:
                block.state.root = oldroot
                return 0, 0
            else:
                recvstate = block.state.get(recvaddr)
                recvstate[CODE_INDEX] = sha3(map(chr,o))
                statedb.put(sha3(map(chr,o)),map(chr,o))
                block.state.update(recvaddr,recvstate)
                return recvaddr, recvstate
开发者ID:lessc0de,项目名称:pyethereum,代码行数:34,代码来源:processblock.py


示例3: delta_index

 def delta_index(self,address,index,value):
     if len(address) == 40: address = address.decode('hex')
     acct = self.state.get(address) or ['','','','']
     if decode_int(acct[index]) + value < 0:
         return False
     acct[index] = encode_int(decode_int(acct[index])+value)
     self.state.update(address,acct)
     return True
开发者ID:gojira,项目名称:pyethereum,代码行数:8,代码来源:blocks.py


示例4: account_to_dict

 def account_to_dict(self, address):
     med_dict = {}
     for i, val in enumerate(self.get_acct(address)):
         med_dict[acct_structure[i][0]] = val
     strie = trie.Trie(utils.get_db_path(), med_dict['storage']).to_dict()
     med_dict['storage'] = {utils.decode_int(k): utils.decode_int(v)
                            for k, v in strie.iteritems()}
     return med_dict
开发者ID:VIAAC,项目名称:pyethereum,代码行数:8,代码来源:blocks.py


示例5: apply_tx

def apply_tx(block,tx):
    fee = tx.gasprice * tx.startgas
    addrstate = block.state.get(tx.sender.decode('hex'))
    if not addrstate:
        raise Exception("Sending from a not-yet-existent account!")
    if decode_int(addrstate[NONCE_INDEX]) != tx.nonce:
        print decode_int(addrstate[NONCE_INDEX]), tx.nonce
        raise Exception("Invalid nonce!")
    if decode_int(addrstate[BALANCE_INDEX]) < fee:
        raise Exception("Not enough in account to pay fee!")
    addrstate[NONCE_INDEX] = encode_int(decode_int(addrstate[NONCE_INDEX])+1)
    addrstate[BALANCE_INDEX] = encode_int(decode_int(addrstate[BALANCE_INDEX])-fee)
    block.state.update(tx.sender.decode('hex'),addrstate)
    block.gas_consumed += fee
    medroot = block.state.root
    message_gas = tx.startgas - GTXDATA * len(tx.data)
    message = Message(tx.sender,tx.to,tx.value,message_gas,tx.data)
    if tx.to:
        s,g,d = apply_msg(block,tx,message)
    else:
        s,g = create_contract(block,tx,message)
    if not s:
        block.state.root = medroot
        minerstate = block.state.get(block.coinbase)
        minerstate[BALANCE_INDEX] = encode_int(decode_int(minerstate[BALANCE_INDEX])+fee)
        block.state.update(block.coinbase,minerstate)
    else:
        addrstate[BALANCE_INDEX] = encode_int(decode_int(addrstate[BALANCE_INDEX])+tx.gasprice * g)
        block.state.update(tx.sender.decode('hex'),addrstate)
        minerstate = block.state.get(block.coinbase.decode('hex')) or ['','','','']
        minerstate[BALANCE_INDEX] = encode_int(decode_int(minerstate[BALANCE_INDEX])+(fee - g * tx.gasprice))
        block.state.update(block.coinbase.decode('hex'),minerstate)
开发者ID:lessc0de,项目名称:pyethereum,代码行数:32,代码来源:processblock.py


示例6: account_to_dict

 def account_to_dict(self, address):
     if len(address) == 40:
         address = address.decode('hex')
     acct = self.state.get(address) or ['', '', '', '']
     chash = acct[CODE_INDEX]
     stdict = Trie(STATEDB_DIR, acct[STORAGE_INDEX]).to_dict(True)
     return {
         'nonce': decode_int(acct[NONCE_INDEX]),
         'balance': decode_int(acct[BALANCE_INDEX]),
         'code': self.state.db.get(chash).encode('hex') if chash else '',
         'storage': {decode_int(k): decode_int(stdict[k]) for k in stdict}
     }
开发者ID:jo,项目名称:pyethereum,代码行数:12,代码来源:blocks.py


示例7: _account_to_dict

 def _account_to_dict(self, acct):
     med_dict = {}
     for i, (name, typ, default) in enumerate(acct_structure):
         med_dict[name] = utils.decoders[typ](acct[i])
     chash = med_dict['code']
     strie = trie.Trie(utils.get_db_path(), med_dict['storage']).to_dict()
     med_dict['code'] = \
         self.state.db.get(chash).encode('hex') if chash else ''
     med_dict['storage'] = {
         utils.decode_int(k): utils.decode_int(strie[k]) for k in strie
     }
     return med_dict
开发者ID:mrmayfield,项目名称:pyethereum,代码行数:12,代码来源:blocks.py


示例8: _delta_item

 def _delta_item(self, address, index, value):
     ''' add value to account item
     :param address: account address, can be binary or hex string
     :param index: item index
     :param value: can be positive or negative
     '''
     if len(address) == 40:
         address = address.decode('hex')
     acct = self.state.get(address) or ['', '', '', '']
     if decode_int(acct[index]) + value < 0:
         return False
     acct[index] = encode_int(decode_int(acct[index]) + value)
     self.state.update(address, acct)
     return True
开发者ID:jo,项目名称:pyethereum,代码行数:14,代码来源:blocks.py


示例9: _delta_item

 def _delta_item(self, address, param, value):
     ''' add value to account item
     :param address: account address, can be binary or hex string
     :param param: parameter to increase/decrease
     :param value: can be positive or negative
     '''
     if len(address) == 40:
         address = address.decode('hex')
     acct = self.state.get(address) or ['', '', '', '']
     index = acct_structure_rev[param][0]
     if utils.decode_int(acct[index]) + value < 0:
         return False
     acct[index] = utils.encode_int(utils.decode_int(acct[index]) + value)
     self.state.update(address, acct)
     return True
开发者ID:mrmayfield,项目名称:pyethereum,代码行数:15,代码来源:blocks.py


示例10: remote_blocks_received_handler

def remote_blocks_received_handler(sender, block_lst, peer, **kwargs):
    logger.debug("received %d remote blocks", len(block_lst))

    old_head = chain_manager.head
    # assuming chain order w/ newest block first
    for block_data in reversed(block_lst):
        try:
            block = blocks.Block.deserialize(rlp.encode(block_data))
        except blocks.UnknownParentException:
            # no way to ask peers for older parts of chain
            bhash = utils.sha3(rlp.encode(block_data)).encode('hex')[:4]
            phash = block_data[0][0].encode('hex')[:4]
            number = utils.decode_int(block_data[0][6])
            logger.debug('Block(#%d %s %s) with unknown parent, requesting ...',
                         number, bhash, phash.encode('hex')[:4])
            chain_manager.synchronize_blockchain()
            break
        if block.hash in chain_manager:
            logger.debug('Known %r', block)
        else:
            if block.has_parent():
                # add block & set HEAD if it's longest chain
                success = chain_manager.add_block(block)
                if success:
                    logger.debug('Added %r', block)
            else:
                logger.debug('Orphant %r', block)
    if chain_manager.head != old_head:
        chain_manager.synchronize_blockchain()
开发者ID:mrmayfield,项目名称:pyethereum,代码行数:29,代码来源:chainmanager.py


示例11: get_transaction

 def get_transaction(self, txhash):
     "return (tx, block)"
     blockhash, tx_num_enc = rlp.decode(self.db.get(txhash))
     blk = blocks.get_block(blockhash)
     num = utils.decode_int(tx_num_enc)
     tx_data, msr, gas = blk.get_transaction(num)
     return Transaction.create(tx_data), blk
开发者ID:csbitcoin,项目名称:pyethereum,代码行数:7,代码来源:chainmanager.py


示例12: to_dict

 def to_dict(self, with_state=False, full_transactions=False, with_storage_roots=False):
     """
     serializes the block
     with_state:             include state for all accounts
     full_transactions:      include serialized tx (hashes otherwise)
     """
     b = {}
     for name, typ, default in block_structure:
         b[name] = utils.printers[typ](getattr(self, name))
     txlist = []
     for i in range(self.transaction_count):
         tx_rlp = self.transactions.get(rlp.encode(utils.encode_int(i)))
         tx, msr, gas = rlp.decode(tx_rlp)
         if full_transactions:
             txjson = transactions.Transaction.create(tx).to_dict()
         else:
             txjson = utils.sha3(rlp.descend(tx_rlp, 0)).encode('hex')  # tx hash
         txlist.append({
             "tx": txjson,
             "medstate": msr.encode('hex'),
             "gas": str(utils.decode_int(gas))
         })
     b["transactions"] = txlist
     if with_state:
         state_dump = {}
         for address, v in self.state.to_dict().iteritems():
             state_dump[address.encode('hex')] = \
                 self.account_to_dict(address, with_storage_roots)
         b['state'] = state_dump
     return b
开发者ID:qualiabyte,项目名称:pyethereum,代码行数:30,代码来源:blocks.py


示例13: decode_datalist

def decode_datalist(arr):
    if isinstance(arr, list):
        arr = ''.join(map(chr, arr))
    o = []
    for i in range(0, len(arr), 32):
        o.append(decode_int(arr[i:i + 32]))
    return o
开发者ID:jo,项目名称:pyethereum,代码行数:7,代码来源:processblock.py


示例14: verify_independent_transaction_spv_proof

def verify_independent_transaction_spv_proof(proof):
    _, prevheader, header, index, nodes = rlp.decode(proof)
    index = utils.decode_int(index)
    pb = blocks.Block.deserialize_header(prevheader)
    b = blocks.Block.init_from_header(header)
    b.set_proof_mode(blocks.VERIFYING, nodes)
    if index != 0:
        _, pre_med, pre_gas = b.get_transaction(index - 1)
    else:
        pre_med, pre_gas = pb['state_root'], ''
        if utils.sha3(rlp.encode(prevheader)) != b.prevhash:
            return False
    b.state_root = pre_med
    b.gas_used = utils.decode_int(pre_gas)
    tx, post_med, post_gas = b.get_transaction(index)
    tx = transactions.Transaction.create(tx)
    o = verify_transaction_spv_proof(b, tx, nodes)
    return o and b.state_root == post_med and b.gas_used == utils.decode_int(post_gas)
开发者ID:Bitcoinzie,项目名称:pyethereum,代码行数:18,代码来源:processblock.py


示例15: __init__

    def __init__(self, data=None):

        self.reward = 10 ** 18
        self.gas_consumed = 0
        self.gaslimit = 1000000  # for now

        if not data:
            self.number = 0
            self.prevhash = ''
            self.uncles_root = ''
            self.coinbase = '0' * 40
            self.state = Trie(get_db_path())
            self.transactions_root = ''
            self.transactions = []
            self.uncles = []
            self.difficulty = 2 ** 23
            self.timestamp = 0
            self.extradata = ''
            self.nonce = 0
            return

        if re.match('^[0-9a-fA-F]*$', data):
            data = data.decode('hex')

        header,  transaction_list, self.uncles = rlp.decode(data)
        self.number = decode_int(header[0])
        self.prevhash = header[1]
        self.uncles_root = header[2]
        self.coinbase = header[3].encode('hex')
        self.state = Trie(STATEDB_DIR, header[4])
        self.transactions_root = header[5]
        self.difficulty = decode_int(header[6])
        self.timestamp = decode_int(header[7])
        self.extradata = header[8]
        self.nonce = decode_int(header[9])
        self.transactions = [Transaction(x) for x in transaction_list]

        # Verifications
        if self.state.root != '' and self.state.db.get(self.state.root) == '':
            raise Exception("State Merkle root not found in database!")
        if sha3(rlp.encode(transaction_list)) != self.transactions_root:
            raise Exception("Transaction list root hash does not match!")
        if sha3(rlp.encode(self.uncles)) != self.uncles_root:
            raise Exception("Uncle root hash does not match!")
开发者ID:jo,项目名称:pyethereum,代码行数:44,代码来源:blocks.py


示例16: deserialize_child

    def deserialize_child(self, rlpdata):
        """
        deserialization w/ replaying transactions
        """
        header_args, transaction_list, uncles = rlp.decode(rlpdata)
        assert len(header_args) == len(block_structure)
        kargs = dict(transaction_list=transaction_list, uncles=uncles)
        # Deserialize all properties
        for i, (name, typ, default) in enumerate(block_structure):
            kargs[name] = utils.decoders[typ](header_args[i])

        block = Block.init_from_parent(self, kargs['coinbase'],
                                       extra_data=kargs['extra_data'],
                                       timestamp=kargs['timestamp'],
                                       uncles=uncles)

        # replay transactions
        for tx_lst_serialized, _state_root, _gas_used_encoded in \
                transaction_list:
            tx = transactions.Transaction.create(tx_lst_serialized)
#            logger.debug('state:\n%s', utils.dump_state(block.state))
#            logger.debug('applying %r', tx)
            success, output = processblock.apply_transaction(block, tx)
            #block.add_transaction_to_list(tx) # < this is done by processblock
#            logger.debug('state:\n%s', utils.dump_state(block.state))
            logger.debug('d %s %s', _gas_used_encoded, block.gas_used)
            assert utils.decode_int(_gas_used_encoded) == block.gas_used, \
                "Gas mismatch (ours %d, theirs %d) on block: %r" % \
                (block.gas_used, _gas_used_encoded, block.to_dict(False, True, True))
            assert _state_root == block.state.root_hash, \
                "State root mismatch (ours %r theirs %r) on block: %r" % \
                (block.state.root_hash.encode('hex'),
                 _state_root.encode('hex'),
                 block.to_dict(False, True, True))

        block.finalize()

        block.uncles_hash = kargs['uncles_hash']
        block.nonce = kargs['nonce']
        block.min_gas_price = kargs['min_gas_price']

        # checks
        assert block.prevhash == self.hash

        assert block.gas_used == kargs['gas_used']
        assert block.gas_limit == kargs['gas_limit']
        assert block.timestamp == kargs['timestamp']
        assert block.difficulty == kargs['difficulty']
        assert block.number == kargs['number']
        assert block.extra_data == kargs['extra_data']
        assert utils.sha3(rlp.encode(block.uncles)) == kargs['uncles_hash']

        assert block.tx_list_root == kargs['tx_list_root']
        assert block.state.root_hash == kargs['state_root'], (block.state.root_hash, kargs['state_root'])

        return block
开发者ID:Bitcoinzie,项目名称:pyethereum,代码行数:56,代码来源:blocks.py


示例17: chain_difficulty

 def chain_difficulty(self):
         # calculate the summarized_difficulty (on the fly for now)
     if self.is_genesis():
         return self.difficulty
     elif 'difficulty:'+self.hex_hash() in self.state.db:
         return utils.decode_int(
             self.state.db.get('difficulty:'+self.hex_hash()))
     else:
         o = self.difficulty + self.get_parent().chain_difficulty()
         self.state.db.put('difficulty:'+self.hex_hash(),
                           utils.encode_int(o))
         return o
开发者ID:andregoiano,项目名称:pyethereum,代码行数:12,代码来源:blocks.py


示例18: chain_difficulty

 def chain_difficulty(self):
     # calculate the summarized_difficulty
     if self.is_genesis():
         return self.difficulty
     elif "difficulty:" + self.hex_hash() in self.state.db:
         return utils.decode_int(self.state.db.get("difficulty:" + self.hex_hash()))
     else:
         _idx, _typ, _ = block_structure_rev["difficulty"]
         o = self.difficulty + self.get_parent().chain_difficulty()
         o += sum([utils.decoders[_typ](u[_idx]) for u in self.uncles])
         self.state.db.put("difficulty:" + self.hex_hash(), utils.encode_int(o))
         return o
开发者ID:miro-blakeley,项目名称:pyethereum,代码行数:12,代码来源:blocks.py


示例19: to_dict

 def to_dict(self):
     state = self.state.to_dict(True)
     nstate = {}
     for s in state:
         t = Trie('statedb',state[s][3])
         nstate[s.encode('hex')] = [ decode_int(state[s][0]),
                                     decode_int(state[s][1]),
                                     state[s][2],
                                     t.to_dict(True) ]
         
     return {
         "number": self.number,
         "prevhash": self.prevhash,
         "uncles_root": self.uncles_root,
         "coinbase": self.coinbase,
         "state": nstate,
         "transactions_root": self.transactions_root,
         "difficulty": self.difficulty,
         "timestamp": self.timestamp,
         "extradata": self.extradata,
         "nonce": self.nonce
     }
开发者ID:lessc0de,项目名称:pyethereum,代码行数:22,代码来源:blocks.py


示例20: verify_independent_transaction_spv_proof

def verify_independent_transaction_spv_proof(db, proof):
    _, prevheader, header, index, nodes = rlp.decode(proof)
    index = utils.decode_int(index)
    pb = blocks.Block.deserialize_header(prevheader)
    b = blocks.Block.init_from_header(db, header)
    b.set_proof_mode(blocks.VERIFYING, nodes)
    if index != 0:
        pre_med, pre_gas, _, _ = b.get_receipt(index - 1)
    else:
        pre_med, pre_gas = pb['state_root'], ''
        if utils.sha3(rlp.encode(prevheader)) != b.prevhash:
            return False
    b.state_root = pre_med
    b.gas_used = utils.decode_int(pre_gas)
    tx = b.get_transaction(index)
    post_med, post_gas, bloom, logs = b.get_receipt(index)
    tx = transactions.Transaction.create(tx)
    o = verify_transaction_spv_proof(b, tx, nodes)
    if b.state_root == post_med:
        if b.gas_used == utils.decode_int(post_gas):
            if [x.serialize() for x in b.logs] == logs:
                if b.mk_log_bloom() == bloom:
                    return o
    return False
开发者ID:ckeenan,项目名称:pyethereum,代码行数:24,代码来源:spv.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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