From 00c720137a425000f89688871867b87cd50f7265 Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 22 Jan 2024 16:27:32 +0100 Subject: [PATCH] Adds method for getting request state and receiving cancelled events --- .../CodexContractsAccess.cs | 31 +++++++++++++++++++ .../Marketplace/Customizations.cs | 5 +++ TestNetRewarder/Program.cs | 3 +- Tests/CodexTests/BasicTests/ExampleTests.cs | 2 ++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/ProjectPlugins/CodexContractsPlugin/CodexContractsAccess.cs b/ProjectPlugins/CodexContractsPlugin/CodexContractsAccess.cs index 5d03e0e..a4140e3 100644 --- a/ProjectPlugins/CodexContractsPlugin/CodexContractsAccess.cs +++ b/ProjectPlugins/CodexContractsPlugin/CodexContractsAccess.cs @@ -21,11 +21,22 @@ namespace CodexContractsPlugin Request[] GetStorageRequests(TimeRange timeRange); EthAddress GetSlotHost(Request storageRequest, decimal slotIndex); + RequestState GetRequestState(Request request); RequestFulfilledEventDTO[] GetRequestFulfilledEvents(TimeRange timeRange); + RequestCancelledEventDTO[] GetRequestCancelledEvents(TimeRange timeRange); SlotFilledEventDTO[] GetSlotFilledEvents(TimeRange timeRange); SlotFreedEventDTO[] GetSlotFreedEvents(TimeRange timeRange); } + public enum RequestState + { + New, + Started, + Cancelled, + Finished, + Failed + } + public class CodexContractsAccess : ICodexContracts { private readonly ILog log; @@ -93,6 +104,17 @@ namespace CodexContractsPlugin }).ToArray(); } + public RequestCancelledEventDTO[] GetRequestCancelledEvents(TimeRange timeRange) + { + var events = gethNode.GetEvents(Deployment.MarketplaceAddress, timeRange); + return events.Select(e => + { + var result = e.Event; + result.BlockNumber = e.Log.BlockNumber.ToUlong(); + return result; + }).ToArray(); + } + public SlotFilledEventDTO[] GetSlotFilledEvents(TimeRange timeRange) { var events = gethNode.GetEvents(Deployment.MarketplaceAddress, timeRange); @@ -133,6 +155,15 @@ namespace CodexContractsPlugin return new EthAddress(gethNode.Call(Deployment.MarketplaceAddress, func)); } + public RequestState GetRequestState(Request request) + { + var func = new RequestStateFunction + { + RequestId = request.RequestId + }; + return gethNode.Call(Deployment.MarketplaceAddress, func); + } + private EthAddress GetEthAddressFromTransaction(string transactionHash) { var transaction = gethNode.GetTransaction(transactionHash); diff --git a/ProjectPlugins/CodexContractsPlugin/Marketplace/Customizations.cs b/ProjectPlugins/CodexContractsPlugin/Marketplace/Customizations.cs index dafd88a..96490b7 100644 --- a/ProjectPlugins/CodexContractsPlugin/Marketplace/Customizations.cs +++ b/ProjectPlugins/CodexContractsPlugin/Marketplace/Customizations.cs @@ -16,6 +16,11 @@ namespace CodexContractsPlugin.Marketplace public ulong BlockNumber { get; set; } } + public partial class RequestCancelledEventDTO + { + public ulong BlockNumber { get; set; } + } + public partial class SlotFilledEventDTO { public ulong BlockNumber { get; set; } diff --git a/TestNetRewarder/Program.cs b/TestNetRewarder/Program.cs index a5dce56..e813005 100644 --- a/TestNetRewarder/Program.cs +++ b/TestNetRewarder/Program.cs @@ -1,5 +1,4 @@ using ArgsUniform; -using GethConnector; using Logging; using Utils; @@ -67,6 +66,8 @@ namespace TestNetRewarder { Log.Error("Exception processing time segment: " + ex); } + + await Task.Delay(1); } private static void PrintHelp() diff --git a/Tests/CodexTests/BasicTests/ExampleTests.cs b/Tests/CodexTests/BasicTests/ExampleTests.cs index a901343..c73a913 100644 --- a/Tests/CodexTests/BasicTests/ExampleTests.cs +++ b/Tests/CodexTests/BasicTests/ExampleTests.cs @@ -93,6 +93,7 @@ namespace CodexTests.BasicTests var requests = contracts.GetStorageRequests(GetTestRunTimeRange()); Assert.That(requests.Length, Is.EqualTo(1)); var request = requests.Single(); + Assert.That(contracts.GetRequestState(request), Is.EqualTo(RequestState.Started)); Assert.That(request.ClientAddress, Is.EqualTo(buyer.EthAddress)); Assert.That(request.Ask.Slots, Is.EqualTo(1)); @@ -115,6 +116,7 @@ namespace CodexTests.BasicTests AssertBalance(contracts, seller, Is.GreaterThan(sellerInitialBalance), "Seller was not paid for storage."); AssertBalance(contracts, buyer, Is.LessThan(buyerInitialBalance), "Buyer was not charged for storage."); + Assert.That(contracts.GetRequestState(request), Is.EqualTo(RequestState.Finished)); var log = Ci.DownloadLog(seller); log.AssertLogContains("Received a request to store a slot!");