cs-codex-dist-tests/ProjectPlugins/GethPlugin/EthTokenExtensions.cs

60 lines
1.3 KiB
C#
Raw Normal View History

2023-09-19 09:51:59 +00:00
namespace GethPlugin
{
public class Ether : IComparable<Ether>
{
public Ether(decimal wei)
{
Wei = wei;
2023-09-19 09:51:59 +00:00
Eth = wei / TokensIntExtensions.WeiPerEth;
}
public decimal Wei { get; }
2023-09-19 09:51:59 +00:00
public decimal Eth { get; }
public int CompareTo(Ether? other)
{
return Wei.CompareTo(other!.Wei);
}
public override bool Equals(object? obj)
{
return obj is Ether ether && Wei == ether.Wei;
}
public override int GetHashCode()
{
return HashCode.Combine(Wei);
}
public override string ToString()
{
return $"{Eth} Eth";
}
}
public static class TokensIntExtensions
{
2023-09-19 09:51:59 +00:00
public const decimal WeiPerEth = 1000000000000000000;
public static Ether Eth(this int i)
{
return Eth(Convert.ToDecimal(i));
}
public static Ether Wei(this int i)
{
return Wei(Convert.ToDecimal(i));
}
public static Ether Eth(this decimal i)
{
2023-09-19 09:51:59 +00:00
return new Ether(i * WeiPerEth);
}
public static Ether Wei(this decimal i)
{
return new Ether(i);
}
}
}