diff --git a/Framework/NethereumWorkflow/NethereumInteraction.cs b/Framework/NethereumWorkflow/NethereumInteraction.cs index 4595d754..b8ada938 100644 --- a/Framework/NethereumWorkflow/NethereumInteraction.cs +++ b/Framework/NethereumWorkflow/NethereumInteraction.cs @@ -1,4 +1,5 @@ -using BlockchainUtils; +using System.Numerics; +using BlockchainUtils; using Logging; using Nethereum.ABI.FunctionEncoding.Attributes; using Nethereum.Contracts; @@ -22,25 +23,26 @@ namespace NethereumWorkflow this.blockCache = blockCache; } - public string SendEth(string toAddress, decimal ethAmount) + + public string SendEth(string toAddress, BigInteger ethAmount) { log.Debug(); - var receipt = Time.Wait(web3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(toAddress, ethAmount)); + var receipt = Time.Wait(web3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(toAddress, ((decimal)ethAmount))); if (!receipt.Succeeded()) throw new Exception("Unable to send Eth"); return receipt.TransactionHash; } - public decimal GetEthBalance() + public BigInteger GetEthBalance() { log.Debug(); return GetEthBalance(web3.TransactionManager.Account.Address); } - public decimal GetEthBalance(string address) + public BigInteger GetEthBalance(string address) { log.Debug(); var balance = Time.Wait(web3.Eth.GetBalance.SendRequestAsync(address)); - return Web3.Convert.FromWei(balance.Value); + return balance.Value; } public TResult Call(string contractAddress, TFunction function) where TFunction : FunctionMessage, new() @@ -57,6 +59,13 @@ namespace NethereumWorkflow return Time.Wait(handler.QueryAsync(contractAddress, function, new BlockParameter(blockNumber))); } + public void Call(string contractAddress, TFunction function) where TFunction : FunctionMessage, new() + { + log.Debug(typeof(TFunction).ToString()); + var handler = web3.Eth.GetContractQueryHandler(); + Time.Wait(handler.QueryRawAsync(contractAddress, function)); + } + public void Call(string contractAddress, TFunction function, ulong blockNumber) where TFunction : FunctionMessage, new() { log.Debug(typeof(TFunction).ToString()); diff --git a/Framework/Utils/EthTokenExtensions.cs b/Framework/Utils/EthTokenExtensions.cs index a85d121e..6fe6f346 100644 --- a/Framework/Utils/EthTokenExtensions.cs +++ b/Framework/Utils/EthTokenExtensions.cs @@ -1,15 +1,17 @@ -namespace Utils +using System.Numerics; + +namespace Utils { public class Ether : IComparable { - public Ether(decimal wei) + public Ether(BigInteger wei) { Wei = wei; Eth = wei / TokensIntExtensions.WeiPerEth; } - public decimal Wei { get; } - public decimal Eth { get; } + public BigInteger Wei { get; } + public BigInteger Eth { get; } public int CompareTo(Ether? other) { @@ -75,7 +77,7 @@ public static class TokensIntExtensions { - public const decimal WeiPerEth = 1000000000000000000; + public static readonly BigInteger WeiPerEth = new BigInteger(1000000000000000000); public static Ether Eth(this int i) { @@ -89,10 +91,22 @@ public static Ether Eth(this decimal i) { - return new Ether(i * WeiPerEth); + var a = new BigInteger(i); + return new Ether(a * WeiPerEth); } public static Ether Wei(this decimal i) + { + var a = new BigInteger(i); + return new Ether(a); + } + + public static Ether Eth(this BigInteger i) + { + return new Ether(i * WeiPerEth); + } + + public static Ether Wei(this BigInteger i) { return new Ether(i); } diff --git a/ProjectPlugins/GethPlugin/GethNode.cs b/ProjectPlugins/GethPlugin/GethNode.cs index 16ebbc99..6f307eef 100644 --- a/ProjectPlugins/GethPlugin/GethNode.cs +++ b/ProjectPlugins/GethPlugin/GethNode.cs @@ -21,6 +21,7 @@ namespace GethPlugin string SendEth(EthAddress account, Ether eth); TResult Call(string contractAddress, TFunction function) where TFunction : FunctionMessage, new(); TResult Call(string contractAddress, TFunction function, ulong blockNumber) where TFunction : FunctionMessage, new(); + void Call(string contractAddress, TFunction function) where TFunction : FunctionMessage, new(); void Call(string contractAddress, TFunction function, ulong blockNumber) where TFunction : FunctionMessage, new(); string SendTransaction(string contractAddress, TFunction function) where TFunction : FunctionMessage, new(); Transaction GetTransaction(string transactionHash); @@ -137,7 +138,7 @@ namespace GethPlugin public Ether GetEthBalance(EthAddress address) { - return StartInteraction().GetEthBalance(address.Address).Eth(); + return StartInteraction().GetEthBalance(address.Address).Wei(); } public string SendEth(IHasEthAddress owner, Ether eth) @@ -160,6 +161,11 @@ namespace GethPlugin return StartInteraction().Call(contractAddress, function, blockNumber); } + public void Call(string contractAddress, TFunction function) where TFunction : FunctionMessage, new() + { + StartInteraction().Call(contractAddress, function); + } + public void Call(string contractAddress, TFunction function, ulong blockNumber) where TFunction : FunctionMessage, new() { StartInteraction().Call(contractAddress, function, blockNumber); diff --git a/Tools/BiblioTech/Commands/MintCommand.cs b/Tools/BiblioTech/Commands/MintCommand.cs index 47126bf0..e734805e 100644 --- a/Tools/BiblioTech/Commands/MintCommand.cs +++ b/Tools/BiblioTech/Commands/MintCommand.cs @@ -93,7 +93,7 @@ namespace BiblioTech.Commands private bool ShouldSendEth(IGethNode gethNode, EthAddress addr) { var eth = gethNode.GetEthBalance(addr); - return eth.Eth < Program.Config.SendEth; + return ((decimal)eth.Eth) < Program.Config.SendEth; } private string FormatTransactionLink(string transaction)