@fleet-sdk/blockchain-providers 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/index.d.mts +156 -37
- package/dist/index.d.ts +156 -37
- package/dist/index.js +349 -105
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +345 -107
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/ergo-graphql/ergoGraphQLProvider.ts +312 -143
- package/src/ergo-graphql/queries.ts +14 -5
- package/src/index.ts +3 -0
- package/src/types/blockchainProvider.ts +101 -18
- package/src/utils/_tests.ts +6 -10
- package/src/utils/graphql.ts +53 -65
- package/src/utils/networking.ts +83 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
# @fleet-sdk/blockchain-providers
|
2
2
|
|
3
|
+
## 0.6.1
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 208ac8e: Fix `Header#votes` encoding
|
8
|
+
- a3d2a62: Export `BlockChainProviders` types
|
9
|
+
- 506dfc4: [`ErgoGraphQLProvider`] Query Addresses/ErgoTrees by chunks of 20
|
10
|
+
- 6245bc9: Export `request` and `createGqlOperation` utility functions
|
11
|
+
- Updated dependencies [ece573c]
|
12
|
+
- @fleet-sdk/core@0.6.1
|
13
|
+
|
14
|
+
## 0.6.0
|
15
|
+
|
16
|
+
### Minor Changes
|
17
|
+
|
18
|
+
- 6ef2c1b: Add custom `BigInt` mapping support
|
19
|
+
- 9cdf4dd: Add transaction fetching
|
20
|
+
|
21
|
+
### Patch Changes
|
22
|
+
|
23
|
+
- 62b881b: Add exponential delay retrying strategy
|
24
|
+
- 9ed3499: Add GraphQL operation URL override
|
25
|
+
|
3
26
|
## 0.5.0
|
4
27
|
|
5
28
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BoxId, HexString, Base58String, TokenId, Box, BlockHeader, SignedTransaction, UnsignedTransaction,
|
1
|
+
import { BoxId, HexString, Base58String, TokenId, TransactionId, Box, DataInput, BlockHeader, SignedTransaction, UnsignedTransaction, ProverResult } from '@fleet-sdk/common';
|
2
2
|
import { ErgoAddress } from '@fleet-sdk/core';
|
3
3
|
|
4
4
|
declare global {
|
@@ -153,6 +153,18 @@ type RequireAtLeastOne<
|
|
153
153
|
Except<ObjectType, KeysType>;
|
154
154
|
|
155
155
|
type BoxSource = "blockchain" | "mempool" | "blockchain+mempool";
|
156
|
+
type BoxWhere = {
|
157
|
+
/** Base16-encoded BoxId */
|
158
|
+
boxId?: BoxId;
|
159
|
+
/** Base16-encoded ErgoTree */
|
160
|
+
ergoTree?: HexString;
|
161
|
+
/** Base58-encoded address */
|
162
|
+
address?: ErgoAddress | Base58String;
|
163
|
+
/** Base16-encoded contract template hash */
|
164
|
+
templateHash?: HexString;
|
165
|
+
/** Base16-encoded TokenId */
|
166
|
+
tokenId?: TokenId;
|
167
|
+
};
|
156
168
|
type BoxQuery<W extends BoxWhere> = {
|
157
169
|
/** The query to filter boxes. */
|
158
170
|
where: RequireAtLeastOne<W>;
|
@@ -162,24 +174,60 @@ type BoxQuery<W extends BoxWhere> = {
|
|
162
174
|
*/
|
163
175
|
from?: BoxSource;
|
164
176
|
};
|
165
|
-
type
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
boxId?: BoxId;
|
177
|
+
type UnconfirmedTransactionWhere = {
|
178
|
+
/** Base16-encoded TransactionId */
|
179
|
+
transactionId?: TransactionId;
|
180
|
+
/** Base58-encoded address */
|
181
|
+
address?: ErgoAddress | Base58String;
|
171
182
|
/** Base16-encoded ErgoTree */
|
172
183
|
ergoTree?: HexString;
|
184
|
+
};
|
185
|
+
type ConfirmedTransactionWhere = {
|
186
|
+
/** Base16-encoded TransactionId */
|
187
|
+
transactionId?: TransactionId;
|
188
|
+
/** Base16-encoded HeaderID */
|
189
|
+
headerId?: HexString;
|
173
190
|
/** Base58-encoded address */
|
174
191
|
address?: ErgoAddress | Base58String;
|
175
|
-
/** Base16-encoded
|
176
|
-
|
177
|
-
/**
|
178
|
-
|
192
|
+
/** Base16-encoded ErgoTree */
|
193
|
+
ergoTree?: HexString;
|
194
|
+
/** Min blockchain height */
|
195
|
+
minHeight?: number;
|
196
|
+
/** Only returns relevant outputs for the selected filter params */
|
197
|
+
onlyRelevantOutputs?: boolean;
|
198
|
+
};
|
199
|
+
type TransactionQuery<W extends ConfirmedTransactionWhere> = {
|
200
|
+
/** The query to filter boxes. */
|
201
|
+
where: RequireAtLeastOne<W, keyof Omit<W, "minHeight" | "onlyRelevantOutputs">>;
|
202
|
+
};
|
203
|
+
type HeaderQuery = {
|
204
|
+
take: number;
|
179
205
|
};
|
180
|
-
type ChainProviderBox = Box
|
206
|
+
type ChainProviderBox<T> = Omit<Box, "value" | "assets"> & {
|
207
|
+
value: T;
|
208
|
+
assets: {
|
209
|
+
tokenId: TokenId;
|
210
|
+
amount: T;
|
211
|
+
}[];
|
181
212
|
confirmed: boolean;
|
182
213
|
};
|
214
|
+
type TransactionOutput<T> = Omit<ChainProviderBox<T>, "confirmed">;
|
215
|
+
type TransactionInput<T> = TransactionOutput<T> & {
|
216
|
+
spendingProof: ProverResult;
|
217
|
+
};
|
218
|
+
type ChainProviderUnconfirmedTransaction<T> = {
|
219
|
+
transactionId: TransactionId;
|
220
|
+
inputs: TransactionInput<T>[];
|
221
|
+
dataInputs: DataInput[];
|
222
|
+
outputs: TransactionOutput<T>[];
|
223
|
+
confirmed: boolean;
|
224
|
+
timestamp: number;
|
225
|
+
};
|
226
|
+
type ChainProviderConfirmedTransaction<T> = ChainProviderUnconfirmedTransaction<T> & {
|
227
|
+
height: number;
|
228
|
+
index: number;
|
229
|
+
headerId: HexString;
|
230
|
+
};
|
183
231
|
type TransactionEvaluationError = {
|
184
232
|
success: false;
|
185
233
|
message: string;
|
@@ -198,15 +246,31 @@ type TransactionReductionResult = TransactionEvaluationError | TransactionReduct
|
|
198
246
|
* Represents a blockchain provider that can interact with the blockchain.
|
199
247
|
* @template B The type of the box query used by the provider.
|
200
248
|
*/
|
201
|
-
interface IBlockchainProvider<
|
249
|
+
interface IBlockchainProvider<I> {
|
202
250
|
/**
|
203
251
|
* Get boxes.
|
204
252
|
*/
|
205
|
-
getBoxes(query: BoxQuery<
|
253
|
+
getBoxes(query: BoxQuery<BoxWhere>): Promise<ChainProviderBox<I>[]>;
|
206
254
|
/**
|
207
255
|
* Stream boxes.
|
208
256
|
*/
|
209
|
-
streamBoxes(query: BoxQuery<
|
257
|
+
streamBoxes(query: BoxQuery<BoxWhere>): AsyncIterable<ChainProviderBox<I>[]>;
|
258
|
+
/**
|
259
|
+
* Stream unconfirmed transactions
|
260
|
+
*/
|
261
|
+
streamUnconfirmedTransactions(query: TransactionQuery<UnconfirmedTransactionWhere>): AsyncIterable<ChainProviderUnconfirmedTransaction<I>[]>;
|
262
|
+
/**
|
263
|
+
* Get unconfirmed transactions
|
264
|
+
*/
|
265
|
+
getUnconfirmedTransactions(query: TransactionQuery<UnconfirmedTransactionWhere>): Promise<ChainProviderUnconfirmedTransaction<I>[]>;
|
266
|
+
/**
|
267
|
+
* Stream confirmed transactions
|
268
|
+
*/
|
269
|
+
streamConfirmedTransactions(query: TransactionQuery<ConfirmedTransactionWhere>): AsyncIterable<ChainProviderConfirmedTransaction<I>[]>;
|
270
|
+
/**
|
271
|
+
* Get confirmed transactions
|
272
|
+
*/
|
273
|
+
getConfirmedTransactions(query: TransactionQuery<ConfirmedTransactionWhere>): Promise<ChainProviderConfirmedTransaction<I>[]>;
|
210
274
|
/**
|
211
275
|
* Get headers.
|
212
276
|
*/
|
@@ -225,9 +289,41 @@ interface IBlockchainProvider<B extends BoxWhere> {
|
|
225
289
|
reduceTransaction(transaction: UnsignedTransaction): Promise<TransactionReductionResult>;
|
226
290
|
}
|
227
291
|
|
228
|
-
|
229
|
-
|
230
|
-
|
292
|
+
interface ParserLike {
|
293
|
+
parse<T>(text: string): T;
|
294
|
+
stringify<T>(value: T): string;
|
295
|
+
}
|
296
|
+
type Route = {
|
297
|
+
base: string;
|
298
|
+
path: string;
|
299
|
+
query?: Record<string, unknown>;
|
300
|
+
};
|
301
|
+
type URLLike = string | Route;
|
302
|
+
type FallbackRetryOptions = {
|
303
|
+
fallbacks?: URLLike[];
|
304
|
+
} & RetryOptions;
|
305
|
+
type FetchOptions = {
|
306
|
+
parser?: ParserLike;
|
307
|
+
base?: string;
|
308
|
+
query?: Record<string, unknown>;
|
309
|
+
retry?: FallbackRetryOptions;
|
310
|
+
httpOptions?: RequestInit;
|
311
|
+
};
|
312
|
+
declare function request<T>(path: string, opt?: Partial<FetchOptions>): Promise<T>;
|
313
|
+
type RetryOptions = {
|
314
|
+
attempts: number;
|
315
|
+
delay: number;
|
316
|
+
};
|
317
|
+
/**
|
318
|
+
* Retries an asynchronous operation a specified number of times with a delay
|
319
|
+
* growing exponentially between each attempt.
|
320
|
+
* @param operation - The asynchronous operation to retry.
|
321
|
+
* @param options - The retry options.
|
322
|
+
* @returns A promise that resolves to the result of the operation, or undefined
|
323
|
+
* if all attempts fail.
|
324
|
+
*/
|
325
|
+
declare function exponentialRetry<T>(operation: (remainingAttempts: number) => Promise<T>, { attempts, delay }: RetryOptions): Promise<T>;
|
326
|
+
|
231
327
|
type GraphQLVariables = Record<string, unknown> | null;
|
232
328
|
interface GraphQLError {
|
233
329
|
message: string;
|
@@ -241,41 +337,64 @@ interface GraphQLErrorResponse {
|
|
241
337
|
errors: GraphQLError[];
|
242
338
|
}
|
243
339
|
type GraphQLResponse<T = unknown> = GraphQLSuccessResponse<T> | GraphQLErrorResponse;
|
244
|
-
type GraphQLOperation<R extends GraphQLResponse, V extends GraphQLVariables> = (variables?: V) => Promise<R>;
|
245
|
-
|
246
|
-
parse<T>(text: string): T;
|
247
|
-
stringify<T>(value: T): string;
|
248
|
-
}
|
340
|
+
type GraphQLOperation<R extends GraphQLResponse, V extends GraphQLVariables> = (variables?: V, url?: string) => Promise<R>;
|
341
|
+
type GraphQLRequiredUrlOperation<R extends GraphQLResponse, V extends GraphQLVariables> = (variables: V | undefined, url: string) => Promise<R>;
|
249
342
|
interface GraphQLRequestOptions {
|
250
|
-
url
|
251
|
-
|
252
|
-
|
253
|
-
fetcher?: Fetcher;
|
254
|
-
credentials?: Credentials;
|
343
|
+
url?: string;
|
344
|
+
parser?: ParserLike;
|
345
|
+
retry?: FallbackRetryOptions;
|
255
346
|
throwOnNonNetworkErrors?: boolean;
|
347
|
+
httpOptions?: Omit<RequestInit, "body" | "method">;
|
256
348
|
}
|
349
|
+
declare function createGqlOperation<R, V extends GraphQLVariables = GraphQLVariables>(query: string, options: GraphQLRequestOptions & {
|
350
|
+
throwOnNonNetworkErrors: true;
|
351
|
+
}): GraphQLOperation<GraphQLSuccessResponse<R>, V>;
|
352
|
+
declare function createGqlOperation<R, V extends GraphQLVariables = GraphQLVariables>(query: string, options?: GraphQLRequestOptions & {
|
353
|
+
url: undefined;
|
354
|
+
}): GraphQLRequiredUrlOperation<GraphQLResponse<R>, V>;
|
355
|
+
declare function createGqlOperation<R, V extends GraphQLVariables = GraphQLVariables>(query: string, options: GraphQLRequestOptions & {
|
356
|
+
url: undefined;
|
357
|
+
throwOnNonNetworkErrors: true;
|
358
|
+
}): GraphQLRequiredUrlOperation<GraphQLSuccessResponse<R>, V>;
|
359
|
+
declare function createGqlOperation<R, V extends GraphQLVariables = GraphQLVariables>(query: string, options: GraphQLRequestOptions): GraphQLOperation<GraphQLResponse<R>, V>;
|
360
|
+
declare function gql(query: TemplateStringsArray): string;
|
361
|
+
declare function getOpName(query: string): string | undefined;
|
257
362
|
|
258
363
|
type GraphQLBoxWhere = BoxWhere & {
|
259
|
-
/** Base16-encoded BoxIds */
|
260
|
-
boxIds?: HexString[];
|
261
364
|
/** Base16-encoded ErgoTrees */
|
262
365
|
ergoTrees?: HexString[];
|
263
366
|
/** Base58-encoded addresses or `ErgoAddress` objects */
|
264
367
|
addresses?: (Base58String | ErgoAddress)[];
|
265
368
|
};
|
369
|
+
type GraphQLConfirmedTransactionWhere = ConfirmedTransactionWhere & {
|
370
|
+
addresses?: (Base58String | ErgoAddress)[];
|
371
|
+
ergoTrees?: HexString[];
|
372
|
+
};
|
373
|
+
type GraphQLUnconfirmedTransactionWhere = UnconfirmedTransactionWhere & {
|
374
|
+
addresses?: (Base58String | ErgoAddress)[];
|
375
|
+
ergoTrees?: HexString[];
|
376
|
+
};
|
266
377
|
type GraphQLBoxQuery = BoxQuery<GraphQLBoxWhere>;
|
267
|
-
type ErgoGraphQLRequestOptions = Omit<GraphQLRequestOptions, "
|
268
|
-
|
378
|
+
type ErgoGraphQLRequestOptions = Omit<GraphQLRequestOptions, "throwOnNonNetworkErrors">;
|
379
|
+
type BiMapper<T> = (value: string) => T;
|
380
|
+
declare class ErgoGraphQLProvider<I = bigint> implements IBlockchainProvider<I> {
|
269
381
|
#private;
|
270
|
-
constructor(url: string
|
271
|
-
constructor(
|
272
|
-
|
273
|
-
|
382
|
+
constructor(url: string);
|
383
|
+
constructor(options: ErgoGraphQLRequestOptions);
|
384
|
+
setUrl(url: string): ErgoGraphQLProvider<I>;
|
385
|
+
setBigIntMapper<M>(mapper: BiMapper<M>): ErgoGraphQLProvider<M>;
|
386
|
+
streamBoxes(query: GraphQLBoxQuery): AsyncGenerator<ChainProviderBox<I>[]>;
|
387
|
+
getBoxes(query: GraphQLBoxQuery): Promise<ChainProviderBox<I>[]>;
|
388
|
+
streamUnconfirmedTransactions(query: TransactionQuery<GraphQLUnconfirmedTransactionWhere>): AsyncIterable<ChainProviderUnconfirmedTransaction<I>[]>;
|
389
|
+
getUnconfirmedTransactions(query: TransactionQuery<GraphQLUnconfirmedTransactionWhere>): Promise<ChainProviderUnconfirmedTransaction<I>[]>;
|
390
|
+
streamConfirmedTransactions(query: TransactionQuery<GraphQLConfirmedTransactionWhere>): AsyncIterable<ChainProviderConfirmedTransaction<I>[]>;
|
391
|
+
getConfirmedTransactions(query: TransactionQuery<GraphQLConfirmedTransactionWhere>): Promise<ChainProviderConfirmedTransaction<I>[]>;
|
274
392
|
getHeaders(query: HeaderQuery): Promise<BlockHeader[]>;
|
275
393
|
createOperation<R, V extends GraphQLVariables = GraphQLVariables>(query: string, options?: Partial<ErgoGraphQLRequestOptions>): GraphQLOperation<GraphQLSuccessResponse<R>, V>;
|
276
394
|
checkTransaction(signedTransaction: SignedTransaction): Promise<TransactionEvaluationResult>;
|
277
395
|
submitTransaction(signedTransaction: SignedTransaction): Promise<TransactionEvaluationResult>;
|
278
396
|
reduceTransaction(): Promise<TransactionReductionResult>;
|
279
397
|
}
|
398
|
+
declare function isRequestParam(obj: unknown): obj is ErgoGraphQLRequestOptions;
|
280
399
|
|
281
|
-
export { ErgoGraphQLProvider, type ErgoGraphQLRequestOptions, type GraphQLBoxQuery, type GraphQLBoxWhere };
|
400
|
+
export { type BoxQuery, type BoxSource, type BoxWhere, type ChainProviderBox, type ChainProviderConfirmedTransaction, type ChainProviderUnconfirmedTransaction, type ConfirmedTransactionWhere, ErgoGraphQLProvider, type ErgoGraphQLRequestOptions, type FallbackRetryOptions, type FetchOptions, type GraphQLBoxQuery, type GraphQLBoxWhere, type GraphQLConfirmedTransactionWhere, type GraphQLError, type GraphQLErrorResponse, type GraphQLOperation, type GraphQLRequestOptions, type GraphQLRequiredUrlOperation, type GraphQLResponse, type GraphQLSuccessResponse, type GraphQLUnconfirmedTransactionWhere, type GraphQLVariables, type HeaderQuery, type IBlockchainProvider, type ParserLike, type RetryOptions, type Route, type TransactionEvaluationError, type TransactionEvaluationResult, type TransactionEvaluationSuccess, type TransactionQuery, type TransactionReductionResult, type TransactionReductionSuccess, type URLLike, type UnconfirmedTransactionWhere, createGqlOperation, exponentialRetry, getOpName, gql, isRequestParam, request };
|
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BoxId, HexString, Base58String, TokenId, Box, BlockHeader, SignedTransaction, UnsignedTransaction,
|
1
|
+
import { BoxId, HexString, Base58String, TokenId, TransactionId, Box, DataInput, BlockHeader, SignedTransaction, UnsignedTransaction, ProverResult } from '@fleet-sdk/common';
|
2
2
|
import { ErgoAddress } from '@fleet-sdk/core';
|
3
3
|
|
4
4
|
declare global {
|
@@ -153,6 +153,18 @@ type RequireAtLeastOne<
|
|
153
153
|
Except<ObjectType, KeysType>;
|
154
154
|
|
155
155
|
type BoxSource = "blockchain" | "mempool" | "blockchain+mempool";
|
156
|
+
type BoxWhere = {
|
157
|
+
/** Base16-encoded BoxId */
|
158
|
+
boxId?: BoxId;
|
159
|
+
/** Base16-encoded ErgoTree */
|
160
|
+
ergoTree?: HexString;
|
161
|
+
/** Base58-encoded address */
|
162
|
+
address?: ErgoAddress | Base58String;
|
163
|
+
/** Base16-encoded contract template hash */
|
164
|
+
templateHash?: HexString;
|
165
|
+
/** Base16-encoded TokenId */
|
166
|
+
tokenId?: TokenId;
|
167
|
+
};
|
156
168
|
type BoxQuery<W extends BoxWhere> = {
|
157
169
|
/** The query to filter boxes. */
|
158
170
|
where: RequireAtLeastOne<W>;
|
@@ -162,24 +174,60 @@ type BoxQuery<W extends BoxWhere> = {
|
|
162
174
|
*/
|
163
175
|
from?: BoxSource;
|
164
176
|
};
|
165
|
-
type
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
boxId?: BoxId;
|
177
|
+
type UnconfirmedTransactionWhere = {
|
178
|
+
/** Base16-encoded TransactionId */
|
179
|
+
transactionId?: TransactionId;
|
180
|
+
/** Base58-encoded address */
|
181
|
+
address?: ErgoAddress | Base58String;
|
171
182
|
/** Base16-encoded ErgoTree */
|
172
183
|
ergoTree?: HexString;
|
184
|
+
};
|
185
|
+
type ConfirmedTransactionWhere = {
|
186
|
+
/** Base16-encoded TransactionId */
|
187
|
+
transactionId?: TransactionId;
|
188
|
+
/** Base16-encoded HeaderID */
|
189
|
+
headerId?: HexString;
|
173
190
|
/** Base58-encoded address */
|
174
191
|
address?: ErgoAddress | Base58String;
|
175
|
-
/** Base16-encoded
|
176
|
-
|
177
|
-
/**
|
178
|
-
|
192
|
+
/** Base16-encoded ErgoTree */
|
193
|
+
ergoTree?: HexString;
|
194
|
+
/** Min blockchain height */
|
195
|
+
minHeight?: number;
|
196
|
+
/** Only returns relevant outputs for the selected filter params */
|
197
|
+
onlyRelevantOutputs?: boolean;
|
198
|
+
};
|
199
|
+
type TransactionQuery<W extends ConfirmedTransactionWhere> = {
|
200
|
+
/** The query to filter boxes. */
|
201
|
+
where: RequireAtLeastOne<W, keyof Omit<W, "minHeight" | "onlyRelevantOutputs">>;
|
202
|
+
};
|
203
|
+
type HeaderQuery = {
|
204
|
+
take: number;
|
179
205
|
};
|
180
|
-
type ChainProviderBox = Box
|
206
|
+
type ChainProviderBox<T> = Omit<Box, "value" | "assets"> & {
|
207
|
+
value: T;
|
208
|
+
assets: {
|
209
|
+
tokenId: TokenId;
|
210
|
+
amount: T;
|
211
|
+
}[];
|
181
212
|
confirmed: boolean;
|
182
213
|
};
|
214
|
+
type TransactionOutput<T> = Omit<ChainProviderBox<T>, "confirmed">;
|
215
|
+
type TransactionInput<T> = TransactionOutput<T> & {
|
216
|
+
spendingProof: ProverResult;
|
217
|
+
};
|
218
|
+
type ChainProviderUnconfirmedTransaction<T> = {
|
219
|
+
transactionId: TransactionId;
|
220
|
+
inputs: TransactionInput<T>[];
|
221
|
+
dataInputs: DataInput[];
|
222
|
+
outputs: TransactionOutput<T>[];
|
223
|
+
confirmed: boolean;
|
224
|
+
timestamp: number;
|
225
|
+
};
|
226
|
+
type ChainProviderConfirmedTransaction<T> = ChainProviderUnconfirmedTransaction<T> & {
|
227
|
+
height: number;
|
228
|
+
index: number;
|
229
|
+
headerId: HexString;
|
230
|
+
};
|
183
231
|
type TransactionEvaluationError = {
|
184
232
|
success: false;
|
185
233
|
message: string;
|
@@ -198,15 +246,31 @@ type TransactionReductionResult = TransactionEvaluationError | TransactionReduct
|
|
198
246
|
* Represents a blockchain provider that can interact with the blockchain.
|
199
247
|
* @template B The type of the box query used by the provider.
|
200
248
|
*/
|
201
|
-
interface IBlockchainProvider<
|
249
|
+
interface IBlockchainProvider<I> {
|
202
250
|
/**
|
203
251
|
* Get boxes.
|
204
252
|
*/
|
205
|
-
getBoxes(query: BoxQuery<
|
253
|
+
getBoxes(query: BoxQuery<BoxWhere>): Promise<ChainProviderBox<I>[]>;
|
206
254
|
/**
|
207
255
|
* Stream boxes.
|
208
256
|
*/
|
209
|
-
streamBoxes(query: BoxQuery<
|
257
|
+
streamBoxes(query: BoxQuery<BoxWhere>): AsyncIterable<ChainProviderBox<I>[]>;
|
258
|
+
/**
|
259
|
+
* Stream unconfirmed transactions
|
260
|
+
*/
|
261
|
+
streamUnconfirmedTransactions(query: TransactionQuery<UnconfirmedTransactionWhere>): AsyncIterable<ChainProviderUnconfirmedTransaction<I>[]>;
|
262
|
+
/**
|
263
|
+
* Get unconfirmed transactions
|
264
|
+
*/
|
265
|
+
getUnconfirmedTransactions(query: TransactionQuery<UnconfirmedTransactionWhere>): Promise<ChainProviderUnconfirmedTransaction<I>[]>;
|
266
|
+
/**
|
267
|
+
* Stream confirmed transactions
|
268
|
+
*/
|
269
|
+
streamConfirmedTransactions(query: TransactionQuery<ConfirmedTransactionWhere>): AsyncIterable<ChainProviderConfirmedTransaction<I>[]>;
|
270
|
+
/**
|
271
|
+
* Get confirmed transactions
|
272
|
+
*/
|
273
|
+
getConfirmedTransactions(query: TransactionQuery<ConfirmedTransactionWhere>): Promise<ChainProviderConfirmedTransaction<I>[]>;
|
210
274
|
/**
|
211
275
|
* Get headers.
|
212
276
|
*/
|
@@ -225,9 +289,41 @@ interface IBlockchainProvider<B extends BoxWhere> {
|
|
225
289
|
reduceTransaction(transaction: UnsignedTransaction): Promise<TransactionReductionResult>;
|
226
290
|
}
|
227
291
|
|
228
|
-
|
229
|
-
|
230
|
-
|
292
|
+
interface ParserLike {
|
293
|
+
parse<T>(text: string): T;
|
294
|
+
stringify<T>(value: T): string;
|
295
|
+
}
|
296
|
+
type Route = {
|
297
|
+
base: string;
|
298
|
+
path: string;
|
299
|
+
query?: Record<string, unknown>;
|
300
|
+
};
|
301
|
+
type URLLike = string | Route;
|
302
|
+
type FallbackRetryOptions = {
|
303
|
+
fallbacks?: URLLike[];
|
304
|
+
} & RetryOptions;
|
305
|
+
type FetchOptions = {
|
306
|
+
parser?: ParserLike;
|
307
|
+
base?: string;
|
308
|
+
query?: Record<string, unknown>;
|
309
|
+
retry?: FallbackRetryOptions;
|
310
|
+
httpOptions?: RequestInit;
|
311
|
+
};
|
312
|
+
declare function request<T>(path: string, opt?: Partial<FetchOptions>): Promise<T>;
|
313
|
+
type RetryOptions = {
|
314
|
+
attempts: number;
|
315
|
+
delay: number;
|
316
|
+
};
|
317
|
+
/**
|
318
|
+
* Retries an asynchronous operation a specified number of times with a delay
|
319
|
+
* growing exponentially between each attempt.
|
320
|
+
* @param operation - The asynchronous operation to retry.
|
321
|
+
* @param options - The retry options.
|
322
|
+
* @returns A promise that resolves to the result of the operation, or undefined
|
323
|
+
* if all attempts fail.
|
324
|
+
*/
|
325
|
+
declare function exponentialRetry<T>(operation: (remainingAttempts: number) => Promise<T>, { attempts, delay }: RetryOptions): Promise<T>;
|
326
|
+
|
231
327
|
type GraphQLVariables = Record<string, unknown> | null;
|
232
328
|
interface GraphQLError {
|
233
329
|
message: string;
|
@@ -241,41 +337,64 @@ interface GraphQLErrorResponse {
|
|
241
337
|
errors: GraphQLError[];
|
242
338
|
}
|
243
339
|
type GraphQLResponse<T = unknown> = GraphQLSuccessResponse<T> | GraphQLErrorResponse;
|
244
|
-
type GraphQLOperation<R extends GraphQLResponse, V extends GraphQLVariables> = (variables?: V) => Promise<R>;
|
245
|
-
|
246
|
-
parse<T>(text: string): T;
|
247
|
-
stringify<T>(value: T): string;
|
248
|
-
}
|
340
|
+
type GraphQLOperation<R extends GraphQLResponse, V extends GraphQLVariables> = (variables?: V, url?: string) => Promise<R>;
|
341
|
+
type GraphQLRequiredUrlOperation<R extends GraphQLResponse, V extends GraphQLVariables> = (variables: V | undefined, url: string) => Promise<R>;
|
249
342
|
interface GraphQLRequestOptions {
|
250
|
-
url
|
251
|
-
|
252
|
-
|
253
|
-
fetcher?: Fetcher;
|
254
|
-
credentials?: Credentials;
|
343
|
+
url?: string;
|
344
|
+
parser?: ParserLike;
|
345
|
+
retry?: FallbackRetryOptions;
|
255
346
|
throwOnNonNetworkErrors?: boolean;
|
347
|
+
httpOptions?: Omit<RequestInit, "body" | "method">;
|
256
348
|
}
|
349
|
+
declare function createGqlOperation<R, V extends GraphQLVariables = GraphQLVariables>(query: string, options: GraphQLRequestOptions & {
|
350
|
+
throwOnNonNetworkErrors: true;
|
351
|
+
}): GraphQLOperation<GraphQLSuccessResponse<R>, V>;
|
352
|
+
declare function createGqlOperation<R, V extends GraphQLVariables = GraphQLVariables>(query: string, options?: GraphQLRequestOptions & {
|
353
|
+
url: undefined;
|
354
|
+
}): GraphQLRequiredUrlOperation<GraphQLResponse<R>, V>;
|
355
|
+
declare function createGqlOperation<R, V extends GraphQLVariables = GraphQLVariables>(query: string, options: GraphQLRequestOptions & {
|
356
|
+
url: undefined;
|
357
|
+
throwOnNonNetworkErrors: true;
|
358
|
+
}): GraphQLRequiredUrlOperation<GraphQLSuccessResponse<R>, V>;
|
359
|
+
declare function createGqlOperation<R, V extends GraphQLVariables = GraphQLVariables>(query: string, options: GraphQLRequestOptions): GraphQLOperation<GraphQLResponse<R>, V>;
|
360
|
+
declare function gql(query: TemplateStringsArray): string;
|
361
|
+
declare function getOpName(query: string): string | undefined;
|
257
362
|
|
258
363
|
type GraphQLBoxWhere = BoxWhere & {
|
259
|
-
/** Base16-encoded BoxIds */
|
260
|
-
boxIds?: HexString[];
|
261
364
|
/** Base16-encoded ErgoTrees */
|
262
365
|
ergoTrees?: HexString[];
|
263
366
|
/** Base58-encoded addresses or `ErgoAddress` objects */
|
264
367
|
addresses?: (Base58String | ErgoAddress)[];
|
265
368
|
};
|
369
|
+
type GraphQLConfirmedTransactionWhere = ConfirmedTransactionWhere & {
|
370
|
+
addresses?: (Base58String | ErgoAddress)[];
|
371
|
+
ergoTrees?: HexString[];
|
372
|
+
};
|
373
|
+
type GraphQLUnconfirmedTransactionWhere = UnconfirmedTransactionWhere & {
|
374
|
+
addresses?: (Base58String | ErgoAddress)[];
|
375
|
+
ergoTrees?: HexString[];
|
376
|
+
};
|
266
377
|
type GraphQLBoxQuery = BoxQuery<GraphQLBoxWhere>;
|
267
|
-
type ErgoGraphQLRequestOptions = Omit<GraphQLRequestOptions, "
|
268
|
-
|
378
|
+
type ErgoGraphQLRequestOptions = Omit<GraphQLRequestOptions, "throwOnNonNetworkErrors">;
|
379
|
+
type BiMapper<T> = (value: string) => T;
|
380
|
+
declare class ErgoGraphQLProvider<I = bigint> implements IBlockchainProvider<I> {
|
269
381
|
#private;
|
270
|
-
constructor(url: string
|
271
|
-
constructor(
|
272
|
-
|
273
|
-
|
382
|
+
constructor(url: string);
|
383
|
+
constructor(options: ErgoGraphQLRequestOptions);
|
384
|
+
setUrl(url: string): ErgoGraphQLProvider<I>;
|
385
|
+
setBigIntMapper<M>(mapper: BiMapper<M>): ErgoGraphQLProvider<M>;
|
386
|
+
streamBoxes(query: GraphQLBoxQuery): AsyncGenerator<ChainProviderBox<I>[]>;
|
387
|
+
getBoxes(query: GraphQLBoxQuery): Promise<ChainProviderBox<I>[]>;
|
388
|
+
streamUnconfirmedTransactions(query: TransactionQuery<GraphQLUnconfirmedTransactionWhere>): AsyncIterable<ChainProviderUnconfirmedTransaction<I>[]>;
|
389
|
+
getUnconfirmedTransactions(query: TransactionQuery<GraphQLUnconfirmedTransactionWhere>): Promise<ChainProviderUnconfirmedTransaction<I>[]>;
|
390
|
+
streamConfirmedTransactions(query: TransactionQuery<GraphQLConfirmedTransactionWhere>): AsyncIterable<ChainProviderConfirmedTransaction<I>[]>;
|
391
|
+
getConfirmedTransactions(query: TransactionQuery<GraphQLConfirmedTransactionWhere>): Promise<ChainProviderConfirmedTransaction<I>[]>;
|
274
392
|
getHeaders(query: HeaderQuery): Promise<BlockHeader[]>;
|
275
393
|
createOperation<R, V extends GraphQLVariables = GraphQLVariables>(query: string, options?: Partial<ErgoGraphQLRequestOptions>): GraphQLOperation<GraphQLSuccessResponse<R>, V>;
|
276
394
|
checkTransaction(signedTransaction: SignedTransaction): Promise<TransactionEvaluationResult>;
|
277
395
|
submitTransaction(signedTransaction: SignedTransaction): Promise<TransactionEvaluationResult>;
|
278
396
|
reduceTransaction(): Promise<TransactionReductionResult>;
|
279
397
|
}
|
398
|
+
declare function isRequestParam(obj: unknown): obj is ErgoGraphQLRequestOptions;
|
280
399
|
|
281
|
-
export { ErgoGraphQLProvider, type ErgoGraphQLRequestOptions, type GraphQLBoxQuery, type GraphQLBoxWhere };
|
400
|
+
export { type BoxQuery, type BoxSource, type BoxWhere, type ChainProviderBox, type ChainProviderConfirmedTransaction, type ChainProviderUnconfirmedTransaction, type ConfirmedTransactionWhere, ErgoGraphQLProvider, type ErgoGraphQLRequestOptions, type FallbackRetryOptions, type FetchOptions, type GraphQLBoxQuery, type GraphQLBoxWhere, type GraphQLConfirmedTransactionWhere, type GraphQLError, type GraphQLErrorResponse, type GraphQLOperation, type GraphQLRequestOptions, type GraphQLRequiredUrlOperation, type GraphQLResponse, type GraphQLSuccessResponse, type GraphQLUnconfirmedTransactionWhere, type GraphQLVariables, type HeaderQuery, type IBlockchainProvider, type ParserLike, type RetryOptions, type Route, type TransactionEvaluationError, type TransactionEvaluationResult, type TransactionEvaluationSuccess, type TransactionQuery, type TransactionReductionResult, type TransactionReductionSuccess, type URLLike, type UnconfirmedTransactionWhere, createGqlOperation, exponentialRetry, getOpName, gql, isRequestParam, request };
|