2018-11-23 23:58:49 +00:00
|
|
|
import
|
|
|
|
tables, random,
|
|
|
|
asyncdispatch2,
|
|
|
|
datatypes
|
|
|
|
|
|
|
|
type
|
|
|
|
ValidatorKind = enum
|
|
|
|
inProcess
|
|
|
|
remote
|
|
|
|
|
|
|
|
ValidatorConnection = object
|
|
|
|
|
|
|
|
RandaoValue = seq[bytes]
|
|
|
|
|
|
|
|
AttachedValidator* = ref object
|
2018-11-26 13:33:06 +00:00
|
|
|
idx*: int
|
2018-11-23 23:58:49 +00:00
|
|
|
case kind: ValidatorKind
|
|
|
|
of inProcess:
|
|
|
|
randaoValue: RandaoValue
|
|
|
|
privKey: BLSPrivateKey
|
2018-11-26 13:33:06 +00:00
|
|
|
randaoSecret: seq[bytes]
|
2018-11-23 23:58:49 +00:00
|
|
|
else:
|
|
|
|
connection: ValidatorConnection
|
|
|
|
|
|
|
|
ValidatorPool* = object
|
|
|
|
validators: Table[BLSPublicKey, AttachedValidator]
|
|
|
|
|
|
|
|
proc init*(T: type ValidatorPool): T =
|
|
|
|
result.validators = initTable[BLSPublicKey, AttachedValidator]()
|
|
|
|
|
|
|
|
proc addLocalValidator*(pool: var ValidatorPool,
|
|
|
|
pubKey: BLSPublicKey,
|
|
|
|
privKey: BLSPrivateKey) =
|
|
|
|
discard
|
|
|
|
|
2018-11-26 13:33:06 +00:00
|
|
|
proc getValidator*(pool: ValidatorPool,
|
|
|
|
validatorKey: BLSPublicKey): AttachedValidator =
|
2018-11-23 23:58:49 +00:00
|
|
|
pool.validatators.getOrDefault(validatorKey)
|
|
|
|
|
|
|
|
proc signBlockProposal*(v: AttachedValidator,
|
|
|
|
proposal: ProposalSignedData): Future[Signature] {.async.} =
|
|
|
|
if v.inProcess:
|
|
|
|
await sleepAsync(1)
|
|
|
|
# TODO:
|
|
|
|
# return sign(proposal, v.privKey)
|
|
|
|
else:
|
|
|
|
# TODO:
|
|
|
|
# send RPC
|
|
|
|
discard
|
|
|
|
|
|
|
|
proc signAttestation*(v: AttachedValidator,
|
|
|
|
attestation: AttestationSignedData): Future[Signature] {.async.} =
|
|
|
|
# TODO: implement this
|
|
|
|
if v.inProcess:
|
|
|
|
await sleepAsync(1)
|
|
|
|
# TODO:
|
|
|
|
# return sign(proposal, v.privKey)
|
|
|
|
else:
|
|
|
|
# TODO:
|
|
|
|
# send RPC
|
|
|
|
discard
|
|
|
|
|