Example #1
0
        public async Task <OperationEstimationResult> EstimateCashoutGas(Guid id, string coinAdapterAddress, string fromAddress, string toAddress, BigInteger amount, string sign)
        {
            var blackListedAddress = await _blackListAddressesRepository.GetAsync(toAddress);

            var whiteListedAddress = await _whiteListAddressesRepository.GetAsync(toAddress);

            if (blackListedAddress != null && whiteListedAddress == null)
            {
                return(new OperationEstimationResult()
                {
                    GasAmount = Constants.GasForCoinTransaction,
                    IsAllowed = false
                });
            }

            //It is ok.
            if (ChaosKitty.MeowButLogically())
            {
                return(new OperationEstimationResult()
                {
                    GasAmount = 50000,
                    IsAllowed = true
                });
            }

            var coinAFromDb = await GetCoinWithCheck(coinAdapterAddress);

            if (string.IsNullOrEmpty(sign))
            {
                sign = await GetSign(id, coinAdapterAddress, fromAddress, toAddress, amount);
            }

            ThrowOnWrongSignature(id, coinAdapterAddress, fromAddress, toAddress, amount, sign);

            var contract    = _web3.Eth.GetContract(_settings.MainExchangeContract.Abi, _settings.MainExchangeContract.Address);
            var cashout     = contract.GetFunction("cashout");
            var convertedId = EthUtils.GuidToBigInteger(id);
            //ACTION
            var estimatedGasForOperation = await cashout.EstimateGasAsync(_settings.EthereumMainAccount,
                                                                          new HexBigInteger(Constants.GasForCoinTransaction), new HexBigInteger(0),
                                                                          convertedId,
                                                                          _addressUtil.ConvertToChecksumAddress(coinAFromDb.AdapterAddress),
                                                                          fromAddress,
                                                                          toAddress,
                                                                          amount,
                                                                          sign.HexToByteArray(),
                                                                          new byte[0]);

            return(new OperationEstimationResult()
            {
                GasAmount = estimatedGasForOperation.Value,
                IsAllowed = estimatedGasForOperation.Value < Constants.GasForCoinTransaction
            });
        }
        public async Task <IActionResult> GetWhiteListAsync([FromRoute][EthereumAddress] string address)
        {
            if (!ModelState.IsValid)
            {
                throw new ClientSideException(ExceptionType.WrongParams, JsonConvert.SerializeObject(ModelState.Errors()));
            }

            var whiteList = await _whiteListAddressesRepository.GetAsync(address);

            if (whiteList == null)
            {
                return(NotFound());
            }


            return(Ok(new EthereumAddressResponse()
            {
                Address = whiteList.Address
            }));
        }