Skip to content

Commit 83e4cb2

Browse files
committed
updates codex api
1 parent fbb8db2 commit 83e4cb2

File tree

4 files changed

+166
-75
lines changed

4 files changed

+166
-75
lines changed

ProjectPlugins/CodexClient/Mapper.cs

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using CodexOpenApi;
2-
using Newtonsoft.Json.Linq;
1+
using Newtonsoft.Json.Linq;
32
using System.Numerics;
43
using Utils;
54

@@ -37,26 +36,26 @@ public LocalDataset Map(CodexOpenApi.DataItem dataItem)
3736
};
3837
}
3938

40-
public CodexOpenApi.SalesAvailabilityCREATE Map(StorageAvailability availability)
39+
public CodexOpenApi.SalesAvailability Map(StorageAvailability availability)
4140
{
42-
return new CodexOpenApi.SalesAvailabilityCREATE
41+
return new CodexOpenApi.SalesAvailability
4342
{
44-
Duration = ToDecInt(availability.MaxDuration.TotalSeconds),
43+
Duration = ToLong(availability.MaxDuration.TotalSeconds),
4544
MinPricePerBytePerSecond = ToDecInt(availability.MinPricePerBytePerSecond),
4645
TotalCollateral = ToDecInt(availability.TotalCollateral),
47-
TotalSize = ToDecInt(availability.TotalSpace.SizeInBytes)
46+
TotalSize = availability.TotalSpace.SizeInBytes
4847
};
4948
}
5049

5150
public CodexOpenApi.StorageRequestCreation Map(StoragePurchaseRequest purchase)
5251
{
5352
return new CodexOpenApi.StorageRequestCreation
5453
{
55-
Duration = ToDecInt(purchase.Duration.TotalSeconds),
54+
Duration = ToLong(purchase.Duration.TotalSeconds),
5655
ProofProbability = ToDecInt(purchase.ProofProbability),
5756
PricePerBytePerSecond = ToDecInt(purchase.PricePerBytePerSecond),
5857
CollateralPerByte = ToDecInt(purchase.CollateralPerByte),
59-
Expiry = ToDecInt(purchase.Expiry.TotalSeconds),
58+
Expiry = ToLong(purchase.Expiry.TotalSeconds),
6059
Nodes = Convert.ToInt32(purchase.MinRequiredNumberOfNodes),
6160
Tolerance = Convert.ToInt32(purchase.NodeFailureTolerance)
6261
};
@@ -73,8 +72,8 @@ public StorageAvailability Map(CodexOpenApi.SalesAvailabilityREAD availability)
7372
(
7473
ToByteSize(availability.TotalSize),
7574
ToTimespan(availability.Duration),
76-
new TestToken(ToBigIng(availability.MinPricePerBytePerSecond)),
77-
new TestToken(ToBigIng(availability.TotalCollateral))
75+
new TestToken(ToBigInt(availability.MinPricePerBytePerSecond)),
76+
new TestToken(ToBigInt(availability.TotalCollateral))
7877
)
7978
{
8079
Id = availability.Id,
@@ -92,29 +91,29 @@ public StoragePurchase Map(CodexOpenApi.Purchase purchase)
9291
};
9392
}
9493

95-
public StoragePurchaseState Map(PurchaseState purchaseState)
94+
public StoragePurchaseState Map(CodexOpenApi.PurchaseState purchaseState)
9695
{
9796
// TODO: to be re-enabled when marketplace api lines up with openapi.yaml.
9897

9998
// Explicit mapping: If the API changes, we will get compile errors here.
10099
// That's what we want.
101100
switch (purchaseState)
102101
{
103-
case PurchaseState.Cancelled:
102+
case CodexOpenApi.PurchaseState.Cancelled:
104103
return StoragePurchaseState.Cancelled;
105-
case PurchaseState.Error:
104+
case CodexOpenApi.PurchaseState.Error:
106105
return StoragePurchaseState.Error;
107-
case PurchaseState.Failed:
106+
case CodexOpenApi.PurchaseState.Failed:
108107
return StoragePurchaseState.Failed;
109-
case PurchaseState.Finished:
108+
case CodexOpenApi.PurchaseState.Finished:
110109
return StoragePurchaseState.Finished;
111-
case PurchaseState.Pending:
110+
case CodexOpenApi.PurchaseState.Pending:
112111
return StoragePurchaseState.Pending;
113-
case PurchaseState.Started:
112+
case CodexOpenApi.PurchaseState.Started:
114113
return StoragePurchaseState.Started;
115-
case PurchaseState.Submitted:
114+
case CodexOpenApi.PurchaseState.Submitted:
116115
return StoragePurchaseState.Submitted;
117-
case PurchaseState.Unknown:
116+
case CodexOpenApi.PurchaseState.Unknown:
118117
return StoragePurchaseState.Unknown;
119118
}
120119

@@ -129,7 +128,7 @@ public StorageRequest Map(CodexOpenApi.StorageRequest request)
129128
Content = Map(request.Content),
130129
Id = request.Id,
131130
Client = request.Client,
132-
Expiry = request.Expiry,
131+
Expiry = TimeSpan.FromSeconds(request.Expiry),
133132
Nonce = request.Nonce
134133
};
135134
}
@@ -138,12 +137,12 @@ public StorageAsk Map(CodexOpenApi.StorageAsk ask)
138137
{
139138
return new StorageAsk
140139
{
141-
Duration = ask.Duration,
140+
Duration = TimeSpan.FromSeconds(ask.Duration),
142141
MaxSlotLoss = ask.MaxSlotLoss,
143142
ProofProbability = ask.ProofProbability,
144-
PricePerBytePerSecond = ask.PricePerBytePerSecond,
143+
PricePerBytePerSecond = ToTestToken(ask.PricePerBytePerSecond),
145144
Slots = ask.Slots,
146-
SlotSize = ask.SlotSize
145+
SlotSize = ToByteSize(ask.SlotSize)
147146
};
148147
}
149148

@@ -258,19 +257,29 @@ private string ToDecInt(TestToken t)
258257
return t.TstWei.ToString("D");
259258
}
260259

261-
private BigInteger ToBigIng(string tokens)
260+
private TestToken ToTestToken(string s)
261+
{
262+
return new TestToken(ToBigInt(s));
263+
}
264+
265+
private long ToLong(double value)
266+
{
267+
return Convert.ToInt64(value);
268+
}
269+
270+
private BigInteger ToBigInt(string tokens)
262271
{
263272
return BigInteger.Parse(tokens);
264273
}
265274

266-
private TimeSpan ToTimespan(string duration)
275+
private TimeSpan ToTimespan(long duration)
267276
{
268-
return TimeSpan.FromSeconds(Convert.ToInt32(duration));
277+
return TimeSpan.FromSeconds(duration);
269278
}
270279

271-
private ByteSize ToByteSize(string size)
280+
private ByteSize ToByteSize(long size)
272281
{
273-
return new ByteSize(Convert.ToInt64(size));
282+
return new ByteSize(size);
274283
}
275284
}
276285
}

ProjectPlugins/CodexClient/MarketplaceTypes.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,18 @@ public class StorageRequest
6363
public string Client { get; set; } = string.Empty;
6464
public StorageAsk Ask { get; set; } = null!;
6565
public StorageContent Content { get; set; } = null!;
66-
public string Expiry { get; set; } = string.Empty;
66+
public TimeSpan Expiry { get; set; }
6767
public string Nonce { get; set; } = string.Empty;
6868
}
6969

7070
public class StorageAsk
7171
{
72-
public int Slots { get; set; }
73-
public string SlotSize { get; set; } = string.Empty;
74-
public string Duration { get; set; } = string.Empty;
72+
public long Slots { get; set; }
73+
public ByteSize SlotSize { get; set; } = 0.Bytes();
74+
public TimeSpan Duration { get; set; }
7575
public string ProofProbability { get; set; } = string.Empty;
76-
public string PricePerBytePerSecond { get; set; } = string.Empty;
77-
public int MaxSlotLoss { get; set; }
76+
public TestToken PricePerBytePerSecond { get; set; } = 0.Tst();
77+
public long MaxSlotLoss { get; set; }
7878
}
7979

8080
public class StorageContent

0 commit comments

Comments
 (0)