[英]How to use index in python list?
I am trying to execute the code of pyethereum but when I was analyzing the code in pyethereum/Ethereum/hybrid_casper/consenus.py
我正在尝试执行pyethereum的代码,但是当我分析
pyethereum/Ethereum/hybrid_casper/consenus.py
的代码时
I can't understand where the 'NULL_SENDER'
value is defined and how this state.config['NULL_SENDER]
will execute. 我不知道在哪里定义
'NULL_SENDER'
值以及此state.config['NULL_SENDER]
将如何执行。
key, account = state.config['NULL_SENDER'], privtoaddr(state.config['NULL_SENDER'])
Let's look through all the code. 让我们浏览所有代码。
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"])
We can see that this code is most likely being imported by multiple programs, which it is! 我们可以看到,此代码很可能是由多个程序导入的! https://github.com/ethereum/pyethereum/blob/develop/ethereum/hybrid_casper/chain.py
https://github.com/ethereum/pyethereum/blob/develop/ethereum/hybrid_casper/chain.py
If we see the usage of the function in chain.py, the state
parameter is being fulfilled with self.state
, it is self.state = self.mk_poststate_of_blockhash(self.db.get(b'head_hash'))
. 如果在chain.py中看到该函数的用法,则
state
参数将通过self.state
来实现,即为self.state = self.mk_poststate_of_blockhash(self.db.get(b'head_hash'))
。
This function returns a State
object, made in ethereum.state
, which can be turned into a dictionary. 此函数返回在
ethereum.state
中ethereum.state
的State
对象,该对象可以转换为字典。 This most likely means that it is getting the value that corresponds to the key called 'NULL_SENDER'. 这很可能意味着它正在获取与名为“ NULL_SENDER”的键相对应的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.