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


Python utils.decode_hex方法代码示例

本文整理汇总了Python中rlp.utils.decode_hex方法的典型用法代码示例。如果您正苦于以下问题:Python utils.decode_hex方法的具体用法?Python utils.decode_hex怎么用?Python utils.decode_hex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rlp.utils的用法示例。


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

示例1: pbkdf2_hash

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
def pbkdf2_hash(val, params):
    assert params["prf"] == "hmac-sha256"
    return pbkdf2.PBKDF2(val, decode_hex(params["salt"]), params["c"],
                         SHA256).read(params["dklen"]) 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:6,代码来源:keys.py

示例2: solc_parse_output

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
def solc_parse_output(compiler_output):
    """ Parses the compiler output. """
    result = yaml.safe_load(compiler_output)['contracts']

    if 'bin' in tuple(result.values())[0]:
        for value in result.values():
            value['bin_hex'] = value['bin']

            # decoding can fail if the compiled contract has unresolved symbols
            try:
                value['bin'] = decode_hex(value['bin_hex'])
            except TypeError:
                pass

    for json_data in ('abi', 'devdoc', 'userdoc'):
        # the values in the output can be configured through the
        # --combined-json flag, check that it's present in the first value and
        # assume all values are consistent
        if json_data not in tuple(result.values())[0]:
            continue

        for value in result.values():
            value[json_data] = yaml.safe_load(value[json_data])

    return result 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:27,代码来源:_solidity.py

示例3: do_test_bloom

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
def do_test_bloom(test_logs):
    """
    The logs sections is a mapping between the blooms and their corresponding logentries.
    Each logentry has the format:
    address: The address of the logentry.
    data: The data of the logentry.
    topics: The topics of the logentry, given as an array of values.
    """
    for data in test_logs:
        address = data['address']
        # Test via bloom
        b = bloom.bloom_insert(0, decode_hex(address))
        for t in data['topics']:
            b = bloom.bloom_insert(b, decode_hex(t))
        # Test via Log
        topics = [decode_int_from_hex(x) for x in data['topics']]
        log = pb.Log(decode_hex(address), topics, '')
        log_bloom = bloom.b64(bloom.bloom_from_list(log.bloomables()))
        assert encode_hex(log_bloom) == encode_hex_from_int(b)
        assert str_to_bytes(data['bloom']) == encode_hex(log_bloom) 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:22,代码来源:test_bloom.py

示例4: solidity_resolve_address

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
def solidity_resolve_address(hex_code, library_symbol, library_address):
    """ Change the bytecode to use the given library address.

    Args:
        hex_code (bin): The bytecode encoded in hexadecimal.
        library_name (str): The library that will be resolved.
        library_address (str): The address of the library.

    Returns:
        bin: The bytecode encoded in hexadecimal with the library references
            resolved.
    """
    if library_address.startswith('0x'):
        raise ValueError('Address should not contain the 0x prefix')

    try:
        _ = decode_hex(library_address)
    except TypeError:
        raise ValueError('library_address contains invalid characters, it must be hex encoded.')

    if len(library_symbol) != 40 or len(library_address) != 40:
        raise ValueError('Address with wrong length')

    return hex_code.replace(library_symbol, library_address) 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:26,代码来源:_solidity.py

示例5: __init__

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
def __init__(self,
                 prevhash=default_config['GENESIS_PREVHASH'],
                 uncles_hash=utils.sha3rlp([]),
                 coinbase=default_config['GENESIS_COINBASE'],
                 state_root=trie.BLANK_ROOT,
                 tx_list_root=trie.BLANK_ROOT,
                 receipts_root=trie.BLANK_ROOT,
                 bloom=0,
                 difficulty=default_config['GENESIS_DIFFICULTY'],
                 number=0,
                 gas_limit=default_config['GENESIS_GAS_LIMIT'],
                 gas_used=0,
                 timestamp=0,
                 extra_data='',
                 mixhash=default_config['GENESIS_MIXHASH'],
                 nonce=''):
        # at the beginning of a method, locals() is a dict of all arguments
        fields = {k: v for k, v in locals().items() if k != 'self'}
        if len(fields['coinbase']) == 40:
            fields['coinbase'] = decode_hex(fields['coinbase'])
        assert len(fields['coinbase']) == 20
        self.block = None
        super(BlockHeader, self).__init__(**fields) 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:25,代码来源:blocks.py

示例6: _get_acct

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
def _get_acct(self, address):
        """Get the account with the given address.

        Note that this method ignores cached account items.
        """
        if len(address) == 40:
            address = decode_hex(address)
        assert len(address) == 20 or len(address) == 0
        rlpdata = self.state.get(address)
        if rlpdata != trie.BLANK_NODE:
            acct = rlp.decode(rlpdata, Account, db=self.db)
            acct._mutable = True
            acct._cached_rlp = None
        else:
            acct = Account.blank_account(self.db, self.config['ACCOUNT_INITIAL_NONCE'])
        return acct 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:18,代码来源:blocks.py

示例7: _get_acct_item

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
def _get_acct_item(self, address, param):
        """Get a specific parameter of a specific account.

        :param address: the address of the account (binary or hex string)
        :param param: the requested parameter (`'nonce'`, `'balance'`,
                      `'storage'` or `'code'`)
        """
        if len(address) == 40:
            address = decode_hex(address)
        assert len(address) == 20 or len(address) == 0
        if address in self.caches[param]:
            return self.caches[param][address]
        else:
            account = self._get_acct(address)
            o = getattr(account, param)
            self.caches[param][address] = o
            return o 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:19,代码来源:blocks.py

示例8: decint

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
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)

# Encodes a base datum 
开发者ID:mattdf,项目名称:sc-tools,代码行数:27,代码来源:abi.py

示例9: from_hex

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
def from_hex(value):
    v = remove_0x_head(value)
    return decode_hex(v) 
开发者ID:davebryson,项目名称:py-tendermint,代码行数:5,代码来源:utils.py

示例10: get_blocks_from_textdump

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
def get_blocks_from_textdump(data):
    if '\n' not in data:
        r = rlp.decode(decode_hex(data))
        if len(r[0]) != 3:
            blocks = [r]
        else:
            blocks = r
    else:
        blocks = [rlp.decode(decode_hex(ln)) for ln in data.split('\n')]
    return blocks 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:12,代码来源:testutils.py

示例11: encode_int

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
def encode_int(s):
    a = "%x" % s
    return b'' if s == 0 else decode_hex('0' * (len(a) % 2) + a)[::-1] 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:5,代码来源:ethash_utils.py

示例12: aes_ctr_encrypt

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
def aes_ctr_encrypt(text, key, params):
    iv = big_endian_to_int(decode_hex(params["iv"]))
    ctr = Counter.new(128, initial_value=iv,  allow_wraparound=True)
    mode = AES.MODE_CTR
    encryptor = AES.new(key, mode, counter=ctr)
    return encryptor.encrypt(text) 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:8,代码来源:keys.py

示例13: scrypt_hash

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
def scrypt_hash(val, params):
    return scrypt.hash(str(val), decode_hex(params["salt"]), params["n"],
                       params["r"], params["p"], params["dklen"]) 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:5,代码来源:keys.py

示例14: decode_keystore_json

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
def decode_keystore_json(jsondata, pw):
    # Get KDF function and parameters
    if "crypto" in jsondata:
        cryptdata = jsondata["crypto"]
    elif "Crypto" in jsondata:
        cryptdata = jsondata["Crypto"]
    else:
        raise Exception("JSON data must contain \"crypto\" object")
    kdfparams = cryptdata["kdfparams"]
    kdf = cryptdata["kdf"]
    if cryptdata["kdf"] not in kdfs:
        raise Exception("Hash algo %s not supported" % kdf)
    kdfeval = kdfs[kdf]["calc"]
    # Get cipher and parameters
    cipherparams = cryptdata["cipherparams"]
    cipher = cryptdata["cipher"]
    if cryptdata["cipher"] not in ciphers:
        raise Exception("Encryption algo %s not supported" % cipher)
    decrypt = ciphers[cipher]["decrypt"]
    # Compute the derived key
    derivedkey = kdfeval(pw, kdfparams)
    assert len(derivedkey) >= 32, \
        "Derived key must be at least 32 bytes long"
    # print(b'derivedkey: ' + encode_hex(derivedkey))
    enckey = derivedkey[:16]
    # print(b'enckey: ' + encode_hex(enckey))
    ctext = decode_hex(cryptdata["ciphertext"])
    # Decrypt the ciphertext
    o = decrypt(ctext, enckey, cipherparams)
    # Compare the provided MAC with a locally computed MAC
    # print(b'macdata: ' + encode_hex(derivedkey[16:32] + ctext))
    mac1 = sha3(derivedkey[16:32] + ctext)
    mac2 = decode_hex(cryptdata["mac"])
    if mac1 != mac2:
        raise ValueError("MAC mismatch. Password incorrect?")
    return o


# Utility functions (done separately from utils so as to make this a standalone file) 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:41,代码来源:keys.py

示例15: privtoaddr

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import decode_hex [as 别名]
def privtoaddr(x):
    if len(x) > 32:
        x = decode_hex(x)
    return sha3(bitcoin.privtopub(x)[1:])[12:] 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:6,代码来源:keys.py


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