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