@acala-network/chopsticks-core 0.9.4-1 → 0.9.4-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/api.d.ts +56 -0
- package/dist/esm/blockchain/block-builder.d.ts +15 -0
- package/dist/esm/blockchain/block.d.ts +92 -0
- package/dist/esm/blockchain/head-state.d.ts +15 -0
- package/dist/esm/blockchain/index.d.ts +172 -0
- package/dist/esm/blockchain/inherent/index.d.ts +19 -0
- package/dist/esm/blockchain/inherent/para-enter.d.ts +7 -0
- package/dist/esm/blockchain/inherent/parachain/babe-randomness.d.ts +7 -0
- package/dist/esm/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +7 -0
- package/dist/esm/blockchain/inherent/parachain/validation-data.d.ts +19 -0
- package/dist/esm/blockchain/storage-layer.d.ts +47 -0
- package/dist/esm/blockchain/txpool.d.ts +48 -0
- package/dist/esm/chopsticks-provider.d.ts +32 -0
- package/dist/esm/database.d.ts +26 -0
- package/dist/esm/genesis-provider.d.ts +52 -0
- package/dist/esm/index.d.ts +28 -0
- package/dist/esm/logger.d.ts +7 -0
- package/dist/esm/offchain.d.ts +10 -0
- package/dist/esm/rpc/index.d.ts +5 -0
- package/dist/esm/rpc/shared.d.ts +27 -0
- package/dist/esm/rpc/substrate/author.d.ts +28 -0
- package/dist/esm/rpc/substrate/chain.d.ts +45 -0
- package/dist/esm/rpc/substrate/index.d.ts +66 -0
- package/dist/esm/rpc/substrate/payment.d.ts +16 -0
- package/dist/esm/rpc/substrate/state.d.ts +97 -0
- package/dist/esm/rpc/substrate/system.d.ts +28 -0
- package/dist/esm/schema/index.d.ts +62 -0
- package/dist/esm/setup.d.ts +20 -0
- package/dist/esm/utils/decoder.d.ts +28 -0
- package/dist/esm/utils/index.d.ts +23 -0
- package/dist/esm/utils/key-cache.d.ts +10 -0
- package/dist/esm/utils/proof.d.ts +16 -0
- package/dist/esm/utils/set-storage.d.ts +7 -0
- package/dist/esm/utils/time-travel.d.ts +5 -0
- package/dist/esm/utils/well-known-keys.d.ts +7 -0
- package/dist/esm/wasm-executor/browser-worker.d.ts +4 -0
- package/dist/esm/wasm-executor/index.d.ts +80 -0
- package/dist/esm/wasm-executor/node-worker.d.ts +4 -0
- package/dist/esm/xcm/downward.d.ts +2 -0
- package/dist/esm/xcm/horizontal.d.ts +2 -0
- package/dist/esm/xcm/index.d.ts +9 -0
- package/dist/esm/xcm/upward.d.ts +2 -0
- package/package.json +8 -15
- /package/dist/{types → cjs}/api.d.ts +0 -0
- /package/dist/{types → cjs}/blockchain/block-builder.d.ts +0 -0
- /package/dist/{types → cjs}/blockchain/block.d.ts +0 -0
- /package/dist/{types → cjs}/blockchain/head-state.d.ts +0 -0
- /package/dist/{types → cjs}/blockchain/index.d.ts +0 -0
- /package/dist/{types → cjs}/blockchain/inherent/index.d.ts +0 -0
- /package/dist/{types → cjs}/blockchain/inherent/para-enter.d.ts +0 -0
- /package/dist/{types → cjs}/blockchain/inherent/parachain/babe-randomness.d.ts +0 -0
- /package/dist/{types → cjs}/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +0 -0
- /package/dist/{types → cjs}/blockchain/inherent/parachain/validation-data.d.ts +0 -0
- /package/dist/{types → cjs}/blockchain/storage-layer.d.ts +0 -0
- /package/dist/{types → cjs}/blockchain/txpool.d.ts +0 -0
- /package/dist/{types → cjs}/chopsticks-provider.d.ts +0 -0
- /package/dist/{types → cjs}/database.d.ts +0 -0
- /package/dist/{types → cjs}/genesis-provider.d.ts +0 -0
- /package/dist/{types → cjs}/index.d.ts +0 -0
- /package/dist/{types → cjs}/logger.d.ts +0 -0
- /package/dist/{types → cjs}/offchain.d.ts +0 -0
- /package/dist/{types → cjs}/rpc/index.d.ts +0 -0
- /package/dist/{types → cjs}/rpc/shared.d.ts +0 -0
- /package/dist/{types → cjs}/rpc/substrate/author.d.ts +0 -0
- /package/dist/{types → cjs}/rpc/substrate/chain.d.ts +0 -0
- /package/dist/{types → cjs}/rpc/substrate/index.d.ts +0 -0
- /package/dist/{types → cjs}/rpc/substrate/payment.d.ts +0 -0
- /package/dist/{types → cjs}/rpc/substrate/state.d.ts +0 -0
- /package/dist/{types → cjs}/rpc/substrate/system.d.ts +0 -0
- /package/dist/{types → cjs}/schema/index.d.ts +0 -0
- /package/dist/{types → cjs}/setup.d.ts +0 -0
- /package/dist/{types → cjs}/utils/decoder.d.ts +0 -0
- /package/dist/{types → cjs}/utils/index.d.ts +0 -0
- /package/dist/{types → cjs}/utils/key-cache.d.ts +0 -0
- /package/dist/{types → cjs}/utils/proof.d.ts +0 -0
- /package/dist/{types → cjs}/utils/set-storage.d.ts +0 -0
- /package/dist/{types → cjs}/utils/time-travel.d.ts +0 -0
- /package/dist/{types → cjs}/utils/well-known-keys.d.ts +0 -0
- /package/dist/{types → cjs}/wasm-executor/browser-worker.d.ts +0 -0
- /package/dist/{types → cjs}/wasm-executor/index.d.ts +0 -0
- /package/dist/{types → cjs}/wasm-executor/node-worker.d.ts +0 -0
- /package/dist/{types → cjs}/xcm/downward.d.ts +0 -0
- /package/dist/{types → cjs}/xcm/horizontal.d.ts +0 -0
- /package/dist/{types → cjs}/xcm/index.d.ts +0 -0
- /package/dist/{types → cjs}/xcm/upward.d.ts +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
|
|
2
|
+
import { HexString } from '@polkadot/util/types';
|
|
3
|
+
import { ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types';
|
|
4
|
+
export type ChainProperties = {
|
|
5
|
+
ss58Format?: number;
|
|
6
|
+
tokenDecimals?: number[];
|
|
7
|
+
tokenSymbol?: string[];
|
|
8
|
+
};
|
|
9
|
+
type Header = {
|
|
10
|
+
parentHash: HexString;
|
|
11
|
+
number: HexString;
|
|
12
|
+
stateRoot: HexString;
|
|
13
|
+
extrinsicsRoot: HexString;
|
|
14
|
+
digest: {
|
|
15
|
+
logs: HexString[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
type SignedBlock = {
|
|
19
|
+
block: {
|
|
20
|
+
header: Header;
|
|
21
|
+
extrinsics: HexString[];
|
|
22
|
+
};
|
|
23
|
+
justifications?: HexString[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* API class. Calls provider to get on-chain data.
|
|
27
|
+
* Either `endpoint` or `genesis` porvider must be provided.
|
|
28
|
+
*
|
|
29
|
+
* @example Instantiate an API
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const provider = new WsProvider(options.endpoint)
|
|
33
|
+
* const api = new Api(provider)
|
|
34
|
+
* await api.isReady
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class Api {
|
|
38
|
+
#private;
|
|
39
|
+
readonly signedExtensions: ExtDef;
|
|
40
|
+
constructor(provider: ProviderInterface, signedExtensions?: ExtDef);
|
|
41
|
+
disconnect(): Promise<void>;
|
|
42
|
+
get isReady(): Promise<void> | undefined;
|
|
43
|
+
get chain(): Promise<string>;
|
|
44
|
+
get chainProperties(): Promise<ChainProperties>;
|
|
45
|
+
getSystemName(): Promise<string>;
|
|
46
|
+
getSystemProperties(): Promise<ChainProperties>;
|
|
47
|
+
getSystemChain(): Promise<string>;
|
|
48
|
+
getBlockHash(blockNumber?: number): Promise<`0x${string}` | null>;
|
|
49
|
+
getHeader(hash?: string): Promise<Header | null>;
|
|
50
|
+
getBlock(hash?: string): Promise<SignedBlock | null>;
|
|
51
|
+
getStorage(key: string, hash?: string): Promise<`0x${string}` | null>;
|
|
52
|
+
getKeysPaged(prefix: string, pageSize: number, startKey: string, hash?: string): Promise<string[]>;
|
|
53
|
+
subscribeRemoteNewHeads(cb: ProviderInterfaceCallback): Promise<string | number>;
|
|
54
|
+
subscribeRemoteFinalizedHeads(cb: ProviderInterfaceCallback): Promise<string | number>;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Header, TransactionValidityError } from '@polkadot/types/interfaces';
|
|
2
|
+
import { Block } from './block.js';
|
|
3
|
+
import { HexString } from '@polkadot/util/types';
|
|
4
|
+
import { TaskCallResponse } from '../wasm-executor/index.js';
|
|
5
|
+
export declare const newHeader: (head: Block, unsafeBlockHeight?: number) => Promise<Header>;
|
|
6
|
+
export type BuildBlockCallbacks = {
|
|
7
|
+
onApplyExtrinsicError?: (extrinsic: HexString, error: TransactionValidityError) => void;
|
|
8
|
+
onPhaseApplied?: (phase: 'initialize' | 'finalize' | number, resp: TaskCallResponse) => void;
|
|
9
|
+
};
|
|
10
|
+
export declare const buildBlock: (head: Block, inherents: HexString[], extrinsics: HexString[], ump: Record<number, HexString[]>, callbacks?: BuildBlockCallbacks, unsafeBlockHeight?: number) => Promise<[Block, HexString[]]>;
|
|
11
|
+
export declare const dryRunExtrinsic: (head: Block, inherents: HexString[], extrinsic: HexString | {
|
|
12
|
+
call: HexString;
|
|
13
|
+
address: string;
|
|
14
|
+
}) => Promise<TaskCallResponse>;
|
|
15
|
+
export declare const dryRunInherents: (head: Block, inherents: HexString[]) => Promise<[HexString, HexString | null][]>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { DecoratedMeta } from '@polkadot/types/metadata/decorate/types';
|
|
2
|
+
import { Header } from '@polkadot/types/interfaces';
|
|
3
|
+
import { TypeRegistry } from '@polkadot/types';
|
|
4
|
+
import { StorageEntry } from '@polkadot/types/primitive/types';
|
|
5
|
+
import type { HexString } from '@polkadot/util/types';
|
|
6
|
+
import { Blockchain } from './index.js';
|
|
7
|
+
import { StorageLayer, StorageLayerProvider, StorageValue } from './storage-layer.js';
|
|
8
|
+
import type { RuntimeVersion, TaskCallResponse } from '../wasm-executor/index.js';
|
|
9
|
+
/**
|
|
10
|
+
* Block class.
|
|
11
|
+
*
|
|
12
|
+
* @example Instantiate a block
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const block = new Block(chain, number, hash)
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example Get storage
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* const block = await chain.getBlock('0x...')
|
|
22
|
+
* block.storage()
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class Block {
|
|
26
|
+
#private;
|
|
27
|
+
readonly number: number;
|
|
28
|
+
readonly hash: HexString;
|
|
29
|
+
constructor(chain: Blockchain, number: number, hash: HexString, parentBlock?: Block, block?: {
|
|
30
|
+
/** See `@polkadot/types/interfaces` Header */
|
|
31
|
+
header: Header;
|
|
32
|
+
/** Extrinsics */
|
|
33
|
+
extrinsics: HexString[];
|
|
34
|
+
/** Storage provider. Default to {@link RemoteStorageLayer} with {@link Blockchain.api chain.api} as remote. */
|
|
35
|
+
storage?: StorageLayerProvider;
|
|
36
|
+
/** Storage diff to apply. */
|
|
37
|
+
storageDiff?: Record<string, StorageValue | null>;
|
|
38
|
+
});
|
|
39
|
+
get chain(): Blockchain;
|
|
40
|
+
get header(): Header | Promise<Header>;
|
|
41
|
+
get extrinsics(): HexString[] | Promise<HexString[]>;
|
|
42
|
+
get parentBlock(): Promise<Block | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* Get the block storage.
|
|
45
|
+
*/
|
|
46
|
+
get storage(): StorageLayerProvider;
|
|
47
|
+
/**
|
|
48
|
+
* Get the block storage by key.
|
|
49
|
+
*/
|
|
50
|
+
get(key: string): Promise<HexString | undefined>;
|
|
51
|
+
read<T extends string>(type: T, query: StorageEntry, ...args: any[]): Promise<import("@polkadot/types/types").DetectCodec<import("@polkadot/types-codec/types").Codec, T> | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* Get paged storage keys.
|
|
54
|
+
*/
|
|
55
|
+
getKeysPaged(options: {
|
|
56
|
+
prefix?: string;
|
|
57
|
+
startKey?: string;
|
|
58
|
+
pageSize: number;
|
|
59
|
+
}): Promise<string[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Push a layer to the storage stack.
|
|
62
|
+
*/
|
|
63
|
+
pushStorageLayer(): StorageLayer;
|
|
64
|
+
/**
|
|
65
|
+
* Pop a layer from the storage stack.
|
|
66
|
+
*/
|
|
67
|
+
popStorageLayer(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Get storage diff.
|
|
70
|
+
*/
|
|
71
|
+
storageDiff(): Promise<Record<HexString, HexString | null>>;
|
|
72
|
+
/**
|
|
73
|
+
* Get the wasm string.
|
|
74
|
+
*/
|
|
75
|
+
get wasm(): Promise<`0x${string}`>;
|
|
76
|
+
/**
|
|
77
|
+
* Set the runtime wasm.
|
|
78
|
+
*/
|
|
79
|
+
setWasm(wasm: HexString): void;
|
|
80
|
+
/**
|
|
81
|
+
* Get the type registry.
|
|
82
|
+
* @see https://polkadot.js.org/docs/api/start/types.create#why-create-types
|
|
83
|
+
*/
|
|
84
|
+
get registry(): Promise<TypeRegistry>;
|
|
85
|
+
get runtimeVersion(): Promise<RuntimeVersion>;
|
|
86
|
+
get metadata(): Promise<HexString>;
|
|
87
|
+
get meta(): Promise<DecoratedMeta>;
|
|
88
|
+
/**
|
|
89
|
+
* Call a runtime method.
|
|
90
|
+
*/
|
|
91
|
+
call(method: string, args: HexString[]): Promise<TaskCallResponse>;
|
|
92
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Block } from './block.js';
|
|
2
|
+
type Callback = (block: Block, pairs: [string, string | null][]) => void | Promise<void>;
|
|
3
|
+
export declare const randomId: () => string;
|
|
4
|
+
export declare class HeadState {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(head: Block);
|
|
7
|
+
subscribeHead(cb: (block: Block) => void): string;
|
|
8
|
+
unsubscribeHead(id: string): void;
|
|
9
|
+
subscribeStorage(keys: string[], cb: Callback): Promise<string>;
|
|
10
|
+
unsubscribeStorage(id: string): void;
|
|
11
|
+
subscrubeRuntimeVersion(cb: (block: Block) => void): Promise<string>;
|
|
12
|
+
unsubscribeRuntimeVersion(id: string): void;
|
|
13
|
+
setHead(head: Block): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { ApplyExtrinsicResult } from '@polkadot/types/interfaces';
|
|
2
|
+
import { HexString } from '@polkadot/util/types';
|
|
3
|
+
import { TypeRegistry } from '@polkadot/types';
|
|
4
|
+
import { RegisteredTypes } from '@polkadot/types/types';
|
|
5
|
+
import type { TransactionValidity } from '@polkadot/types/interfaces/txqueue';
|
|
6
|
+
import { Api } from '../api.js';
|
|
7
|
+
import { Block } from './block.js';
|
|
8
|
+
import { BuildBlockMode, BuildBlockParams, DownwardMessage, HorizontalMessage, TxPool } from './txpool.js';
|
|
9
|
+
import { Database } from '../database.js';
|
|
10
|
+
import { HeadState } from './head-state.js';
|
|
11
|
+
import { InherentProvider } from './inherent/index.js';
|
|
12
|
+
import { OffchainWorker } from '../offchain.js';
|
|
13
|
+
import { RuntimeVersion } from '../wasm-executor/index.js';
|
|
14
|
+
export interface Options {
|
|
15
|
+
/** API instance, for getting on-chain data. */
|
|
16
|
+
api: Api;
|
|
17
|
+
/** Build block mode. Default to Batch. */
|
|
18
|
+
buildBlockMode?: BuildBlockMode;
|
|
19
|
+
/** Inherent provider, for creating inherents. */
|
|
20
|
+
inherentProvider: InherentProvider;
|
|
21
|
+
/** Datasource for caching storage and blocks data. */
|
|
22
|
+
db?: Database;
|
|
23
|
+
/** Used to create the initial head. */
|
|
24
|
+
header: {
|
|
25
|
+
number: number;
|
|
26
|
+
hash: HexString;
|
|
27
|
+
};
|
|
28
|
+
/** Whether to enable mock signature. Any signature starts with 0xdeadbeef and filled by 0xcd is considered valid */
|
|
29
|
+
mockSignatureHost?: boolean;
|
|
30
|
+
/** Whether to allow wasm unresolved imports. */
|
|
31
|
+
allowUnresolvedImports?: boolean;
|
|
32
|
+
/** Wasm runtime log level. */
|
|
33
|
+
runtimeLogLevel?: number;
|
|
34
|
+
/** Polkadot.js custom types registration. */
|
|
35
|
+
registeredTypes: RegisteredTypes;
|
|
36
|
+
/** Whether to enable offchain Worker. */
|
|
37
|
+
offchainWorker?: boolean;
|
|
38
|
+
/** Max memory block count */
|
|
39
|
+
maxMemoryBlockCount?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Local blockchain which provides access to blocks, txpool and methods
|
|
43
|
+
* to manipulate the chain such as build blocks, submit extrinsics, xcm and more!
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* const chain = new Blockchain({
|
|
49
|
+
* api,
|
|
50
|
+
* buildBlockMode: BuildBlockMode.Manual,
|
|
51
|
+
* inherentProvider: inherents,
|
|
52
|
+
* header: {
|
|
53
|
+
* hash: blockHash,
|
|
54
|
+
* number: Number(header.number),
|
|
55
|
+
* },
|
|
56
|
+
* mockSignatureHost: true,
|
|
57
|
+
* allowUnresolvedImports: true,
|
|
58
|
+
* registeredTypes: {},
|
|
59
|
+
* })
|
|
60
|
+
* // build a block
|
|
61
|
+
* chain.newBlock()
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare class Blockchain {
|
|
65
|
+
#private;
|
|
66
|
+
readonly uid: string;
|
|
67
|
+
/** API instance, for getting on-chain data. */
|
|
68
|
+
readonly api: Api;
|
|
69
|
+
/** Datasource for caching storage and blocks data. */
|
|
70
|
+
readonly db: Database | undefined;
|
|
71
|
+
/** Enable mock signature. Any signature starts with 0xdeadbeef and filled by 0xcd is considered valid */
|
|
72
|
+
readonly mockSignatureHost: boolean;
|
|
73
|
+
/** Allow wasm unresolved imports. */
|
|
74
|
+
readonly allowUnresolvedImports: boolean;
|
|
75
|
+
/** Polkadot.js custom types registration. */
|
|
76
|
+
readonly registeredTypes: RegisteredTypes;
|
|
77
|
+
/** For subscribing and managing the head state. */
|
|
78
|
+
readonly headState: HeadState;
|
|
79
|
+
readonly offchainWorker: OffchainWorker | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* @param options - Options for instantiating the blockchain
|
|
82
|
+
*/
|
|
83
|
+
constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost, allowUnresolvedImports, runtimeLogLevel, registeredTypes, offchainWorker, maxMemoryBlockCount, }: Options);
|
|
84
|
+
get head(): Block;
|
|
85
|
+
get txPool(): TxPool;
|
|
86
|
+
get runtimeLogLevel(): number;
|
|
87
|
+
set runtimeLogLevel(level: number);
|
|
88
|
+
buildRegistry(metadata: HexString, version: RuntimeVersion): Promise<TypeRegistry>;
|
|
89
|
+
saveBlockToDB(block: Block): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Try to load block from db and register it.
|
|
92
|
+
* If pass in number, get block by number, else get block by hash.
|
|
93
|
+
*/
|
|
94
|
+
loadBlockFromDB(hashOrNumber: number | HexString): Promise<Block | undefined>;
|
|
95
|
+
/**
|
|
96
|
+
* Get block by number.
|
|
97
|
+
*/
|
|
98
|
+
getBlockAt(number?: number | null): Promise<Block | undefined>;
|
|
99
|
+
/**
|
|
100
|
+
* Get block by hash.
|
|
101
|
+
*/
|
|
102
|
+
getBlock(hash?: HexString): Promise<Block | undefined>;
|
|
103
|
+
/**
|
|
104
|
+
* Get all blocks in memory.
|
|
105
|
+
*/
|
|
106
|
+
blocksInMemory(): Block[];
|
|
107
|
+
/**
|
|
108
|
+
* Remove block from memory and db.
|
|
109
|
+
*/
|
|
110
|
+
unregisterBlock(block: Block): Promise<void>;
|
|
111
|
+
onNewBlock(block: Block): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Set block as head.
|
|
114
|
+
*/
|
|
115
|
+
setHead(block: Block): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Submit extrinsic to txpool.
|
|
118
|
+
*/
|
|
119
|
+
submitExtrinsic(extrinsic: HexString): Promise<HexString>;
|
|
120
|
+
/**
|
|
121
|
+
* Validate extrinsic by calling `TaggedTransactionQueue_validate_transaction`.
|
|
122
|
+
*/
|
|
123
|
+
validateExtrinsic(extrinsic: HexString, source?: '0x00' | '0x01' | '0x02' /** External */): Promise<TransactionValidity>;
|
|
124
|
+
submitUpwardMessages(id: number, ump: HexString[]): void;
|
|
125
|
+
submitDownwardMessages(dmp: DownwardMessage[]): void;
|
|
126
|
+
submitHorizontalMessages(id: number, hrmp: HorizontalMessage[]): void;
|
|
127
|
+
/**
|
|
128
|
+
* Build a new block with optional params. Use this when you don't have all the {@link BuildBlockParams}
|
|
129
|
+
*/
|
|
130
|
+
newBlock(params?: Partial<BuildBlockParams>): Promise<Block>;
|
|
131
|
+
/**
|
|
132
|
+
* Build a new block with {@link BuildBlockParams}.
|
|
133
|
+
*/
|
|
134
|
+
newBlockWithParams(params: BuildBlockParams): Promise<Block>;
|
|
135
|
+
/**
|
|
136
|
+
* Get the upcoming blocks.
|
|
137
|
+
*/
|
|
138
|
+
upcomingBlocks(): Promise<number>;
|
|
139
|
+
/**
|
|
140
|
+
* Dry run extrinsic in block `at`.
|
|
141
|
+
*/
|
|
142
|
+
dryRunExtrinsic(extrinsic: HexString | {
|
|
143
|
+
call: HexString;
|
|
144
|
+
address: string;
|
|
145
|
+
}, at?: HexString): Promise<{
|
|
146
|
+
outcome: ApplyExtrinsicResult;
|
|
147
|
+
storageDiff: [HexString, HexString | null][];
|
|
148
|
+
}>;
|
|
149
|
+
/**
|
|
150
|
+
* Dry run hrmp messages in block `at`.
|
|
151
|
+
* Return the storage diff.
|
|
152
|
+
*/
|
|
153
|
+
dryRunHrmp(hrmp: Record<number, HorizontalMessage[]>, at?: HexString): Promise<[HexString, HexString | null][]>;
|
|
154
|
+
/**
|
|
155
|
+
* Dry run dmp messages in block `at`.
|
|
156
|
+
* Return the storage diff.
|
|
157
|
+
*/
|
|
158
|
+
dryRunDmp(dmp: DownwardMessage[], at?: HexString): Promise<[HexString, HexString | null][]>;
|
|
159
|
+
/**
|
|
160
|
+
* Dry run ump messages in block `at`.
|
|
161
|
+
* Return the storage diff.
|
|
162
|
+
*/
|
|
163
|
+
dryRunUmp(ump: Record<number, HexString[]>, at?: HexString): Promise<[HexString, HexString | null][]>;
|
|
164
|
+
/**
|
|
165
|
+
* Get inherents of head.
|
|
166
|
+
*/
|
|
167
|
+
getInherents(): Promise<HexString[]>;
|
|
168
|
+
/**
|
|
169
|
+
* Close the db and disconnect api.
|
|
170
|
+
*/
|
|
171
|
+
close(): Promise<void>;
|
|
172
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Block } from '../block.js';
|
|
2
|
+
import { BuildBlockParams } from '../txpool.js';
|
|
3
|
+
import { HexString } from '@polkadot/util/types';
|
|
4
|
+
export { SetValidationData } from './parachain/validation-data.js';
|
|
5
|
+
export { ParaInherentEnter } from './para-enter.js';
|
|
6
|
+
export { SetBabeRandomness } from './parachain/babe-randomness.js';
|
|
7
|
+
export { SetNimbusAuthorInherent } from './parachain/nimbus-author-inherent.js';
|
|
8
|
+
export interface CreateInherents {
|
|
9
|
+
createInherents(parent: Block, params: BuildBlockParams): Promise<HexString[]>;
|
|
10
|
+
}
|
|
11
|
+
export type InherentProvider = CreateInherents;
|
|
12
|
+
export declare class SetTimestamp implements InherentProvider {
|
|
13
|
+
createInherents(parent: Block): Promise<HexString[]>;
|
|
14
|
+
}
|
|
15
|
+
export declare class InherentProviders implements InherentProvider {
|
|
16
|
+
#private;
|
|
17
|
+
constructor(base: InherentProvider, providers: CreateInherents[]);
|
|
18
|
+
createInherents(parent: Block, params: BuildBlockParams): Promise<HexString[]>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HexString } from '@polkadot/util/types';
|
|
2
|
+
import { Block } from '../block.js';
|
|
3
|
+
import { BuildBlockParams } from '../txpool.js';
|
|
4
|
+
import { CreateInherents } from './index.js';
|
|
5
|
+
export declare class ParaInherentEnter implements CreateInherents {
|
|
6
|
+
createInherents(parent: Block, _params: BuildBlockParams): Promise<HexString[]>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HexString } from '@polkadot/util/types';
|
|
2
|
+
import { Block } from '../../block.js';
|
|
3
|
+
import { BuildBlockParams } from '../../txpool.js';
|
|
4
|
+
import { CreateInherents } from '../index.js';
|
|
5
|
+
export declare class SetBabeRandomness implements CreateInherents {
|
|
6
|
+
createInherents(parent: Block, _params: BuildBlockParams): Promise<HexString[]>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HexString } from '@polkadot/util/types';
|
|
2
|
+
import { Block } from '../../block.js';
|
|
3
|
+
import { BuildBlockParams } from '../../txpool.js';
|
|
4
|
+
import { CreateInherents } from '../index.js';
|
|
5
|
+
export declare class SetNimbusAuthorInherent implements CreateInherents {
|
|
6
|
+
createInherents(parent: Block, _params: BuildBlockParams): Promise<HexString[]>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HexString } from '@polkadot/util/types';
|
|
2
|
+
import { Block } from '../../block.js';
|
|
3
|
+
import { BuildBlockParams, DownwardMessage, HorizontalMessage } from '../../txpool.js';
|
|
4
|
+
import { CreateInherents } from '../index.js';
|
|
5
|
+
export type ValidationData = {
|
|
6
|
+
downwardMessages: DownwardMessage[];
|
|
7
|
+
horizontalMessages: Record<number, HorizontalMessage[]>;
|
|
8
|
+
validationData: {
|
|
9
|
+
relayParentNumber: number;
|
|
10
|
+
relayParentStorageRoot: HexString;
|
|
11
|
+
maxPovSize: number;
|
|
12
|
+
};
|
|
13
|
+
relayChainState: {
|
|
14
|
+
trieNodes: HexString[];
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export declare class SetValidationData implements CreateInherents {
|
|
18
|
+
createInherents(parent: Block, params: BuildBlockParams): Promise<HexString[]>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Api } from '../api.js';
|
|
2
|
+
import { Database } from '../database.js';
|
|
3
|
+
export declare const enum StorageValueKind {
|
|
4
|
+
Deleted = "Deleted",
|
|
5
|
+
DeletedPrefix = "DeletedPrefix"
|
|
6
|
+
}
|
|
7
|
+
export type StorageValue = string | StorageValueKind | undefined;
|
|
8
|
+
export interface StorageLayerProvider {
|
|
9
|
+
/**
|
|
10
|
+
* Get the value of a storage key.
|
|
11
|
+
*/
|
|
12
|
+
get(key: string, cache: boolean): Promise<StorageValue>;
|
|
13
|
+
/**
|
|
14
|
+
* Fold the storage layer into another layer.
|
|
15
|
+
*/
|
|
16
|
+
foldInto(into: StorageLayer): Promise<StorageLayerProvider | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Fold the storage layer into the parent if it exists.
|
|
19
|
+
*/
|
|
20
|
+
fold(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Get paged storage keys.
|
|
23
|
+
*/
|
|
24
|
+
getKeysPaged(prefix: string, pageSize: number, startKey: string): Promise<string[]>;
|
|
25
|
+
}
|
|
26
|
+
export declare class RemoteStorageLayer implements StorageLayerProvider {
|
|
27
|
+
#private;
|
|
28
|
+
constructor(api: Api, at: string, db: Database | undefined);
|
|
29
|
+
get(key: string, _cache: boolean): Promise<StorageValue>;
|
|
30
|
+
foldInto(_into: StorageLayer): Promise<StorageLayerProvider>;
|
|
31
|
+
fold(): Promise<void>;
|
|
32
|
+
getKeysPaged(prefix: string, pageSize: number, startKey: string): Promise<string[]>;
|
|
33
|
+
}
|
|
34
|
+
export declare class StorageLayer implements StorageLayerProvider {
|
|
35
|
+
#private;
|
|
36
|
+
constructor(parent?: StorageLayerProvider);
|
|
37
|
+
get(key: string, cache: boolean): Promise<StorageValue | undefined>;
|
|
38
|
+
set(key: string, value: StorageValue): void;
|
|
39
|
+
setAll(values: Record<string, StorageValue | null> | [string, StorageValue | null][]): void;
|
|
40
|
+
foldInto(into: StorageLayer): Promise<StorageLayerProvider | undefined>;
|
|
41
|
+
fold(): Promise<void>;
|
|
42
|
+
getKeysPaged(prefix: string, pageSize: number, startKey: string): Promise<string[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Merge the storage layer into the given object, can be used to get sotrage diff.
|
|
45
|
+
*/
|
|
46
|
+
mergeInto(into: Record<string, string | null>): Promise<void>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { EventEmitter } from 'eventemitter3';
|
|
2
|
+
import { HexString } from '@polkadot/util/types';
|
|
3
|
+
import { Blockchain } from './index.js';
|
|
4
|
+
import { InherentProvider } from './inherent/index.js';
|
|
5
|
+
export declare const APPLY_EXTRINSIC_ERROR = "TxPool::ApplyExtrinsicError";
|
|
6
|
+
export declare enum BuildBlockMode {
|
|
7
|
+
/** One block per batch (default) */
|
|
8
|
+
Batch = 0,
|
|
9
|
+
/** One block per tx */
|
|
10
|
+
Instant = 1,
|
|
11
|
+
/** Only build when triggered */
|
|
12
|
+
Manual = 2
|
|
13
|
+
}
|
|
14
|
+
export interface DownwardMessage {
|
|
15
|
+
sentAt: number;
|
|
16
|
+
msg: HexString;
|
|
17
|
+
}
|
|
18
|
+
export interface HorizontalMessage {
|
|
19
|
+
sentAt: number;
|
|
20
|
+
data: HexString;
|
|
21
|
+
}
|
|
22
|
+
export interface BuildBlockParams {
|
|
23
|
+
downwardMessages: DownwardMessage[];
|
|
24
|
+
upwardMessages: Record<number, HexString[]>;
|
|
25
|
+
horizontalMessages: Record<number, HorizontalMessage[]>;
|
|
26
|
+
transactions: HexString[];
|
|
27
|
+
unsafeBlockHeight?: number;
|
|
28
|
+
}
|
|
29
|
+
export declare class TxPool {
|
|
30
|
+
#private;
|
|
31
|
+
readonly event: EventEmitter<string | symbol, any>;
|
|
32
|
+
constructor(chain: Blockchain, inherentProvider: InherentProvider, mode?: BuildBlockMode);
|
|
33
|
+
get pendingExtrinsics(): HexString[];
|
|
34
|
+
get ump(): Record<number, HexString[]>;
|
|
35
|
+
get dmp(): DownwardMessage[];
|
|
36
|
+
get hrmp(): Record<number, HorizontalMessage[]>;
|
|
37
|
+
get mode(): BuildBlockMode;
|
|
38
|
+
set mode(mode: BuildBlockMode);
|
|
39
|
+
clear(): void;
|
|
40
|
+
pendingExtrinsicsBy(address: string): HexString[];
|
|
41
|
+
submitExtrinsic(extrinsic: HexString): Promise<void>;
|
|
42
|
+
submitUpwardMessages(id: number, ump: HexString[]): void;
|
|
43
|
+
submitDownwardMessages(dmp: DownwardMessage[]): void;
|
|
44
|
+
submitHorizontalMessages(id: number, hrmp: HorizontalMessage[]): void;
|
|
45
|
+
buildBlockWithParams(params: BuildBlockParams): Promise<void>;
|
|
46
|
+
buildBlock(params?: Partial<BuildBlockParams>): Promise<void>;
|
|
47
|
+
upcomingBlocks(): Promise<number>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
|
|
2
|
+
import { Blockchain } from './blockchain/index.js';
|
|
3
|
+
import { Database } from './database.js';
|
|
4
|
+
interface SubscriptionHandler {
|
|
5
|
+
callback: ProviderInterfaceCallback;
|
|
6
|
+
type: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Provider for local chopsticks chain
|
|
10
|
+
*/
|
|
11
|
+
export declare class ChopsticksProvider implements ProviderInterface {
|
|
12
|
+
#private;
|
|
13
|
+
readonly chain: Blockchain;
|
|
14
|
+
constructor(chain: Blockchain);
|
|
15
|
+
static fromEndpoint: (endpoint: string, block?: number | string | null, db?: Database) => Promise<ChopsticksProvider>;
|
|
16
|
+
get hasSubscriptions(): boolean;
|
|
17
|
+
get isClonable(): boolean;
|
|
18
|
+
get isConnected(): boolean;
|
|
19
|
+
get isReady(): Promise<void>;
|
|
20
|
+
clone: () => ChopsticksProvider;
|
|
21
|
+
connect: () => Promise<void>;
|
|
22
|
+
disconnect: () => Promise<void>;
|
|
23
|
+
on: (type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb) => (() => void);
|
|
24
|
+
subscriptionManager: {
|
|
25
|
+
subscribe: (method: string, subid: string, onCancel?: () => void) => (data: any) => void;
|
|
26
|
+
unsubscribe: (subid: string) => void;
|
|
27
|
+
};
|
|
28
|
+
send: <T>(method: string, params: unknown[], _isCacheable?: boolean, subscription?: SubscriptionHandler) => Promise<T>;
|
|
29
|
+
subscribe(type: string, method: string, params: unknown[], callback: ProviderInterfaceCallback): Promise<number | string>;
|
|
30
|
+
unsubscribe(_type: string, method: string, id: number | string): Promise<boolean>;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { HexString } from '@polkadot/util/types';
|
|
2
|
+
export interface BlockEntry {
|
|
3
|
+
hash: HexString;
|
|
4
|
+
number: number;
|
|
5
|
+
header: HexString;
|
|
6
|
+
parentHash: HexString | null;
|
|
7
|
+
extrinsics: HexString[];
|
|
8
|
+
storageDiff: Record<HexString, HexString | null> | null;
|
|
9
|
+
}
|
|
10
|
+
export interface KeyValueEntry {
|
|
11
|
+
blockHash: string;
|
|
12
|
+
key: string;
|
|
13
|
+
value: string | null;
|
|
14
|
+
}
|
|
15
|
+
export declare class Database {
|
|
16
|
+
constructor(location: string);
|
|
17
|
+
close: () => Promise<void>;
|
|
18
|
+
saveBlock: (block: BlockEntry) => Promise<void>;
|
|
19
|
+
queryBlock: (hash: HexString) => Promise<BlockEntry | null>;
|
|
20
|
+
queryBlockByNumber: (number: number) => Promise<BlockEntry | null>;
|
|
21
|
+
queryHighestBlock: () => Promise<BlockEntry | null>;
|
|
22
|
+
deleteBlock: (hash: HexString) => Promise<void>;
|
|
23
|
+
blocksCount: () => Promise<number>;
|
|
24
|
+
saveStorage: (blockHash: HexString, key: HexString, value: HexString | null) => Promise<void>;
|
|
25
|
+
queryStorage: (blockHash: HexString, key: HexString) => Promise<KeyValueEntry | null>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { HexString } from '@polkadot/util/types';
|
|
2
|
+
import { ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
|
|
3
|
+
import { Genesis } from './schema/index.js';
|
|
4
|
+
import { JsCallback } from './wasm-executor/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Provider to start a chain from genesis
|
|
7
|
+
*/
|
|
8
|
+
export declare class GenesisProvider implements ProviderInterface {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* @ignore
|
|
12
|
+
* Create a genesis provider
|
|
13
|
+
*
|
|
14
|
+
* @param genesis - genesis file
|
|
15
|
+
* @requires genesis provider
|
|
16
|
+
*/
|
|
17
|
+
constructor(genesis: Genesis);
|
|
18
|
+
get isClonable(): boolean;
|
|
19
|
+
clone: () => GenesisProvider;
|
|
20
|
+
get hasSubscriptions(): boolean;
|
|
21
|
+
get isConnected(): boolean;
|
|
22
|
+
get isReady(): Promise<void>;
|
|
23
|
+
connect: () => Promise<void>;
|
|
24
|
+
disconnect: () => Promise<void>;
|
|
25
|
+
on: (type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb) => (() => void);
|
|
26
|
+
get blockHash(): HexString;
|
|
27
|
+
getHeader: () => Promise<{
|
|
28
|
+
blockHash: `0x${string}`;
|
|
29
|
+
number: `0x${string}`;
|
|
30
|
+
stateRoot: `0x${string}`;
|
|
31
|
+
digest: {
|
|
32
|
+
logs: never[];
|
|
33
|
+
};
|
|
34
|
+
}>;
|
|
35
|
+
getBlock: () => Promise<{
|
|
36
|
+
block: {
|
|
37
|
+
header: {
|
|
38
|
+
blockHash: `0x${string}`;
|
|
39
|
+
number: `0x${string}`;
|
|
40
|
+
stateRoot: `0x${string}`;
|
|
41
|
+
digest: {
|
|
42
|
+
logs: never[];
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
extrinsics: never[];
|
|
46
|
+
};
|
|
47
|
+
}>;
|
|
48
|
+
get _jsCallback(): JsCallback;
|
|
49
|
+
send: (method: string, params: unknown[], _isCacheable?: boolean) => Promise<any>;
|
|
50
|
+
subscribe: (_type: string, _method: string, _params: unknown[], _cb: ProviderInterfaceCallback) => Promise<number | string>;
|
|
51
|
+
unsubscribe: (_type: string, _method: string, _id: number | string) => Promise<boolean>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chopsticks core package. A common package for usage in both server and browser.
|
|
3
|
+
* It contains a local blockchain implementation, a transaction pool, a runtime executor and more!
|
|
4
|
+
*
|
|
5
|
+
* @privateRemarks
|
|
6
|
+
* Above is the package description for `chopsticks-core` package.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
export * from './api.js';
|
|
11
|
+
export * from './blockchain/index.js';
|
|
12
|
+
export * from './blockchain/block.js';
|
|
13
|
+
export * from './blockchain/block-builder.js';
|
|
14
|
+
export * from './blockchain/txpool.js';
|
|
15
|
+
export * from './blockchain/storage-layer.js';
|
|
16
|
+
export * from './blockchain/head-state.js';
|
|
17
|
+
export * from './utils/index.js';
|
|
18
|
+
export * from './wasm-executor/index.js';
|
|
19
|
+
export * from './schema/index.js';
|
|
20
|
+
export * from './xcm/index.js';
|
|
21
|
+
export * from './setup.js';
|
|
22
|
+
export * from './database.js';
|
|
23
|
+
export * from './blockchain/inherent/index.js';
|
|
24
|
+
export * from './logger.js';
|
|
25
|
+
export * from './offchain.js';
|
|
26
|
+
export * from './chopsticks-provider.js';
|
|
27
|
+
export * from './genesis-provider.js';
|
|
28
|
+
export * from './rpc/index.js';
|