[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
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 =

View File

@ -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,

View File

@ -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)

View File

@ -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
)

View File

@ -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) =

View File

@ -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)

View File

@ -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"

View File

@ -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",

View File

@ -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)

View File

@ -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]]

View File

@ -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.} =