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

Python utils.big_endian_to_int函数代码示例

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

本文整理汇总了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函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: decode_abi

def decode_abi(types, data):
    # Process types
    proctypes = [process_type(typ) for typ in types]
    # Get sizes of everything
    sizes = [get_size(typ) for typ in proctypes]
    # Initialize array of outputs
    outs = [None] * len(types)
    # Initialize array of start positions
    start_positions = [None] * len(types) + [len(data)]
    # If a type is static, grab the data directly, otherwise record
    # its start position
    pos = 0
    for i, typ in enumerate(types):
        if sizes[i] is None:
            start_positions[i] = big_endian_to_int(data[pos:pos + 32])
            j = i - 1
            while j >= 0 and start_positions[j] is None:
                start_positions[j] = start_positions[i]
                j -= 1
            pos += 32
        else:
            outs[i] = data[pos:pos + sizes[i]]
            pos += sizes[i]
    # We add a start position equal to the length of the entire data
    # for convenience.
    j = len(types) - 1
    while j >= 0 and start_positions[j] is None:
        start_positions[j] = start_positions[len(types)]
        j -= 1
    assert pos <= len(data), "Not enough data for head"
    # Grab the data for tail arguments using the start positions
    # calculated above
    for i, typ in enumerate(types):
        if sizes[i] is None:
            offset = start_positions[i]
            next_offset = start_positions[i + 1]
            outs[i] = data[offset:next_offset]
    # Recursively decode them all
    return [dec(proctypes[i], outs[i]) for i in range(len(outs))]
开发者ID:shiftcurrency,项目名称:phantom,代码行数:39,代码来源:abi.py


示例17: 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"] = {}
     for k, v in strie.to_dict().iteritems():
         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:
             med_dict["storage"][hexkey] = "0x" + utils.int_to_big_endian(v2).encode("hex")
         else:
             med_dict["storage"][hexkey] = "0x" + v.encode("hex")
     return med_dict
开发者ID:miro-blakeley,项目名称:pyethereum,代码行数:23,代码来源:blocks.py


示例18: decint

def decint(n, signed=False):
    if isinstance(n, str):
        n = utils.to_string(n)

    if is_numeric(n):
        min_, max_ = (-TT255, TT255 - 1) if signed else (0, TT256 - 1)
        if n > max_ or n < min_:
            raise EncodingError("Number out of range: %r" % n)
        return n
    elif is_string(n):
        if len(n) == 40:
            n = decode_hex(n)
        if len(n) > 32:
            raise EncodingError("String too long: %r" % n)

        i = big_endian_to_int(n)
        return (i - TT256) if signed and i >= TT255 else i
    elif n is True:
        return 1
    elif n is False or n is None:
        return 0
    else:
        raise EncodingError("Cannot encode integer: %r" % n)
开发者ID:shiftcurrency,项目名称:phantom,代码行数:23,代码来源:abi.py


示例19: event_id

def event_id(name, encode_types):
    """ Return the event id.

    Defined as:

        `keccak(EVENT_NAME+"("+EVENT_ARGS.map(canonical_type_of).join(",")+")")`

    Where `canonical_type_of` is a function that simply returns the canonical
    type of a given argument, e.g. for uint indexed foo, it would return
    uint256). Note the lack of spaces.
    """

    event_types = [
        _canonical_name(type_)
        for type_ in encode_types
    ]

    event_signature = '{event_name}({canonical_types})'.format(
        event_name=name,
        canonical_types=','.join(event_types),
    )

    return big_endian_to_int(utils.sha3(event_signature))
开发者ID:shiftcurrency,项目名称:phantom,代码行数:23,代码来源:abi.py


示例20: method_id

def method_id(name, encode_types):
    """ Return the unique method id.

    The signature is defined as the canonical expression of the basic
    prototype, i.e. the function name with the parenthesised list of parameter
    types. Parameter types are split by a single comma - no spaces are used.

    The method id is defined as the first four bytes (left, high-order in
    big-endian) of the Keccak (SHA-3) hash of the signature of the function.
    """
    function_types = [
        _canonical_name(type_)
        for type_ in encode_types
    ]

    function_signature = '{function_name}({canonical_types})'.format(
        function_name=name,
        canonical_types=','.join(function_types),
    )

    function_keccak = utils.sha3(function_signature)
    first_bytes = function_keccak[:4]

    return big_endian_to_int(first_bytes)
开发者ID:shiftcurrency,项目名称:phantom,代码行数:24,代码来源:abi.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utils.blender函数代码示例发布时间:2022-05-26
下一篇:
Python utils.bbox2str函数代码示例发布时间: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