Skip to content

Commit c6a73c4

Browse files
committed
Block / REST explorer
1 parent 8b07f4f commit c6a73c4

35 files changed

+1709
-9
lines changed

.gitmodules

+7
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@
199199
path = vendor/nim-toml-serialization
200200
url = https://github.com/status-im/nim-toml-serialization.git
201201
ignore = untracked
202+
[submodule "vendor/DOtherSide"]
203+
path = vendor/DOtherSide
204+
url = https://github.com/filcuc/DOtherSide.git
205+
branch = master
206+
[submodule "vendor/nimqml"]
207+
path = vendor/nimqml
208+
url = https://github.com/status-im/nimqml.git
202209
branch = master
203210
[submodule "vendor/gnosis-chain-configs"]
204211
path = vendor/gnosis-chain-configs

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ force_build_alone_tools: | $(FORCE_BUILD_ALONE_TOOLS_DEPS)
491491
# https://www.gnu.org/software/make/manual/html_node/Multiple-Rules.html#Multiple-Rules
492492
# Already defined as a reult
493493
nimbus_beacon_node: force_build_alone_tools
494+
ngui/ngui: | build deps
495+
+ echo -e $(BUILD_MSG) "build/$@" && \
496+
MAKE="$(MAKE)" V="$(V)" $(ENV_SCRIPT) scripts/compile_nim_program.sh $@ "ngui.ngui.nim" $(NIM_PARAMS) && \
497+
echo -e $(BUILD_END_MSG) "ngui/ngui"
494498

495499
GOERLI_TESTNETS_PARAMS := \
496500
--tcp-port=$$(( $(BASE_PORT) + $(NODE_ID) )) \

beacon_chain/rpc/rest_debug_api.nim

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ proc installDebugApiHandlers*(router: var RestRouter, node: BeaconNode) =
7272
"/eth/v2/debug/beacon/heads") do () -> RestApiResponse:
7373
return RestApiResponse.jsonResponse(
7474
node.dag.heads.mapIt(
75-
(
75+
RestChainHeadV2(
7676
root: it.root,
7777
slot: it.slot,
7878
execution_optimistic: not it.executionValid

beacon_chain/spec/eth2_apis/rest_debug_calls.nim

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import
1313

1414
export chronos, client, rest_types, eth2_rest_serialization
1515

16+
proc getDebugChainHeadsV2*(): RestResponse[GetDebugChainHeadsV2Response] {.
17+
rest, endpoint: "/eth/v2/debug/beacon/heads",
18+
meth: MethodGet.}
19+
## https://ethereum.github.io/beacon-APIs/#/Beacon/getDebugChainHeadsV2
20+
21+
1622
proc getStateV2Plain*(state_id: StateIdent): RestPlainResponse {.
1723
rest, endpoint: "/eth/v2/debug/beacon/states/{state_id}",
1824
accept: preferSSZ,

beacon_chain/spec/eth2_apis/rest_types.nim

+3-2
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,10 @@ type
249249
connected*: uint64
250250
disconnecting*: uint64
251251

252-
RestChainHead* = object
252+
RestChainHeadV2* = object
253253
root*: Eth2Digest
254254
slot*: Slot
255+
execution_optmistic*: bool
255256

256257
RestMetadata* = object
257258
seq_number*: string
@@ -512,7 +513,7 @@ type
512513
GetBlockHeaderResponse* = DataOptimisticObject[RestBlockHeaderInfo]
513514
GetBlockHeadersResponse* = DataEnclosedObject[seq[RestBlockHeaderInfo]]
514515
GetBlockRootResponse* = DataOptimisticObject[RestRoot]
515-
GetDebugChainHeadsResponse* = DataEnclosedObject[seq[RestChainHead]]
516+
GetDebugChainHeadsV2Response* = DataEnclosedObject[seq[RestChainHeadV2]]
516517
GetDepositContractResponse* = DataEnclosedObject[RestDepositContract]
517518
GetDepositSnapshotResponse* = DataEnclosedObject[RestDepositSnapshot]
518519
GetEpochCommitteesResponse* = DataEnclosedObject[seq[RestBeaconStatesCommittees]]

beacon_chain/spec/forks.nim

+19-6
Original file line numberDiff line numberDiff line change
@@ -838,28 +838,41 @@ template getForkedBlockField*(
838838
of ConsensusFork.Capella: unsafeAddr x.capellaData.message.y
839839
of ConsensusFork.Deneb: unsafeAddr x.denebData.message.y)[]
840840

841-
template signature*(x: ForkedSignedBeaconBlock |
841+
template getForkedBodyField*(
842+
x: ForkedSignedBeaconBlock |
843+
ForkedMsgTrustedSignedBeaconBlock |
844+
ForkedTrustedSignedBeaconBlock,
845+
y: untyped): untyped =
846+
# unsafeAddr avoids a copy of the field in some cases
847+
(case x.kind
848+
of ConsensusFork.Phase0: unsafeAddr x.phase0Data.message.body.y
849+
of ConsensusFork.Altair: unsafeAddr x.altairData.message.body.y
850+
of ConsensusFork.Bellatrix: unsafeAddr x.bellatrixData.message.body.y
851+
of ConsensusFork.Capella: unsafeAddr x.capellaData.message.body.y
852+
of ConsensusFork.Deneb: unsafeAddr x.denebData.message.body.y)[]
853+
854+
func signature*(x: ForkedSignedBeaconBlock |
842855
ForkedMsgTrustedSignedBeaconBlock |
843856
ForkedSignedBlindedBeaconBlock): ValidatorSig =
844857
withBlck(x): forkyBlck.signature
845858

846-
template signature*(x: ForkedTrustedSignedBeaconBlock): TrustedSig =
859+
func signature*(x: ForkedTrustedSignedBeaconBlock): TrustedSig =
847860
withBlck(x): forkyBlck.signature
848861

849-
template root*(x: ForkedSignedBeaconBlock |
862+
func root*(x: ForkedSignedBeaconBlock |
850863
ForkedMsgTrustedSignedBeaconBlock |
851864
ForkedTrustedSignedBeaconBlock): Eth2Digest =
852865
withBlck(x): forkyBlck.root
853866

854-
template slot*(x: ForkedSignedBeaconBlock |
867+
func slot*(x: ForkedSignedBeaconBlock |
855868
ForkedMsgTrustedSignedBeaconBlock |
856869
ForkedTrustedSignedBeaconBlock): Slot =
857870
withBlck(x): forkyBlck.message.slot
858871

859-
template shortLog*(x: ForkedBeaconBlock | ForkedBlindedBeaconBlock): auto =
872+
func shortLog*(x: ForkedBeaconBlock | ForkedBlindedBeaconBlock): auto =
860873
withBlck(x): shortLog(forkyBlck)
861874

862-
template shortLog*(x: ForkedSignedBeaconBlock |
875+
func shortLog*(x: ForkedSignedBeaconBlock |
863876
ForkedMsgTrustedSignedBeaconBlock |
864877
ForkedTrustedSignedBeaconBlock |
865878
ForkedSignedBlindedBeaconBlock): auto =

beacon_chain/spec/helpers.nim

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import
1313
# Status libraries
14+
std/times,
1415
stew/[byteutils, endians2, objects, saturation_arith],
1516
chronicles,
1617
eth/common/[eth_types, eth_types_rlp],

ngui/attestationlist.nim

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import
2+
std/[sequtils, tables],
3+
NimQml,
4+
../beacon_chain/spec/eth2_apis/rest_beacon_client,
5+
../beacon_chain/spec/[eth2_merkleization, helpers],
6+
./objecttablemodel, ./utils
7+
8+
type
9+
AttestationInfo* = object
10+
slot*: int
11+
index*: int
12+
beacon_block_root*: string
13+
source_epoch*: int
14+
source_root*: string
15+
target_epoch*: int
16+
target_root*: string
17+
aggregation_bits*: string
18+
19+
proc toAttestationInfo*(v: Attestation): AttestationInfo =
20+
AttestationInfo(
21+
slot: v.data.slot.int,
22+
index: v.data.index.int,
23+
beacon_block_root: toBlockLink(v.data.beacon_block_root),
24+
source_epoch: v.data.source.epoch.int,
25+
source_root: toBlockLink(v.data.source.root),
26+
target_epoch: v.data.target.epoch.int,
27+
target_root: toBlockLink(v.data.target.root),
28+
aggregation_bits: $v.aggregation_bits,
29+
)
30+
31+
QtObject:
32+
type AttestationList* = ref object of QAbstractTableModel
33+
# TODO this could be a generic ObjectTableModel, except generics + method don't work..
34+
data: ObjectTableModelImpl[AttestationInfo]
35+
36+
proc setup(self: AttestationList) = self.QAbstractTableModel.setup
37+
38+
proc delete(self: AttestationList) =
39+
self.QAbstractTableModel.delete
40+
41+
proc newAttestationList*(data: seq[Attestation]): AttestationList =
42+
new(result, delete)
43+
result.data = ObjectTableModelImpl[AttestationInfo](items: data.mapIt(it.toAttestationInfo()))
44+
result.setup
45+
46+
method rowCount(self: AttestationList, index: QModelIndex = nil): int =
47+
self.data.rowCount(index)
48+
49+
method columnCount(self: AttestationList, index: QModelIndex = nil): int =
50+
self.data.columnCount(index)
51+
52+
method headerData*(self: AttestationList, section: int, orientation: QtOrientation, role: int): QVariant =
53+
self.data.headerData(section, orientation, role)
54+
55+
method data(self: AttestationList, index: QModelIndex, role: int): QVariant =
56+
self.data.data(index, role)
57+
58+
method roleNames(self: AttestationList): Table[int, string] =
59+
self.data.roleNames()
60+
61+
proc setNewData*(self: AttestationList, v: seq[Attestation]) =
62+
self.data.setNewData(self, v.mapIt(it.toAttestationInfo()))
63+
64+
proc sort*(self: AttestationList, section: int) {.slot.} =
65+
self.data.sort(self, section)

ngui/attesterslashinglist.nim

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import
2+
std/[sequtils, tables],
3+
NimQml,
4+
../beacon_chain/spec/eth2_apis/rest_beacon_client,
5+
../beacon_chain/spec/[helpers],
6+
./objecttablemodel, ./utils
7+
8+
type
9+
AttesterSlashingInfo* = object
10+
info*: string
11+
12+
proc toAttesterSlashingInfo*(v: AttesterSlashing): AttesterSlashingInfo =
13+
AttesterSlashingInfo(
14+
info: $v
15+
)
16+
17+
QtObject:
18+
type AttesterSlashingList* = ref object of QAbstractTableModel
19+
# TODO this could be a generic ObjectTableModel, except generics + method don't work..
20+
data: ObjectTableModelImpl[AttesterSlashingInfo]
21+
22+
proc setup(self: AttesterSlashingList) = self.QAbstractTableModel.setup
23+
24+
proc delete(self: AttesterSlashingList) =
25+
self.QAbstractTableModel.delete
26+
27+
proc newAttesterSlashingList*(data: openArray[AttesterSlashing]): AttesterSlashingList =
28+
new(result, delete)
29+
result.data = ObjectTableModelImpl[AttesterSlashingInfo](items: data.mapIt(it.toAttesterSlashingInfo()))
30+
result.setup
31+
32+
method rowCount(self: AttesterSlashingList, index: QModelIndex = nil): int =
33+
self.data.rowCount(index)
34+
35+
method columnCount(self: AttesterSlashingList, index: QModelIndex = nil): int =
36+
self.data.columnCount(index)
37+
38+
method headerData*(self: AttesterSlashingList, section: int, orientation: QtOrientation, role: int): QVariant =
39+
self.data.headerData(section, orientation, role)
40+
41+
method data(self: AttesterSlashingList, index: QModelIndex, role: int): QVariant =
42+
self.data.data(index, role)
43+
44+
method roleNames(self: AttesterSlashingList): Table[int, string] =
45+
self.data.roleNames()
46+
47+
proc setNewData*(self: AttesterSlashingList, v: openArray[AttesterSlashing]) =
48+
self.data.setNewData(self, v.mapIt(it.toAttesterSlashingInfo()))
49+
50+
proc sort*(self: AttesterSlashingList, section: int) {.slot.} =
51+
self.data.sort(self, section)

ngui/blockmodel.nim

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import
2+
std/[sequtils, times],
3+
NimQml,
4+
../beacon_chain/spec/eth2_apis/rest_beacon_client,
5+
"."/[
6+
attestationlist, depositlist, attesterslashinglist, proposerslashinglist,
7+
voluntaryexitlist, utils]
8+
9+
QtObject:
10+
type
11+
BlockModel* = ref object of QObject
12+
blck: ForkedSignedBeaconBlock
13+
attestationsx: AttestationList
14+
depositsx: DepositList
15+
attester_slashingsx: AttesterSlashingList
16+
proposer_slashingsx: ProposerSlashingList
17+
voluntary_exitsx: VoluntaryExitList
18+
genesis_time*: uint64
19+
20+
proc delete*(self: BlockModel) =
21+
self.QObject.delete
22+
23+
proc setup*(self: BlockModel) =
24+
self.QObject.setup
25+
26+
proc newBlockModel*(forked: ForkedSignedBeaconBlock, genesis_time: uint64): BlockModel =
27+
let res = withBlck(forked): BlockModel(
28+
blck: forked,
29+
attestationsx: newAttestationList(forkyBlck.message.body.attestations.asSeq()),
30+
depositsx: newDepositList(forkyBlck.message.body.deposits.mapIt(it.toDepositInfo())),
31+
attester_slashingsx: newAttesterSlashingList(forkyBlck.message.body.attester_slashings.asSeq()),
32+
proposer_slashingsx: newProposerSlashingList(forkyBlck.message.body.proposer_slashings.asSeq()),
33+
voluntary_exitsx: newVoluntaryExitList(forkyBlck.message.body.voluntary_exits.asSeq()),
34+
genesis_time: genesis_time,
35+
)
36+
res.setup()
37+
res
38+
39+
proc `blck=`*(self: BlockModel, forked: ForkedSignedBeaconBlock) =
40+
self.blck = forked
41+
withBlck(forked):
42+
self.attestationsx.setNewData(forkyBlck.message.body.attestations.asSeq())
43+
self.depositsx.setNewData(forkyBlck.message.body.deposits.mapIt(it.toDepositInfo()))
44+
self.attester_slashingsx.setNewData(forkyBlck.message.body.attester_slashings.asSeq())
45+
self.proposer_slashingsx.setNewData(forkyBlck.message.body.proposer_slashings.asSeq())
46+
self.voluntary_exitsx.setNewData(forkyBlck.message.body.voluntary_exits.asSeq())
47+
48+
proc slot*(self: BlockModel): int {.slot.} = getForkedBlockField(self.blck, slot).int
49+
QtProperty[int] slot: read = slot
50+
51+
proc time*(self: BlockModel): string {.slot.} =
52+
let t = self.genesis_time + getForkedBlockField(self.blck, slot) * SECONDS_PER_SLOT
53+
$fromUnix(t.int64).utc
54+
QtProperty[string] time: read = time
55+
56+
proc root*(self: BlockModel): string {.slot.} = toDisplayHex(self.blck.root.data)
57+
QtProperty[string] root: read = root
58+
59+
proc proposer_index*(self: BlockModel): int {.slot.} = getForkedBlockField(self.blck, proposer_index).int
60+
QtProperty[int] proposer_index: read = proposer_index
61+
62+
proc parent_root*(self: BlockModel): string {.slot.} = toBlockLink(getForkedBlockField(self.blck, parent_root))
63+
QtProperty[string] parent_root: read = parent_root
64+
65+
proc state_root*(self: BlockModel): string {.slot.} = toDisplayHex(getForkedBlockField(self.blck, state_root).data)
66+
QtProperty[string] state_root: read = state_root
67+
68+
proc randao_reveal*(self: BlockModel): string {.slot.} = toDisplayHex(getForkedBodyField(self.blck, randao_reveal))
69+
QtProperty[string] randao_reveal: read = randao_reveal
70+
71+
proc eth1_data*(self: BlockModel): string {.slot.} = RestJson.encode(getForkedBodyField(self.blck, eth1_data), pretty=true)
72+
QtProperty[string] eth1_data: read = eth1_data
73+
74+
proc graffiti*(self: BlockModel): string {.slot.} = $getForkedBodyField(self.blck, graffiti)
75+
QtProperty[string] graffiti: read = graffiti
76+
77+
proc proposer_slashings*(self: BlockModel): QVariant {.slot.} = newQVariant(self.proposer_slashingsx)
78+
QtProperty[QVariant] proposer_slashings: read = proposer_slashings
79+
80+
proc attester_slashings*(self: BlockModel): QVariant {.slot.} = newQVariant(self.attester_slashingsx)
81+
QtProperty[QVariant] attester_slashings: read = attester_slashings
82+
83+
proc attestations*(self: BlockModel): QVariant {.slot.} = newQVariant(self.attestationsx)
84+
QtProperty[QVariant] attestations: read = attestations
85+
86+
proc deposits*(self: BlockModel): QVariant {.slot.} = newQVariant(self.depositsx)
87+
QtProperty[QVariant] deposits: read = deposits
88+
89+
proc voluntary_exits*(self: BlockModel): QVariant {.slot.} = newQVariant(self.voluntary_exitsx)
90+
QtProperty[QVariant] voluntary_exits: read = voluntary_exits
91+
92+
proc signature*(self: BlockModel): string {.slot.} = toDisplayHex(self.blck.signature)
93+
QtProperty[string] signature: read = signature

ngui/depositlist.nim

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import
2+
std/[tables],
3+
NimQml,
4+
../beacon_chain/spec/datatypes/base,
5+
./objecttablemodel, ./utils
6+
7+
type
8+
DepositInfo* = object
9+
pubkey*: string
10+
withdrawal_credentials*: string
11+
amount*: uint64
12+
signature*: string
13+
14+
proc toDepositInfo*(v: Deposit): DepositInfo =
15+
DepositInfo(
16+
pubkey: toDisplayHex(v.data.pubkey.toRaw()),
17+
withdrawal_credentials: toDisplayHex(v.data.withdrawal_credentials),
18+
amount: v.data.amount,
19+
signature: toDisplayHex(v.data.signature),
20+
)
21+
22+
QtObject:
23+
type DepositList* = ref object of QAbstractTableModel
24+
# TODO this could be a generic ObjectTableModel, except generics + method don't work..
25+
data: ObjectTableModelImpl[DepositInfo]
26+
27+
proc setup(self: DepositList) = self.QAbstractTableModel.setup
28+
29+
proc delete(self: DepositList) =
30+
self.QAbstractTableModel.delete
31+
32+
proc newDepositList*(data: seq[DepositInfo]): DepositList =
33+
new(result, delete)
34+
result.data = ObjectTableModelImpl[DepositInfo](items: data)
35+
result.setup
36+
37+
method rowCount(self: DepositList, index: QModelIndex = nil): int =
38+
self.data.rowCount(index)
39+
40+
method columnCount(self: DepositList, index: QModelIndex = nil): int =
41+
self.data.columnCount(index)
42+
43+
method headerData*(self: DepositList, section: int, orientation: QtOrientation, role: int): QVariant =
44+
self.data.headerData(section, orientation, role)
45+
46+
method data(self: DepositList, index: QModelIndex, role: int): QVariant =
47+
self.data.data(index, role)
48+
49+
method roleNames(self: DepositList): Table[int, string] =
50+
self.data.roleNames()
51+
52+
proc setNewData*(self: DepositList, v: seq[DepositInfo]) =
53+
self.data.setNewData(self, v)
54+
55+
proc sort*(self: DepositList, section: int) {.slot.} =
56+
self.data.sort(self, section)

0 commit comments

Comments
 (0)