@helium/account-fetch-cache
Advanced tools
Comparing version 0.6.28 to 0.6.29
@@ -102,6 +102,13 @@ "use strict"; | ||
const result = yield self.oldSendTransaction(...args); | ||
this.confirmTransaction(result, "finalized") | ||
// First try to requery when confirmed. Then mop up any that didn't change during confirmed. | ||
this.confirmTransaction(result, "confirmed") | ||
.then(() => { | ||
return self.requeryMissing(args[0].instructions); | ||
}) | ||
.then((unchanged) => __awaiter(this, void 0, void 0, function* () { | ||
if (unchanged.length > 0) { | ||
yield this.confirmTransaction(result, "finalized"); | ||
return self.requeryMissingByAccount(unchanged); | ||
} | ||
})) | ||
.catch(console.error); | ||
@@ -116,6 +123,13 @@ return result; | ||
const instructions = web3_js_1.Transaction.from(rawTransaction).instructions; | ||
this.confirmTransaction(result, "finalized") | ||
// First try to requery when confirmed. Then mop up any that didn't change during confirmed. | ||
this.confirmTransaction(result, "confirmed") | ||
.then(() => { | ||
return self.requeryMissing(instructions); | ||
}) | ||
.then((unchanged) => __awaiter(this, void 0, void 0, function* () { | ||
if (unchanged.length > 0) { | ||
yield this.confirmTransaction(result, "finalized"); | ||
return self.requeryMissingByAccount(unchanged); | ||
} | ||
})) | ||
.catch(console.error); | ||
@@ -131,9 +145,24 @@ } | ||
} | ||
// Requeries missin accounts and returns the ones that didn't change | ||
requeryMissing(instructions) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const writeableAccounts = getWriteableAccounts(instructions).map((a) => a.toBase58()); | ||
const writeableAccounts = Array.from(new Set(getWriteableAccounts(instructions).map((a) => a.toBase58()))); | ||
return this.requeryMissingByAccount(writeableAccounts.map(a => new web3_js_1.PublicKey(a))); | ||
}); | ||
} | ||
requeryMissingByAccount(accounts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const writeableAccounts = accounts.map(a => a.toBase58()); | ||
const unchanged = []; | ||
yield Promise.all(writeableAccounts.map((account) => __awaiter(this, void 0, void 0, function* () { | ||
const parser = this.missingAccounts.get(account); | ||
const prevAccount = this.genericCache.get(account); | ||
const [found, dispose] = yield this.searchAndWatch(new web3_js_1.PublicKey(account), parser, this.statics.has(account), true); | ||
dispose(); | ||
const changed = (prevAccount && !found) || | ||
(found && !prevAccount) || | ||
(prevAccount && !(found === null || found === void 0 ? void 0 : found.account.data.equals(prevAccount.account.data))); | ||
if (!changed) { | ||
unchanged.push(new web3_js_1.PublicKey(account)); | ||
} | ||
if (found) { | ||
@@ -143,2 +172,3 @@ this.missingAccounts.delete(account); | ||
}))); | ||
return unchanged; | ||
}); | ||
@@ -399,3 +429,5 @@ } | ||
try { | ||
this.accountChangeListeners.set(address, this.connection.onAccountChange(id, (account) => this.onAccountChange(id, undefined, account), this.commitment)); | ||
this.accountChangeListeners.set(address, this.connection.onAccountChange(id, (account) => { | ||
this.onAccountChange(id, undefined, account); | ||
}, this.commitment)); | ||
} | ||
@@ -402,0 +434,0 @@ catch (e) { |
@@ -96,6 +96,13 @@ import { Connection, PublicKey, Transaction, } from "@solana/web3.js"; | ||
const result = await self.oldSendTransaction(...args); | ||
this.confirmTransaction(result, "finalized") | ||
// First try to requery when confirmed. Then mop up any that didn't change during confirmed. | ||
this.confirmTransaction(result, "confirmed") | ||
.then(() => { | ||
return self.requeryMissing(args[0].instructions); | ||
}) | ||
.then(async (unchanged) => { | ||
if (unchanged.length > 0) { | ||
await this.confirmTransaction(result, "finalized"); | ||
return self.requeryMissingByAccount(unchanged); | ||
} | ||
}) | ||
.catch(console.error); | ||
@@ -108,6 +115,13 @@ return result; | ||
const instructions = Transaction.from(rawTransaction).instructions; | ||
this.confirmTransaction(result, "finalized") | ||
// First try to requery when confirmed. Then mop up any that didn't change during confirmed. | ||
this.confirmTransaction(result, "confirmed") | ||
.then(() => { | ||
return self.requeryMissing(instructions); | ||
}) | ||
.then(async (unchanged) => { | ||
if (unchanged.length > 0) { | ||
await this.confirmTransaction(result, "finalized"); | ||
return self.requeryMissingByAccount(unchanged); | ||
} | ||
}) | ||
.catch(console.error); | ||
@@ -122,8 +136,21 @@ } | ||
} | ||
// Requeries missin accounts and returns the ones that didn't change | ||
async requeryMissing(instructions) { | ||
const writeableAccounts = getWriteableAccounts(instructions).map((a) => a.toBase58()); | ||
const writeableAccounts = Array.from(new Set(getWriteableAccounts(instructions).map((a) => a.toBase58()))); | ||
return this.requeryMissingByAccount(writeableAccounts.map(a => new PublicKey(a))); | ||
} | ||
async requeryMissingByAccount(accounts) { | ||
const writeableAccounts = accounts.map(a => a.toBase58()); | ||
const unchanged = []; | ||
await Promise.all(writeableAccounts.map(async (account) => { | ||
const parser = this.missingAccounts.get(account); | ||
const prevAccount = this.genericCache.get(account); | ||
const [found, dispose] = await this.searchAndWatch(new PublicKey(account), parser, this.statics.has(account), true); | ||
dispose(); | ||
const changed = (prevAccount && !found) || | ||
(found && !prevAccount) || | ||
(prevAccount && !found?.account.data.equals(prevAccount.account.data)); | ||
if (!changed) { | ||
unchanged.push(new PublicKey(account)); | ||
} | ||
if (found) { | ||
@@ -133,2 +160,3 @@ this.missingAccounts.delete(account); | ||
})); | ||
return unchanged; | ||
} | ||
@@ -376,3 +404,5 @@ async fetchMissing() { | ||
try { | ||
this.accountChangeListeners.set(address, this.connection.onAccountChange(id, (account) => this.onAccountChange(id, undefined, account), this.commitment)); | ||
this.accountChangeListeners.set(address, this.connection.onAccountChange(id, (account) => { | ||
this.onAccountChange(id, undefined, account); | ||
}, this.commitment)); | ||
} | ||
@@ -379,0 +409,0 @@ catch (e) { |
@@ -61,3 +61,4 @@ /// <reference types="node" /> | ||
}); | ||
requeryMissing(instructions: TransactionInstruction[]): Promise<void>; | ||
requeryMissing(instructions: TransactionInstruction[]): Promise<PublicKey[]>; | ||
requeryMissingByAccount(accounts: PublicKey[]): Promise<PublicKey[]>; | ||
fetchMissing(): Promise<void>; | ||
@@ -64,0 +65,0 @@ close(): void; |
{ | ||
"name": "@helium/account-fetch-cache", | ||
"version": "0.6.28", | ||
"version": "0.6.29", | ||
"description": "Solana account fetch cache to eliminate reduntant fetching, and batch fetches", | ||
@@ -41,3 +41,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "98f0e037b4b35f87dcb3b55c6baf60522695e447" | ||
"gitHead": "058b6d73f1331bff296f1c9fd287f192163df833" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
156954
1397
3
113