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)