Skip to content

Commit 53703f4

Browse files
committed
Block / REST explorer
1 parent 6c0d756 commit 53703f4

31 files changed

+1701
-6
lines changed

.gitmodules

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@
192192
path = vendor/nim-toml-serialization
193193
url = https://github.com/status-im/nim-toml-serialization.git
194194
ignore = untracked
195+
[submodule "vendor/DOtherSide"]
196+
path = vendor/DOtherSide
197+
url = https://github.com/filcuc/DOtherSide.git
198+
branch = master
199+
[submodule "vendor/nimqml"]
200+
path = vendor/nimqml
201+
url = https://github.com/status-im/nimqml.git
195202
branch = master
196203
[submodule "vendor/merge-testnets"]
197204
path = vendor/merge-testnets

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,10 @@ force_build_alone_tools: | $(FORCE_BUILD_ALONE_TOOLS_DEPS)
458458
# https://www.gnu.org/software/make/manual/html_node/Multiple-Rules.html#Multiple-Rules
459459
# Already defined as a reult
460460
nimbus_beacon_node: force_build_alone_tools
461+
ngui/ngui: | build deps
462+
+ echo -e $(BUILD_MSG) "build/$@" && \
463+
MAKE="$(MAKE)" V="$(V)" $(ENV_SCRIPT) scripts/compile_nim_program.sh $@ "ngui.ngui.nim" $(NIM_PARAMS) && \
464+
echo -e $(BUILD_END_MSG) "ngui/ngui"
461465

462466
clean_eth2_network_simulation_data:
463467
rm -rf tests/simulation/data

beacon_chain/spec/forks.nim

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -750,28 +750,41 @@ template getForkedBlockField*(
750750
of ConsensusFork.Capella: unsafeAddr x.capellaData.message.y
751751
of ConsensusFork.Deneb: unsafeAddr x.denebData.message.y)[]
752752

753-
template signature*(x: ForkedSignedBeaconBlock |
753+
template getForkedBodyField*(
754+
x: ForkedSignedBeaconBlock |
755+
ForkedMsgTrustedSignedBeaconBlock |
756+
ForkedTrustedSignedBeaconBlock,
757+
y: untyped): untyped =
758+
# unsafeAddr avoids a copy of the field in some cases
759+
(case x.kind
760+
of ConsensusFork.Phase0: unsafeAddr x.phase0Data.message.body.y
761+
of ConsensusFork.Altair: unsafeAddr x.altairData.message.body.y
762+
of ConsensusFork.Bellatrix: unsafeAddr x.bellatrixData.message.body.y
763+
of ConsensusFork.Capella: unsafeAddr x.capellaData.message.body.y
764+
of ConsensusFork.Deneb: unsafeAddr x.denebData.message.body.y)[]
765+
766+
func signature*(x: ForkedSignedBeaconBlock |
754767
ForkedMsgTrustedSignedBeaconBlock |
755768
ForkedSignedBlindedBeaconBlock): ValidatorSig =
756769
withBlck(x): blck.signature
757770

758-
template signature*(x: ForkedTrustedSignedBeaconBlock): TrustedSig =
771+
func signature*(x: ForkedTrustedSignedBeaconBlock): TrustedSig =
759772
withBlck(x): blck.signature
760773

761-
template root*(x: ForkedSignedBeaconBlock |
774+
func root*(x: ForkedSignedBeaconBlock |
762775
ForkedMsgTrustedSignedBeaconBlock |
763776
ForkedTrustedSignedBeaconBlock): Eth2Digest =
764777
withBlck(x): blck.root
765778

766-
template slot*(x: ForkedSignedBeaconBlock |
779+
func slot*(x: ForkedSignedBeaconBlock |
767780
ForkedMsgTrustedSignedBeaconBlock |
768781
ForkedTrustedSignedBeaconBlock): Slot =
769782
withBlck(x): blck.message.slot
770783

771-
template shortLog*(x: ForkedBeaconBlock | ForkedBlindedBeaconBlock): auto =
784+
func shortLog*(x: ForkedBeaconBlock | ForkedBlindedBeaconBlock): auto =
772785
withBlck(x): shortLog(blck)
773786

774-
template shortLog*(x: ForkedSignedBeaconBlock |
787+
func shortLog*(x: ForkedSignedBeaconBlock |
775788
ForkedMsgTrustedSignedBeaconBlock |
776789
ForkedTrustedSignedBeaconBlock |
777790
ForkedSignedBlindedBeaconBlock): auto =

ngui/attestationlist.nim

Lines changed: 65 additions & 0 deletions
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

Lines changed: 51 additions & 0 deletions
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

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

ngui/depositlist.nim

Lines changed: 56 additions & 0 deletions
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)

ngui/epochmodel.nim

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import NimQml
2+
3+
import
4+
../beacon_chain/spec/eth2_apis/rest_beacon_client,
5+
./slotlist
6+
7+
QtObject:
8+
type
9+
EpochModel* = ref object of QObject
10+
client: RestClientRef
11+
epoch: int
12+
slotList: SlotList
13+
14+
proc delete*(self: EpochModel) =
15+
self.QObject.delete
16+
17+
proc setup*(self: EpochModel) =
18+
self.QObject.setup
19+
20+
proc newEpochModel*(client: RestClientRef, epoch: int): EpochModel =
21+
let data = client.loadSlots(epoch.Epoch)
22+
let res = EpochModel(client: client, epoch: epoch, slotList: newSlotList(data))
23+
res.setup()
24+
res
25+
26+
proc epoch*(self: EpochModel): int {.slot.} = self.epoch
27+
proc epochChanged*(self: EpochModel, v: int) {.signal.}
28+
QtProperty[int] epoch:
29+
read = epoch
30+
notify = epochChanged
31+
32+
proc getSlotList*(self: EpochModel): QVariant {.slot.} = newQVariant(self.slotList)
33+
QtProperty[QVariant] slotList: read = getSlotList
34+
35+
proc setNewData*(self: EpochModel, epoch: int, data: seq[SlotInfo]) =
36+
self.epoch = epoch
37+
self.epochChanged(epoch)
38+
39+
self.slotList.setNewData(data)
40+
41+
proc reload(self: EpochModel) {.slot.} =
42+
self.slotList.setNewData(self.client.loadSlots(self.epoch.Epoch))
43+
44+
proc next(self: EpochModel) {.slot.} =
45+
self.epoch = self.epoch + 1
46+
self.epochChanged(self.epoch)
47+
self.reload() # TODO listen to epochchanged
48+
49+
proc prev(self: EpochModel) {.slot.} =
50+
self.epoch = self.epoch - 1
51+
self.epochChanged(self.epoch)
52+
self.reload() # TODO listen to epochchanged

0 commit comments

Comments
 (0)