removed NodeJS dependency from common.js
This commit is contained in:
26
contract.js
26
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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user