polkadot-api 0.6.0 → 0.7.1
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/index.d.mts +291 -67
- package/dist/index.d.ts +291 -67
- package/dist/index.js +574 -444
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +578 -435
- package/dist/index.mjs.map +1 -1
- package/dist/min/index.d.ts +291 -67
- package/dist/min/index.js +1 -1
- package/dist/min/index.js.map +1 -1
- package/package.json +10 -15
package/dist/index.d.mts
CHANGED
|
@@ -1,15 +1,109 @@
|
|
|
1
|
-
import { HexString, SS58String, Enum, Binary, Descriptors, QueryFromDescriptors, TxFromDescriptors, EventsFromDescriptors, ConstFromDescriptors, BlockHeader, RuntimeDescriptor } from '@polkadot-api/substrate-bindings';
|
|
2
|
-
export { AccountId, AssetDescriptor, Binary, Codec, ConstFromDescriptors, Enum, EnumVariant, ErrorsFromDescriptors, EventsFromDescriptors, FixedSizeBinary, GetEnum, HexString, PlainDescriptor, QueryFromDescriptors, ResultPayload, RuntimeDescriptor, SS58String, StorageDescriptor, TxDescriptor, TxFromDescriptors, _Enum } from '@polkadot-api/substrate-bindings';
|
|
3
|
-
import { Observable } from 'rxjs';
|
|
4
|
-
import { BlockInfo, SystemEvent as SystemEvent$1 } from '@polkadot-api/observable-client';
|
|
5
|
-
import { ChainSpecData } from '@polkadot-api/substrate-client';
|
|
6
1
|
import { JsonRpcProvider } from '@polkadot-api/json-rpc-provider';
|
|
2
|
+
import { RuntimeContext, ChainHead$, BlockInfo, SystemEvent as SystemEvent$1, getObservableClient } from '@polkadot-api/observable-client';
|
|
3
|
+
import { HexString, Binary, SS58String, Enum, BlockHeader } from '@polkadot-api/substrate-bindings';
|
|
4
|
+
export { AccountId, Binary, Codec, Enum, EnumVariant, FixedSizeBinary, GetEnum, HexString, ResultPayload, SS58String, _Enum } from '@polkadot-api/substrate-bindings';
|
|
5
|
+
import { ChainSpecData } from '@polkadot-api/substrate-client';
|
|
6
|
+
import { Observable } from 'rxjs';
|
|
7
|
+
import { PolkadotSigner } from '@polkadot-api/polkadot-signer';
|
|
7
8
|
export { PolkadotSigner } from '@polkadot-api/polkadot-signer';
|
|
8
9
|
|
|
10
|
+
type PlainDescriptor<T> = {
|
|
11
|
+
_type?: T;
|
|
12
|
+
};
|
|
13
|
+
type AssetDescriptor<T> = string & {
|
|
14
|
+
_type?: T;
|
|
15
|
+
};
|
|
16
|
+
type StorageDescriptor<Args extends Array<any>, T, Optional extends true | false> = {
|
|
17
|
+
_type: T;
|
|
18
|
+
_args: Args;
|
|
19
|
+
_optional: Optional;
|
|
20
|
+
};
|
|
21
|
+
type TxDescriptor<Args extends {} | undefined> = {
|
|
22
|
+
___: Args;
|
|
23
|
+
};
|
|
24
|
+
type RuntimeDescriptor<Args extends Array<any>, T> = [Args, T];
|
|
25
|
+
type DescriptorEntry<T> = Record<string, Record<string, T>>;
|
|
26
|
+
type PalletDescriptors = Record<string, [
|
|
27
|
+
Record<string, number>,
|
|
28
|
+
Record<string, number>,
|
|
29
|
+
Record<string, number>,
|
|
30
|
+
Record<string, number>,
|
|
31
|
+
Record<string, number>
|
|
32
|
+
]>;
|
|
33
|
+
type PalletsTypedef<St extends DescriptorEntry<StorageDescriptor<any, any, any>>, Tx extends DescriptorEntry<TxDescriptor<any>>, Ev extends DescriptorEntry<PlainDescriptor<any>>, Err extends DescriptorEntry<PlainDescriptor<any>>, Ct extends DescriptorEntry<PlainDescriptor<any>>> = {
|
|
34
|
+
__storage: St;
|
|
35
|
+
__tx: Tx;
|
|
36
|
+
__event: Ev;
|
|
37
|
+
__error: Err;
|
|
38
|
+
__const: Ct;
|
|
39
|
+
};
|
|
40
|
+
type ApisDescriptors = DescriptorEntry<number>;
|
|
41
|
+
type ApisTypedef<T extends DescriptorEntry<RuntimeDescriptor<any, any>>> = T;
|
|
42
|
+
type DescriptorsValue = {
|
|
43
|
+
pallets: PalletDescriptors;
|
|
44
|
+
apis: ApisDescriptors;
|
|
45
|
+
};
|
|
46
|
+
type ChainDefinition = {
|
|
47
|
+
descriptors: Promise<DescriptorsValue> & {
|
|
48
|
+
pallets: PalletsTypedef<any, any, any, any, any>;
|
|
49
|
+
apis: ApisTypedef<any>;
|
|
50
|
+
};
|
|
51
|
+
asset: AssetDescriptor<any>;
|
|
52
|
+
checksums: Promise<string[]>;
|
|
53
|
+
};
|
|
54
|
+
type ExtractStorage<T extends DescriptorEntry<StorageDescriptor<any, any, any>>> = {
|
|
55
|
+
[K in keyof T]: {
|
|
56
|
+
[KK in keyof T[K]]: T[K][KK] extends StorageDescriptor<infer Key, infer Value, infer Optional> ? {
|
|
57
|
+
KeyArgs: Key;
|
|
58
|
+
Value: Value;
|
|
59
|
+
IsOptional: Optional;
|
|
60
|
+
} : unknown;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
type ExtractTx<T extends DescriptorEntry<TxDescriptor<any>>> = {
|
|
64
|
+
[K in keyof T]: {
|
|
65
|
+
[KK in keyof T[K]]: T[K][KK] extends TxDescriptor<infer Args> ? Args : unknown;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
type ExtractPlain<T extends DescriptorEntry<PlainDescriptor<any>>> = {
|
|
69
|
+
[K in keyof T]: {
|
|
70
|
+
[KK in keyof T[K]]: T[K][KK] extends PlainDescriptor<infer Value> ? Value : unknown;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
type QueryFromPalletsDef<T extends PalletsTypedef<any, any, any, any, any>> = ExtractStorage<T["__storage"]>;
|
|
74
|
+
type TxFromPalletsDef<T extends PalletsTypedef<any, any, any, any, any>> = ExtractTx<T["__tx"]>;
|
|
75
|
+
type EventsFromPalletsDef<T extends PalletsTypedef<any, any, any, any, any>> = ExtractPlain<T["__event"]>;
|
|
76
|
+
type ErrorsFromPalletsDef<T extends PalletsTypedef<any, any, any, any, any>> = ExtractPlain<T["__error"]>;
|
|
77
|
+
type ConstFromPalletsDef<T extends PalletsTypedef<any, any, any, any, any>> = ExtractPlain<T["__const"]>;
|
|
78
|
+
|
|
79
|
+
declare const enum OpType {
|
|
80
|
+
Storage = 0,
|
|
81
|
+
Tx = 1,
|
|
82
|
+
Event = 2,
|
|
83
|
+
Error = 3,
|
|
84
|
+
Const = 4
|
|
85
|
+
}
|
|
9
86
|
declare class Runtime {
|
|
10
|
-
|
|
11
|
-
|
|
87
|
+
private _ctx;
|
|
88
|
+
private _checksums;
|
|
89
|
+
private _descriptors;
|
|
12
90
|
private constructor();
|
|
91
|
+
/**
|
|
92
|
+
* @access package - Internal implementation detail. Do not use.
|
|
93
|
+
*/
|
|
94
|
+
static _create(ctx: RuntimeContext, checksums: string[], descriptors: DescriptorsValue): Runtime;
|
|
95
|
+
/**
|
|
96
|
+
* @access package - Internal implementation detail. Do not use.
|
|
97
|
+
*/
|
|
98
|
+
_getCtx(): RuntimeContext;
|
|
99
|
+
/**
|
|
100
|
+
* @access package - Internal implementation detail. Do not use.
|
|
101
|
+
*/
|
|
102
|
+
_getPalletChecksum(opType: OpType, pallet: string, name: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* @access package - Internal implementation detail. Do not use.
|
|
105
|
+
*/
|
|
106
|
+
_getApiChecksum(name: string, method: string): string;
|
|
13
107
|
}
|
|
14
108
|
type RuntimeApi = Observable<Runtime> & {
|
|
15
109
|
latest: () => Promise<Runtime>;
|
|
@@ -18,6 +112,19 @@ interface IsCompatible {
|
|
|
18
112
|
(): Promise<boolean>;
|
|
19
113
|
(runtime: Runtime): boolean;
|
|
20
114
|
}
|
|
115
|
+
declare const compatibilityHelper: (runtimeApi: RuntimeApi, getDescriptorChecksum: (runtime: Runtime) => string) => (getChecksum: (ctx: RuntimeContext) => string | null) => {
|
|
116
|
+
isCompatible: IsCompatible;
|
|
117
|
+
waitChecksums: () => Promise<(ctx: RuntimeContext) => boolean>;
|
|
118
|
+
withCompatibleRuntime: <T>(chainHead: ChainHead$, mapper: (x: T) => string, error: () => Error) => (source$: Observable<T>) => Observable<[T, RuntimeContext]>;
|
|
119
|
+
compatibleRuntime$: (chainHead: ChainHead$, hash: string | null, error: () => Error) => Observable<RuntimeContext>;
|
|
120
|
+
};
|
|
121
|
+
type CompatibilityHelper = ReturnType<typeof compatibilityHelper>;
|
|
122
|
+
|
|
123
|
+
interface ConstantEntry<T> {
|
|
124
|
+
(): Promise<T>;
|
|
125
|
+
(runtime: Runtime): T;
|
|
126
|
+
isCompatible: IsCompatible;
|
|
127
|
+
}
|
|
21
128
|
|
|
22
129
|
type EventPhase = {
|
|
23
130
|
type: "ApplyExtrinsic";
|
|
@@ -64,53 +171,60 @@ type CallOptions$1 = Partial<{
|
|
|
64
171
|
at: string;
|
|
65
172
|
signal: AbortSignal;
|
|
66
173
|
}>;
|
|
67
|
-
type WithCallOptions$1<Args extends Array<any>> = [
|
|
174
|
+
type WithCallOptions$1<Args extends Array<any>> = Args["length"] extends 0 ? [options?: CallOptions$1] : [...args: Args, options?: CallOptions$1];
|
|
175
|
+
interface RuntimeCall<Args extends Array<any>, Payload> {
|
|
176
|
+
(...args: WithCallOptions$1<Args>): Promise<Payload>;
|
|
177
|
+
isCompatible: IsCompatible;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
type CallOptions = Partial<{
|
|
181
|
+
at: string;
|
|
182
|
+
signal: AbortSignal;
|
|
183
|
+
}>;
|
|
184
|
+
type WithCallOptions<Args extends Array<any>> = [
|
|
68
185
|
...args: Args,
|
|
69
|
-
options?: CallOptions
|
|
186
|
+
options?: CallOptions
|
|
70
187
|
];
|
|
71
188
|
type PossibleParents<A extends Array<any>> = A extends [...infer Left, any] ? Left | PossibleParents<Left> : [];
|
|
72
189
|
type StorageEntryWithoutKeys<Payload> = {
|
|
73
190
|
isCompatible: IsCompatible;
|
|
74
|
-
getValue: (options?: CallOptions
|
|
191
|
+
getValue: (options?: CallOptions) => Promise<Payload>;
|
|
75
192
|
watchValue: (bestOrFinalized?: "best" | "finalized") => Observable<Payload>;
|
|
76
193
|
};
|
|
77
194
|
type StorageEntryWithKeys<Args extends Array<any>, Payload> = {
|
|
78
195
|
isCompatible: IsCompatible;
|
|
79
|
-
getValue: (...args: [...WithCallOptions
|
|
196
|
+
getValue: (...args: [...WithCallOptions<Args>]) => Promise<Payload>;
|
|
80
197
|
watchValue: (...args: [...Args, bestOrFinalized?: "best" | "finalized"]) => Observable<Payload>;
|
|
81
|
-
getValues: (keys: Array<[...Args]>, options?: CallOptions
|
|
82
|
-
getEntries: (...args: WithCallOptions
|
|
198
|
+
getValues: (keys: Array<[...Args]>, options?: CallOptions) => Promise<Array<Payload>>;
|
|
199
|
+
getEntries: (...args: WithCallOptions<PossibleParents<Args>>) => Promise<Array<{
|
|
83
200
|
keyArgs: Args;
|
|
84
201
|
value: NonNullable<Payload>;
|
|
85
202
|
}>>;
|
|
86
203
|
};
|
|
87
204
|
type StorageEntry<Args extends Array<any>, Payload> = Args extends [] ? StorageEntryWithoutKeys<Payload> : StorageEntryWithKeys<Args, Payload>;
|
|
88
205
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
identifier: string;
|
|
93
|
-
value: Uint8Array;
|
|
94
|
-
additionalSigned: Uint8Array;
|
|
95
|
-
}>, metadata: Uint8Array, atBlockNumber: number, hasher?: (data: Uint8Array) => Uint8Array) => Promise<Uint8Array>;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
type TxBroadcastEvent = {
|
|
99
|
-
type: "broadcasted";
|
|
100
|
-
} | {
|
|
101
|
-
type: "bestChainBlockIncluded";
|
|
102
|
-
block: {
|
|
103
|
-
hash: string;
|
|
104
|
-
index: number;
|
|
105
|
-
};
|
|
106
|
-
} | ({
|
|
107
|
-
type: "finalized";
|
|
108
|
-
} & TxFinalizedPayload);
|
|
109
|
-
type TxEvent = TxBroadcastEvent | {
|
|
206
|
+
type TxEvent = TxSigned | TxBroadcasted | TxBestBlocksState | TxFinalized;
|
|
207
|
+
type TxBroadcastEvent = TxSigned | TxBroadcasted | TxBestBlocksState | TxFinalized;
|
|
208
|
+
type TxSigned = {
|
|
110
209
|
type: "signed";
|
|
111
|
-
|
|
210
|
+
txHash: HexString;
|
|
211
|
+
};
|
|
212
|
+
type TxBroadcasted = {
|
|
213
|
+
type: "broadcasted";
|
|
214
|
+
txHash: HexString;
|
|
215
|
+
};
|
|
216
|
+
type TxBestBlocksState = {
|
|
217
|
+
type: "txBestBlocksState";
|
|
218
|
+
txHash: HexString;
|
|
219
|
+
} & (TxInBestBlocksNotFound | TxInBestBlocksFound);
|
|
220
|
+
type TxInBestBlocksNotFound = {
|
|
221
|
+
found: false;
|
|
222
|
+
isValid: boolean;
|
|
112
223
|
};
|
|
113
|
-
type
|
|
224
|
+
type TxInBestBlocksFound = {
|
|
225
|
+
found: true;
|
|
226
|
+
} & TxEventsPayload;
|
|
227
|
+
type TxEventsPayload = {
|
|
114
228
|
ok: boolean;
|
|
115
229
|
events: Array<SystemEvent$1["event"]>;
|
|
116
230
|
block: {
|
|
@@ -118,7 +232,12 @@ type TxFinalizedPayload = {
|
|
|
118
232
|
index: number;
|
|
119
233
|
};
|
|
120
234
|
};
|
|
121
|
-
type
|
|
235
|
+
type TxFinalized = {
|
|
236
|
+
type: "finalized";
|
|
237
|
+
txHash: HexString;
|
|
238
|
+
} & TxEventsPayload;
|
|
239
|
+
type TxOptions<Asset> = Partial<void extends Asset ? {
|
|
240
|
+
at: HexString | "best" | "finalized";
|
|
122
241
|
tip: bigint;
|
|
123
242
|
mortality: {
|
|
124
243
|
mortal: false;
|
|
@@ -126,7 +245,9 @@ type HintedSignExtensions<Asset> = Partial<void extends Asset ? {
|
|
|
126
245
|
mortal: true;
|
|
127
246
|
period: number;
|
|
128
247
|
};
|
|
248
|
+
nonce: number;
|
|
129
249
|
} : {
|
|
250
|
+
at: HexString | "best" | "finalized";
|
|
130
251
|
tip: bigint;
|
|
131
252
|
mortality: {
|
|
132
253
|
mortal: false;
|
|
@@ -135,20 +256,22 @@ type HintedSignExtensions<Asset> = Partial<void extends Asset ? {
|
|
|
135
256
|
period: number;
|
|
136
257
|
};
|
|
137
258
|
asset: Asset;
|
|
259
|
+
nonce: number;
|
|
138
260
|
}>;
|
|
139
|
-
type
|
|
140
|
-
type
|
|
261
|
+
type TxFinalizedPayload = Omit<TxFinalized, "type">;
|
|
262
|
+
type TxPromise<Asset> = (from: PolkadotSigner, txOptions?: TxOptions<Asset>) => Promise<TxFinalizedPayload>;
|
|
263
|
+
type TxObservable<Asset> = (from: PolkadotSigner, txOptions?: TxOptions<Asset>) => Observable<TxEvent>;
|
|
141
264
|
interface TxCall {
|
|
142
265
|
(): Promise<Binary>;
|
|
143
266
|
(runtime: Runtime): Binary;
|
|
144
267
|
}
|
|
145
|
-
type
|
|
268
|
+
type TxSignFn<Asset> = (from: PolkadotSigner, txOptions?: TxOptions<Asset>) => Promise<HexString>;
|
|
146
269
|
type Transaction<Arg extends {} | undefined, Pallet extends string, Name extends string, Asset> = {
|
|
147
|
-
sign:
|
|
270
|
+
sign: TxSignFn<Asset>;
|
|
148
271
|
signSubmitAndWatch: TxObservable<Asset>;
|
|
149
|
-
signAndSubmit:
|
|
272
|
+
signAndSubmit: TxPromise<Asset>;
|
|
150
273
|
getEncodedData: TxCall;
|
|
151
|
-
getEstimatedFees: (from: Uint8Array | SS58String,
|
|
274
|
+
getEstimatedFees: (from: Uint8Array | SS58String, txOptions?: TxOptions<Asset>) => Promise<bigint>;
|
|
152
275
|
decodedCall: Enum<{
|
|
153
276
|
[P in Pallet]: Enum<{
|
|
154
277
|
[N in Name]: Arg;
|
|
@@ -160,21 +283,10 @@ interface TxEntry<Arg extends {} | undefined, Pallet extends string, Name extend
|
|
|
160
283
|
isCompatible: IsCompatible;
|
|
161
284
|
}
|
|
162
285
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
(runtime: Runtime): T;
|
|
166
|
-
isCompatible: IsCompatible;
|
|
167
|
-
}
|
|
286
|
+
declare const submit$: (chainHead: ChainHead$, broadcastTx$: (tx: string) => Observable<never>, tx: HexString, at?: HexString, emitSign?: boolean) => Observable<TxEvent>;
|
|
287
|
+
declare const submit: (chainHead: ChainHead$, broadcastTx$: (tx: string) => Observable<never>, transaction: HexString, at?: HexString) => Promise<TxFinalizedPayload>;
|
|
168
288
|
|
|
169
|
-
|
|
170
|
-
at: string;
|
|
171
|
-
signal: AbortSignal;
|
|
172
|
-
}>;
|
|
173
|
-
type WithCallOptions<Args extends Array<any>> = Args["length"] extends 0 ? [options?: CallOptions] : [...args: Args, options?: CallOptions];
|
|
174
|
-
interface RuntimeCall<Args extends Array<any>, Payload> {
|
|
175
|
-
(...args: WithCallOptions<Args>): Promise<Payload>;
|
|
176
|
-
isCompatible: IsCompatible;
|
|
177
|
-
}
|
|
289
|
+
declare const createTxEntry: <Arg extends {} | undefined, Pallet extends string, Name extends string, Asset extends AssetDescriptor<any>>(pallet: Pallet, name: Name, assetChecksum: Asset, chainHead: ReturnType<ReturnType<typeof getObservableClient>["chainHead$"]>, broadcast: (tx: string) => Observable<never>, compatibilityHelper: CompatibilityHelper) => TxEntry<Arg, Pallet, Name, Asset["_type"]>;
|
|
178
290
|
|
|
179
291
|
type StorageApi<A extends Record<string, Record<string, {
|
|
180
292
|
KeyArgs: Array<any>;
|
|
@@ -209,32 +321,144 @@ type ConstApi<A extends Record<string, Record<string, any>>> = {
|
|
|
209
321
|
[KK in keyof A[K]]: ConstantEntry<A[K][KK]>;
|
|
210
322
|
};
|
|
211
323
|
};
|
|
212
|
-
type TypedApi<D extends
|
|
213
|
-
query: StorageApi<
|
|
214
|
-
tx: TxApi<
|
|
215
|
-
event: EvApi<
|
|
216
|
-
apis: RuntimeCallsApi<D["apis"]>;
|
|
217
|
-
constants: ConstApi<
|
|
324
|
+
type TypedApi<D extends ChainDefinition> = {
|
|
325
|
+
query: StorageApi<QueryFromPalletsDef<D["descriptors"]["pallets"]>>;
|
|
326
|
+
tx: TxApi<TxFromPalletsDef<D["descriptors"]["pallets"]>, D["asset"]["_type"]>;
|
|
327
|
+
event: EvApi<EventsFromPalletsDef<D["descriptors"]["pallets"]>>;
|
|
328
|
+
apis: RuntimeCallsApi<D["descriptors"]["apis"]>;
|
|
329
|
+
constants: ConstApi<ConstFromPalletsDef<D["descriptors"]["pallets"]>>;
|
|
218
330
|
runtime: RuntimeApi;
|
|
219
331
|
};
|
|
220
332
|
interface PolkadotClient {
|
|
333
|
+
/**
|
|
334
|
+
* Retrieve the ChainSpecData as it comes from the
|
|
335
|
+
* [JSON-RPC spec](https://paritytech.github.io/json-rpc-interface-spec/api/chainSpec.html)
|
|
336
|
+
*/
|
|
221
337
|
getChainSpecData: () => Promise<ChainSpecData>;
|
|
338
|
+
/**
|
|
339
|
+
* Observable that emits `BlockInfo` from the latest known finalized block.
|
|
340
|
+
* It's a multicast and stateful observable, that will synchronously replay
|
|
341
|
+
* its latest known state.
|
|
342
|
+
*/
|
|
222
343
|
finalizedBlock$: Observable<BlockInfo>;
|
|
344
|
+
/**
|
|
345
|
+
* @returns Latest known finalized block.
|
|
346
|
+
*/
|
|
223
347
|
getFinalizedBlock: () => Promise<BlockInfo>;
|
|
348
|
+
/**
|
|
349
|
+
* Observable that emits an Array of `BlockInfo`, being the first element the
|
|
350
|
+
* latest known best block, and the last element the latest known finalized
|
|
351
|
+
* block. It's a multicast and stateful observable, that will synchronously
|
|
352
|
+
* replay its latest known state. This array is an immutable data structure;
|
|
353
|
+
* i.e. a new array is emitted at every event but the reference to its
|
|
354
|
+
* children are stable if the children didn't change.
|
|
355
|
+
*
|
|
356
|
+
* Note that subscribing to this observable already supersedes the need of
|
|
357
|
+
* subscribing to `finalizedBlock$`, since the last element of the array will
|
|
358
|
+
* be the latest known finalized block.
|
|
359
|
+
*/
|
|
224
360
|
bestBlocks$: Observable<BlockInfo[]>;
|
|
361
|
+
/**
|
|
362
|
+
* @returns Array of `BlockInfo`, being the first element the latest
|
|
363
|
+
* known best block, and the last element the latest known
|
|
364
|
+
* finalized block.
|
|
365
|
+
*/
|
|
225
366
|
getBestBlocks: () => Promise<BlockInfo[]>;
|
|
367
|
+
/**
|
|
368
|
+
* Observable to watch Block Body.
|
|
369
|
+
*
|
|
370
|
+
* @param hash It can be a block hash, `"finalized"`, or `"best"`
|
|
371
|
+
* @returns Observable to watch a block body. There'll be just one event
|
|
372
|
+
* with the payload and the observable will complete.
|
|
373
|
+
*/
|
|
226
374
|
watchBlockBody: (hash: string) => Observable<HexString[]>;
|
|
375
|
+
/**
|
|
376
|
+
* Get Block Body (Promise-based)
|
|
377
|
+
*
|
|
378
|
+
* @param hash It can be a block hash, `"finalized"`, or `"best"`
|
|
379
|
+
* @returns Block body.
|
|
380
|
+
*/
|
|
227
381
|
getBlockBody: (hash: string) => Promise<HexString[]>;
|
|
382
|
+
/**
|
|
383
|
+
* Get Block Header (Promise-based)
|
|
384
|
+
*
|
|
385
|
+
* @param hash It can be a block hash, `"finalized"` (default), or
|
|
386
|
+
* `"best"`
|
|
387
|
+
* @returns Block hash.
|
|
388
|
+
*/
|
|
228
389
|
getBlockHeader: (hash?: string) => Promise<BlockHeader>;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
390
|
+
/**
|
|
391
|
+
* Broadcast a transaction (Promise-based)
|
|
392
|
+
*
|
|
393
|
+
* @param transaction SCALE-encoded tx to broadcast.
|
|
394
|
+
* @param at It can be a block hash, `"finalized"`, or `"best"`.
|
|
395
|
+
* That block will be used to verify the validity of
|
|
396
|
+
* the tx, retrieve the next nonce,
|
|
397
|
+
* and create the mortality taking that block into
|
|
398
|
+
* account.
|
|
399
|
+
*/
|
|
400
|
+
submit: (transaction: HexString, at?: HexString) => Promise<TxFinalizedPayload>;
|
|
401
|
+
/**
|
|
402
|
+
* Broadcast a transaction and returns an Observable. The observable will
|
|
403
|
+
* complete as soon as the transaction is in a finalized block.
|
|
404
|
+
*
|
|
405
|
+
* @param transaction SCALE-encoded tx to broadcast.
|
|
406
|
+
* @param at It can be a block hash, `"finalized"`, or `"best"`.
|
|
407
|
+
* That block will be used to verify the validity of
|
|
408
|
+
* the tx, retrieve the next nonce,
|
|
409
|
+
* and create the mortality taking that block into
|
|
410
|
+
* account.
|
|
411
|
+
*/
|
|
412
|
+
submitAndWatch: (transaction: HexString, at?: HexString) => Observable<TxBroadcastEvent>;
|
|
413
|
+
/**
|
|
414
|
+
* Returns an instance of a `TypedApi`
|
|
415
|
+
*
|
|
416
|
+
* @param descriptors Pass descriptors from `@polkadot-api/descriptors`
|
|
417
|
+
* generated by `papi` CLI.
|
|
418
|
+
*/
|
|
419
|
+
getTypedApi: <D extends ChainDefinition>(descriptors: D) => TypedApi<D>;
|
|
232
420
|
destroy: () => void;
|
|
421
|
+
/**
|
|
422
|
+
* This API is meant as an "escape hatch" to allow access to debug endpoints
|
|
423
|
+
* such as `system_version`, and other useful endpoints that are not spec
|
|
424
|
+
* compliant.
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
*
|
|
428
|
+
* const systemVersion = await client._request<string>("system_version", [])
|
|
429
|
+
* const myFancyThhing = await client._request<
|
|
430
|
+
* { value: string },
|
|
431
|
+
* [id: number]
|
|
432
|
+
* >("very_fancy", [1714])
|
|
433
|
+
*
|
|
434
|
+
*/
|
|
435
|
+
_request: <Reply = any, Params extends Array<any> = any[]>(method: string, params: Params) => Promise<Reply>;
|
|
233
436
|
}
|
|
234
437
|
type FixedSizeArray<L extends number, T> = Array<T> & {
|
|
235
438
|
length: L;
|
|
236
439
|
};
|
|
237
440
|
|
|
441
|
+
/**
|
|
442
|
+
* This is the top-level export for `polkadot-api`.
|
|
443
|
+
*
|
|
444
|
+
* @param provider A `JsonRpcProvider` compliant with the [JSON-RPC
|
|
445
|
+
* spec](https://paritytech.github.io/json-rpc-interface-spec/),
|
|
446
|
+
* which must support the `chainHead`, `transaction` and
|
|
447
|
+
* `chainSpec` groups.
|
|
448
|
+
* @example
|
|
449
|
+
*
|
|
450
|
+
* import { createClient } from "polkadot-api"
|
|
451
|
+
* import { getSmProvider } from "polkadot-api/sm-provider"
|
|
452
|
+
* import { chainSpec } from "polkadot-api/chains/polkadot"
|
|
453
|
+
* import { start } from "polkadot-api/smoldot"
|
|
454
|
+
*
|
|
455
|
+
* const smoldot = start()
|
|
456
|
+
* const chain = await smoldot.addChain({ chainSpec })
|
|
457
|
+
*
|
|
458
|
+
* // Connect to the polkadot relay chain.
|
|
459
|
+
* const client = createClient(getSmProvider(chain))
|
|
460
|
+
*
|
|
461
|
+
*/
|
|
238
462
|
declare function createClient(provider: JsonRpcProvider): PolkadotClient;
|
|
239
463
|
|
|
240
|
-
export { type EventPhase, type FixedSizeArray, type PolkadotClient, type Transaction, type TxBroadcastEvent, type TxEvent, type TxFinalizedPayload, type TypedApi, createClient };
|
|
464
|
+
export { type ApisDescriptors, type ApisTypedef, type AssetDescriptor, type ChainDefinition, type ConstFromPalletsDef, type DescriptorEntry, type DescriptorsValue, type ErrorsFromPalletsDef, type EventPhase, type EventsFromPalletsDef, type FixedSizeArray, type PalletDescriptors, type PalletsTypedef, type PlainDescriptor, type PolkadotClient, type QueryFromPalletsDef, type RuntimeDescriptor, type StorageDescriptor, type Transaction, type TxBestBlocksState, type TxBroadcastEvent, type TxBroadcasted, type TxCall, type TxDescriptor, type TxEntry, type TxEvent, type TxEventsPayload, type TxFinalized, type TxFinalizedPayload, type TxFromPalletsDef, type TxInBestBlocksFound, type TxInBestBlocksNotFound, type TxObservable, type TxOptions, type TxPromise, type TxSignFn, type TxSigned, type TypedApi, createClient, createTxEntry, submit, submit$ };
|