Merge pull request #214 from blockworks-foundation/ts/reload-slot
reload mango account with slot
This commit is contained in:
commit
3e462c5530
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue