diff --git a/README.md b/README.md index 6c68867c..0542605e 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Make sure you have setup Rust environment (>= 1.64). - Submit any transaction to produce a new block in the in parallel reality - (Optional) Pre-define/override storage using option `--import-storage=storage.[json/yaml]`. See example storage below. - ```json + ```json5 // prettier-ignore { "Sudo": { diff --git a/karura-rococo.yml b/karura-rococo.yml index 12c7f723..413230b7 100644 --- a/karura-rococo.yml +++ b/karura-rococo.yml @@ -2,3 +2,7 @@ endpoint: wss://karura-rococo-rpc.aca-staging.network/ws mock-signature-host: true block: 1238000 db: ./db.sqlite + +import-storage: + Sudo: + Key: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice diff --git a/src/index.ts b/src/index.ts index f956af69..3820ef99 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,8 +59,7 @@ const setup = async (argv: any) => { tasks.updateListeningPort(listeningPort) - const storagePath = argv['import-storage'] - storagePath && (await importStorage(storagePath, chain)) + await importStorage(argv['import-storage'], chain) return context } @@ -107,7 +106,7 @@ const configSchema = z block: z.union([z.string(), z.number()]).optional(), 'executor-cmd': z.string().optional(), 'build-block-mode': z.nativeEnum(BuildBlockMode).optional(), - 'import-storage': z.string().optional(), + 'import-storage': z.any().optional(), 'mock-signature-host': z.boolean().optional(), db: z.string().optional(), }) diff --git a/src/rpc/substrate/system.ts b/src/rpc/substrate/system.ts index 187787b9..e3d46e25 100644 --- a/src/rpc/substrate/system.ts +++ b/src/rpc/substrate/system.ts @@ -13,6 +13,9 @@ const handlers: Handlers = { system_version: async (_context) => { return 'chopsticks-1.1.0' }, + system_chainType: async (_context) => { + return 'Development' + }, system_health: async () => { return { peers: 0, diff --git a/src/utils/import-storage.ts b/src/utils/import-storage.ts index 0ffd9e9f..46cc1dc1 100644 --- a/src/utils/import-storage.ts +++ b/src/utils/import-storage.ts @@ -5,9 +5,17 @@ import { Blockchain } from '../blockchain' import { defaultLogger } from '../logger' import { setStorage } from './set-storage' -export const importStorage = async (storagePath: string, chain: Blockchain) => { - if (!existsSync(storagePath)) throw Error(`File ${storagePath} does not exist`) - const storage: any = yaml.load(String(readFileSync(storagePath))) - const blockHash = await setStorage(chain, storage) +export const importStorage = async (storage: any, chain: Blockchain) => { + let storageValue + if (storage == null) { + return + } + if (typeof storage === 'string') { + if (!existsSync(storage)) throw Error(`File ${storage} does not exist`) + storageValue = yaml.load(String(readFileSync(storage))) + } else { + storageValue = storage + } + const blockHash = await setStorage(chain, storageValue) defaultLogger.trace({ blockHash, storage }, 'ImportStorage') }