eth2.0-specs/test_libs/pyspec/eth2spec/test/helpers/voluntary_exits.py

25 lines
752 B
Python
Raw Normal View History

2019-05-15 16:36:32 +00:00
from eth2spec.utils.bls import bls_sign
2019-05-31 23:51:09 +00:00
from eth2spec.utils.ssz.ssz_impl import signing_root
2019-05-15 16:36:32 +00:00
2019-05-30 20:57:18 +00:00
def build_voluntary_exit(spec, state, epoch, validator_index, privkey, signed=False):
voluntary_exit = spec.VoluntaryExit(
2019-05-15 16:36:32 +00:00
epoch=epoch,
validator_index=validator_index,
)
2019-05-15 17:31:02 +00:00
if signed:
2019-05-30 20:57:18 +00:00
sign_voluntary_exit(spec, state, voluntary_exit, privkey)
2019-05-15 17:31:02 +00:00
return voluntary_exit
2019-05-30 20:57:18 +00:00
def sign_voluntary_exit(spec, state, voluntary_exit, privkey):
2019-05-15 16:36:32 +00:00
voluntary_exit.signature = bls_sign(
message_hash=signing_root(voluntary_exit),
privkey=privkey,
2019-05-30 20:57:18 +00:00
domain=spec.get_domain(
2019-05-15 16:36:32 +00:00
state=state,
domain_type=spec.DOMAIN_VOLUNTARY_EXIT,
2019-05-15 17:31:02 +00:00
message_epoch=voluntary_exit.epoch,
2019-05-15 16:36:32 +00:00
)
)