function solanaAccountCount(block) {
const accountCounts = {};
for (const tx of block.transactions) {
if (tx.meta.err) continue;
const allAccounts = tx.transaction.message.accountKeys
.concat(tx.meta.loadedAddresses.writable)
.concat(tx.meta.loadedAddresses.readonly);
for (const acc of allAccounts) {
if (!accountCounts[acc]) {
accountCounts[acc] = 0;
}
}
const allInstructions = tx.transaction.message.instructions.concat(
tx.meta.innerInstructions.map((ii) => ii.instructions).flat()
);
for (const inst of allInstructions) {
for (const accIdx of inst.accounts) {
accountCounts[allAccounts[accIdx]] += 1;
}
}
}
return Object.entries(accountCounts).map(([account, count]) => ({ account, count }));
}