MarketplaceTypes.cs
1 using Logging; 2 using Utils; 3 4 namespace CodexClient 5 { 6 public class StoragePurchaseRequest 7 { 8 public StoragePurchaseRequest(ContentId cid) 9 { 10 ContentId = cid; 11 } 12 13 public ContentId ContentId { get; } 14 public TestToken PricePerBytePerSecond { get; set; } = 1.TstWei(); 15 public TestToken CollateralPerByte { get; set; } = 1.TstWei(); 16 public uint MinRequiredNumberOfNodes { get; set; } 17 public uint NodeFailureTolerance { get; set; } 18 public int ProofProbability { get; set; } 19 public TimeSpan Duration { get; set; } 20 public TimeSpan Expiry { get; set; } 21 22 public void Log(ILog log) 23 { 24 log.Log($"Requesting storage for: {ContentId.Id}... (" + 25 $"pricePerBytePerSecond: {PricePerBytePerSecond}, " + 26 $"collateralPerByte: {CollateralPerByte}, " + 27 $"minRequiredNumberOfNodes: {MinRequiredNumberOfNodes}, " + 28 $"nodeFailureTolerance: {NodeFailureTolerance}, " + 29 $"proofProbability: {ProofProbability}, " + 30 $"expiry: {Time.FormatDuration(Expiry)}, " + 31 $"duration: {Time.FormatDuration(Duration)})"); 32 } 33 } 34 35 public class StoragePurchase 36 { 37 public StoragePurchaseState State { get; set; } = StoragePurchaseState.Unknown; 38 public string Error { get; set; } = string.Empty; 39 public StorageRequest Request { get; set; } = null!; 40 41 public bool IsCancelled => State == StoragePurchaseState.Cancelled; 42 public bool IsError => State == StoragePurchaseState.Errored; 43 public bool IsFinished => State == StoragePurchaseState.Finished; 44 public bool IsStarted => State == StoragePurchaseState.Started; 45 public bool IsSubmitted => State == StoragePurchaseState.Submitted; 46 } 47 48 public enum StoragePurchaseState 49 { 50 Cancelled = 0, 51 Errored = 1, 52 Failed = 2, 53 Finished = 3, 54 Pending = 4, 55 Started = 5, 56 Submitted = 6, 57 Unknown = 7, 58 } 59 60 public class StorageRequest 61 { 62 public string Id { get; set; } = string.Empty; 63 public string Client { get; set; } = string.Empty; 64 public StorageAsk Ask { get; set; } = null!; 65 public StorageContent Content { get; set; } = null!; 66 public long Expiry { get; set; } 67 public string Nonce { get; set; } = string.Empty; 68 } 69 70 public class StorageAsk 71 { 72 public long Slots { get; set; } 73 public long SlotSize { get; set; } 74 public long Duration { get; set; } 75 public string ProofProbability { get; set; } = string.Empty; 76 public string PricePerBytePerSecond { get; set; } = string.Empty; 77 public long MaxSlotLoss { get; set; } 78 } 79 80 public class StorageContent 81 { 82 public string Cid { get; set; } = string.Empty; 83 //public ErasureParameters Erasure { get; set; } 84 //public PoRParameters Por { get; set; } 85 } 86 87 public class CreateStorageAvailability 88 { 89 public CreateStorageAvailability(ByteSize totalSpace, TimeSpan maxDuration, TestToken minPricePerBytePerSecond, TestToken totalCollateral) 90 { 91 TotalSpace = totalSpace; 92 MaxDuration = maxDuration; 93 MinPricePerBytePerSecond = minPricePerBytePerSecond; 94 TotalCollateral = totalCollateral; 95 } 96 97 public ByteSize TotalSpace { get; } 98 public TimeSpan MaxDuration { get; } 99 public TestToken MinPricePerBytePerSecond { get; } 100 public TestToken TotalCollateral { get; } 101 102 public void Log(ILog log) 103 { 104 log.Log($"Create storage Availability: (" + 105 $"totalSize: {TotalSpace}, " + 106 $"maxDuration: {Time.FormatDuration(MaxDuration)}, " + 107 $"minPricePerBytePerSecond: {MinPricePerBytePerSecond}, " + 108 $"totalCollateral: {TotalCollateral})"); 109 } 110 } 111 112 public class StorageAvailability 113 { 114 public StorageAvailability(string id, ByteSize totalSpace, TimeSpan maxDuration, TestToken minPricePerBytePerSecond, TestToken totalCollateral, ByteSize freeSpace) 115 { 116 Id = id; 117 TotalSpace = totalSpace; 118 MaxDuration = maxDuration; 119 MinPricePerBytePerSecond = minPricePerBytePerSecond; 120 TotalCollateral = totalCollateral; 121 FreeSpace = freeSpace; 122 } 123 124 public string Id { get; } 125 public ByteSize TotalSpace { get; } 126 public TimeSpan MaxDuration { get; } 127 public TestToken MinPricePerBytePerSecond { get; } 128 public TestToken TotalCollateral { get; } 129 public ByteSize FreeSpace { get; } 130 131 public void Log(ILog log) 132 { 133 log.Log($"Storage Availability: (" + 134 $"id: {Id}, " + 135 $"totalSize: {TotalSpace}, " + 136 $"maxDuration: {Time.FormatDuration(MaxDuration)}, " + 137 $"minPricePerBytePerSecond: {MinPricePerBytePerSecond}, " + 138 $"totalCollateral: {TotalCollateral}, " + 139 $"freeSpace: {FreeSpace})"); 140 } 141 } 142 }