2022-04-13 11:18:38 +00:00
|
|
|
import pkg/ethers
|
2022-04-25 13:12:37 +00:00
|
|
|
import pkg/chronicles
|
2022-04-13 11:18:38 +00:00
|
|
|
import ../purchasing
|
|
|
|
import ../sales
|
|
|
|
import ../proving
|
|
|
|
import ./deployment
|
2023-01-19 05:58:04 +00:00
|
|
|
import ./marketplace
|
2022-04-13 11:18:38 +00:00
|
|
|
import ./market
|
|
|
|
import ./proofs
|
2022-05-17 14:42:03 +00:00
|
|
|
import ./clock
|
2022-04-13 11:18:38 +00:00
|
|
|
|
|
|
|
export purchasing
|
|
|
|
export sales
|
|
|
|
export proving
|
2022-04-25 13:12:37 +00:00
|
|
|
export chronicles
|
2022-04-13 11:18:38 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
ContractInteractions* = ref object
|
|
|
|
purchasing*: Purchasing
|
|
|
|
sales*: Sales
|
|
|
|
proving*: Proving
|
2022-05-17 14:42:03 +00:00
|
|
|
clock: OnChainClock
|
2022-04-13 11:18:38 +00:00
|
|
|
|
|
|
|
proc new*(_: type ContractInteractions,
|
|
|
|
signer: Signer,
|
2022-04-25 13:12:37 +00:00
|
|
|
deployment: Deployment): ?ContractInteractions =
|
|
|
|
|
2023-01-19 05:58:04 +00:00
|
|
|
without address =? deployment.address(Marketplace):
|
|
|
|
error "Unable to determine address of the Marketplace smart contract"
|
2022-04-25 13:12:37 +00:00
|
|
|
return none ContractInteractions
|
|
|
|
|
2023-01-19 05:58:04 +00:00
|
|
|
let contract = Marketplace.new(address, signer)
|
2022-04-13 11:18:38 +00:00
|
|
|
let market = OnChainMarket.new(contract)
|
|
|
|
let proofs = OnChainProofs.new(contract)
|
2022-05-17 14:42:03 +00:00
|
|
|
let clock = OnChainClock.new(signer.provider)
|
2022-08-17 04:02:53 +00:00
|
|
|
let proving = Proving.new(proofs, clock)
|
2022-04-25 13:12:37 +00:00
|
|
|
some ContractInteractions(
|
2022-05-17 14:51:29 +00:00
|
|
|
purchasing: Purchasing.new(market, clock),
|
2022-08-17 04:02:53 +00:00
|
|
|
sales: Sales.new(market, clock, proving),
|
|
|
|
proving: proving,
|
2022-05-17 14:42:03 +00:00
|
|
|
clock: clock
|
2022-04-13 11:18:38 +00:00
|
|
|
)
|
|
|
|
|
2022-04-14 08:34:42 +00:00
|
|
|
proc new*(_: type ContractInteractions,
|
|
|
|
providerUrl: string,
|
2022-08-09 04:29:06 +00:00
|
|
|
account: Address,
|
|
|
|
deploymentFile: string = string.default): ?ContractInteractions =
|
2022-04-25 13:12:37 +00:00
|
|
|
|
2022-04-14 08:34:42 +00:00
|
|
|
let provider = JsonRpcProvider.new(providerUrl)
|
2022-08-09 04:29:06 +00:00
|
|
|
let signer = provider.getSigner(account)
|
2022-04-14 08:34:42 +00:00
|
|
|
|
2022-04-25 13:12:37 +00:00
|
|
|
var deploy: Deployment
|
|
|
|
try:
|
|
|
|
if deploymentFile == string.default:
|
|
|
|
deploy = deployment()
|
|
|
|
else:
|
|
|
|
deploy = deployment(deploymentFile)
|
|
|
|
except IOError as e:
|
|
|
|
error "Unable to read deployment json", msg = e.msg
|
|
|
|
return none ContractInteractions
|
|
|
|
|
|
|
|
ContractInteractions.new(signer, deploy)
|
|
|
|
|
2022-08-09 04:29:06 +00:00
|
|
|
proc new*(_: type ContractInteractions,
|
|
|
|
account: Address): ?ContractInteractions =
|
|
|
|
ContractInteractions.new("ws://localhost:8545", account)
|
2022-04-14 10:48:10 +00:00
|
|
|
|
|
|
|
proc start*(interactions: ContractInteractions) {.async.} =
|
2022-05-17 14:42:03 +00:00
|
|
|
await interactions.clock.start()
|
2022-05-17 14:40:57 +00:00
|
|
|
await interactions.sales.start()
|
2022-05-17 14:40:21 +00:00
|
|
|
await interactions.proving.start()
|
2022-11-08 07:10:17 +00:00
|
|
|
await interactions.purchasing.start()
|
2022-04-14 10:48:10 +00:00
|
|
|
|
|
|
|
proc stop*(interactions: ContractInteractions) {.async.} =
|
2022-11-08 07:10:17 +00:00
|
|
|
await interactions.purchasing.stop()
|
2022-05-17 14:40:57 +00:00
|
|
|
await interactions.sales.stop()
|
2022-05-17 14:40:21 +00:00
|
|
|
await interactions.proving.stop()
|
2022-05-17 14:42:03 +00:00
|
|
|
await interactions.clock.stop()
|