2023-01-18 15:00:14 +00:00
|
|
|
# Nimbus
|
2024-02-04 14:28:20 +00:00
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
2023-01-18 15:00:14 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed
|
|
|
|
# except according to those terms.
|
|
|
|
|
2023-03-07 14:23:22 +00:00
|
|
|
{.used, push raises: [].}
|
|
|
|
|
2023-01-18 15:00:14 +00:00
|
|
|
import
|
|
|
|
eth/p2p,
|
|
|
|
../../core/[chain, tx_pool],
|
|
|
|
../protocol,
|
2023-09-08 08:21:59 +00:00
|
|
|
./eth as handlers_eth
|
2023-01-18 15:00:14 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions: convenience mappings for `eth`
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc setEthHandlerNewBlocksAndHashes*(
|
2023-09-09 06:54:58 +00:00
|
|
|
node: EthereumNode;
|
2023-01-18 15:00:14 +00:00
|
|
|
blockHandler: NewBlockHandler;
|
|
|
|
hashesHandler: NewBlockHashesHandler;
|
2023-01-20 15:01:29 +00:00
|
|
|
arg: pointer;
|
2023-01-30 22:10:23 +00:00
|
|
|
) {.gcsafe, raises: [CatchableError].} =
|
2023-01-18 15:00:14 +00:00
|
|
|
let w = EthWireRef(node.protocolState protocol.eth)
|
|
|
|
w.setNewBlockHandler(blockHandler, arg)
|
|
|
|
w.setNewBlockHashesHandler(hashesHandler, arg)
|
|
|
|
|
|
|
|
proc addEthHandlerCapability*(
|
2023-09-09 06:54:58 +00:00
|
|
|
node: EthereumNode;
|
2023-01-20 15:01:29 +00:00
|
|
|
peerPool: PeerPool;
|
2023-01-18 15:00:14 +00:00
|
|
|
chain: ChainRef;
|
2023-01-20 15:01:29 +00:00
|
|
|
txPool = TxPoolRef(nil);
|
|
|
|
) =
|
|
|
|
## Install `eth` handlers. Passing `txPool` as `nil` installs the handler
|
|
|
|
## in minimal/outbound mode.
|
2023-01-18 15:00:14 +00:00
|
|
|
node.addCapability(
|
|
|
|
protocol.eth,
|
|
|
|
EthWireRef.new(chain, txPool, peerPool))
|
2023-01-20 15:01:29 +00:00
|
|
|
|
2023-01-18 15:00:14 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions: convenience mappings for `snap`
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-05-20 10:17:51 +00:00
|
|
|
when false: # needs to be updated
|
|
|
|
import
|
|
|
|
./snap as handlers_snap
|
2023-09-09 06:54:58 +00:00
|
|
|
|
2024-05-20 10:17:51 +00:00
|
|
|
proc addSnapHandlerCapability*(
|
|
|
|
node: EthereumNode;
|
|
|
|
peerPool: PeerPool;
|
|
|
|
chain = ChainRef(nil);
|
|
|
|
) =
|
|
|
|
## Install `snap` handlers,Passing `chein` as `nil` installs the handler
|
|
|
|
## in minimal/outbound mode.
|
|
|
|
if chain.isNil:
|
|
|
|
node.addCapability protocol.snap
|
|
|
|
else:
|
|
|
|
node.addCapability(protocol.snap, SnapWireRef.init(chain, peerPool))
|
2023-01-18 15:00:14 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|