2025-03-18 14:31:10 +01:00
|
|
|
import pkg/ethers
|
|
|
|
|
import pkg/questionable
|
2025-03-18 13:42:22 +01:00
|
|
|
import ./marketplace/market
|
2025-03-18 14:31:10 +01:00
|
|
|
import ./marketplace/marketplace
|
|
|
|
|
import ../config
|
2025-03-18 14:55:52 +01:00
|
|
|
import ../component
|
|
|
|
|
import ../state
|
2025-03-11 09:34:33 +01:00
|
|
|
|
2025-03-18 14:55:52 +01:00
|
|
|
logScope:
|
|
|
|
|
topics = "marketplace"
|
2025-03-18 14:31:10 +01:00
|
|
|
|
2025-03-18 15:55:58 +01:00
|
|
|
type MarketplaceService* = ref object of Component
|
|
|
|
|
state: State
|
|
|
|
|
market: ?OnChainMarket
|
2025-03-18 14:31:10 +01:00
|
|
|
|
2025-03-18 15:55:58 +01:00
|
|
|
method getRecentSlotFillEvents*(
|
|
|
|
|
m: MarketplaceService
|
|
|
|
|
): Future[?!seq[SlotFilled]] {.async: (raises: []), base.} =
|
2025-03-18 15:05:35 +01:00
|
|
|
# There is (aprox.) 1 block every 10 seconds.
|
|
|
|
|
# 10 seconds * 6 * 60 = 3600 = 1 hour.
|
2025-03-18 15:55:58 +01:00
|
|
|
let blocksAgo = 6 * 60
|
2025-03-18 15:05:35 +01:00
|
|
|
|
|
|
|
|
if market =? m.market:
|
|
|
|
|
try:
|
|
|
|
|
return success(await market.queryPastSlotFilledEvents(blocksAgo))
|
|
|
|
|
except CatchableError as err:
|
|
|
|
|
return failure(err.msg)
|
|
|
|
|
return failure("MarketplaceService is not started")
|
2025-03-18 14:55:52 +01:00
|
|
|
|
|
|
|
|
method start*(m: MarketplaceService): Future[?!void] {.async.} =
|
2025-03-19 15:25:17 +01:00
|
|
|
# Todo:
|
|
|
|
|
# - subscribe to requestSubmitted -> add id to list
|
|
|
|
|
# - queryPastStorageRequestedEvents from 3 months ago (max duration) -> add ids to list
|
|
|
|
|
# for list:
|
|
|
|
|
# - get status of request
|
|
|
|
|
# if running:
|
|
|
|
|
# - sum total bytes
|
|
|
|
|
# else:
|
|
|
|
|
# - remove from list
|
|
|
|
|
|
2025-03-18 14:55:52 +01:00
|
|
|
let provider = JsonRpcProvider.new(m.state.config.ethProvider)
|
|
|
|
|
without marketplaceAddress =? Address.init(m.state.config.marketplaceAddress):
|
|
|
|
|
return failure("Invalid MarketplaceAddress provided")
|
2025-03-18 14:31:10 +01:00
|
|
|
|
2025-03-18 14:55:52 +01:00
|
|
|
let marketplace = Marketplace.new(marketplaceAddress, provider)
|
|
|
|
|
m.market = some(OnChainMarket.new(marketplace))
|
|
|
|
|
|
|
|
|
|
return success()
|
|
|
|
|
|
|
|
|
|
method stop*(m: MarketplaceService): Future[?!void] {.async.} =
|
|
|
|
|
return success()
|
|
|
|
|
|
2025-03-18 15:55:58 +01:00
|
|
|
proc new(T: type MarketplaceService, state: State): MarketplaceService =
|
|
|
|
|
return MarketplaceService(state: state, market: none(OnChainMarket))
|
2025-03-18 14:55:52 +01:00
|
|
|
|
|
|
|
|
proc createMarketplace*(state: State): MarketplaceService =
|
2025-03-18 15:55:58 +01:00
|
|
|
return MarketplaceService.new(state)
|