-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use ts path, refactor, cleanup (#107)
- Loading branch information
1 parent
c52dc02
commit 9a7a976
Showing
33 changed files
with
456 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,9 @@ module.exports = { | |
}, | ||
], | ||
}, | ||
settings: { | ||
'import/resolver': { | ||
typescript: {}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
], | ||
"main": "chopsticks_executor.js", | ||
"types": "chopsticks_executor.d.ts" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Block } from '../block' | ||
import { DecoratedMeta } from '@polkadot/types/metadata/decorate/types' | ||
import { GenericExtrinsic } from '@polkadot/types' | ||
import { HexString } from '@polkadot/util/types' | ||
|
||
export { SetValidationData } from './parachain/validation-data' | ||
|
||
export interface CreateInherents { | ||
createInherents(meta: DecoratedMeta, timestamp: number, parent: Block): Promise<HexString[]> | ||
} | ||
|
||
export interface InherentProvider extends CreateInherents { | ||
getTimestamp(blockNumber: number): number | ||
} | ||
|
||
export class SetTimestamp implements InherentProvider { | ||
readonly #getTimestamp: (blockNumber: number) => number | ||
|
||
constructor(getTimestamp: (blockNumber: number) => number = Date.now) { | ||
this.#getTimestamp = getTimestamp | ||
} | ||
|
||
async createInherents(meta: DecoratedMeta, timestamp: number, _parent: Block): Promise<HexString[]> { | ||
return [new GenericExtrinsic(meta.registry, meta.tx.timestamp.set(timestamp)).toHex()] | ||
} | ||
|
||
getTimestamp(blockNumber: number): number { | ||
return this.#getTimestamp(blockNumber) | ||
} | ||
} | ||
|
||
export class InherentProviders implements InherentProvider { | ||
readonly #base: InherentProvider | ||
readonly #providers: CreateInherents[] | ||
|
||
constructor(base: InherentProvider, providers: CreateInherents[]) { | ||
this.#base = base | ||
this.#providers = providers | ||
} | ||
|
||
async createInherents(meta: DecoratedMeta, timestamp: number, parent: Block): Promise<HexString[]> { | ||
const base = await this.#base.createInherents(meta, timestamp, parent) | ||
const extra = await Promise.all( | ||
this.#providers.map((provider) => provider.createInherents(meta, timestamp, parent)) | ||
) | ||
return [...base, ...extra.flat()] | ||
} | ||
|
||
getTimestamp(blockNumber: number): number { | ||
return this.#base.getTimestamp(blockNumber) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import '@polkadot/types-codec' | ||
import { u8aToHex } from '@polkadot/util' | ||
|
||
import { setup } from './setup' | ||
|
||
export const decodeKey = async (argv: any) => { | ||
const context = await setup(argv) | ||
|
||
const key = argv.key | ||
const meta = await context.chain.head.meta | ||
outer: for (const module of Object.values(meta.query)) { | ||
for (const storage of Object.values(module)) { | ||
const keyPrefix = u8aToHex(storage.keyPrefix()) | ||
if (key.startsWith(keyPrefix)) { | ||
const decodedKey = meta.registry.createType('StorageKey', key) | ||
decodedKey.setMeta(storage.meta) | ||
console.log(`${storage.section}.${storage.method}`, decodedKey.args.map((x) => x.toHuman()).join(', ')) | ||
break outer | ||
} | ||
} | ||
} | ||
|
||
setTimeout(() => process.exit(0), 50) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.