From e7e8f4da9bc69e3a920867431b4a70f55832a51b Mon Sep 17 00:00:00 2001 From: Swift Date: Wed, 17 Nov 2021 17:58:26 -0500 Subject: [PATCH] ts: Remove console logs from Node package (#1031) --- ts/src/program/context.ts | 7 ------- ts/src/program/namespace/instruction.ts | 4 +++- ts/src/program/namespace/rpc.ts | 6 +++++- ts/src/program/namespace/simulate.ts | 6 +++++- ts/src/workspace.ts | 3 +-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/ts/src/program/context.ts b/ts/src/program/context.ts index 5d82cff5..993abc25 100644 --- a/ts/src/program/context.ts +++ b/ts/src/program/context.ts @@ -50,13 +50,6 @@ export type Context = { * Commitment parameters to use for a transaction. */ options?: ConfirmOptions; - - /** - * @hidden - * - * Private namespace for development. - */ - __private?: { logAccounts: boolean }; }; /** diff --git a/ts/src/program/namespace/instruction.ts b/ts/src/program/namespace/instruction.ts index 5753a003..5de90762 100644 --- a/ts/src/program/namespace/instruction.ts +++ b/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, diff --git a/ts/src/program/namespace/rpc.ts b/ts/src/program/namespace/rpc.ts index a95e108f..0d5f2eac 100644 --- a/ts/src/program/namespace/rpc.ts +++ b/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; diff --git a/ts/src/program/namespace/simulate.ts b/ts/src/program/namespace/simulate.ts index 8757efd1..16d5658d 100644 --- a/ts/src/program/namespace/simulate.ts +++ b/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; diff --git a/ts/src/workspace.ts b/ts/src/workspace.ts index a1e01bfe..e42d6c2a 100644 --- a/ts/src/workspace.ts +++ b/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");