mirror of https://github.com/status-im/nim-eth.git
turn networkId into distinct uint
This commit is contained in:
parent
e8c9691b35
commit
dda2bec8aa
|
@ -33,7 +33,7 @@ template addCapability*(node: var EthereumNode, Protocol: type) =
|
|||
|
||||
proc newEthereumNode*(keys: KeyPair,
|
||||
address: Address,
|
||||
networkId: uint,
|
||||
networkId: NetworkId,
|
||||
chain: AbstractChainDB,
|
||||
clientId = "nim-eth-p2p/0.2.0", # TODO: read this value from nimble somehow
|
||||
addAllCapabilities = true,
|
||||
|
|
|
@ -11,7 +11,7 @@ const
|
|||
connectLoopSleep = chronos.milliseconds(2000)
|
||||
|
||||
proc newPeerPool*(network: EthereumNode,
|
||||
networkId: uint, keyPair: KeyPair,
|
||||
networkId: NetworkId, keyPair: KeyPair,
|
||||
discovery: DiscoveryProtocol, clientId: string,
|
||||
listenPort = Port(30303), minPeers = 10): PeerPool =
|
||||
new result
|
||||
|
|
|
@ -7,8 +7,10 @@ const
|
|||
useSnappy* = defined(useSnappy)
|
||||
|
||||
type
|
||||
NetworkId* = distinct uint
|
||||
|
||||
EthereumNode* = ref object
|
||||
networkId*: uint
|
||||
networkId*: NetworkId
|
||||
chain*: AbstractChainDB
|
||||
clientId*: string
|
||||
connectionState*: ConnectionState
|
||||
|
@ -46,7 +48,7 @@ type
|
|||
# Private fields:
|
||||
network*: EthereumNode
|
||||
keyPair*: KeyPair
|
||||
networkId*: uint
|
||||
networkId*: NetworkId
|
||||
minPeers*: int
|
||||
clientId*: string
|
||||
discovery*: DiscoveryProtocol
|
||||
|
@ -171,3 +173,15 @@ proc `$`*(peer: Peer): string = $peer.remote
|
|||
|
||||
proc toENode*(v: EthereumNode): ENode =
|
||||
ENode(pubkey: v.keys.pubkey, address: v.address)
|
||||
|
||||
proc append*(rlpWriter: var RlpWriter, id: NetworkId) {.inline.} =
|
||||
rlpWriter.append(id.uint)
|
||||
|
||||
proc read*(rlp: var Rlp, T: type NetworkId): T {.inline.} =
|
||||
rlp.read(uint).NetworkId
|
||||
|
||||
func `==`*(a, b: NetworkId): bool {.inline.} =
|
||||
a.uint == b.uint
|
||||
|
||||
func `$`*(x: NetworkId): string {.inline.} =
|
||||
`$`(uint(x))
|
||||
|
|
|
@ -64,7 +64,7 @@ p2pProtocol eth(version = protocolVersion,
|
|||
handshake:
|
||||
proc status(peer: Peer,
|
||||
protocolVersion: uint,
|
||||
networkId: uint,
|
||||
networkId: NetworkId,
|
||||
totalDifficulty: DifficultyInt,
|
||||
bestHash: KeccakHash,
|
||||
genesisHash: KeccakHash)
|
||||
|
|
|
@ -206,7 +206,7 @@ p2pProtocol les(version = lesVersion,
|
|||
|
||||
let
|
||||
s = await peer.status(lesProperties, timeout = chronos.seconds(10))
|
||||
peerNetworkId = s.values.getRequiredValue(keyNetworkId, uint)
|
||||
peerNetworkId = s.values.getRequiredValue(keyNetworkId, NetworkId)
|
||||
peerGenesisHash = s.values.getRequiredValue(keyGenesisHash, KeccakHash)
|
||||
peerLesVersion = s.values.getRequiredValue(keyProtocolVersion, uint)
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ proc setupTestNode*(
|
|||
capabilities: varargs[ProtocolInfo, `protocolInfo`]): EthereumNode {.gcsafe.} =
|
||||
# Don't create new RNG every time in production code!
|
||||
let keys1 = KeyPair.random(rng[])
|
||||
result = newEthereumNode(keys1, localAddress(nextPort), 1, nil,
|
||||
result = newEthereumNode(keys1, localAddress(nextPort), NetworkId(1), nil,
|
||||
addAllCapabilities = false, rng = rng)
|
||||
nextPort.inc
|
||||
for capability in capabilities:
|
||||
|
|
Loading…
Reference in New Issue