| | 1 | | using System.Globalization; |
| | 2 | | using NBitcoin; |
| | 3 | |
|
| | 4 | | namespace NLightning.Domain.Money; |
| | 5 | |
|
| | 6 | | using Enums; |
| | 7 | |
|
| | 8 | | public class LightningMoney : IMoney |
| | 9 | | { |
| | 10 | | // For decimal.TryParse. None of the NumberStyles' composed values is useful for bitcoin style |
| | 11 | | private const NumberStyles BITCOIN_STYLE = NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite |
| | 12 | | | NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint; |
| | 13 | |
|
| | 14 | | private ulong _milliSatoshi; |
| | 15 | |
|
| | 16 | | public const ulong COIN = 100 * 1000 * 1000 * 1000UL; |
| | 17 | | public const ulong CENT = COIN / 100; |
| | 18 | | public const ulong NANO = CENT / 100; |
| | 19 | |
|
| | 20 | | public ulong MilliSatoshi |
| | 21 | | { |
| 1740 | 22 | | get => _milliSatoshi; |
| | 23 | | set |
| | 24 | | { |
| 4588 | 25 | | _milliSatoshi = value; |
| 4588 | 26 | | } |
| | 27 | | } |
| | 28 | |
|
| | 29 | | public long Satoshi |
| | 30 | | { |
| 1056 | 31 | | get => checked((long)(_milliSatoshi / 1000)); |
| | 32 | | set |
| | 33 | | { |
| 144 | 34 | | if (value < 0) |
| 4 | 35 | | throw new ArgumentOutOfRangeException(nameof(value), "Satoshi value cannot be negative"); |
| | 36 | |
|
| | 37 | | checked |
| | 38 | | { |
| 140 | 39 | | _milliSatoshi = (ulong)(value * 1000); |
| | 40 | | } |
| 140 | 41 | | } |
| | 42 | | } |
| | 43 | |
|
| 988 | 44 | | public static LightningMoney Zero => 0UL; |
| 2036 | 45 | | public bool IsZero => _milliSatoshi == 0; |
| | 46 | |
|
| | 47 | | #region Constructors |
| 2988 | 48 | | public LightningMoney(ulong milliSatoshi) |
| | 49 | | { |
| 2988 | 50 | | MilliSatoshi = milliSatoshi; |
| 2988 | 51 | | } |
| | 52 | |
|
| 160 | 53 | | public LightningMoney(decimal amount, LightningMoneyUnit unit) |
| | 54 | | { |
| | 55 | | // sanity check. Only valid units are allowed |
| 160 | 56 | | CheckLightningMoneyUnit(unit, nameof(unit)); |
| | 57 | | checked |
| | 58 | | { |
| 156 | 59 | | var milliSats = amount * (long)unit; |
| 156 | 60 | | MilliSatoshi = (ulong)milliSats; |
| | 61 | | } |
| 152 | 62 | | } |
| | 63 | |
|
| 316 | 64 | | public LightningMoney(long amount, LightningMoneyUnit unit) |
| | 65 | | { |
| | 66 | | // Sanity check. Only valid units are allowed |
| 316 | 67 | | CheckLightningMoneyUnit(unit, nameof(unit)); |
| | 68 | | checked |
| | 69 | | { |
| 316 | 70 | | var milliSats = amount * (long)unit; |
| 316 | 71 | | MilliSatoshi = (ulong)milliSats; |
| | 72 | | } |
| 316 | 73 | | } |
| | 74 | |
|
| 1132 | 75 | | public LightningMoney(ulong amount, LightningMoneyUnit unit) |
| | 76 | | { |
| | 77 | | // Sanity check. Only valid units are allowed |
| 1132 | 78 | | CheckLightningMoneyUnit(unit, nameof(unit)); |
| | 79 | | checked |
| | 80 | | { |
| 1132 | 81 | | var milliSats = amount * (ulong)unit; |
| 1132 | 82 | | MilliSatoshi = milliSats; |
| | 83 | | } |
| 1132 | 84 | | } |
| | 85 | | #endregion |
| | 86 | |
|
| | 87 | | #region Parsers |
| | 88 | | /// <summary> |
| | 89 | | /// Parse a bitcoin amount (Culture Invariant) |
| | 90 | | /// </summary> |
| | 91 | | /// <param name="bitcoin"></param> |
| | 92 | | /// <param name="nRet"></param> |
| | 93 | | /// <returns></returns> |
| | 94 | | public static bool TryParse(string bitcoin, out LightningMoney? nRet) |
| | 95 | | { |
| 16 | 96 | | nRet = null; |
| | 97 | |
|
| 16 | 98 | | if (!decimal.TryParse(bitcoin, BITCOIN_STYLE, CultureInfo.InvariantCulture, out var value)) |
| | 99 | | { |
| 8 | 100 | | return false; |
| | 101 | | } |
| | 102 | |
|
| | 103 | | try |
| | 104 | | { |
| 8 | 105 | | nRet = new LightningMoney(value, LightningMoneyUnit.Btc); |
| 8 | 106 | | return true; |
| | 107 | | } |
| 0 | 108 | | catch (OverflowException) |
| | 109 | | { |
| 0 | 110 | | return false; |
| | 111 | | } |
| 8 | 112 | | } |
| | 113 | |
|
| | 114 | | /// <summary> |
| | 115 | | /// Parse a bitcoin amount (Culture Invariant) |
| | 116 | | /// </summary> |
| | 117 | | /// <param name="bitcoin"></param> |
| | 118 | | /// <returns></returns> |
| | 119 | | public static LightningMoney? Parse(string bitcoin) |
| | 120 | | { |
| 8 | 121 | | if (TryParse(bitcoin, out var result)) |
| | 122 | | { |
| 4 | 123 | | return result; |
| | 124 | | } |
| 4 | 125 | | throw new FormatException("Impossible to parse the string in a bitcoin amount"); |
| | 126 | | } |
| | 127 | | #endregion |
| | 128 | |
|
| | 129 | | #region Conversions |
| | 130 | | /// <summary> |
| | 131 | | /// Convert Money to decimal (same as ToDecimal) |
| | 132 | | /// </summary> |
| | 133 | | /// <param name="unit"></param> |
| | 134 | | /// <returns></returns> |
| | 135 | | public decimal ToUnit(LightningMoneyUnit unit) |
| | 136 | | { |
| 184 | 137 | | CheckLightningMoneyUnit(unit, nameof(unit)); |
| | 138 | | // overflow safe because (long / int) always fit in decimal |
| | 139 | | // decimal operations are checked by default |
| 184 | 140 | | return (decimal)MilliSatoshi / (ulong)unit; |
| | 141 | | } |
| | 142 | | /// <summary> |
| | 143 | | /// Convert Money to decimal (same as ToUnit) |
| | 144 | | /// </summary> |
| | 145 | | /// <param name="unit"></param> |
| | 146 | | /// <returns></returns> |
| | 147 | | public decimal ToDecimal(LightningMoneyUnit unit) |
| | 148 | | { |
| 8 | 149 | | return ToUnit(unit); |
| | 150 | | } |
| | 151 | | #endregion |
| | 152 | |
|
| | 153 | | /// <summary> |
| | 154 | | /// Split the Money in parts without loss |
| | 155 | | /// </summary> |
| | 156 | | /// <param name="parts">The number of parts (must be more than 0)</param> |
| | 157 | | /// <returns>The split money</returns> |
| | 158 | | public IEnumerable<LightningMoney> Split(int parts) |
| | 159 | | { |
| 4 | 160 | | if (parts <= 0) |
| 0 | 161 | | throw new ArgumentOutOfRangeException(nameof(parts), "Parts should be more than 0"); |
| | 162 | |
|
| 4 | 163 | | var result = DivRem(_milliSatoshi, (ulong)parts, out var remain); |
| | 164 | |
|
| 32 | 165 | | for (var i = 0; i < parts; i++) |
| | 166 | | { |
| 12 | 167 | | yield return MilliSatoshis(result + (remain > 0 ? 1UL : 0UL)); |
| 12 | 168 | | if (remain > 0) |
| | 169 | | { |
| 4 | 170 | | remain--; |
| | 171 | | } |
| | 172 | | } |
| 4 | 173 | | } |
| | 174 | | IEnumerable<IMoney> IMoney.Split(int parts) |
| | 175 | | { |
| 0 | 176 | | return Split(parts); |
| | 177 | | } |
| | 178 | |
|
| | 179 | | #region Static Converters |
| | 180 | | public static LightningMoney FromUnit(decimal amount, LightningMoneyUnit unit) |
| | 181 | | { |
| 124 | 182 | | return new LightningMoney(amount, unit); |
| | 183 | | } |
| | 184 | |
|
| | 185 | | public static LightningMoney Coins(decimal coins) |
| | 186 | | { |
| | 187 | | // overflow safe. |
| | 188 | | // decimal operations are checked by default |
| 4 | 189 | | return new LightningMoney(coins * COIN, LightningMoneyUnit.MilliSatoshi); |
| | 190 | | } |
| | 191 | |
|
| | 192 | | public static LightningMoney Bits(decimal bits) |
| | 193 | | { |
| | 194 | | // overflow safe. |
| | 195 | | // decimal operations are checked by default |
| 4 | 196 | | return new LightningMoney(bits * CENT, LightningMoneyUnit.MilliSatoshi); |
| | 197 | | } |
| | 198 | |
|
| | 199 | | public static LightningMoney Cents(decimal cents) |
| | 200 | | { |
| | 201 | | // overflow safe. |
| | 202 | | // decimal operations are checked by default |
| 4 | 203 | | return new LightningMoney(cents * CENT, LightningMoneyUnit.MilliSatoshi); |
| | 204 | | } |
| | 205 | |
|
| | 206 | | public static LightningMoney Satoshis(decimal sats) |
| | 207 | | { |
| 4 | 208 | | return new LightningMoney(sats, LightningMoneyUnit.Satoshi); |
| | 209 | | } |
| | 210 | |
|
| | 211 | | public static LightningMoney Satoshis(ulong sats) |
| | 212 | | { |
| 48 | 213 | | return new LightningMoney(sats, LightningMoneyUnit.Satoshi); |
| | 214 | | } |
| | 215 | |
|
| | 216 | | public static LightningMoney Satoshis(long sats) |
| | 217 | | { |
| 1080 | 218 | | return new LightningMoney((ulong)sats, LightningMoneyUnit.Satoshi); |
| | 219 | | } |
| | 220 | |
|
| | 221 | | public static LightningMoney MilliSatoshis(ulong milliSats) |
| | 222 | | { |
| 16 | 223 | | return new LightningMoney(milliSats); |
| | 224 | | } |
| | 225 | |
|
| | 226 | | public static LightningMoney MilliSatoshis(long sats) |
| | 227 | | { |
| 28 | 228 | | return new LightningMoney((ulong)sats); |
| | 229 | | } |
| | 230 | | #endregion |
| | 231 | |
|
| | 232 | | #region IEquatable<Money> Members |
| | 233 | | public bool Equals(LightningMoney? other) |
| | 234 | | { |
| 24 | 235 | | return other is not null && _milliSatoshi.Equals(other._milliSatoshi); |
| | 236 | | } |
| | 237 | | bool IEquatable<IMoney>.Equals(IMoney? other) |
| | 238 | | { |
| 0 | 239 | | return Equals(other); |
| | 240 | | } |
| | 241 | |
|
| | 242 | | public int CompareTo(LightningMoney? other) |
| | 243 | | { |
| 604 | 244 | | return other is null ? 1 : _milliSatoshi.CompareTo(other._milliSatoshi); |
| | 245 | | } |
| | 246 | |
|
| | 247 | | bool IMoney.IsCompatible(IMoney money) |
| | 248 | | { |
| 8 | 249 | | ArgumentNullException.ThrowIfNull(money); |
| | 250 | |
|
| 8 | 251 | | return money is LightningMoney; |
| | 252 | | } |
| | 253 | | #endregion |
| | 254 | |
|
| | 255 | | #region IComparable Members |
| | 256 | | public int CompareTo(object? obj) |
| | 257 | | { |
| 128 | 258 | | return obj switch |
| 128 | 259 | | { |
| 0 | 260 | | null => 1, |
| 128 | 261 | | LightningMoney m => _milliSatoshi.CompareTo(m._milliSatoshi), |
| 0 | 262 | | _ => _milliSatoshi.CompareTo((ulong)obj) |
| 128 | 263 | | }; |
| | 264 | | } |
| | 265 | | int IComparable.CompareTo(object? obj) |
| | 266 | | { |
| 0 | 267 | | return CompareTo(obj); |
| | 268 | | } |
| | 269 | | int IComparable<IMoney>.CompareTo(IMoney? other) |
| | 270 | | { |
| 128 | 271 | | return CompareTo(other); |
| | 272 | | } |
| | 273 | | #endregion |
| | 274 | |
|
| | 275 | | #region Unary Operators |
| | 276 | | public static LightningMoney operator -(LightningMoney left, LightningMoney right) |
| | 277 | | { |
| 236 | 278 | | ArgumentNullException.ThrowIfNull(left); |
| 236 | 279 | | ArgumentNullException.ThrowIfNull(right); |
| | 280 | |
|
| 236 | 281 | | if (left._milliSatoshi < right._milliSatoshi) |
| 0 | 282 | | throw new ArithmeticException("LightningMoney does not support negative values"); |
| | 283 | |
|
| 236 | 284 | | return new LightningMoney(checked(left._milliSatoshi - right._milliSatoshi)); |
| | 285 | | } |
| | 286 | | public static LightningMoney operator -(LightningMoney _) |
| | 287 | | { |
| 0 | 288 | | throw new ArithmeticException("LightningMoney does not support unary negation"); |
| | 289 | | } |
| | 290 | | public static LightningMoney operator +(LightningMoney left, LightningMoney right) |
| | 291 | | { |
| 136 | 292 | | ArgumentNullException.ThrowIfNull(left); |
| 136 | 293 | | ArgumentNullException.ThrowIfNull(right); |
| | 294 | |
|
| 136 | 295 | | return new LightningMoney(checked(left._milliSatoshi + right._milliSatoshi)); |
| | 296 | | } |
| | 297 | | public static LightningMoney operator *(ulong left, LightningMoney right) |
| | 298 | | { |
| 0 | 299 | | ArgumentNullException.ThrowIfNull(right); |
| | 300 | |
|
| 0 | 301 | | return MilliSatoshis(checked(left * right._milliSatoshi)); |
| | 302 | | } |
| | 303 | |
|
| | 304 | | public static LightningMoney operator *(LightningMoney left, ulong right) |
| | 305 | | { |
| 0 | 306 | | ArgumentNullException.ThrowIfNull(left); |
| | 307 | |
|
| 0 | 308 | | return MilliSatoshis(checked(left._milliSatoshi * right)); |
| | 309 | | } |
| | 310 | | public static LightningMoney operator *(long left, LightningMoney right) |
| | 311 | | { |
| 0 | 312 | | ArgumentNullException.ThrowIfNull(right); |
| | 313 | |
|
| 0 | 314 | | return MilliSatoshis(checked((ulong)left * right._milliSatoshi)); |
| | 315 | | } |
| | 316 | | public static LightningMoney operator *(LightningMoney left, long right) |
| | 317 | | { |
| 0 | 318 | | ArgumentNullException.ThrowIfNull(left); |
| | 319 | |
|
| 0 | 320 | | return MilliSatoshis(checked((ulong)right * left._milliSatoshi)); |
| | 321 | | } |
| | 322 | |
|
| | 323 | | public static LightningMoney operator /(LightningMoney left, ulong right) |
| | 324 | | { |
| 0 | 325 | | ArgumentNullException.ThrowIfNull(left); |
| | 326 | |
|
| 0 | 327 | | return new LightningMoney(left._milliSatoshi / right); |
| | 328 | | } |
| | 329 | |
|
| | 330 | | public static bool operator <(LightningMoney left, LightningMoney right) |
| | 331 | | { |
| 4 | 332 | | ArgumentNullException.ThrowIfNull(left); |
| 4 | 333 | | ArgumentNullException.ThrowIfNull(right); |
| | 334 | |
|
| 4 | 335 | | return left._milliSatoshi < right._milliSatoshi; |
| | 336 | | } |
| | 337 | | public static bool operator >(LightningMoney left, LightningMoney right) |
| | 338 | | { |
| 120 | 339 | | ArgumentNullException.ThrowIfNull(left); |
| 120 | 340 | | ArgumentNullException.ThrowIfNull(right); |
| | 341 | |
|
| 120 | 342 | | return left._milliSatoshi > right._milliSatoshi; |
| | 343 | | } |
| | 344 | | public static bool operator <=(LightningMoney left, LightningMoney right) |
| | 345 | | { |
| 148 | 346 | | ArgumentNullException.ThrowIfNull(left); |
| 148 | 347 | | ArgumentNullException.ThrowIfNull(right); |
| | 348 | |
|
| 148 | 349 | | return left._milliSatoshi <= right._milliSatoshi; |
| | 350 | | } |
| | 351 | | public static bool operator >=(LightningMoney left, LightningMoney right) |
| | 352 | | { |
| 256 | 353 | | ArgumentNullException.ThrowIfNull(left); |
| 256 | 354 | | ArgumentNullException.ThrowIfNull(right); |
| | 355 | |
|
| 256 | 356 | | return left._milliSatoshi >= right._milliSatoshi; |
| | 357 | | } |
| | 358 | | #endregion |
| | 359 | |
|
| | 360 | | #region Implicit Operators |
| | 361 | | public static implicit operator LightningMoney(long value) |
| | 362 | | { |
| 296 | 363 | | return new LightningMoney((ulong)value); |
| | 364 | | } |
| | 365 | | public static implicit operator LightningMoney(ulong value) |
| | 366 | | { |
| 1804 | 367 | | return new LightningMoney(value); |
| | 368 | | } |
| | 369 | | public static implicit operator LightningMoney(NBitcoin.Money value) |
| | 370 | | { |
| 148 | 371 | | return new LightningMoney((ulong)value.Satoshi * 1_000UL); |
| | 372 | | } |
| | 373 | | public static implicit operator LightningMoney(string value) |
| | 374 | | { |
| 0 | 375 | | return Parse(value) ?? throw new ArgumentException("Cannot parse value into a valid LightningMoney", nameof(valu |
| | 376 | | } |
| | 377 | |
|
| | 378 | | public static implicit operator long(LightningMoney value) |
| | 379 | | { |
| 672 | 380 | | return checked((long)value.MilliSatoshi); |
| | 381 | | } |
| | 382 | |
|
| | 383 | | public static implicit operator ulong(LightningMoney value) |
| | 384 | | { |
| 32 | 385 | | return value.MilliSatoshi; |
| | 386 | | } |
| | 387 | |
|
| | 388 | | public static implicit operator NBitcoin.Money(LightningMoney value) |
| | 389 | | { |
| 704 | 390 | | return new NBitcoin.Money(value.Satoshi); |
| | 391 | | } |
| | 392 | | #endregion |
| | 393 | |
|
| | 394 | | #region Equality Operators |
| | 395 | | public override bool Equals(object? obj) |
| | 396 | | { |
| 0 | 397 | | return obj is LightningMoney item && _milliSatoshi.Equals(item._milliSatoshi); |
| | 398 | | } |
| | 399 | |
|
| | 400 | | public override int GetHashCode() |
| | 401 | | { |
| 0 | 402 | | return _milliSatoshi.GetHashCode(); |
| | 403 | | } |
| | 404 | |
|
| | 405 | | public static bool operator ==(LightningMoney? a, LightningMoney? b) |
| | 406 | | { |
| 240 | 407 | | if (ReferenceEquals(a, b)) |
| 0 | 408 | | return true; |
| 240 | 409 | | if (a is null || b is null) |
| 0 | 410 | | return false; |
| 240 | 411 | | return a._milliSatoshi == b._milliSatoshi; |
| | 412 | | } |
| | 413 | |
|
| | 414 | | public static bool operator !=(LightningMoney a, LightningMoney b) |
| | 415 | | { |
| 100 | 416 | | return !(a == b); |
| | 417 | | } |
| | 418 | | #endregion |
| | 419 | |
|
| | 420 | | #region ToString |
| | 421 | | /// <summary> |
| | 422 | | /// Returns a culture invariant string representation of Bitcoin amount |
| | 423 | | /// </summary> |
| | 424 | | /// <returns></returns> |
| | 425 | | public override string ToString() |
| | 426 | | { |
| 0 | 427 | | return ToString(false); |
| | 428 | | } |
| | 429 | | /// <summary> |
| | 430 | | /// Returns a culture invariant string representation of Bitcoin amount |
| | 431 | | /// </summary> |
| | 432 | | /// <param name="trimExcessZero">True if trim excess zeros</param> |
| | 433 | | /// <returns></returns> |
| | 434 | | public string ToString(bool trimExcessZero = true) |
| | 435 | | { |
| 12 | 436 | | var val = (decimal)_milliSatoshi / (ulong)LightningMoneyUnit.Btc; |
| 12 | 437 | | var decPos = trimExcessZero ? 2 : 11; |
| 12 | 438 | | var zeros = new string('0', decPos); |
| 12 | 439 | | var rest = new string('#', 11 - decPos); |
| 12 | 440 | | var fmt = "{0:0" + ("." + zeros + rest) + "}"; |
| | 441 | |
|
| 12 | 442 | | return string.Format(CultureInfo.InvariantCulture, fmt, val); |
| | 443 | | } |
| | 444 | | #endregion |
| | 445 | |
|
| | 446 | | /// <summary> |
| | 447 | | /// Tell if the amount is almost equal to this instance |
| | 448 | | /// </summary> |
| | 449 | | /// <param name="amount"></param> |
| | 450 | | /// <param name="dust">more or less amount</param> |
| | 451 | | /// <returns>true if equals, else false</returns> |
| | 452 | | public bool Almost(LightningMoney amount, LightningMoney dust) |
| | 453 | | { |
| 8 | 454 | | ArgumentNullException.ThrowIfNull(amount); |
| 8 | 455 | | ArgumentNullException.ThrowIfNull(dust); |
| | 456 | |
|
| 8 | 457 | | return amount - this <= dust; |
| | 458 | | } |
| | 459 | |
|
| | 460 | | /// <summary> |
| | 461 | | /// Tell if the amount is almost equal to this instance |
| | 462 | | /// </summary> |
| | 463 | | /// <param name="amount"></param> |
| | 464 | | /// <param name="margin">error margin (between 0 and 1)</param> |
| | 465 | | /// <returns>true if equals, else false</returns> |
| | 466 | | public bool Almost(LightningMoney amount, decimal margin) |
| | 467 | | { |
| 4 | 468 | | ArgumentNullException.ThrowIfNull(amount); |
| 4 | 469 | | if (margin is < 0.0m or > 1.0m) |
| 0 | 470 | | throw new ArgumentOutOfRangeException(nameof(margin), "margin should be between 0 and 1"); |
| | 471 | |
|
| 4 | 472 | | var dust = new LightningMoney(MilliSatoshi * margin, LightningMoneyUnit.MilliSatoshi); |
| 4 | 473 | | return Almost(amount, dust); |
| | 474 | | } |
| | 475 | |
|
| | 476 | | public static LightningMoney Min(LightningMoney a, LightningMoney b) |
| | 477 | | { |
| 4 | 478 | | ArgumentNullException.ThrowIfNull(a); |
| 4 | 479 | | ArgumentNullException.ThrowIfNull(b); |
| | 480 | |
|
| 4 | 481 | | return a <= b ? a : b; |
| | 482 | | } |
| | 483 | |
|
| | 484 | | public static LightningMoney Max(LightningMoney a, LightningMoney b) |
| | 485 | | { |
| 4 | 486 | | ArgumentNullException.ThrowIfNull(a); |
| 4 | 487 | | ArgumentNullException.ThrowIfNull(b); |
| | 488 | |
|
| 4 | 489 | | return a >= b ? a : b; |
| | 490 | | } |
| | 491 | |
|
| | 492 | | #region IMoney Members |
| | 493 | | public IMoney Add(IMoney money) |
| | 494 | | { |
| 0 | 495 | | return this + (LightningMoney)money; |
| | 496 | | } |
| | 497 | |
|
| | 498 | | public IMoney Sub(IMoney money) |
| | 499 | | { |
| 0 | 500 | | return this - (LightningMoney)money; |
| | 501 | | } |
| | 502 | |
|
| | 503 | | public IMoney Negate() |
| | 504 | | { |
| 4 | 505 | | throw new ArithmeticException("LightningMoney does not support unary negation"); |
| | 506 | | } |
| | 507 | | #endregion |
| | 508 | |
|
| | 509 | | private static void CheckLightningMoneyUnit(LightningMoneyUnit value, string paramName) |
| | 510 | | { |
| 1792 | 511 | | var typeOfMoneyUnit = typeof(LightningMoneyUnit); |
| 1792 | 512 | | if (!Enum.IsDefined(typeOfMoneyUnit, value)) |
| | 513 | | { |
| 4 | 514 | | throw new ArgumentException("Invalid value for LightningMoneyUnit", paramName); |
| | 515 | | } |
| 1788 | 516 | | } |
| | 517 | |
|
| | 518 | | private static ulong DivRem(ulong a, ulong b, out ulong result) |
| | 519 | | { |
| 4 | 520 | | result = a % b; |
| 4 | 521 | | return a / b; |
| | 522 | | } |
| | 523 | | } |