Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@helium/account-fetch-cache

Package Overview
Dependencies
Maintainers
7
Versions
169
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@helium/account-fetch-cache - npm Package Compare versions

Comparing version 0.6.23 to 0.6.24-next.3

40

lib/cjs/accountFetchCache.js

@@ -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) {

3

lib/types/src/accountFetchCache.d.ts

@@ -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.23",
"version": "0.6.24-next.3+34a3b1bb",
"description": "Solana account fetch cache to eliminate reduntant fetching, and batch fetches",

@@ -41,3 +41,3 @@ "publishConfig": {

},
"gitHead": "eaafe267577259470a3856e6495d380a24807cf9"
"gitHead": "34a3b1bb6b7cf068a1d69f882be3b1efe16acf24"
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc