Cleanup: remove StorageOffer everywhere

This commit is contained in:
Mark Spanbroek 2022-07-06 15:45:34 +02:00 committed by markspanbroek
parent bd2fba50c7
commit 96ca1de768
10 changed files with 0 additions and 70 deletions

View File

@ -1,5 +1,4 @@
import contracts/requests import contracts/requests
import contracts/offers
import contracts/storage import contracts/storage
import contracts/deployment import contracts/deployment
import contracts/market import contracts/market
@ -7,7 +6,6 @@ import contracts/proofs
import contracts/interactions import contracts/interactions
export requests export requests
export offers
export storage export storage
export deployment export deployment
export market export market

View File

@ -1,35 +0,0 @@
import pkg/contractabi
import pkg/nimcrypto
import pkg/ethers/fields
import pkg/questionable/results
export contractabi
type
StorageOffer* = object
host*: Address
requestId*: array[32, byte]
price*: UInt256
expiry*: UInt256
func fromTuple(_: type StorageOffer, tupl: tuple): StorageOffer =
StorageOffer(
host: tupl[0],
requestId: tupl[1],
price: tupl[2],
expiry: tupl[3]
)
func solidityType*(_: type StorageOffer): string =
solidityType(StorageOffer.fieldTypes)
func encode*(encoder: var AbiEncoder, offer: StorageOffer) =
encoder.write(offer.fieldValues)
func decode*(decoder: var AbiDecoder, T: type StorageOffer): ?!T =
let tupl = ?decoder.read(StorageOffer.fieldTypes)
success StorageOffer.fromTuple(tupl)
func id*(offer: StorageOffer): array[32, byte] =
let encoding = AbiEncoder.encode(offer)
keccak256.digest(encoding).data

View File

@ -3,7 +3,6 @@ import pkg/json_rpc/rpcclient
import pkg/stint import pkg/stint
import pkg/chronos import pkg/chronos
import ./requests import ./requests
import ./offers
export stint export stint
export ethers export ethers

View File

@ -2,12 +2,10 @@ import pkg/chronos
import pkg/upraises import pkg/upraises
import pkg/questionable import pkg/questionable
import ./contracts/requests import ./contracts/requests
import ./contracts/offers
export chronos export chronos
export questionable export questionable
export requests export requests
export offers
type type
Market* = ref object of RootObj Market* = ref object of RootObj

View File

@ -16,20 +16,16 @@ type
purchases: Table[array[32, byte], Purchase] purchases: Table[array[32, byte], Purchase]
proofProbability*: UInt256 proofProbability*: UInt256
requestExpiryInterval*: UInt256 requestExpiryInterval*: UInt256
offerExpiryMargin*: UInt256
Purchase* = ref object Purchase* = ref object
future: Future[void] future: Future[void]
market: Market market: Market
clock: Clock clock: Clock
offerExpiryMargin: UInt256
request*: StorageRequest request*: StorageRequest
offers*: seq[StorageOffer]
selected*: ?Address selected*: ?Address
PurchaseTimeout* = Timeout PurchaseTimeout* = Timeout
const DefaultProofProbability = 100.u256 const DefaultProofProbability = 100.u256
const DefaultRequestExpiryInterval = (10 * 60).u256 const DefaultRequestExpiryInterval = (10 * 60).u256
const DefaultOfferExpiryMargin = (8 * 60).u256
proc start(purchase: Purchase) {.gcsafe.} proc start(purchase: Purchase) {.gcsafe.}
func id*(purchase: Purchase): array[32, byte] func id*(purchase: Purchase): array[32, byte]
@ -40,7 +36,6 @@ proc new*(_: type Purchasing, market: Market, clock: Clock): Purchasing =
clock: clock, clock: clock,
proofProbability: DefaultProofProbability, proofProbability: DefaultProofProbability,
requestExpiryInterval: DefaultRequestExpiryInterval, requestExpiryInterval: DefaultRequestExpiryInterval,
offerExpiryMargin: DefaultOfferExpiryMargin
) )
proc populate*(purchasing: Purchasing, request: StorageRequest): StorageRequest = proc populate*(purchasing: Purchasing, request: StorageRequest): StorageRequest =
@ -58,7 +53,6 @@ proc purchase*(purchasing: Purchasing, request: StorageRequest): Purchase =
request: request, request: request,
market: purchasing.market, market: purchasing.market,
clock: purchasing.clock, clock: purchasing.clock,
offerExpiryMargin: purchasing.offerExpiryMargin
) )
purchase.start() purchase.start()
purchasing.purchases[purchase.id] = purchase purchasing.purchases[purchase.id] = purchase

View File

@ -44,6 +44,5 @@ func `%`*(purchase: Purchase): JsonNode =
"finished": purchase.finished, "finished": purchase.finished,
"error": purchase.error.?msg, "error": purchase.error.?msg,
"request": purchase.request, "request": purchase.request,
"offers": purchase.offers,
"selected": purchase.selected "selected": purchase.selected
} }

View File

@ -9,15 +9,12 @@ import ./clock
export stint export stint
const DefaultOfferExpiryInterval = (10 * 60).u256
type type
Sales* = ref object Sales* = ref object
market: Market market: Market
clock: Clock clock: Clock
subscription: ?Subscription subscription: ?Subscription
available*: seq[Availability] available*: seq[Availability]
offerExpiryInterval*: UInt256
retrieve: ?Retrieve retrieve: ?Retrieve
prove: ?Prove prove: ?Prove
onSale: ?OnSale onSale: ?OnSale
@ -32,7 +29,6 @@ type
ask: StorageAsk ask: StorageAsk
availability: Availability availability: Availability
request: ?StorageRequest request: ?StorageRequest
offer: ?StorageOffer
subscription: ?Subscription subscription: ?Subscription
running: ?Future[void] running: ?Future[void]
waiting: ?Future[void] waiting: ?Future[void]
@ -45,7 +41,6 @@ func new*(_: type Sales, market: Market, clock: Clock): Sales =
Sales( Sales(
market: market, market: market,
clock: clock, clock: clock,
offerExpiryInterval: DefaultOfferExpiryInterval
) )
proc init*(_: type Availability, proc init*(_: type Availability,

View File

@ -34,11 +34,3 @@ proc example*(_: type StorageRequest): StorageRequest =
expiry: (getTime() + initDuration(hours=1)).toUnix.u256, expiry: (getTime() + initDuration(hours=1)).toUnix.u256,
nonce: array[32, byte].example nonce: array[32, byte].example
) )
proc example*(_: type StorageOffer): StorageOffer =
StorageOffer(
host: Address.example,
requestId: StorageRequest.example.id,
price: 42.u256,
expiry: (getTime() + initDuration(hours=1)).toUnix.u256,
)

View File

@ -17,7 +17,6 @@ ethersuite "Storage contracts":
var collateralAmount: UInt256 var collateralAmount: UInt256
var periodicity: Periodicity var periodicity: Periodicity
var request: StorageRequest var request: StorageRequest
var offer: StorageOffer
var id: array[32, byte] var id: array[32, byte]
proc switchAccount(account: Signer) = proc switchAccount(account: Signer) =
@ -41,10 +40,6 @@ ethersuite "Storage contracts":
request = StorageRequest.example request = StorageRequest.example
request.client = await client.getAddress() request.client = await client.getAddress()
offer = StorageOffer.example
offer.host = await host.getAddress()
offer.requestId = request.id
switchAccount(client) switchAccount(client)
await token.approve(storage.address, request.ask.maxPrice) await token.approve(storage.address, request.ask.maxPrice)
await storage.requestStorage(request) await storage.requestStorage(request)

View File

@ -12,7 +12,6 @@ ethersuite "On-Chain Market":
var storage: Storage var storage: Storage
var token: TestToken var token: TestToken
var request: StorageRequest var request: StorageRequest
var offer: StorageOffer
setup: setup:
let deployment = deployment() let deployment = deployment()
@ -27,11 +26,7 @@ ethersuite "On-Chain Market":
market = OnChainMarket.new(storage) market = OnChainMarket.new(storage)
request = StorageRequest.example request = StorageRequest.example
offer = StorageOffer.example
request.client = accounts[0] request.client = accounts[0]
offer.host = accounts[0]
offer.requestId = request.id
offer.price = request.ask.maxPrice
test "fails to instantiate when contract does not have a signer": test "fails to instantiate when contract does not have a signer":
let storageWithoutSigner = storage.connect(provider) let storageWithoutSigner = storage.connect(provider)