2024-05-21 11:09:46 +00:00
|
|
|
|
using System.Numerics;
|
|
|
|
|
|
|
|
|
|
namespace CodexContractsPlugin
|
2023-09-19 09:51:59 +00:00
|
|
|
|
{
|
|
|
|
|
public class TestToken : IComparable<TestToken>
|
|
|
|
|
{
|
2024-05-22 09:06:34 +00:00
|
|
|
|
public static BigInteger WeiFactor = new BigInteger(1000000000000000000);
|
|
|
|
|
|
|
|
|
|
public TestToken(BigInteger tstWei)
|
2023-09-19 09:51:59 +00:00
|
|
|
|
{
|
2024-05-22 09:06:34 +00:00
|
|
|
|
TstWei = tstWei;
|
|
|
|
|
Tst = tstWei / WeiFactor;
|
2023-09-19 09:51:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 09:06:34 +00:00
|
|
|
|
public BigInteger TstWei { get; }
|
|
|
|
|
public BigInteger Tst { get; }
|
2023-09-19 09:51:59 +00:00
|
|
|
|
|
|
|
|
|
public int CompareTo(TestToken? other)
|
|
|
|
|
{
|
2024-05-22 09:06:34 +00:00
|
|
|
|
return TstWei.CompareTo(other!.TstWei);
|
2023-09-19 09:51:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object? obj)
|
|
|
|
|
{
|
2024-05-22 09:06:34 +00:00
|
|
|
|
return obj is TestToken token && TstWei == token.TstWei;
|
2023-09-19 09:51:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
2024-05-22 09:06:34 +00:00
|
|
|
|
return HashCode.Combine(TstWei);
|
2023-09-19 09:51:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2024-05-22 09:06:34 +00:00
|
|
|
|
var weiOnly = TstWei % WeiFactor;
|
|
|
|
|
|
|
|
|
|
var tokens = new List<string>();
|
|
|
|
|
if (Tst > 0) tokens.Add($"{Tst} TST");
|
|
|
|
|
if (weiOnly > 0) tokens.Add($"{weiOnly} TSTWEI");
|
|
|
|
|
|
|
|
|
|
return string.Join(" + ", tokens);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TestToken operator +(TestToken a, TestToken b)
|
|
|
|
|
{
|
|
|
|
|
return new TestToken(a.TstWei + b.TstWei);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator <(TestToken a, TestToken b)
|
|
|
|
|
{
|
|
|
|
|
return a.TstWei < b.TstWei;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator >(TestToken a, TestToken b)
|
|
|
|
|
{
|
|
|
|
|
return a.TstWei > b.TstWei;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator ==(TestToken a, TestToken b)
|
|
|
|
|
{
|
|
|
|
|
return a.TstWei == b.TstWei;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator !=(TestToken a, TestToken b)
|
|
|
|
|
{
|
|
|
|
|
return a.TstWei != b.TstWei;
|
2023-09-19 09:51:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 09:06:34 +00:00
|
|
|
|
public static class TestTokensExtensions
|
2023-09-19 09:51:59 +00:00
|
|
|
|
{
|
2024-05-22 09:06:34 +00:00
|
|
|
|
public static TestToken TstWei(this int i)
|
|
|
|
|
{
|
|
|
|
|
return TstWei(Convert.ToDecimal(i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TestToken TstWei(this decimal i)
|
2023-09-19 09:51:59 +00:00
|
|
|
|
{
|
2024-05-22 09:06:34 +00:00
|
|
|
|
return new TestToken(new BigInteger(i));
|
2023-09-19 09:51:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 09:06:34 +00:00
|
|
|
|
public static TestToken TstWei(this BigInteger i)
|
2023-09-19 09:51:59 +00:00
|
|
|
|
{
|
|
|
|
|
return new TestToken(i);
|
|
|
|
|
}
|
2024-05-21 11:09:46 +00:00
|
|
|
|
|
2024-05-22 09:06:34 +00:00
|
|
|
|
public static TestToken Tst(this int i)
|
|
|
|
|
{
|
|
|
|
|
return Tst(Convert.ToDecimal(i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TestToken Tst(this decimal i)
|
|
|
|
|
{
|
|
|
|
|
return new TestToken(new BigInteger(i) * TestToken.WeiFactor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TestToken Tst(this BigInteger i)
|
2024-05-21 11:09:46 +00:00
|
|
|
|
{
|
2024-05-22 09:06:34 +00:00
|
|
|
|
return new TestToken(i * TestToken.WeiFactor);
|
2024-05-21 11:09:46 +00:00
|
|
|
|
}
|
2023-09-19 09:51:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|