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/offers
import contracts/storage
import contracts/deployment
import contracts/market
@ -7,7 +6,6 @@ import contracts/proofs
import contracts/interactions
export requests
export offers
export storage
export deployment
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/chronos
import ./requests
import ./offers
export stint
export ethers

View File

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

View File

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

View File

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

View File

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

View File

@ -34,11 +34,3 @@ proc example*(_: type StorageRequest): StorageRequest =
expiry: (getTime() + initDuration(hours=1)).toUnix.u256,
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 periodicity: Periodicity
var request: StorageRequest
var offer: StorageOffer
var id: array[32, byte]
proc switchAccount(account: Signer) =
@ -41,10 +40,6 @@ ethersuite "Storage contracts":
request = StorageRequest.example
request.client = await client.getAddress()
offer = StorageOffer.example
offer.host = await host.getAddress()
offer.requestId = request.id
switchAccount(client)
await token.approve(storage.address, request.ask.maxPrice)
await storage.requestStorage(request)

View File

@ -12,7 +12,6 @@ ethersuite "On-Chain Market":
var storage: Storage
var token: TestToken
var request: StorageRequest
var offer: StorageOffer
setup:
let deployment = deployment()
@ -27,11 +26,7 @@ ethersuite "On-Chain Market":
market = OnChainMarket.new(storage)
request = StorageRequest.example
offer = StorageOffer.example
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":
let storageWithoutSigner = storage.connect(provider)