public async Task FetchValues(RequesterPOCO req) { if (await FetchRequesterState(req)) { await FetchBalance(req); await GetAvgMonthlyCost(req); } }
private async Task FetchBalance(RequesterPOCO req) { var jsonString = await Fetch.GetAsync(req.Ip + Resources.RequesterConfig); var json = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonString); var currencyBalance = JsonConvert.DeserializeObject <Dictionary <string, object> >(json["response"].ToString())["currencyBalance"]; var balance = ((currencyBalance as JArray).First as JValue).Value.ToString(); req.Balance = balance; }
private async Task GetAvgMonthlyCost(RequesterPOCO req) { var jsonResp = await Fetch.GetAsync(req.Ip + Resources.SidechainConfiguration + req.Account); var succeded = bool.Parse(JsonStringNavigator.GetDeeper(jsonResp, "succeeded")); if (!succeded) { throw new Exception(JsonStringNavigator.GetDeeper(jsonResp, "exception")); } var response = JsonStringNavigator.GetDeeper(jsonResp, "response"); var rc = JsonConvert.DeserializeObject <NetworkSidechainConfigurations>(response); req.MonthlyCost = averageMonthlyCost(rc); }
private async Task <bool> FetchRequesterState(RequesterPOCO req) { var jsonString = await Fetch.GetAsync(req.Ip + Resources.SidechainState + req.Account); var succeeded = bool.Parse(JsonStringNavigator.GetDeeper(jsonString, "succeeded")); if (!succeeded) { req.State = "No sidechain"; return(false); } var response = JsonStringNavigator.GetDeeper(jsonString, "response"); req.Stake = JsonStringNavigator.GetDeeper(response, "currentRequesterStake"); var inProduction = bool.Parse(JsonStringNavigator.GetDeeper(response, "inProduction")); req.State = inProduction ? "ON" : "OFF"; return(true); }
public async Task FetchDetailedValues(DetailedProducerPOCO res) { var _reqService = new RequesterService(); var producingSidechainNames = await FetchProducingChains(res.IP); var pastSidechainNames = await FetchPastChains(res.IP); foreach (var name in producingSidechainNames) { var working = new RequesterPOCO() { Account = name, Ip = res.IP }; await _reqService.FetchValues(working); res.SideChains.Add(working); if (await CheckCandidate(res.IP, name)) { res.AppliedTo.Add(working); } else { res.WorkingOn.Add(working); } } foreach (var name in pastSidechainNames) { var past = new RequesterPOCO() { Account = name, Ip = res.IP }; await _reqService.FetchValues(past); res.SideChains.Add(past); } }