@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/dist/index.js CHANGED
@@ -4,79 +4,187 @@ 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
+ };
53
+ async function request(path, opt) {
54
+ const url = buildURL(path, opt?.query, opt?.base);
55
+ let response;
56
+ if (opt?.retry) {
57
+ const routes = common.some(opt.retry.fallbacks) ? [url, ...opt.retry.fallbacks] : [url];
58
+ const attempts = opt.retry.attempts;
59
+ response = await exponentialRetry(
60
+ (r) => fetch(resolveUrl(routes, attempts - r), opt.httpOptions),
61
+ opt.retry
62
+ );
63
+ } else {
64
+ response = await fetch(url, opt?.httpOptions);
65
+ }
66
+ return (opt?.parser || JSON).parse(await response.text());
67
+ }
68
+ function resolveUrl(routes, attempt) {
69
+ const route = routes[attempt % routes.length];
70
+ return typeof route === "string" ? route : buildURL(route.path, route.query, route.base).toString();
71
+ }
72
+ function buildURL(path, query, base) {
73
+ if (!base && !query) return path;
74
+ const url = new URL(path, base);
75
+ if (common.some(query)) {
76
+ for (const key in query) url.searchParams.append(key, String(query[key]));
77
+ }
78
+ return url.toString();
79
+ }
80
+ async function exponentialRetry(operation, { attempts, delay }) {
81
+ try {
82
+ return await operation(attempts);
83
+ } catch (e) {
84
+ if (attempts > 0) {
85
+ await new Promise((resolve) => setTimeout(resolve, delay));
86
+ return exponentialRetry(operation, { attempts: attempts - 1, delay: delay * 2 });
87
+ }
88
+ throw e;
89
+ }
90
+ }
91
+
92
+ // src/utils/graphql.ts
7
93
  var OP_NAME_REGEX = /(query|mutation)\s?([\w\-_]+)?/;
8
94
  var DEFAULT_HEADERS = {
9
95
  "content-type": "application/json; charset=utf-8",
10
96
  accept: "application/graphql-response+json, application/json"
11
97
  };
12
98
  function createGqlOperation(query, options) {
13
- return async (variables) => {
14
- const response = await (options.fetcher ?? fetch)(options.url, {
15
- method: "POST",
16
- headers: common.ensureDefaults(options.headers, DEFAULT_HEADERS),
17
- credentials: options.credentials,
18
- body: (options.parser ?? JSON).stringify({
19
- operationName: getOpName(query),
20
- query,
21
- variables: variables ? common.clearUndefined(variables) : void 0
22
- })
99
+ return async (variables, url) => {
100
+ url = url ?? options?.url;
101
+ if (!url) throw new Error("URL is required");
102
+ const response = await request(url, {
103
+ ...options,
104
+ httpOptions: {
105
+ ...options?.httpOptions,
106
+ method: "POST",
107
+ headers: common.ensureDefaults(options?.httpOptions?.headers, DEFAULT_HEADERS),
108
+ body: (options?.parser ?? JSON).stringify({
109
+ operationName: getOpName(query),
110
+ query,
111
+ variables: variables ? common.clearUndefined(variables) : void 0
112
+ })
113
+ }
23
114
  });
24
- const rawData = await response.text();
25
- const parsedData = (options.parser ?? JSON).parse(
26
- rawData
27
- );
28
- if (options.throwOnNonNetworkErrors && common.some(parsedData.errors) && common.isEmpty(parsedData.data)) {
29
- throw new common.BlockchainProviderError(parsedData.errors[0].message, {
30
- cause: parsedData.errors
31
- });
115
+ if (options?.throwOnNonNetworkErrors && common.some(response.errors) && common.isEmpty(response.data)) {
116
+ const msg = response.errors[0].message;
117
+ throw new common.BlockchainProviderError(msg, { cause: response.errors });
32
118
  }
33
- return parsedData;
119
+ return response;
34
120
  };
35
121
  }
122
+ function gql(query) {
123
+ return query[0];
124
+ }
36
125
  function getOpName(query) {
37
126
  return OP_NAME_REGEX.exec(query)?.at(2);
38
127
  }
39
- function isRequestParam(obj) {
40
- return typeof obj === "object" && obj.url !== void 0;
41
- }
42
128
 
43
129
  // src/ergo-graphql/queries.ts
44
130
  var B = [
45
- "query boxes($spent: Boolean! $boxIds: [String!] $ergoTrees: [String!] $ergoTreeTemplateHash: String $tokenId: String $skip: Int $take: Int)",
131
+ "$boxIds: [String!] $ergoTrees: [String!] $ergoTreeTemplateHash: String $tokenId: String $skip: Int $take: Int",
46
132
  "boxIds: $boxIds ergoTrees: $ergoTrees ergoTreeTemplateHash: $ergoTreeTemplateHash tokenId: $tokenId skip: $skip take: $take",
47
- "boxId transactionId index value creationHeight ergoTree assets { tokenId amount } additionalRegisters beingSpent"
133
+ "boxId transactionId index value creationHeight ergoTree assets { tokenId amount } additionalRegisters"
48
134
  ];
49
- var CONF_BOXES_QUERY = `${B[0]} { boxes(spent: $spent ${B[1]}) { ${B[2]} } }`;
50
- var UNCONF_BOXES_QUERY = `${B[0]} { mempool { boxes(${B[1]}) { ${B[2]} } } }`;
51
- var ALL_BOXES_QUERY = `${B[0]} { boxes(spent: $spent ${B[1]}) { ${B[2]} } mempool { boxes(${B[1]}) { ${B[2]} } } }`;
135
+ var CONF_BOXES_QUERY = `query boxes($spent: Boolean! ${B[0]}) { boxes(spent: $spent ${B[1]}) { ${B[2]} beingSpent } }`;
136
+ var UNCONF_BOXES_QUERY = `query boxes(${B[0]}) { mempool { boxes(${B[1]}) { ${B[2]} beingSpent } } }`;
137
+ var ALL_BOXES_QUERY = `query boxes($spent: Boolean! ${B[0]}) { boxes(spent: $spent ${B[1]}) { ${B[2]} beingSpent } mempool { boxes(${B[1]}) { ${B[2]} beingSpent } } }`;
52
138
  var HEADERS_QUERY = "query blockHeaders($take: Int) { blockHeaders(take: $take) {headerId timestamp version adProofsRoot stateRoot transactionsRoot nBits extensionHash powSolutions height difficulty parentId votes } }";
53
139
  var CHECK_TX_MUTATION = "mutation checkTransaction($signedTransaction: SignedTransaction!) { checkTransaction(signedTransaction: $signedTransaction) }";
54
140
  var SEND_TX_MUTATION = "mutation submitTransaction($signedTransaction: SignedTransaction!) { submitTransaction(signedTransaction: $signedTransaction) }";
141
+ var T = [
142
+ "$addresses: [String!], $transactionIds: [String!], $skip: Int, $take: Int",
143
+ "addresses: $addresses, transactionIds: $transactionIds, skip: $skip, take: $take",
144
+ `transactionId timestamp inputs { proofBytes extension index box { ${B[2]} } } dataInputs { boxId }`
145
+ ];
146
+ var CONF_TX_QUERY = `query confirmedTransactions(${T[0]} $relevantOnly: Boolean) { transactions(${T[1]}) { ${T[2]} outputs(relevantOnly: $relevantOnly) { ${B[2]} } inclusionHeight headerId index } }`;
147
+ var UNCONF_TX_QUERY = `query unconfirmedTransactions(${T[0]}) { mempool { transactions(${T[1]}) { ${T[2]} outputs { ${B[2]} } } } }`;
55
148
 
56
149
  // src/ergo-graphql/ergoGraphQLProvider.ts
57
150
  var PAGE_SIZE = 50;
151
+ var MAX_ARGS = 20;
58
152
  var ErgoGraphQLProvider = class {
59
153
  #options;
60
- #getConfBoxes;
61
- #getUnconfBoxes;
154
+ #biMapper;
155
+ #getConfirmedBoxes;
156
+ #getUnconfirmedBoxes;
62
157
  #getAllBoxes;
158
+ #getConfirmedTransactions;
159
+ #getUnconfirmedTransactions;
160
+ #checkTransaction;
161
+ #sendTransaction;
63
162
  #getHeaders;
64
- #checkTx;
65
- #sendTx;
66
163
  constructor(optOrUrl) {
164
+ this.#biMapper = (value) => BigInt(value);
67
165
  this.#options = {
68
166
  ...isRequestParam(optOrUrl) ? optOrUrl : { url: optOrUrl },
69
167
  throwOnNonNetworkErrors: true
70
168
  };
71
- this.#getConfBoxes = this.createOperation(CONF_BOXES_QUERY);
72
- this.#getUnconfBoxes = this.createOperation(UNCONF_BOXES_QUERY);
169
+ this.#getConfirmedBoxes = this.createOperation(CONF_BOXES_QUERY);
170
+ this.#getUnconfirmedBoxes = this.createOperation(UNCONF_BOXES_QUERY);
73
171
  this.#getAllBoxes = this.createOperation(ALL_BOXES_QUERY);
172
+ this.#getConfirmedTransactions = this.createOperation(CONF_TX_QUERY);
173
+ this.#getUnconfirmedTransactions = this.createOperation(UNCONF_TX_QUERY);
174
+ this.#checkTransaction = this.createOperation(CHECK_TX_MUTATION);
175
+ this.#sendTransaction = this.createOperation(SEND_TX_MUTATION);
74
176
  this.#getHeaders = this.createOperation(HEADERS_QUERY);
75
- this.#checkTx = this.createOperation(CHECK_TX_MUTATION);
76
- this.#sendTx = this.createOperation(SEND_TX_MUTATION);
77
177
  }
78
178
  #fetchBoxes(args, inclConf, inclUnconf) {
79
- return inclConf && inclUnconf ? this.#getAllBoxes(args) : inclUnconf ? this.#getUnconfBoxes(args) : this.#getConfBoxes(args);
179
+ return inclConf && inclUnconf ? this.#getAllBoxes(args) : inclUnconf ? this.#getUnconfirmedBoxes(args) : this.#getConfirmedBoxes(args);
180
+ }
181
+ setUrl(url) {
182
+ this.#options.url = url;
183
+ return this;
184
+ }
185
+ setBigIntMapper(mapper) {
186
+ this.#biMapper = mapper;
187
+ return this;
80
188
  }
81
189
  async *streamBoxes(query) {
82
190
  if (common.isEmpty(query.where)) {
@@ -85,56 +193,101 @@ var ErgoGraphQLProvider = class {
85
193
  const notBeingSpent = (box) => !box.beingSpent;
86
194
  const returnedBoxIds = /* @__PURE__ */ new Set();
87
195
  const { where, from } = query;
88
- const args = buildGqlBoxQueryArgs(where);
89
- let inclChain = from !== "mempool";
90
- let inclPool = from !== "blockchain";
91
- const isMempoolAware = inclPool;
92
- do {
93
- const response = await this.#fetchBoxes(args, inclChain, inclPool);
94
- const { data } = response;
95
- let boxes = [];
96
- if (inclChain && hasConfirmed(data)) {
97
- if (common.some(data.boxes)) {
98
- const confirmedBoxes = (isMempoolAware ? data.boxes.filter(notBeingSpent) : data.boxes).map(asConfirmed(true));
99
- boxes = boxes.concat(confirmedBoxes);
100
- }
101
- inclChain = data.boxes.length === PAGE_SIZE;
102
- }
103
- if (isMempoolAware && hasMempool(data)) {
104
- if (common.some(data.mempool.boxes)) {
105
- const mempoolBoxes = data.mempool.boxes.filter(notBeingSpent).map(asConfirmed(false));
106
- boxes = boxes.concat(mempoolBoxes);
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;
107
210
  }
108
- inclPool = data.mempool.boxes.length === PAGE_SIZE;
109
- }
110
- if (common.some(boxes)) {
111
- if (boxes.some((box) => returnedBoxIds.has(box.boxId))) {
112
- 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;
113
217
  }
114
218
  if (common.some(boxes)) {
115
- boxes = common.uniqBy(boxes, (box) => box.boxId);
116
- for (const box of boxes) returnedBoxIds.add(box.boxId);
117
- yield boxes;
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
+ }
118
227
  }
228
+ if (inclChain || inclPool) query2.skip += PAGE_SIZE;
119
229
  }
120
- if (inclChain || inclPool) args.skip += PAGE_SIZE;
121
- } while (inclChain || inclPool);
230
+ }
122
231
  }
123
232
  async getBoxes(query) {
124
- let boxes = [];
125
- for await (const chunk of this.streamBoxes(query)) {
126
- boxes = boxes.concat(chunk);
233
+ const boxes = [];
234
+ for await (const chunk2 of this.streamBoxes(query)) boxes.push(chunk2);
235
+ return common.orderBy(boxes.flat(), (box) => box.creationHeight);
236
+ }
237
+ async *streamUnconfirmedTransactions(query) {
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;
250
+ }
251
+ }
252
+ }
253
+ async getUnconfirmedTransactions(query) {
254
+ const transactions = [];
255
+ for await (const chunk2 of this.streamUnconfirmedTransactions(query)) {
256
+ transactions.push(chunk2);
257
+ }
258
+ return transactions.flat();
259
+ }
260
+ async *streamConfirmedTransactions(query) {
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;
273
+ }
274
+ }
275
+ }
276
+ async getConfirmedTransactions(query) {
277
+ const transactions = [];
278
+ for await (const chunk2 of this.streamConfirmedTransactions(query)) {
279
+ transactions.push(chunk2);
127
280
  }
128
- return common.orderBy(boxes, (box) => box.creationHeight);
281
+ return transactions.flat();
129
282
  }
130
283
  async getHeaders(query) {
131
284
  const response = await this.#getHeaders(query);
132
- return response.data?.blockHeaders.map((header) => ({
133
- ...header,
134
- id: header.headerId,
135
- timestamp: Number(header.timestamp),
136
- nBits: Number(header.nBits),
137
- votes: header.votes.join("")
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))
138
291
  })) ?? [];
139
292
  }
140
293
  createOperation(query, options) {
@@ -144,7 +297,7 @@ var ErgoGraphQLProvider = class {
144
297
  }
145
298
  async checkTransaction(signedTransaction) {
146
299
  try {
147
- const response = await this.#checkTx({ signedTransaction });
300
+ const response = await this.#checkTransaction({ signedTransaction });
148
301
  return { success: true, transactionId: response.data.checkTransaction };
149
302
  } catch (e) {
150
303
  return { success: false, message: e.message };
@@ -152,38 +305,60 @@ var ErgoGraphQLProvider = class {
152
305
  }
153
306
  async submitTransaction(signedTransaction) {
154
307
  try {
155
- const response = await this.#sendTx({ signedTransaction });
308
+ const response = await this.#sendTransaction({ signedTransaction });
156
309
  return { success: true, transactionId: response.data.submitTransaction };
157
310
  } catch (e) {
158
311
  return { success: false, message: e.message };
159
312
  }
160
313
  }
161
314
  reduceTransaction() {
162
- throw new common.NotSupportedError(
163
- "Transaction reducing is not supported by ergo-graphql."
164
- );
315
+ throw new common.NotSupportedError("Transaction reducing is not supported by ergo-graphql.");
165
316
  }
166
317
  };
167
- function buildGqlBoxQueryArgs(where) {
168
- const args = {
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) => ({
169
328
  spent: false,
170
- boxIds: merge(where.boxIds, where.boxId),
171
- ergoTrees: merge(where.ergoTrees, where.ergoTree),
329
+ boxIds: where.boxId ? [where.boxId] : void 0,
330
+ ergoTrees: chunk2,
172
331
  ergoTreeTemplateHash: where.templateHash,
173
332
  tokenId: where.tokenId,
174
333
  skip: 0,
175
334
  take: PAGE_SIZE
176
- };
177
- const addresses = merge(where.addresses, where.address);
178
- if (common.some(addresses)) {
179
- const trees = addresses.map(
180
- (address) => typeof address === "string" ? core.ErgoAddress.fromBase58(address).ergoTree : address.ergoTree
181
- );
182
- args.ergoTrees = common.uniq(
183
- common.some(args.ergoTrees) ? args.ergoTrees.concat(trees) : trees
184
- );
185
- }
186
- return args;
335
+ }));
336
+ }
337
+ function buildGqlUnconfirmedTxQueries(where) {
338
+ const addresses = common.uniq(
339
+ [
340
+ merge(where.addresses, where.address)?.map(
341
+ (address) => typeof address === "string" ? address : address.encode()
342
+ ) ?? [],
343
+ merge(where.ergoTrees, where.ergoTree)?.map(
344
+ (tree) => core.ErgoAddress.fromErgoTree(tree).encode()
345
+ ) ?? []
346
+ ].flat()
347
+ );
348
+ return common.chunk(addresses, MAX_ARGS).map((chunk2) => ({
349
+ addresses: chunk2.length ? chunk2 : void 0,
350
+ transactionIds: where.transactionId ? [where.transactionId] : void 0,
351
+ skip: 0,
352
+ take: PAGE_SIZE
353
+ }));
354
+ }
355
+ function buildGqlConfirmedTxQueries(where) {
356
+ return buildGqlUnconfirmedTxQueries(where).map((query) => ({
357
+ ...query,
358
+ headerId: where.headerId,
359
+ minHeight: where.minHeight,
360
+ onlyRelevantOutputs: where.onlyRelevantOutputs
361
+ }));
187
362
  }
188
363
  function merge(array, el) {
189
364
  if (common.isEmpty(array) && common.isUndefined(el)) return;
@@ -197,18 +372,87 @@ function hasMempool(data) {
197
372
  function hasConfirmed(data) {
198
373
  return !!data?.boxes;
199
374
  }
200
- function asConfirmed(confirmed) {
201
- return (box) => ({
202
- ...box,
203
- value: BigInt(box.value),
204
- assets: box.assets.map((asset) => ({
205
- tokenId: asset.tokenId,
206
- amount: BigInt(asset.amount)
375
+ function mapConfirmedBox(box, mapper) {
376
+ const mapped = mapBox(box, mapper);
377
+ mapped.confirmed = true;
378
+ return mapped;
379
+ }
380
+ function mapUnconfirmedBox(box, mapper) {
381
+ const mapped = mapBox(box, mapper);
382
+ mapped.confirmed = false;
383
+ return mapped;
384
+ }
385
+ function mapBox(box, mapper) {
386
+ return {
387
+ boxId: box.boxId,
388
+ transactionId: box.transactionId,
389
+ value: mapper(box.value),
390
+ ergoTree: box.ergoTree,
391
+ assets: box.assets.map((t) => ({ tokenId: t.tokenId, amount: mapper(t.amount) })),
392
+ creationHeight: box.creationHeight,
393
+ additionalRegisters: box.additionalRegisters,
394
+ index: box.index
395
+ };
396
+ }
397
+ function mapUnconfirmedTransaction(tx, mapper) {
398
+ return {
399
+ transactionId: tx.transactionId,
400
+ timestamp: Number(tx.timestamp),
401
+ inputs: tx.inputs.map((i) => ({
402
+ spendingProof: {
403
+ // biome-ignore lint/style/noNonNullAssertion: bad type declarations at '@ergo-graphql/type'
404
+ extension: i.extension,
405
+ // biome-ignore lint/style/noNonNullAssertion: bad type declarations at '@ergo-graphql/type'
406
+ proofBytes: i.proofBytes
407
+ },
408
+ // biome-ignore lint/style/noNonNullAssertion: bad type declarations at '@ergo-graphql/type'
409
+ ...mapBox(i.box, mapper)
207
410
  })),
208
- confirmed
209
- });
411
+ dataInputs: tx.dataInputs.map((di) => ({ boxId: di.boxId })),
412
+ outputs: tx.outputs.map((b) => mapBox(b, mapper)),
413
+ confirmed: false
414
+ };
210
415
  }
416
+ function mapConfirmedTransaction(tx, mapper) {
417
+ return {
418
+ transactionId: tx.transactionId,
419
+ timestamp: Number(tx.timestamp),
420
+ inputs: tx.inputs.map((i) => ({
421
+ spendingProof: {
422
+ // biome-ignore lint/style/noNonNullAssertion: bad type declarations at '@ergo-graphql/type'
423
+ extension: i.extension,
424
+ // biome-ignore lint/style/noNonNullAssertion: bad type declarations at '@ergo-graphql/type'
425
+ proofBytes: i.proofBytes
426
+ },
427
+ // biome-ignore lint/style/noNonNullAssertion: bad type declarations at '@ergo-graphql/type'
428
+ ...mapBox(i.box, mapper)
429
+ })),
430
+ dataInputs: tx.dataInputs.map((di) => ({ boxId: di.boxId })),
431
+ outputs: tx.outputs.map((b) => mapBox(b, mapper)),
432
+ height: tx.inclusionHeight,
433
+ headerId: tx.headerId,
434
+ index: tx.index,
435
+ confirmed: true
436
+ };
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
+ */
211
449
 
212
450
  exports.ErgoGraphQLProvider = ErgoGraphQLProvider;
213
- //# sourceMappingURL=out.js.map
451
+ exports.createGqlOperation = createGqlOperation;
452
+ exports.exponentialRetry = exponentialRetry;
453
+ exports.getOpName = getOpName;
454
+ exports.gql = gql;
455
+ exports.isRequestParam = isRequestParam;
456
+ exports.request = request;
457
+ //# sourceMappingURL=index.js.map
214
458
  //# sourceMappingURL=index.js.map