2021-02-19 05:13:56 -08:00
|
|
|
import { PublicKey } from "solray"
|
|
|
|
import fs from "fs"
|
2021-02-20 01:05:05 -08:00
|
|
|
import BN from "bn.js"
|
2021-02-19 05:13:56 -08:00
|
|
|
|
|
|
|
export function jsonReviver(_key: string, val: any) {
|
|
|
|
if (val && typeof val == "object") {
|
|
|
|
if (val["type"] == "PublicKey") {
|
|
|
|
return new PublicKey(val.base58)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
|
|
|
|
export function jsonReplacer(key: string, value: any) {
|
2021-02-20 01:05:05 -08:00
|
|
|
if (value && typeof value == "object") {
|
|
|
|
if (value.constructor == PublicKey) {
|
|
|
|
return {
|
|
|
|
type: "PublicKey",
|
|
|
|
base58: value.toBase58(),
|
|
|
|
}
|
2021-02-19 05:13:56 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
|
|
|
|
export function loadJSONFile<T>(file: string): T {
|
|
|
|
return JSON.parse(fs.readFileSync(file, "utf8"), jsonReviver)
|
|
|
|
}
|