diff --git a/ts/src/coder/accounts.ts b/ts/src/coder/accounts.ts index 5b86ea6b..c81eb466 100644 --- a/ts/src/coder/accounts.ts +++ b/ts/src/coder/accounts.ts @@ -11,28 +11,25 @@ export const ACCOUNT_DISCRIMINATOR_SIZE = 8; /** * Encodes and decodes account objects. */ -export class AccountsCoder { +export class AccountsCoder { /** * Maps account type identifier to a layout. */ - private accountLayouts: Map; + private accountLayouts: Map; public constructor(idl: Idl) { if (idl.accounts === undefined) { this.accountLayouts = new Map(); return; } - const layouts: [string, Layout][] = idl.accounts.map((acc) => { - return [acc.name, IdlCoder.typeDefLayout(acc, idl.types)]; + const layouts: [A, Layout][] = idl.accounts.map((acc) => { + return [acc.name as A, IdlCoder.typeDefLayout(acc, idl.types)]; }); this.accountLayouts = new Map(layouts); } - public async encode( - accountName: string, - account: T - ): Promise { + public async encode(accountName: A, account: T): Promise { const buffer = Buffer.alloc(1000); // TODO: use a tighter buffer. const layout = this.accountLayouts.get(accountName); if (!layout) { @@ -44,7 +41,7 @@ export class AccountsCoder { return Buffer.concat([discriminator, accountData]); } - public decode(accountName: string, ix: Buffer): T { + public decode(accountName: A, ix: Buffer): T { // Chop off the discriminator before decoding. const data = ix.slice(8); const layout = this.accountLayouts.get(accountName); diff --git a/ts/src/coder/index.ts b/ts/src/coder/index.ts index e0ececbe..4e9eba17 100644 --- a/ts/src/coder/index.ts +++ b/ts/src/coder/index.ts @@ -20,7 +20,7 @@ export { StateCoder, stateDiscriminator } from "./state"; /** * Coder provides a facade for encoding and decoding all IDL related objects. */ -export default class Coder { +export default class Coder { /** * Instruction coder. */ @@ -29,7 +29,7 @@ export default class Coder { /** * Account coder. */ - readonly accounts: AccountsCoder; + readonly accounts: AccountsCoder; /** * Types coder.