From a3fdd35f73bc67579165f9b84d0e7755d637c770 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 23 Mar 2022 09:11:15 +0100 Subject: [PATCH] [contracts] Split marketplace.nim into requests.nim and offers.nim --- dagger/contracts.nim | 6 ++++-- dagger/contracts/offers.nim | 15 +++++++++++++++ .../contracts/{marketplace.nim => requests.nim} | 13 +------------ dagger/contracts/storage.nim | 3 ++- tests/contracts/examples.nim | 2 +- 5 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 dagger/contracts/offers.nim rename dagger/contracts/{marketplace.nim => requests.nim} (58%) diff --git a/dagger/contracts.nim b/dagger/contracts.nim index f4ef8497..24bc6321 100644 --- a/dagger/contracts.nim +++ b/dagger/contracts.nim @@ -1,7 +1,9 @@ -import contracts/marketplace +import contracts/requests +import contracts/offers import contracts/storage import contracts/deployment -export marketplace +export requests +export offers export storage export deployment diff --git a/dagger/contracts/offers.nim b/dagger/contracts/offers.nim new file mode 100644 index 00000000..275f9d81 --- /dev/null +++ b/dagger/contracts/offers.nim @@ -0,0 +1,15 @@ +import pkg/contractabi +import pkg/nimcrypto + +export contractabi + +type + StorageOffer* = tuple + host: Address + requestId: array[32, byte] + price: UInt256 + expiry: UInt256 + +func id*(offer: StorageOffer): array[32, byte] = + let encoding = AbiEncoder.encode(offer) + keccak256.digest(encoding).data diff --git a/dagger/contracts/marketplace.nim b/dagger/contracts/requests.nim similarity index 58% rename from dagger/contracts/marketplace.nim rename to dagger/contracts/requests.nim index df6c2716..468c2467 100644 --- a/dagger/contracts/marketplace.nim +++ b/dagger/contracts/requests.nim @@ -1,9 +1,7 @@ -import pkg/stint import pkg/contractabi import pkg/nimcrypto -import pkg/chronos -export stint +export contractabi type StorageRequest* = tuple @@ -15,16 +13,7 @@ type maxPrice: UInt256 expiry: UInt256 nonce: array[32, byte] - StorageOffer* = tuple - host: Address - requestId: array[32, byte] - price: UInt256 - expiry: UInt256 func id*(request: StorageRequest): array[32, byte] = let encoding = AbiEncoder.encode(request) keccak256.digest(encoding).data - -func id*(offer: StorageOffer): array[32, byte] = - let encoding = AbiEncoder.encode(offer) - keccak256.digest(encoding).data diff --git a/dagger/contracts/storage.nim b/dagger/contracts/storage.nim index 90aef23d..95d8a080 100644 --- a/dagger/contracts/storage.nim +++ b/dagger/contracts/storage.nim @@ -2,7 +2,8 @@ import pkg/ethers import pkg/json_rpc/rpcclient import pkg/stint import pkg/chronos -import ./marketplace +import ./requests +import ./offers export stint export contract diff --git a/tests/contracts/examples.nim b/tests/contracts/examples.nim index ff3b70c4..50fe2372 100644 --- a/tests/contracts/examples.nim +++ b/tests/contracts/examples.nim @@ -2,7 +2,7 @@ import std/times import pkg/stint import pkg/nimcrypto import pkg/ethers -import dagger/contracts/marketplace +import dagger/contracts proc randomBytes(amount: static int): array[amount, byte] = doAssert randomBytes(result) == amount