[contracts] Start contract interactions when node starts

This commit is contained in:
Mark Spanbroek 2022-04-14 12:48:10 +02:00 committed by markspanbroek
parent 142ddd0fd3
commit 59f75fc540
3 changed files with 18 additions and 1 deletions

View File

@ -42,3 +42,11 @@ proc new*(_: type ContractInteractions,
proc new*(_: type ContractInteractions): ContractInteractions =
ContractInteractions.new("ws://localhost:8545")
proc start*(interactions: ContractInteractions) {.async.} =
interactions.sales.start()
interactions.proving.start()
proc stop*(interactions: ContractInteractions) {.async.} =
interactions.sales.stop()
interactions.proving.stop()

View File

@ -51,6 +51,9 @@ proc start*(node: DaggerNodeRef) {.async.} =
await node.erasure.start()
await node.discovery.start()
if not node.contracts.isNil:
await node.contracts.start()
node.networkId = node.switch.peerInfo.peerId
notice "Started dagger node", id = $node.networkId, addrs = node.switch.peerInfo.addrs
@ -62,6 +65,9 @@ proc stop*(node: DaggerNodeRef) {.async.} =
await node.erasure.stop()
await node.discovery.stop()
if not node.contracts.isNil:
await node.contracts.stop()
proc findPeer*(
node: DaggerNodeRef,
peerId: PeerID): Future[?PeerRecord] {.async.} =

View File

@ -17,6 +17,7 @@ import pkg/dagger/node
import pkg/dagger/manifest
import pkg/dagger/discovery
import pkg/dagger/blocktype as bt
import pkg/dagger/contracts
import ./helpers
@ -35,6 +36,7 @@ suite "Test Node":
store: NetworkStore
node: DaggerNodeRef
discovery: Discovery
contracts: ContractInteractions
setup:
file = open(path.splitFile().dir /../ "fixtures" / "test.jpg")
@ -46,7 +48,8 @@ suite "Test Node":
discovery = Discovery.new(switch.peerInfo, Port(0))
engine = BlockExcEngine.new(localStore, wallet, network, discovery)
store = NetworkStore.new(engine, localStore)
node = DaggerNodeRef.new(switch, store, engine, nil, discovery, nil) # TODO: pass `Erasure`
contracts = ContractInteractions.new()
node = DaggerNodeRef.new(switch, store, engine, nil, discovery, contracts) # TODO: pass `Erasure`
await node.start()