reload mango account with slot

This commit is contained in:
tjs 2022-09-05 12:31:57 -04:00
parent 2d0772833b
commit 27c42e70e9
2 changed files with 24 additions and 0 deletions

View File

@ -86,6 +86,16 @@ export class MangoAccount {
return mangoAccount;
}
async reloadWithSlot(
client: MangoClient,
group: Group,
): Promise<{ value: MangoAccount; slot: number }> {
const resp = await client.getMangoAccountWithSlot(this.publicKey);
await resp?.value.reloadAccountData(client, group);
Object.assign(this, resp?.value);
return { value: resp!.value, slot: resp!.slot };
}
async reloadAccountData(
client: MangoClient,
group: Group,

View File

@ -608,6 +608,20 @@ export class MangoClient {
);
}
public async getMangoAccountWithSlot(mangoAccountPk: PublicKey) {
const resp =
await this.program.provider.connection.getAccountInfoAndContext(
mangoAccountPk,
);
if (!resp?.value) return;
const decodedMangoAccount = this.program.coder.accounts.decode(
'mangoAccount',
resp.value.data,
);
const mangoAccount = MangoAccount.from(mangoAccountPk, decodedMangoAccount);
return { slot: resp.context.slot, value: mangoAccount };
}
public async getMangoAccountForOwner(
group: Group,
ownerPk: PublicKey,