首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在python列表中使用索引?

如何在python列表中使用索引?
EN

Stack Overflow用户
提问于 2019-01-03 05:45:56
回答 1查看 76关注 0票数 1

我正在尝试执行pyethereum的代码,但是当我在pyethereum/Ethereum/hybrid_casper/consenus.py中分析代码时

我不能理解'NULL_SENDER'的值是在哪里定义的,以及这个state.config['NULL_SENDER]将如何执行。

key, account = state.config['NULL_SENDER'], privtoaddr(state.config['NULL_SENDER'])

EN

回答 1

Stack Overflow用户

发布于 2019-01-03 10:22:07

让我们看一看所有的代码。

代码语言:javascript
复制
from ethereum import utils, transactions
from ethereum.common import update_block_env_variables
from ethereum.messages import apply_transaction
from ethereum.hybrid_casper import casper_utils
from ethereum.utils import privtoaddr

# Block initialization state transition
def initialize(state, block=None):
    config = state.config

    state.txindex = 0
    state.gas_used = 0
    state.bloom = 0
    state.receipts = []

    if block is not None:
        update_block_env_variables(state, block)

    # Initalize the next epoch in the Casper contract
    if state.block_number % state.config['EPOCH_LENGTH'] == 0 and state.block_number != 0:
        key, account = state.config['NULL_SENDER'], privtoaddr(state.config['NULL_SENDER'])
        data = casper_utils.casper_translator.encode('initialize_epoch', [state.block_number // state.config['EPOCH_LENGTH']])
        transaction = transactions.Transaction(state.get_nonce(account), 0, 3141592,
                                               state.config['CASPER_ADDRESS'], 0, data).sign(key)
        success, output = apply_transaction(state, transaction)
        assert success

    if state.is_DAO(at_fork_height=True):
        for acct in state.config['CHILD_DAO_LIST']:
            state.transfer_value(
                acct,
                state.config['DAO_WITHDRAWER'],
                state.get_balance(acct))

    if state.is_METROPOLIS(at_fork_height=True):
        state.set_code(utils.normalize_address(
            config["METROPOLIS_STATEROOT_STORE"]), config["METROPOLIS_GETTER_CODE"])
        state.set_code(utils.normalize_address(
            config["METROPOLIS_BLOCKHASH_STORE"]), config["METROPOLIS_GETTER_CODE"])

我们可以看到,这段代码很可能是由多个程序导入的,确实如此!https://github.com/ethereum/pyethereum/blob/develop/ethereum/hybrid_casper/chain.py

如果我们在chain.py中看到函数的用法,那么state参数是用self.state实现的,它是self.state = self.mk_poststate_of_blockhash(self.db.get(b'head_hash'))

此函数返回一个在ethereum.state中创建的State对象,可以将该对象转换为字典。这很可能意味着它正在获取与名为'NULL_SENDER‘的键相对应的值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54013570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档