@fleet-sdk/blockchain-providers 0.6.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 +11 -0
- package/dist/index.d.mts +36 -8
- package/dist/index.d.ts +36 -8
- package/dist/index.js +159 -95
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +155 -97
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/ergo-graphql/ergoGraphQLProvider.ts +122 -123
- package/src/index.ts +3 -0
- package/src/utils/graphql.ts +1 -5
- package/src/utils/networking.ts +0 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
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
|
+
|
3
14
|
## 0.6.0
|
4
15
|
|
5
16
|
### Minor Changes
|
package/dist/index.d.mts
CHANGED
@@ -302,10 +302,27 @@ type URLLike = string | Route;
|
|
302
302
|
type FallbackRetryOptions = {
|
303
303
|
fallbacks?: URLLike[];
|
304
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>;
|
305
313
|
type RetryOptions = {
|
306
314
|
attempts: number;
|
307
315
|
delay: number;
|
308
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>;
|
309
326
|
|
310
327
|
type GraphQLVariables = Record<string, unknown> | null;
|
311
328
|
interface GraphQLError {
|
@@ -321,6 +338,7 @@ interface GraphQLErrorResponse {
|
|
321
338
|
}
|
322
339
|
type GraphQLResponse<T = unknown> = GraphQLSuccessResponse<T> | GraphQLErrorResponse;
|
323
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>;
|
324
342
|
interface GraphQLRequestOptions {
|
325
343
|
url?: string;
|
326
344
|
parser?: ParserLike;
|
@@ -328,32 +346,41 @@ interface GraphQLRequestOptions {
|
|
328
346
|
throwOnNonNetworkErrors?: boolean;
|
329
347
|
httpOptions?: Omit<RequestInit, "body" | "method">;
|
330
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;
|
331
362
|
|
332
|
-
type BiMapper<T> = (value: string) => T;
|
333
363
|
type GraphQLBoxWhere = BoxWhere & {
|
334
|
-
/** Base16-encoded BoxIds */
|
335
|
-
boxIds?: HexString[];
|
336
364
|
/** Base16-encoded ErgoTrees */
|
337
365
|
ergoTrees?: HexString[];
|
338
366
|
/** Base58-encoded addresses or `ErgoAddress` objects */
|
339
367
|
addresses?: (Base58String | ErgoAddress)[];
|
340
368
|
};
|
341
369
|
type GraphQLConfirmedTransactionWhere = ConfirmedTransactionWhere & {
|
342
|
-
transactionIds?: HexString[];
|
343
370
|
addresses?: (Base58String | ErgoAddress)[];
|
344
371
|
ergoTrees?: HexString[];
|
345
372
|
};
|
346
373
|
type GraphQLUnconfirmedTransactionWhere = UnconfirmedTransactionWhere & {
|
347
|
-
transactionIds?: HexString[];
|
348
374
|
addresses?: (Base58String | ErgoAddress)[];
|
349
375
|
ergoTrees?: HexString[];
|
350
376
|
};
|
351
377
|
type GraphQLBoxQuery = BoxQuery<GraphQLBoxWhere>;
|
352
|
-
type ErgoGraphQLRequestOptions = Omit<GraphQLRequestOptions, "
|
378
|
+
type ErgoGraphQLRequestOptions = Omit<GraphQLRequestOptions, "throwOnNonNetworkErrors">;
|
379
|
+
type BiMapper<T> = (value: string) => T;
|
353
380
|
declare class ErgoGraphQLProvider<I = bigint> implements IBlockchainProvider<I> {
|
354
381
|
#private;
|
355
382
|
constructor(url: string);
|
356
|
-
constructor(
|
383
|
+
constructor(options: ErgoGraphQLRequestOptions);
|
357
384
|
setUrl(url: string): ErgoGraphQLProvider<I>;
|
358
385
|
setBigIntMapper<M>(mapper: BiMapper<M>): ErgoGraphQLProvider<M>;
|
359
386
|
streamBoxes(query: GraphQLBoxQuery): AsyncGenerator<ChainProviderBox<I>[]>;
|
@@ -368,5 +395,6 @@ declare class ErgoGraphQLProvider<I = bigint> implements IBlockchainProvider<I>
|
|
368
395
|
submitTransaction(signedTransaction: SignedTransaction): Promise<TransactionEvaluationResult>;
|
369
396
|
reduceTransaction(): Promise<TransactionReductionResult>;
|
370
397
|
}
|
398
|
+
declare function isRequestParam(obj: unknown): obj is ErgoGraphQLRequestOptions;
|
371
399
|
|
372
|
-
export { ErgoGraphQLProvider, type ErgoGraphQLRequestOptions, type GraphQLBoxQuery, type GraphQLBoxWhere, type GraphQLConfirmedTransactionWhere, type GraphQLUnconfirmedTransactionWhere };
|
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
@@ -302,10 +302,27 @@ type URLLike = string | Route;
|
|
302
302
|
type FallbackRetryOptions = {
|
303
303
|
fallbacks?: URLLike[];
|
304
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>;
|
305
313
|
type RetryOptions = {
|
306
314
|
attempts: number;
|
307
315
|
delay: number;
|
308
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>;
|
309
326
|
|
310
327
|
type GraphQLVariables = Record<string, unknown> | null;
|
311
328
|
interface GraphQLError {
|
@@ -321,6 +338,7 @@ interface GraphQLErrorResponse {
|
|
321
338
|
}
|
322
339
|
type GraphQLResponse<T = unknown> = GraphQLSuccessResponse<T> | GraphQLErrorResponse;
|
323
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>;
|
324
342
|
interface GraphQLRequestOptions {
|
325
343
|
url?: string;
|
326
344
|
parser?: ParserLike;
|
@@ -328,32 +346,41 @@ interface GraphQLRequestOptions {
|
|
328
346
|
throwOnNonNetworkErrors?: boolean;
|
329
347
|
httpOptions?: Omit<RequestInit, "body" | "method">;
|
330
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;
|
331
362
|
|
332
|
-
type BiMapper<T> = (value: string) => T;
|
333
363
|
type GraphQLBoxWhere = BoxWhere & {
|
334
|
-
/** Base16-encoded BoxIds */
|
335
|
-
boxIds?: HexString[];
|
336
364
|
/** Base16-encoded ErgoTrees */
|
337
365
|
ergoTrees?: HexString[];
|
338
366
|
/** Base58-encoded addresses or `ErgoAddress` objects */
|
339
367
|
addresses?: (Base58String | ErgoAddress)[];
|
340
368
|
};
|
341
369
|
type GraphQLConfirmedTransactionWhere = ConfirmedTransactionWhere & {
|
342
|
-
transactionIds?: HexString[];
|
343
370
|
addresses?: (Base58String | ErgoAddress)[];
|
344
371
|
ergoTrees?: HexString[];
|
345
372
|
};
|
346
373
|
type GraphQLUnconfirmedTransactionWhere = UnconfirmedTransactionWhere & {
|
347
|
-
transactionIds?: HexString[];
|
348
374
|
addresses?: (Base58String | ErgoAddress)[];
|
349
375
|
ergoTrees?: HexString[];
|
350
376
|
};
|
351
377
|
type GraphQLBoxQuery = BoxQuery<GraphQLBoxWhere>;
|
352
|
-
type ErgoGraphQLRequestOptions = Omit<GraphQLRequestOptions, "
|
378
|
+
type ErgoGraphQLRequestOptions = Omit<GraphQLRequestOptions, "throwOnNonNetworkErrors">;
|
379
|
+
type BiMapper<T> = (value: string) => T;
|
353
380
|
declare class ErgoGraphQLProvider<I = bigint> implements IBlockchainProvider<I> {
|
354
381
|
#private;
|
355
382
|
constructor(url: string);
|
356
|
-
constructor(
|
383
|
+
constructor(options: ErgoGraphQLRequestOptions);
|
357
384
|
setUrl(url: string): ErgoGraphQLProvider<I>;
|
358
385
|
setBigIntMapper<M>(mapper: BiMapper<M>): ErgoGraphQLProvider<M>;
|
359
386
|
streamBoxes(query: GraphQLBoxQuery): AsyncGenerator<ChainProviderBox<I>[]>;
|
@@ -368,5 +395,6 @@ declare class ErgoGraphQLProvider<I = bigint> implements IBlockchainProvider<I>
|
|
368
395
|
submitTransaction(signedTransaction: SignedTransaction): Promise<TransactionEvaluationResult>;
|
369
396
|
reduceTransaction(): Promise<TransactionReductionResult>;
|
370
397
|
}
|
398
|
+
declare function isRequestParam(obj: unknown): obj is ErgoGraphQLRequestOptions;
|
371
399
|
|
372
|
-
export { ErgoGraphQLProvider, type ErgoGraphQLRequestOptions, type GraphQLBoxQuery, type GraphQLBoxWhere, type GraphQLConfirmedTransactionWhere, type GraphQLUnconfirmedTransactionWhere };
|
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.js
CHANGED
@@ -4,6 +4,52 @@ var common = require('@fleet-sdk/common');
|
|
4
4
|
var core = require('@fleet-sdk/core');
|
5
5
|
|
6
6
|
// src/ergo-graphql/ergoGraphQLProvider.ts
|
7
|
+
new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
8
|
+
var HEXES = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
9
|
+
var HexChar = {
|
10
|
+
ZERO: 48,
|
11
|
+
// 0
|
12
|
+
NINE: 57,
|
13
|
+
// 9
|
14
|
+
A_UP: 65,
|
15
|
+
// A
|
16
|
+
F_UP: 70,
|
17
|
+
// F
|
18
|
+
A_LO: 97,
|
19
|
+
// a
|
20
|
+
F_LO: 102
|
21
|
+
// f
|
22
|
+
};
|
23
|
+
function bytesToHex(bytes2) {
|
24
|
+
common.assertInstanceOf(bytes2, Uint8Array);
|
25
|
+
let hex3 = "";
|
26
|
+
for (let i = 0, len = bytes2.length; i < len; i++) {
|
27
|
+
hex3 += HEXES[bytes2[i]];
|
28
|
+
}
|
29
|
+
return hex3;
|
30
|
+
}
|
31
|
+
function hexToBytes(hex3) {
|
32
|
+
common.assertTypeOf(hex3, "string");
|
33
|
+
common.assert(hex3.length % 2 === 0, "Invalid hex padding.");
|
34
|
+
const len = hex3.length / 2;
|
35
|
+
const bytes2 = new Uint8Array(len);
|
36
|
+
for (let i = 0, j = 0; i < len; i++) {
|
37
|
+
const n1 = charCodeToBase16(hex3.charCodeAt(j++));
|
38
|
+
const n2 = charCodeToBase16(hex3.charCodeAt(j++));
|
39
|
+
bytes2[i] = n1 * 16 + n2;
|
40
|
+
}
|
41
|
+
return bytes2;
|
42
|
+
}
|
43
|
+
function charCodeToBase16(char) {
|
44
|
+
if (char >= HexChar.ZERO && char <= HexChar.NINE) return char - HexChar.ZERO;
|
45
|
+
if (char >= HexChar.A_UP && char <= HexChar.F_UP) return char - (HexChar.A_UP - 10);
|
46
|
+
if (char >= HexChar.A_LO && char <= HexChar.F_LO) return char - (HexChar.A_LO - 10);
|
47
|
+
throw new Error("Invalid byte sequence.");
|
48
|
+
}
|
49
|
+
var hex2 = {
|
50
|
+
encode: bytesToHex,
|
51
|
+
decode: hexToBytes
|
52
|
+
};
|
7
53
|
async function request(path, opt) {
|
8
54
|
const url = buildURL(path, opt?.query, opt?.base);
|
9
55
|
let response;
|
@@ -73,12 +119,12 @@ function createGqlOperation(query, options) {
|
|
73
119
|
return response;
|
74
120
|
};
|
75
121
|
}
|
122
|
+
function gql(query) {
|
123
|
+
return query[0];
|
124
|
+
}
|
76
125
|
function getOpName(query) {
|
77
126
|
return OP_NAME_REGEX.exec(query)?.at(2);
|
78
127
|
}
|
79
|
-
function isRequestParam(obj) {
|
80
|
-
return typeof obj === "object" && obj.url !== void 0;
|
81
|
-
}
|
82
128
|
|
83
129
|
// src/ergo-graphql/queries.ts
|
84
130
|
var B = [
|
@@ -102,6 +148,7 @@ var UNCONF_TX_QUERY = `query unconfirmedTransactions(${T[0]}) { mempool { transa
|
|
102
148
|
|
103
149
|
// src/ergo-graphql/ergoGraphQLProvider.ts
|
104
150
|
var PAGE_SIZE = 50;
|
151
|
+
var MAX_ARGS = 20;
|
105
152
|
var ErgoGraphQLProvider = class {
|
106
153
|
#options;
|
107
154
|
#biMapper;
|
@@ -114,11 +161,11 @@ var ErgoGraphQLProvider = class {
|
|
114
161
|
#sendTransaction;
|
115
162
|
#getHeaders;
|
116
163
|
constructor(optOrUrl) {
|
164
|
+
this.#biMapper = (value) => BigInt(value);
|
117
165
|
this.#options = {
|
118
166
|
...isRequestParam(optOrUrl) ? optOrUrl : { url: optOrUrl },
|
119
167
|
throwOnNonNetworkErrors: true
|
120
168
|
};
|
121
|
-
this.#biMapper = (value) => BigInt(value);
|
122
169
|
this.#getConfirmedBoxes = this.createOperation(CONF_BOXES_QUERY);
|
123
170
|
this.#getUnconfirmedBoxes = this.createOperation(UNCONF_BOXES_QUERY);
|
124
171
|
this.#getAllBoxes = this.createOperation(ALL_BOXES_QUERY);
|
@@ -129,7 +176,7 @@ var ErgoGraphQLProvider = class {
|
|
129
176
|
this.#getHeaders = this.createOperation(HEADERS_QUERY);
|
130
177
|
}
|
131
178
|
#fetchBoxes(args, inclConf, inclUnconf) {
|
132
|
-
return inclConf && inclUnconf ? this.#getAllBoxes(args
|
179
|
+
return inclConf && inclUnconf ? this.#getAllBoxes(args) : inclUnconf ? this.#getUnconfirmedBoxes(args) : this.#getConfirmedBoxes(args);
|
133
180
|
}
|
134
181
|
setUrl(url) {
|
135
182
|
this.#options.url = url;
|
@@ -146,95 +193,101 @@ var ErgoGraphQLProvider = class {
|
|
146
193
|
const notBeingSpent = (box) => !box.beingSpent;
|
147
194
|
const returnedBoxIds = /* @__PURE__ */ new Set();
|
148
195
|
const { where, from } = query;
|
149
|
-
const
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
if (
|
158
|
-
|
159
|
-
|
196
|
+
const queries = buildGqlBoxQueries(where);
|
197
|
+
const isMempoolAware = from !== "blockchain";
|
198
|
+
for (const query2 of queries) {
|
199
|
+
let inclChain = from !== "mempool";
|
200
|
+
let inclPool = from !== "blockchain";
|
201
|
+
while (inclChain || inclPool) {
|
202
|
+
const { data } = await this.#fetchBoxes(query2, inclChain, inclPool);
|
203
|
+
let boxes = [];
|
204
|
+
if (inclChain && hasConfirmed(data)) {
|
205
|
+
if (common.some(data.boxes)) {
|
206
|
+
const confirmedBoxes = (isMempoolAware ? data.boxes.filter(notBeingSpent) : data.boxes).map((b) => mapConfirmedBox(b, this.#biMapper));
|
207
|
+
boxes = boxes.concat(confirmedBoxes);
|
208
|
+
}
|
209
|
+
inclChain = data.boxes.length === PAGE_SIZE;
|
160
210
|
}
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
}
|
168
|
-
inclPool = data.mempool.boxes.length === PAGE_SIZE;
|
169
|
-
}
|
170
|
-
if (common.some(boxes)) {
|
171
|
-
if (boxes.some((box) => returnedBoxIds.has(box.boxId))) {
|
172
|
-
boxes = boxes.filter((b) => !returnedBoxIds.has(b.boxId));
|
211
|
+
if (isMempoolAware && hasMempool(data)) {
|
212
|
+
if (common.some(data.mempool.boxes)) {
|
213
|
+
const mempoolBoxes = data.mempool.boxes.filter(notBeingSpent).map((b) => mapUnconfirmedBox(b, this.#biMapper));
|
214
|
+
boxes = boxes.concat(mempoolBoxes);
|
215
|
+
}
|
216
|
+
inclPool = data.mempool.boxes.length === PAGE_SIZE;
|
173
217
|
}
|
174
218
|
if (common.some(boxes)) {
|
175
|
-
|
176
|
-
|
177
|
-
|
219
|
+
if (boxes.some((box) => returnedBoxIds.has(box.boxId))) {
|
220
|
+
boxes = boxes.filter((b) => !returnedBoxIds.has(b.boxId));
|
221
|
+
}
|
222
|
+
if (common.some(boxes)) {
|
223
|
+
boxes = common.uniqBy(boxes, (box) => box.boxId);
|
224
|
+
for (const box of boxes) returnedBoxIds.add(box.boxId);
|
225
|
+
yield boxes;
|
226
|
+
}
|
178
227
|
}
|
228
|
+
if (inclChain || inclPool) query2.skip += PAGE_SIZE;
|
179
229
|
}
|
180
|
-
|
181
|
-
} while (inclChain || inclPool);
|
230
|
+
}
|
182
231
|
}
|
183
232
|
async getBoxes(query) {
|
184
233
|
const boxes = [];
|
185
|
-
for await (const
|
234
|
+
for await (const chunk2 of this.streamBoxes(query)) boxes.push(chunk2);
|
186
235
|
return common.orderBy(boxes.flat(), (box) => box.creationHeight);
|
187
236
|
}
|
188
237
|
async *streamUnconfirmedTransactions(query) {
|
189
|
-
const
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
238
|
+
const queries = buildGqlUnconfirmedTxQueries(query.where);
|
239
|
+
for (const query2 of queries) {
|
240
|
+
let keepFetching = true;
|
241
|
+
while (keepFetching) {
|
242
|
+
const response = await this.#getUnconfirmedTransactions(query2);
|
243
|
+
if (common.some(response.data?.mempool?.transactions)) {
|
244
|
+
yield response.data.mempool.transactions.map(
|
245
|
+
(t) => mapUnconfirmedTransaction(t, this.#biMapper)
|
246
|
+
);
|
247
|
+
}
|
248
|
+
keepFetching = response.data?.mempool?.transactions?.length === PAGE_SIZE;
|
249
|
+
if (keepFetching) query2.skip += PAGE_SIZE;
|
197
250
|
}
|
198
|
-
keepFetching = response.data?.mempool?.transactions?.length === PAGE_SIZE;
|
199
|
-
if (keepFetching) args.skip += PAGE_SIZE;
|
200
251
|
}
|
201
252
|
}
|
202
253
|
async getUnconfirmedTransactions(query) {
|
203
254
|
const transactions = [];
|
204
|
-
for await (const
|
205
|
-
transactions.push(
|
255
|
+
for await (const chunk2 of this.streamUnconfirmedTransactions(query)) {
|
256
|
+
transactions.push(chunk2);
|
206
257
|
}
|
207
258
|
return transactions.flat();
|
208
259
|
}
|
209
260
|
async *streamConfirmedTransactions(query) {
|
210
|
-
const
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
261
|
+
const queries = buildGqlConfirmedTxQueries(query.where);
|
262
|
+
for (const query2 of queries) {
|
263
|
+
let keepFetching = true;
|
264
|
+
while (keepFetching) {
|
265
|
+
const response = await this.#getConfirmedTransactions(query2);
|
266
|
+
if (common.some(response.data?.transactions)) {
|
267
|
+
yield response.data.transactions.map(
|
268
|
+
(t) => mapConfirmedTransaction(t, this.#biMapper)
|
269
|
+
);
|
270
|
+
}
|
271
|
+
keepFetching = response.data?.transactions?.length === PAGE_SIZE;
|
272
|
+
if (keepFetching) query2.skip += PAGE_SIZE;
|
218
273
|
}
|
219
|
-
keepFetching = response.data?.transactions?.length === PAGE_SIZE;
|
220
|
-
if (keepFetching) args.skip += PAGE_SIZE;
|
221
274
|
}
|
222
275
|
}
|
223
276
|
async getConfirmedTransactions(query) {
|
224
277
|
const transactions = [];
|
225
|
-
for await (const
|
226
|
-
transactions.push(
|
278
|
+
for await (const chunk2 of this.streamConfirmedTransactions(query)) {
|
279
|
+
transactions.push(chunk2);
|
227
280
|
}
|
228
281
|
return transactions.flat();
|
229
282
|
}
|
230
283
|
async getHeaders(query) {
|
231
|
-
const response = await this.#getHeaders(query
|
232
|
-
return response.data?.blockHeaders.map((
|
233
|
-
...
|
234
|
-
id:
|
235
|
-
timestamp: Number(
|
236
|
-
nBits: Number(
|
237
|
-
votes:
|
284
|
+
const response = await this.#getHeaders(query);
|
285
|
+
return response.data?.blockHeaders.map((h) => ({
|
286
|
+
...h,
|
287
|
+
id: h.headerId,
|
288
|
+
timestamp: Number(h.timestamp),
|
289
|
+
nBits: Number(h.nBits),
|
290
|
+
votes: hex2.encode(Uint8Array.from(h.votes))
|
238
291
|
})) ?? [];
|
239
292
|
}
|
240
293
|
createOperation(query, options) {
|
@@ -244,10 +297,7 @@ var ErgoGraphQLProvider = class {
|
|
244
297
|
}
|
245
298
|
async checkTransaction(signedTransaction) {
|
246
299
|
try {
|
247
|
-
const response = await this.#checkTransaction(
|
248
|
-
{ signedTransaction },
|
249
|
-
this.#options.url
|
250
|
-
);
|
300
|
+
const response = await this.#checkTransaction({ signedTransaction });
|
251
301
|
return { success: true, transactionId: response.data.checkTransaction };
|
252
302
|
} catch (e) {
|
253
303
|
return { success: false, message: e.message };
|
@@ -255,10 +305,7 @@ var ErgoGraphQLProvider = class {
|
|
255
305
|
}
|
256
306
|
async submitTransaction(signedTransaction) {
|
257
307
|
try {
|
258
|
-
const response = await this.#sendTransaction(
|
259
|
-
{ signedTransaction },
|
260
|
-
this.#options.url
|
261
|
-
);
|
308
|
+
const response = await this.#sendTransaction({ signedTransaction });
|
262
309
|
return { success: true, transactionId: response.data.submitTransaction };
|
263
310
|
} catch (e) {
|
264
311
|
return { success: false, message: e.message };
|
@@ -268,26 +315,26 @@ var ErgoGraphQLProvider = class {
|
|
268
315
|
throw new common.NotSupportedError("Transaction reducing is not supported by ergo-graphql.");
|
269
316
|
}
|
270
317
|
};
|
271
|
-
function
|
272
|
-
const
|
318
|
+
function buildGqlBoxQueries(where) {
|
319
|
+
const ergoTrees = common.uniq(
|
320
|
+
[
|
321
|
+
merge(where.ergoTrees, where.ergoTree) ?? [],
|
322
|
+
merge(where.addresses, where.address)?.map(
|
323
|
+
(a) => typeof a === "string" ? core.ErgoAddress.decode(a).ergoTree : a.ergoTree
|
324
|
+
) ?? []
|
325
|
+
].flat()
|
326
|
+
);
|
327
|
+
return common.chunk(ergoTrees, MAX_ARGS).map((chunk2) => ({
|
273
328
|
spent: false,
|
274
|
-
boxIds:
|
275
|
-
ergoTrees:
|
329
|
+
boxIds: where.boxId ? [where.boxId] : void 0,
|
330
|
+
ergoTrees: chunk2,
|
276
331
|
ergoTreeTemplateHash: where.templateHash,
|
277
332
|
tokenId: where.tokenId,
|
278
333
|
skip: 0,
|
279
334
|
take: PAGE_SIZE
|
280
|
-
};
|
281
|
-
const addresses = merge(where.addresses, where.address);
|
282
|
-
if (common.some(addresses)) {
|
283
|
-
const trees = addresses.map(
|
284
|
-
(address) => typeof address === "string" ? core.ErgoAddress.decode(address).ergoTree : address.ergoTree
|
285
|
-
);
|
286
|
-
args.ergoTrees = common.uniq(common.some(args.ergoTrees) ? args.ergoTrees.concat(trees) : trees);
|
287
|
-
}
|
288
|
-
return args;
|
335
|
+
}));
|
289
336
|
}
|
290
|
-
function
|
337
|
+
function buildGqlUnconfirmedTxQueries(where) {
|
291
338
|
const addresses = common.uniq(
|
292
339
|
[
|
293
340
|
merge(where.addresses, where.address)?.map(
|
@@ -298,20 +345,20 @@ function buildGqlUnconfirmedTxQueryArgs(where) {
|
|
298
345
|
) ?? []
|
299
346
|
].flat()
|
300
347
|
);
|
301
|
-
return {
|
302
|
-
addresses:
|
303
|
-
transactionIds:
|
348
|
+
return common.chunk(addresses, MAX_ARGS).map((chunk2) => ({
|
349
|
+
addresses: chunk2.length ? chunk2 : void 0,
|
350
|
+
transactionIds: where.transactionId ? [where.transactionId] : void 0,
|
304
351
|
skip: 0,
|
305
352
|
take: PAGE_SIZE
|
306
|
-
};
|
353
|
+
}));
|
307
354
|
}
|
308
|
-
function
|
309
|
-
return {
|
310
|
-
...
|
355
|
+
function buildGqlConfirmedTxQueries(where) {
|
356
|
+
return buildGqlUnconfirmedTxQueries(where).map((query) => ({
|
357
|
+
...query,
|
311
358
|
headerId: where.headerId,
|
312
359
|
minHeight: where.minHeight,
|
313
360
|
onlyRelevantOutputs: where.onlyRelevantOutputs
|
314
|
-
};
|
361
|
+
}));
|
315
362
|
}
|
316
363
|
function merge(array, el) {
|
317
364
|
if (common.isEmpty(array) && common.isUndefined(el)) return;
|
@@ -388,7 +435,24 @@ function mapConfirmedTransaction(tx, mapper) {
|
|
388
435
|
confirmed: true
|
389
436
|
};
|
390
437
|
}
|
438
|
+
function isRequestParam(obj) {
|
439
|
+
return typeof obj === "object" && obj.url !== void 0;
|
440
|
+
}
|
441
|
+
/*! Bundled license information:
|
442
|
+
|
443
|
+
@noble/hashes/esm/utils.js:
|
444
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
445
|
+
|
446
|
+
@scure/base/lib/esm/index.js:
|
447
|
+
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
448
|
+
*/
|
391
449
|
|
392
450
|
exports.ErgoGraphQLProvider = ErgoGraphQLProvider;
|
451
|
+
exports.createGqlOperation = createGqlOperation;
|
452
|
+
exports.exponentialRetry = exponentialRetry;
|
453
|
+
exports.getOpName = getOpName;
|
454
|
+
exports.gql = gql;
|
455
|
+
exports.isRequestParam = isRequestParam;
|
456
|
+
exports.request = request;
|
393
457
|
//# sourceMappingURL=index.js.map
|
394
458
|
//# sourceMappingURL=index.js.map
|