[contracts] StorageRequest/Offer is object instead of tuple
This commit is contained in:
parent
5f10549f19
commit
9ade3fdd37
|
@ -4,11 +4,25 @@ import pkg/nimcrypto
|
||||||
export contractabi
|
export contractabi
|
||||||
|
|
||||||
type
|
type
|
||||||
StorageOffer* = tuple
|
StorageOffer* = object
|
||||||
host: Address
|
host*: Address
|
||||||
requestId: array[32, byte]
|
requestId*: array[32, byte]
|
||||||
price: UInt256
|
price*: UInt256
|
||||||
expiry: UInt256
|
expiry*: UInt256
|
||||||
|
|
||||||
|
func toTuple(offer: StorageOffer): auto =
|
||||||
|
(
|
||||||
|
offer.host,
|
||||||
|
offer.requestId,
|
||||||
|
offer.price,
|
||||||
|
offer.expiry
|
||||||
|
)
|
||||||
|
|
||||||
|
func solidityType*(_: type StorageOffer): string =
|
||||||
|
solidityType(typeof StorageOffer.default.toTuple)
|
||||||
|
|
||||||
|
func encode*(encoder: var AbiEncoder, offer: StorageOffer) =
|
||||||
|
encoder.write(offer.toTuple)
|
||||||
|
|
||||||
func id*(offer: StorageOffer): array[32, byte] =
|
func id*(offer: StorageOffer): array[32, byte] =
|
||||||
let encoding = AbiEncoder.encode(offer)
|
let encoding = AbiEncoder.encode(offer)
|
||||||
|
|
|
@ -4,15 +4,33 @@ import pkg/nimcrypto
|
||||||
export contractabi
|
export contractabi
|
||||||
|
|
||||||
type
|
type
|
||||||
StorageRequest* = tuple
|
StorageRequest* = object
|
||||||
client: Address
|
client*: Address
|
||||||
duration: UInt256
|
duration*: UInt256
|
||||||
size: UInt256
|
size*: UInt256
|
||||||
contentHash: array[32, byte]
|
contentHash*: array[32, byte]
|
||||||
proofProbability: UInt256
|
proofProbability*: UInt256
|
||||||
maxPrice: UInt256
|
maxPrice*: UInt256
|
||||||
expiry: UInt256
|
expiry*: UInt256
|
||||||
nonce: array[32, byte]
|
nonce*: array[32, byte]
|
||||||
|
|
||||||
|
func toTuple(request: StorageRequest): auto =
|
||||||
|
(
|
||||||
|
request.client,
|
||||||
|
request.duration,
|
||||||
|
request.size,
|
||||||
|
request.contentHash,
|
||||||
|
request.proofProbability,
|
||||||
|
request.maxPrice,
|
||||||
|
request.expiry,
|
||||||
|
request.nonce
|
||||||
|
)
|
||||||
|
|
||||||
|
func solidityType*(_: type StorageRequest): string =
|
||||||
|
solidityType(typeof StorageRequest.default.toTuple)
|
||||||
|
|
||||||
|
func encode*(encoder: var AbiEncoder, request: StorageRequest) =
|
||||||
|
encoder.write(request.toTuple)
|
||||||
|
|
||||||
func id*(request: StorageRequest): array[32, byte] =
|
func id*(request: StorageRequest): array[32, byte] =
|
||||||
let encoding = AbiEncoder.encode(request)
|
let encoding = AbiEncoder.encode(request)
|
||||||
|
|
|
@ -41,7 +41,7 @@ proc getNonce(): array[32, byte] =
|
||||||
doAssert randomBytes(result) == 32
|
doAssert randomBytes(result) == 32
|
||||||
|
|
||||||
proc purchase*(purchasing: Purchasing, request: PurchaseRequest): Purchase =
|
proc purchase*(purchasing: Purchasing, request: PurchaseRequest): Purchase =
|
||||||
let request: StorageRequest = (
|
let request = StorageRequest(
|
||||||
client: Address.default, # TODO
|
client: Address.default, # TODO
|
||||||
duration: request.duration,
|
duration: request.duration,
|
||||||
size: request.size,
|
size: request.size,
|
||||||
|
|
|
@ -11,7 +11,7 @@ proc example*(_: type Address): Address =
|
||||||
Address(randomBytes(20))
|
Address(randomBytes(20))
|
||||||
|
|
||||||
proc example*(_: type StorageRequest): StorageRequest =
|
proc example*(_: type StorageRequest): StorageRequest =
|
||||||
(
|
StorageRequest(
|
||||||
client: Address.example,
|
client: Address.example,
|
||||||
duration: (10 * 60 * 60).u256, # 10 hours
|
duration: (10 * 60 * 60).u256, # 10 hours
|
||||||
size: (1 * 1024 * 1024 * 1024).u256, # 1 Gigabyte
|
size: (1 * 1024 * 1024 * 1024).u256, # 1 Gigabyte
|
||||||
|
@ -23,7 +23,7 @@ proc example*(_: type StorageRequest): StorageRequest =
|
||||||
)
|
)
|
||||||
|
|
||||||
proc example*(_: type StorageOffer): StorageOffer =
|
proc example*(_: type StorageOffer): StorageOffer =
|
||||||
(
|
StorageOffer(
|
||||||
host: Address.example,
|
host: Address.example,
|
||||||
requestId: StorageRequest.example.id,
|
requestId: StorageRequest.example.id,
|
||||||
price: 42.u256,
|
price: 42.u256,
|
||||||
|
|
Loading…
Reference in New Issue