gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 21:23:41 26 4
gpt4 key购买 nike

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

我不明白'NULL_SENDER'在哪里值是如何定义的 state.config['NULL_SENDER]将执行。

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

最佳答案

让我们看一下所有代码。

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”的键对应的值。

关于python - 如何在Python列表中使用索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54013570/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com