|
| 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 |
0 commit comments