Swap to latest extrinsic version if no blocks found (#1298)

* Swap to latest extrinsic version if no blocks found

* Rename const
This commit is contained in:
Jaco Greeff
2019-08-12 14:25:05 +02:00
committed by GitHub
parent 2fabf00a2a
commit e942e68798
2 changed files with 9 additions and 3 deletions
+6 -2
View File
@@ -20,7 +20,7 @@ import RpcCore from '@polkadot/rpc-core';
import { WsProvider } from '@polkadot/rpc-provider';
import { getTypeRegistry, GenericCall, GenericEvent, Metadata, Null, u64 } from '@polkadot/types';
import Linkage, { LinkageResult } from '@polkadot/types/codec/Linkage';
import { DEFAULT_VERSION as EXTRINSIC_DEFAULT_VERSION } from '@polkadot/types/primitive/Extrinsic/constants';
import { DEFAULT_VERSION as EXTRINSIC_DEFAULT_VERSION, LATEST_VERSION as EXTRINSIC_LATEST_VERSION } from '@polkadot/types/primitive/Extrinsic/constants';
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
import { assert, compactStripLength, isString, isUndefined, logger, u8aToHex, u8aToU8a } from '@polkadot/util';
import { cryptoWaitReady } from '@polkadot/util-crypto';
@@ -564,8 +564,12 @@ export default abstract class ApiBase<ApiType> {
// detect the extrinsic version in-use based on the last block
const lastBlock: SignedBlock = await this._rpcCore.chain.getBlock().toPromise();
const blockExtrinsic = lastBlock.block.extrinsics[0];
this._extrinsicType = lastBlock.block.extrinsics[0].type;
// If we haven't sync-ed to 1 yes, this won't have any values
this._extrinsicType = blockExtrinsic
? blockExtrinsic.type
: EXTRINSIC_LATEST_VERSION;
// HACK Assume that old versions, substrate 1.x is u64 BlockNumber/Nonce
// and has the old EventRecord format. Remove this ASAP with support for
@@ -8,7 +8,9 @@ export const BIT_UNSIGNED = 0;
export const EMPTY_U8A = new Uint8Array();
// TODO We really want to swap this to V2, however all the test data is setup
export const LATEST_VERSION = 3;
// TODO We really want to swap this to V3, however all the test data is setup
// for V1, so this will take some time to convert... "some" time :)
export const DEFAULT_VERSION = 1;