From ec26966340729c7ce3d22509355254c7d9ee5b2a Mon Sep 17 00:00:00 2001 From: Matthew Callens Date: Wed, 27 Oct 2021 14:09:40 -0400 Subject: [PATCH] ts: Capitalize account discriminator in `AccountCoder` (#931) --- ts/src/coder/accounts.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ts/src/coder/accounts.ts b/ts/src/coder/accounts.ts index cfa7d404..983e404e 100644 --- a/ts/src/coder/accounts.ts +++ b/ts/src/coder/accounts.ts @@ -2,6 +2,7 @@ import { Layout } from "buffer-layout"; import { Idl } from "../idl"; import { IdlCoder } from "./idl"; import { sha256 } from "js-sha256"; +import camelcase from "camelcase"; /** * Number of bytes of the account discriminator. @@ -43,7 +44,7 @@ export class AccountsCoder { public decode(accountName: A, ix: Buffer): T { // Chop off the discriminator before decoding. - const data = ix.slice(8); + const data = ix.slice(ACCOUNT_DISCRIMINATOR_SIZE); const layout = this.accountLayouts.get(accountName); if (!layout) { throw new Error(`Unknown account: ${accountName}`); @@ -57,6 +58,8 @@ export class AccountsCoder { * @param name The name of the account to calculate the discriminator. */ public static accountDiscriminator(name: string): Buffer { - return Buffer.from(sha256.digest(`account:${name}`)).slice(0, 8); + return Buffer.from( + sha256.digest(`account:${camelcase(name, { pascalCase: true })}`) + ).slice(0, ACCOUNT_DISCRIMINATOR_SIZE); } }