예제 #1
0
    public override string CreateNewAddress(int userId)
    {
        BlocktrailAPI api = new BlocktrailAPI(AppSettings.Cryptocurrencies.BlocktrailAPIKey, AppSettings.Cryptocurrencies.BlocktrailAPIKeySecret);

        string adminAddress = string.Empty;

        try
        {
            adminAddress = api.GenerateBTCAddress();

            if (!string.IsNullOrWhiteSpace(adminAddress))
            {
                string         query   = string.Format("SELECT * FROM BitcoinAddresses WHERE UserId = {0}", userId);
                BitcoinAddress address = TableHelper.GetListFromRawQuery <BitcoinAddress>(query).FirstOrDefault();
                if (address == null)
                {
                    address        = new BitcoinAddress();
                    address.UserId = userId;
                }
                address.BlocktrailAddress = adminAddress;
                address.Save();
            }
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
        }

        return(adminAddress);
    }
예제 #2
0
 public void TryWithDrawBitcoinsFromWalletInBatchTransaction(List <KeyValuePair <string, decimal> > addressesWithAmounts)
 {
     try
     {
         BlocktrailAPI api = new BlocktrailAPI(AppSettings.Cryptocurrencies.BlocktrailAPIKey, AppSettings.Cryptocurrencies.BlocktrailAPIKeySecret);
         api.SendTransactions(addressesWithAmounts);
     }
     catch (Exception ex)
     {
         throw new MsgException(ex.Message);
     }
 }
예제 #3
0
 public override Money GetAccountBalance()
 {
     try
     {
         BlocktrailAPI api = new BlocktrailAPI(AppSettings.Cryptocurrencies.BlocktrailAPIKey, AppSettings.Cryptocurrencies.BlocktrailAPIKeySecret);
         return(api.GetBalance());
     }
     catch (Exception)
     {
         return(Money.Zero);
     }
 }
예제 #4
0
 public override void TryWithDrawCryptocurrencyFromWallet(decimal amountInCryptocurrency, string userAddress, CryptocurrencyType cryptocurrencyType)
 {
     try
     {
         BlocktrailAPI api = new BlocktrailAPI(AppSettings.Cryptocurrencies.BlocktrailAPIKey, AppSettings.Cryptocurrencies.BlocktrailAPIKeySecret);
         api.SendTransaction(userAddress, amountInCryptocurrency);
     }
     catch (Exception ex)
     {
         throw new MsgException(ex.Message);
     }
 }
예제 #5
0
    public override decimal GetEstimatedWithdrawalFee(decimal amount, string userAddress)
    {
        try
        {
            if (TitanFeatures.IsAhmed) //He only wants to use his own fee
            {
                return(new decimal(0));
            }

            BlocktrailAPI api = new BlocktrailAPI(AppSettings.Cryptocurrencies.BlocktrailAPIKey, AppSettings.Cryptocurrencies.BlocktrailAPIKeySecret);
            return(api.GetFees(userAddress, amount));
        }
        catch (Exception ex)
        {
            throw new MsgException(ex.Message);
        }
    }
예제 #6
0
        public override void ProcessRequest()
        {
            try
            {
                var originalJson = JObject.Parse(context.Request.GetFromBodyString());

                string transactionHash = originalJson["data"]["hash"].ToString();
                string operationType   = originalJson["event_type"].ToString();
                string address         = ((JProperty)originalJson["addresses"].First).Name.ToString();
                string currency        = originalJson["network"].ToString();
                int    retryCount      = Int32.Parse(originalJson["retry_count"].ToString());

                //Get the info about TX from Blocktrail anyway
                BlocktrailAPI api  = new BlocktrailAPI(AppSettings.Cryptocurrencies.BlocktrailAPIKey, AppSettings.Cryptocurrencies.BlocktrailAPIKeySecret);
                var           json = api.GetTransactionInformation(transactionHash);

                //Get the value
                var transactionFound = false;
                var amountInSatoshis = "0";
                var outputs          = (JArray)json["outputs"];

                foreach (var output in outputs)
                {
                    if (output["address"].ToString() == address)
                    {
                        amountInSatoshis = output["value"].ToString();
                        transactionFound = true;
                    }
                }

                if (!transactionFound)
                {
                    throw new MsgException("We can't find such transaction.");
                }

                if (currency != "BTC")
                {
                    throw new MsgException("This is not BTC.");
                }

                if (retryCount > 0)
                {
                    throw new MsgException("Retry count = " + retryCount);
                }

                var confirmations           = Convert.ToInt32(json["confirmations"].ToString());
                var IsDepositOperation      = (operationType == "address-transactions");
                var bitcoinAmountInSatoshis = Convert.ToInt64(amountInSatoshis);
                var amountInCryptocurrency  = bitcoinAmountInSatoshis / 100000000;
                var currencyInfo            = string.Format("{0}{1}", amountInCryptocurrency, currency);

                var Cryptocurrency = CryptocurrencyFactory.Get(currency);

                //End of API fetch data operations, now proceeding with our methods
                if (IsDepositOperation)
                {
                    Cryptocurrency.TryDepositCryptocurrency(CryptocurrencyAPIProvider.Blocktrail, address, amountInCryptocurrency, transactionHash, currencyInfo, confirmations);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
            }
        }