Browse Source

fix: Remove TypesCoder (#859)

Susmitha Kodamarthi 4 years ago
parent
commit
a845af21af
3 changed files with 0 additions and 54 deletions
  1. 0 8
      ts/src/coder/index.ts
  2. 0 45
      ts/src/coder/types.ts
  3. 0 1
      ts/src/index.ts

+ 0 - 8
ts/src/coder/index.ts

@@ -1,13 +1,11 @@
 import { Idl } from "../idl";
 import { InstructionCoder } from "./instruction";
 import { AccountsCoder } from "./accounts";
-import { TypesCoder } from "./types";
 import { EventCoder } from "./event";
 import { StateCoder } from "./state";
 import { sighash } from "./common";
 
 export { accountSize } from "./common";
-export { TypesCoder } from "./types";
 export { InstructionCoder } from "./instruction";
 export { AccountsCoder, ACCOUNT_DISCRIMINATOR_SIZE } from "./accounts";
 export { EventCoder, eventDiscriminator } from "./event";
@@ -27,11 +25,6 @@ export default class Coder<A extends string = string> {
    */
   readonly accounts: AccountsCoder<A>;
 
-  /**
-   * Types coder.
-   */
-  readonly types: TypesCoder;
-
   /**
    * Coder for state structs.
    */
@@ -45,7 +38,6 @@ export default class Coder<A extends string = string> {
   constructor(idl: Idl) {
     this.instruction = new InstructionCoder(idl);
     this.accounts = new AccountsCoder(idl);
-    this.types = new TypesCoder(idl);
     this.events = new EventCoder(idl);
     if (idl.state) {
       this.state = new StateCoder(idl);

+ 0 - 45
ts/src/coder/types.ts

@@ -1,45 +0,0 @@
-import { Layout } from "buffer-layout";
-import { Idl } from "../idl";
-import { IdlCoder } from "./idl";
-
-/**
- * Encodes and decodes user defined types.
- */
-export class TypesCoder {
-  /**
-   * Maps account type identifier to a layout.
-   */
-  private layouts: Map<string, Layout>;
-
-  public constructor(idl: Idl) {
-    if (idl.types === undefined) {
-      this.layouts = new Map();
-      return;
-    }
-    const types = idl.types;
-    const layouts = types.map((acc) => {
-      return [acc.name, IdlCoder.typeDefLayout(acc, types)];
-    });
-
-    // @ts-ignore
-    this.layouts = new Map(layouts);
-  }
-
-  public encode<T = any>(accountName: string, account: T): Buffer {
-    const buffer = Buffer.alloc(1000); // TODO: use a tighter buffer.
-    const layout = this.layouts.get(accountName);
-    if (!layout) {
-      throw new Error(`Unknown account type: ${accountName}`);
-    }
-    const len = layout.encode(account, buffer);
-    return buffer.slice(0, len);
-  }
-
-  public decode<T = any>(accountName: string, ix: Buffer): T {
-    const layout = this.layouts.get(accountName);
-    if (!layout) {
-      throw new Error(`Unknown account type: ${accountName}`);
-    }
-    return layout.decode(ix);
-  }
-}

+ 0 - 1
ts/src/index.ts

@@ -11,7 +11,6 @@ export {
   InstructionCoder,
   EventCoder,
   StateCoder,
-  TypesCoder,
   AccountsCoder,
 } from "./coder";