mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-02 14:03:06 +00:00
Changes:
modified: .gitmodules
modified: tests/waku_discv5/utils.nim
modified: tests/waku_enr/utils.nim
modified: tests/waku_rln_relay/test_rln_group_manager_onchain.nim
modified: tests/waku_rln_relay/utils.nim
modified: tests/waku_rln_relay/utils_onchain.nim
modified: vendor/nim-chronicles
modified: vendor/nim-eth
modified: vendor/nim-http-utils
modified: vendor/nim-json-rpc
modified: vendor/nim-json-serialization
modified: vendor/nim-libp2p - 1.8.0!
modified: vendor/nim-metrics
new file: vendor/nim-minilru
modified: vendor/nim-nat-traversal
modified: vendor/nim-presto
modified: vendor/nim-secp256k1
modified: vendor/nim-serialization
modified: vendor/nim-stew
modified: vendor/nim-taskpools
modified: vendor/nim-testutils
modified: vendor/nim-toml-serialization
modified: vendor/nim-unicodedb
modified: vendor/nim-unittest2
modified: vendor/nim-web3 - from distinct branch that solves Ethereum ABI issue.
modified: vendor/nim-websock
modified: vendor/nim-zlib
modified: vendor/nimcrypto
modified: waku.nimble
modified: waku/common/enr/builder.nim
modified: waku/common/enr/typed_record.nim
modified: waku/common/utils/nat.nim
modified: waku/discovery/waku_discv5.nim
modified: waku/waku_rln_relay/conversion_utils.nim
modified: waku/waku_rln_relay/group_manager/on_chain/group_manager.nim
modified: waku/waku_rln_relay/rln/wrappers.nim
modified: waku/waku_rln_relay/rln_relay.nim
* Eliminate C compilation issue with chat2bridge due to an overcomplicating import from json_rpc instead of using std/json
* Adapt ENR Record handling to new interface of nim-eth
* Fix chrash in group_manager on_chain
* Fix signature of register and MemberRegister to UInt256, check transaction success in register
* Upgrade json-rpc and serialization
* Update to match latest enr and nat interface
* Using of extracted result of contract macro - with necessary adaption
* Bump nim-chornicles, nim-libp2p, nimcrypto
* Bump nim-web3, nim-eth and deps - on_chain/group_manager.nim adaption
* Added status-im/nim-minilru submodule required by latest nim-eth
Fixing tests.
* group_manager: adapt smart contract param types
* update web3 vendor
* bump vendors for v0.35.0
* protobuf.nim: fix compilation error after nim-libp2p bump
* changes to make it compile after rebase from master
---------
Co-authored-by: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com>
86 lines
2.5 KiB
Nim
86 lines
2.5 KiB
Nim
{.push raises: [].}
|
|
|
|
import
|
|
std/[options, net],
|
|
results,
|
|
eth/keys as eth_keys,
|
|
eth/p2p/discoveryv5/enr,
|
|
libp2p/crypto/crypto as libp2p_crypto
|
|
|
|
import ./typed_record
|
|
|
|
## Builder
|
|
|
|
type EnrBuilder* = object
|
|
seqNumber: uint64
|
|
privateKey: eth_keys.PrivateKey
|
|
ipAddress: Opt[IpAddress]
|
|
tcpPort: Opt[Port]
|
|
udpPort: Opt[Port]
|
|
fields: seq[FieldPair]
|
|
|
|
proc init*(T: type EnrBuilder, key: eth_keys.PrivateKey, seqNum: uint64 = 1): T =
|
|
EnrBuilder(
|
|
seqNumber: seqNum,
|
|
privateKey: key,
|
|
ipAddress: Opt.none(IpAddress),
|
|
tcpPort: Opt.none(Port),
|
|
udpPort: Opt.none(Port),
|
|
fields: newSeq[FieldPair](),
|
|
)
|
|
|
|
proc init*(T: type EnrBuilder, key: libp2p_crypto.PrivateKey, seqNum: uint64 = 1): T =
|
|
# TODO: Inconvenient runtime assertion. Move this assertion to compile time
|
|
if key.scheme != PKScheme.Secp256k1:
|
|
raise newException(Defect, "invalid private key scheme")
|
|
|
|
let
|
|
bytes = key.getRawBytes().expect("Private key is valid")
|
|
privateKey =
|
|
eth_keys.PrivateKey.fromRaw(bytes).expect("Raw private key is of valid length")
|
|
|
|
EnrBuilder.init(key = privateKey, seqNum = seqNum)
|
|
|
|
proc addFieldPair*(builder: var EnrBuilder, pair: FieldPair) =
|
|
builder.fields.add(pair)
|
|
|
|
proc addFieldPair*[V](builder: var EnrBuilder, key: string, value: V) =
|
|
builder.addFieldPair(toFieldPair(key, value))
|
|
|
|
proc build*(builder: EnrBuilder): EnrResult[enr.Record] =
|
|
# Note that nim-eth's `Record.init` does not deduplicate the field pairs.
|
|
# See: https://github.com/status-im/nim-eth/blob/4b22fcd/eth/p2p/discoveryv5/enr.nim#L143-L144
|
|
enr.Record.init(
|
|
seqNum = builder.seqNumber,
|
|
pk = builder.privateKey,
|
|
ip = builder.ipAddress,
|
|
tcpPort = builder.tcpPort,
|
|
udpPort = builder.udpPort,
|
|
extraFields = builder.fields,
|
|
)
|
|
|
|
## Builder extension: IP address and TCP/UDP ports
|
|
|
|
proc addAddressAndPorts(
|
|
builder: var EnrBuilder, ip: IpAddress, tcpPort, udpPort: Option[Port]
|
|
) =
|
|
builder.ipAddress = Opt.some(ip)
|
|
builder.tcpPort = tcpPort.toOpt()
|
|
builder.udpPort = udpPort.toOpt()
|
|
|
|
proc addPorts(builder: var EnrBuilder, tcp, udp: Option[Port]) =
|
|
# Based on: https://github.com/status-im/nim-eth/blob/4b22fcd/eth/p2p/discoveryv5/enr.nim#L166
|
|
builder.tcpPort = tcp.toOpt()
|
|
builder.udpPort = udp.toOpt()
|
|
|
|
proc withIpAddressAndPorts*(
|
|
builder: var EnrBuilder,
|
|
ipAddr = none(IpAddress),
|
|
tcpPort = none(Port),
|
|
udpPort = none(Port),
|
|
) =
|
|
if ipAddr.isSome():
|
|
addAddressAndPorts(builder, ipAddr.get(), tcpPort, udpPort)
|
|
else:
|
|
addPorts(builder, tcpPort, udpPort)
|