Skip to content

Commit 9e35ed6

Browse files
api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 13.1.1
1 parent ddc00f7 commit 9e35ed6

File tree

29 files changed

+2295
-166
lines changed

29 files changed

+2295
-166
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## master
44

5+
- api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 13.1.1
56
- hw-{ledger, ledger-transports}, keyring, networks, util, util-crypto, x-{bigint, fetch, global, randomvalues, textdecoder, textencoder, ws} 13.1.1
67
- api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 13.0.1
78
- api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 12.4.2

api-augment/kusama/runtime.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { BeefyAuthoritySet, BeefyEquivocationProof, BeefyNextAuthoritySet,
1010
import type { CheckInherentsResult, InherentData } from 'https://deno.land/x/polkadot/types/interfaces/blockbuilder/index.ts';
1111
import type { BlockHash } from 'https://deno.land/x/polkadot/types/interfaces/chain/index.ts';
1212
import type { AuthorityId } from 'https://deno.land/x/polkadot/types/interfaces/consensus/index.ts';
13+
import type { CallDryRunEffects, XcmDryRunApiError, XcmDryRunEffects } from 'https://deno.land/x/polkadot/types/interfaces/dryRunApi/index.ts';
1314
import type { Extrinsic } from 'https://deno.land/x/polkadot/types/interfaces/extrinsics/index.ts';
1415
import type { GenesisBuildErr } from 'https://deno.land/x/polkadot/types/interfaces/genesisBuilder/index.ts';
1516
import type { AuthorityList, GrandpaEquivocationProof, SetId } from 'https://deno.land/x/polkadot/types/interfaces/grandpa/index.ts';
@@ -18,12 +19,13 @@ import type { MmrBatchProof, MmrEncodableOpaqueLeaf, MmrError } from 'https://de
1819
import type { NpPoolId } from 'https://deno.land/x/polkadot/types/interfaces/nompools/index.ts';
1920
import type { ApprovalVotingParams, AsyncBackingParams, BackingState, CandidateCommitments, CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreIndex, CoreState, DisputeProof, DisputeState, ExecutorParams, GroupRotationInfo, InboundDownwardMessage, InboundHrmpMessage, NodeFeatures, OccupiedCoreAssumption, ParaId, ParaValidatorIndex, PendingSlashes, PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes, SessionInfo, ValidationCode, ValidationCodeHash, ValidatorSignature } from 'https://deno.land/x/polkadot/types/interfaces/parachains/index.ts';
2021
import type { FeeDetails, RuntimeDispatchInfo } from 'https://deno.land/x/polkadot/types/interfaces/payment/index.ts';
21-
import type { AccountId, Balance, Block, BlockNumber, Call, ExtrinsicInclusionMode, Hash, Header, Index, KeyTypeId, Slot, ValidatorId, Weight, WeightV2 } from 'https://deno.land/x/polkadot/types/interfaces/runtime/index.ts';
22+
import type { AccountId, Balance, Block, BlockNumber, Call, ExtrinsicInclusionMode, Hash, Header, Index, KeyTypeId, OriginCaller, RuntimeCall, Slot, ValidatorId, Weight, WeightV2 } from 'https://deno.land/x/polkadot/types/interfaces/runtime/index.ts';
2223
import type { SessionIndex } from 'https://deno.land/x/polkadot/types/interfaces/session/index.ts';
2324
import type { ValidatorIndex } from 'https://deno.land/x/polkadot/types/interfaces/staking/index.ts';
2425
import type { RuntimeVersion } from 'https://deno.land/x/polkadot/types/interfaces/state/index.ts';
2526
import type { ApplyExtrinsicResult } from 'https://deno.land/x/polkadot/types/interfaces/system/index.ts';
2627
import type { TransactionSource, TransactionValidity } from 'https://deno.land/x/polkadot/types/interfaces/txqueue/index.ts';
28+
import type { VersionedMultiLocation, VersionedXcm } from 'https://deno.land/x/polkadot/types/interfaces/xcm/index.ts';
2729
import type { XcmPaymentApiError } from 'https://deno.land/x/polkadot/types/interfaces/xcmPaymentApi/index.ts';
2830
import type { Error } from 'https://deno.land/x/polkadot/types/interfaces/xcmRuntimeApi/index.ts';
2931
import type { XcmVersionedAssetId, XcmVersionedLocation, XcmVersionedXcm } from 'https://deno.land/x/polkadot/types/lookup.ts';
@@ -167,6 +169,21 @@ declare module 'https://deno.land/x/polkadot/api-base/types/calls.ts' {
167169
**/
168170
[key: string]: DecoratedCallBase<ApiType>;
169171
};
172+
/** 0x91b1c8b16328eb92/1 */
173+
dryRunApi: {
174+
/**
175+
* Dry run call
176+
**/
177+
dryRunCall: AugmentedCall<ApiType, (origin: OriginCaller | { System: any } | string | Uint8Array, call: RuntimeCall | IMethod | string | Uint8Array) => Observable<Result<CallDryRunEffects, XcmDryRunApiError>>>;
178+
/**
179+
* Dry run XCM program
180+
**/
181+
dryRunXcm: AugmentedCall<ApiType, (originLocation: VersionedMultiLocation | { V0: any } | { V1: any } | { V2: any } | { V3: any } | { V4: any } | string | Uint8Array, xcm: VersionedXcm | { V0: any } | { V1: any } | { V2: any } | { V3: any } | { V4: any } | string | Uint8Array) => Observable<Result<XcmDryRunEffects, XcmDryRunApiError>>>;
182+
/**
183+
* Generic call
184+
**/
185+
[key: string]: DecoratedCallBase<ApiType>;
186+
};
170187
/** 0xfbc577b9d747efd6/1 */
171188
genesisBuilder: {
172189
/**

api-augment/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.0.1' };
3+
export const packageInfo = { name: '@polkadot/api-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.1.1' };

api-base/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-base', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.0.1' };
3+
export const packageInfo = { name: '@polkadot/api-base', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.1.1' };

api-contract/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-contract', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.0.1' };
3+
export const packageInfo = { name: '@polkadot/api-contract', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.1.1' };

api-derive/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-derive', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.0.1' };
3+
export const packageInfo = { name: '@polkadot/api-derive', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.1.1' };

api/base/Init.ts

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
import type { Observable, Subscription } from 'https://esm.sh/rxjs@7.8.1';
3-
import type { Text } from 'https://deno.land/x/polkadot/types/mod.ts';
3+
import type { Bytes, Text, u32, Vec } from 'https://deno.land/x/polkadot/types/mod.ts';
44
import type { ExtDef } from 'https://deno.land/x/polkadot/types/extrinsic/signedExtensions/types.ts';
5-
import type { ChainProperties, Hash, HeaderPartial, RuntimeVersion, RuntimeVersionPartial } from 'https://deno.land/x/polkadot/types/interfaces/index.ts';
5+
import type { BlockHash, ChainProperties, Hash, HeaderPartial, RuntimeVersion, RuntimeVersionApi, RuntimeVersionPartial } from 'https://deno.land/x/polkadot/types/interfaces/index.ts';
66
import type { Registry } from 'https://deno.land/x/polkadot/types/types/index.ts';
77
import type { BN } from 'https://deno.land/x/polkadot/util/mod.ts';
88
import type { HexString } from 'https://deno.land/x/polkadot/util/types.ts';
@@ -14,12 +14,13 @@ import { firstValueFrom, map, of, switchMap } from 'https://esm.sh/rxjs@7.8.1';
1414
import { Metadata, TypeRegistry } from 'https://deno.land/x/polkadot/types/mod.ts';
1515
import { getSpecAlias, getSpecExtensions, getSpecHasher, getSpecRpc, getSpecTypes, getUpgradeVersion } from 'https://deno.land/x/polkadot/types-known/mod.ts';
1616
import { assertReturn, BN_ZERO, isUndefined, logger, noop, objectSpread, u8aEq, u8aToHex, u8aToU8a } from 'https://deno.land/x/polkadot/util/mod.ts';
17-
import { cryptoWaitReady } from 'https://deno.land/x/polkadot/util-crypto/mod.ts';
17+
import { blake2AsHex, cryptoWaitReady } from 'https://deno.land/x/polkadot/util-crypto/mod.ts';
1818

1919
import { Decorate } from './Decorate.ts';
2020

2121
const KEEPALIVE_INTERVAL = 10000;
2222
const WITH_VERSION_SHORTCUT = false;
23+
const SUPPORTED_METADATA_VERSIONS = [15, 14];
2324

2425
const l = logger('api/init');
2526

@@ -123,9 +124,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
123124

124125
private async _createBlockRegistry (blockHash: Uint8Array, header: HeaderPartial, version: RuntimeVersionPartial): Promise<VersionedRegistry<ApiType>> {
125126
const registry = new TypeRegistry(blockHash);
126-
const metadata = new Metadata(registry,
127-
await firstValueFrom(this._rpcCore.state.getMetadata.raw<HexString>(header.parentHash))
128-
);
127+
const metadata = await this._retrieveMetadata(version.apis, header.parentHash, registry);
129128
const runtimeChain = this._runtimeChain;
130129

131130
if (!runtimeChain) {
@@ -328,15 +327,12 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
328327
}
329328

330329
private async _metaFromChain (optMetadata?: Record<string, HexString>): Promise<[Hash, Metadata]> {
331-
const [genesisHash, runtimeVersion, chain, chainProps, rpcMethods, chainMetadata] = await Promise.all([
330+
const [genesisHash, runtimeVersion, chain, chainProps, rpcMethods] = await Promise.all([
332331
firstValueFrom(this._rpcCore.chain.getBlockHash(0)),
333332
firstValueFrom(this._rpcCore.state.getRuntimeVersion()),
334333
firstValueFrom(this._rpcCore.system.chain()),
335334
firstValueFrom(this._rpcCore.system.properties()),
336-
firstValueFrom(this._rpcCore.rpc.methods()),
337-
optMetadata
338-
? Promise.resolve(null)
339-
: firstValueFrom(this._rpcCore.state.getMetadata())
335+
firstValueFrom(this._rpcCore.rpc.methods())
340336
]);
341337

342338
// set our chain version & genesisHash as returned
@@ -346,11 +342,9 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
346342

347343
// retrieve metadata, either from chain or as pass-in via options
348344
const metadataKey = `${genesisHash.toHex() || '0x'}-${runtimeVersion.specVersion.toString()}`;
349-
const metadata = chainMetadata || (
350-
optMetadata?.[metadataKey]
351-
? new Metadata(this.registry, optMetadata[metadataKey])
352-
: await firstValueFrom(this._rpcCore.state.getMetadata())
353-
);
345+
const metadata = optMetadata?.[metadataKey]
346+
? new Metadata(this.registry, optMetadata[metadataKey])
347+
: await this._retrieveMetadata(runtimeVersion.apis);
354348

355349
// initializes the registry & RPC
356350
this._initRegistry(this.registry, chain, runtimeVersion, metadata, chainProps);
@@ -390,6 +384,72 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
390384
return true;
391385
}
392386

387+
/**
388+
* @internal
389+
*
390+
* Tries to use runtime api calls to retrieve metadata. This ensures the api initializes with the latest metadata.
391+
* If the runtime call is not there it will use the rpc method.
392+
*/
393+
private async _retrieveMetadata (apis: Vec<RuntimeVersionApi>, at?: BlockHash | string | Uint8Array, registry?: TypeRegistry): Promise<Metadata> {
394+
let metadataVersion: u32 | null = null;
395+
const metadataApi = apis.find(([a]) => a.eq(blake2AsHex('Metadata', 64)));
396+
const typeRegistry = registry || this.registry;
397+
398+
// This chain does not have support for the metadataApi, or does not have the required version.
399+
if (!metadataApi || metadataApi[1].toNumber() < 2) {
400+
l.warn('MetadataApi not available, rpc::state::get_metadata will be used.');
401+
402+
return at
403+
? new Metadata(typeRegistry, await firstValueFrom(this._rpcCore.state.getMetadata.raw<HexString>(at)))
404+
: await firstValueFrom(this._rpcCore.state.getMetadata());
405+
}
406+
407+
try {
408+
const metadataVersionsAsBytes = at
409+
? await firstValueFrom(this._rpcCore.state.call.raw('Metadata_metadata_versions', '0x', at))
410+
: await firstValueFrom(this._rpcCore.state.call('Metadata_metadata_versions', '0x'));
411+
const versions = typeRegistry.createType('Vec<u32>', metadataVersionsAsBytes);
412+
413+
metadataVersion = versions.reduce((largest, current) => current.gt(largest) ? current : largest);
414+
} catch (e) {
415+
l.debug((e as Error).message);
416+
l.warn('error with state_call::Metadata_metadata_versions, rpc::state::get_metadata will be used');
417+
}
418+
419+
// When the metadata version does not align with the latest supported versions we ensure not to call the metadata runtime call.
420+
// I noticed on some previous runtimes that have support for `Metadata_metadata_at_version` that very irregular versions were being returned.
421+
// This was evident with runtime 1000000 - it return a very large number. This ensures we always stick within what is supported.
422+
if (metadataVersion && !SUPPORTED_METADATA_VERSIONS.includes(metadataVersion.toNumber())) {
423+
metadataVersion = null;
424+
}
425+
426+
if (metadataVersion) {
427+
try {
428+
const metadataBytes = at
429+
? await firstValueFrom(this._rpcCore.state.call.raw<Bytes>('Metadata_metadata_at_version', u8aToHex(metadataVersion.toU8a()), at))
430+
: await firstValueFrom(this._rpcCore.state.call('Metadata_metadata_at_version', u8aToHex(metadataVersion.toU8a())));
431+
// When the metadata is called with `at` it is required to use `.raw`. Therefore since the length prefix is not present the
432+
// need to create a `Raw` type is necessary before creating the `OpaqueMetadata` type or else there will be a magic number
433+
// mismatch
434+
const rawMeta = at
435+
? typeRegistry.createType('Raw', metadataBytes).toU8a()
436+
: metadataBytes;
437+
const opaqueMetadata = typeRegistry.createType('Option<OpaqueMetadata>', rawMeta).unwrapOr(null);
438+
439+
if (opaqueMetadata) {
440+
return new Metadata(typeRegistry, opaqueMetadata.toHex());
441+
}
442+
} catch (e) {
443+
l.debug((e as Error).message);
444+
l.warn('error with state_call::Metadata_metadata_at_version, rpc::state::get_metadata will be used');
445+
}
446+
}
447+
448+
return at
449+
? new Metadata(typeRegistry, await firstValueFrom(this._rpcCore.state.getMetadata.raw<HexString>(at)))
450+
: await firstValueFrom(this._rpcCore.state.getMetadata());
451+
}
452+
393453
private _subscribeHealth (): void {
394454
this._unsubscribeHealth();
395455

api/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.0.1' };
3+
export const packageInfo = { name: '@polkadot/api', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.1.1' };

rpc-augment/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/rpc-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.0.1' };
3+
export const packageInfo = { name: '@polkadot/rpc-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.1.1' };

rpc-core/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/rpc-core', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.0.1' };
3+
export const packageInfo = { name: '@polkadot/rpc-core', path: new URL(import.meta.url).pathname, type: 'deno', version: '13.1.1' };

0 commit comments

Comments
 (0)