Restores marketplace access
This commit is contained in:
parent
3bd297a22d
commit
f57188914e
@ -85,11 +85,12 @@ namespace CodexPlugin
|
|||||||
public string RequestStorage(StoragePurchaseRequest request)
|
public string RequestStorage(StoragePurchaseRequest request)
|
||||||
{
|
{
|
||||||
var body = Map(request);
|
var body = Map(request);
|
||||||
|
throw new Exception("todo");
|
||||||
var read = ""; /* fix incoming*/ OnCodex<string>(api => api.CreateStorageRequestAsync(request.ContentId.Id, body));
|
var read = ""; /* fix incoming*/ OnCodex<string>(api => api.CreateStorageRequestAsync(request.ContentId.Id, body));
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StoragePurchaseRequest GetPurchaseStatus(string purchaseId)
|
public StoragePurchase GetPurchaseStatus(string purchaseId)
|
||||||
{
|
{
|
||||||
return Map(OnCodex(api => api.GetPurchaseAsync(purchaseId)));
|
return Map(OnCodex(api => api.GetPurchaseAsync(purchaseId)));
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ namespace CodexPlugin
|
|||||||
|
|
||||||
public LocalDataset[] Map(ICollection<CodexOpenApi.DataList> dataList)
|
public LocalDataset[] Map(ICollection<CodexOpenApi.DataList> dataList)
|
||||||
{
|
{
|
||||||
|
throw new Exception("todo");
|
||||||
return Array.Empty<LocalDataset>();
|
return Array.Empty<LocalDataset>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +59,19 @@ namespace CodexPlugin
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StorageAvailability Map(CodexOpenApi.SalesAvailabilityREAD read)
|
||||||
|
{
|
||||||
|
return new StorageAvailability(
|
||||||
|
totalSpace: new Utils.ByteSize(Convert.ToInt64(read.TotalSize)),
|
||||||
|
maxDuration: TimeSpan.FromSeconds(Convert.ToDouble(read.Duration)),
|
||||||
|
minPriceForTotalSpace: new TestToken(Convert.ToDecimal(read.MinPrice)),
|
||||||
|
maxCollateral: new TestToken(Convert.ToDecimal(read.MaxCollateral))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Id = read.Id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private DebugInfoVersion MapDebugInfoVersion(JObject obj)
|
private DebugInfoVersion MapDebugInfoVersion(JObject obj)
|
||||||
{
|
{
|
||||||
return new DebugInfoVersion
|
return new DebugInfoVersion
|
||||||
|
@ -7,7 +7,7 @@ namespace CodexPlugin
|
|||||||
public interface IMarketplaceAccess
|
public interface IMarketplaceAccess
|
||||||
{
|
{
|
||||||
string MakeStorageAvailable(StorageAvailability availability);
|
string MakeStorageAvailable(StorageAvailability availability);
|
||||||
StoragePurchaseContract RequestStorage(StoragePurchase purchase);
|
StoragePurchaseContract RequestStorage(StoragePurchaseRequest purchase);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MarketplaceAccess : IMarketplaceAccess
|
public class MarketplaceAccess : IMarketplaceAccess
|
||||||
@ -21,14 +21,14 @@ namespace CodexPlugin
|
|||||||
this.codexAccess = codexAccess;
|
this.codexAccess = codexAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StoragePurchaseContract RequestStorage(StoragePurchase purchase)
|
public StoragePurchaseContract RequestStorage(StoragePurchaseRequest purchase)
|
||||||
{
|
{
|
||||||
purchase.Log(log);
|
purchase.Log(log);
|
||||||
var request = purchase.ToApiRequest();
|
|
||||||
|
|
||||||
var response = codexAccess.RequestStorage(request, purchase.ContentId.Id);
|
var response = codexAccess.RequestStorage(purchase);
|
||||||
|
|
||||||
if (response == "Purchasing not available" ||
|
if (string.IsNullOrEmpty(response) ||
|
||||||
|
response == "Purchasing not available" ||
|
||||||
response == "Expiry required" ||
|
response == "Expiry required" ||
|
||||||
response == "Expiry needs to be in future" ||
|
response == "Expiry needs to be in future" ||
|
||||||
response == "Expiry has to be before the request's end (now + duration)")
|
response == "Expiry has to be before the request's end (now + duration)")
|
||||||
@ -44,13 +44,12 @@ namespace CodexPlugin
|
|||||||
public string MakeStorageAvailable(StorageAvailability availability)
|
public string MakeStorageAvailable(StorageAvailability availability)
|
||||||
{
|
{
|
||||||
availability.Log(log);
|
availability.Log(log);
|
||||||
var request = availability.ToApiRequest();
|
|
||||||
|
|
||||||
var response = codexAccess.SalesAvailability(request);
|
var response = codexAccess.SalesAvailability(availability);
|
||||||
|
|
||||||
Log($"Storage successfully made available. Id: {response.id}");
|
Log($"Storage successfully made available. Id: {response.Id}");
|
||||||
|
|
||||||
return response.id;
|
return response.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Log(string msg)
|
private void Log(string msg)
|
||||||
@ -67,7 +66,7 @@ namespace CodexPlugin
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StoragePurchaseContract RequestStorage(StoragePurchase purchase)
|
public StoragePurchaseContract RequestStorage(StoragePurchaseRequest purchase)
|
||||||
{
|
{
|
||||||
Unavailable();
|
Unavailable();
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
@ -87,7 +86,7 @@ namespace CodexPlugin
|
|||||||
private readonly TimeSpan gracePeriod = TimeSpan.FromSeconds(10);
|
private readonly TimeSpan gracePeriod = TimeSpan.FromSeconds(10);
|
||||||
private DateTime? contractStartUtc;
|
private DateTime? contractStartUtc;
|
||||||
|
|
||||||
public StoragePurchaseContract(ILog log, CodexAccess codexAccess, string purchaseId, StoragePurchase purchase)
|
public StoragePurchaseContract(ILog log, CodexAccess codexAccess, string purchaseId, StoragePurchaseRequest purchase)
|
||||||
{
|
{
|
||||||
this.log = log;
|
this.log = log;
|
||||||
this.codexAccess = codexAccess;
|
this.codexAccess = codexAccess;
|
||||||
@ -96,7 +95,7 @@ namespace CodexPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string PurchaseId { get; }
|
public string PurchaseId { get; }
|
||||||
public StoragePurchase Purchase { get; }
|
public StoragePurchaseRequest Purchase { get; }
|
||||||
|
|
||||||
public void WaitForStorageContractStarted()
|
public void WaitForStorageContractStarted()
|
||||||
{
|
{
|
||||||
@ -117,7 +116,7 @@ namespace CodexPlugin
|
|||||||
WaitForStorageContractState(timeout, "finished");
|
WaitForStorageContractState(timeout, "finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
public CodexStoragePurchase GetPurchaseStatus(string purchaseId)
|
public StoragePurchase GetPurchaseStatus(string purchaseId)
|
||||||
{
|
{
|
||||||
return codexAccess.GetPurchaseStatus(purchaseId);
|
return codexAccess.GetPurchaseStatus(purchaseId);
|
||||||
}
|
}
|
||||||
@ -132,9 +131,9 @@ namespace CodexPlugin
|
|||||||
{
|
{
|
||||||
var purchaseStatus = codexAccess.GetPurchaseStatus(PurchaseId);
|
var purchaseStatus = codexAccess.GetPurchaseStatus(PurchaseId);
|
||||||
var statusJson = JsonConvert.SerializeObject(purchaseStatus);
|
var statusJson = JsonConvert.SerializeObject(purchaseStatus);
|
||||||
if (purchaseStatus != null && purchaseStatus.state != lastState)
|
if (purchaseStatus != null && purchaseStatus.State != lastState)
|
||||||
{
|
{
|
||||||
lastState = purchaseStatus.state;
|
lastState = purchaseStatus.State;
|
||||||
log.Debug("Purchase status: " + statusJson);
|
log.Debug("Purchase status: " + statusJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ namespace CodexPlugin
|
|||||||
MaxCollateral = maxCollateral;
|
MaxCollateral = maxCollateral;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Id { get; set; } = string.Empty;
|
||||||
public ByteSize TotalSpace { get; }
|
public ByteSize TotalSpace { get; }
|
||||||
public TimeSpan MaxDuration { get; }
|
public TimeSpan MaxDuration { get; }
|
||||||
public TestToken MinPriceForTotalSpace { get; }
|
public TestToken MinPriceForTotalSpace { get; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user