getAccountData
This function is required to be implemented by the app developer for internal use by shardus. It takes in 3 parameters.
accountStartThe start of accountId's in the range shardus wants to grab fromaccountEndThe end of accountId's in the range shardus wants to grab frommaxRecordsThe maximum number of account records shardus wants to get back from the function
Because shardus allows you to use whatever kind of database you choose, this is required by the app developer to implement so shardus can grab the account data for it's internal uses.
getAccountData(accountStart, accountEnd, maxRecords) {
const results = [];
const start = parseInt(accountStart, 16);
const end = parseInt(accountEnd, 16);
// Loop all accounts
for (const account of Object.values(accounts)) {
// Skip if not in account id range
const id = parseInt(account.id, 16);
if (id < start || id > end) continue;
// Add to results
const wrapped = {
accountId: account.id,
stateId: account.hash,
data: account,
timestamp: account.timestamp
};
results.push(wrapped);
// Return results early if maxRecords reached
if (results.length >= maxRecords) return results;
}
return results;
}This example uses a local, in-memory
accountsobject to store account data, but you can use whatever you wish.