ts: Use hex by default for decoding Instruction (#547)

This commit is contained in:
Kirill Fomichev 2021-07-24 20:59:12 +03:00 committed by GitHub
parent 0998422348
commit 8dc7bed4ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -13,6 +13,7 @@ incremented for features.
### Breaking Changes
* ts: Use `hex` by default for decoding Instruction ([#547](https://github.com/project-serum/anchor/pull/547)).
* lang: `CpiAccount::reload` mutates the existing struct instead of returning a new one ([#526](https://github.com/project-serum/anchor/pull/526)).
## [0.11.1] - 2021-07-09

View File

@ -109,9 +109,12 @@ export class InstructionCoder {
/**
* Dewcodes a program instruction.
*/
public decode(ix: Buffer | string): Instruction | null {
public decode(
ix: Buffer | string,
encoding: "hex" | "base58" = "hex"
): Instruction | null {
if (typeof ix === "string") {
ix = bs58.decode(ix);
ix = encoding === "hex" ? Buffer.from(ix, "hex") : bs58.decode(ix);
}
let sighash = bs58.encode(ix.slice(0, 8));
let data = ix.slice(8);