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


Python utils.big_endian_to_int函数代码示例

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


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

示例1: add_block

    def add_block(self, block):

        blockhash = block.hash()
        if blockhash == GENESIS_H:
            parent_score = 0
        else:
            try:
                parent = rlp.decode(self.blockchain.get(block.prevhash))
            except:
                raise Exception("Parent of block not found")
            parent_score = utils.big_endian_to_int(parent[1])
        total_score = utils.int_to_big_endian(block.difficulty + parent_score)
        self.blockchain.put(
            blockhash, rlp.encode([block.serialize(), total_score]))
        try:
            head = self.blockchain.get('head')
            head_data = rlp.decode(self.blockchain.get(head))
            head_score = utils.big_endian_to_int(head_data[1])
        except:
            head_score = 0
        if total_score > head_score:
            self.head = blockhash
            self.blockchain.put('head', blockhash)
            return True
        return False
开发者ID:zancas,项目名称:pyethereum,代码行数:25,代码来源:chainmanager.py

示例2: __decode

def __decode(s, pos=0):
    assert pos < len(s), "read beyond end of string in __decode"

    fchar = ord(s[pos])
    if fchar < 128:
        return (s[pos], pos + 1)
    elif fchar < 184:
        b = fchar - 128
        return (s[pos + 1:pos + 1 + b], pos + 1 + b)
    elif fchar < 192:
        b = fchar - 183
        b2 = big_endian_to_int(s[pos + 1:pos + 1 + b])
        return (s[pos + 1 + b:pos + 1 + b + b2], pos + 1 + b + b2)
    elif fchar < 248:
        o = []
        pos += 1
        pos_end = pos + fchar - 192

        while pos < pos_end:
            obj, pos = __decode(s, pos)
            o.append(obj)
        assert pos == pos_end, "read beyond list boundary in __decode"
        return (o, pos)
    else:
        b = fchar - 247
        b2 = big_endian_to_int(s[pos + 1:pos + 1 + b])
        o = []
        pos += 1 + b
        pos_end = pos + b2
        while pos < pos_end:
            obj, pos = __decode(s, pos)
            o.append(obj)
        assert pos == pos_end, "read beyond list boundary in __decode"
        return (o, pos)
开发者ID:zancas,项目名称:pyethereum,代码行数:34,代码来源:rlp.py

示例3: decode_single

def decode_single(typ, data):
    base, sub, _ = typ
    if base == 'address':
        return encode_hex(data[12:])
    elif base == 'hash':
        return data[32 - int(sub):]
    elif base == 'string' or base == 'bytes':
        if len(sub):
            return data[:int(sub)]
        else:
            l = big_endian_to_int(data[0:32])
            return data[32:][:l]
    elif base == 'uint':
        return big_endian_to_int(data)
    elif base == 'int':
        o = big_endian_to_int(data)
        return (o - 2 ** int(sub)) if o >= 2 ** (int(sub) - 1) else o
    elif base == 'ureal':
        high, low = [int(x) for x in sub.split('x')]
        return big_endian_to_int(data) * 1.0 // 2 ** low
    elif base == 'real':
        high, low = [int(x) for x in sub.split('x')]
        o = big_endian_to_int(data)
        i = (o - 2 ** (high + low)) if o >= 2 ** (high + low - 1) else o
        return (i * 1.0 // 2 ** low)
    elif base == 'bool':
        return bool(int(encode_hex(data), 16))
开发者ID:shiftcurrency,项目名称:phantom,代码行数:27,代码来源:abi.py

示例4: __init__

 def __init__(self, pubkey):
     assert len(pubkey) == 64 and isinstance(pubkey, str)
     self.pubkey = pubkey
     if k_id_size == 512:
         self.id = big_endian_to_int(pubkey)
     else:
         assert k_id_size == 256
         self.id = big_endian_to_int(sha3(pubkey))
开发者ID:RomanZacharia,项目名称:pydevp2p,代码行数:8,代码来源:kademlia.py

示例5: account_to_dict

 def account_to_dict(self, address, with_storage_root=False,
                     with_storage=True, for_vmtest=False):
     if with_storage_root:
         assert len(self.journal) == 0
     med_dict = {}
     for i, val in enumerate(self.get_acct(address)):
         name, typ, default = acct_structure[i]
         key = acct_structure[i][0]
         if name == 'storage':
             strie = trie.Trie(self.db, val)
             if with_storage_root:
                 med_dict['storage_root'] = strie.get_root_hash().encode('hex')
         else:
             med_dict[key] = utils.printers[typ](self.caches[key].get(address, val))
     if with_storage:
         med_dict['storage'] = {}
         d = strie.to_dict()
         subcache = self.caches.get('storage:' + address, {})
         subkeys = [utils.zpad(utils.coerce_to_bytes(kk), 32) for kk in subcache.keys()]
         for k in d.keys() + subkeys:
             v = d.get(k, None)
             v2 = subcache.get(utils.big_endian_to_int(k), None)
             hexkey = '0x' + utils.zunpad(k).encode('hex')
             if v2 is not None:
                 if v2 != 0:
                     med_dict['storage'][hexkey] = \
                         '0x' + utils.int_to_big_endian(v2).encode('hex')
             elif v is not None:
                 med_dict['storage'][hexkey] = '0x' + rlp.decode(v).encode('hex')
     return med_dict
开发者ID:ckeenan,项目名称:pyethereum,代码行数:30,代码来源:blocks.py

示例6: check_header_pow

def check_header_pow(header):
    assert len(header[-1]) == 32
    rlp_Hn = rlp.encode(header[:-1])
    nonce = header[-1]
    diff = utils.decoders['int'](header[block_structure_rev['difficulty'][0]])
    h = utils.sha3(utils.sha3(rlp_Hn) + nonce)
    return utils.big_endian_to_int(h) < 2 ** 256 / diff
开发者ID:qualiabyte,项目名称:pyethereum,代码行数:7,代码来源:blocks.py

示例7: 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(utils.big_endian_to_int(arr[i:i + 32]))
    return o
开发者ID:prodigeni,项目名称:pyethereum,代码行数:7,代码来源:processblock.py

示例8: check_proof_of_work

 def check_proof_of_work(self, nonce):
     assert len(nonce) == 32
     rlp_Hn = self.serialize_header_without_nonce()
     # BE(SHA3(SHA3(RLP(Hn)) o n))
     h = utils.sha3(utils.sha3(rlp_Hn) + nonce)
     l256 = utils.big_endian_to_int(h)
     return l256 < 2 ** 256 / self.difficulty
开发者ID:etc255,项目名称:pyethereum,代码行数:7,代码来源:blocks.py

示例9: mine

    def mine(self, steps=1000):
        """
        It is formally defined as PoW: PoW(H, n) = BE(SHA3(SHA3(RLP(Hn)) o n))
        where:
        RLP(Hn) is the RLP encoding of the block header H, not including the
            final nonce component;
        SHA3 is the SHA3 hash function accepting an arbitrary length series of
            bytes and evaluating to a series of 32 bytes (i.e. 256-bit);
        n is the nonce, a series of 32 bytes;
        o is the series concatenation operator;
        BE(X) evaluates to the value equal to X when interpreted as a
            big-endian-encoded integer.
        """

        nonce_bin_prefix = '\x00' * (32 - len(struct.pack('>q', 0)))
        target = 2 ** 256 / self.block.difficulty
        rlp_Hn = self.block.serialize_header_without_nonce()

        for nonce in range(self.nonce, self.nonce + steps):
            nonce_bin = nonce_bin_prefix + struct.pack('>q', nonce)
            # BE(SHA3(SHA3(RLP(Hn)) o n))
            h = utils.sha3(utils.sha3(rlp_Hn) + nonce_bin)
            l256 = utils.big_endian_to_int(h)
            if l256 < target:
                self.block.nonce = nonce_bin
                assert self.block.check_proof_of_work(self.block.nonce) is True
                assert self.block.get_parent()
                logger.debug(
                    'Nonce found %d %r', nonce, self.block)
                return self.block

        self.nonce = nonce
        return False
开发者ID:VIAAC,项目名称:pyethereum,代码行数:33,代码来源:chainmanager.py

示例10: account_to_dict

 def account_to_dict(self, address, with_storage_root=False):
     if with_storage_root:
         assert len(self.journal) == 0
     med_dict = {}
     for i, val in enumerate(self.get_acct(address)):
         name, typ, default = acct_structure[i]
         key = acct_structure[i][0]
         if name == 'storage':
             strie = trie.Trie(utils.get_db_path(), val)
             if with_storage_root:
                 med_dict['storage_root'] = strie.get_root_hash().encode('hex')
         else:
             med_dict[key] = self.caches[key].get(address, utils.printers[typ](val))
     med_dict['storage'] = {}
     d = strie.to_dict()
     for k in d.keys() + self.caches['all'].keys():
         v = d.get(k, None)
         subcache = self.caches.get('storage:'+address, {})
         v2 = subcache.get(utils.big_endian_to_int(k), None)
         hexkey = '0x'+k.encode('hex')
         if v2 is not None:
             if v2 != 0:
                 med_dict['storage'][hexkey] = '0x'+utils.int_to_big_endian(v2).encode('hex')
         elif v is not None:
             med_dict['storage'][hexkey] = '0x'+rlp.decode(v).encode('hex')
     return med_dict
开发者ID:qualiabyte,项目名称:pyethereum,代码行数:26,代码来源:blocks.py

示例11: get_storage_data

 def get_storage_data(self, address, index):
     CACHE_KEY = 'storage:'+address
     if CACHE_KEY in self.caches:
         if index in self.caches[CACHE_KEY]:
             return self.caches[CACHE_KEY][index]
     key = utils.zpad(utils.coerce_to_bytes(index), 32)
     val = rlp.decode(self.get_storage(address).get(key))
     return utils.big_endian_to_int(val) if val else 0
开发者ID:ckeenan,项目名称:pyethereum,代码行数:8,代码来源:blocks.py

示例12: get_storage_data

 def get_storage_data(self, address, index):
     if address in self.caches['storage']:
         if index in self.caches['storage'][address]:
             return self.caches['storage'][address][index]
     t = self.get_storage(address)
     key = utils.zpad(utils.coerce_to_bytes(index), 32)
     val = rlp.decode(t.get(key))
     return utils.big_endian_to_int(val) if val else 0
开发者ID:andregoiano,项目名称:pyethereum,代码行数:8,代码来源:blocks.py

示例13: next

def next(data, pos):
    fchar = ord(data[pos])
    if fchar < 128:
        return pos + 1
    elif (fchar % 64) < 56:
        return pos + 1 + (fchar % 64)
    else:
        b = (fchar % 64) - 55
        b2 = big_endian_to_int(data[pos + 1:pos + 1 + b])
        return pos + 1 + b + b2
开发者ID:zancas,项目名称:pyethereum,代码行数:10,代码来源:rlp.py

示例14: get_storage_data

 def get_storage_data(self, address, index):
     if 'storage:'+address in self.caches:
         if index in self.caches['storage:'+address]:
             return self.caches['storage:'+address][index]
     t = self.get_storage(address)
     t.proof_mode = self.proof_mode
     t.proof_nodes = self.proof_nodes
     key = utils.zpad(utils.coerce_to_bytes(index), 32)
     val = rlp.decode(t.get(key))
     if self.proof_mode == RECORDING:
         self.proof_nodes.extend(t.proof_nodes)
     return utils.big_endian_to_int(val) if val else 0
开发者ID:qualiabyte,项目名称:pyethereum,代码行数:12,代码来源:blocks.py

示例15: dec

def dec(typ, arg):
    base, sub, arrlist = typ
    sz = get_size(typ)
    # Dynamic-sized strings are encoded as <len(str)> + <str>
    if base in ('string', 'bytes') and not sub:
        L = big_endian_to_int(arg[:32])
        assert len(arg[32:]) == ceil32(L), "Wrong data size for string/bytes object"
        return arg[32:][:L]
    # Dynamic-sized arrays
    elif sz is None:
        L = big_endian_to_int(arg[:32])
        subtyp = base, sub, arrlist[:-1]
        subsize = get_size(subtyp)
        # If children are dynamic, use the head/tail mechanism. Fortunately,
        # here the code is simpler since we do not have to worry about
        # mixed dynamic and static children, as we do in the top-level multi-arg
        # case
        if subsize is None:
            assert len(arg) >= 32 + 32 * L, "Not enough data for head"
            start_positions = [big_endian_to_int(arg[32 + 32 * i: 64 + 32 * i])
                               for i in range(L)] + [len(arg)]
            outs = [arg[start_positions[i]: start_positions[i + 1]]
                    for i in range(L)]
            return [dec(subtyp, out) for out in outs]
        # If children are static, then grab the data slice for each one and
        # sequentially decode them manually
        else:
            return [dec(subtyp, arg[32 + subsize * i: 32 + subsize * (i + 1)])
                    for i in range(L)]
    # Static-sized arrays: decode piece-by-piece
    elif len(arrlist):
        L = arrlist[-1][0]
        subtyp = base, sub, arrlist[:-1]
        subsize = get_size(subtyp)
        return [dec(subtyp, arg[subsize * i:subsize * (i + 1)])
                for i in range(L)]
    else:
        return decode_single(typ, arg)
开发者ID:shiftcurrency,项目名称:phantom,代码行数:38,代码来源:abi.py


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