Move Extrinsic/Method to generic (#1205)
* Move Extrinsic/Method to generic * Strip Generic* primitives * Move Origin & Method, pass lint/tests
This commit is contained in:
@@ -23,10 +23,10 @@ import { Storage } from '@polkadot/api-metadata/storage/types';
|
||||
import storageFromMeta from '@polkadot/api-metadata/storage/fromMetadata';
|
||||
import RpcCore from '@polkadot/rpc-core';
|
||||
import { WsProvider } from '@polkadot/rpc-provider';
|
||||
import { getTypeRegistry, GenericEvent, Metadata, Method, Null, u64 } from '@polkadot/types';
|
||||
import { getTypeRegistry, GenericEvent, GenericMethod, 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 { MethodFunction, ModulesWithMethods } from '@polkadot/types/primitive/Method';
|
||||
import { MethodFunction, ModulesWithMethods } from '@polkadot/types/primitive/Generic/Method';
|
||||
import * as interfacesTypes from '@polkadot/types/interfaces/definitions';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import { assert, compactStripLength, isFunction, isObject, isUndefined, logger, u8aToHex } from '@polkadot/util';
|
||||
@@ -534,7 +534,7 @@ export default abstract class ApiBase<ApiType> {
|
||||
// only inject if we are not a clone (global init)
|
||||
if (!this._options.source) {
|
||||
GenericEvent.injectMetadata(this.runtimeMetadata);
|
||||
Method.injectMethods(extrinsics);
|
||||
GenericMethod.injectMethods(extrinsics);
|
||||
|
||||
// detect the extrinsic version in-use based on the last block
|
||||
const lastBlock: SignedBlock = await this._rpcCore.chain.getBlock().toPromise();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import extrinsics from '@polkadot/api-metadata/extrinsics/static';
|
||||
import { Method, ExtrinsicEra, SignaturePayload } from '@polkadot/types';
|
||||
import { createType, ClassOf, GenericMethod } from '@polkadot/types';
|
||||
|
||||
import SignerPayload from './SignerPayload';
|
||||
|
||||
@@ -21,7 +21,7 @@ describe('SignerPayload', (): void => {
|
||||
};
|
||||
|
||||
beforeEach((): void => {
|
||||
Method.injectMethods(extrinsics);
|
||||
GenericMethod.injectMethods(extrinsics);
|
||||
});
|
||||
|
||||
it('creates a valid JSON output', (): void => {
|
||||
@@ -30,9 +30,9 @@ describe('SignerPayload', (): void => {
|
||||
address: '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE',
|
||||
blockHash: '0xde8f69eeb5e065e18c6950ff708d7e551f68dc9bf59a07c52367c0280f805ec7',
|
||||
blockNumber: '0x231d30',
|
||||
era: new ExtrinsicEra({ current: 2301232, period: 200 }),
|
||||
era: createType('ExtrinsicEra', { current: 2301232, period: 200 }),
|
||||
genesisHash: '0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b',
|
||||
method: new Method('0x0500ffd7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9e56c'),
|
||||
method: createType('Method', '0x0500ffd7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9e56c'),
|
||||
nonce: 0x1234,
|
||||
tip: 0x5678,
|
||||
version: 2
|
||||
@@ -64,9 +64,9 @@ describe('SignerPayload', (): void => {
|
||||
).toEqual(TEST);
|
||||
});
|
||||
|
||||
it('can be used as a feed to SignaturePayload', (): void => {
|
||||
it('can be used as a feed to ExtrinsicPayload', (): void => {
|
||||
const signer = new SignerPayload(TEST).toPayload();
|
||||
const payload = new SignaturePayload(signer, { version: signer.version });
|
||||
const payload = new (ClassOf('ExtrinsicPayload'))(signer, { version: signer.version });
|
||||
|
||||
expect(payload.era.toHex()).toEqual(TEST.era);
|
||||
expect(payload.method.toHex()).toEqual(TEST.method);
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Address, Balance, BlockNumber, Hash, Index } from '@polkadot/types/interfaces';
|
||||
import { Address, Balance, BlockNumber, ExtrinsicEra, Hash, Index, Method } from '@polkadot/types/interfaces';
|
||||
import { SignerPayload as ISignerPayload } from './types';
|
||||
|
||||
import { ClassOf, Compact, ExtrinsicEra, Struct, u8, Method } from '@polkadot/types';
|
||||
import { ClassOf, Compact, Struct, u8 } from '@polkadot/types';
|
||||
|
||||
export interface SignerPayloadType {
|
||||
address: Address;
|
||||
@@ -23,9 +23,9 @@ export default class SignerPayload extends Struct.with({
|
||||
address: ClassOf('Address'),
|
||||
blockHash: ClassOf('Hash'),
|
||||
blockNumber: ClassOf('BlockNumber'),
|
||||
era: ExtrinsicEra,
|
||||
era: ClassOf('ExtrinsicEra'),
|
||||
genesisHash: ClassOf('Hash'),
|
||||
method: Method,
|
||||
method: ClassOf('Method'),
|
||||
nonce: ClassOf('Compact<Index>'),
|
||||
tip: ClassOf('Compact<Balance>'),
|
||||
version: u8
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AccountId, Address, ExtrinsicStatus, EventRecord, Hash, Header, Index, SignedBlock } from '@polkadot/types/interfaces';
|
||||
import { AccountId, Address, ExtrinsicEra, ExtrinsicStatus, EventRecord, Hash, Header, Index, Method, SignedBlock } from '@polkadot/types/interfaces';
|
||||
import { AnyNumber, AnyU8a, Callback, Codec, IExtrinsic, IExtrinsicEra, IKeyringPair, SignatureOptions } from '@polkadot/types/types';
|
||||
import { ApiInterfaceRx, ApiTypes } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { first, map, mergeMap, switchMap, tap } from 'rxjs/operators';
|
||||
import { createType, ClassOf, Method, Vec, ExtrinsicEra } from '@polkadot/types';
|
||||
import { createType, ClassOf, Vec } from '@polkadot/types';
|
||||
import { isBn, isFunction, isNumber, isUndefined } from '@polkadot/util';
|
||||
|
||||
import filterEvents from './util/filterEvents';
|
||||
@@ -196,7 +196,7 @@ export default function createSubmittableExtrinsic<ApiType> (
|
||||
|
||||
return expandOptions(options, {
|
||||
blockHash: header.hash,
|
||||
era: new ExtrinsicEra({
|
||||
era: createType('ExtrinsicEra', {
|
||||
current: header.number,
|
||||
period: options.era || DEFAULT_MORTAL_LENGTH
|
||||
}),
|
||||
|
||||
@@ -11,7 +11,7 @@ import { DeriveCustom } from '@polkadot/api-derive';
|
||||
import { Constants } from '@polkadot/api-metadata/consts/types';
|
||||
import { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
|
||||
import { u64 } from '@polkadot/types';
|
||||
import { MethodFunction } from '@polkadot/types/primitive/Method';
|
||||
import { MethodFunction } from '@polkadot/types/primitive/Generic/Method';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
|
||||
import ApiBase from './Base';
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { SignedBlock } from '@polkadot/types/interfaces';
|
||||
import { Extrinsic, SignedBlock } from '@polkadot/types/interfaces';
|
||||
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { Extrinsic } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import '@polkadot/types/injector';
|
||||
|
||||
import { EventRecord, Hash, Header, Index, SignedBlock } from '@polkadot/types/interfaces';
|
||||
|
||||
import Keyring from '@polkadot/keyring';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { createType } from '@polkadot/types';
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
import { randomAsHex } from '@polkadot/util-crypto';
|
||||
import { ExtrinsicEra } from '@polkadot/types';
|
||||
|
||||
import { SubmittableResult } from '../../../src';
|
||||
import ApiPromise from '../../../src/promise';
|
||||
@@ -150,7 +152,7 @@ describeE2E({
|
||||
it('makes a transfer (specified era)', async (done): Promise<void> => {
|
||||
const signedBlock = await api.rpc.chain.getBlock() as SignedBlock;
|
||||
const currentHeight = signedBlock.block.header.number;
|
||||
const exERA = new ExtrinsicEra({ current: currentHeight, period: 10 });
|
||||
const exERA = createType('ExtrinsicEra', { current: currentHeight, period: 10 });
|
||||
const ex = api.tx.balances.transfer(keyring.eve.address, 12345);
|
||||
|
||||
await ex.signAndSend(keyring.charlie, {
|
||||
@@ -162,7 +164,7 @@ describeE2E({
|
||||
it('makes a transfer (specified era, previous block)', async (done): Promise<void> => {
|
||||
const signedBlock = await api.rpc.chain.getBlock() as SignedBlock;
|
||||
const currentHeight = signedBlock.block.header.number.toBn().subn(1);
|
||||
const exERA = new ExtrinsicEra({ current: currentHeight, period: 10 });
|
||||
const exERA = createType('ExtrinsicEra', { current: currentHeight, period: 10 });
|
||||
const ex = api.tx.balances.transfer(keyring.eve.address, 12345);
|
||||
|
||||
await ex.signAndSend(keyring.charlie, {
|
||||
@@ -175,7 +177,7 @@ describeE2E({
|
||||
const nonce = await api.query.system.accountNonce(keyring.alice.address) as Index;
|
||||
const signedBlock = await api.rpc.chain.getBlock() as SignedBlock;
|
||||
const currentHeight = signedBlock.block.header.number;
|
||||
const exERA = new ExtrinsicEra({ current: currentHeight, period: 4 });
|
||||
const exERA = createType('ExtrinsicEra', { current: currentHeight, period: 4 });
|
||||
const eraDeath = exERA.asMortalEra.death(currentHeight.toNumber());
|
||||
const blockHash = signedBlock.block.header.hash;
|
||||
const ex = api.tx.balances.transfer(keyring.eve.address, 12345);
|
||||
@@ -203,7 +205,7 @@ describeE2E({
|
||||
const nonce = await api.query.system.accountNonce(keyring.alice.address) as Index;
|
||||
const signedBlock = await api.rpc.chain.getBlock() as SignedBlock;
|
||||
const currentHeight = signedBlock.block.header.number;
|
||||
const exERA = new ExtrinsicEra({ current: currentHeight, period: 4 });
|
||||
const exERA = createType('ExtrinsicEra', { current: currentHeight, period: 4 });
|
||||
const eraDeath = exERA.asMortalEra.death(currentHeight.toNumber());
|
||||
const blockHash = signedBlock.block.header.hash;
|
||||
const ex = api.tx.balances.transfer(keyring.eve.address, 12345);
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ChainProperties } from '@polkadot/types/interfaces';
|
||||
import { ChainProperties, Extrinsic } from '@polkadot/types/interfaces';
|
||||
|
||||
import { ClassOf, Extrinsic, Vec } from '@polkadot/types';
|
||||
import { ClassOf, Vec } from '@polkadot/types';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { Signer, SignerPayload, SignerResult } from '@polkadot/api/types';
|
||||
import { KeyringPair } from '@polkadot/keyring/types';
|
||||
|
||||
import { SignaturePayload } from '@polkadot/types';
|
||||
import { ClassOf } from '@polkadot/types';
|
||||
|
||||
let id = 0;
|
||||
|
||||
@@ -41,7 +41,7 @@ export default class SingleAccountSigner implements Signer {
|
||||
|
||||
return new Promise((resolve): void => {
|
||||
setTimeout((): void => {
|
||||
const signed = new SignaturePayload(payload, { version: payload.version }).sign(this.keyringPair);
|
||||
const signed = new (ClassOf('ExtrinsicPayload'))(payload, { version: payload.version }).sign(this.keyringPair);
|
||||
const result: SignerResult = { id: ++id, ...signed };
|
||||
|
||||
resolve(result);
|
||||
|
||||
Reference in New Issue
Block a user