コード例 #1
0
        public ReturnObject UpdateAddress(string id, string networkName, string label)
        {
            try
            {
                switch (networkName)
                {
                case CryptoCurrency.BTC:
                    using (var bitcoinAddressRepository = new BitcoinAddressRepository(_connectionDb))
                    {
                        BitcoinAddress bitcoinAddress = bitcoinAddressRepository.FindById(id);
                        bitcoinAddress.Label = label;
                        return(bitcoinAddressRepository.Update(bitcoinAddress));
                    }


                case CryptoCurrency.ETH:
                    using (var ethereumAddressRepository = new EthereumAddressRepository(_connectionDb))
                    {
                        EthereumAddress ethereumAddress = ethereumAddressRepository.FindById(id);
                        ethereumAddress.Label = label;
                        return(ethereumAddressRepository.Update(ethereumAddress));
                    }

                case CryptoCurrency.VAKA:
                    using (var vakacoinAddressRepository = new VakacoinAccountRepository(_connectionDb))
                    {
                        VakacoinAccount vakacoinAccount = vakacoinAddressRepository.FindById(id);
                        vakacoinAccount.Label = label;
                        return(vakacoinAddressRepository.Update(vakacoinAccount));
                    }

                default:
                    return(new ReturnObject
                    {
                        Status = Status.STATUS_ERROR
                    });
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new ReturnObject
                {
                    Status = Status.STATUS_ERROR
                });
            }
        }
コード例 #2
0
        public ActionResult <string> GetAddressInfoById(string idAddress, string currency)
        {
            try
            {
                var checkIdAddress = CheckIdAddress(idAddress);
                if (!string.IsNullOrEmpty(checkIdAddress))
                {
                    return(CreateDataError(checkIdAddress));
                }

                var apiKey        = (ApiKey)RouteData.Values[Requests.KEY_PASS_DATA_API_KEY_MODEL];
                var checkCurrency = CheckCurrency(currency, apiKey);
                if (!string.IsNullOrEmpty(checkCurrency))
                {
                    return(checkCurrency);
                }

                if (!apiKey.Permissions.Contains(Permissions.READ_ADDRESSES))
                {
                    return(CreateDataError(MessageError.READ_ADDRESS_NOT_PERMISSION));
                }

                BlockchainAddress blockChainAddress;
                switch (currency)
                {
                case CryptoCurrency.BTC:
                    var bitCoinAddressRepository =
                        new BitcoinAddressRepository(VakapayRepositoryFactory.GetOldConnection());
                    blockChainAddress = bitCoinAddressRepository.FindById(idAddress);
                    break;

                case CryptoCurrency.ETH:
                    var ethereumAddressRepository =
                        new EthereumAddressRepository(VakapayRepositoryFactory.GetOldConnection());
                    blockChainAddress = ethereumAddressRepository.FindById(idAddress);
                    break;

                case CryptoCurrency.VAKA:
                    var vaKaCoinAccountRepository =
                        new VakacoinAccountRepository(VakapayRepositoryFactory.GetOldConnection());
                    blockChainAddress = vaKaCoinAccountRepository.FindById(idAddress);
                    break;

                default:
                    return(CreateDataError(MessageError.PARAM_INVALID));
                }

                if (blockChainAddress?.WalletId == null)
                {
                    return(CreateDataError(MessageError.DATA_NOT_FOUND));
                }
                var userModel      = (User)RouteData.Values[Requests.KEY_PASS_DATA_USER_MODEL];
                var walletBusiness = new WalletBusiness.WalletBusiness(VakapayRepositoryFactory);
                var walletModel    = walletBusiness.GetWalletById(blockChainAddress.WalletId);
                if (walletModel != null && string.Equals(walletModel.UserId, userModel.Id))
                {
                    return(CreateDataSuccess(JsonConvert.SerializeObject(blockChainAddress)));
                }

                return(CreateDataError(MessageError.DATA_NOT_FOUND));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(CreateDataError(MessageError.DATA_NOT_FOUND));
            }
        }
コード例 #3
0
        public async Task <ActionResult <string> > CreateAddress(string currency)
        {
            try
            {
                var apiKey        = (ApiKey)RouteData.Values[Requests.KEY_PASS_DATA_API_KEY_MODEL];
                var checkCurrency = CheckCurrency(currency, apiKey);
                if (!string.IsNullOrEmpty(checkCurrency))
                {
                    return(checkCurrency);
                }

                if (!apiKey.Permissions.Contains(Permissions.CREATED_ADDRESSES))
                {
                    return(CreateDataError(MessageError.CREATE_TRANSACION_NOT_PERMISSION));
                }

                var userModel      = (User)RouteData.Values[Requests.KEY_PASS_DATA_USER_MODEL];
                var walletBusiness = new WalletBusiness.WalletBusiness(VakapayRepositoryFactory);
                var wallet         = walletBusiness.FindByUserAndNetwork(userModel.Id, currency);
                if (wallet == null)
                {
                    return(CreateDataError(MessageError.CREATE_ADDRESS_FAIL));
                }
                var result = await walletBusiness.CreateAddressAsync(wallet);

                if (result.Status != Status.STATUS_SUCCESS)
                {
                    return(CreateDataError(MessageError.CREATE_ADDRESS_FAIL));
                }
                BlockchainAddress blockChainAddress;
                switch (currency)
                {
                case CryptoCurrency.BTC:
                    var bitCoinAddressRepository =
                        new BitcoinAddressRepository(VakapayRepositoryFactory.GetOldConnection());
                    blockChainAddress = bitCoinAddressRepository.FindByAddress(result.Data);
                    break;

                case CryptoCurrency.ETH:
                    var ethereumAddressRepository =
                        new EthereumAddressRepository(VakapayRepositoryFactory.GetOldConnection());
                    blockChainAddress = ethereumAddressRepository.FindById(result.Data);
                    break;

                case CryptoCurrency.VAKA:
                    var vaKaCoinAccountRepository =
                        new VakacoinAccountRepository(VakapayRepositoryFactory.GetOldConnection());
                    blockChainAddress = vaKaCoinAccountRepository.FindById(result.Data);
                    break;

                default:
                    return(CreateDataError(MessageError.CREATE_ADDRESS_FAIL));
                }

                return(blockChainAddress != null
                    ? CreateDataSuccess(JsonConvert.SerializeObject(blockChainAddress))
                    : CreateDataError(MessageError.CREATE_ADDRESS_FAIL));
            }
            catch (Exception)
            {
                return(CreateDataError(MessageError.CREATE_ADDRESS_FAIL));
            }
        }