From 6a8a6c252f32be82ef42ff8329be6010655e515a Mon Sep 17 00:00:00 2001 From: thatben Date: Tue, 18 Mar 2025 15:55:58 +0100 Subject: [PATCH] formatting --- codexcrawler/components/chainmetrics.nim | 7 +++-- codexcrawler/config.nim | 4 +-- codexcrawler/services/marketplace.nim | 27 +++++++------------ codexcrawler/services/metrics.nim | 5 ++-- .../components/testchainmetrics.nim | 11 +++----- tests/codexcrawler/mocks/mockmarketplace.nim | 9 ++++--- 6 files changed, 28 insertions(+), 35 deletions(-) diff --git a/codexcrawler/components/chainmetrics.nim b/codexcrawler/components/chainmetrics.nim index 3aaf68c..9691192 100644 --- a/codexcrawler/components/chainmetrics.nim +++ b/codexcrawler/components/chainmetrics.nim @@ -26,7 +26,7 @@ proc step(c: ChainMetrics): Future[?!void] {.async: (raises: []).} = return success() method start*(c: ChainMetrics): Future[?!void] {.async.} = - info "Starting..." + info "Starting..." proc onStep(): Future[?!void] {.async: (raises: []), gcsafe.} = return await c.step() @@ -40,6 +40,9 @@ method stop*(c: ChainMetrics): Future[?!void] {.async.} = return success() proc new*( - T: type ChainMetrics, state: State, metrics: Metrics, marketplace: MarketplaceService + T: type ChainMetrics, + state: State, + metrics: Metrics, + marketplace: MarketplaceService, ): ChainMetrics = ChainMetrics(state: state, metrics: metrics, marketplace: marketplace) diff --git a/codexcrawler/config.nim b/codexcrawler/config.nim index f599a71..bc56e40 100644 --- a/codexcrawler/config.nim +++ b/codexcrawler/config.nim @@ -25,8 +25,8 @@ Options: --revisitDelay= Delay in minutes after which a node can be revisited [default: 60] --checkDelay= Delay with which the 'revisitDelay' is checked for all known nodes [default: 10] --expiryDelay= Delay in minutes after which unresponsive nodes are discarded [default: 1440] (24h) - --ethProvider= Address including http(s) or ws of the eth provider - --marketplaceAddress= Eth address of Codex contracts deployment + --ethProvider= Address including http(s) or ws of the eth provider + --marketplaceAddress= Eth address of Codex contracts deployment --marketplaceEnable= Set to "1" to enable marketplace metrics [default: 1] """ diff --git a/codexcrawler/services/marketplace.nim b/codexcrawler/services/marketplace.nim index 318032e..c959a22 100644 --- a/codexcrawler/services/marketplace.nim +++ b/codexcrawler/services/marketplace.nim @@ -9,15 +9,16 @@ import ../state logScope: topics = "marketplace" -type - MarketplaceService* = ref object of Component - state: State - market: ?OnChainMarket +type MarketplaceService* = ref object of Component + state: State + market: ?OnChainMarket -method getRecentSlotFillEvents*(m: MarketplaceService): Future[?!seq[SlotFilled]] {.async: (raises: []), base.} = +method getRecentSlotFillEvents*( + m: MarketplaceService +): Future[?!seq[SlotFilled]] {.async: (raises: []), base.} = # There is (aprox.) 1 block every 10 seconds. # 10 seconds * 6 * 60 = 3600 = 1 hour. - let blocksAgo = 6 * 60; + let blocksAgo = 6 * 60 if market =? m.market: try: @@ -39,16 +40,8 @@ method start*(m: MarketplaceService): Future[?!void] {.async.} = method stop*(m: MarketplaceService): Future[?!void] {.async.} = return success() -proc new( - T: type MarketplaceService, - state: State -): MarketplaceService = - return MarketplaceService( - state: state, - market: none(OnChainMarket) - ) +proc new(T: type MarketplaceService, state: State): MarketplaceService = + return MarketplaceService(state: state, market: none(OnChainMarket)) proc createMarketplace*(state: State): MarketplaceService = - return MarketplaceService.new( - state - ) + return MarketplaceService.new(state) diff --git a/codexcrawler/services/metrics.nim b/codexcrawler/services/metrics.nim index 322b80c..13115ed 100644 --- a/codexcrawler/services/metrics.nim +++ b/codexcrawler/services/metrics.nim @@ -53,8 +53,9 @@ proc createMetrics*(metricsAddress: IpAddress, metricsPort: Port): Metrics = proc onNok(value: int64) = nokNodesGauge.set(value) - + proc onSlotFill(value: int64) = slotFillGauge.set(value) - return Metrics(todoNodes: onTodo, okNodes: onOk, nokNodes: onNok, onSlotFill: onSlotFill) + return + Metrics(todoNodes: onTodo, okNodes: onOk, nokNodes: onNok, onSlotFill: onSlotFill) diff --git a/tests/codexcrawler/components/testchainmetrics.nim b/tests/codexcrawler/components/testchainmetrics.nim index 4668e41..99c2a89 100644 --- a/tests/codexcrawler/components/testchainmetrics.nim +++ b/tests/codexcrawler/components/testchainmetrics.nim @@ -24,7 +24,7 @@ suite "ChainMetrics": state = createMockState() metrics = createMockMetrics() marketplace = createMockMarketplaceService() - + metrics.slotFill = -1 chain = ChainMetrics.new(state, metrics, marketplace) @@ -75,14 +75,9 @@ suite "ChainMetrics": metrics.slotFill == 0 test "step should setSlotFill to the length of seq returned from getRecentSlotFillEvents": - let fills = @[ - SlotFilled(), - SlotFilled(), - SlotFilled(), - SlotFilled() - ] + let fills = @[SlotFilled(), SlotFilled(), SlotFilled(), SlotFilled()] - marketplace.recentSlotFillEventsReturn = success(fills) + marketplace.recentSlotFillEventsReturn = success(fills) await onStep() diff --git a/tests/codexcrawler/mocks/mockmarketplace.nim b/tests/codexcrawler/mocks/mockmarketplace.nim index bf4a717..2956e8d 100644 --- a/tests/codexcrawler/mocks/mockmarketplace.nim +++ b/tests/codexcrawler/mocks/mockmarketplace.nim @@ -7,11 +7,12 @@ import ../../../codexcrawler/services/marketplace/market logScope: topics = "marketplace" -type - MockMarketplaceService* = ref object of MarketplaceService - recentSlotFillEventsReturn*: ?!seq[SlotFilled] +type MockMarketplaceService* = ref object of MarketplaceService + recentSlotFillEventsReturn*: ?!seq[SlotFilled] -method getRecentSlotFillEvents*(m: MockMarketplaceService): Future[?!seq[SlotFilled]] {.async: (raises: []).} = +method getRecentSlotFillEvents*( + m: MockMarketplaceService +): Future[?!seq[SlotFilled]] {.async: (raises: []).} = return m.recentSlotFillEventsReturn proc createMockMarketplaceService*(): MockMarketplaceService =