Skip to content

Commit

Permalink
Chopsticks provider (#432)
Browse files Browse the repository at this point in the history
* add chopsticks provider

* refactor substrate rpc handlers into core

* add e2e tests

* add e2e test

* put chain setup in worker

* manual testing

* remove snapshot

* fix tx subscribe

* add playwright tests

* fix vite build

* try fix playwright tests

* fix subscribe

* fix test

* remote coment

* fix log level

* fix indent

* fix logger

* fix lint
  • Loading branch information
qiweiii authored Oct 17, 2023
1 parent dcecaac commit 732150c
Show file tree
Hide file tree
Showing 35 changed files with 677 additions and 66 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ dist
*.sqlite
*.sqlite-journal
*.wasm
*.db

.DS_store

Expand Down
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ vendor/
.pnp.loader.mjs
lib/
preview/
tsconfig.json
2 changes: 1 addition & 1 deletion packages/chopsticks/src/plugins/dry-run/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HexString } from '@polkadot/util/types'
import { z } from 'zod'

import { Context, ResponseError } from '../../rpc/shared'
import { Context, ResponseError } from '@acala-network/chopsticks-core'
import { decodeStorageDiff } from '../../utils/decoder'
import { generateHtmlDiff } from '../../utils/generate-html-diff'

Expand Down
2 changes: 1 addition & 1 deletion packages/chopsticks/src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Handlers } from '@acala-network/chopsticks-core'
import { camelCase } from 'lodash'
import { lstatSync, readdirSync } from 'fs'
import type yargs from 'yargs'

import { Handlers } from '../rpc/shared'
import { defaultLogger } from '../logger'

const logger = defaultLogger.child({ name: 'plugin' })
Expand Down
3 changes: 1 addition & 2 deletions packages/chopsticks/src/plugins/new-block/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Context, ResponseError } from '../../rpc/shared'
import { DownwardMessage, HorizontalMessage } from '@acala-network/chopsticks-core'
import { Context, DownwardMessage, HorizontalMessage, ResponseError } from '@acala-network/chopsticks-core'
import { HexString } from '@polkadot/util/types'
import { defaultLogger } from '../../logger'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BuildBlockMode } from '@acala-network/chopsticks-core'
import { Context, ResponseError } from '../../rpc/shared'
import { BuildBlockMode, Context, ResponseError } from '@acala-network/chopsticks-core'
import { defaultLogger } from '../../logger'

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/chopsticks/src/plugins/set-head/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Block } from '@acala-network/chopsticks-core'
import { Context, ResponseError } from '../../rpc/shared'
import { Block, Context, ResponseError } from '@acala-network/chopsticks-core'
import { HexString } from '@polkadot/util/types'

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context, ResponseError } from '../../rpc/shared'
import { Context, ResponseError } from '@acala-network/chopsticks-core'
import { defaultLogger } from '../../logger'

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/chopsticks/src/plugins/set-storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Context, ResponseError, StorageValues, setStorage } from '@acala-network/chopsticks-core'
import { HexString } from '@polkadot/util/types'

import { Context, ResponseError } from '../../rpc/shared'
import { StorageValues, setStorage } from '@acala-network/chopsticks-core'
import { defaultLogger } from '../../logger'

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/chopsticks/src/plugins/time-travel/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Context, ResponseError } from '../../rpc/shared'
import { timeTravel } from '@acala-network/chopsticks-core'
import { Context, ResponseError, timeTravel } from '@acala-network/chopsticks-core'

/**
* Travel to a specific time.
Expand Down
11 changes: 9 additions & 2 deletions packages/chopsticks/src/rpc/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Context, Handlers, ResponseError, SubscriptionManager, logger } from './shared'
import {
Context,
Handlers,
ResponseError,
SubscriptionManager,
logger,
substrate,
} from '@acala-network/chopsticks-core'

import { pluginHandlers } from '../plugins'
import substrate from './substrate'

const allHandlers: Handlers = {
...substrate,
Expand Down
2 changes: 1 addition & 1 deletion packages/chopsticks/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ResponseError, SubscriptionManager } from '@acala-network/chopsticks-core'
import { z } from 'zod'
import WebSocket, { AddressInfo, WebSocketServer } from 'ws'

import { ResponseError, SubscriptionManager } from './rpc/shared'
import { defaultLogger, truncate } from './logger'

const logger = defaultLogger.child({ name: 'ws' })
Expand Down
2 changes: 1 addition & 1 deletion packages/chopsticks/src/setup-with-server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Config } from './schema'
import { createServer } from './server'
import { handler } from './rpc'
import { logger } from './rpc/shared'
import { logger } from '@acala-network/chopsticks-core'
import { setupContext } from './context'
import _ from 'lodash'

Expand Down
11 changes: 8 additions & 3 deletions packages/chopsticks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
*
* @packageDocumentation
*/
export { ChainProperties, RuntimeVersion } from '@acala-network/chopsticks-core'
export type {
ChainProperties,
RuntimeVersion,
Context,
SubscriptionManager,
Handler,
} from '@acala-network/chopsticks-core'
export * from '@acala-network/chopsticks-core/src/rpc/substrate'
export * from './plugins/types'
export * from './rpc/substrate'
export { Context, SubscriptionManager, Handler } from './rpc/shared'
16 changes: 7 additions & 9 deletions packages/chopsticks/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
},
"include": ["src/**/*"],
"exclude": ["src/**/*.test.ts"],
"references": [
{ "path": "../core" },
],
"typedocOptions": {
"entryPoints": ["src/types.ts"],
"out": "../../docs-src/chopsticks",
"plugin": "typedoc-plugin-markdown",
"readme": "none",
}
"references": [{ "path": "../core" }],
"typedocOptions": {
"entryPoints": ["src/types.ts"],
"out": "../../docs-src/chopsticks",
"plugin": "typedoc-plugin-markdown",
"readme": "none"
}
}
Loading

0 comments on commit 732150c

Please sign in to comment.