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


Python utils.sha3方法代码示例

本文整理汇总了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 
开发者ID:gnosis,项目名称:django-eth-events,代码行数:23,代码来源:decoder.py

示例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 
开发者ID:pipermerriam,项目名称:eth-testrpc,代码行数:23,代码来源:test_call.py

示例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 
开发者ID:ethereum,项目名称:research,代码行数:26,代码来源:new_bintrie.py

示例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]) 
开发者ID:omgnetwork,项目名称:plasma-mvp,代码行数:18,代码来源:fixed_merkle.py

示例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 
开发者ID:omgnetwork,项目名称:plasma-mvp,代码行数:18,代码来源:fixed_merkle.py

示例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 
开发者ID:omgnetwork,项目名称:plasma-mvp,代码行数:21,代码来源:test_fixed_merkle.py

示例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') 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:7,代码来源:ethereum_processor.py

示例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} 
开发者ID:KyberNetwork,项目名称:exchange-simulator,代码行数:8,代码来源:fake_dev_chain_wrapper.py

示例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))

# 
开发者ID:KyberNetwork,项目名称:exchange-simulator,代码行数:6,代码来源:web3_interface.py

示例10: mk_privkey

# 需要导入模块: from ethereum import utils [as 别名]
# 或者: from ethereum.utils import sha3 [as 别名]
def mk_privkey(seed):
    return sha3(seed) 
开发者ID:heikoheiko,项目名称:pyethapp,代码行数:4,代码来源:accounts.py

示例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') 
开发者ID:gnosis,项目名称:django-eth-events,代码行数:11,代码来源:decoder.py

示例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 
开发者ID:pipermerriam,项目名称:eth-testrpc,代码行数:32,代码来源:test_eth_call.py

示例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
################################## 
开发者ID:thoschm,项目名称:START-Summit-2017-Blockchain-Machine-Learning-Workshop,代码行数:13,代码来源:user.py

示例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]) 
开发者ID:ethereum,项目名称:research,代码行数:7,代码来源:simple_casper_tester.py

示例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]) 
开发者ID:ethereum,项目名称:research,代码行数:7,代码来源:simple_casper_tester.py


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