Skip to content

Commit c94bc18

Browse files
committed
Block / RPC explorer
1 parent 1622a12 commit c94bc18

22 files changed

+1380
-0
lines changed

ngui/attestationlist.nim

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import
2+
std/[tables],
3+
NimQml,
4+
../beacon_chain/spec/[helpers, eth2_apis/beacon_rpc_client],
5+
../beacon_chain/ssz/merkleization,
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[AttestationInfo]): AttestationList =
42+
new(result, delete)
43+
result.data = ObjectTableModelImpl[AttestationInfo](items: data)
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[AttestationInfo]) =
62+
self.data.setNewData(self, v)
63+
64+
proc sort*(self: AttestationList, section: int) {.slot.} =
65+
self.data.sort(self, section)

ngui/blockmodel.nim

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import NimQml
2+
3+
import
4+
std/[sequtils, json, times],
5+
NimQml,
6+
../beacon_chain/eth2_json_rpc_serialization,
7+
../beacon_chain/spec/[datatypes, crypto],
8+
./attestationlist, ./depositlist, ./utils
9+
10+
QtObject:
11+
type
12+
BlockModel* = ref object of QObject
13+
blck: SignedBeaconBlock
14+
attestationsx: AttestationList
15+
depositsx: DepositList
16+
genesis_time*: uint64
17+
18+
proc delete*(self: BlockModel) =
19+
self.QObject.delete
20+
21+
proc setup*(self: BlockModel) =
22+
self.QObject.setup
23+
24+
proc newBlockModel*(blck: SignedBeaconBlock, genesis_time: uint64): BlockModel =
25+
let res = BlockModel(
26+
blck: blck,
27+
attestationsx: newAttestationList(blck.message.body.attestations.mapIt(it.toAttestationInfo())),
28+
depositsx: newDepositList(blck.message.body.deposits.mapIt(it.toDepositInfo())),
29+
genesis_time: genesis_time,
30+
)
31+
res.setup()
32+
res
33+
34+
proc `blck=`*(self: BlockModel, blck: SignedBeaconBlock) =
35+
self.blck = blck
36+
self.attestationsx.setNewData(blck.message.body.attestations.mapIt(it.toAttestationInfo()))
37+
self.depositsx.setNewData(blck.message.body.deposits.mapIt(it.toDepositInfo()))
38+
39+
proc slot*(self: BlockModel): int {.slot.} = self.blck.message.slot.int
40+
QtProperty[int] slot: read = slot
41+
42+
proc time*(self: BlockModel): string {.slot.} =
43+
let t = self.genesis_time + self.blck.message.slot * SECONDS_PER_SLOT
44+
$fromUnix(t.int64).utc
45+
QtProperty[string] time: read = time
46+
47+
proc root*(self: BlockModel): string {.slot.} = toDisplayHex(self.blck.root.data)
48+
QtProperty[string] root: read = root
49+
50+
proc proposer_index*(self: BlockModel): int {.slot.} = self.blck.message.proposer_index.int
51+
QtProperty[int] proposer_index: read = proposer_index
52+
53+
proc parent_root*(self: BlockModel): string {.slot.} = toBlockLink(self.blck.message.parent_root)
54+
QtProperty[string] parent_root: read = parent_root
55+
56+
proc state_root*(self: BlockModel): string {.slot.} = toDisplayHex(self.blck.message.state_root.data)
57+
QtProperty[string] state_root: read = state_root
58+
59+
proc randao_reveal*(self: BlockModel): string {.slot.} = toDisplayHex(self.blck.message.body.randao_reveal)
60+
QtProperty[string] randao_reveal: read = randao_reveal
61+
62+
proc eth1_data*(self: BlockModel): string {.slot.} = (%*self.blck.message.body.eth1_data).pretty()
63+
QtProperty[string] eth1_data: read = eth1_data
64+
65+
proc graffiti*(self: BlockModel): string {.slot.} = $self.blck.message.body.graffiti
66+
QtProperty[string] graffiti: read = graffiti
67+
68+
proc proposer_slashings*(self: BlockModel): string {.slot.} = (%*self.blck.message.body.proposer_slashings.asSeq()).pretty()
69+
QtProperty[string] proposer_slashings: read = proposer_slashings
70+
71+
proc attester_slashings*(self: BlockModel): string {.slot.} = (%*self.blck.message.body.attester_slashings.asSeq()).pretty()
72+
QtProperty[string] attester_slashings: read = attester_slashings
73+
74+
proc attestations*(self: BlockModel): QVariant {.slot.} = newQVariant(self.attestationsx)
75+
QtProperty[QVariant] attestations: read = attestations
76+
77+
proc deposits*(self: BlockModel): QVariant {.slot.} = newQVariant(self.depositsx)
78+
QtProperty[QVariant] deposits: read = deposits
79+
80+
proc voluntary_exits*(self: BlockModel): string {.slot.} = (%*self.blck.message.body.voluntary_exits.asSeq()).pretty()
81+
QtProperty[string] voluntary_exits: read = voluntary_exits
82+
83+
proc signature*(self: BlockModel): string {.slot.} = toDisplayHex(self.blck.signature)
84+
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/[eth2_apis/beacon_rpc_client],
5+
./objecttablemodel, ./utils
6+
7+
type
8+
DepositInfo* = object
9+
pubkey*: string
10+
withdrawal_credentials*: string
11+
amount*: string
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

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import NimQml
2+
3+
import
4+
./slotlist,
5+
../beacon_chain/[spec/eth2_apis/beacon_rpc_client]
6+
7+
QtObject:
8+
type
9+
EpochModel* = ref object of QObject
10+
client: RpcHttpClient
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: RpcHttpClient, 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

ngui/footermodel.nim

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import NimQml
2+
3+
QtObject:
4+
type
5+
FooterModel* = ref object of QObject
6+
finalized: string
7+
head: string
8+
syncing: string
9+
10+
proc delete*(self: FooterModel) =
11+
self.QObject.delete
12+
13+
proc setup*(self: FooterModel) =
14+
self.QObject.setup
15+
16+
proc newFooterModel*(): FooterModel =
17+
let res = FooterModel()
18+
res.setup()
19+
res
20+
21+
proc finalized*(self: FooterModel): string {.slot.} = self.finalized
22+
proc finalizedChanged*(self: FooterModel, v: string) {.signal.}
23+
proc `finalized=`*(self: FooterModel, v: string) =
24+
self.finalized = v
25+
self.finalizedChanged(v)
26+
QtProperty[string] finalized:
27+
read = finalized
28+
notify = finalizedChanged
29+
30+
proc head*(self: FooterModel): string {.slot.} = self.head
31+
proc headChanged*(self: FooterModel, v: string) {.signal.}
32+
proc `head=`*(self: FooterModel, v: string) =
33+
self.head = v
34+
self.headChanged(v)
35+
QtProperty[string] head: read = head; notify = headChanged
36+
37+
proc syncing*(self: FooterModel): string {.slot.} = self.syncing
38+
proc syncingChanged*(self: FooterModel, v: string) {.signal.}
39+
proc `syncing=`*(self: FooterModel, v: string) =
40+
self.syncing = v
41+
self.syncingChanged(v)
42+
QtProperty[string] syncing: read = syncing; notify = syncingChanged

0 commit comments

Comments
 (0)