diff --git a/codex/contracts/requests.nim b/codex/contracts/requests.nim index 0172701d..cae3c55a 100644 --- a/codex/contracts/requests.nim +++ b/codex/contracts/requests.nim @@ -16,7 +16,7 @@ type size*: UInt256 duration*: UInt256 proofProbability*: UInt256 - maxPrice*: UInt256 + reward*: UInt256 StorageContent* = object cid*: string erasure*: StorageErasure @@ -44,7 +44,7 @@ func fromTuple(_: type StorageAsk, tupl: tuple): StorageAsk = size: tupl[0], duration: tupl[1], proofProbability: tupl[2], - maxPrice: tupl[3] + reward: tupl[3] ) func fromTuple(_: type StorageContent, tupl: tuple): StorageContent = diff --git a/codex/node.nim b/codex/node.nim index 196e1df4..4caf83e2 100644 --- a/codex/node.nim +++ b/codex/node.nim @@ -220,7 +220,7 @@ proc requestStorage*(self: CodexNodeRef, duration: UInt256, nodes: uint, tolerance: uint, - maxPrice: UInt256, + reward: UInt256, expiry = UInt256.none): Future[?!array[32, byte]] {.async.} = ## Initiate a request for storage sequence, this might ## be a multistep procedure. @@ -231,7 +231,7 @@ proc requestStorage*(self: CodexNodeRef, ## - Run the PoR setup on the erasure dataset ## - Call into the marketplace and purchasing contracts ## - trace "Received a request for storage!", cid, duration, nodes, tolerance, maxPrice + trace "Received a request for storage!", cid, duration, nodes, tolerance, reward without contracts =? self.contracts: trace "Purchasing not available" @@ -262,7 +262,7 @@ proc requestStorage*(self: CodexNodeRef, ask: StorageAsk( size: encoded.size.u256, duration: duration, - maxPrice: maxPrice + reward: reward ), content: StorageContent( cid: $encodedBlk.cid, diff --git a/codex/rest/api.nim b/codex/rest/api.nim index eb3f8ddd..8e062db2 100644 --- a/codex/rest/api.nim +++ b/codex/rest/api.nim @@ -192,7 +192,7 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter = ## ## cid - the cid of a previously uploaded dataset ## duration - the duration of the contract - ## maxPrice - the maximum price the client is willing to pay + ## reward - the maximum price the client is willing to pay # TODO: store on multiple nodes let nodes: uint = 1 @@ -210,7 +210,7 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter = params.duration, nodes, tolerance, - params.maxPrice, + params.reward, params.expiry), error: return RestApiResponse.error(Http500, error.msg) diff --git a/codex/rest/json.nim b/codex/rest/json.nim index 0d558f65..3ee7471e 100644 --- a/codex/rest/json.nim +++ b/codex/rest/json.nim @@ -8,7 +8,7 @@ import ../purchasing type StorageRequestParams* = object duration*: UInt256 - maxPrice*: UInt256 + reward*: UInt256 expiry*: ?UInt256 proc fromJson*(_: type Availability, bytes: seq[byte]): ?!Availability = @@ -22,11 +22,11 @@ proc fromJson*(_: type StorageRequestParams, bytes: seq[byte]): ?! StorageRequestParams = let json = ?catch parseJson(string.fromBytes(bytes)) let duration = ?catch UInt256.fromHex(json["duration"].getStr) - let maxPrice = ?catch UInt256.fromHex(json["maxPrice"].getStr) + let reward = ?catch UInt256.fromHex(json["reward"].getStr) let expiry = UInt256.fromHex(json["expiry"].getStr).catch.option success StorageRequestParams( duration: duration, - maxPrice: maxPrice, + reward: reward, expiry: expiry ) diff --git a/codex/sales.nim b/codex/sales.nim index 1375d636..acf83a75 100644 --- a/codex/sales.nim +++ b/codex/sales.nim @@ -93,7 +93,7 @@ func findAvailability(sales: Sales, ask: StorageAsk): ?Availability = for availability in sales.available: if ask.size <= availability.size and ask.duration <= availability.duration and - ask.maxPrice >= availability.minPrice: + ask.reward >= availability.minPrice: return some availability proc finish(agent: SalesAgent, success: bool) = diff --git a/tests/codex/testpurchasing.nim b/tests/codex/testpurchasing.nim index e74f655d..0e7447ab 100644 --- a/tests/codex/testpurchasing.nim +++ b/tests/codex/testpurchasing.nim @@ -30,7 +30,7 @@ suite "Purchasing": let submitted = market.requested[0] check submitted.ask.duration == request.ask.duration check submitted.ask.size == request.ask.size - check submitted.ask.maxPrice == request.ask.maxPrice + check submitted.ask.reward == request.ask.reward test "remembers purchases": let purchase1 = purchasing.purchase(request) diff --git a/tests/codex/testsales.nim b/tests/codex/testsales.nim index b38248e4..b2cac7d3 100644 --- a/tests/codex/testsales.nim +++ b/tests/codex/testsales.nim @@ -16,7 +16,7 @@ suite "Sales": ask: StorageAsk( duration: 60.u256, size: 100.u256, - maxPrice:42.u256 + reward:42.u256 ), content: StorageContent( cid: "some cid" diff --git a/tests/contracts/examples.nim b/tests/contracts/examples.nim index 49f063ea..f096b079 100644 --- a/tests/contracts/examples.nim +++ b/tests/contracts/examples.nim @@ -16,7 +16,7 @@ proc example*(_: type StorageRequest): StorageRequest = size: (1 * 1024 * 1024 * 1024).u256, # 1 Gigabyte duration: (10 * 60 * 60).u256, # 10 hours proofProbability: 4.u256, # require a proof roughly once every 4 periods - maxPrice: 84.u256 + reward: 84.u256 ), content: StorageContent( cid: "zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob", diff --git a/tests/contracts/testContracts.nim b/tests/contracts/testContracts.nim index e6303867..3336ac04 100644 --- a/tests/contracts/testContracts.nim +++ b/tests/contracts/testContracts.nim @@ -41,7 +41,7 @@ ethersuite "Storage contracts": request.client = await client.getAddress() switchAccount(client) - await token.approve(storage.address, request.ask.maxPrice) + await token.approve(storage.address, request.ask.reward) await storage.requestStorage(request) switchAccount(host) await token.approve(storage.address, collateralAmount) diff --git a/tests/contracts/testMarket.nim b/tests/contracts/testMarket.nim index a0aa872a..a9b2f40c 100644 --- a/tests/contracts/testMarket.nim +++ b/tests/contracts/testMarket.nim @@ -37,19 +37,19 @@ ethersuite "On-Chain Market": check (await market.getSigner()) == (await provider.getSigner().getAddress()) test "supports storage requests": - await token.approve(storage.address, request.ask.maxPrice) + await token.approve(storage.address, request.ask.reward) check (await market.requestStorage(request)) == request test "sets client address when submitting storage request": var requestWithoutClient = request requestWithoutClient.client = Address.default - await token.approve(storage.address, request.ask.maxPrice) + await token.approve(storage.address, request.ask.reward) let submitted = await market.requestStorage(requestWithoutClient) check submitted.client == accounts[0] test "can retrieve previously submitted requests": check (await market.getRequest(request.id)) == none StorageRequest - await token.approve(storage.address, request.ask.maxPrice) + await token.approve(storage.address, request.ask.reward) discard await market.requestStorage(request) check (await market.getRequest(request.id)) == some request @@ -60,26 +60,26 @@ ethersuite "On-Chain Market": receivedIds.add(id) receivedAsks.add(ask) let subscription = await market.subscribeRequests(onRequest) - await token.approve(storage.address, request.ask.maxPrice) + await token.approve(storage.address, request.ask.reward) discard await market.requestStorage(request) check receivedIds == @[request.id] check receivedAsks == @[request.ask] await subscription.unsubscribe() test "supports fulfilling of requests": - await token.approve(storage.address, request.ask.maxPrice) + await token.approve(storage.address, request.ask.reward) discard await market.requestStorage(request) await market.fulfillRequest(request.id, proof) test "can retrieve host that fulfilled request": - await token.approve(storage.address, request.ask.maxPrice) + await token.approve(storage.address, request.ask.reward) discard await market.requestStorage(request) check (await market.getHost(request.id)) == none Address await market.fulfillRequest(request.id, proof) check (await market.getHost(request.id)) == some accounts[0] test "support fulfillment subscriptions": - await token.approve(storage.address, request.ask.maxPrice) + await token.approve(storage.address, request.ask.reward) discard await market.requestStorage(request) var receivedIds: seq[array[32, byte]] proc onFulfillment(id: array[32, byte]) = @@ -93,9 +93,9 @@ ethersuite "On-Chain Market": var otherRequest = StorageRequest.example otherRequest.client = accounts[0] - await token.approve(storage.address, request.ask.maxPrice) + await token.approve(storage.address, request.ask.reward) discard await market.requestStorage(request) - await token.approve(storage.address, otherrequest.ask.maxPrice) + await token.approve(storage.address, otherrequest.ask.reward) discard await market.requestStorage(otherRequest) var receivedIds: seq[array[32, byte]] diff --git a/tests/testIntegration.nim b/tests/testIntegration.nim index e72e846b..309fcf71 100644 --- a/tests/testIntegration.nim +++ b/tests/testIntegration.nim @@ -62,19 +62,19 @@ ethersuite "Integration tests": test "node handles storage request": let cid = client.post(baseurl1 & "/upload", "some file contents").body let url = baseurl1 & "/storage/request/" & cid - let json = %*{"duration": "0x1", "maxPrice": "0x2"} + let json = %*{"duration": "0x1", "reward": "0x2"} let response = client.post(url, $json) check response.status == "200 OK" test "node retrieves purchase status": let cid = client.post(baseurl1 & "/upload", "some file contents").body - let request = %*{"duration": "0x1", "maxPrice": "0x2"} + let request = %*{"duration": "0x1", "reward": "0x2"} let id = client.post(baseurl1 & "/storage/request/" & cid, $request).body let response = client.get(baseurl1 & "/storage/purchases/" & id) check response.status == "200 OK" let json = parseJson(response.body) check json["request"]["ask"]["duration"].getStr == "0x1" - check json["request"]["ask"]["maxPrice"].getStr == "0x2" + check json["request"]["ask"]["reward"].getStr == "0x2" test "nodes negotiate contracts on the marketplace": proc sell = @@ -89,7 +89,7 @@ ethersuite "Integration tests": proc buy(cid: string): string = let expiry = ((waitFor provider.currentTime()) + 30).toHex - let json = %*{"duration": "0x100", "maxPrice": "0x400", "expiry": expiry} + let json = %*{"duration": "0x100", "reward": "0x400", "expiry": expiry} client.post(baseurl1 & "/storage/request/" & cid, $json).body proc finish(purchase: string): Future[JsonNode] {.async.} =