fix libnimbus compilation errors related to eth/keys changes

This commit is contained in:
jangko 2020-06-24 20:32:49 +07:00
parent 12ddfee675
commit 2ef8179ab0
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9

View File

@ -101,12 +101,11 @@ proc nimbus_start(port: uint16, startListening: bool, enableDiscovery: bool,
else: else:
let let
privKey = PrivateKey.fromRaw(makeOpenArray(privateKey, 32)) privKey = PrivateKey.fromRaw(makeOpenArray(privateKey, 32))
kp = privKey and privKey[].toKeyPair() if privKey.isErr:
if kp.isErr:
error "Passed an invalid private key." error "Passed an invalid private key."
return false return false
keypair = kp[] keypair = privKey[].toKeyPair()
node = newEthereumNode(keypair, address, 1, nil, addAllCapabilities = false) node = newEthereumNode(keypair, address, 1, nil, addAllCapabilities = false)
node.addCapability Whisper node.addCapability Whisper
@ -174,7 +173,7 @@ proc nimbus_new_keypair(id: var Identifier): bool
discard discard
proc nimbus_add_keypair(privateKey: ptr byte, id: var Identifier): proc nimbus_add_keypair(privateKey: ptr byte, id: var Identifier):
bool {.exportc, dynlib, raises: [Defect].} = bool {.exportc, dynlib, raises: [Defect, Exception].} =
## Caller needs to provide as id a pointer to 32 bytes allocation. ## Caller needs to provide as id a pointer to 32 bytes allocation.
doAssert(not (unsafeAddr id).isNil, "Key id cannot be nil.") doAssert(not (unsafeAddr id).isNil, "Key id cannot be nil.")
doAssert(not privateKey.isNil, "Private key cannot be nil.") doAssert(not privateKey.isNil, "Private key cannot be nil.")
@ -189,12 +188,11 @@ proc nimbus_add_keypair(privateKey: ptr byte, id: var Identifier):
else: else:
let let
privKey = PrivateKey.fromRaw(makeOpenArray(privateKey, 32)) privKey = PrivateKey.fromRaw(makeOpenArray(privateKey, 32))
kp = privKey and privKey[].toKeyPair() if privKey.isErr:
if kp.isErr:
error "Passed an invalid private key." error "Passed an invalid private key."
return false return false
keypair = kp[] keypair = privKey[].toKeyPair()
result = true result = true
id = generateRandomID() id = generateRandomID()
@ -208,7 +206,7 @@ proc nimbus_delete_keypair(id: Identifier): bool
result = whisperKeys.asymKeys.take(id.toHex(), unneeded) result = whisperKeys.asymKeys.take(id.toHex(), unneeded)
proc nimbus_get_private_key(id: Identifier, privateKey: var PrivateKey): proc nimbus_get_private_key(id: Identifier, privateKey: var PrivateKey):
bool {.exportc, dynlib, raises: [OSError, IOError, ValueError].} = bool {.exportc, dynlib, raises: [OSError, IOError, ValueError, Exception].} =
doAssert(not (unsafeAddr id).isNil, "Key id cannot be nil.") doAssert(not (unsafeAddr id).isNil, "Key id cannot be nil.")
doAssert(not (unsafeAddr privateKey).isNil, "Private key cannot be nil.") doAssert(not (unsafeAddr privateKey).isNil, "Private key cannot be nil.")
@ -256,7 +254,7 @@ proc nimbus_delete_symkey(id: Identifier): bool
result = whisperKeys.symKeys.take(id.toHex(), unneeded) result = whisperKeys.symKeys.take(id.toHex(), unneeded)
proc nimbus_get_symkey(id: Identifier, symKey: var SymKey): proc nimbus_get_symkey(id: Identifier, symKey: var SymKey):
bool {.exportc, dynlib, raises: [Defect].} = bool {.exportc, dynlib, raises: [Defect, Exception].} =
doAssert(not (unsafeAddr id).isNil, "Key id cannot be nil.") doAssert(not (unsafeAddr id).isNil, "Key id cannot be nil.")
doAssert(not (unsafeAddr symKey).isNil, "Symmetric key cannot be nil.") doAssert(not (unsafeAddr symKey).isNil, "Symmetric key cannot be nil.")