removed NodeJS dependency from common.js

This commit is contained in:
Tim
2024-07-12 16:11:33 -04:00
parent ffef7e6312
commit 588707c1b8

View File

@@ -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)