Adds method for getting request state and receiving cancelled events

This commit is contained in:
benbierens 2024-01-22 16:27:32 +01:00
parent 890cff93d5
commit 00c720137a
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 40 additions and 1 deletions

View File

@ -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<RequestCancelledEventDTO>(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<SlotFilledEventDTO>(Deployment.MarketplaceAddress, timeRange);
@ -133,6 +155,15 @@ namespace CodexContractsPlugin
return new EthAddress(gethNode.Call<GetHostFunction, string>(Deployment.MarketplaceAddress, func));
}
public RequestState GetRequestState(Request request)
{
var func = new RequestStateFunction
{
RequestId = request.RequestId
};
return gethNode.Call<RequestStateFunction, RequestState>(Deployment.MarketplaceAddress, func);
}
private EthAddress GetEthAddressFromTransaction(string transactionHash)
{
var transaction = gethNode.GetTransaction(transactionHash);

View File

@ -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; }

View File

@ -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()

View File

@ -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!");