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


Python utils.encode_hex方法代码示例

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


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

示例1: run_abi_test

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import encode_hex [as 别名]
def run_abi_test(params, mode):
    types, args = params['types'], params['args']
    out = abi.encode_abi(types, args)
    assert abi.decode_abi(types, out) == args
    if mode == FILL:
        params['result'] = encode_hex(out)
        return params
    elif mode == VERIFY:
        assert params['result'] == encode_hex(out)
    elif mode == TIME:
        x = time.time()
        abi.encode_abi(types, args)
        y = time.time()
        abi.decode_abi(out, args)
        return {
            'encoding': y - x,
            'decoding': time.time() - y
        } 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:20,代码来源:testutils.py

示例2: test_library_from_file

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import encode_hex [as 别名]
def test_library_from_file():
    state = tester.state()
    state.env.config['HOMESTEAD_FORK_BLKNUM'] = 0  # enable CALLCODE opcode

    library = state.abi_contract(
        None,
        path=path.join(CONTRACTS_DIR, 'seven_library.sol'),
        language='solidity',
    )

    libraries = {
        'SevenLibrary': encode_hex(library.address),
    }
    contract = state.abi_contract(
        None,
        path=path.join(CONTRACTS_DIR, 'seven_contract.sol'),
        libraries=libraries,
        language='solidity',
    )

    # pylint: disable=no-member
    assert library.seven() == 7
    assert contract.test() == 7 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:25,代码来源:test_solidity.py

示例3: do_test_bloom

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

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import encode_hex [as 别名]
def chain_difficulty(self):
        """Get the summarized difficulty.

        If the summarized difficulty is not stored in the database, it will be
        calculated recursively and put in the database.
        """
        if self.is_genesis():
            return self.difficulty
        elif b'difficulty:' + encode_hex(self.hash) in self.db:
            encoded = self.db.get(b'difficulty:' + encode_hex(self.hash))
            return utils.decode_int(encoded)
        else:
            o = self.difficulty + self.get_parent().chain_difficulty()
            # o += sum([uncle.difficulty for uncle in self.uncles])
            self.state.db.put_temporarily(
                b'difficulty:' + encode_hex(self.hash), utils.encode_int(o))
            return o 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:19,代码来源:blocks.py

示例5: address

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import encode_hex [as 别名]
def address(self, compressed=True, testnet=False):
        """ Address property that returns the Base58Check
        encoded version of the HASH160.

        Args:
            compressed (bool): Whether or not the compressed key should
               be used.
            testnet (bool): Whether or not the key is intended for testnet
               usage. False indicates mainnet usage.

        Returns:
            bytes: Base58Check encoded string
        """
        version = '0x'
        return version + encode_hex(self.keccak[12:])
        # Put the version byte in front, 0x00 for Mainnet, 0x6F for testnet
        # version = bytes([self.TESTNET_VERSION]) if testnet else bytes([self.MAINNET_VERSION])
        # return base58.b58encode_check(version + self.hash160(compressed)) 
开发者ID:michailbrynard,项目名称:ethereum-bip44-python,代码行数:20,代码来源:crypto.py

示例6: to_hex

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import encode_hex [as 别名]
def to_hex(value):
    return '0x' + encode_hex(value) 
开发者ID:davebryson,项目名称:py-tendermint,代码行数:4,代码来源:utils.py

示例7: mktest

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import encode_hex [as 别名]
def mktest(code, language, data=None, fun=None, args=None,
           gas=1000000, value=0, test_type=VM):
    s = t.state(1)
    if language == 'evm':
        ca = s.contract('x = 5')
        s.block.set_code(ca, code)
        d = data or b''
    else:
        c = s.abi_contract(code, language=language)
        d = c._translator.encode(fun, args) if fun else (data or b'')
        ca = c.address
    pre = s.block.to_dict(True)['state']
    if test_type == VM:
        exek = {"address": ca, "caller": t.a0,
                "code": b'0x' + encode_hex(s.block.get_code(ca)),
                "data": b'0x' + encode_hex(d), "gas": to_string(gas),
                "gasPrice": to_string(1), "origin": t.a0,
                "value": to_string(value)}
        return fill_vm_test({"env": env, "pre": pre, "exec": exek})
    else:
        tx = {"data": b'0x' + encode_hex(d), "gasLimit": parse_int_or_hex(gas),
              "gasPrice": to_string(1), "nonce": to_string(s.block.get_nonce(t.a0)),
              "secretKey": encode_hex(t.k0), "to": ca, "value": to_string(value)}
        return fill_state_test({"env": env, "pre": pre, "transaction": tx})


# Fills up a vm test without post data, or runs the test 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:29,代码来源:testutils.py

示例8: __init__

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import encode_hex [as 别名]
def __init__(self, env, genesis=None, new_head_cb=None, coinbase=b'\x00' * 20):
        assert isinstance(env, Env)
        self.env = env
        self.db = self.blockchain = env.db
        self.new_head_cb = new_head_cb
        self.index = Index(self.env)
        self._coinbase = coinbase
        if 'HEAD' not in self.db:
            self._initialize_blockchain(genesis)
        log.debug('chain @', head_hash=self.head)
        self.genesis = self.get(self.index.get_block_by_number(0))
        log.debug('got genesis', nonce=encode_hex(self.genesis.nonce),
                  difficulty=self.genesis.difficulty)
        self._update_head_candidate() 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:16,代码来源:chain.py

示例9: decode_int

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import encode_hex [as 别名]
def decode_int(s):
    return int(encode_hex(s[::-1]), 16) if s else 0 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:4,代码来源:ethash_utils.py

示例10: bin_to_nibbles

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import encode_hex [as 别名]
def bin_to_nibbles(s):
    """convert string s to nibbles (half-bytes)

    >>> bin_to_nibbles("")
    []
    >>> bin_to_nibbles("h")
    [6, 8]
    >>> bin_to_nibbles("he")
    [6, 8, 6, 5]
    >>> bin_to_nibbles("hello")
    [6, 8, 6, 5, 6, 12, 6, 12, 6, 15]
    """
    return [hti[c] for c in encode_hex(s)] 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:15,代码来源:pruning_trie.py

示例11: spv_grabbing

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import encode_hex [as 别名]
def spv_grabbing(self, node):
        global proving
        if not proving:
            pass
        elif proof.get_mode() == RECORDING:
            proof.add_node(copy.copy(node))
            # print('recording %s' % encode_hex(utils.sha3(rlp_encode(node))))
        elif proof.get_mode() == VERIFYING:
            # print('verifying %s' % encode_hex(utils.sha3(rlp_encode(node))))
            if rlp_encode(node) not in proof.get_nodes():
                raise InvalidSPVProof("Proof invalid!") 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:13,代码来源:pruning_trie.py

示例12: replace_root_hash

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import encode_hex [as 别名]
def replace_root_hash(self, old_node, new_node):
        # sys.stderr.write('rrh %r %r\n' % (old_node, new_node))
        self._delete_node_storage(old_node, is_root=True)
        self._encode_node(new_node, is_root=True)
        self.root_node = new_node
        # sys.stderr.write('nrh: %s\n' % encode_hex(self.root_hash)) 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:8,代码来源:pruning_trie.py

示例13: encode_node

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import encode_hex [as 别名]
def encode_node(nd):
        if is_string(nd):
            return encode_hex(nd)
        else:
            return encode_hex(rlp_encode(nd)) 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:7,代码来源:pruning_trie.py

示例14: mk_scrypt_params

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import encode_hex [as 别名]
def mk_scrypt_params():
    params = SCRYPT_CONSTANTS.copy()
    params['salt'] = encode_hex(os.urandom(16))
    return params 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:6,代码来源:keys.py

示例15: mk_pbkdf2_params

# 需要导入模块: from rlp import utils [as 别名]
# 或者: from rlp.utils import encode_hex [as 别名]
def mk_pbkdf2_params():
    params = PBKDF2_CONSTANTS.copy()
    params['salt'] = encode_hex(os.urandom(16))
    return params 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:6,代码来源:keys.py


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