public async Task CompleteTransfer(TransferContractUserAssignment assignment)
        {
            ICoin coinAdapter = await _coinRepository.GetCoinByAddress(assignment.CoinAdapterAddress);

            if (coinAdapter == null)
            {
                throw new Exception($"CoinAdapterAddress {assignment.CoinAdapterAddress} does not exis");
            }

            string coinAbi;

            if (coinAdapter.ContainsEth)
            {
                coinAbi = _settings.EthAdapterContract.Abi;
            }
            else
            {
                coinAbi = _settings.TokenAdapterContract.Abi;
            }

            var ethereumContract = _web3.Eth.GetContract(coinAbi, assignment.CoinAdapterAddress);
            var function         = ethereumContract.GetFunction("setTransferAddressUser");
            //function setTransferAddressUser(address userAddress, address transferAddress) onlyowner{

            string transactionHash =
                await function.SendTransactionAsync(_settings.EthereumMainAccount,
                                                    assignment.UserAddress, assignment.TransferContractAddress);

            var transferContract = await _transferContractRepository.GetAsync(assignment.TransferContractAddress);

            transferContract.AssignmentHash = transactionHash;

            await _transferContractRepository.SaveAsync(transferContract);
        }
        public async Task TestCashinTokenFlow()
        {
            //Transfer to transition contract
            ICoin colorCoin = await _coinRepository.GetCoinByAddress(_tokenAdapterAddress);

            BigInteger cashinAmount = new BigInteger(100);

            await CashinTokens(_externalTokenAddress, _clientTokenTransferAddress, cashinAmount, _tokenAdapterAddress, _clientA);

            string transferUser = await _transferContractService.GetTransferAddressUser(colorCoin.AdapterAddress, _clientTokenTransferAddress);

            var currentBalance = await _transferContractService.GetBalanceOnAdapter(colorCoin.AdapterAddress, _clientA);

            Assert.AreEqual(_clientA.ToLower(), transferUser);
            Assert.IsTrue(currentBalance >= cashinAmount);
        }
Beispiel #3
0
        public async Task <string> CashIn(Guid id, string coinAddress, string receiver, BigInteger amount)
        {
            var web3 = new Web3(_settings.EthereumUrl);

            await web3.Personal.UnlockAccount.SendRequestAsync(_settings.EthereumMainAccount, _settings.EthereumMainAccountPassword, 120);

            var coinAFromDb = await _coinRepository.GetCoinByAddress(coinAddress);

            if (coinAFromDb == null)
            {
                throw new Exception($"Coin with address {coinAddress} deos not exist");
            }

            Contract contract;

            if (coinAFromDb.ContainsEth)
            {
                contract = web3.Eth.GetContract(_settings.EthAdapterContract.Abi, coinAFromDb.AdapterAddress);
            }
            else
            {
                contract = web3.Eth.GetContract(_settings.TokenAdapterContract.Abi, coinAFromDb.AdapterAddress);
            }

            var convertedAmountA = amount;

            var convertedId = EthUtils.GuidToBigInteger(id);

            var cashin = contract.GetFunction("cashin");
            var res    = await cashin.CallAsync <bool>(_settings.EthereumMainAccount, new HexBigInteger(Constants.GasForCoinTransaction),
                                                       new HexBigInteger(0), receiver, convertedAmountA);

            string tr;

            if (coinAFromDb.ContainsEth)
            {
                tr = await cashin.SendTransactionAsync(_settings.EthereumMainAccount, new HexBigInteger(Constants.GasForCoinTransaction),
                                                       new HexBigInteger(convertedAmountA), receiver, convertedAmountA);
            }
            else
            {
                tr = await cashin.SendTransactionAsync(_settings.EthereumMainAccount, new HexBigInteger(Constants.GasForCoinTransaction),
                                                       new HexBigInteger(0), receiver, convertedAmountA);
            }

            return(tr);
        }
Beispiel #4
0
        public async Task Execute(string coinAdapterAddress)
        {
            ICoin coin = await _coinRepository.GetCoinByAddress(coinAdapterAddress);

            if (coin == null)
            {
                throw new Exception($"Coin with addres {coinAdapterAddress} does not exist");
            }

            await Execute(coin);
        }
        private async Task <ICoin> GetCoinWithCheck(string coinAddress)
        {
            var coin = await _coinRepository.GetCoinByAddress(coinAddress);

            if (coin == null)
            {
                throw new ClientSideException(ExceptionType.WrongParams, $"Coin with address {coinAddress}");
            }

            return(coin);
        }
Beispiel #6
0
        public async Task <string> GetUserAddressForTransferContract(string transferContractAddress)
        {
            ITransferContract transferContract = await _transferContractRepository.GetAsync(transferContractAddress);

            if (transferContract == null)
            {
                throw new ClientSideException(ExceptionType.WrongParams, $"Transfer contract with address {transferContractAddress} does not exist");
            }

            ICoin coin = await _coinRepository.GetCoinByAddress(transferContract.CoinAdapterAddress);

            if (coin == null)
            {
                throw new ClientSideException(ExceptionType.WrongParams, $"Coin with address {transferContract.CoinAdapterAddress} does not exist");
            }

            string   coinAbi     = _settings.CoinAbi;
            Contract contract    = _web3.Eth.GetContract(coinAbi, transferContract.CoinAdapterAddress);
            Function function    = contract.GetFunction("getTransferAddressUser");
            string   userAddress = await function.CallAsync <string>(transferContractAddress);

            return(userAddress);
        }
Beispiel #7
0
        public async Task <ICoin> GetByAddress(string adapterAddress)
        {
            var coin = await _coinRepository.GetCoinByAddress(adapterAddress);

            return(coin);
        }