ts prettier

This commit is contained in:
Armani Ferrante 2022-02-21 13:05:42 -05:00
parent e9f8623337
commit 900cc7389a
No known key found for this signature in database
GPG Key ID: D597A80BCF8E12B7
2 changed files with 12 additions and 10 deletions

View File

@ -35,12 +35,12 @@ export class BorshStateCoder {
return this.layout.decode(data); return this.layout.decode(data);
} }
// Calculates unique 8 byte discriminator prepended to all anchor state accounts. // Calculates unique 8 byte discriminator prepended to all anchor state accounts.
async discriminator(name: string): Promise<Buffer> { async discriminator(name: string): Promise<Buffer> {
let ns = features.isSet("anchor-deprecated-state") ? "account" : "state"; let ns = features.isSet("anchor-deprecated-state") ? "account" : "state";
return Buffer.from(sha256.digest(`${ns}:${name}`)).slice( return Buffer.from(sha256.digest(`${ns}:${name}`)).slice(
0, 0,
this.header.discriminatorSize() this.header.discriminatorSize()
); );
} }
} }

View File

@ -85,7 +85,7 @@ export class StateClient<IDL extends Idl> {
public readonly provider: Provider = getProvider(), public readonly provider: Provider = getProvider(),
/** /**
* Returns the coder. Note that we use BorshCoder and not `Coder` because * Returns the coder. Note that we use BorshCoder and not `Coder` because
* the deprecated state abstraction only applies to Anchor programs. * the deprecated state abstraction only applies to Anchor programs.
*/ */
public readonly coder: BorshCoder = new BorshCoder(idl) public readonly coder: BorshCoder = new BorshCoder(idl)
) { ) {
@ -173,7 +173,9 @@ export class StateClient<IDL extends Idl> {
throw new Error("State is not specified in IDL."); throw new Error("State is not specified in IDL.");
} }
const expectedDiscriminator = await this.coder.state.discriminator(state.struct.name); const expectedDiscriminator = await this.coder.state.discriminator(
state.struct.name
);
const discriminator = this.coder.state.header.parseDiscriminator( const discriminator = this.coder.state.header.parseDiscriminator(
accountInfo.data accountInfo.data
); );