Browse Source

ts: Assign namespaces correctly (#272)

Armani Ferrante 4 years ago
parent
commit
e4a1b3cb52
2 changed files with 13 additions and 15 deletions
  1. 1 1
      ts/src/program/index.ts
  2. 12 14
      ts/src/program/namespace/index.ts

+ 1 - 1
ts/src/program/index.ts

@@ -65,7 +65,7 @@ export class Program {
    * const txSignature = await program.rpc.increment({
    *   accounts: {
    *     counter,
-	 *     authority,
+   *     authority,
    *   },
    * });
    * ```

+ 12 - 14
ts/src/program/namespace/index.ts

@@ -21,9 +21,7 @@ export { SimulateNamespace } from "./simulate";
 
 export default class NamespaceFactory {
   /**
-   * build dynamically generates RPC methods.
-   *
-   * @returns an object with all the RPC methods attached.
+   * Generates all namespaces for a given program.
    */
   public static build(
     idl: Idl,
@@ -54,12 +52,12 @@ export default class NamespaceFactory {
     );
 
     idl.instructions.forEach((idlIx) => {
-      const ix = InstructionFactory.build(idlIx, coder, programId);
-      const tx = TransactionFactory.build(idlIx, ix);
-      const rpc = RpcFactory.build(idlIx, tx, idlErrors, provider);
-      const simulate = SimulateFactory.build(
+      const ixItem = InstructionFactory.build(idlIx, coder, programId);
+      const txItem = TransactionFactory.build(idlIx, ixItem);
+      const rpcItem = RpcFactory.build(idlIx, txItem, idlErrors, provider);
+      const simulateItem = SimulateFactory.build(
         idlIx,
-        tx,
+        txItem,
         idlErrors,
         provider,
         coder,
@@ -69,16 +67,16 @@ export default class NamespaceFactory {
 
       const name = camelCase(idlIx.name);
 
-      instruction[name] = ix;
-      transaction[name] = tx;
-      rpc[name] = rpc;
-      simulate[name] = simulate;
+      instruction[name] = ixItem;
+      transaction[name] = txItem;
+      rpc[name] = rpcItem;
+      simulate[name] = simulateItem;
     });
 
-    const accountFns = idl.accounts
+    const account = idl.accounts
       ? AccountFactory.build(idl, coder, programId, provider)
       : {};
 
-    return [rpc, instruction, transaction, accountFns, state, simulate];
+    return [rpc, instruction, transaction, account, state, simulate];
   }
 }