2022-03-23 08:11:15 +00:00
|
|
|
import pkg/contractabi
|
|
|
|
import pkg/nimcrypto
|
2022-03-29 07:47:49 +00:00
|
|
|
import pkg/ethers/fields
|
|
|
|
import pkg/questionable/results
|
2022-03-23 08:11:15 +00:00
|
|
|
|
|
|
|
export contractabi
|
|
|
|
|
|
|
|
type
|
2022-03-23 13:20:36 +00:00
|
|
|
StorageOffer* = object
|
|
|
|
host*: Address
|
|
|
|
requestId*: array[32, byte]
|
|
|
|
price*: UInt256
|
|
|
|
expiry*: UInt256
|
|
|
|
|
2022-03-29 07:47:49 +00:00
|
|
|
func fromTuple(_: type StorageOffer, tupl: tuple): StorageOffer =
|
|
|
|
StorageOffer(
|
|
|
|
host: tupl[0],
|
|
|
|
requestId: tupl[1],
|
|
|
|
price: tupl[2],
|
|
|
|
expiry: tupl[3]
|
2022-03-23 13:20:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func solidityType*(_: type StorageOffer): string =
|
2022-03-29 07:47:49 +00:00
|
|
|
solidityType(StorageOffer.fieldTypes)
|
2022-03-23 13:20:36 +00:00
|
|
|
|
|
|
|
func encode*(encoder: var AbiEncoder, offer: StorageOffer) =
|
2022-03-29 07:47:49 +00:00
|
|
|
encoder.write(offer.fieldValues)
|
|
|
|
|
|
|
|
func decode*(decoder: var AbiDecoder, T: type StorageOffer): ?!T =
|
|
|
|
let tupl = ?decoder.read(StorageOffer.fieldTypes)
|
|
|
|
success StorageOffer.fromTuple(tupl)
|
2022-03-23 08:11:15 +00:00
|
|
|
|
|
|
|
func id*(offer: StorageOffer): array[32, byte] =
|
|
|
|
let encoding = AbiEncoder.encode(offer)
|
|
|
|
keccak256.digest(encoding).data
|