2019-09-09 14:06:29 -05:00
|
|
|
import
|
2020-05-14 13:19:10 +02:00
|
|
|
confutils, os, strutils, json_serialization,
|
2020-04-29 22:12:07 +02:00
|
|
|
stew/byteutils,
|
2019-10-25 12:59:56 +02:00
|
|
|
../beacon_chain/spec/[crypto, datatypes, digest],
|
2020-06-03 15:52:02 +02:00
|
|
|
../beacon_chain/ssz/[merkleization, ssz_serialization]
|
2019-09-09 14:06:29 -05:00
|
|
|
|
|
|
|
# TODO turn into arguments
|
|
|
|
cli do(kind: string, file: string):
|
|
|
|
|
|
|
|
template printit(t: untyped) {.dirty.} =
|
2020-04-29 22:12:07 +02:00
|
|
|
let v = newClone(
|
|
|
|
if cmpIgnoreCase(ext, ".ssz") == 0:
|
|
|
|
SSZ.loadFile(file, t)
|
|
|
|
elif cmpIgnoreCase(ext, ".json") == 0:
|
|
|
|
JSON.loadFile(file, t)
|
|
|
|
else:
|
|
|
|
echo "Unknown file type: ", ext
|
|
|
|
quit 1
|
|
|
|
)
|
2020-06-12 18:43:20 +02:00
|
|
|
when t is SignedBeaconBlock:
|
|
|
|
echo hash_tree_root(v.message).data.toHex()
|
|
|
|
else:
|
|
|
|
echo hash_tree_root(v[]).data.toHex()
|
2019-09-09 14:06:29 -05:00
|
|
|
|
|
|
|
let ext = splitFile(file).ext
|
|
|
|
|
|
|
|
case kind
|
|
|
|
of "attester_slashing": printit(AttesterSlashing)
|
|
|
|
of "attestation": printit(Attestation)
|
2020-06-12 18:43:20 +02:00
|
|
|
of "signed_block": printit(SignedBeaconBlock)
|
2019-09-09 14:06:29 -05:00
|
|
|
of "block": printit(BeaconBlock)
|
|
|
|
of "block_body": printit(BeaconBlockBody)
|
|
|
|
of "block_header": printit(BeaconBlockHeader)
|
|
|
|
of "deposit": printit(Deposit)
|
|
|
|
of "deposit_data": printit(DepositData)
|
|
|
|
of "eth1_data": printit(Eth1Data)
|
2020-04-29 22:12:07 +02:00
|
|
|
of "state": printit(BeaconState)
|
2019-09-09 14:06:29 -05:00
|
|
|
of "proposer_slashing": printit(ProposerSlashing)
|
|
|
|
of "voluntary_exit": printit(VoluntaryExit)
|