@solana/rpc-graphql 2.0.0-experimental.dd2096e → 2.0.0-experimental.e15a66f
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.browser.cjs +673 -353
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +674 -354
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +674 -354
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +673 -353
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +674 -354
- package/dist/index.node.js.map +1 -1
- package/dist/types/context.d.ts +15 -3
- package/dist/types/context.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/loaders/account.d.ts +12 -3
- package/dist/types/loaders/account.d.ts.map +1 -1
- package/dist/types/loaders/block.d.ts +1 -2
- package/dist/types/loaders/block.d.ts.map +1 -1
- package/dist/types/loaders/coalescer.d.ts +48 -0
- package/dist/types/loaders/coalescer.d.ts.map +1 -0
- package/dist/types/loaders/index.d.ts +1 -1
- package/dist/types/loaders/index.d.ts.map +1 -1
- package/dist/types/loaders/loader.d.ts +24 -9
- package/dist/types/loaders/loader.d.ts.map +1 -1
- package/dist/types/loaders/program-accounts.d.ts +6 -3
- package/dist/types/loaders/program-accounts.d.ts.map +1 -1
- package/dist/types/loaders/transaction.d.ts +1 -2
- package/dist/types/loaders/transaction.d.ts.map +1 -1
- package/dist/types/resolvers/account.d.ts +160 -42
- package/dist/types/resolvers/account.d.ts.map +1 -1
- package/dist/types/resolvers/block.d.ts +1 -1
- package/dist/types/resolvers/block.d.ts.map +1 -1
- package/dist/types/resolvers/index.d.ts.map +1 -1
- package/dist/types/resolvers/instruction.d.ts +1275 -255
- package/dist/types/resolvers/instruction.d.ts.map +1 -1
- package/dist/types/resolvers/program-accounts.d.ts +12 -3
- package/dist/types/resolvers/program-accounts.d.ts.map +1 -1
- package/dist/types/resolvers/resolve-info/account.d.ts +15 -0
- package/dist/types/resolvers/resolve-info/account.d.ts.map +1 -0
- package/dist/types/resolvers/resolve-info/index.d.ts +4 -0
- package/dist/types/resolvers/resolve-info/index.d.ts.map +1 -0
- package/dist/types/resolvers/resolve-info/program-accounts.d.ts +20 -0
- package/dist/types/resolvers/resolve-info/program-accounts.d.ts.map +1 -0
- package/dist/types/resolvers/resolve-info/visitor.d.ts +18 -0
- package/dist/types/resolvers/resolve-info/visitor.d.ts.map +1 -0
- package/dist/types/resolvers/transaction.d.ts +1 -1
- package/dist/types/resolvers/transaction.d.ts.map +1 -1
- package/dist/types/resolvers/types.d.ts +79 -4
- package/dist/types/resolvers/types.d.ts.map +1 -1
- package/dist/types/schema/account.d.ts +1 -1
- package/dist/types/schema/account.d.ts.map +1 -1
- package/dist/types/schema/index.d.ts.map +1 -1
- package/dist/types/schema/root.d.ts +1 -1
- package/dist/types/schema/root.d.ts.map +1 -1
- package/dist/types/schema/types.d.ts +2 -0
- package/dist/types/schema/types.d.ts.map +1 -0
- package/package.json +11 -38
- package/dist/types/resolvers/resolve-info.d.ts +0 -3
- package/dist/types/resolvers/resolve-info.d.ts.map +0 -1
- package/dist/types/resolvers/scalars.d.ts +0 -44
- package/dist/types/resolvers/scalars.d.ts.map +0 -1
- package/dist/types/schema/common/inputs.d.ts +0 -2
- package/dist/types/schema/common/inputs.d.ts.map +0 -1
- package/dist/types/schema/common/scalars.d.ts +0 -2
- package/dist/types/schema/common/scalars.d.ts.map +0 -1
- package/dist/types/schema/common/types.d.ts +0 -2
- package/dist/types/schema/common/types.d.ts.map +0 -1
package/dist/index.browser.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var schema = require('@graphql-tools/schema');
|
|
4
4
|
var graphql = require('graphql');
|
|
5
|
+
var codecsStrings = require('@solana/codecs-strings');
|
|
5
6
|
var DataLoader = require('dataloader');
|
|
6
7
|
var stringify = require('json-stable-stringify');
|
|
7
8
|
|
|
@@ -19,40 +20,225 @@ function replacer(_, value) {
|
|
|
19
20
|
}
|
|
20
21
|
var cacheKeyFn = (obj) => stringify__default.default(obj, { replacer });
|
|
21
22
|
|
|
23
|
+
// src/loaders/coalescer.ts
|
|
24
|
+
var hashOmit = (args, omit) => {
|
|
25
|
+
const argsObj = {};
|
|
26
|
+
for (const [key, value] of Object.entries(args)) {
|
|
27
|
+
if (!omit.includes(key)) {
|
|
28
|
+
argsObj[key] = value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return cacheKeyFn(argsObj);
|
|
32
|
+
};
|
|
33
|
+
function buildCoalescedFetchesByArgsHashWithDataSlice(toFetchMap, maxDataSliceByteRange) {
|
|
34
|
+
const fetchesByArgsHash = {};
|
|
35
|
+
const orphanedFetches = {};
|
|
36
|
+
Object.entries(toFetchMap).forEach(([address, toFetch]) => {
|
|
37
|
+
toFetch.forEach(({ args, promiseCallback }) => {
|
|
38
|
+
if (!args.encoding) {
|
|
39
|
+
const toFetch2 = orphanedFetches[address] ||= [];
|
|
40
|
+
toFetch2.push({ args, promiseCallback });
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (args.encoding != "base64+zstd" && args.dataSlice) {
|
|
44
|
+
const r = args.dataSlice;
|
|
45
|
+
for (const { fetches: fetchAddresses, args: fetchArgs } of Object.values(fetchesByArgsHash)) {
|
|
46
|
+
const addCallbackWithDataSlice = (updateDataSlice) => {
|
|
47
|
+
const { callbacks: promiseCallbacksForAddress2 } = fetchAddresses[address] ||= {
|
|
48
|
+
callbacks: []
|
|
49
|
+
};
|
|
50
|
+
promiseCallbacksForAddress2.push({
|
|
51
|
+
callback: promiseCallback,
|
|
52
|
+
dataSlice: args.dataSlice ?? null
|
|
53
|
+
});
|
|
54
|
+
if (fetchArgs.dataSlice && updateDataSlice) {
|
|
55
|
+
fetchArgs.dataSlice = updateDataSlice;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
if (hashOmit(args, ["dataSlice"]) === hashOmit(fetchArgs, ["dataSlice"])) {
|
|
59
|
+
if (fetchArgs.dataSlice) {
|
|
60
|
+
const g = fetchArgs.dataSlice;
|
|
61
|
+
if (r.offset <= g.offset && g.offset - r.offset + r.length <= maxDataSliceByteRange) {
|
|
62
|
+
const length = Math.max(r.length, g.offset + g.length - r.offset);
|
|
63
|
+
const offset = r.offset;
|
|
64
|
+
addCallbackWithDataSlice({ length, offset });
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (r.offset >= g.offset && r.offset - g.offset + g.length <= maxDataSliceByteRange) {
|
|
68
|
+
const length = Math.max(g.length, r.offset + r.length - g.offset);
|
|
69
|
+
const offset = g.offset;
|
|
70
|
+
addCallbackWithDataSlice({ length, offset });
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
const { length, offset } = r;
|
|
75
|
+
addCallbackWithDataSlice({ length, offset });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const argsHash = hashOmit(args, []);
|
|
82
|
+
const accountFetches = fetchesByArgsHash[argsHash] ||= {
|
|
83
|
+
args,
|
|
84
|
+
fetches: {}
|
|
85
|
+
};
|
|
86
|
+
const { callbacks: promiseCallbacksForAddress } = accountFetches.fetches[address] ||= {
|
|
87
|
+
callbacks: []
|
|
88
|
+
};
|
|
89
|
+
promiseCallbacksForAddress.push({ callback: promiseCallback, dataSlice: args.dataSlice ?? null });
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
Object.entries(orphanedFetches).forEach(([address, toFetch]) => {
|
|
93
|
+
toFetch.forEach(({ args: orphanedArgs, promiseCallback: orphanPromiseCallback }) => {
|
|
94
|
+
if (Object.keys(fetchesByArgsHash).length !== 0) {
|
|
95
|
+
for (const { fetches, args: args2 } of Object.values(fetchesByArgsHash)) {
|
|
96
|
+
if (hashOmit(orphanedArgs, ["encoding", "dataSlice"]) === hashOmit(args2, ["encoding", "dataSlice"])) {
|
|
97
|
+
const { callbacks: promiseCallbacksForAddress2 } = fetches[address] ||= {
|
|
98
|
+
callbacks: []
|
|
99
|
+
};
|
|
100
|
+
promiseCallbacksForAddress2.push({ callback: orphanPromiseCallback });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const args = { ...orphanedArgs, encoding: "base64" };
|
|
106
|
+
const argsHash = hashOmit(args, []);
|
|
107
|
+
const accountFetches = fetchesByArgsHash[argsHash] ||= {
|
|
108
|
+
args,
|
|
109
|
+
fetches: {}
|
|
110
|
+
};
|
|
111
|
+
const { callbacks: promiseCallbacksForAddress } = accountFetches.fetches[address] ||= {
|
|
112
|
+
callbacks: []
|
|
113
|
+
};
|
|
114
|
+
promiseCallbacksForAddress.push({ callback: orphanPromiseCallback });
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
return fetchesByArgsHash;
|
|
118
|
+
}
|
|
119
|
+
|
|
22
120
|
// src/loaders/account.ts
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
encoding
|
|
35
|
-
|
|
36
|
-
|
|
121
|
+
function getCodec(encoding) {
|
|
122
|
+
switch (encoding) {
|
|
123
|
+
case "base58":
|
|
124
|
+
return codecsStrings.getBase58Codec();
|
|
125
|
+
default:
|
|
126
|
+
return codecsStrings.getBase64Codec();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function sliceData(account, dataSlice, masterDataSlice) {
|
|
130
|
+
if (dataSlice) {
|
|
131
|
+
const masterOffset = masterDataSlice ? masterDataSlice.offset : 0;
|
|
132
|
+
const slicedData = (data, encoding) => {
|
|
133
|
+
if (encoding === "base64+zstd") {
|
|
134
|
+
return data;
|
|
135
|
+
}
|
|
136
|
+
const { offset, length } = dataSlice;
|
|
137
|
+
const trueOffset = offset - masterOffset;
|
|
138
|
+
const codec = getCodec(encoding);
|
|
139
|
+
return codec.decode(codec.encode(data).slice(trueOffset, trueOffset + length));
|
|
140
|
+
};
|
|
141
|
+
if (Array.isArray(account.data)) {
|
|
142
|
+
const [data, encoding] = account.data;
|
|
143
|
+
return {
|
|
144
|
+
...account,
|
|
145
|
+
data: [slicedData(data, encoding), encoding]
|
|
146
|
+
};
|
|
147
|
+
} else if (typeof account.data === "string") {
|
|
148
|
+
const data = account.data;
|
|
149
|
+
return {
|
|
150
|
+
...account,
|
|
151
|
+
data: slicedData(data, "base58")
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return account;
|
|
37
156
|
}
|
|
38
157
|
async function loadAccount(rpc, { address, ...config }) {
|
|
39
158
|
return await rpc.getAccountInfo(address, config).send().then((res) => res.value);
|
|
40
159
|
}
|
|
41
|
-
function
|
|
160
|
+
async function loadMultipleAccounts(rpc, { addresses, ...config }) {
|
|
161
|
+
return await rpc.getMultipleAccounts(addresses, config).send().then((res) => res.value);
|
|
162
|
+
}
|
|
163
|
+
function createAccountBatchLoadFn(rpc, config) {
|
|
42
164
|
const resolveAccountUsingRpc = loadAccount.bind(null, rpc);
|
|
165
|
+
const resolveMultipleAccountsUsingRpc = loadMultipleAccounts.bind(null, rpc);
|
|
43
166
|
return async (accountQueryArgs) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
167
|
+
const accountsToFetch = {};
|
|
168
|
+
try {
|
|
169
|
+
return Promise.all(
|
|
170
|
+
accountQueryArgs.map(
|
|
171
|
+
({ address, ...args }) => new Promise((resolve, reject) => {
|
|
172
|
+
const accountRecords = accountsToFetch[address] ||= [];
|
|
173
|
+
if (!args.commitment) {
|
|
174
|
+
args.commitment = "confirmed";
|
|
175
|
+
}
|
|
176
|
+
accountRecords.push({ args, promiseCallback: { reject, resolve } });
|
|
177
|
+
})
|
|
178
|
+
)
|
|
179
|
+
);
|
|
180
|
+
} finally {
|
|
181
|
+
const { maxDataSliceByteRange, maxMultipleAccountsBatchSize } = config;
|
|
182
|
+
const accountFetchesByArgsHash = buildCoalescedFetchesByArgsHashWithDataSlice(
|
|
183
|
+
accountsToFetch,
|
|
184
|
+
maxDataSliceByteRange
|
|
185
|
+
);
|
|
186
|
+
Object.values(accountFetchesByArgsHash).map(({ args, fetches: addressCallbacks }) => {
|
|
187
|
+
const addresses = Object.keys(addressCallbacks);
|
|
188
|
+
if (addresses.length === 1) {
|
|
189
|
+
const address = addresses[0];
|
|
190
|
+
return Array.from({ length: 1 }, async () => {
|
|
191
|
+
try {
|
|
192
|
+
const result = await resolveAccountUsingRpc({ address, ...args });
|
|
193
|
+
addressCallbacks[address].callbacks.forEach(({ callback, dataSlice }) => {
|
|
194
|
+
callback.resolve(sliceData(result, dataSlice, args.dataSlice));
|
|
195
|
+
});
|
|
196
|
+
} catch (e) {
|
|
197
|
+
addressCallbacks[address].callbacks.forEach(({ callback }) => {
|
|
198
|
+
callback.reject(e);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
} else {
|
|
203
|
+
return Array.from(
|
|
204
|
+
{ length: Math.ceil(addresses.length / maxMultipleAccountsBatchSize) },
|
|
205
|
+
async (_, ii) => {
|
|
206
|
+
const startIndex = ii * maxMultipleAccountsBatchSize;
|
|
207
|
+
const endIndex = startIndex + maxMultipleAccountsBatchSize;
|
|
208
|
+
const chunk = addresses.slice(startIndex, endIndex);
|
|
209
|
+
try {
|
|
210
|
+
const results = await resolveMultipleAccountsUsingRpc({
|
|
211
|
+
addresses: chunk,
|
|
212
|
+
...args
|
|
213
|
+
});
|
|
214
|
+
chunk.forEach((address, ii2) => {
|
|
215
|
+
const result = results[ii2];
|
|
216
|
+
addressCallbacks[address].callbacks.forEach(({ callback, dataSlice }) => {
|
|
217
|
+
callback.resolve(sliceData(result, dataSlice, args.dataSlice));
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
} catch (e) {
|
|
221
|
+
chunk.forEach((address) => {
|
|
222
|
+
addressCallbacks[address].callbacks.forEach(({ callback }) => {
|
|
223
|
+
callback.reject(e);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
47
232
|
};
|
|
48
233
|
}
|
|
49
|
-
function createAccountLoader(rpc) {
|
|
50
|
-
const loader = new DataLoader__default.default(createAccountBatchLoadFn(rpc), { cacheKeyFn });
|
|
234
|
+
function createAccountLoader(rpc, config) {
|
|
235
|
+
const loader = new DataLoader__default.default(createAccountBatchLoadFn(rpc, config), { cacheKeyFn });
|
|
51
236
|
return {
|
|
52
|
-
load: async (args) => loader.load(
|
|
237
|
+
load: async (args) => loader.load(args),
|
|
238
|
+
loadMany: async (args) => loader.loadMany(args)
|
|
53
239
|
};
|
|
54
240
|
}
|
|
55
|
-
function
|
|
241
|
+
function applyDefaultArgs({
|
|
56
242
|
slot,
|
|
57
243
|
commitment,
|
|
58
244
|
encoding = "jsonParsed",
|
|
@@ -72,61 +258,75 @@ function applyDefaultArgs2({
|
|
|
72
258
|
async function loadBlock(rpc, { slot, ...config }) {
|
|
73
259
|
return await rpc.getBlock(
|
|
74
260
|
slot,
|
|
75
|
-
// @ts-expect-error FIX ME: https://github.com/
|
|
261
|
+
// @ts-expect-error FIX ME: https://github.com/microsoft/TypeScript/issues/43187
|
|
76
262
|
config
|
|
77
263
|
).send();
|
|
78
264
|
}
|
|
79
265
|
function createBlockBatchLoadFn(rpc) {
|
|
80
266
|
const resolveBlockUsingRpc = loadBlock.bind(null, rpc);
|
|
81
|
-
return async (blockQueryArgs) =>
|
|
82
|
-
return await Promise.all(blockQueryArgs.map(async (args) => await resolveBlockUsingRpc(applyDefaultArgs2(args))));
|
|
83
|
-
};
|
|
267
|
+
return async (blockQueryArgs) => Promise.all(blockQueryArgs.map(async (args) => resolveBlockUsingRpc(applyDefaultArgs(args))));
|
|
84
268
|
}
|
|
85
269
|
function createBlockLoader(rpc) {
|
|
86
270
|
const loader = new DataLoader__default.default(createBlockBatchLoadFn(rpc), { cacheKeyFn });
|
|
87
271
|
return {
|
|
88
|
-
load: async (args) => loader.load(
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
function applyDefaultArgs3({
|
|
92
|
-
commitment,
|
|
93
|
-
dataSlice,
|
|
94
|
-
encoding = "jsonParsed",
|
|
95
|
-
filters,
|
|
96
|
-
minContextSlot,
|
|
97
|
-
programAddress
|
|
98
|
-
}) {
|
|
99
|
-
return {
|
|
100
|
-
commitment,
|
|
101
|
-
dataSlice,
|
|
102
|
-
encoding,
|
|
103
|
-
filters,
|
|
104
|
-
minContextSlot,
|
|
105
|
-
programAddress
|
|
272
|
+
load: async (args) => loader.load(applyDefaultArgs(args)),
|
|
273
|
+
loadMany: async (args) => loader.loadMany(args.map(applyDefaultArgs))
|
|
106
274
|
};
|
|
107
275
|
}
|
|
108
276
|
async function loadProgramAccounts(rpc, { programAddress, ...config }) {
|
|
109
277
|
return await rpc.getProgramAccounts(
|
|
110
278
|
programAddress,
|
|
111
|
-
// @ts-expect-error FIX ME: https://github.com/
|
|
279
|
+
// @ts-expect-error FIX ME: https://github.com/microsoft/TypeScript/issues/43187
|
|
112
280
|
config
|
|
113
281
|
).send();
|
|
114
282
|
}
|
|
115
|
-
function createProgramAccountsBatchLoadFn(rpc) {
|
|
283
|
+
function createProgramAccountsBatchLoadFn(rpc, config) {
|
|
116
284
|
const resolveProgramAccountsUsingRpc = loadProgramAccounts.bind(null, rpc);
|
|
117
|
-
return async (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
285
|
+
return async (accountQueryArgs) => {
|
|
286
|
+
const programAccountsToFetch = {};
|
|
287
|
+
try {
|
|
288
|
+
return Promise.all(accountQueryArgs.map(
|
|
289
|
+
({ programAddress, ...args }) => new Promise((resolve, reject) => {
|
|
290
|
+
const accountRecords = programAccountsToFetch[programAddress] ||= [];
|
|
291
|
+
if (!args.commitment) {
|
|
292
|
+
args.commitment = "confirmed";
|
|
293
|
+
}
|
|
294
|
+
accountRecords.push({ args, promiseCallback: { reject, resolve } });
|
|
295
|
+
})
|
|
296
|
+
));
|
|
297
|
+
} finally {
|
|
298
|
+
const { maxDataSliceByteRange } = config;
|
|
299
|
+
const programAccountsFetchesByArgsHash = buildCoalescedFetchesByArgsHashWithDataSlice(programAccountsToFetch, maxDataSliceByteRange);
|
|
300
|
+
Object.values(programAccountsFetchesByArgsHash).map(({ args, fetches: programAddressCallbacks }) => {
|
|
301
|
+
return Object.entries(programAddressCallbacks).map(([programAddress, { callbacks }]) => {
|
|
302
|
+
return Array.from({ length: 1 }, async () => {
|
|
303
|
+
try {
|
|
304
|
+
const result = await resolveProgramAccountsUsingRpc({
|
|
305
|
+
programAddress,
|
|
306
|
+
...args
|
|
307
|
+
});
|
|
308
|
+
callbacks.forEach(({ callback, dataSlice }) => {
|
|
309
|
+
callback.resolve(sliceData(result, dataSlice, args.dataSlice));
|
|
310
|
+
});
|
|
311
|
+
} catch (e) {
|
|
312
|
+
callbacks.forEach(({ callback }) => {
|
|
313
|
+
callback.reject(e);
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
}
|
|
121
320
|
};
|
|
122
321
|
}
|
|
123
|
-
function createProgramAccountsLoader(rpc) {
|
|
124
|
-
const loader = new DataLoader__default.default(createProgramAccountsBatchLoadFn(rpc), { cacheKeyFn });
|
|
322
|
+
function createProgramAccountsLoader(rpc, config) {
|
|
323
|
+
const loader = new DataLoader__default.default(createProgramAccountsBatchLoadFn(rpc, config), { cacheKeyFn });
|
|
125
324
|
return {
|
|
126
|
-
load: async (args) => loader.load(
|
|
325
|
+
load: async (args) => loader.load(args),
|
|
326
|
+
loadMany: async (args) => loader.loadMany(args)
|
|
127
327
|
};
|
|
128
328
|
}
|
|
129
|
-
function
|
|
329
|
+
function applyDefaultArgs2({
|
|
130
330
|
commitment,
|
|
131
331
|
encoding = "jsonParsed",
|
|
132
332
|
signature
|
|
@@ -140,170 +340,280 @@ function applyDefaultArgs4({
|
|
|
140
340
|
async function loadTransaction(rpc, { signature, ...config }) {
|
|
141
341
|
return await rpc.getTransaction(
|
|
142
342
|
signature,
|
|
143
|
-
// @ts-expect-error FIX ME: https://github.com/
|
|
343
|
+
// @ts-expect-error FIX ME: https://github.com/microsoft/TypeScript/issues/43187
|
|
144
344
|
config
|
|
145
345
|
).send();
|
|
146
346
|
}
|
|
147
347
|
function createTransactionBatchLoadFn(rpc) {
|
|
148
348
|
const resolveTransactionUsingRpc = loadTransaction.bind(null, rpc);
|
|
149
|
-
return async (transactionQueryArgs) =>
|
|
150
|
-
return await Promise.all(
|
|
151
|
-
transactionQueryArgs.map(async (args) => await resolveTransactionUsingRpc(applyDefaultArgs4(args)))
|
|
152
|
-
);
|
|
153
|
-
};
|
|
349
|
+
return async (transactionQueryArgs) => Promise.all(transactionQueryArgs.map(async (args) => resolveTransactionUsingRpc(applyDefaultArgs2(args))));
|
|
154
350
|
}
|
|
155
351
|
function createTransactionLoader(rpc) {
|
|
156
352
|
const loader = new DataLoader__default.default(createTransactionBatchLoadFn(rpc), { cacheKeyFn });
|
|
157
353
|
return {
|
|
158
|
-
load: async (args) => loader.load(
|
|
354
|
+
load: async (args) => loader.load(applyDefaultArgs2(args)),
|
|
355
|
+
loadMany: async (args) => loader.loadMany(args.map(applyDefaultArgs2))
|
|
159
356
|
};
|
|
160
357
|
}
|
|
161
358
|
|
|
162
359
|
// src/context.ts
|
|
163
|
-
function createSolanaGraphQLContext(rpc) {
|
|
360
|
+
function createSolanaGraphQLContext(rpc, config) {
|
|
164
361
|
return {
|
|
165
362
|
loaders: {
|
|
166
|
-
account: createAccountLoader(rpc),
|
|
363
|
+
account: createAccountLoader(rpc, config),
|
|
167
364
|
block: createBlockLoader(rpc),
|
|
168
|
-
programAccounts: createProgramAccountsLoader(rpc),
|
|
365
|
+
programAccounts: createProgramAccountsLoader(rpc, config),
|
|
169
366
|
transaction: createTransactionLoader(rpc)
|
|
170
367
|
}
|
|
171
368
|
};
|
|
172
369
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (
|
|
180
|
-
return
|
|
370
|
+
function injectableRootVisitor(info, rootNode, operations) {
|
|
371
|
+
const { fieldNodes } = info;
|
|
372
|
+
const root = rootNode ?? fieldNodes[0];
|
|
373
|
+
const parentIsRoot = (ancestors) => (Array.isArray(ancestors) ? ancestors[0] : ancestors) === root;
|
|
374
|
+
graphql.visit(root, {
|
|
375
|
+
Field(node, key, parent, path, ancestors) {
|
|
376
|
+
if (!parentIsRoot(ancestors))
|
|
377
|
+
return;
|
|
378
|
+
return operations.fieldNodeOperation(info, node, key, parent, path, ancestors);
|
|
379
|
+
},
|
|
380
|
+
FragmentSpread(node, key, parent, path, ancestors) {
|
|
381
|
+
const fragmentDefinition = info.fragments[node.name.value];
|
|
382
|
+
return operations.fragmentSpreadNodeOperation(info, fragmentDefinition, node, key, parent, path, ancestors);
|
|
383
|
+
},
|
|
384
|
+
InlineFragment(node, key, parent, path, ancestors) {
|
|
385
|
+
if (!parentIsRoot(ancestors))
|
|
386
|
+
return;
|
|
387
|
+
return operations.inlineFragmentNodeOperation(info, node, key, parent, path, ancestors);
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
function onlyFieldsRequested(fieldNames, info, rootNode) {
|
|
392
|
+
let onlyFieldsRequested2 = true;
|
|
393
|
+
function checkFieldsWithVisitor(root) {
|
|
394
|
+
injectableRootVisitor(info, root, {
|
|
395
|
+
fieldNodeOperation(_info, node) {
|
|
396
|
+
onlyFieldsRequested2 = fieldNames.includes(node.name.value);
|
|
397
|
+
if (!onlyFieldsRequested2) {
|
|
398
|
+
return graphql.BREAK;
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
fragmentSpreadNodeOperation(_info, fragment) {
|
|
402
|
+
checkFieldsWithVisitor(fragment);
|
|
403
|
+
},
|
|
404
|
+
inlineFragmentNodeOperation(_info, node) {
|
|
405
|
+
checkFieldsWithVisitor(node);
|
|
181
406
|
}
|
|
182
|
-
return null;
|
|
183
407
|
});
|
|
184
|
-
|
|
185
|
-
|
|
408
|
+
}
|
|
409
|
+
checkFieldsWithVisitor(rootNode ?? null);
|
|
410
|
+
return onlyFieldsRequested2;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// src/resolvers/resolve-info/account.ts
|
|
414
|
+
function findArgumentNodeByName(argumentNodes, name) {
|
|
415
|
+
return argumentNodes.find((argumentNode) => argumentNode.name.value === name);
|
|
416
|
+
}
|
|
417
|
+
function parseAccountEncodingArgument(argumentNodes, variableValues) {
|
|
418
|
+
const argumentNode = findArgumentNodeByName(argumentNodes, "encoding");
|
|
419
|
+
if (argumentNode) {
|
|
420
|
+
if (argumentNode.value.kind === "EnumValue") {
|
|
421
|
+
if (argumentNode.value.value === "BASE_58") {
|
|
422
|
+
return "base58";
|
|
423
|
+
}
|
|
424
|
+
if (argumentNode.value.value === "BASE_64") {
|
|
425
|
+
return "base64";
|
|
426
|
+
}
|
|
427
|
+
if (argumentNode.value.value === "BASE_64_ZSTD") {
|
|
428
|
+
return "base64+zstd";
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
if (argumentNode.value.kind === "Variable") {
|
|
432
|
+
return variableValues[argumentNode.value.name.value];
|
|
433
|
+
}
|
|
434
|
+
} else {
|
|
435
|
+
return void 0;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
function parseAccountDataSliceArgument(argumentNodes, variableValues) {
|
|
439
|
+
const argumentNode = findArgumentNodeByName(argumentNodes, "dataSlice");
|
|
440
|
+
if (argumentNode) {
|
|
441
|
+
if (argumentNode.value.kind === "ObjectValue") {
|
|
442
|
+
const offsetArg = argumentNode.value.fields?.find((field) => field.name.value === "offset");
|
|
443
|
+
const lengthArg = argumentNode.value.fields?.find((field) => field.name.value === "length");
|
|
444
|
+
const length = lengthArg?.value.kind === "IntValue" ? parseInt(lengthArg.value.value) : lengthArg?.value.kind === "Variable" ? variableValues[lengthArg.value.name.value] : void 0;
|
|
445
|
+
const offset = offsetArg?.value.kind === "IntValue" ? parseInt(offsetArg.value.value) : offsetArg?.value.kind === "Variable" ? variableValues[offsetArg.value.name.value] : void 0;
|
|
446
|
+
return length !== void 0 && length !== null && offset !== void 0 && offset !== null ? { length, offset } : void 0;
|
|
447
|
+
}
|
|
448
|
+
if (argumentNode.value.kind === "Variable") {
|
|
449
|
+
return variableValues[argumentNode.value.name.value];
|
|
186
450
|
}
|
|
451
|
+
} else {
|
|
452
|
+
return void 0;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function buildAccountArgSetWithVisitor(args, info) {
|
|
456
|
+
const argSet = [args];
|
|
457
|
+
function buildArgSetWithVisitor(root) {
|
|
458
|
+
injectableRootVisitor(info, root, {
|
|
459
|
+
fieldNodeOperation(info2, node) {
|
|
460
|
+
if (node.name.value !== "data") {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (node.arguments) {
|
|
464
|
+
const { variableValues } = info2;
|
|
465
|
+
const encoding = parseAccountEncodingArgument(node.arguments, variableValues);
|
|
466
|
+
const dataSlice = parseAccountDataSliceArgument(node.arguments, variableValues);
|
|
467
|
+
argSet.push({ ...args, dataSlice, encoding });
|
|
468
|
+
}
|
|
469
|
+
},
|
|
470
|
+
fragmentSpreadNodeOperation(_info, fragment) {
|
|
471
|
+
buildArgSetWithVisitor(fragment);
|
|
472
|
+
},
|
|
473
|
+
inlineFragmentNodeOperation(info2, node) {
|
|
474
|
+
const { schema } = info2;
|
|
475
|
+
const accountInterface = schema.getType("Account");
|
|
476
|
+
if (graphql.isInterfaceType(accountInterface) && // Recursively check if the inline fragment requests any
|
|
477
|
+
// fields outside of the `Account` interface.
|
|
478
|
+
!onlyFieldsRequested(Object.keys(accountInterface.getFields()), info2, node)) {
|
|
479
|
+
argSet.push({ ...args, encoding: "jsonParsed" });
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
});
|
|
187
483
|
}
|
|
188
|
-
|
|
484
|
+
buildArgSetWithVisitor(null);
|
|
485
|
+
return argSet;
|
|
486
|
+
}
|
|
487
|
+
function buildAccountLoaderArgSetFromResolveInfo(args, info) {
|
|
488
|
+
return buildAccountArgSetWithVisitor(args, info);
|
|
189
489
|
}
|
|
190
490
|
|
|
191
|
-
// src/resolvers/
|
|
192
|
-
function
|
|
193
|
-
|
|
194
|
-
parsed: { info: result, type: accountType },
|
|
195
|
-
program: programName,
|
|
196
|
-
programId
|
|
197
|
-
} = parsedAccountData;
|
|
198
|
-
result.accountType = accountType;
|
|
199
|
-
result.programId = programId;
|
|
200
|
-
result.programName = programName;
|
|
201
|
-
return result;
|
|
491
|
+
// src/resolvers/resolve-info/program-accounts.ts
|
|
492
|
+
function buildProgramAccountsLoaderArgSetFromResolveInfo(args, info) {
|
|
493
|
+
return buildAccountArgSetWithVisitor(args, info);
|
|
202
494
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const [
|
|
209
|
-
// The account's data, either encoded or parsed.
|
|
210
|
-
data,
|
|
211
|
-
// Tells GraphQL which encoding has been returned
|
|
212
|
-
// by the RPC.
|
|
213
|
-
responseEncoding
|
|
214
|
-
] = Array.isArray(account.data) ? encoding === "jsonParsed" ? (
|
|
215
|
-
// The requested encoding is jsonParsed,
|
|
216
|
-
// but the data could not be parsed.
|
|
217
|
-
// Defaults to base64 encoding.
|
|
218
|
-
[{ data: account.data[0] }, "base64"]
|
|
219
|
-
) : (
|
|
220
|
-
// The requested encoding is base58,
|
|
221
|
-
// base64, or base64+zstd.
|
|
222
|
-
[{ data: account.data[0] }, encoding]
|
|
223
|
-
) : (
|
|
224
|
-
// The account data was returned as an object,
|
|
225
|
-
// so it was parsed successfully.
|
|
226
|
-
[transformParsedAccountData(account.data), "jsonParsed"]
|
|
227
|
-
);
|
|
228
|
-
account.address = address;
|
|
229
|
-
account.encoding = responseEncoding;
|
|
230
|
-
account.ownerProgram = account.owner;
|
|
231
|
-
return {
|
|
232
|
-
...account,
|
|
233
|
-
...data
|
|
495
|
+
|
|
496
|
+
// src/resolvers/account.ts
|
|
497
|
+
var resolveAccountData = () => {
|
|
498
|
+
return (parent, args) => {
|
|
499
|
+
return parent === null ? null : parent.encodedData ? parent.encodedData[cacheKeyFn(args)] : null;
|
|
234
500
|
};
|
|
235
|
-
}
|
|
501
|
+
};
|
|
236
502
|
var resolveAccount = (fieldName) => {
|
|
237
503
|
return async (parent, args, context, info) => {
|
|
238
504
|
const address = fieldName ? parent[fieldName] : args.address;
|
|
239
|
-
if (
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if (onlyPresentFieldRequested("address", info)) {
|
|
243
|
-
return { address };
|
|
244
|
-
}
|
|
245
|
-
const account = await context.loaders.account.load({ ...args, address });
|
|
246
|
-
return account === null ? { address } : transformLoadedAccount({ account, address, encoding: args.encoding });
|
|
247
|
-
};
|
|
248
|
-
};
|
|
249
|
-
var accountResolvers = {
|
|
250
|
-
Account: {
|
|
251
|
-
__resolveType(account) {
|
|
252
|
-
if (account.encoding === "base58") {
|
|
253
|
-
return "AccountBase58";
|
|
254
|
-
}
|
|
255
|
-
if (account.encoding === "base64") {
|
|
256
|
-
return "AccountBase64";
|
|
505
|
+
if (address) {
|
|
506
|
+
if (onlyFieldsRequested(["address"], info)) {
|
|
507
|
+
return { address };
|
|
257
508
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (account
|
|
266
|
-
|
|
509
|
+
const argsSet = buildAccountLoaderArgSetFromResolveInfo({ ...args, address }, info);
|
|
510
|
+
const loadedAccounts = await context.loaders.account.loadMany(argsSet);
|
|
511
|
+
let result = {
|
|
512
|
+
address,
|
|
513
|
+
encodedData: {}
|
|
514
|
+
};
|
|
515
|
+
loadedAccounts.forEach((account, i) => {
|
|
516
|
+
if (account instanceof Error) {
|
|
517
|
+
console.error(account);
|
|
518
|
+
return;
|
|
267
519
|
}
|
|
268
|
-
if (account
|
|
269
|
-
return
|
|
520
|
+
if (account === null) {
|
|
521
|
+
return;
|
|
270
522
|
}
|
|
271
|
-
if (
|
|
272
|
-
|
|
523
|
+
if (!result.ownerProgram) {
|
|
524
|
+
result = {
|
|
525
|
+
...result,
|
|
526
|
+
...account,
|
|
527
|
+
ownerProgram: account.owner
|
|
528
|
+
};
|
|
273
529
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
530
|
+
const { data } = account;
|
|
531
|
+
const { encoding, dataSlice } = argsSet[i];
|
|
532
|
+
if (encoding && result.encodedData) {
|
|
533
|
+
if (Array.isArray(data)) {
|
|
534
|
+
result.encodedData[cacheKeyFn({
|
|
535
|
+
dataSlice,
|
|
536
|
+
encoding: encoding === "jsonParsed" ? "base64" : encoding
|
|
537
|
+
})] = data[0];
|
|
538
|
+
} else if (typeof data === "string") {
|
|
539
|
+
result.encodedData[cacheKeyFn({
|
|
540
|
+
dataSlice,
|
|
541
|
+
encoding: "base58"
|
|
542
|
+
})] = data;
|
|
543
|
+
} else if (typeof data === "object") {
|
|
544
|
+
const {
|
|
545
|
+
parsed: { info: parsedData, type: accountType },
|
|
546
|
+
program: programName,
|
|
547
|
+
programId
|
|
548
|
+
} = data;
|
|
549
|
+
result.jsonParsedConfigs = {
|
|
550
|
+
accountType,
|
|
551
|
+
programId,
|
|
552
|
+
programName
|
|
553
|
+
};
|
|
554
|
+
result = {
|
|
555
|
+
...result,
|
|
556
|
+
...parsedData
|
|
557
|
+
};
|
|
558
|
+
}
|
|
279
559
|
}
|
|
280
|
-
}
|
|
281
|
-
return
|
|
560
|
+
});
|
|
561
|
+
return result;
|
|
282
562
|
}
|
|
563
|
+
return null;
|
|
564
|
+
};
|
|
565
|
+
};
|
|
566
|
+
function resolveAccountType(accountResult) {
|
|
567
|
+
const { jsonParsedConfigs } = accountResult;
|
|
568
|
+
if (jsonParsedConfigs) {
|
|
569
|
+
if (jsonParsedConfigs.programName === "nonce") {
|
|
570
|
+
return "NonceAccount";
|
|
571
|
+
}
|
|
572
|
+
if (jsonParsedConfigs.accountType === "mint" && jsonParsedConfigs.programName === "spl-token") {
|
|
573
|
+
return "MintAccount";
|
|
574
|
+
}
|
|
575
|
+
if (jsonParsedConfigs.accountType === "account" && jsonParsedConfigs.programName === "spl-token") {
|
|
576
|
+
return "TokenAccount";
|
|
577
|
+
}
|
|
578
|
+
if (jsonParsedConfigs.programName === "stake") {
|
|
579
|
+
return "StakeAccount";
|
|
580
|
+
}
|
|
581
|
+
if (jsonParsedConfigs.accountType === "vote" && jsonParsedConfigs.programName === "vote") {
|
|
582
|
+
return "VoteAccount";
|
|
583
|
+
}
|
|
584
|
+
if (jsonParsedConfigs.accountType === "lookupTable" && jsonParsedConfigs.programName === "address-lookup-table") {
|
|
585
|
+
return "LookupTableAccount";
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
return "GenericAccount";
|
|
589
|
+
}
|
|
590
|
+
var accountResolvers = {
|
|
591
|
+
Account: {
|
|
592
|
+
__resolveType: resolveAccountType,
|
|
593
|
+
data: resolveAccountData()
|
|
283
594
|
},
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
},
|
|
287
|
-
AccountBase64: {
|
|
288
|
-
ownerProgram: resolveAccount("ownerProgram")
|
|
289
|
-
},
|
|
290
|
-
AccountBase64Zstd: {
|
|
595
|
+
GenericAccount: {
|
|
596
|
+
data: resolveAccountData(),
|
|
291
597
|
ownerProgram: resolveAccount("ownerProgram")
|
|
292
598
|
},
|
|
293
599
|
LookupTableAccount: {
|
|
294
600
|
authority: resolveAccount("authority"),
|
|
601
|
+
data: resolveAccountData(),
|
|
295
602
|
ownerProgram: resolveAccount("ownerProgram")
|
|
296
603
|
},
|
|
297
604
|
MintAccount: {
|
|
605
|
+
data: resolveAccountData(),
|
|
298
606
|
freezeAuthority: resolveAccount("freezeAuthority"),
|
|
299
607
|
mintAuthority: resolveAccount("mintAuthority"),
|
|
300
608
|
ownerProgram: resolveAccount("ownerProgram")
|
|
301
609
|
},
|
|
302
610
|
NonceAccount: {
|
|
303
611
|
authority: resolveAccount("authority"),
|
|
612
|
+
data: resolveAccountData(),
|
|
304
613
|
ownerProgram: resolveAccount("ownerProgram")
|
|
305
614
|
},
|
|
306
615
|
StakeAccount: {
|
|
616
|
+
data: resolveAccountData(),
|
|
307
617
|
ownerProgram: resolveAccount("ownerProgram")
|
|
308
618
|
},
|
|
309
619
|
StakeAccountDataMetaAuthorized: {
|
|
@@ -317,12 +627,14 @@ var accountResolvers = {
|
|
|
317
627
|
voter: resolveAccount("voter")
|
|
318
628
|
},
|
|
319
629
|
TokenAccount: {
|
|
630
|
+
data: resolveAccountData(),
|
|
320
631
|
mint: resolveAccount("mint"),
|
|
321
632
|
owner: resolveAccount("owner"),
|
|
322
633
|
ownerProgram: resolveAccount("ownerProgram")
|
|
323
634
|
},
|
|
324
635
|
VoteAccount: {
|
|
325
636
|
authorizedWithdrawer: resolveAccount("authorizedWithdrawer"),
|
|
637
|
+
data: resolveAccountData(),
|
|
326
638
|
node: resolveAccount("nodePubkey"),
|
|
327
639
|
ownerProgram: resolveAccount("ownerProgram")
|
|
328
640
|
},
|
|
@@ -382,7 +694,7 @@ function resolveTransaction(fieldName) {
|
|
|
382
694
|
if (!signature) {
|
|
383
695
|
return null;
|
|
384
696
|
}
|
|
385
|
-
if (
|
|
697
|
+
if (onlyFieldsRequested(["signature"], info)) {
|
|
386
698
|
return { signature };
|
|
387
699
|
}
|
|
388
700
|
const transaction = await context.loaders.transaction.load({ ...args, signature });
|
|
@@ -448,7 +760,7 @@ var resolveBlock = (fieldName) => {
|
|
|
448
760
|
if (!slot) {
|
|
449
761
|
return null;
|
|
450
762
|
}
|
|
451
|
-
if (
|
|
763
|
+
if (onlyFieldsRequested(["slot"], info)) {
|
|
452
764
|
return { slot };
|
|
453
765
|
}
|
|
454
766
|
const block = await context.loaders.block.load({ ...args, slot });
|
|
@@ -1197,20 +1509,57 @@ var instructionResolvers = {
|
|
|
1197
1509
|
function resolveProgramAccounts(fieldName) {
|
|
1198
1510
|
return async (parent, args, context, info) => {
|
|
1199
1511
|
const programAddress = fieldName ? parent[fieldName] : args.programAddress;
|
|
1200
|
-
if (
|
|
1201
|
-
|
|
1512
|
+
if (programAddress) {
|
|
1513
|
+
const argsSet = buildProgramAccountsLoaderArgSetFromResolveInfo({ ...args, programAddress }, info);
|
|
1514
|
+
const loadedProgramAccountsLists = await context.loaders.programAccounts.loadMany(argsSet);
|
|
1515
|
+
const result = {};
|
|
1516
|
+
loadedProgramAccountsLists.forEach((programAccounts, i) => {
|
|
1517
|
+
if (programAccounts instanceof Error) {
|
|
1518
|
+
console.error(programAccounts);
|
|
1519
|
+
return;
|
|
1520
|
+
}
|
|
1521
|
+
programAccounts.forEach((programAccount) => {
|
|
1522
|
+
const { account, pubkey: address } = programAccount;
|
|
1523
|
+
const thisResult = result[address] ||= {
|
|
1524
|
+
...account,
|
|
1525
|
+
address,
|
|
1526
|
+
encodedData: {},
|
|
1527
|
+
ownerProgram: account.owner
|
|
1528
|
+
};
|
|
1529
|
+
const { data } = account;
|
|
1530
|
+
const { encoding, dataSlice } = argsSet[i];
|
|
1531
|
+
if (encoding && thisResult.encodedData) {
|
|
1532
|
+
if (Array.isArray(data)) {
|
|
1533
|
+
thisResult.encodedData[cacheKeyFn({
|
|
1534
|
+
dataSlice,
|
|
1535
|
+
encoding: encoding === "jsonParsed" ? "base64" : encoding
|
|
1536
|
+
})] = data[0];
|
|
1537
|
+
} else if (typeof data === "string") {
|
|
1538
|
+
thisResult.encodedData[cacheKeyFn({
|
|
1539
|
+
dataSlice,
|
|
1540
|
+
encoding: "base58"
|
|
1541
|
+
})] = data;
|
|
1542
|
+
} else if (typeof data === "object") {
|
|
1543
|
+
const {
|
|
1544
|
+
parsed: { info: parsedData, type: accountType },
|
|
1545
|
+
program: programName,
|
|
1546
|
+
programId
|
|
1547
|
+
} = data;
|
|
1548
|
+
thisResult.jsonParsedConfigs = {
|
|
1549
|
+
accountType,
|
|
1550
|
+
programId,
|
|
1551
|
+
programName
|
|
1552
|
+
};
|
|
1553
|
+
for (const key in parsedData) {
|
|
1554
|
+
thisResult[key] = parsedData[key];
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
1559
|
+
});
|
|
1560
|
+
return Object.values(result);
|
|
1202
1561
|
}
|
|
1203
|
-
|
|
1204
|
-
return { programAddress };
|
|
1205
|
-
}
|
|
1206
|
-
const programAccounts = await context.loaders.programAccounts.load({ ...args, programAddress });
|
|
1207
|
-
return programAccounts === null ? { programAddress } : programAccounts.map(
|
|
1208
|
-
(programAccount) => transformLoadedAccount({
|
|
1209
|
-
account: programAccount.account,
|
|
1210
|
-
address: programAccount.pubkey,
|
|
1211
|
-
encoding: args.encoding
|
|
1212
|
-
})
|
|
1213
|
-
);
|
|
1562
|
+
return null;
|
|
1214
1563
|
};
|
|
1215
1564
|
}
|
|
1216
1565
|
|
|
@@ -1237,35 +1586,44 @@ var stringScalarAlias = {
|
|
|
1237
1586
|
return value;
|
|
1238
1587
|
}
|
|
1239
1588
|
};
|
|
1240
|
-
var
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
Base64ZstdEncodedBytes: stringScalarAlias,
|
|
1245
|
-
BigInt: {
|
|
1246
|
-
__parseLiteral(ast) {
|
|
1247
|
-
if (ast.kind === graphql.Kind.STRING) {
|
|
1248
|
-
return BigInt(ast.value);
|
|
1249
|
-
}
|
|
1250
|
-
return null;
|
|
1251
|
-
},
|
|
1252
|
-
__parseValue(value) {
|
|
1253
|
-
return BigInt(value);
|
|
1254
|
-
},
|
|
1255
|
-
__serialize(value) {
|
|
1256
|
-
return BigInt(value);
|
|
1589
|
+
var bigIntScalarAlias = {
|
|
1590
|
+
__parseLiteral(ast) {
|
|
1591
|
+
if (ast.kind === graphql.Kind.STRING) {
|
|
1592
|
+
return BigInt(ast.value);
|
|
1257
1593
|
}
|
|
1594
|
+
return null;
|
|
1595
|
+
},
|
|
1596
|
+
__parseValue(value) {
|
|
1597
|
+
return BigInt(value);
|
|
1598
|
+
},
|
|
1599
|
+
__serialize(value) {
|
|
1600
|
+
return BigInt(value);
|
|
1258
1601
|
}
|
|
1259
1602
|
};
|
|
1260
|
-
|
|
1261
|
-
// src/resolvers/types.ts
|
|
1262
|
-
var commonTypeResolvers = {
|
|
1603
|
+
var typeTypeResolvers = {
|
|
1263
1604
|
AccountEncoding: {
|
|
1264
1605
|
BASE_58: "base58",
|
|
1265
1606
|
BASE_64: "base64",
|
|
1266
|
-
BASE_64_ZSTD: "base64+zstd"
|
|
1267
|
-
PARSED: "jsonParsed"
|
|
1607
|
+
BASE_64_ZSTD: "base64+zstd"
|
|
1268
1608
|
},
|
|
1609
|
+
Address: stringScalarAlias,
|
|
1610
|
+
Base58EncodedBytes: stringScalarAlias,
|
|
1611
|
+
Base64EncodedBytes: stringScalarAlias,
|
|
1612
|
+
Base64ZstdEncodedBytes: stringScalarAlias,
|
|
1613
|
+
BigInt: bigIntScalarAlias,
|
|
1614
|
+
BlockTransactionDetails: {
|
|
1615
|
+
ACCOUNTS: "accounts",
|
|
1616
|
+
FULL: "full",
|
|
1617
|
+
NONE: "none",
|
|
1618
|
+
SIGNATURES: "signatures"
|
|
1619
|
+
},
|
|
1620
|
+
Commitment: {
|
|
1621
|
+
CONFIRMED: "confirmed",
|
|
1622
|
+
FINALIZED: "finalized",
|
|
1623
|
+
PROCESSED: "processed"
|
|
1624
|
+
},
|
|
1625
|
+
Signature: stringScalarAlias,
|
|
1626
|
+
Slot: bigIntScalarAlias,
|
|
1269
1627
|
TokenBalance: {
|
|
1270
1628
|
mint: resolveAccount("mint"),
|
|
1271
1629
|
owner: resolveAccount("owner")
|
|
@@ -1286,11 +1644,10 @@ function createSolanaGraphQLResolvers() {
|
|
|
1286
1644
|
return {
|
|
1287
1645
|
...accountResolvers,
|
|
1288
1646
|
...blockResolvers,
|
|
1289
|
-
...commonTypeResolvers,
|
|
1290
1647
|
...instructionResolvers,
|
|
1291
1648
|
...rootResolvers,
|
|
1292
|
-
...
|
|
1293
|
-
...
|
|
1649
|
+
...transactionResolvers,
|
|
1650
|
+
...typeTypeResolvers
|
|
1294
1651
|
};
|
|
1295
1652
|
}
|
|
1296
1653
|
|
|
@@ -1303,6 +1660,7 @@ var accountTypeDefs = (
|
|
|
1303
1660
|
"""
|
|
1304
1661
|
interface Account {
|
|
1305
1662
|
address: Address
|
|
1663
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1306
1664
|
executable: Boolean
|
|
1307
1665
|
lamports: BigInt
|
|
1308
1666
|
ownerProgram: Account
|
|
@@ -1311,37 +1669,11 @@ var accountTypeDefs = (
|
|
|
1311
1669
|
}
|
|
1312
1670
|
|
|
1313
1671
|
"""
|
|
1314
|
-
|
|
1315
|
-
"""
|
|
1316
|
-
type AccountBase58 implements Account {
|
|
1317
|
-
address: Address
|
|
1318
|
-
data: Base58EncodedBytes
|
|
1319
|
-
executable: Boolean
|
|
1320
|
-
lamports: BigInt
|
|
1321
|
-
ownerProgram: Account
|
|
1322
|
-
space: BigInt
|
|
1323
|
-
rentEpoch: BigInt
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
"""
|
|
1327
|
-
An account with base64 encoded data
|
|
1672
|
+
Generic base account type
|
|
1328
1673
|
"""
|
|
1329
|
-
type
|
|
1674
|
+
type GenericAccount implements Account {
|
|
1330
1675
|
address: Address
|
|
1331
|
-
data:
|
|
1332
|
-
executable: Boolean
|
|
1333
|
-
lamports: BigInt
|
|
1334
|
-
ownerProgram: Account
|
|
1335
|
-
space: BigInt
|
|
1336
|
-
rentEpoch: BigInt
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
"""
|
|
1340
|
-
An account with base64+zstd encoded data
|
|
1341
|
-
"""
|
|
1342
|
-
type AccountBase64Zstd implements Account {
|
|
1343
|
-
address: Address
|
|
1344
|
-
data: Base64ZstdEncodedBytes
|
|
1676
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1345
1677
|
executable: Boolean
|
|
1346
1678
|
lamports: BigInt
|
|
1347
1679
|
ownerProgram: Account
|
|
@@ -1357,6 +1689,7 @@ var accountTypeDefs = (
|
|
|
1357
1689
|
"""
|
|
1358
1690
|
type NonceAccount implements Account {
|
|
1359
1691
|
address: Address
|
|
1692
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1360
1693
|
executable: Boolean
|
|
1361
1694
|
lamports: BigInt
|
|
1362
1695
|
ownerProgram: Account
|
|
@@ -1372,6 +1705,7 @@ var accountTypeDefs = (
|
|
|
1372
1705
|
"""
|
|
1373
1706
|
type LookupTableAccount implements Account {
|
|
1374
1707
|
address: Address
|
|
1708
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1375
1709
|
executable: Boolean
|
|
1376
1710
|
lamports: BigInt
|
|
1377
1711
|
ownerProgram: Account
|
|
@@ -1389,6 +1723,7 @@ var accountTypeDefs = (
|
|
|
1389
1723
|
"""
|
|
1390
1724
|
type MintAccount implements Account {
|
|
1391
1725
|
address: Address
|
|
1726
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1392
1727
|
executable: Boolean
|
|
1393
1728
|
lamports: BigInt
|
|
1394
1729
|
ownerProgram: Account
|
|
@@ -1406,6 +1741,7 @@ var accountTypeDefs = (
|
|
|
1406
1741
|
"""
|
|
1407
1742
|
type TokenAccount implements Account {
|
|
1408
1743
|
address: Address
|
|
1744
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1409
1745
|
executable: Boolean
|
|
1410
1746
|
lamports: BigInt
|
|
1411
1747
|
ownerProgram: Account
|
|
@@ -1448,6 +1784,7 @@ var accountTypeDefs = (
|
|
|
1448
1784
|
"""
|
|
1449
1785
|
type StakeAccount implements Account {
|
|
1450
1786
|
address: Address
|
|
1787
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1451
1788
|
executable: Boolean
|
|
1452
1789
|
lamports: BigInt
|
|
1453
1790
|
ownerProgram: Account
|
|
@@ -1479,6 +1816,7 @@ var accountTypeDefs = (
|
|
|
1479
1816
|
"""
|
|
1480
1817
|
type VoteAccount implements Account {
|
|
1481
1818
|
address: Address
|
|
1819
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1482
1820
|
executable: Boolean
|
|
1483
1821
|
lamports: BigInt
|
|
1484
1822
|
ownerProgram: Account
|
|
@@ -1592,101 +1930,6 @@ var blockTypeDefs = (
|
|
|
1592
1930
|
`
|
|
1593
1931
|
);
|
|
1594
1932
|
|
|
1595
|
-
// src/schema/common/inputs.ts
|
|
1596
|
-
var inputTypeDefs = (
|
|
1597
|
-
/* GraphQL */
|
|
1598
|
-
`
|
|
1599
|
-
input DataSlice {
|
|
1600
|
-
offset: Int
|
|
1601
|
-
length: Int
|
|
1602
|
-
}
|
|
1603
|
-
|
|
1604
|
-
input ProgramAccountsFilter {
|
|
1605
|
-
bytes: BigInt
|
|
1606
|
-
dataSize: BigInt
|
|
1607
|
-
encoding: AccountEncoding
|
|
1608
|
-
offset: BigInt
|
|
1609
|
-
}
|
|
1610
|
-
`
|
|
1611
|
-
);
|
|
1612
|
-
|
|
1613
|
-
// src/schema/common/scalars.ts
|
|
1614
|
-
var scalarTypeDefs = (
|
|
1615
|
-
/* GraphQL */
|
|
1616
|
-
`
|
|
1617
|
-
scalar Address
|
|
1618
|
-
scalar Base58EncodedBytes
|
|
1619
|
-
scalar Base64EncodedBytes
|
|
1620
|
-
scalar Base64ZstdEncodedBytes
|
|
1621
|
-
scalar BigInt
|
|
1622
|
-
`
|
|
1623
|
-
);
|
|
1624
|
-
|
|
1625
|
-
// src/schema/common/types.ts
|
|
1626
|
-
var commonTypeDefs = (
|
|
1627
|
-
/* GraphQL */
|
|
1628
|
-
`
|
|
1629
|
-
enum AccountEncoding {
|
|
1630
|
-
BASE_58
|
|
1631
|
-
BASE_64
|
|
1632
|
-
BASE_64_ZSTD
|
|
1633
|
-
PARSED
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
enum BlockTransactionDetails {
|
|
1637
|
-
accounts
|
|
1638
|
-
full
|
|
1639
|
-
none
|
|
1640
|
-
signatures
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
enum Commitment {
|
|
1644
|
-
confirmed
|
|
1645
|
-
finalized
|
|
1646
|
-
processed
|
|
1647
|
-
}
|
|
1648
|
-
|
|
1649
|
-
type ReturnData {
|
|
1650
|
-
data: Base64EncodedBytes
|
|
1651
|
-
programId: Address
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
|
-
type Reward {
|
|
1655
|
-
commission: Int
|
|
1656
|
-
lamports: BigInt
|
|
1657
|
-
postBalance: BigInt
|
|
1658
|
-
pubkey: Address
|
|
1659
|
-
rewardType: String
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
type TokenAmount {
|
|
1663
|
-
amount: String
|
|
1664
|
-
decimals: Int
|
|
1665
|
-
uiAmount: BigInt
|
|
1666
|
-
uiAmountString: String
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
type TokenBalance {
|
|
1670
|
-
accountIndex: Int
|
|
1671
|
-
mint: Account
|
|
1672
|
-
owner: Account
|
|
1673
|
-
programId: Address
|
|
1674
|
-
uiTokenAmount: TokenAmount
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
enum TransactionEncoding {
|
|
1678
|
-
BASE_58
|
|
1679
|
-
BASE_64
|
|
1680
|
-
PARSED
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
|
-
enum TransactionVersion {
|
|
1684
|
-
LEGACY
|
|
1685
|
-
ZERO
|
|
1686
|
-
}
|
|
1687
|
-
`
|
|
1688
|
-
);
|
|
1689
|
-
|
|
1690
1933
|
// src/schema/instruction.ts
|
|
1691
1934
|
var instructionTypeDefs = (
|
|
1692
1935
|
/* GraphQL */
|
|
@@ -2740,28 +2983,20 @@ var rootTypeDefs = (
|
|
|
2740
2983
|
/* GraphQL */
|
|
2741
2984
|
`
|
|
2742
2985
|
type Query {
|
|
2743
|
-
account(
|
|
2744
|
-
address: String!
|
|
2745
|
-
commitment: Commitment
|
|
2746
|
-
dataSlice: DataSlice
|
|
2747
|
-
encoding: AccountEncoding
|
|
2748
|
-
minContextSlot: BigInt
|
|
2749
|
-
): Account
|
|
2986
|
+
account(address: Address!, commitment: Commitment, minContextSlot: Slot): Account
|
|
2750
2987
|
block(
|
|
2751
|
-
slot:
|
|
2988
|
+
slot: Slot!
|
|
2752
2989
|
commitment: Commitment
|
|
2753
2990
|
encoding: TransactionEncoding
|
|
2754
2991
|
transactionDetails: BlockTransactionDetails
|
|
2755
2992
|
): Block
|
|
2756
2993
|
programAccounts(
|
|
2757
|
-
programAddress:
|
|
2994
|
+
programAddress: Address!
|
|
2758
2995
|
commitment: Commitment
|
|
2759
|
-
dataSlice: DataSlice
|
|
2760
|
-
encoding: AccountEncoding
|
|
2761
2996
|
filters: [ProgramAccountsFilter]
|
|
2762
|
-
minContextSlot:
|
|
2997
|
+
minContextSlot: Slot
|
|
2763
2998
|
): [Account]
|
|
2764
|
-
transaction(signature:
|
|
2999
|
+
transaction(signature: Signature!, commitment: Commitment, encoding: TransactionEncoding): Transaction
|
|
2765
3000
|
}
|
|
2766
3001
|
|
|
2767
3002
|
schema {
|
|
@@ -2884,29 +3119,114 @@ var transactionTypeDefs = (
|
|
|
2884
3119
|
`
|
|
2885
3120
|
);
|
|
2886
3121
|
|
|
3122
|
+
// src/schema/types.ts
|
|
3123
|
+
var typeTypeDefs = (
|
|
3124
|
+
/* GraphQL */
|
|
3125
|
+
`
|
|
3126
|
+
enum AccountEncoding {
|
|
3127
|
+
BASE_58
|
|
3128
|
+
BASE_64
|
|
3129
|
+
BASE_64_ZSTD
|
|
3130
|
+
}
|
|
3131
|
+
|
|
3132
|
+
scalar Address
|
|
3133
|
+
|
|
3134
|
+
scalar Base58EncodedBytes
|
|
3135
|
+
|
|
3136
|
+
scalar Base64EncodedBytes
|
|
3137
|
+
|
|
3138
|
+
scalar Base64ZstdEncodedBytes
|
|
3139
|
+
|
|
3140
|
+
scalar BigInt
|
|
3141
|
+
|
|
3142
|
+
enum BlockTransactionDetails {
|
|
3143
|
+
ACCOUNTS
|
|
3144
|
+
FULL
|
|
3145
|
+
NONE
|
|
3146
|
+
SIGNATURES
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
enum Commitment {
|
|
3150
|
+
CONFIRMED
|
|
3151
|
+
FINALIZED
|
|
3152
|
+
PROCESSED
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3155
|
+
input DataSlice {
|
|
3156
|
+
offset: Int!
|
|
3157
|
+
length: Int!
|
|
3158
|
+
}
|
|
3159
|
+
|
|
3160
|
+
input ProgramAccountsFilter {
|
|
3161
|
+
bytes: BigInt
|
|
3162
|
+
dataSize: BigInt
|
|
3163
|
+
encoding: AccountEncoding
|
|
3164
|
+
offset: BigInt
|
|
3165
|
+
}
|
|
3166
|
+
|
|
3167
|
+
type ReturnData {
|
|
3168
|
+
data: Base64EncodedBytes
|
|
3169
|
+
programId: Address
|
|
3170
|
+
}
|
|
3171
|
+
|
|
3172
|
+
type Reward {
|
|
3173
|
+
commission: Int
|
|
3174
|
+
lamports: BigInt
|
|
3175
|
+
postBalance: BigInt
|
|
3176
|
+
pubkey: Address
|
|
3177
|
+
rewardType: String
|
|
3178
|
+
}
|
|
3179
|
+
|
|
3180
|
+
scalar Signature
|
|
3181
|
+
|
|
3182
|
+
scalar Slot
|
|
3183
|
+
|
|
3184
|
+
type TokenAmount {
|
|
3185
|
+
amount: String
|
|
3186
|
+
decimals: Int
|
|
3187
|
+
uiAmount: BigInt
|
|
3188
|
+
uiAmountString: String
|
|
3189
|
+
}
|
|
3190
|
+
|
|
3191
|
+
type TokenBalance {
|
|
3192
|
+
accountIndex: Int
|
|
3193
|
+
mint: Account
|
|
3194
|
+
owner: Account
|
|
3195
|
+
programId: Address
|
|
3196
|
+
uiTokenAmount: TokenAmount
|
|
3197
|
+
}
|
|
3198
|
+
|
|
3199
|
+
enum TransactionEncoding {
|
|
3200
|
+
BASE_58
|
|
3201
|
+
BASE_64
|
|
3202
|
+
PARSED
|
|
3203
|
+
}
|
|
3204
|
+
|
|
3205
|
+
enum TransactionVersion {
|
|
3206
|
+
LEGACY
|
|
3207
|
+
ZERO
|
|
3208
|
+
}
|
|
3209
|
+
`
|
|
3210
|
+
);
|
|
3211
|
+
|
|
2887
3212
|
// src/schema/index.ts
|
|
2888
3213
|
function createSolanaGraphQLTypeDefs() {
|
|
2889
|
-
return [
|
|
2890
|
-
accountTypeDefs,
|
|
2891
|
-
blockTypeDefs,
|
|
2892
|
-
commonTypeDefs,
|
|
2893
|
-
inputTypeDefs,
|
|
2894
|
-
instructionTypeDefs,
|
|
2895
|
-
rootTypeDefs,
|
|
2896
|
-
scalarTypeDefs,
|
|
2897
|
-
transactionTypeDefs
|
|
2898
|
-
];
|
|
3214
|
+
return [accountTypeDefs, blockTypeDefs, instructionTypeDefs, rootTypeDefs, typeTypeDefs, transactionTypeDefs];
|
|
2899
3215
|
}
|
|
2900
3216
|
|
|
2901
3217
|
// src/index.ts
|
|
2902
|
-
function createRpcGraphQL(rpc) {
|
|
3218
|
+
function createRpcGraphQL(rpc, config) {
|
|
3219
|
+
const rpcGraphQLConfig = {
|
|
3220
|
+
maxDataSliceByteRange: config?.maxDataSliceByteRange ?? 200,
|
|
3221
|
+
maxMultipleAccountsBatchSize: config?.maxMultipleAccountsBatchSize ?? 100
|
|
3222
|
+
};
|
|
2903
3223
|
const schema$1 = schema.makeExecutableSchema({
|
|
2904
3224
|
resolvers: createSolanaGraphQLResolvers(),
|
|
2905
3225
|
typeDefs: createSolanaGraphQLTypeDefs()
|
|
2906
3226
|
});
|
|
2907
3227
|
return {
|
|
2908
3228
|
async query(source, variableValues) {
|
|
2909
|
-
const contextValue = createSolanaGraphQLContext(rpc);
|
|
3229
|
+
const contextValue = createSolanaGraphQLContext(rpc, rpcGraphQLConfig);
|
|
2910
3230
|
return graphql.graphql({
|
|
2911
3231
|
contextValue,
|
|
2912
3232
|
schema: schema$1,
|