@fleet-sdk/blockchain-providers 0.8.5 → 0.9.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 +17 -0
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/ergo-graphql/ergoGraphQLProvider.ts +12 -19
- package/src/types/blockchainProvider.ts +8 -15
- package/src/utils/graphql.test-d.ts +3 -5
- package/src/utils/graphql.ts +7 -15
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fleet-sdk/blockchain-providers",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.9.1",
|
4
4
|
"description": "Blockchain data providers",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"module": "./dist/index.mjs",
|
@@ -33,8 +33,8 @@
|
|
33
33
|
"node": ">=18"
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
|
-
"@fleet-sdk/common": "^0.
|
37
|
-
"@fleet-sdk/core": "^0.
|
36
|
+
"@fleet-sdk/common": "^0.9.1",
|
37
|
+
"@fleet-sdk/core": "^0.9.1"
|
38
38
|
},
|
39
39
|
"files": [
|
40
40
|
"src",
|
@@ -1,28 +1,28 @@
|
|
1
1
|
import type {
|
2
2
|
Box as GQLBox,
|
3
|
-
|
3
|
+
UnconfirmedBox as GQLUnconfirmedBox,
|
4
4
|
Header,
|
5
|
+
MempoolTransactionsArgs,
|
5
6
|
QueryBlockHeadersArgs,
|
6
|
-
|
7
|
+
QueryBoxesArgs,
|
7
8
|
QueryTransactionsArgs,
|
8
|
-
|
9
|
-
UnconfirmedTransaction
|
10
|
-
UnconfirmedBox as GQLUnconfirmedBox
|
9
|
+
Transaction,
|
10
|
+
UnconfirmedTransaction
|
11
11
|
} from "@ergo-graphql/types";
|
12
12
|
import {
|
13
13
|
type Base58String,
|
14
14
|
type BlockHeader,
|
15
15
|
type HexString,
|
16
|
+
NotSupportedError,
|
16
17
|
type SignedTransaction,
|
18
|
+
chunk,
|
17
19
|
ensureDefaults,
|
18
20
|
isEmpty,
|
19
21
|
isUndefined,
|
20
|
-
NotSupportedError,
|
21
22
|
orderBy,
|
22
23
|
some,
|
23
24
|
uniq,
|
24
|
-
uniqBy
|
25
|
-
chunk
|
25
|
+
uniqBy
|
26
26
|
} from "@fleet-sdk/common";
|
27
27
|
import { ErgoAddress } from "@fleet-sdk/core";
|
28
28
|
import { hex } from "@fleet-sdk/crypto";
|
@@ -32,12 +32,12 @@ import type {
|
|
32
32
|
ChainProviderBox,
|
33
33
|
ChainProviderConfirmedTransaction,
|
34
34
|
ChainProviderUnconfirmedTransaction,
|
35
|
+
ConfirmedTransactionWhere,
|
35
36
|
HeaderQuery,
|
36
37
|
IBlockchainProvider,
|
37
38
|
TransactionEvaluationResult,
|
38
39
|
TransactionQuery,
|
39
40
|
TransactionReductionResult,
|
40
|
-
ConfirmedTransactionWhere,
|
41
41
|
UnconfirmedTransactionWhere
|
42
42
|
} from "../types/blockchainProvider";
|
43
43
|
import {
|
@@ -79,10 +79,7 @@ export type GraphQLUnconfirmedTransactionWhere = UnconfirmedTransactionWhere & {
|
|
79
79
|
};
|
80
80
|
|
81
81
|
export type GraphQLBoxQuery = BoxQuery<GraphQLBoxWhere>;
|
82
|
-
export type ErgoGraphQLRequestOptions = Omit<
|
83
|
-
GraphQLRequestOptions,
|
84
|
-
"throwOnNonNetworkErrors"
|
85
|
-
>;
|
82
|
+
export type ErgoGraphQLRequestOptions = Omit<GraphQLRequestOptions, "throwOnNonNetworkErrors">;
|
86
83
|
|
87
84
|
type ConfirmedBoxesResponse = { boxes: GQLBox[] };
|
88
85
|
type UnconfirmedBoxesResponse = { mempool: { boxes: GQLBox[] } };
|
@@ -154,9 +151,7 @@ export class ErgoGraphQLProvider<I = bigint> implements IBlockchainProvider<I> {
|
|
154
151
|
return this as unknown as ErgoGraphQLProvider<M>;
|
155
152
|
}
|
156
153
|
|
157
|
-
async *streamBoxes(
|
158
|
-
query: GraphQLBoxQuery & SkipAndTake
|
159
|
-
): AsyncGenerator<ChainProviderBox<I>[]> {
|
154
|
+
async *streamBoxes(query: GraphQLBoxQuery & SkipAndTake): AsyncGenerator<ChainProviderBox<I>[]> {
|
160
155
|
if (isEmpty(query.where)) {
|
161
156
|
throw new Error("Cannot fetch unspent boxes without a where clause.");
|
162
157
|
}
|
@@ -268,9 +263,7 @@ export class ErgoGraphQLProvider<I = bigint> implements IBlockchainProvider<I> {
|
|
268
263
|
while (keepFetching) {
|
269
264
|
const response = await this.#getConfirmedTransactions(query);
|
270
265
|
if (some(response.data?.transactions)) {
|
271
|
-
yield response.data.transactions.map((t) =>
|
272
|
-
mapConfirmedTransaction(t, this.#biMapper)
|
273
|
-
);
|
266
|
+
yield response.data.transactions.map((t) => mapConfirmedTransaction(t, this.#biMapper));
|
274
267
|
}
|
275
268
|
|
276
269
|
keepFetching = response.data?.transactions?.length === pageSize;
|
@@ -100,12 +100,11 @@ export type ChainProviderUnconfirmedTransaction<T> = {
|
|
100
100
|
timestamp: number;
|
101
101
|
};
|
102
102
|
|
103
|
-
export type ChainProviderConfirmedTransaction<T> =
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
};
|
103
|
+
export type ChainProviderConfirmedTransaction<T> = ChainProviderUnconfirmedTransaction<T> & {
|
104
|
+
height: number;
|
105
|
+
index: number;
|
106
|
+
headerId: HexString;
|
107
|
+
};
|
109
108
|
|
110
109
|
export type TransactionEvaluationError = {
|
111
110
|
success: false;
|
@@ -122,12 +121,8 @@ export type TransactionReductionSuccess = {
|
|
122
121
|
reducedTransaction: HexString;
|
123
122
|
};
|
124
123
|
|
125
|
-
export type TransactionEvaluationResult =
|
126
|
-
|
127
|
-
| TransactionEvaluationSuccess;
|
128
|
-
export type TransactionReductionResult =
|
129
|
-
| TransactionEvaluationError
|
130
|
-
| TransactionReductionSuccess;
|
124
|
+
export type TransactionEvaluationResult = TransactionEvaluationError | TransactionEvaluationSuccess;
|
125
|
+
export type TransactionReductionResult = TransactionEvaluationError | TransactionReductionSuccess;
|
131
126
|
|
132
127
|
/**
|
133
128
|
* Represents a blockchain provider that can interact with the blockchain.
|
@@ -190,7 +185,5 @@ export interface IBlockchainProvider<I> {
|
|
190
185
|
/**
|
191
186
|
* Evaluate a transaction and return Base16-encoded evaluation result.
|
192
187
|
*/
|
193
|
-
reduceTransaction(
|
194
|
-
transaction: UnsignedTransaction
|
195
|
-
): Promise<TransactionReductionResult>;
|
188
|
+
reduceTransaction(transaction: UnsignedTransaction): Promise<TransactionReductionResult>;
|
196
189
|
}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { describe, expectTypeOf, it } from "vitest";
|
2
2
|
import {
|
3
|
-
createGqlOperation,
|
4
3
|
type GraphQLOperation,
|
5
4
|
type GraphQLResponse,
|
6
5
|
type GraphQLSuccessResponse,
|
7
|
-
type GraphQLVariables
|
6
|
+
type GraphQLVariables,
|
7
|
+
createGqlOperation
|
8
8
|
} from "./graphql";
|
9
9
|
|
10
10
|
describe("createGqlOperation() types", () => {
|
@@ -24,8 +24,6 @@ describe("createGqlOperation() types", () => {
|
|
24
24
|
throwOnNonNetworkErrors: false,
|
25
25
|
url
|
26
26
|
});
|
27
|
-
expectTypeOf(notThrowable).toMatchTypeOf<
|
28
|
-
GraphQLOperation<GraphQLResponse, GraphQLVariables>
|
29
|
-
>();
|
27
|
+
expectTypeOf(notThrowable).toMatchTypeOf<GraphQLOperation<GraphQLResponse, GraphQLVariables>>();
|
30
28
|
});
|
31
29
|
});
|
package/src/utils/graphql.ts
CHANGED
@@ -30,19 +30,17 @@ export interface GraphQLErrorResponse {
|
|
30
30
|
errors: GraphQLError[];
|
31
31
|
}
|
32
32
|
|
33
|
-
export type GraphQLResponse<T = unknown> =
|
34
|
-
| GraphQLSuccessResponse<T>
|
35
|
-
| GraphQLErrorResponse;
|
33
|
+
export type GraphQLResponse<T = unknown> = GraphQLSuccessResponse<T> | GraphQLErrorResponse;
|
36
34
|
|
37
35
|
export type GraphQLOperation<R extends GraphQLResponse, V extends GraphQLVariables> = (
|
38
36
|
variables?: V,
|
39
37
|
url?: string
|
40
38
|
) => Promise<R>;
|
41
39
|
|
42
|
-
export type GraphQLRequiredUrlOperation<
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
export type GraphQLRequiredUrlOperation<R extends GraphQLResponse, V extends GraphQLVariables> = (
|
41
|
+
variables: V | undefined,
|
42
|
+
url: string
|
43
|
+
) => Promise<R>;
|
46
44
|
|
47
45
|
interface RequestParams {
|
48
46
|
operationName?: string | null;
|
@@ -77,9 +75,7 @@ export function createGqlOperation<R, V extends GraphQLVariables = GraphQLVariab
|
|
77
75
|
export function createGqlOperation<R, V extends GraphQLVariables = GraphQLVariables>(
|
78
76
|
query: string,
|
79
77
|
options?: GraphQLRequestOptions
|
80
|
-
):
|
81
|
-
| GraphQLOperation<GraphQLResponse<R>, V>
|
82
|
-
| GraphQLRequiredUrlOperation<GraphQLResponse<R>, V> {
|
78
|
+
): GraphQLOperation<GraphQLResponse<R>, V> | GraphQLRequiredUrlOperation<GraphQLResponse<R>, V> {
|
83
79
|
return async (variables?: V, url?: string): Promise<GraphQLResponse<R>> => {
|
84
80
|
url = url ?? options?.url;
|
85
81
|
if (!url) throw new Error("URL is required");
|
@@ -98,11 +94,7 @@ export function createGqlOperation<R, V extends GraphQLVariables = GraphQLVariab
|
|
98
94
|
}
|
99
95
|
});
|
100
96
|
|
101
|
-
if (
|
102
|
-
options?.throwOnNonNetworkErrors &&
|
103
|
-
some(response.errors) &&
|
104
|
-
isEmpty(response.data)
|
105
|
-
) {
|
97
|
+
if (options?.throwOnNonNetworkErrors && some(response.errors) && isEmpty(response.data)) {
|
106
98
|
const msg = response.errors[0].message;
|
107
99
|
throw new BlockchainProviderError(msg, { cause: response.errors });
|
108
100
|
}
|