[contracts] Rename: maxPrice -> reward

This commit is contained in:
Mark Spanbroek 2022-07-20 14:11:00 +02:00 committed by markspanbroek
parent 5a00eddfba
commit 360c03e7c4
11 changed files with 28 additions and 28 deletions

View File

@ -16,7 +16,7 @@ type
size*: UInt256 size*: UInt256
duration*: UInt256 duration*: UInt256
proofProbability*: UInt256 proofProbability*: UInt256
maxPrice*: UInt256 reward*: UInt256
StorageContent* = object StorageContent* = object
cid*: string cid*: string
erasure*: StorageErasure erasure*: StorageErasure
@ -44,7 +44,7 @@ func fromTuple(_: type StorageAsk, tupl: tuple): StorageAsk =
size: tupl[0], size: tupl[0],
duration: tupl[1], duration: tupl[1],
proofProbability: tupl[2], proofProbability: tupl[2],
maxPrice: tupl[3] reward: tupl[3]
) )
func fromTuple(_: type StorageContent, tupl: tuple): StorageContent = func fromTuple(_: type StorageContent, tupl: tuple): StorageContent =

View File

@ -220,7 +220,7 @@ proc requestStorage*(self: CodexNodeRef,
duration: UInt256, duration: UInt256,
nodes: uint, nodes: uint,
tolerance: uint, tolerance: uint,
maxPrice: UInt256, reward: UInt256,
expiry = UInt256.none): Future[?!array[32, byte]] {.async.} = expiry = UInt256.none): Future[?!array[32, byte]] {.async.} =
## Initiate a request for storage sequence, this might ## Initiate a request for storage sequence, this might
## be a multistep procedure. ## be a multistep procedure.
@ -231,7 +231,7 @@ proc requestStorage*(self: CodexNodeRef,
## - Run the PoR setup on the erasure dataset ## - Run the PoR setup on the erasure dataset
## - Call into the marketplace and purchasing contracts ## - 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: without contracts =? self.contracts:
trace "Purchasing not available" trace "Purchasing not available"
@ -262,7 +262,7 @@ proc requestStorage*(self: CodexNodeRef,
ask: StorageAsk( ask: StorageAsk(
size: encoded.size.u256, size: encoded.size.u256,
duration: duration, duration: duration,
maxPrice: maxPrice reward: reward
), ),
content: StorageContent( content: StorageContent(
cid: $encodedBlk.cid, cid: $encodedBlk.cid,

View File

@ -192,7 +192,7 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter =
## ##
## cid - the cid of a previously uploaded dataset ## cid - the cid of a previously uploaded dataset
## duration - the duration of the contract ## 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 # TODO: store on multiple nodes
let nodes: uint = 1 let nodes: uint = 1
@ -210,7 +210,7 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter =
params.duration, params.duration,
nodes, nodes,
tolerance, tolerance,
params.maxPrice, params.reward,
params.expiry), error: params.expiry), error:
return RestApiResponse.error(Http500, error.msg) return RestApiResponse.error(Http500, error.msg)

View File

@ -8,7 +8,7 @@ import ../purchasing
type type
StorageRequestParams* = object StorageRequestParams* = object
duration*: UInt256 duration*: UInt256
maxPrice*: UInt256 reward*: UInt256
expiry*: ?UInt256 expiry*: ?UInt256
proc fromJson*(_: type Availability, bytes: seq[byte]): ?!Availability = proc fromJson*(_: type Availability, bytes: seq[byte]): ?!Availability =
@ -22,11 +22,11 @@ proc fromJson*(_: type StorageRequestParams,
bytes: seq[byte]): ?! StorageRequestParams = bytes: seq[byte]): ?! StorageRequestParams =
let json = ?catch parseJson(string.fromBytes(bytes)) let json = ?catch parseJson(string.fromBytes(bytes))
let duration = ?catch UInt256.fromHex(json["duration"].getStr) 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 let expiry = UInt256.fromHex(json["expiry"].getStr).catch.option
success StorageRequestParams( success StorageRequestParams(
duration: duration, duration: duration,
maxPrice: maxPrice, reward: reward,
expiry: expiry expiry: expiry
) )

View File

@ -93,7 +93,7 @@ func findAvailability(sales: Sales, ask: StorageAsk): ?Availability =
for availability in sales.available: for availability in sales.available:
if ask.size <= availability.size and if ask.size <= availability.size and
ask.duration <= availability.duration and ask.duration <= availability.duration and
ask.maxPrice >= availability.minPrice: ask.reward >= availability.minPrice:
return some availability return some availability
proc finish(agent: SalesAgent, success: bool) = proc finish(agent: SalesAgent, success: bool) =

View File

@ -30,7 +30,7 @@ suite "Purchasing":
let submitted = market.requested[0] let submitted = market.requested[0]
check submitted.ask.duration == request.ask.duration check submitted.ask.duration == request.ask.duration
check submitted.ask.size == request.ask.size check submitted.ask.size == request.ask.size
check submitted.ask.maxPrice == request.ask.maxPrice check submitted.ask.reward == request.ask.reward
test "remembers purchases": test "remembers purchases":
let purchase1 = purchasing.purchase(request) let purchase1 = purchasing.purchase(request)

View File

@ -16,7 +16,7 @@ suite "Sales":
ask: StorageAsk( ask: StorageAsk(
duration: 60.u256, duration: 60.u256,
size: 100.u256, size: 100.u256,
maxPrice:42.u256 reward:42.u256
), ),
content: StorageContent( content: StorageContent(
cid: "some cid" cid: "some cid"

View File

@ -16,7 +16,7 @@ proc example*(_: type StorageRequest): StorageRequest =
size: (1 * 1024 * 1024 * 1024).u256, # 1 Gigabyte size: (1 * 1024 * 1024 * 1024).u256, # 1 Gigabyte
duration: (10 * 60 * 60).u256, # 10 hours duration: (10 * 60 * 60).u256, # 10 hours
proofProbability: 4.u256, # require a proof roughly once every 4 periods proofProbability: 4.u256, # require a proof roughly once every 4 periods
maxPrice: 84.u256 reward: 84.u256
), ),
content: StorageContent( content: StorageContent(
cid: "zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob", cid: "zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob",

View File

@ -41,7 +41,7 @@ ethersuite "Storage contracts":
request.client = await client.getAddress() request.client = await client.getAddress()
switchAccount(client) switchAccount(client)
await token.approve(storage.address, request.ask.maxPrice) await token.approve(storage.address, request.ask.reward)
await storage.requestStorage(request) await storage.requestStorage(request)
switchAccount(host) switchAccount(host)
await token.approve(storage.address, collateralAmount) await token.approve(storage.address, collateralAmount)

View File

@ -37,19 +37,19 @@ ethersuite "On-Chain Market":
check (await market.getSigner()) == (await provider.getSigner().getAddress()) check (await market.getSigner()) == (await provider.getSigner().getAddress())
test "supports storage requests": 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 check (await market.requestStorage(request)) == request
test "sets client address when submitting storage request": test "sets client address when submitting storage request":
var requestWithoutClient = request var requestWithoutClient = request
requestWithoutClient.client = Address.default 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) let submitted = await market.requestStorage(requestWithoutClient)
check submitted.client == accounts[0] check submitted.client == accounts[0]
test "can retrieve previously submitted requests": test "can retrieve previously submitted requests":
check (await market.getRequest(request.id)) == none StorageRequest 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) discard await market.requestStorage(request)
check (await market.getRequest(request.id)) == some request check (await market.getRequest(request.id)) == some request
@ -60,26 +60,26 @@ ethersuite "On-Chain Market":
receivedIds.add(id) receivedIds.add(id)
receivedAsks.add(ask) receivedAsks.add(ask)
let subscription = await market.subscribeRequests(onRequest) 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) discard await market.requestStorage(request)
check receivedIds == @[request.id] check receivedIds == @[request.id]
check receivedAsks == @[request.ask] check receivedAsks == @[request.ask]
await subscription.unsubscribe() await subscription.unsubscribe()
test "supports fulfilling of requests": 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) discard await market.requestStorage(request)
await market.fulfillRequest(request.id, proof) await market.fulfillRequest(request.id, proof)
test "can retrieve host that fulfilled request": 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) discard await market.requestStorage(request)
check (await market.getHost(request.id)) == none Address check (await market.getHost(request.id)) == none Address
await market.fulfillRequest(request.id, proof) await market.fulfillRequest(request.id, proof)
check (await market.getHost(request.id)) == some accounts[0] check (await market.getHost(request.id)) == some accounts[0]
test "support fulfillment subscriptions": 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) discard await market.requestStorage(request)
var receivedIds: seq[array[32, byte]] var receivedIds: seq[array[32, byte]]
proc onFulfillment(id: array[32, byte]) = proc onFulfillment(id: array[32, byte]) =
@ -93,9 +93,9 @@ ethersuite "On-Chain Market":
var otherRequest = StorageRequest.example var otherRequest = StorageRequest.example
otherRequest.client = accounts[0] 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) 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) discard await market.requestStorage(otherRequest)
var receivedIds: seq[array[32, byte]] var receivedIds: seq[array[32, byte]]

View File

@ -62,19 +62,19 @@ ethersuite "Integration tests":
test "node handles storage request": test "node handles storage request":
let cid = client.post(baseurl1 & "/upload", "some file contents").body let cid = client.post(baseurl1 & "/upload", "some file contents").body
let url = baseurl1 & "/storage/request/" & cid let url = baseurl1 & "/storage/request/" & cid
let json = %*{"duration": "0x1", "maxPrice": "0x2"} let json = %*{"duration": "0x1", "reward": "0x2"}
let response = client.post(url, $json) let response = client.post(url, $json)
check response.status == "200 OK" check response.status == "200 OK"
test "node retrieves purchase status": test "node retrieves purchase status":
let cid = client.post(baseurl1 & "/upload", "some file contents").body 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 id = client.post(baseurl1 & "/storage/request/" & cid, $request).body
let response = client.get(baseurl1 & "/storage/purchases/" & id) let response = client.get(baseurl1 & "/storage/purchases/" & id)
check response.status == "200 OK" check response.status == "200 OK"
let json = parseJson(response.body) let json = parseJson(response.body)
check json["request"]["ask"]["duration"].getStr == "0x1" 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": test "nodes negotiate contracts on the marketplace":
proc sell = proc sell =
@ -89,7 +89,7 @@ ethersuite "Integration tests":
proc buy(cid: string): string = proc buy(cid: string): string =
let expiry = ((waitFor provider.currentTime()) + 30).toHex 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 client.post(baseurl1 & "/storage/request/" & cid, $json).body
proc finish(purchase: string): Future[JsonNode] {.async.} = proc finish(purchase: string): Future[JsonNode] {.async.} =