From 7f4536b28498ba485fc661d6c4752fd191783647 Mon Sep 17 00:00:00 2001 From: armaniferrante Date: Sun, 23 May 2021 16:21:03 -0700 Subject: [PATCH 1/2] ts: Make workspace metadata optional --- ts/package.json | 2 +- ts/src/workspace.ts | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ts/package.json b/ts/package.json index a3a8104635..346aadfbbf 100644 --- a/ts/package.json +++ b/ts/package.json @@ -1,6 +1,6 @@ { "name": "@project-serum/anchor", - "version": "0.6.0", + "version": "0.6.1-beta.1", "description": "Anchor client", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", diff --git a/ts/src/workspace.ts b/ts/src/workspace.ts index b1c9205a44..00c61540e4 100644 --- a/ts/src/workspace.ts +++ b/ts/src/workspace.ts @@ -2,7 +2,7 @@ import camelCase from "camelcase"; import * as toml from "toml"; import { PublicKey } from "@solana/web3.js"; import { Program } from "./program"; -import { getProvider } from "./"; +import { Idl } from "./idl"; let _populatedWorkspace = false; @@ -40,11 +40,14 @@ const workspace = new Proxy({} as any, { throw new Error("Could not find workspace root."); } + const idlMap = new Map(); + find .fileSync(/target\/idl\/.*\.json/, projectRoot) .reduce((programs: any, path: string) => { const idlStr = fs.readFileSync(path); const idl = JSON.parse(idlStr); + idlMap.set(idl.name, idl); const name = camelCase(idl.name, { pascalCase: true }); if (idl.metadata && idl.metadata.address) { programs[name] = new Program( @@ -61,7 +64,11 @@ const workspace = new Proxy({} as any, { ); const clusterId = anchorToml.provider.cluster; if (anchorToml.clusters && anchorToml.clusters[clusterId]) { - attachWorkspaceOverride(workspaceCache, anchorToml.clusters[clusterId]); + attachWorkspaceOverride( + workspaceCache, + anchorToml.clusters[clusterId], + idlMap + ); } _populatedWorkspace = true; @@ -73,14 +80,14 @@ const workspace = new Proxy({} as any, { function attachWorkspaceOverride( workspaceCache: { [key: string]: Program }, - overrideConfig: { [key: string]: string } + overrideConfig: { [key: string]: string }, + idlMap: Map ) { Object.keys(overrideConfig).forEach((programName) => { const wsProgramName = camelCase(programName, { pascalCase: true }); - const oldProgram = workspaceCache[wsProgramName]; const overrideAddress = new PublicKey(overrideConfig[programName]); workspaceCache[wsProgramName] = new Program( - oldProgram.idl, + idlMap.get(programName), overrideAddress ); }); From e2ed10ba624195aa1564ed4833326f6da3e3b3b7 Mon Sep 17 00:00:00 2001 From: armaniferrante Date: Sun, 23 May 2021 16:26:19 -0700 Subject: [PATCH 2/2] Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 565e35dc0e..5861c98027 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ incremented for features. ## [Unreleased] +## Features + +* ts: Address metadata is now optional for `anchor.workspace` clients ([#310](https://github.com/project-serum/anchor/pull/310)). + ## [0.6.0] - 2021-05-23 ## Features