mirror of
https://github.com/status-im/nim-eth.git
synced 2025-02-16 07:56:38 +00:00
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,
|
proc newEthereumNode*(keys: KeyPair,
|
||||||
address: Address,
|
address: Address,
|
||||||
networkId: uint,
|
networkId: NetworkId,
|
||||||
chain: AbstractChainDB,
|
chain: AbstractChainDB,
|
||||||
clientId = "nim-eth-p2p/0.2.0", # TODO: read this value from nimble somehow
|
clientId = "nim-eth-p2p/0.2.0", # TODO: read this value from nimble somehow
|
||||||
addAllCapabilities = true,
|
addAllCapabilities = true,
|
||||||
|
@ -11,7 +11,7 @@ const
|
|||||||
connectLoopSleep = chronos.milliseconds(2000)
|
connectLoopSleep = chronos.milliseconds(2000)
|
||||||
|
|
||||||
proc newPeerPool*(network: EthereumNode,
|
proc newPeerPool*(network: EthereumNode,
|
||||||
networkId: uint, keyPair: KeyPair,
|
networkId: NetworkId, keyPair: KeyPair,
|
||||||
discovery: DiscoveryProtocol, clientId: string,
|
discovery: DiscoveryProtocol, clientId: string,
|
||||||
listenPort = Port(30303), minPeers = 10): PeerPool =
|
listenPort = Port(30303), minPeers = 10): PeerPool =
|
||||||
new result
|
new result
|
||||||
|
@ -7,8 +7,10 @@ const
|
|||||||
useSnappy* = defined(useSnappy)
|
useSnappy* = defined(useSnappy)
|
||||||
|
|
||||||
type
|
type
|
||||||
|
NetworkId* = distinct uint
|
||||||
|
|
||||||
EthereumNode* = ref object
|
EthereumNode* = ref object
|
||||||
networkId*: uint
|
networkId*: NetworkId
|
||||||
chain*: AbstractChainDB
|
chain*: AbstractChainDB
|
||||||
clientId*: string
|
clientId*: string
|
||||||
connectionState*: ConnectionState
|
connectionState*: ConnectionState
|
||||||
@ -46,7 +48,7 @@ type
|
|||||||
# Private fields:
|
# Private fields:
|
||||||
network*: EthereumNode
|
network*: EthereumNode
|
||||||
keyPair*: KeyPair
|
keyPair*: KeyPair
|
||||||
networkId*: uint
|
networkId*: NetworkId
|
||||||
minPeers*: int
|
minPeers*: int
|
||||||
clientId*: string
|
clientId*: string
|
||||||
discovery*: DiscoveryProtocol
|
discovery*: DiscoveryProtocol
|
||||||
@ -171,3 +173,15 @@ proc `$`*(peer: Peer): string = $peer.remote
|
|||||||
|
|
||||||
proc toENode*(v: EthereumNode): ENode =
|
proc toENode*(v: EthereumNode): ENode =
|
||||||
ENode(pubkey: v.keys.pubkey, address: v.address)
|
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:
|
handshake:
|
||||||
proc status(peer: Peer,
|
proc status(peer: Peer,
|
||||||
protocolVersion: uint,
|
protocolVersion: uint,
|
||||||
networkId: uint,
|
networkId: NetworkId,
|
||||||
totalDifficulty: DifficultyInt,
|
totalDifficulty: DifficultyInt,
|
||||||
bestHash: KeccakHash,
|
bestHash: KeccakHash,
|
||||||
genesisHash: KeccakHash)
|
genesisHash: KeccakHash)
|
||||||
|
@ -206,7 +206,7 @@ p2pProtocol les(version = lesVersion,
|
|||||||
|
|
||||||
let
|
let
|
||||||
s = await peer.status(lesProperties, timeout = chronos.seconds(10))
|
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)
|
peerGenesisHash = s.values.getRequiredValue(keyGenesisHash, KeccakHash)
|
||||||
peerLesVersion = s.values.getRequiredValue(keyProtocolVersion, uint)
|
peerLesVersion = s.values.getRequiredValue(keyProtocolVersion, uint)
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ proc setupTestNode*(
|
|||||||
capabilities: varargs[ProtocolInfo, `protocolInfo`]): EthereumNode {.gcsafe.} =
|
capabilities: varargs[ProtocolInfo, `protocolInfo`]): EthereumNode {.gcsafe.} =
|
||||||
# Don't create new RNG every time in production code!
|
# Don't create new RNG every time in production code!
|
||||||
let keys1 = KeyPair.random(rng[])
|
let keys1 = KeyPair.random(rng[])
|
||||||
result = newEthereumNode(keys1, localAddress(nextPort), 1, nil,
|
result = newEthereumNode(keys1, localAddress(nextPort), NetworkId(1), nil,
|
||||||
addAllCapabilities = false, rng = rng)
|
addAllCapabilities = false, rng = rng)
|
||||||
nextPort.inc
|
nextPort.inc
|
||||||
for capability in capabilities:
|
for capability in capabilities:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user