/ ProjectPlugins / CodexClient / CodexTypes.cs
CodexTypes.cs
  1  using Newtonsoft.Json;
  2  using Utils;
  3  
  4  namespace CodexClient
  5  {
  6      public class DebugInfo
  7      {
  8          public string[] Addrs { get; set; } = Array.Empty<string>();
  9          public string Spr { get; set; } = string.Empty;
 10          public string Id { get; set; } = string.Empty;
 11          public string[] AnnounceAddresses { get; set; } = Array.Empty<string>();
 12          public DebugInfoVersion Version { get; set; } = new();
 13          public DebugInfoTable Table { get; set; } = new();
 14      }
 15  
 16      public class DebugInfoVersion
 17      {
 18          public string Version { get; set; } = string.Empty;
 19          public string Revision { get; set; } = string.Empty;
 20          public string Contracts { get; set; } = string.Empty;
 21  
 22          public bool IsValid()
 23          {
 24              return !string.IsNullOrEmpty(Version) && !string.IsNullOrEmpty(Revision);
 25          }
 26  
 27          public override string ToString()
 28          {
 29              return JsonConvert.SerializeObject(this);
 30          }
 31      }
 32  
 33      public class DebugInfoTable
 34      {
 35          public DebugInfoTableNode LocalNode { get; set; } = new();
 36          public DebugInfoTableNode[] Nodes { get; set; } = Array.Empty<DebugInfoTableNode>();
 37      }
 38  
 39      public class DebugInfoTableNode
 40      {
 41          public string NodeId { get; set; } = string.Empty;
 42          public string PeerId { get; set; } = string.Empty;
 43          public string Record { get; set; } = string.Empty;
 44          public string Address { get; set; } = string.Empty;
 45          public bool Seen { get; set; }
 46      }
 47  
 48      public class DebugPeer
 49      {
 50          public bool IsPeerFound { get; set; }
 51          public string PeerId { get; set; } = string.Empty;
 52          public string[] Addresses { get; set; } = Array.Empty<string>();
 53      }
 54  
 55      public class LocalDatasetList
 56      {
 57          public LocalDataset[] Content { get; set; } = Array.Empty<LocalDataset>();
 58      } 
 59  
 60      public class LocalDataset
 61      {
 62          public ContentId Cid { get; set; } = new();
 63          public Manifest Manifest { get; set; } = new();
 64      }
 65  
 66      public class Manifest
 67      {
 68          public string RootHash { get; set; } = string.Empty;
 69          public ByteSize DatasetSize { get; set; } = ByteSize.Zero;
 70          public ByteSize BlockSize { get; set; } = ByteSize.Zero;
 71          public bool Protected { get; set; }
 72      }
 73  
 74      public class SalesRequestStorageRequest
 75      {
 76          public string Duration { get; set; } = string.Empty;
 77          public string ProofProbability { get; set; } = string.Empty;
 78          public string Reward { get; set; } = string.Empty;
 79          public string Collateral { get; set; } = string.Empty;
 80          public string? Expiry { get; set; }
 81          public uint? Nodes { get; set; }
 82          public uint? Tolerance { get; set; }
 83      }
 84  
 85      public class ContentId
 86      {
 87          public ContentId()
 88          {
 89              Id = string.Empty;
 90          }
 91  
 92          public ContentId(string id)
 93          {
 94              Id = id;
 95          }
 96  
 97          public string Id { get; }
 98  
 99          public override string ToString()
100          {
101              return Id;
102          }
103  
104          public override bool Equals(object? obj)
105          {
106              return obj is ContentId id && Id == id.Id;
107          }
108  
109          public override int GetHashCode()
110          {
111              return HashCode.Combine(Id);
112          }
113  
114          public static bool operator ==(ContentId a, ContentId b)
115          {
116              return a.Id == b.Id;
117          }
118  
119          public static bool operator !=(ContentId a, ContentId b)
120          {
121              return a.Id != b.Id;
122          }
123      }
124  
125      public class CodexSpace
126      {
127          public long TotalBlocks { get; set; }
128          public long QuotaMaxBytes { get; set; }
129          public long QuotaUsedBytes { get; set; }
130          public long QuotaReservedBytes { get; set; }
131          public long FreeBytes => QuotaMaxBytes - (QuotaUsedBytes + QuotaReservedBytes);
132  
133          public override string ToString()
134          {
135              return JsonConvert.SerializeObject(this);
136          }
137      }
138  }