//public Task<Transaction> GetTransactionAsync(string currentTx) //{ // return _web3.Eth.Transactions.GetTransactionByHash.SendRequestAsync(currentTx); //} public async Task <string> SetRateAsync(int rate, string buyer, BigInteger amount) { _logger?.LogDebug("Set rate {0} for buyer {1} and amount {2}", rate, buyer, amount); Contract contract = _web3.Eth.GetContract(_json.Sale.ABI.ToString(), _opts.SmartContractAddr); FixRateModel fixRateModel = await GetRateForBuyerAsync(buyer); long unixTimestamp = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; if (fixRateModel.Amount != amount || fixRateModel.Time - unixTimestamp <= 0) { var gasPrice = await _web3.Eth.GasPrice.SendRequestAsync(); var currentGasPrice = gasPrice.Value * 2; var hash = await contract.GetFunction("setRateForTransaction") .SendTransactionAsync(_opts.AppAddress, new HexBigInteger(0x153D8), new HexBigInteger(currentGasPrice), new HexBigInteger(0), rate, buyer, amount); return(hash); } return(string.Empty); }
public async Task <FixRateModel> SetRateForTransactionAsync(int rate, string buyer, BigInteger amount) { FixRateModel fixRateModel = await GetRateForBuyerAsync(buyer, amount); long unixTimestamp = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; if (fixRateModel.Amount != amount || fixRateModel.Time - unixTimestamp <= 0) { var currentGasPrice = _settings.GasPrice * UnitConversion.Convert.GetEthUnitValue(UnitConversion.EthUnit.Gwei); var hash = await _saleContract.GetFunction("setRateForTransaction") .SendTransactionAsync(_settings.AppAddress, new HexBigInteger(_settings.GasLimit), new HexBigInteger(currentGasPrice), new HexBigInteger(0), rate, buyer, amount); _logger.LogDebug("Transaction hash: {0}", hash); await WaitReciept(hash); _logger.LogDebug("done"); fixRateModel = await GetRateForBuyerAsync(buyer, amount); } return(fixRateModel); }