@helium/account-fetch-cache
Advanced tools
Comparing version 0.7.4 to 0.7.5
@@ -20,2 +20,3 @@ "use strict"; | ||
__exportStar(require("./getMultipleAccounts"), exports); | ||
__exportStar(require("./transactionCompletionQueue"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -16,2 +16,3 @@ "use strict"; | ||
const getMultipleAccounts_1 = require("./getMultipleAccounts"); | ||
const transactionCompletionQueue_1 = require("./transactionCompletionQueue"); | ||
exports.DEFAULT_CHUNK_SIZE = 99; | ||
@@ -100,2 +101,6 @@ exports.DEFAULT_DELAY = 50; | ||
} | ||
const queue = new transactionCompletionQueue_1.TransactionCompletionQueue({ | ||
connection, | ||
log: this.enableLogging, | ||
}); | ||
connection.sendTransaction = function overloadedSendTransaction(...args) { | ||
@@ -105,9 +110,13 @@ return __awaiter(this, void 0, void 0, function* () { | ||
// 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); | ||
}) | ||
queue | ||
.wait("confirmed", result) | ||
.then(() => __awaiter(this, void 0, void 0, function* () { | ||
const instructions = args[0].instructions | ||
? args[0].instructions | ||
: yield getInstructions(connection, args[0]); | ||
return self.requeryMissing(instructions); | ||
})) | ||
.then((unchanged) => __awaiter(this, void 0, void 0, function* () { | ||
if (unchanged.length > 0) { | ||
yield this.confirmTransaction(result, "finalized"); | ||
yield queue.wait("finalized", result); | ||
return self.requeryMissingByAccount(unchanged); | ||
@@ -124,5 +133,7 @@ } | ||
try { | ||
const instructions = web3_js_1.Transaction.from(rawTransaction).instructions; | ||
const message = web3_js_1.VersionedTransaction.deserialize(new Uint8Array(rawTransaction)).message; | ||
const instructions = yield getInstructions(connection, message); | ||
// First try to requery when confirmed. Then mop up any that didn't change during confirmed. | ||
this.confirmTransaction(result, "confirmed") | ||
queue | ||
.wait("confirmed", result) | ||
.then(() => { | ||
@@ -133,3 +144,3 @@ return self.requeryMissing(instructions); | ||
if (unchanged.length > 0) { | ||
yield this.confirmTransaction(result, "finalized"); | ||
yield queue.wait("finalized", result); | ||
return self.requeryMissingByAccount(unchanged); | ||
@@ -152,3 +163,3 @@ } | ||
const writeableAccounts = Array.from(new Set(getWriteableAccounts(instructions).map((a) => a.toBase58()))); | ||
return this.requeryMissingByAccount(writeableAccounts.map(a => new web3_js_1.PublicKey(a))); | ||
return this.requeryMissingByAccount(writeableAccounts.map((a) => new web3_js_1.PublicKey(a))); | ||
}); | ||
@@ -158,3 +169,3 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const writeableAccounts = accounts.map(a => a.toBase58()); | ||
const writeableAccounts = accounts.map((a) => a.toBase58()); | ||
const unchanged = []; | ||
@@ -168,3 +179,4 @@ yield Promise.all(writeableAccounts.map((account) => __awaiter(this, void 0, void 0, function* () { | ||
(found && !prevAccount) || | ||
(prevAccount && !(found === null || found === void 0 ? void 0 : found.account.data.equals(prevAccount.account.data))); | ||
(prevAccount && | ||
!(found === null || found === void 0 ? void 0 : found.account.data.equals(prevAccount.account.data))); | ||
if (!changed) { | ||
@@ -209,2 +221,5 @@ unchanged.push(new web3_js_1.PublicKey(account)); | ||
const keys = Array.from(currentBatch); | ||
if (keys.length === 0) { | ||
return { keys: [], array: [] }; | ||
} | ||
const { array } = yield (0, getMultipleAccounts_1.getMultipleAccounts)(this.connection, keys, this.commitment); | ||
@@ -569,2 +584,21 @@ keys.forEach((key, index) => { | ||
}); | ||
function getInstructions(connection, message) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const LUTs = (yield Promise.all(message.addressTableLookups.map((acc) => connection.getAddressLookupTable(acc.accountKey)))) | ||
.map((lut) => lut.value) | ||
.filter((val) => val !== null); | ||
const allAccs = message.getAccountKeys({ addressLookupTableAccounts: LUTs }); | ||
return message.compiledInstructions.map((ix) => { | ||
return new web3_js_1.TransactionInstruction({ | ||
programId: allAccs.get(ix.programIdIndex), | ||
data: Buffer.from(ix.data), | ||
keys: ix.accountKeyIndexes.map((key) => ({ | ||
pubkey: allAccs.get(key), | ||
isSigner: message.isAccountSigner(key), | ||
isWritable: message.isAccountWritable(key), | ||
})), | ||
}); | ||
}); | ||
}); | ||
} | ||
//# sourceMappingURL=accountFetchCache.js.map |
@@ -20,2 +20,3 @@ "use strict"; | ||
__exportStar(require("./getMultipleAccounts"), exports); | ||
__exportStar(require("./transactionCompletionQueue"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,5 @@ | ||
import { Connection, PublicKey, Transaction, } from "@solana/web3.js"; | ||
import { Connection, PublicKey, TransactionInstruction, VersionedTransaction, } from "@solana/web3.js"; | ||
import { EventEmitter } from "./eventEmitter"; | ||
import { getMultipleAccounts } from "./getMultipleAccounts"; | ||
import { TransactionCompletionQueue } from "./transactionCompletionQueue"; | ||
export const DEFAULT_CHUNK_SIZE = 99; | ||
@@ -94,12 +95,20 @@ export const DEFAULT_DELAY = 50; | ||
} | ||
const queue = new TransactionCompletionQueue({ | ||
connection, | ||
log: this.enableLogging, | ||
}); | ||
connection.sendTransaction = async function overloadedSendTransaction(...args) { | ||
const result = await self.oldSendTransaction(...args); | ||
// 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); | ||
queue | ||
.wait("confirmed", result) | ||
.then(async () => { | ||
const instructions = args[0].instructions | ||
? args[0].instructions | ||
: await getInstructions(connection, args[0]); | ||
return self.requeryMissing(instructions); | ||
}) | ||
.then(async (unchanged) => { | ||
if (unchanged.length > 0) { | ||
await this.confirmTransaction(result, "finalized"); | ||
await queue.wait("finalized", result); | ||
return self.requeryMissingByAccount(unchanged); | ||
@@ -114,5 +123,7 @@ } | ||
try { | ||
const instructions = Transaction.from(rawTransaction).instructions; | ||
const message = VersionedTransaction.deserialize(new Uint8Array(rawTransaction)).message; | ||
const instructions = await getInstructions(connection, message); | ||
// First try to requery when confirmed. Then mop up any that didn't change during confirmed. | ||
this.confirmTransaction(result, "confirmed") | ||
queue | ||
.wait("confirmed", result) | ||
.then(() => { | ||
@@ -123,3 +134,3 @@ return self.requeryMissing(instructions); | ||
if (unchanged.length > 0) { | ||
await this.confirmTransaction(result, "finalized"); | ||
await queue.wait("finalized", result); | ||
return self.requeryMissingByAccount(unchanged); | ||
@@ -140,6 +151,6 @@ } | ||
const writeableAccounts = Array.from(new Set(getWriteableAccounts(instructions).map((a) => a.toBase58()))); | ||
return this.requeryMissingByAccount(writeableAccounts.map(a => new PublicKey(a))); | ||
return this.requeryMissingByAccount(writeableAccounts.map((a) => new PublicKey(a))); | ||
} | ||
async requeryMissingByAccount(accounts) { | ||
const writeableAccounts = accounts.map(a => a.toBase58()); | ||
const writeableAccounts = accounts.map((a) => a.toBase58()); | ||
const unchanged = []; | ||
@@ -153,3 +164,4 @@ await Promise.all(writeableAccounts.map(async (account) => { | ||
(found && !prevAccount) || | ||
(prevAccount && !found?.account.data.equals(prevAccount.account.data)); | ||
(prevAccount && | ||
!found?.account.data.equals(prevAccount.account.data)); | ||
if (!changed) { | ||
@@ -190,2 +202,5 @@ unchanged.push(new PublicKey(account)); | ||
const keys = Array.from(currentBatch); | ||
if (keys.length === 0) { | ||
return { keys: [], array: [] }; | ||
} | ||
const { array } = await getMultipleAccounts(this.connection, keys, this.commitment); | ||
@@ -534,2 +549,19 @@ keys.forEach((key, index) => { | ||
} | ||
async function getInstructions(connection, message) { | ||
const LUTs = (await Promise.all(message.addressTableLookups.map((acc) => connection.getAddressLookupTable(acc.accountKey)))) | ||
.map((lut) => lut.value) | ||
.filter((val) => val !== null); | ||
const allAccs = message.getAccountKeys({ addressLookupTableAccounts: LUTs }); | ||
return message.compiledInstructions.map((ix) => { | ||
return new TransactionInstruction({ | ||
programId: allAccs.get(ix.programIdIndex), | ||
data: Buffer.from(ix.data), | ||
keys: ix.accountKeyIndexes.map((key) => ({ | ||
pubkey: allAccs.get(key), | ||
isSigner: message.isAccountSigner(key), | ||
isWritable: message.isAccountWritable(key), | ||
})), | ||
}); | ||
}); | ||
} | ||
//# sourceMappingURL=accountFetchCache.js.map |
export * from "./accountFetchCache"; | ||
export * from "./eventEmitter"; | ||
export * from "./getMultipleAccounts"; | ||
export * from "./transactionCompletionQueue"; | ||
//# sourceMappingURL=index.js.map |
export * from "./accountFetchCache"; | ||
export * from "./eventEmitter"; | ||
export * from "./getMultipleAccounts"; | ||
export * from "./transactionCompletionQueue"; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@helium/account-fetch-cache", | ||
"version": "0.7.4", | ||
"version": "0.7.5", | ||
"description": "Solana account fetch cache to eliminate reduntant fetching, and batch fetches", | ||
@@ -41,3 +41,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "f5cd80427e87d0ba32d0fec033355ffa9e8d8432" | ||
"gitHead": "4d776e26f84709b13e3ae11837f9b0d7db85498c" | ||
} |
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
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
189561
40
1802
6