public LiskDelegates GetDelegates(int offSet) { string jsonResult; LiskDelegates result = new LiskDelegates(); try { HttpWebRequest http = (HttpWebRequest)WebRequest.Create(baseUrl + string.Format("/api/delegates/?offset={0}", offSet)); http.Method = "GET"; WebResponse response = http.GetResponse(); using (Stream stream = response.GetResponseStream()) { StreamReader sr = new StreamReader(stream); jsonResult = sr.ReadToEnd(); } result = JsonConvert.DeserializeObject <LiskDelegates>(jsonResult); } catch (Exception ex) { SendEmail("ERROR LiskApi GetDelegates ", "*****@*****.**", "ERROR LiskApi GetDelegates" + ex.Message); } return(result); }
private Contracts.Contracts GetDelegateByUsername(string username) { //http://164.132.201.52:7000/api/delegates/get?username=NTELO string jsonResult; LiskDelegates result = new LiskDelegates(); try { HttpWebRequest http = (HttpWebRequest)WebRequest.Create(baseUrl + string.Format("/api/delegates/get?username=={0}", username)); http.Method = "GET"; WebResponse response = http.GetResponse(); using (Stream stream = response.GetResponseStream()) { StreamReader sr = new StreamReader(stream); jsonResult = sr.ReadToEnd(); } result = JsonConvert.DeserializeObject <LiskDelegates>(jsonResult); } catch (Exception ex) { SendEmail("ERROR LiskApi GetDelegateByUsername", "*****@*****.**", "ERROR LiskApi GetDelegateByUsername" + ex.Message); } return(result.delegates[0]); }
//used to load sql server public LiskDelegates GetTop200(string address = null) { LiskDelegates result200Delegates = new LiskDelegates(); result200Delegates.success = true; try { #region top 200 deledates result200Delegates.delegates = new List <Contracts.Contracts>(); List <Task <LiskDelegates> > tasksDelegates = new List <Task <LiskDelegates> >(); Task <LiskDelegates> t = Task.Factory.StartNew(() => { return(GetDelegates(0)); }); Task <LiskDelegates> t1 = Task.Factory.StartNew(() => { return(GetDelegates(101)); }); tasksDelegates.Add(t); tasksDelegates.Add(t1); Task.WhenAll(tasksDelegates.ToArray()); if (t.Result != null && t.Result.delegates != null) { result200Delegates.delegates.AddRange(t.Result.delegates); } if (t1.Result != null && t1.Result.delegates != null) { result200Delegates.delegates.AddRange(t1.Result.delegates); } #endregion //get forged #region Forged List <Task <FogedAccount> > tasksForged = new List <Task <FogedAccount> >(); foreach (Contracts.Contracts var in result200Delegates.delegates) { Task <FogedAccount> t3 = Task.Factory.StartNew(() => { return(GetForgedByAccount(var.publicKey)); }); tasksForged.Add(t3); } Task.WhenAll(tasksForged.ToArray()); #endregion //get accounts #region account List <Task <LiskAccount> > tasksAccount = new List <Task <LiskAccount> >(); foreach (Contracts.Contracts var in result200Delegates.delegates) { Task <LiskAccount> t3 = Task.Factory.StartNew(() => { return(GetAccount(var.address)); }); tasksAccount.Add(t3); } Task.WhenAll(tasksAccount.ToArray()); #endregion // NumberVotesMade #region NumberVotesMade List <Task <LiskDelegates> > tasksVotedDelegates = new List <Task <LiskDelegates> >(); foreach (Contracts.Contracts var in result200Delegates.delegates) { Task <LiskDelegates> t4 = Task.Factory.StartNew(() => { return(GetVotedDelegates(var.address)); }); tasksVotedDelegates.Add(t4); } Task.WhenAll(tasksVotedDelegates.ToArray()); for (int i = 0; i < result200Delegates.delegates.Count; i++) { result200Delegates.delegates[i].Forged = tasksForged[i].Result.forged; result200Delegates.delegates[i].NumberVotesMade = tasksVotedDelegates[i].Result.delegates.ToArray().Length; } #endregion // NumberVotesReceived #region NumberVotesReceived List <Task <LiskVoterAccount> > tasksVotedReceivesDelegates = new List <Task <LiskVoterAccount> >(); foreach (Contracts.Contracts var in result200Delegates.delegates) { Task <LiskVoterAccount> t4 = Task.Factory.StartNew(() => { return(GetVotersInAccount(var.address)); }); tasksVotedReceivesDelegates.Add(t4); } Task.WhenAll(tasksVotedReceivesDelegates.ToArray()); #endregion for (int i = 0; i < result200Delegates.delegates.Count; i++) { result200Delegates.delegates[i].Forged = tasksForged[i].Result.forged; result200Delegates.delegates[i].NumberVotesMade = tasksVotedDelegates[i].Result.delegates.ToArray().Length; result200Delegates.delegates[i].NumberVotesReceived = tasksVotedReceivesDelegates[i].Result.accounts.ToArray().Length; result200Delegates.delegates[i].NumberVotesReceivedWithoutTop200 = tasksVotedReceivesDelegates[i].Result.accounts.Select(s => s.address).Where(x => !result200Delegates.delegates.Select(s => s.address).Contains(x)).Count(); result200Delegates.delegates[i].balance = tasksAccount[i].Result.account.balance; if (!string.IsNullOrEmpty(address)) { // List<Contracts.Contracts> temp = tasksVotedDelegates[i].Result.delegates.ToList(); result200Delegates.delegates[i].VotedOnMe = tasksVotedDelegates[i].Result.delegates.Where(a => a.address.Trim() == address.Trim()).Count() > 0 ? true : false; } } } catch (Exception ex) { //SendEmail("ERROR LiskApi GetTop200", "*****@*****.**", "ERROR LiskApi GetTop200" + ex.Message); } return(result200Delegates); }