Browse Source

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

Kirill Fomichev 4 years ago
parent
commit
8dc7bed4ef
2 changed files with 6 additions and 2 deletions
  1. 1 0
      CHANGELOG.md
  2. 5 2
      ts/src/coder/instruction.ts

+ 1 - 0
CHANGELOG.md

@@ -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

+ 5 - 2
ts/src/coder/instruction.ts

@@ -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);