Browse Source

ts: Remove console logs from Node package (#1031)

Swift 3 years ago
parent
commit
e7e8f4da9b

+ 0 - 7
ts/src/program/context.ts

@@ -50,13 +50,6 @@ export type Context<A extends Accounts = Accounts> = {
    * Commitment parameters to use for a transaction.
    */
   options?: ConfirmOptions;
-
-  /**
-   * @hidden
-   *
-   * Private namespace for development.
-   */
-  __private?: { logAccounts: boolean };
 };
 
 /**

+ 3 - 1
ts/src/program/namespace/instruction.ts

@@ -18,6 +18,7 @@ import {
   Address,
 } from "../common";
 import { Accounts, splitArgsAndCtx } from "../context";
+import * as features from "../../utils/features";
 import {
   AllInstructions,
   AllInstructionsMap,
@@ -49,9 +50,10 @@ export default class InstructionNamespaceFactory {
         keys.push(...ctx.remainingAccounts);
       }
 
-      if (ctx.__private && ctx.__private.logAccounts) {
+      if (features.isSet("debug-logs")) {
         console.log("Outgoing account metas:", keys);
       }
+
       return new TransactionInstruction({
         keys,
         programId,

+ 5 - 1
ts/src/program/namespace/rpc.ts

@@ -4,6 +4,7 @@ import { Idl } from "../../idl";
 import { splitArgsAndCtx } from "../context";
 import { TransactionFn } from "./transaction";
 import { ProgramError } from "../../error";
+import * as features from "../../utils/features";
 import {
   AllInstructions,
   InstructionContextFn,
@@ -24,7 +25,10 @@ export default class RpcFactory {
         const txSig = await provider.send(tx, ctx.signers, ctx.options);
         return txSig;
       } catch (err) {
-        console.log("Translating error", err);
+        if (features.isSet("debug-logs")) {
+          console.log("Translating error:", err);
+        }
+
         let translatedErr = ProgramError.parse(err, idlErrors);
         if (translatedErr === null) {
           throw err;

+ 5 - 1
ts/src/program/namespace/simulate.ts

@@ -10,6 +10,7 @@ import { EventParser, Event } from "../event";
 import Coder from "../../coder";
 import { Idl, IdlEvent } from "../../idl";
 import { ProgramError } from "../../error";
+import * as features from "../../utils/features";
 import {
   AllInstructions,
   IdlTypes,
@@ -36,7 +37,10 @@ export default class SimulateFactory {
       try {
         resp = await provider!.simulate(tx, ctx.signers, ctx.options);
       } catch (err) {
-        console.log("Translating error", err);
+        if (features.isSet("debug-logs")) {
+          console.log("Translating error:", err);
+        }
+
         let translatedErr = ProgramError.parse(err, idlErrors);
         if (translatedErr === null) {
           throw err;

+ 1 - 2
ts/src/workspace.ts

@@ -17,8 +17,7 @@ let _populatedWorkspace = false;
 const workspace = new Proxy({} as any, {
   get(workspaceCache: { [key: string]: Program }, programName: string) {
     if (isBrowser) {
-      console.log("Workspaces aren't available in the browser");
-      return undefined;
+      throw new Error("Workspaces aren't available in the browser");
     }
 
     const fs = require("fs");