@helium/spl-utils 0.0.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/LICENSE +203 -0
- package/lib/cjs/accountFetchCache/accountFetchCache.js +365 -0
- package/lib/cjs/accountFetchCache/accountFetchCache.js.map +1 -0
- package/lib/cjs/accountFetchCache/eventEmitter.js +37 -0
- package/lib/cjs/accountFetchCache/eventEmitter.js.map +1 -0
- package/lib/cjs/accountFetchCache/getMultipleAccounts.js +53 -0
- package/lib/cjs/accountFetchCache/getMultipleAccounts.js.map +1 -0
- package/lib/cjs/accountFetchCache/index.js +20 -0
- package/lib/cjs/accountFetchCache/index.js.map +1 -0
- package/lib/cjs/accountsResolver/ataResolver.js +35 -0
- package/lib/cjs/accountsResolver/ataResolver.js.map +1 -0
- package/lib/cjs/accountsResolver/combineResolvers.js +27 -0
- package/lib/cjs/accountsResolver/combineResolvers.js.map +1 -0
- package/lib/cjs/accountsResolver/individual.js +90 -0
- package/lib/cjs/accountsResolver/individual.js.map +1 -0
- package/lib/cjs/accountsResolver/utils.js +32 -0
- package/lib/cjs/accountsResolver/utils.js.map +1 -0
- package/lib/cjs/anchorError.js +265 -0
- package/lib/cjs/anchorError.js.map +1 -0
- package/lib/cjs/constants.js +8 -0
- package/lib/cjs/constants.js.map +1 -0
- package/lib/cjs/executeRemoteTxn.js +109 -0
- package/lib/cjs/executeRemoteTxn.js.map +1 -0
- package/lib/cjs/extendBorsh.js +33 -0
- package/lib/cjs/extendBorsh.js.map +1 -0
- package/lib/cjs/index.js +35 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/token.js +196 -0
- package/lib/cjs/token.js.map +1 -0
- package/lib/cjs/transaction.js +308 -0
- package/lib/cjs/transaction.js.map +1 -0
- package/lib/cjs/utils.js +58 -0
- package/lib/cjs/utils.js.map +1 -0
- package/lib/esm/src/accountFetchCache/accountFetchCache.js +338 -0
- package/lib/esm/src/accountFetchCache/accountFetchCache.js.map +1 -0
- package/lib/esm/src/accountFetchCache/eventEmitter.js +33 -0
- package/lib/esm/src/accountFetchCache/eventEmitter.js.map +1 -0
- package/lib/esm/src/accountFetchCache/getMultipleAccounts.js +32 -0
- package/lib/esm/src/accountFetchCache/getMultipleAccounts.js.map +1 -0
- package/lib/esm/src/accountFetchCache/index.js +4 -0
- package/lib/esm/src/accountFetchCache/index.js.map +1 -0
- package/lib/esm/src/accountsResolver/ataResolver.js +22 -0
- package/lib/esm/src/accountsResolver/ataResolver.js.map +1 -0
- package/lib/esm/src/accountsResolver/combineResolvers.js +14 -0
- package/lib/esm/src/accountsResolver/combineResolvers.js.map +1 -0
- package/lib/esm/src/accountsResolver/individual.js +72 -0
- package/lib/esm/src/accountsResolver/individual.js.map +1 -0
- package/lib/esm/src/accountsResolver/utils.js +27 -0
- package/lib/esm/src/accountsResolver/utils.js.map +1 -0
- package/lib/esm/src/anchorError.js +262 -0
- package/lib/esm/src/anchorError.js.map +1 -0
- package/lib/esm/src/constants.js +5 -0
- package/lib/esm/src/constants.js.map +1 -0
- package/lib/esm/src/executeRemoteTxn.js +79 -0
- package/lib/esm/src/executeRemoteTxn.js.map +1 -0
- package/lib/esm/src/extendBorsh.js +26 -0
- package/lib/esm/src/extendBorsh.js.map +1 -0
- package/lib/esm/src/index.js +13 -0
- package/lib/esm/src/index.js.map +1 -0
- package/lib/esm/src/token.js +175 -0
- package/lib/esm/src/token.js.map +1 -0
- package/lib/esm/src/transaction.js +274 -0
- package/lib/esm/src/transaction.js.map +1 -0
- package/lib/esm/src/utils.js +44 -0
- package/lib/esm/src/utils.js.map +1 -0
- package/lib/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/lib/types/src/accountFetchCache/accountFetchCache.d.ts +67 -0
- package/lib/types/src/accountFetchCache/accountFetchCache.d.ts.map +1 -0
- package/lib/types/src/accountFetchCache/eventEmitter.d.ts +19 -0
- package/lib/types/src/accountFetchCache/eventEmitter.d.ts.map +1 -0
- package/lib/types/src/accountFetchCache/getMultipleAccounts.d.ts +7 -0
- package/lib/types/src/accountFetchCache/getMultipleAccounts.d.ts.map +1 -0
- package/lib/types/src/accountFetchCache/index.d.ts +4 -0
- package/lib/types/src/accountFetchCache/index.d.ts.map +1 -0
- package/lib/types/src/accountsResolver/ataResolver.d.ts +9 -0
- package/lib/types/src/accountsResolver/ataResolver.d.ts.map +1 -0
- package/lib/types/src/accountsResolver/combineResolvers.d.ts +3 -0
- package/lib/types/src/accountsResolver/combineResolvers.d.ts.map +1 -0
- package/lib/types/src/accountsResolver/individual.d.ts +25 -0
- package/lib/types/src/accountsResolver/individual.d.ts.map +1 -0
- package/lib/types/src/accountsResolver/utils.d.ts +7 -0
- package/lib/types/src/accountsResolver/utils.d.ts.map +1 -0
- package/lib/types/src/anchorError.d.ts +9 -0
- package/lib/types/src/anchorError.d.ts.map +1 -0
- package/lib/types/src/constants.d.ts +5 -0
- package/lib/types/src/constants.d.ts.map +1 -0
- package/lib/types/src/executeRemoteTxn.d.ts +23 -0
- package/lib/types/src/executeRemoteTxn.d.ts.map +1 -0
- package/lib/types/src/extendBorsh.d.ts +3 -0
- package/lib/types/src/extendBorsh.d.ts.map +1 -0
- package/lib/types/src/index.d.ts +13 -0
- package/lib/types/src/index.d.ts.map +1 -0
- package/lib/types/src/token.d.ts +16 -0
- package/lib/types/src/token.d.ts.map +1 -0
- package/lib/types/src/transaction.d.ts +26 -0
- package/lib/types/src/transaction.d.ts.map +1 -0
- package/lib/types/src/utils.d.ts +12 -0
- package/lib/types/src/utils.d.ts.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { PublicKey, Transaction } from "@solana/web3.js";
|
|
2
|
+
import { EventEmitter } from "./eventEmitter";
|
|
3
|
+
import { getMultipleAccounts } from "./getMultipleAccounts";
|
|
4
|
+
export const DEFAULT_CHUNK_SIZE = 99;
|
|
5
|
+
export const DEFAULT_DELAY = 50;
|
|
6
|
+
function getWriteableAccounts(instructions) {
|
|
7
|
+
return instructions
|
|
8
|
+
.flatMap((i) => i.keys)
|
|
9
|
+
.filter((k) => k.isWritable)
|
|
10
|
+
.map((a) => a.pubkey);
|
|
11
|
+
}
|
|
12
|
+
let id = 0;
|
|
13
|
+
export class AccountFetchCache {
|
|
14
|
+
connection;
|
|
15
|
+
chunkSize;
|
|
16
|
+
delay;
|
|
17
|
+
commitment;
|
|
18
|
+
accountWatchersCount = new Map();
|
|
19
|
+
accountChangeListeners = new Map();
|
|
20
|
+
statics = new Set();
|
|
21
|
+
missingAccounts = new Map();
|
|
22
|
+
genericCache = new Map();
|
|
23
|
+
keyToAccountParser = new Map();
|
|
24
|
+
timeout = null;
|
|
25
|
+
currentBatch = new Set();
|
|
26
|
+
pendingCallbacks = new Map();
|
|
27
|
+
pendingCalls = new Map();
|
|
28
|
+
emitter = new EventEmitter();
|
|
29
|
+
oldGetAccountinfo;
|
|
30
|
+
oldSendTransaction;
|
|
31
|
+
oldSendRawTransaction;
|
|
32
|
+
missingInterval;
|
|
33
|
+
constructor({ connection, chunkSize = DEFAULT_CHUNK_SIZE, delay = DEFAULT_DELAY, commitment, missingRefetchDelay = 10000, extendConnection = false, }) {
|
|
34
|
+
this.connection = connection;
|
|
35
|
+
this.chunkSize = chunkSize;
|
|
36
|
+
this.delay = delay;
|
|
37
|
+
this.commitment = commitment;
|
|
38
|
+
this.missingInterval = setInterval(this.fetchMissing.bind(this), missingRefetchDelay);
|
|
39
|
+
this.oldSendTransaction = connection.sendTransaction.bind(connection);
|
|
40
|
+
this.oldSendRawTransaction =
|
|
41
|
+
connection.sendRawTransaction.bind(connection);
|
|
42
|
+
const self = this;
|
|
43
|
+
if (extendConnection) {
|
|
44
|
+
this.oldGetAccountinfo = connection.getAccountInfo.bind(connection);
|
|
45
|
+
connection.getAccountInfo = async (publicKey, com) => {
|
|
46
|
+
if ((com || connection.commitment) == commitment ||
|
|
47
|
+
typeof (com || connection.commitment) == "undefined") {
|
|
48
|
+
const [result, dispose] = await this.searchAndWatch(publicKey);
|
|
49
|
+
setTimeout(dispose, 30 * 1000); // cache for 30s
|
|
50
|
+
return result?.account || null;
|
|
51
|
+
}
|
|
52
|
+
return self.oldGetAccountinfo(publicKey, com);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
connection.sendTransaction = async function overloadedSendTransaction(transaction, signers, options) {
|
|
56
|
+
const result = await self.oldSendTransaction(transaction, signers, options);
|
|
57
|
+
this.confirmTransaction(result, "finalized")
|
|
58
|
+
.then(() => {
|
|
59
|
+
return self.requeryMissing(transaction.instructions);
|
|
60
|
+
})
|
|
61
|
+
.catch(console.error);
|
|
62
|
+
return result;
|
|
63
|
+
};
|
|
64
|
+
connection.sendRawTransaction = async function overloadedSendRawTransaction(rawTransaction, options) {
|
|
65
|
+
const result = await self.oldSendRawTransaction(rawTransaction, options);
|
|
66
|
+
const instructions = Transaction.from(rawTransaction).instructions;
|
|
67
|
+
this.confirmTransaction(result, "finalized")
|
|
68
|
+
.then(() => {
|
|
69
|
+
return self.requeryMissing(instructions);
|
|
70
|
+
})
|
|
71
|
+
.catch(console.error);
|
|
72
|
+
return result;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async requeryMissing(instructions) {
|
|
76
|
+
const writeableAccounts = getWriteableAccounts(instructions).map((a) => a.toBase58());
|
|
77
|
+
await Promise.all(writeableAccounts.map(async (account) => {
|
|
78
|
+
const parser = this.missingAccounts.get(account);
|
|
79
|
+
const [found, dispose] = await this.searchAndWatch(new PublicKey(account), parser, this.statics.has(account), true);
|
|
80
|
+
dispose();
|
|
81
|
+
if (found) {
|
|
82
|
+
this.missingAccounts.delete(account);
|
|
83
|
+
}
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
async fetchMissing() {
|
|
87
|
+
try {
|
|
88
|
+
await Promise.all([...this.missingAccounts].map(([account, _]) => this.searchAndWatch(new PublicKey(account), this.missingAccounts.get(account), this.statics.has(account), true).then(([_, dispose]) => dispose()) // Dispose immediately, this isn't watching.
|
|
89
|
+
));
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
// This happens in an interval, so just log errors
|
|
93
|
+
console.error(e);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
close() {
|
|
97
|
+
if (this.oldGetAccountinfo) {
|
|
98
|
+
this.connection.getAccountInfo = this.oldGetAccountinfo;
|
|
99
|
+
}
|
|
100
|
+
this.connection.sendTransaction = this.oldSendTransaction;
|
|
101
|
+
this.connection.sendRawTransaction = this.oldSendRawTransaction;
|
|
102
|
+
clearInterval(this.missingInterval);
|
|
103
|
+
}
|
|
104
|
+
async fetchBatch() {
|
|
105
|
+
const currentBatch = this.currentBatch;
|
|
106
|
+
this.currentBatch = new Set(); // Erase current batch from state, so we can fetch multiple at a time
|
|
107
|
+
try {
|
|
108
|
+
console.log(`Batching account fetch of ${currentBatch.size}`);
|
|
109
|
+
const { keys, array } = await getMultipleAccounts(this.connection, Array.from(currentBatch), this.commitment);
|
|
110
|
+
keys.forEach((key, index) => {
|
|
111
|
+
const callback = this.pendingCallbacks.get(key);
|
|
112
|
+
callback && callback(array[index], null);
|
|
113
|
+
});
|
|
114
|
+
return { keys, array };
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
currentBatch.forEach((key) => {
|
|
118
|
+
const callback = this.pendingCallbacks.get(key);
|
|
119
|
+
callback && callback(null, e);
|
|
120
|
+
});
|
|
121
|
+
throw e;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async addToBatch(id) {
|
|
125
|
+
const idStr = id.toBase58();
|
|
126
|
+
this.currentBatch.add(idStr);
|
|
127
|
+
this.timeout != null && clearTimeout(this.timeout);
|
|
128
|
+
if (this.currentBatch.size > DEFAULT_CHUNK_SIZE) {
|
|
129
|
+
this.fetchBatch();
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
this.timeout = setTimeout(() => this.fetchBatch(), this.delay);
|
|
133
|
+
}
|
|
134
|
+
const promise = new Promise((resolve, reject) => {
|
|
135
|
+
this.pendingCallbacks.set(idStr, (info, err) => {
|
|
136
|
+
this.pendingCallbacks.delete(idStr);
|
|
137
|
+
if (err) {
|
|
138
|
+
return reject(err);
|
|
139
|
+
}
|
|
140
|
+
resolve(info);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
return promise;
|
|
144
|
+
}
|
|
145
|
+
async flush() {
|
|
146
|
+
this.timeout && clearTimeout(this.timeout);
|
|
147
|
+
await this.fetchBatch();
|
|
148
|
+
}
|
|
149
|
+
async searchAndWatch(pubKey, parser, isStatic = false, // optimization, set if the data will never change
|
|
150
|
+
forceRequery = false) {
|
|
151
|
+
let id;
|
|
152
|
+
if (typeof pubKey === "string") {
|
|
153
|
+
id = new PublicKey(pubKey);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
id = pubKey;
|
|
157
|
+
}
|
|
158
|
+
if (!pubKey) {
|
|
159
|
+
return [undefined, () => { }];
|
|
160
|
+
}
|
|
161
|
+
const address = id.toBase58();
|
|
162
|
+
const data = await this.search(pubKey, parser, isStatic, forceRequery);
|
|
163
|
+
const dispose = this.watch(id, parser, !!data);
|
|
164
|
+
const cacheEntry = this.genericCache.get(address);
|
|
165
|
+
if (!this.genericCache.has(address) || cacheEntry != data) {
|
|
166
|
+
this.updateCache(address, data || null);
|
|
167
|
+
}
|
|
168
|
+
return [data, dispose];
|
|
169
|
+
}
|
|
170
|
+
async updateCache(id, data) {
|
|
171
|
+
const isNew = !this.genericCache.has(id);
|
|
172
|
+
this.genericCache.set(id, data || null);
|
|
173
|
+
this.emitter.raiseCacheUpdated(id, isNew, this.keyToAccountParser.get(id));
|
|
174
|
+
}
|
|
175
|
+
static defaultParser = (pubkey, account) => ({
|
|
176
|
+
pubkey,
|
|
177
|
+
account,
|
|
178
|
+
});
|
|
179
|
+
// The same as query, except swallows errors and returns undefined.
|
|
180
|
+
async search(pubKey, parser, isStatic = false, // optimization, set if the data will never change
|
|
181
|
+
forceRequery = false) {
|
|
182
|
+
let id;
|
|
183
|
+
if (typeof pubKey === "string") {
|
|
184
|
+
id = new PublicKey(pubKey);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
id = pubKey;
|
|
188
|
+
}
|
|
189
|
+
this.registerParser(id, parser);
|
|
190
|
+
const address = id.toBase58();
|
|
191
|
+
if (isStatic) {
|
|
192
|
+
this.statics.add(address);
|
|
193
|
+
}
|
|
194
|
+
else if (this.statics.has(address)) {
|
|
195
|
+
this.statics.delete(address); // If trying to use this as not static, need to rm it from the statics list.
|
|
196
|
+
}
|
|
197
|
+
if (!forceRequery && this.genericCache.has(address)) {
|
|
198
|
+
const result = this.genericCache.get(address);
|
|
199
|
+
return result == null
|
|
200
|
+
? undefined
|
|
201
|
+
: result;
|
|
202
|
+
}
|
|
203
|
+
const existingQuery = this.pendingCalls.get(address);
|
|
204
|
+
if (!forceRequery && existingQuery) {
|
|
205
|
+
return existingQuery;
|
|
206
|
+
}
|
|
207
|
+
const query = this.addToBatch(id).then((data) => {
|
|
208
|
+
this.pendingCalls.delete(address);
|
|
209
|
+
if (!data) {
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
const result = this.getParsed(id, data, parser) || {
|
|
213
|
+
pubkey: id,
|
|
214
|
+
account: data,
|
|
215
|
+
info: undefined,
|
|
216
|
+
};
|
|
217
|
+
// Only set the cache for defined static accounts. Static accounts can change if they go from nonexistant to existant.
|
|
218
|
+
// Rely on searchAndWatch to set the generic cache for everything else.
|
|
219
|
+
if (isStatic && result && result.info) {
|
|
220
|
+
this.updateCache(address, result);
|
|
221
|
+
}
|
|
222
|
+
return result;
|
|
223
|
+
});
|
|
224
|
+
this.pendingCalls.set(address, query);
|
|
225
|
+
return query;
|
|
226
|
+
}
|
|
227
|
+
onAccountChange(key, parser, account) {
|
|
228
|
+
const parsed = this.getParsed(key, account, parser);
|
|
229
|
+
const address = key.toBase58();
|
|
230
|
+
this.updateCache(address, parsed || null);
|
|
231
|
+
}
|
|
232
|
+
watch(id, parser, exists = true) {
|
|
233
|
+
const address = id.toBase58();
|
|
234
|
+
const isStatic = this.statics.has(address);
|
|
235
|
+
let oldCount = (this.accountWatchersCount.get(address) || 0) + 1;
|
|
236
|
+
this.accountWatchersCount.set(address, oldCount);
|
|
237
|
+
if (exists && !isStatic) {
|
|
238
|
+
// Only websocket watch accounts that exist
|
|
239
|
+
// Don't recreate listeners
|
|
240
|
+
if (!this.accountChangeListeners.has(address)) {
|
|
241
|
+
this.accountChangeListeners.set(address, this.connection.onAccountChange(id, (account) => this.onAccountChange(id, undefined, account), this.commitment));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else if (!exists) {
|
|
245
|
+
// Poll accounts that don't exist
|
|
246
|
+
this.missingAccounts.set(address, parser || this.missingAccounts.get(address));
|
|
247
|
+
}
|
|
248
|
+
return () => {
|
|
249
|
+
const newCount = this.accountWatchersCount.get(address) - 1;
|
|
250
|
+
this.accountWatchersCount.set(address, newCount);
|
|
251
|
+
if (newCount <= 0) {
|
|
252
|
+
const subscriptionId = this.accountChangeListeners.get(address);
|
|
253
|
+
if (subscriptionId) {
|
|
254
|
+
this.accountChangeListeners.delete(address);
|
|
255
|
+
this.connection.removeAccountChangeListener(subscriptionId);
|
|
256
|
+
}
|
|
257
|
+
this.missingAccounts.delete(address);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
async query(pubKey, parser) {
|
|
262
|
+
const ret = await this.search(pubKey, parser);
|
|
263
|
+
if (!ret) {
|
|
264
|
+
throw new Error("Account not found");
|
|
265
|
+
}
|
|
266
|
+
return ret;
|
|
267
|
+
}
|
|
268
|
+
getParsed(id, obj, parser) {
|
|
269
|
+
const address = typeof id === "string" ? id : id?.toBase58();
|
|
270
|
+
this.registerParser(id, parser);
|
|
271
|
+
const deserialize = (this.keyToAccountParser.get(address) ||
|
|
272
|
+
AccountFetchCache.defaultParser);
|
|
273
|
+
const account = deserialize(new PublicKey(address), obj);
|
|
274
|
+
if (!account) {
|
|
275
|
+
return {
|
|
276
|
+
pubkey: new PublicKey(id),
|
|
277
|
+
account: obj,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
return account;
|
|
281
|
+
}
|
|
282
|
+
get(pubKey) {
|
|
283
|
+
let key;
|
|
284
|
+
if (typeof pubKey !== "string") {
|
|
285
|
+
key = pubKey.toBase58();
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
key = pubKey;
|
|
289
|
+
}
|
|
290
|
+
return this.genericCache.get(key);
|
|
291
|
+
}
|
|
292
|
+
delete(pubKey) {
|
|
293
|
+
let key;
|
|
294
|
+
if (typeof pubKey !== "string") {
|
|
295
|
+
key = pubKey.toBase58();
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
key = pubKey;
|
|
299
|
+
}
|
|
300
|
+
const subId = this.accountChangeListeners.get(key);
|
|
301
|
+
if (subId) {
|
|
302
|
+
this.connection.removeAccountChangeListener(subId);
|
|
303
|
+
this.accountChangeListeners.delete(key);
|
|
304
|
+
}
|
|
305
|
+
if (this.genericCache.has(key)) {
|
|
306
|
+
this.genericCache.delete(key);
|
|
307
|
+
this.emitter.raiseCacheDeleted(key);
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
byParser(parser) {
|
|
313
|
+
const result = [];
|
|
314
|
+
for (const id of this.keyToAccountParser.keys()) {
|
|
315
|
+
if (this.keyToAccountParser.get(id) === parser) {
|
|
316
|
+
result.push(id);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return result;
|
|
320
|
+
}
|
|
321
|
+
registerParser(pubkey, parser) {
|
|
322
|
+
if (pubkey) {
|
|
323
|
+
const address = typeof pubkey === "string" ? pubkey : pubkey?.toBase58();
|
|
324
|
+
if (parser && !this.keyToAccountParser.get(address)) {
|
|
325
|
+
this.keyToAccountParser.set(address, parser);
|
|
326
|
+
const cached = this.genericCache.get(address);
|
|
327
|
+
if (cached) {
|
|
328
|
+
const parsed = parser(cached.pubkey, cached.account);
|
|
329
|
+
if (parsed) {
|
|
330
|
+
this.genericCache.set(address, parsed);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return pubkey;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
//# sourceMappingURL=accountFetchCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accountFetchCache.js","sourceRoot":"","sources":["../../../../src/accountFetchCache/accountFetchCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,SAAS,EAGT,WAAW,EAEZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AACrC,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAkBhC,SAAS,oBAAoB,CAC3B,YAAsC;IAEtC,OAAO,YAAY;SAChB,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SACtB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;SAC3B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC1B,CAAC;AAED,IAAI,EAAE,GAAG,CAAC,CAAC;AAEX,MAAM,OAAO,iBAAiB;IAC5B,UAAU,CAAa;IACvB,SAAS,CAAS;IAClB,KAAK,CAAS;IACd,UAAU,CAAa;IACvB,oBAAoB,GAAG,IAAI,GAAG,EAAkB,CAAC;IACjD,sBAAsB,GAAG,IAAI,GAAG,EAAkB,CAAC;IACnD,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5B,eAAe,GAAG,IAAI,GAAG,EAA8C,CAA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M,CAAC,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;YACzE,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;gBACnD,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;gBAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC9C,IAAI,MAAM,EAAE;oBACV,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;oBACrD,IAAI,MAAM,EAAE;wBACV,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;qBACxC;iBACF;aACF;SACF;QAED,OAAO,MAAM,CAAC;IAChB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EventEmitter as Emitter } from "eventemitter3";
|
|
2
|
+
export class CacheUpdateEvent {
|
|
3
|
+
static type = "CacheUpdate";
|
|
4
|
+
id;
|
|
5
|
+
parser;
|
|
6
|
+
isNew;
|
|
7
|
+
constructor(id, isNew, parser) {
|
|
8
|
+
this.id = id;
|
|
9
|
+
this.parser = parser;
|
|
10
|
+
this.isNew = isNew;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class CacheDeleteEvent {
|
|
14
|
+
static type = "CacheDelete";
|
|
15
|
+
id;
|
|
16
|
+
constructor(id) {
|
|
17
|
+
this.id = id;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export class EventEmitter {
|
|
21
|
+
emitter = new Emitter();
|
|
22
|
+
onCache(callback) {
|
|
23
|
+
this.emitter.on(CacheUpdateEvent.type, callback);
|
|
24
|
+
return () => this.emitter.removeListener(CacheUpdateEvent.type, callback);
|
|
25
|
+
}
|
|
26
|
+
raiseCacheUpdated(id, isNew, parser) {
|
|
27
|
+
this.emitter.emit(CacheUpdateEvent.type, new CacheUpdateEvent(id, isNew, parser));
|
|
28
|
+
}
|
|
29
|
+
raiseCacheDeleted(id) {
|
|
30
|
+
this.emitter.emit(CacheDeleteEvent.type, new CacheDeleteEvent(id));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=eventEmitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventEmitter.js","sourceRoot":"","sources":["../../../../src/accountFetchCache/eventEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,OAAO,EAAE,MAAM,eAAe,CAAC;AAExD,MAAM,OAAO,gBAAgB;IAC3B,MAAM,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,EAAE,CAAS;IACX,MAAM,CAAM;IACZ,KAAK,CAAU;IACf,YAAY,EAAU,EAAE,KAAc,EAAE,MAAW;QACjD,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;;AAGH,MAAM,OAAO,gBAAgB;IAC3B,MAAM,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,EAAE,CAAS;IACX,YAAY,EAAU;QACpB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;;AAGH,MAAM,OAAO,YAAY;IACf,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAEhC,OAAO,CAAC,QAA0C;QAChD,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAEjD,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC5E,CAAC;IAED,iBAAiB,CAAC,EAAU,EAAE,KAAc,EAAE,MAAW;QACvD,IAAI,CAAC,OAAO,CAAC,IAAI,CACf,gBAAgB,CAAC,IAAI,EACrB,IAAI,gBAAgB,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CACxC,CAAC;IACJ,CAAC;IAED,iBAAiB,CAAC,EAAU;QAC1B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC;IACrE,CAAC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
export const chunks = (array, size) => Array.apply(0, new Array(Math.ceil(array.length / size))).map((_, index) => array.slice(index * size, (index + 1) * size));
|
|
3
|
+
const getMultipleAccountsCore = async (connection, keys, commitment) => {
|
|
4
|
+
const args = connection._buildArgs([keys], commitment, "base64");
|
|
5
|
+
const unsafeRes = await connection._rpcRequest("getMultipleAccounts", args);
|
|
6
|
+
if (unsafeRes.error) {
|
|
7
|
+
throw new Error("failed to get info about account " + unsafeRes.error.message);
|
|
8
|
+
}
|
|
9
|
+
if (unsafeRes.result.value) {
|
|
10
|
+
const array = unsafeRes.result.value;
|
|
11
|
+
return { keys, array };
|
|
12
|
+
}
|
|
13
|
+
// TODO: fix
|
|
14
|
+
throw new Error();
|
|
15
|
+
};
|
|
16
|
+
export const getMultipleAccounts = async (connection, keys, commitment) => {
|
|
17
|
+
const result = await getMultipleAccountsCore(connection, keys, commitment);
|
|
18
|
+
const array = result.array.map((acc) => {
|
|
19
|
+
if (!acc) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const { data, ...rest } = acc;
|
|
23
|
+
const obj = {
|
|
24
|
+
...rest,
|
|
25
|
+
owner: rest.owner && new PublicKey(rest.owner),
|
|
26
|
+
data: Buffer.from(data[0], "base64"),
|
|
27
|
+
};
|
|
28
|
+
return obj;
|
|
29
|
+
});
|
|
30
|
+
return { keys, array };
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=getMultipleAccounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMultipleAccounts.js","sourceRoot":"","sources":["../../../../src/accountFetchCache/getMultipleAccounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAK,KAAU,EAAE,IAAY,EAAS,EAAE,CAC5D,KAAK,CAAC,KAAK,CACT,CAAC,EACD,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAC1C,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AAErE,MAAM,uBAAuB,GAAG,KAAK,EACnC,UAAe,EACf,IAAc,EACd,UAAkB,EAClB,EAAE;IACF,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IAEjE,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,WAAW,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;IAC5E,IAAI,SAAS,CAAC,KAAK,EAAE;QACnB,MAAM,IAAI,KAAK,CACb,mCAAmC,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,CAC9D,CAAC;KACH;IAED,IAAI,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE;QAC1B,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,KAAgC,CAAC;QAChE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;KACxB;IAED,YAAY;IACZ,MAAM,IAAI,KAAK,EAAE,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,UAAe,EACf,IAAc,EACd,UAAkB,EACyC,EAAE;IAC7D,MAAM,MAAM,GAAG,MAAM,uBAAuB,CAAC,UAAU,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;IAE3E,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACrC,IAAI,CAAC,GAAG,EAAE;YACR,OAAO,SAAS,CAAC;SAClB;QAED,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,GAAG,CAAC;QAC9B,MAAM,GAAG,GAAG;YACV,GAAG,IAAI;YACP,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;YAC9C,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC;SACd,CAAC;QACzB,OAAO,GAAG,CAAC;IACb,CAAC,CAA0B,CAAC;IAC5B,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACzB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/accountFetchCache/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { resolveIndividual } from "./individual";
|
|
2
|
+
import { getAssociatedTokenAddress } from "@solana/spl-token";
|
|
3
|
+
import { get } from "./utils";
|
|
4
|
+
export function ataResolver({ instruction, account, mint, owner, }) {
|
|
5
|
+
return resolveIndividual(async ({ path, accounts, idlIx }) => {
|
|
6
|
+
if (idlIx.name === instruction && path[path.length - 1] === account) {
|
|
7
|
+
const mintKey = get(accounts, [
|
|
8
|
+
...path.slice(0, path.length - 1),
|
|
9
|
+
mint,
|
|
10
|
+
]);
|
|
11
|
+
const ownerKey = get(accounts, [
|
|
12
|
+
...path.slice(0, path.length - 1),
|
|
13
|
+
owner,
|
|
14
|
+
]);
|
|
15
|
+
if (mintKey && ownerKey) {
|
|
16
|
+
return getAssociatedTokenAddress(mintKey, ownerKey, true);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=ataResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ataResolver.js","sourceRoot":"","sources":["../../../../src/accountsResolver/ataResolver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAS9B,MAAM,UAAU,WAAW,CAAuB,EAChD,WAAW,EACX,OAAO,EACP,IAAI,EACJ,KAAK,GACW;IAChB,OAAO,iBAAiB,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE;QAC3D,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,OAAO,EAAE;YACnE,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,EAAE;gBAC5B,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;gBACjC,IAAI;aACL,CAAc,CAAC;YAChB,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE;gBAC7B,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;gBACjC,KAAK;aACN,CAAc,CAAC;YAEhB,IAAI,OAAO,IAAI,QAAQ,EAAE;gBACvB,OAAO,yBAAyB,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;aAC3D;SACF;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function combineResolvers(...resolvers) {
|
|
2
|
+
return async (args) => {
|
|
3
|
+
let resolved = 0;
|
|
4
|
+
let accounts = args.accounts;
|
|
5
|
+
for (let i = 0; i < resolvers.length; i += 1) {
|
|
6
|
+
const resolver = resolvers[i];
|
|
7
|
+
const result = await resolver({ ...args, accounts });
|
|
8
|
+
accounts = result.accounts;
|
|
9
|
+
resolved += result.resolved;
|
|
10
|
+
}
|
|
11
|
+
return { accounts, resolved };
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=combineResolvers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combineResolvers.js","sourceRoot":"","sources":["../../../../src/accountsResolver/combineResolvers.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB,CAC9B,GAAG,SAA4C;IAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE;QACpB,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,IAAI,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;YAC5C,MAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YAC9B,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;YACrD,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;YAC3B,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC;SAC7B;QAED,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import camelCase from "camelcase";
|
|
2
|
+
import { get, set } from "./utils";
|
|
3
|
+
async function resolveIndividualImpl({ idlAccounts, programId, provider, args, accounts, path = [], resolver, idlIx, }) {
|
|
4
|
+
const newPath = [...path, camelCase(idlAccounts.name)];
|
|
5
|
+
if (idlAccounts.accounts) {
|
|
6
|
+
let resolved = 0;
|
|
7
|
+
const subAccounts = idlAccounts.accounts;
|
|
8
|
+
for (let k = 0; k < subAccounts.length; k += 1) {
|
|
9
|
+
const subAccount = subAccounts[k];
|
|
10
|
+
resolved += await resolveIndividualImpl({
|
|
11
|
+
idlAccounts: subAccount,
|
|
12
|
+
programId,
|
|
13
|
+
provider,
|
|
14
|
+
args,
|
|
15
|
+
accounts,
|
|
16
|
+
path: newPath,
|
|
17
|
+
resolver,
|
|
18
|
+
idlIx,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return resolved;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
let resolved = 0;
|
|
25
|
+
let value = get(accounts, newPath);
|
|
26
|
+
if (!value) {
|
|
27
|
+
value = await resolver({
|
|
28
|
+
programId,
|
|
29
|
+
provider,
|
|
30
|
+
path: newPath,
|
|
31
|
+
args,
|
|
32
|
+
accounts,
|
|
33
|
+
idlIx,
|
|
34
|
+
});
|
|
35
|
+
if (value) {
|
|
36
|
+
resolved = 1;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
set(accounts, newPath, value);
|
|
40
|
+
return resolved;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Allows custom account resolution by functionaly operating on one account at a time.
|
|
45
|
+
*
|
|
46
|
+
* Check the `path` arg to see the account name being operated on, and use `accounts` , `args` , and `provider` to fill in any
|
|
47
|
+
* details necessary
|
|
48
|
+
*
|
|
49
|
+
* @param resolver
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
export function resolveIndividual(resolver) {
|
|
53
|
+
return async ({ idlIx, args, accounts, programId, provider }) => {
|
|
54
|
+
let resolved = 0;
|
|
55
|
+
for (let k = 0; k < idlIx.accounts.length; k += 1) {
|
|
56
|
+
resolved += await resolveIndividualImpl({
|
|
57
|
+
idlAccounts: idlIx.accounts[k],
|
|
58
|
+
programId,
|
|
59
|
+
provider,
|
|
60
|
+
resolver,
|
|
61
|
+
args,
|
|
62
|
+
accounts,
|
|
63
|
+
idlIx,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
accounts,
|
|
68
|
+
resolved
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=individual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"individual.js","sourceRoot":"","sources":["../../../../src/accountsResolver/individual.ts"],"names":[],"mappings":"AAQA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAY,GAAG,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAW7C,KAAK,UAAU,qBAAqB,CAAC,EACnC,WAAW,EACX,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,IAAI,GAAG,EAAE,EACT,QAAQ,EACR,KAAK,GAUN;IACC,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,EAAE,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;IAEvD,IAAK,WAA2B,CAAC,QAAQ,EAAE;QACzC,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,MAAM,WAAW,GAAI,WAA2B,CAAC,QAAQ,CAAC;QAC1D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;YAC9C,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;YAElC,QAAQ,IAAI,MAAM,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
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function set(accounts, path, value) {
|
|
2
|
+
if (!value) {
|
|
3
|
+
return accounts;
|
|
4
|
+
}
|
|
5
|
+
let curr = accounts;
|
|
6
|
+
path.forEach((p, idx) => {
|
|
7
|
+
const isLast = idx == path.length - 1;
|
|
8
|
+
if (isLast) {
|
|
9
|
+
curr[p] = value;
|
|
10
|
+
}
|
|
11
|
+
curr[p] = curr[p] || {};
|
|
12
|
+
curr = curr[p];
|
|
13
|
+
});
|
|
14
|
+
return accounts;
|
|
15
|
+
}
|
|
16
|
+
export function get(accounts, path) {
|
|
17
|
+
// Only return if pubkey
|
|
18
|
+
const ret = path.reduce((acc, subPath) => {
|
|
19
|
+
if (acc) {
|
|
20
|
+
return acc[subPath];
|
|
21
|
+
}
|
|
22
|
+
}, accounts);
|
|
23
|
+
if (ret && ret.toBase58) {
|
|
24
|
+
return ret;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/accountsResolver/utils.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,GAAG,CACjB,QAAkB,EAClB,IAAc,EACd,KAA4B;IAE5B,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,QAAQ,CAAC;KACjB;IAED,IAAI,IAAI,GAAG,QAAQ,CAAC;IACpB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;QACtB,MAAM,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QACtC,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;SACjB;QAED,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,GAAG,IAAI,CAAC,CAAC,CAAa,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,QAAkB,EAAE,IAAc;IACpD,wBAAwB;IACxB,MAAM,GAAG,GAAqC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;QACzE,IAAI,GAAG,EAAE;YACP,OAAQ,GAAgB,CAAC,OAAO,CAAC,CAAC;SACnC;IACH,CAAC,EAAE,QAA4C,CAAC,CAAC;IAEjD,IAAI,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE;QACvB,OAAO,GAAgB,CAAC;KACzB;AACH,CAAC"}
|