move `Transaction`, `ExecutionAddress` and `BloomLogs` to `base`
Preparation for EIP-7495 SSZ `StableContainer` which can only contain immutable types in their fields.
This commit is contained in:
parent
ee5af9f7ee
commit
bd0689f048
|
@ -373,6 +373,15 @@ type
|
||||||
sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE]
|
sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE]
|
||||||
sync_committee_signature*: TrustedSig
|
sync_committee_signature*: TrustedSig
|
||||||
|
|
||||||
|
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.2/specs/bellatrix/beacon-chain.md#custom-types
|
||||||
|
Transaction* = List[byte, Limit MAX_BYTES_PER_TRANSACTION]
|
||||||
|
|
||||||
|
ExecutionAddress* = object
|
||||||
|
data*: array[20, byte] # TODO there's a network_metadata type, but the import hierarchy's inconvenient
|
||||||
|
|
||||||
|
BloomLogs* = object
|
||||||
|
data*: array[BYTES_PER_LOGS_BLOOM, byte]
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#beaconblockheader
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#beaconblockheader
|
||||||
BeaconBlockHeader* = object
|
BeaconBlockHeader* = object
|
||||||
slot*: Slot
|
slot*: Slot
|
||||||
|
@ -837,6 +846,30 @@ func hasSupermajoritySyncParticipation*(
|
||||||
func hasSupermajoritySyncParticipation*(v: SomeSyncAggregate): bool =
|
func hasSupermajoritySyncParticipation*(v: SomeSyncAggregate): bool =
|
||||||
hasSupermajoritySyncParticipation(v.num_active_participants.uint64)
|
hasSupermajoritySyncParticipation(v.num_active_participants.uint64)
|
||||||
|
|
||||||
|
func fromHex*(
|
||||||
|
T: typedesc[BloomLogs], s: string): T {.raises: [ValueError].} =
|
||||||
|
hexToByteArray(s, result.data)
|
||||||
|
|
||||||
|
func fromHex*(
|
||||||
|
T: typedesc[ExecutionAddress], s: string): T {.raises: [ValueError].} =
|
||||||
|
hexToByteArray(s, result.data)
|
||||||
|
|
||||||
|
proc writeValue*(
|
||||||
|
writer: var JsonWriter, value: ExecutionAddress) {.raises: [IOError].} =
|
||||||
|
writer.writeValue to0xHex(value.data)
|
||||||
|
|
||||||
|
proc readValue*(
|
||||||
|
reader: var JsonReader,
|
||||||
|
value: var ExecutionAddress) {.raises: [IOError, SerializationError].} =
|
||||||
|
try:
|
||||||
|
hexToByteArray(reader.readValue(string), value.data)
|
||||||
|
except ValueError:
|
||||||
|
reader.raiseUnexpectedValue(
|
||||||
|
"ExecutionAddress value should be a valid hex string")
|
||||||
|
|
||||||
|
func `$`*(v: ExecutionAddress): string =
|
||||||
|
v.data.toHex()
|
||||||
|
|
||||||
chronicles.formatIt AttestationData: it.shortLog
|
chronicles.formatIt AttestationData: it.shortLog
|
||||||
chronicles.formatIt Checkpoint: it.shortLog
|
chronicles.formatIt Checkpoint: it.shortLog
|
||||||
|
|
||||||
|
|
|
@ -35,15 +35,6 @@ const
|
||||||
NEWPAYLOAD_TIMEOUT* = 8.seconds
|
NEWPAYLOAD_TIMEOUT* = 8.seconds
|
||||||
|
|
||||||
type
|
type
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.2/specs/bellatrix/beacon-chain.md#custom-types
|
|
||||||
Transaction* = List[byte, Limit MAX_BYTES_PER_TRANSACTION]
|
|
||||||
|
|
||||||
ExecutionAddress* = object
|
|
||||||
data*: array[20, byte] # TODO there's a network_metadata type, but the import hierarchy's inconvenient
|
|
||||||
|
|
||||||
BloomLogs* = object
|
|
||||||
data*: array[BYTES_PER_LOGS_BLOOM, byte]
|
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.2/specs/bellatrix/beacon-chain.md#executionpayload
|
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.2/specs/bellatrix/beacon-chain.md#executionpayload
|
||||||
ExecutionPayload* = object
|
ExecutionPayload* = object
|
||||||
# Execution block header fields
|
# Execution block header fields
|
||||||
|
@ -361,29 +352,6 @@ type
|
||||||
func initHashedBeaconState*(s: BeaconState): HashedBeaconState =
|
func initHashedBeaconState*(s: BeaconState): HashedBeaconState =
|
||||||
HashedBeaconState(data: s)
|
HashedBeaconState(data: s)
|
||||||
|
|
||||||
func fromHex*(T: typedesc[BloomLogs], s: string): T {.
|
|
||||||
raises: [ValueError].} =
|
|
||||||
hexToByteArray(s, result.data)
|
|
||||||
|
|
||||||
func fromHex*(T: typedesc[ExecutionAddress], s: string): T {.
|
|
||||||
raises: [ValueError].} =
|
|
||||||
hexToByteArray(s, result.data)
|
|
||||||
|
|
||||||
proc writeValue*(
|
|
||||||
writer: var JsonWriter, value: ExecutionAddress) {.raises: [IOError].} =
|
|
||||||
writer.writeValue to0xHex(value.data)
|
|
||||||
|
|
||||||
proc readValue*(reader: var JsonReader, value: var ExecutionAddress) {.
|
|
||||||
raises: [IOError, SerializationError].} =
|
|
||||||
try:
|
|
||||||
hexToByteArray(reader.readValue(string), value.data)
|
|
||||||
except ValueError:
|
|
||||||
raiseUnexpectedValue(reader,
|
|
||||||
"ExecutionAddress value should be a valid hex string")
|
|
||||||
|
|
||||||
func `$`*(v: ExecutionAddress): string =
|
|
||||||
v.data.toHex()
|
|
||||||
|
|
||||||
func shortLog*(v: SomeBeaconBlock): auto =
|
func shortLog*(v: SomeBeaconBlock): auto =
|
||||||
(
|
(
|
||||||
slot: shortLog(v.slot),
|
slot: shortLog(v.slot),
|
||||||
|
|
Loading…
Reference in New Issue