mirror of https://github.com/status-im/nim-eth.git
Networkid common (#547)
* Move NetworkId type to common eth_types NetworkId is after all a common type and this way it avoid an application that requires it to also import all devp2p related network types. RLP related calls are moved to eth_types_rlp, this means that p2p protocols that send NetworkId over the wire need to import this too. Or just common in general. * Remove # in front of multiline comment end bracket These seem to be interpreted wrongly by the GitHub code browser.
This commit is contained in:
parent
cc52ef35e4
commit
fef47331c3
|
@ -51,6 +51,8 @@ type
|
|||
# they are separate entity
|
||||
ChainId* = distinct uint64
|
||||
|
||||
NetworkId* = distinct uint
|
||||
|
||||
Account* = object
|
||||
nonce*: AccountNonce
|
||||
balance*: UInt256
|
||||
|
@ -284,3 +286,9 @@ template hasData*(r: EthResourceRefs): bool = r != nil
|
|||
template deref*(b: Blob): auto = b
|
||||
template deref*(o: Option): auto = o.get
|
||||
template deref*(r: EthResourceRefs): auto = r[]
|
||||
|
||||
func `==`*(a, b: NetworkId): bool =
|
||||
a.uint == b.uint
|
||||
|
||||
func `$`*(x: NetworkId): string =
|
||||
`$`(uint(x))
|
||||
|
|
|
@ -336,3 +336,8 @@ proc rlpHash*[T](v: T): Hash256 =
|
|||
|
||||
func blockHash*(h: BlockHeader): KeccakHash {.inline.} = rlpHash(h)
|
||||
|
||||
proc append*(rlpWriter: var RlpWriter, id: NetworkId) =
|
||||
rlpWriter.append(id.uint)
|
||||
|
||||
proc read*(rlp: var Rlp, T: type NetworkId): T =
|
||||
rlp.read(uint).NetworkId
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# nim-eth
|
||||
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
||||
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
||||
# Licensed and distributed under either of
|
||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||
|
@ -73,7 +73,7 @@ proc newEthereumNode*(
|
|||
keys: KeyPair,
|
||||
address: Address,
|
||||
networkId: NetworkId,
|
||||
clientId = "nim-eth-p2p/0.2.0", # TODO: read this value from nimble somehow
|
||||
clientId = "nim-eth-p2p",
|
||||
addAllCapabilities = true,
|
||||
useCompression: bool = false,
|
||||
minPeers = 10,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
# nim-eth
|
||||
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
||||
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
||||
# Licensed and distributed under either of
|
||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||
|
@ -10,15 +9,15 @@ import
|
|||
std/[deques, tables],
|
||||
chronos,
|
||||
stew/results,
|
||||
".."/../[rlp, keys],
|
||||
".."/../[rlp, keys], ../../common/eth_types,
|
||||
".."/[enode, kademlia, discovery, rlpxcrypt]
|
||||
|
||||
export eth_types.NetworkId
|
||||
|
||||
const
|
||||
useSnappy* = defined(useSnappy)
|
||||
|
||||
type
|
||||
NetworkId* = distinct uint
|
||||
|
||||
EthereumNode* = ref object
|
||||
networkId*: NetworkId
|
||||
clientId*: string
|
||||
|
@ -188,15 +187,3 @@ 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))
|
||||
|
|
|
@ -525,7 +525,7 @@ proc getRlpxHeaderData(header: RlpxHeader): (int,int,int) =
|
|||
capabilityId = result[0],
|
||||
contextId = result[1],
|
||||
datagramSize = datagramSize()
|
||||
#]#
|
||||
]#
|
||||
except:
|
||||
error "RLPx message header-data options, parse error",
|
||||
capabilityId = result[0],
|
||||
|
@ -659,7 +659,7 @@ proc recvMsg*(peer: Peer): Future[tuple[msgId: int, msgData: Rlp]] {.async.} =
|
|||
trace "RLPx next chunked datagram fragment",
|
||||
peer, msgId = result[0], ctxId, msgSize, moreData, totalMsgSize,
|
||||
dcrBytesCount, payloadSoFar = decryptedBytes.len
|
||||
#]#
|
||||
]#
|
||||
|
||||
# End While
|
||||
|
||||
|
|
Loading…
Reference in New Issue