本文整理匯總了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
}
示例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
示例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)
示例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
示例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))
示例6: to_hex
# 需要導入模塊: from rlp import utils [as 別名]
# 或者: from rlp.utils import encode_hex [as 別名]
def to_hex(value):
return '0x' + encode_hex(value)
示例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
示例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()
示例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
示例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)]
示例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!")
示例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))
示例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))
示例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
示例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