Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache created ChainContext objects #101

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions connect/src/wormhole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { getCircleAttestation } from "./circle-api";

export class Wormhole {
protected _platforms: Map<PlatformName, Platform<PlatformName>>;
protected _chains: Map<ChainName, ChainContext<PlatformName>>;

readonly conf: WormholeConfig;

Expand All @@ -47,6 +48,7 @@ export class Wormhole {
) {
this.conf = conf ?? CONFIG[network];

this._chains = new Map();
this._platforms = new Map();
for (const p of platforms) {
const platformName = p.platform;
Expand Down Expand Up @@ -230,8 +232,12 @@ export class Wormhole {
* @throws Errors if context is not found
*/
getChain(chain: ChainName): ChainContext<PlatformName> {
const platform = this.getPlatform(chain);
return platform.getChain(chain);
if (!this._chains.has(chain)) {
const platform = this.getPlatform(chain);
this._chains.set(chain, platform.getChain(chain));
}

return this._chains.get(chain)!;
}

/**
Expand Down