當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。