From b61f5d835c4ca3b48a22a9ce32aea9914a7e482b Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 23 Nov 2023 14:10:59 +0100 Subject: [PATCH] Fixes request-storage endpoint --- .../CodexPlugin/MarketplaceAccess.cs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs b/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs index 9edea6e..d910471 100644 --- a/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs +++ b/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs @@ -10,6 +10,7 @@ namespace CodexPlugin { string MakeStorageAvailable(ByteSize size, TestToken minPriceForTotalSpace, TestToken maxCollateral, TimeSpan maxDuration); StoragePurchaseContract RequestStorage(ContentId contentId, TestToken pricePerSlotPerSecond, TestToken requiredCollateral, uint minRequiredNumberOfNodes, int proofProbability, TimeSpan duration); + StoragePurchaseContract RequestStorage(ContentId contentId, TestToken pricePerSlotPerSecond, TestToken requiredCollateral, uint minRequiredNumberOfNodes, int proofProbability, TimeSpan duration, TimeSpan expiry); } public class MarketplaceAccess : IMarketplaceAccess @@ -25,13 +26,20 @@ namespace CodexPlugin public StoragePurchaseContract RequestStorage(ContentId contentId, TestToken pricePerSlotPerSecond, TestToken requiredCollateral, uint minRequiredNumberOfNodes, int proofProbability, TimeSpan duration) { + return RequestStorage(contentId, pricePerSlotPerSecond, requiredCollateral, minRequiredNumberOfNodes, proofProbability, duration, TimeSpan.FromMinutes(5)); + } + + public StoragePurchaseContract RequestStorage(ContentId contentId, TestToken pricePerSlotPerSecond, TestToken requiredCollateral, uint minRequiredNumberOfNodes, int proofProbability, TimeSpan duration, TimeSpan expiry) + { + var expireUtc = DateTimeOffset.UtcNow.ToUnixTimeSeconds() + expiry.TotalSeconds; + var request = new CodexSalesRequestStorageRequest { duration = ToDecInt(duration.TotalSeconds), proofProbability = ToDecInt(proofProbability), reward = ToDecInt(pricePerSlotPerSecond), collateral = ToDecInt(requiredCollateral), - expiry = null, + expiry = ToDecInt(expireUtc), nodes = minRequiredNumberOfNodes, tolerance = null, }; @@ -41,11 +49,14 @@ namespace CodexPlugin $"requiredCollateral: {requiredCollateral}, " + $"minRequiredNumberOfNodes: {minRequiredNumberOfNodes}, " + $"proofProbability: {proofProbability}, " + + $"expiry: {Time.FormatDuration(expiry)}, " + $"duration: {Time.FormatDuration(duration)})"); var response = codexAccess.RequestStorage(request, contentId.Id); - if (response == "Purchasing not available") + if (response == "Purchasing not available" || + response == "Expiry required" || + response == "Expiry needs to be in future") { throw new InvalidOperationException(response); } @@ -104,6 +115,12 @@ namespace CodexPlugin return null!; } + public StoragePurchaseContract RequestStorage(ContentId contentId, TestToken pricePerSlotPerSecond, TestToken requiredCollateral, uint minRequiredNumberOfNodes, int proofProbability, TimeSpan duration, TimeSpan expiry) + { + Unavailable(); + throw new NotImplementedException(); + } + public string MakeStorageAvailable(ByteSize size, TestToken minPricePerBytePerSecond, TestToken maxCollateral, TimeSpan duration) { Unavailable();