From 588707c1b8073841f77bc06e4249937e39ee44b2 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 12 Jul 2024 16:11:33 -0400 Subject: [PATCH] removed NodeJS dependency from common.js --- contract.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/contract.js b/contract.js index fb3c552..54147e7 100644 --- a/contract.js +++ b/contract.js @@ -1,8 +1,32 @@ -import {AbiFileCache} from "../web/src/common.js" +import {AsyncAbiCache} from "../web/src/common.js" import {ethers} from "ethers"; +import fs from "fs"; const ABI_BASE_URL = '../contract/out/' + +export class AsyncFileCache extends AsyncAbiCache { + constructor(pathForKey) { + super(async (key) => { + const path = this.pathForKey(key) + const data = fs.readFileSync(path, 'utf8'); + return JSON.parse(data); + }) + this.pathForKey = pathForKey + } +} + + +export class AbiFileCache extends AsyncFileCache { + constructor(basePath) { + super((name)=>{ + return this.basePath+abiPath(name) + }) + this.basePath = basePath.endsWith('/') ? basePath : basePath + '/' + } +} + + const abiCache = new AbiFileCache(ABI_BASE_URL)