fix compilation error following breaking changes in nim-eth
This commit is contained in:
parent
063019ab95
commit
845671bf0a
|
@ -11,7 +11,7 @@ import
|
||||||
parseopt, strutils, macros, os, times, json, stew/[byteutils],
|
parseopt, strutils, macros, os, times, json, stew/[byteutils],
|
||||||
chronos, eth/[keys, common, p2p, net/nat], chronicles, nimcrypto/hash,
|
chronos, eth/[keys, common, p2p, net/nat], chronicles, nimcrypto/hash,
|
||||||
eth/p2p/bootnodes, eth/p2p/rlpx_protocols/whisper_protocol,
|
eth/p2p/bootnodes, eth/p2p/rlpx_protocols/whisper_protocol,
|
||||||
./db/select_backend,
|
./db/select_backend, ./random_keys,
|
||||||
./vm/interpreter/vm_forks
|
./vm/interpreter/vm_forks
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -847,7 +847,7 @@ proc initConfiguration(): NimbusConfiguration =
|
||||||
result.net.ident = NimbusIdent
|
result.net.ident = NimbusIdent
|
||||||
result.net.nat = NatAny
|
result.net.nat = NatAny
|
||||||
result.net.protocols = defaultProtocols
|
result.net.protocols = defaultProtocols
|
||||||
result.net.nodekey = PrivateKey.random().tryGet()
|
result.net.nodekey = randomPrivateKey()
|
||||||
|
|
||||||
const dataDir = getDefaultDataDir()
|
const dataDir = getDefaultDataDir()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
import eth/keys as ethkeys
|
||||||
|
|
||||||
|
# You should only create one instance of the RNG per application / library
|
||||||
|
# Ref is used so that it can be shared between components
|
||||||
|
|
||||||
|
var theRNG {.threadvar.}: ref BrHmacDrbgContext
|
||||||
|
|
||||||
|
proc getRng*(): ref BrHmacDrbgContext {.gcsafe.} =
|
||||||
|
if theRNG.isNil:
|
||||||
|
theRNG = newRng()
|
||||||
|
theRNG
|
||||||
|
|
||||||
|
proc randomPrivateKey*(): PrivateKey =
|
||||||
|
random(PrivateKey, theRNG[])
|
||||||
|
|
||||||
|
proc randomKeyPair*(): KeyPair =
|
||||||
|
random(KeyPair, theRNG[])
|
|
@ -2,10 +2,13 @@ import
|
||||||
json_rpc/rpcserver, tables, options,
|
json_rpc/rpcserver, tables, options,
|
||||||
eth/[common, rlp, keys, p2p], eth/p2p/rlpx_protocols/whisper_protocol,
|
eth/[common, rlp, keys, p2p], eth/p2p/rlpx_protocols/whisper_protocol,
|
||||||
nimcrypto/[sysrand, hmac, sha2, pbkdf2],
|
nimcrypto/[sysrand, hmac, sha2, pbkdf2],
|
||||||
rpc_types, hexstrings, key_storage
|
rpc_types, hexstrings, key_storage, ../random_keys
|
||||||
|
|
||||||
from stew/byteutils import hexToSeqByte, hexToByteArray
|
from stew/byteutils import hexToSeqByte, hexToByteArray
|
||||||
|
|
||||||
|
template generateRandomID*(): string =
|
||||||
|
generateRandomID(getRNG()[])
|
||||||
|
|
||||||
# Whisper RPC implemented mostly as in
|
# Whisper RPC implemented mostly as in
|
||||||
# https://github.com/ethereum/go-ethereum/wiki/Whisper-v6-RPC-API
|
# https://github.com/ethereum/go-ethereum/wiki/Whisper-v6-RPC-API
|
||||||
|
|
||||||
|
@ -71,7 +74,7 @@ proc setupWhisperRPC*(node: EthereumNode, keys: KeyStorage, rpcsrv: RpcServer) =
|
||||||
##
|
##
|
||||||
## Returns key identifier on success and an error on failure.
|
## Returns key identifier on success and an error on failure.
|
||||||
result = generateRandomID().Identifier
|
result = generateRandomID().Identifier
|
||||||
keys.asymKeys.add(result.string, KeyPair.random().tryGet())
|
keys.asymKeys.add(result.string, randomKeyPair())
|
||||||
|
|
||||||
rpcsrv.rpc("shh_addPrivateKey") do(key: PrivateKey) -> Identifier:
|
rpcsrv.rpc("shh_addPrivateKey") do(key: PrivateKey) -> Identifier:
|
||||||
## Stores the key pair, and returns its ID.
|
## Stores the key pair, and returns its ID.
|
||||||
|
|
|
@ -59,7 +59,7 @@ proc getSender*(transaction: Transaction, output: var EthAddress): bool =
|
||||||
var sig: Signature
|
var sig: Signature
|
||||||
if transaction.getSignature(sig):
|
if transaction.getSignature(sig):
|
||||||
var txHash = transaction.txHashNoSignature
|
var txHash = transaction.txHashNoSignature
|
||||||
let pubkey = recover(sig, txHash)
|
let pubkey = recover(sig, SkMessage(txHash.data))
|
||||||
if pubkey.isOk:
|
if pubkey.isOk:
|
||||||
output = pubkey[].toCanonicalAddress()
|
output = pubkey[].toCanonicalAddress()
|
||||||
result = true
|
result = true
|
||||||
|
|
|
@ -101,7 +101,7 @@ proc ecRecover*(computation: Computation) =
|
||||||
var
|
var
|
||||||
(msgHash, sig) = computation.getSignature()
|
(msgHash, sig) = computation.getSignature()
|
||||||
|
|
||||||
var pubkey = recover(sig, SkMessage(data: msgHash))
|
var pubkey = recover(sig, SkMessage(msgHash))
|
||||||
if pubkey.isErr:
|
if pubkey.isErr:
|
||||||
raise newException(ValidationError, "Could not derive public key from computation")
|
raise newException(ValidationError, "Could not derive public key from computation")
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ proc calcMinerAddress(sigRaw: openArray[byte], vmState: BaseVMState, output: var
|
||||||
var sig: Signature
|
var sig: Signature
|
||||||
if sigRaw.getSignature(sig):
|
if sigRaw.getSignature(sig):
|
||||||
let headerHash = headerHashOriExtraData(vmState)
|
let headerHash = headerHashOriExtraData(vmState)
|
||||||
let pubkey = recover(sig, headerHash)
|
let pubkey = recover(sig, SKMessage(headerHash.data))
|
||||||
if pubkey.isOk:
|
if pubkey.isOk:
|
||||||
output = pubkey[].toCanonicalAddress()
|
output = pubkey[].toCanonicalAddress()
|
||||||
result = true
|
result = true
|
||||||
|
|
|
@ -11,7 +11,8 @@ import
|
||||||
testutils/markdown_reports,
|
testutils/markdown_reports,
|
||||||
../nimbus/[config, transaction, utils, errors],
|
../nimbus/[config, transaction, utils, errors],
|
||||||
../nimbus/vm/interpreter/vm_forks,
|
../nimbus/vm/interpreter/vm_forks,
|
||||||
../nimbus/db/accounts_cache
|
../nimbus/db/accounts_cache,
|
||||||
|
../nimbus/random_keys
|
||||||
|
|
||||||
func revmap(x: Table[Fork, string]): Table[string, Fork] =
|
func revmap(x: Table[Fork, string]): Table[string, Fork] =
|
||||||
result = initTable[string, Fork]()
|
result = initTable[string, Fork]()
|
||||||
|
@ -211,7 +212,7 @@ proc hashLogEntries*(logs: seq[Log]): string =
|
||||||
|
|
||||||
proc setupEthNode*(capabilities: varargs[ProtocolInfo, `protocolInfo`]): EthereumNode =
|
proc setupEthNode*(capabilities: varargs[ProtocolInfo, `protocolInfo`]): EthereumNode =
|
||||||
var conf = getConfiguration()
|
var conf = getConfiguration()
|
||||||
conf.net.nodekey = PrivateKey.random().tryGet()
|
conf.net.nodekey = randomPrivateKey()
|
||||||
let keypair = conf.net.nodekey.toKeyPair()
|
let keypair = conf.net.nodekey.toKeyPair()
|
||||||
|
|
||||||
var srvAddress: Address
|
var srvAddress: Address
|
||||||
|
|
Loading…
Reference in New Issue