示例#1
0
        public CoinProperty GetCoinProperty(string coinName)
        {
            HttpUtilities      httpUtilities      = new HttpUtilities();
            CoinCapApiSettings coinCapApiSettings = GetSettings();
            HttpResponseBO     _res         = httpUtilities.GetAsync(coinCapApiSettings.ApiUri, "v2/assets/" + coinName).Result;
            CoinProperty       coinProperty = JsonConvert.DeserializeObject <CoinProperty>(_res.ResponseResult);

            return(coinProperty);
        }
示例#2
0
        public async Task <BlockchainTx> GetAddressTransactions(string walletAddress)
        {
            HttpUtilities         httpUtilities         = new HttpUtilities();
            BlockchainApiSettings blockchainApiSettings = GetSettings();
            HttpResponseBO        _res = await httpUtilities.GetAsync(blockchainApiSettings.BlockCypherApiUri,
                                                                      "v1/btc/main/addrs/" + walletAddress, new object { });

            BlockchainTx blockchainTx = JsonConvert.DeserializeObject <BlockchainTx>(_res.ResponseResult);

            CoinCap      coinCap      = new CoinCap();
            CoinProperty coinProperty = coinCap.GetCoinProperty("bitcoin");

            foreach (var item in blockchainTx.Txrefs)
            {
                item.ValueFiat = (long)decimal.Parse(coinProperty.Data.PriceUsd) * item.Value;
            }

            return(blockchainTx);
        }
示例#3
0
        public int CoinHandler(string user, CoinProperty property, int coinValue = 0)
        {
            try
            {
                string sql;
                string sqls = "";
                if (property == CoinProperty.Load)
                {
                    sql = "SELECT coins FROM \"user\" WHERE username=@u LIMIT 1";
                }
                else if (property == CoinProperty.Increase)
                {
                    sql  = "UPDATE \"user\" SET coins=coins+@c WHERE username=@u";
                    sqls = "UPDATE \"user\" SET gainedcoins=gainedcoins+@c WHERE username=@u";
                }
                else if (property == CoinProperty.Decrease)
                {
                    sql  = "UPDATE \"user\" SET coins=coins-@c WHERE username=@u";
                    sqls = "UPDATE \"user\" SET spendcoins=spendcoins+@c WHERE username=@u";
                }
                else
                {
                    return(coinValue);
                }

                _conn.Open();
                NpgsqlCommand cmd = new NpgsqlCommand(sql, _conn);
                cmd.Parameters.AddWithValue("u", user);

                if (property != CoinProperty.Load)
                {
                    cmd.Parameters.AddWithValue("c", coinValue);
                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                    _conn.Close();

                    _conn.Open();
                    cmd = new NpgsqlCommand(sqls, _conn);
                    cmd.Parameters.AddWithValue("u", user);
                    cmd.Parameters.AddWithValue("c", coinValue);
                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                    _conn.Close();
                    return(0);
                }

                cmd.Prepare();
                NpgsqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    coinValue = Int32.Parse(reader[0].ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            _conn.Close();
            return(coinValue);
        }
示例#4
0
 SetValue(CoinProperty, value);