本文整理汇总了Python中ethereum.utils.sha3方法的典型用法代码示例。如果您正苦于以下问题:Python utils.sha3方法的具体用法?Python utils.sha3怎么用?Python utils.sha3使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ethereum.utils
的用法示例。
在下文中一共展示了utils.sha3方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_abi
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def add_abi(self, abi) -> int:
"""
Add ABI array into the decoder collection, in this step the method id is generated from:
sha3(function_name + '(' + param_type1 + ... + param_typeN + ')')
:param abi: Array of dictionaries
:return: Items added
:rtype: int
"""
added = 0
abi_sha3 = sha3(str(abi))
# Check that abi was not processed before
if abi_sha3 not in self.added_abis:
for item in abi:
if item.get('name'):
method_id = self.get_method_id(item)
self.methods[method_id] = item
added += 1
if item.get('type') == 'event':
self.events.add(HexBytes(method_id).hex())
self.added_abis[abi_sha3] = None
return added
示例2: test_eth_call
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def test_eth_call(client, hex_accounts):
txn_hash = client.send_transaction(
_from=hex_accounts[0],
data=CONTRACT_BIN,
value=1234,
)
txn_receipt = client.get_transaction_receipt(txn_hash)
contract_address = txn_receipt['contractAddress']
assert contract_address
function_sig = encode_data(sha3("return13()")[:4])
should_be_13 = client.call(
_from=hex_accounts[0],
to=contract_address,
data=function_sig,
)
result = big_endian_to_int(decode_hex(should_be_13[2:]))
assert result == 13
示例3: update
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def update(db, root, key, value):
v = root
path = path2 = key_to_path(key)
sidenodes = []
for i in range(256):
if (path >> 255) & 1:
sidenodes.append(db.get(v)[:32])
v = db.get(v)[32:]
else:
sidenodes.append(db.get(v)[32:])
v = db.get(v)[:32]
path <<= 1
v = value
for i in range(256):
if (path2 & 1):
newv = sha3(sidenodes[-1] + v)
db.put(newv, sidenodes[-1] + v)
else:
newv = sha3(v + sidenodes[-1])
db.put(newv, v + sidenodes[-1])
path2 >>= 1
v = newv
sidenodes.pop()
return v
示例4: __init__
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def __init__(self, depth, leaves=[], hashed=False):
if depth < 1:
raise ValueError('depth should be at least 1')
self.depth = depth
self.leaf_count = 2 ** depth
self.hashed = hashed
if len(leaves) > self.leaf_count:
raise ValueError('num of leaves exceed max avaiable num with the depth')
if not hashed:
leaves = [sha3(leaf) for leaf in leaves]
self.leaves = leaves + [NULL_HASH] * (self.leaf_count - len(leaves))
self.tree = [self.create_nodes(self.leaves)]
self.create_tree(self.tree[0])
示例5: create_membership_proof
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def create_membership_proof(self, leaf):
if not self.hashed:
leaf = sha3(leaf)
if not self.is_member(leaf):
raise MemberNotExistException('leaf is not in the merkle tree')
index = self.leaves.index(leaf)
proof = b''
for i in range(0, self.depth, 1):
if index % 2 == 0:
sibling_index = index + 1
else:
sibling_index = index - 1
index = index // 2
proof += self.tree[i][sibling_index].data
return proof
示例6: test_check_membership
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def test_check_membership(u):
leaf_1 = b'\xff' * 31 + b'\x01'
leaf_2 = b'\xff' * 31 + b'\x02'
leaf_3 = b'\xff' * 31 + b'\x03'
leaf_4 = b'\xff' * 31 + b'\x04'
root = u.sha3(u.sha3(leaf_1 + leaf_2) + u.sha3(leaf_3 + leaf_4))
zeros_hashes = get_empty_merkle_tree_hash(2)
for i in range(13):
root = u.sha3(root + zeros_hashes[-32:])
zeros_hashes += u.sha3(zeros_hashes[-32:] + zeros_hashes[-32:])
left_proof = leaf_2 + u.sha3(leaf_3 + leaf_4) + zeros_hashes
left_middle_proof = leaf_1 + u.sha3(leaf_3 + leaf_4) + zeros_hashes
right_middle_proof = leaf_4 + u.sha3(leaf_1 + leaf_2) + zeros_hashes
right_proof = leaf_3 + u.sha3(leaf_1 + leaf_2) + zeros_hashes
fixed_merkle = FixedMerkle(16, [leaf_1, leaf_2, leaf_3, leaf_4], True)
assert fixed_merkle.check_membership(leaf_1, 0, left_proof) is True
assert fixed_merkle.check_membership(leaf_2, 1, left_middle_proof) is True
assert fixed_merkle.check_membership(leaf_3, 2, right_middle_proof) is True
assert fixed_merkle.check_membership(leaf_4, 3, right_proof) is True
示例7: decode_private_key
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def decode_private_key(encoded_private_key):
fernet_encryption_key = base64.b64encode(utils.sha3(config.SECRET_KEY))
cipher_suite = Fernet(fernet_encryption_key)
return cipher_suite.decrypt(encoded_private_key.encode('utf-8')).decode('utf-8')
示例8: handle_send_raw_tx
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def handle_send_raw_tx(method_name, params, rpc_version, id, current_timestamp):
global pending_txs
raw_tx = params[0]
tx_hash = b2h(utils.sha3(h2b(raw_tx[2:])))
pending_txs.add(PendingTx(raw_tx, tx_hash, current_timestamp))
return {"id": id, "jsonrpc": rpc_version, "result": tx_hash}
示例9: get_test_private_key
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def get_test_private_key(index):
return utils.sha3("exchange" + str(index))
#
示例10: mk_privkey
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def mk_privkey(seed):
return sha3(seed)
示例11: get_method_id
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def get_method_id(item):
if item.get('inputs'):
# Generate methodID and link it with the abi
method_header = "{}({})".format(item['name'],
','.join(map(lambda method_input: method_input['type'], item['inputs'])))
else:
method_header = "{}()".format(item['name'])
return binascii.hexlify(sha3(method_header)).decode('ascii')
示例12: test_eth_call
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def test_eth_call(rpc_client, accounts):
txn_hash = rpc_client(
method="eth_sendTransaction",
params=[{
"from": accounts[0],
"data": CONTRACT_BIN,
"value": 1234,
}],
)
txn_receipt = rpc_client(
method="eth_getTransactionReceipt",
params=[txn_hash],
)
contract_address = txn_receipt['contractAddress']
assert contract_address
function_sig = encode_data(sha3("return13()")[:4])
should_be_13 = rpc_client(
method="eth_call",
params=[{
"from": accounts[0],
"to": contract_address,
"data": function_sig,
}],
)
result = big_endian_to_int(decode_hex(should_be_13[2:]))
assert result == 13
示例13: decodeABI
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def decodeABI(tinput, sig='setNewUserState(string,bytes,string)'):
abi = tinput[2 :]
hash = utils.sha3(sig)[: 4].encode('hex')
if abi[: 8] != hash:
return None
return decode_abi(['string', 'bytes', 'string'], abi[8 :].decode('hex'))
##################################
# image helper
##################################
示例14: mk_prepare
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def mk_prepare(validator_index, epoch, hash, ancestry_hash, source_epoch, source_ancestry_hash, key):
sighash = utils.sha3(rlp.encode([validator_index, epoch, hash, ancestry_hash, source_epoch, source_ancestry_hash]))
v, r, s = utils.ecdsa_raw_sign(sighash, key)
sig = utils.encode_int32(v) + utils.encode_int32(r) + utils.encode_int32(s)
return rlp.encode([validator_index, epoch, hash, ancestry_hash, source_epoch, source_ancestry_hash, sig])
示例15: mk_commit
# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def mk_commit(validator_index, epoch, hash, prev_commit_epoch, key):
sighash = utils.sha3(rlp.encode([validator_index, epoch, hash, prev_commit_epoch]))
v, r, s = utils.ecdsa_raw_sign(sighash, key)
sig = utils.encode_int32(v) + utils.encode_int32(r) + utils.encode_int32(s)
return rlp.encode([validator_index, epoch, hash, prev_commit_epoch, sig])