Skip to content

Commit

Permalink
Add support for custom types registration in config yaml (#167)
Browse files Browse the repository at this point in the history
* mangata support (#1)

* move types to config

* remove api types changes

* format

* fix lint issues
  • Loading branch information
vanderian authored Jan 27, 2023
1 parent 885d78e commit c8aa779
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
30 changes: 30 additions & 0 deletions configs/mangata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
endpoint: wss://mangata-x.api.onfinality.io/public-ws
mock-signature-host: true
db: ./mangata.db.sqlite

registered-types:
types:
ShufflingSeed:
seed: 'H256'
proof: 'H512'
Header:
parentHash: 'Hash'
number: 'Compact<BlockNumber>'
stateRoot: 'Hash'
extrinsicsRoot: 'Hash'
digest: 'Digest'
seed: 'ShufflingSeed'
count: 'BlockNumber'

import-storage:
Sudo:
Key: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
Tokens:
Accounts:
-
-
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
- token: 0
- free: '1000000000000000000000000' # 1M MG
Council:
Members: [5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY]
1 change: 1 addition & 0 deletions e2e/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const setupAll = async ({
},
mockSignatureHost,
allowUnresolvedImports,
registeredTypes: {},
})

const { port, close } = await createServer(handler({ chain }))
Expand Down
1 change: 1 addition & 0 deletions src/blockchain/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export class Block {
this.runtimeVersion,
]).then(([data, properties, chain, version]) => {
const registry = new TypeRegistry(this.hash)
registry.setKnownTypes(this.chain.registeredTypes)
registry.setChainProperties(registry.createType('ChainProperties', properties) as ChainProperties)
registry.register(getSpecTypes(registry, chain, version.specName, version.specVersion))
registry.setHasher(getSpecHasher(registry, chain, version.specName))
Expand Down
5 changes: 5 additions & 0 deletions src/blockchain/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ApplyExtrinsicResult } from '@polkadot/types/interfaces'
import { DataSource } from 'typeorm'
import { HexString } from '@polkadot/util/types'
import { RegisteredTypes } from '@polkadot/types/types'
import { blake2AsHex } from '@polkadot/util-crypto'
import { u8aConcat, u8aToHex } from '@polkadot/util'
import type { TransactionValidity } from '@polkadot/types/interfaces/txqueue'
Expand All @@ -23,6 +24,7 @@ export interface Options {
header: { number: number; hash: HexString }
mockSignatureHost?: boolean
allowUnresolvedImports?: boolean
registeredTypes: RegisteredTypes
}

export class Blockchain {
Expand All @@ -31,6 +33,7 @@ export class Blockchain {
readonly db: DataSource | undefined
readonly mockSignatureHost: boolean
readonly allowUnresolvedImports: boolean
readonly registeredTypes: RegisteredTypes

readonly #txpool: TxPool
readonly #inherentProvider: InherentProvider
Expand All @@ -50,11 +53,13 @@ export class Blockchain {
header,
mockSignatureHost = false,
allowUnresolvedImports = false,
registeredTypes = {},
}: Options) {
this.api = api
this.db = db
this.mockSignatureHost = mockSignatureHost
this.allowUnresolvedImports = allowUnresolvedImports
this.registeredTypes = registeredTypes

this.#head = new Block(this, header.number, header.hash)
this.#registerBlock(this.#head)
Expand Down
1 change: 1 addition & 0 deletions src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const configSchema = z
'wasm-override': z.string().optional(),
genesis: z.union([z.string(), genesisSchema]).optional(),
timestamp: z.number().optional(),
'registered-types': z.any().optional(),
})
.strict()

Expand Down
1 change: 1 addition & 0 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const setup = async (argv: Config) => {
},
mockSignatureHost: argv['mock-signature-host'],
allowUnresolvedImports: argv['allow-unresolved-imports'],
registeredTypes: argv['registered-types'],
})

if (argv.timestamp) await timeTravel(chain, argv.timestamp)
Expand Down

0 comments on commit c8aa779

Please sign in to comment.