Beispiel #1
0
        public async Task <string> CreateCoinContract(ICoin coin)
        {
            if (coin == null)
            {
                throw new ClientSideException(ExceptionType.MissingRequiredParams, "Coin should not be null");
            }

            string abi;
            string byteCode;

            string[] constructorParametes;

            if (coin.ContainsEth)
            {
                abi                  = _settings.EthAdapterContract.Abi;
                byteCode             = _settings.EthAdapterContract.ByteCode;
                constructorParametes = new string[] { _settings.MainExchangeContract.Address };
            }
            else
            {
                if (string.IsNullOrEmpty(coin.ExternalTokenAddress))
                {
                    throw new ClientSideException(ExceptionType.MissingRequiredParams, "coin.ExternalTokenAddress should not be empty");
                }

                //TODO: check that external exists
                abi                  = _settings.TokenAdapterContract.Abi;
                byteCode             = _settings.TokenAdapterContract.ByteCode;
                constructorParametes = new string[] { _settings.MainExchangeContract.Address, coin.ExternalTokenAddress };
            }

            var deploymentInfo =
                await _contractService.CreateContractWithDeploymentInfo(abi,
                                                                        byteCode, constructorParametes);

            coin.AdapterAddress          = deploymentInfo.ContractAddress;
            coin.DeployedTransactionHash = deploymentInfo.TransactionHash;
            await _coinRepository.InsertOrReplace(coin);

            return(coin.AdapterAddress);
        }