2020-06-12 16:43:20 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
2020-02-07 07:13:38 +00:00
|
|
|
import
|
2020-06-12 16:43:20 +00:00
|
|
|
os, strformat, chronicles,
|
2020-06-03 13:52:02 +00:00
|
|
|
ssz/ssz_serialization,
|
2020-02-07 07:13:38 +00:00
|
|
|
beacon_node_types,
|
|
|
|
./spec/[crypto, datatypes, digest]
|
|
|
|
|
2020-06-12 16:43:20 +00:00
|
|
|
# Dump errors are generally not fatal where used currently - the code calling
|
|
|
|
# these functions, like most code, is not exception safe
|
|
|
|
template logErrors(body: untyped) =
|
|
|
|
try:
|
|
|
|
body
|
|
|
|
except CatchableError as err:
|
|
|
|
notice "Failed to write SSZ", dir, msg = err.msg
|
|
|
|
|
2020-02-07 07:13:38 +00:00
|
|
|
proc dump*(dir: string, v: AttestationData, validator: ValidatorPubKey) =
|
2020-06-12 16:43:20 +00:00
|
|
|
logErrors:
|
|
|
|
SSZ.saveFile(dir / &"att-{v.slot}-{v.index}-{shortLog(validator)}.ssz", v)
|
2020-02-07 07:13:38 +00:00
|
|
|
|
2020-05-11 18:08:52 +00:00
|
|
|
proc dump*(dir: string, v: SignedBeaconBlock, root: Eth2Digest) =
|
2020-06-12 16:43:20 +00:00
|
|
|
logErrors:
|
|
|
|
SSZ.saveFile(dir / &"block-{v.message.slot}-{shortLog(root)}.ssz", v)
|
2020-05-11 18:08:52 +00:00
|
|
|
|
2020-02-07 07:13:38 +00:00
|
|
|
proc dump*(dir: string, v: SignedBeaconBlock, blck: BlockRef) =
|
2020-05-11 18:08:52 +00:00
|
|
|
dump(dir, v, blck.root)
|
2020-02-07 07:13:38 +00:00
|
|
|
|
|
|
|
proc dump*(dir: string, v: HashedBeaconState, blck: BlockRef) =
|
2020-06-12 16:43:20 +00:00
|
|
|
logErrors:
|
|
|
|
SSZ.saveFile(
|
|
|
|
dir / &"state-{v.data.slot}-{shortLog(blck.root)}-{shortLog(v.root)}.ssz",
|
|
|
|
v.data)
|
2020-05-11 18:08:52 +00:00
|
|
|
|
2020-06-06 11:26:19 +00:00
|
|
|
proc dump*(dir: string, v: HashedBeaconState) =
|
2020-06-12 16:43:20 +00:00
|
|
|
logErrors:
|
|
|
|
SSZ.saveFile(
|
|
|
|
dir / &"state-{v.data.slot}-{shortLog(v.root)}.ssz",
|
|
|
|
v.data)
|