Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

override sudo #42

Merged
merged 1 commit into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions karura-rococo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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(),
})
Expand Down
3 changes: 3 additions & 0 deletions src/rpc/substrate/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 12 additions & 4 deletions src/utils/import-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}