use case statement to avoid runtime doAssert
This commit is contained in:
parent
c142de4b7f
commit
9c65c50249
|
@ -108,23 +108,22 @@ func toPubKey*(privkey: ValidatorPrivKey): ValidatorPubKey =
|
||||||
proc toRealPubKey(pubkey: ValidatorPubKey): Option[ValidatorPubKey] =
|
proc toRealPubKey(pubkey: ValidatorPubKey): Option[ValidatorPubKey] =
|
||||||
var validatorKeyCache {.threadvar.}: Table[Hash, Option[ValidatorPubKey]]
|
var validatorKeyCache {.threadvar.}: Table[Hash, Option[ValidatorPubKey]]
|
||||||
|
|
||||||
if pubkey.kind == Real:
|
case pubkey.kind:
|
||||||
|
of Real:
|
||||||
return some(pubkey)
|
return some(pubkey)
|
||||||
|
of OpaqueBlob:
|
||||||
doAssert pubkey.kind == OpaqueBlob
|
let key = hash(pubkey.blob)
|
||||||
|
try:
|
||||||
let key = hash(pubkey.blob)
|
validatorKeyCache[key]
|
||||||
try:
|
except KeyError:
|
||||||
validatorKeyCache[key]
|
var val: blscurve.PublicKey
|
||||||
except KeyError:
|
let maybeRealKey =
|
||||||
var val: blscurve.PublicKey
|
if fromBytes(val, pubkey.blob):
|
||||||
let maybeRealKey =
|
some ValidatorPubKey(kind: Real, blsValue: val)
|
||||||
if fromBytes(val, pubkey.blob):
|
else:
|
||||||
some ValidatorPubKey(kind: Real, blsValue: val)
|
none ValidatorPubKey
|
||||||
else:
|
validatorKeyCache[key] = maybeRealKey
|
||||||
none ValidatorPubKey
|
maybeRealKey
|
||||||
validatorKeyCache[key] = maybeRealKey
|
|
||||||
maybeRealKey
|
|
||||||
|
|
||||||
proc initPubKey*(pubkey: ValidatorPubKey): ValidatorPubKey =
|
proc initPubKey*(pubkey: ValidatorPubKey): ValidatorPubKey =
|
||||||
let key = toRealPubKey(pubkey)
|
let key = toRealPubKey(pubkey)
|
||||||
|
|
Loading…
Reference in New Issue