2019-05-15 16:36:32 +00:00
|
|
|
# Access constants from spec pkg reference.
|
|
|
|
import eth2spec.phase0.spec as spec
|
|
|
|
|
2019-05-27 17:09:52 +00:00
|
|
|
from eth2spec.phase0.spec import process_slots
|
2019-05-15 16:36:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_balance(state, index):
|
|
|
|
return state.balances[index]
|
|
|
|
|
|
|
|
|
|
|
|
def next_slot(state):
|
|
|
|
"""
|
|
|
|
Transition to the next slot.
|
|
|
|
"""
|
2019-05-27 17:09:52 +00:00
|
|
|
process_slots(state, state.slot + 1)
|
2019-05-15 16:36:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def next_epoch(state):
|
|
|
|
"""
|
|
|
|
Transition to the start slot of the next epoch
|
|
|
|
"""
|
|
|
|
slot = state.slot + spec.SLOTS_PER_EPOCH - (state.slot % spec.SLOTS_PER_EPOCH)
|
2019-05-27 17:09:52 +00:00
|
|
|
process_slots(state, slot)
|
2019-05-15 16:36:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_state_root(state, slot) -> bytes:
|
|
|
|
"""
|
|
|
|
Return the state root at a recent ``slot``.
|
|
|
|
"""
|
|
|
|
assert slot < state.slot <= slot + spec.SLOTS_PER_HISTORICAL_ROOT
|
|
|
|
return state.latest_state_roots[slot % spec.SLOTS_PER_HISTORICAL_ROOT]
|