nim-codex/dagger/contracts/offers.nim

36 lines
888 B
Nim
Raw Normal View History

import pkg/contractabi
import pkg/nimcrypto
2022-03-29 07:47:49 +00:00
import pkg/ethers/fields
import pkg/questionable/results
export contractabi
type
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]
)
func solidityType*(_: type StorageOffer): string =
2022-03-29 07:47:49 +00:00
solidityType(StorageOffer.fieldTypes)
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)
func id*(offer: StorageOffer): array[32, byte] =
let encoding = AbiEncoder.encode(offer)
keccak256.digest(encoding).data