@@ -58,15 +58,22 @@ private string GenerateJwtToken(string secret, string issuer)
5858 string query ,
5959 object ? variables ,
6060 CancellationToken stoppingToken = default ,
61- ILogger ? contextualLogger = null
61+ ILogger ? contextualLogger = null ,
62+ bool useExplorer = false
6263 )
6364 {
6465 var logger = contextualLogger is null ? _logger : contextualLogger ;
6566
6667 for ( int attempt = 0 ; attempt < RetryAttempts ; attempt ++ )
6768 {
68- foreach ( var url in _urls )
69+ foreach ( var _url in _urls )
6970 {
71+ Uri url = _url ;
72+ if ( useExplorer )
73+ {
74+ url = new Uri ( _url , "graphql/explorer" ) ;
75+ }
76+
7077 try
7178 {
7279 logger . Debug (
@@ -81,7 +88,7 @@ private string GenerateJwtToken(string secret, string issuer)
8188
8289 using var httpRequest = new HttpRequestMessage ( HttpMethod . Post , url )
8390 {
84- Content = content
91+ Content = content ,
8592 } ;
8693
8794 if ( _secret is not null && _issuer is not null )
@@ -101,7 +108,11 @@ private string GenerateJwtToken(string secret, string issuer)
101108 jsonResponse
102109 ) ;
103110
104- if ( graphQLResponse is null || graphQLResponse . Data is null || graphQLResponse . Errors is not null )
111+ if (
112+ graphQLResponse is null
113+ || graphQLResponse . Data is null
114+ || graphQLResponse . Errors is not null
115+ )
105116 {
106117 throw new HttpRequestException ( "Response data is null." ) ;
107118 }
@@ -171,7 +182,7 @@ private string GenerateJwtToken(string secret, string issuer)
171182 {
172183 baseIndex ,
173184 changedIndex ,
174- accountAddress
185+ accountAddress ,
175186 } ,
176187 stoppingToken ,
177188 contextualLogger
@@ -219,22 +230,45 @@ public async Task<GetTransactionsResponse> GetTransactionsAsync(
219230 blockIndex ,
220231 async index =>
221232 {
222- var ( response , jsonResponse ) = await PostGraphQLRequestAsync < GetTransactionsResponse > (
223- GraphQLQueries . GetTransactions ,
224- new { blockIndex = index } ,
225- stoppingToken
226- ) ;
233+ var ( response , jsonResponse ) =
234+ await PostGraphQLRequestAsync < GetTransactionsResponse > (
235+ GraphQLQueries . GetTransactions ,
236+ new { blockIndex = index } ,
237+ stoppingToken
238+ ) ;
227239
228240 // Validate `GetTransactionsResponse` is valid.
229- if ( response . Transaction ? . NCTransactions is null ||
230- response . Transaction . NCTransactions . Any ( t => t is null || t . Actions . Any ( a => a is null ) ) )
241+ if (
242+ response . Transaction ? . NCTransactions is null
243+ || response . Transaction . NCTransactions . Any ( t =>
244+ t is null || t . Actions . Any ( a => a is null )
245+ )
246+ )
231247 {
232- throw new InvalidOperationException ( "Invalid transactions response." +
233- $ " blockIndex: { index } " +
234- $ " response: { jsonResponse } ") ;
248+ throw new InvalidOperationException (
249+ "Invalid transactions response."
250+ + $ " blockIndex: { index } "
251+ + $ " response: { jsonResponse } "
252+ ) ;
235253 }
236254
237255 return response ;
238- } ) ;
256+ }
257+ ) ;
258+ }
259+
260+ public async Task < ( GetBlocksResponse response , string jsonResponse ) > GetBlocksAsync (
261+ int offset ,
262+ int limit ,
263+ CancellationToken stoppingToken
264+ )
265+ {
266+ return await PostGraphQLRequestAsync < GetBlocksResponse > (
267+ GraphQLQueries . GetBlocks ,
268+ new { offset , limit } ,
269+ stoppingToken ,
270+ null ,
271+ true
272+ ) ;
239273 }
240274}
0 commit comments