public async Task <List <TransactionResponse> > GetTransactions(string address, OrderDirection order = OrderDirection.ASC, string cursor = "", int limit = 100) { try { var builder = new TransactionsRequestBuilder(_horizonUrl, _httpClientFactory.CreateClient()); builder.ForAccount(address); builder.Order(order).Cursor(cursor).Limit(limit); var details = await builder.Execute(); var transactions = details?.Embedded?.Records; if (transactions != null) { return(transactions .Where(tx => GetTransactionResult(tx) == TransactionResultCode.TransactionResultCodeEnum.txSUCCESS) .ToList()); } } catch (Exception e) when(IsNotFound(e)) { // address not found } return(new List <TransactionResponse>()); }
public async Task <UserAccountInformation> GetUserAccountInformation(string userAccountId) { Network.UseTestNetwork(); var transactionsRequestBuilder = new TransactionsRequestBuilder(new Uri("https://horizon-testnet.stellar.org"), this.http); var res = await transactionsRequestBuilder.ForAccount(userAccountId).Execute(); var record = res.Records.FirstOrDefault(x => !string.IsNullOrEmpty(x.MemoValue)); if (record != null) { return(new UserAccountInformation(record.Hash, record.MemoValue, userAccountId)); } return(new UserAccountInformation(userAccountId)); }
public async Task <TransactionResponse> GetTransactionDetails(string hash) { try { var builder = new TransactionsRequestBuilder(_horizonUrl, _httpClientFactory.CreateClient()); var tx = await builder.Transaction(hash); return(tx); } catch (Exception e) when(IsNotFound(e)) { // address not found return(null); } }
public async Task <Dictionary <string, int> > GetElectionResults() { Network.UseTestNetwork(); Server server = new Server("https://horizon-testnet.stellar.org"); Dictionary <string, int> candidateVotes = new Dictionary <string, int>(); var transactionsRequestBuilder = new TransactionsRequestBuilder(new Uri("https://horizon-testnet.stellar.org"), this.http); var res = await transactionsRequestBuilder.ForAccount(DistributionAccount.PublicKey).Execute(); var records = res.Records; while (records.Count > 0) { var result = await this.http.GetAsync(res.Links.Next.Uri); var json = await result.Content.ReadAsStringAsync(); res = this.jsonConverter.DeserializeJson <Page <TransactionResponse> >(json); records = res.Records; foreach (var rec in records) { var memo = rec.MemoValue; if (!string.IsNullOrWhiteSpace(memo)) { if (this.CheckStellarVIsValidVote(rec)) { if (!candidateVotes.ContainsKey(memo)) { candidateVotes.Add(memo, 1); } else { candidateVotes[memo]++; } } } } } return(candidateVotes); }