Convert all type/* (and some primitives) to srml/* (#1189)

* Convert (almost-all) non-primitives (and some primitives) to srml/*

* Move Vote to primitives, remove type folder

* Move Balance :-o

* Fixup tests, override Balance.toRaw()
This commit is contained in:
Jaco Greeff
2019-07-25 16:34:47 +02:00
committed by GitHub
parent 6d65095ee0
commit 39323a8896
112 changed files with 489 additions and 794 deletions
+3 -2
View File
@@ -3,6 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { ISubmittableResult, SubmittableResult } from '@polkadot/api/SubmittableExtrinsic';
import { Hash } from '@polkadot/types/srml/types';
import { IKeyringPair } from '@polkadot/types/types';
import { ContractABI } from './types';
@@ -10,7 +11,7 @@ import BN from 'bn.js';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { ApiRx } from '@polkadot/api';
import { AccountId, Address, Hash } from '@polkadot/types';
import { createType, AccountId, Address } from '@polkadot/types';
import Abi from './Abi';
import RxBase from './RxBase';
@@ -39,7 +40,7 @@ export default class Blueprint extends RxBase {
public constructor (api: ApiRx, abi: ContractABI | Abi, codeHash: string | Hash) {
super(api, abi);
this.codeHash = new Hash(codeHash);
this.codeHash = createType('Hash', codeHash);
}
public deployContract (endowment: number | BN, maxGas: number | BN, ...params: any[]): BlueprintCreate {
+2 -1
View File
@@ -3,6 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { ISubmittableResult, SubmittableResult } from '@polkadot/api/SubmittableExtrinsic';
import { Hash } from '@polkadot/types/srml/types';
import { IKeyringPair } from '@polkadot/types/types';
import { ContractABI } from './types';
@@ -10,7 +11,7 @@ import BN from 'bn.js';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { ApiRx } from '@polkadot/api';
import { AccountId, Address, Hash } from '@polkadot/types';
import { AccountId, Address } from '@polkadot/types';
import { compactAddLength, u8aToU8a } from '@polkadot/util';
import Abi from './Abi';
+3 -2
View File
@@ -3,12 +3,13 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { BalanceLock, VestingSchedule } from '@polkadot/types/srml/balances/types';
import { Balance, BlockNumber, Index } from '@polkadot/types/srml/runtime/types';
import BN from 'bn.js';
import { combineLatest, of, Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { AccountId, AccountIndex, Address, Balance, BlockNumber, ClassOf, Index, Option, createType } from '@polkadot/types';
import { AccountId, AccountIndex, Address, ClassOf, Option, createType } from '@polkadot/types';
import { bnMax } from '@polkadot/util';
import { idAndIndex } from '../accounts/idAndIndex';
@@ -19,7 +20,7 @@ import { drr } from '../util/drr';
type Result = [AccountId | undefined, BlockNumber | undefined, [Balance?, Balance?, BalanceLock[]?, Option<VestingSchedule>?, Index?]];
const EMPTY_ACCOUNT = new AccountId();
const ZERO = new Balance(0);
const ZERO = createType<Balance>('Balance', 0);
function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalance = ZERO, reservedBalance = ZERO, locks = [], vesting = new Option<VestingSchedule>(ClassOf<VestingSchedule>('VestingSchedule'), null), accountNonce = ZERO]]: Result): DerivedBalances {
let lockedBalance = ZERO;
+3 -1
View File
@@ -2,10 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { BlockNumber } from '@polkadot/types/srml/types';
import { Observable } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { BlockNumber, Header } from '@polkadot/types';
import { Header } from '@polkadot/types';
import { drr } from '../util/drr';
@@ -2,10 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { BlockNumber } from '@polkadot/types/srml/types';
import { Observable } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { BlockNumber, Header } from '@polkadot/types';
import { Header } from '@polkadot/types';
import { drr } from '../util/drr';
@@ -2,10 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { BlockNumber } from '@polkadot/types/srml/types';
import { Observable, combineLatest } from 'rxjs';
import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { BlockNumber } from '@polkadot/types';
import { createType } from '@polkadot/types';
import { drr } from '../util/drr';
import { bestNumber } from './bestNumber';
@@ -31,7 +33,7 @@ export function bestNumberLag (api: ApiInterfaceRx): () => Observable<BlockNumbe
bestNumberFinalized(api)()
]).pipe(
map(([bestNumber, bestNumberFinalized]): BlockNumber =>
new BlockNumber(bestNumber.sub(bestNumberFinalized))
createType('BlockNumber', bestNumber.sub(bestNumberFinalized))
),
drr()
);
@@ -2,11 +2,13 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Balance } from '@polkadot/types/srml/types';
import BN from 'bn.js';
import { combineLatest, Observable, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { AccountId, Balance, Vector, Vote } from '@polkadot/types';
import { AccountId, Vector, Vote, createType } from '@polkadot/types';
import { DerivedBalances, DerivedReferendumVote } from '../types';
import { drr } from '../util/drr';
@@ -26,7 +28,7 @@ export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | nu
map(([votersFor, votes, balances]): DerivedReferendumVote[] =>
votersFor.map((accountId, index): DerivedReferendumVote => ({
accountId,
balance: balances[index].votingBalance || new Balance(0),
balance: balances[index].votingBalance || createType<Balance>('Balance', 0),
vote: votes[index] || new Vote(0)
} as unknown as DerivedReferendumVote))
),
+2 -1
View File
@@ -3,12 +3,13 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { SetIndex, VoteIndex } from '@polkadot/types/srml/elections/types';
import { BlockNumber } from '@polkadot/types/srml/types';
import BN from 'bn.js';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { AccountId, BlockNumber } from '@polkadot/types';
import { AccountId } from '@polkadot/types';
import { DerivedElectionsInfo } from '../types';
import { drr } from '../util/drr';
+2 -1
View File
@@ -2,13 +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 { BlockNumber } from '@polkadot/types/srml/types';
import { DerivedSessionInfo } from '../types';
import BN from 'bn.js';
import { Observable, combineLatest, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { BlockNumber, Option } from '@polkadot/types';
import { Option } from '@polkadot/types';
import { drr } from '../util/drr';
import { bestNumber } from '../chain';
+9 -10
View File
@@ -2,8 +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 { BlockNumber } from '@polkadot/types/srml/runtime/types';
import { Keys } from '@polkadot/types/srml/session/types';
import { Exposure, RewardDestination, ValidatorPrefs } from '@polkadot/types/srml/staking/types';
import { Exposure, RewardDestination, StakingLedger, UnlockChunk, ValidatorPrefs } from '@polkadot/types/srml/staking/types';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { DerivedStaking, DerivedUnlocking } from '../types';
@@ -11,7 +12,7 @@ import { DerivedStaking, DerivedUnlocking } from '../types';
import BN from 'bn.js';
import { combineLatest, Observable, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { AccountId, BlockNumber, Option, StakingLedger, Tuple, Vector, UnlockChunk } from '@polkadot/types';
import { createType, AccountId, Option, Tuple, Vector } from '@polkadot/types';
import { isUndefined } from '@polkadot/util';
@@ -24,9 +25,9 @@ function groupByEra (list: UnlockChunk[]): Record<string, BN> {
const key = era.toString();
if (!map[key]) {
map[key] = value;
map[key] = value.unwrap();
} else {
map[key] = map[key].add(value);
map[key] = map[key].add(value.unwrap());
}
return map;
@@ -46,7 +47,7 @@ function calculateUnlocking (stakingLedger: StakingLedger | undefined, eraLength
// select the Unlockchunks that can't be redeemed yet.
const unlockingChunks = stakingLedger.unlocking.filter((chunk): boolean =>
remainingBlocks(chunk.era, eraLength, bestNumber).gtn(0)
remainingBlocks(chunk.era.unwrap(), eraLength, bestNumber).gtn(0)
);
if (!unlockingChunks.length) {
@@ -57,7 +58,7 @@ function calculateUnlocking (stakingLedger: StakingLedger | undefined, eraLength
const groupedResult = groupByEra(unlockingChunks);
const results = Object.entries(groupedResult).map(([eraString, value]): { value: BN; remainingBlocks: BN } => ({
value,
remainingBlocks: remainingBlocks(new BlockNumber(eraString), eraLength, bestNumber)
remainingBlocks: remainingBlocks(createType<BlockNumber>('BlockNumber', eraString), eraLength, bestNumber)
}));
return results.length ? results : undefined;
@@ -69,10 +70,8 @@ function redeemableSum (stakingLedger: StakingLedger | undefined, eraLength: BN,
}
return stakingLedger.unlocking
.filter((chunk): boolean => remainingBlocks(chunk.era, eraLength, bestNumber).eqn(0))
.reduce((curr, prev): BN => {
return curr.add(prev.value);
}, new BN(0));
.filter((chunk): boolean => remainingBlocks(chunk.era.unwrap(), eraLength, bestNumber).eqn(0))
.reduce((curr, prev): BN => curr.add(prev.value.unwrap()), new BN(0));
}
function unwrapSessionIds (stashId: AccountId, validatorIds: AccountId[], auraIds: AccountId[], nextKeys: Option<AccountId> | Vector<Tuple>): { nextSessionId?: AccountId; sessionId?: AccountId } {
+3 -2
View File
@@ -3,10 +3,11 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { SetIndex, VoteIndex } from '@polkadot/types/srml/elections/types';
import { Exposure, RewardDestination, ValidatorPrefs } from '@polkadot/types/srml/staking/types';
import { Balance, BlockNumber, Index } from '@polkadot/types/srml/runtime/types';
import { Exposure, RewardDestination, StakingLedger, ValidatorPrefs } from '@polkadot/types/srml/staking/types';
import BN from 'bn.js';
import { AccountId, Balance, BlockNumber, Index, StakingLedger, Vote } from '@polkadot/types';
import { AccountId, Vote } from '@polkadot/types';
export interface DerivedBalances {
accountId: AccountId;
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Metadata, BlockNumber } from '@polkadot/types';
import { ClassOf, Metadata } from '@polkadot/types';
import json from '@polkadot/types/Metadata/v6/static';
import { injectDefinitions } from '@polkadot/types/srml';
@@ -16,7 +16,7 @@ const consts = fromMetadata(metadata);
describe('fromMetadata', (): void => {
it('should return constants with the correct type and value', (): void => {
expect(consts.democracy.cooloffPeriod).toBeInstanceOf(BlockNumber);
expect(consts.democracy.cooloffPeriod).toBeInstanceOf(ClassOf('BlockNumber'));
expect(consts.democracy.cooloffPeriod.eq(432000)).toBeTruthy();
});
});
@@ -3,6 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import testingPairs from '@polkadot/keyring/testingPairs';
import { injectDefinitions } from '@polkadot/types/srml';
import { Extrinsic } from '@polkadot/types';
import extrinsics from './static';
@@ -10,6 +11,10 @@ import extrinsics from './static';
const keyring = testingPairs({ type: 'ed25519' }, false);
describe('extrinsics', (): void => {
beforeEach((): void => {
injectDefinitions();
});
it('encodes an actual transfer (actual data)', (): void => {
expect(
new Extrinsic(
+2 -1
View File
@@ -3,6 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { ProviderInterface } from '@polkadot/rpc-provider/types';
import { Hash } from '@polkadot/types/srml/types';
import { AnyFunction, Codec, CodecArg, RegistryTypes } from '@polkadot/types/types';
import {
ApiInterfaceRx, ApiInterfaceEvents, ApiOptions, ApiTypes, DecorateMethodOptions,
@@ -22,7 +23,7 @@ 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 { Event, getTypeRegistry, Hash, Metadata, Method, RuntimeVersion, SignedBlock, Null, U64 } from '@polkadot/types';
import { Event, getTypeRegistry, Metadata, Method, RuntimeVersion, SignedBlock, 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';
+8 -7
View File
@@ -2,9 +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 { Balance, BlockNumber, Hash, Index } from '@polkadot/types/srml/types';
import { SignerPayload as ISignerPayload } from './types';
import { Address, Balance, BlockNumber, Compact, ExtrinsicEra, Hash, Nonce, Struct, U8, Method } from '@polkadot/types';
import { Address, ClassOf, Compact, ExtrinsicEra, Struct, U8, Method } from '@polkadot/types';
export interface SignerPayloadType {
address: Address;
@@ -13,20 +14,20 @@ export interface SignerPayloadType {
era: ExtrinsicEra;
genesisHash: Hash;
method: Method;
nonce: Compact<Nonce>;
nonce: Compact<Index>;
tip: Compact<Balance>;
version: U8;
}
export default class SignerPayload extends Struct.with({
address: Address,
blockHash: Hash,
blockNumber: BlockNumber,
blockHash: ClassOf('Hash'),
blockNumber: ClassOf('BlockNumber'),
era: ExtrinsicEra,
genesisHash: Hash,
genesisHash: ClassOf('Hash'),
method: Method,
nonce: Compact.with(Nonce),
tip: Compact.with(Balance),
nonce: ClassOf('Compact<Index>'),
tip: ClassOf('Compact<Balance>'),
version: U8
}) {
/**
+3 -2
View File
@@ -2,13 +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 { Hash, Index } from '@polkadot/types/srml/types';
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 { AccountId, Address, ExtrinsicStatus, EventRecord, getTypeRegistry, Hash, Header, Index, Method, SignedBlock, Vector, ExtrinsicEra } from '@polkadot/types';
import { createType, AccountId, Address, ExtrinsicStatus, EventRecord, getTypeRegistry, Header, Method, SignedBlock, Vector, ExtrinsicEra } from '@polkadot/types';
import { isBn, isFunction, isNumber, isUndefined } from '@polkadot/util';
import filterEvents from './util/filterEvents';
@@ -250,7 +251,7 @@ export default function createSubmittableExtrinsic<ApiType> (
// if we have a nonce already, don't retrieve the latest, use what is there
isUndefined(options.nonce)
? api.query.system.accountNonce<Index>(address)
: of(new Index(options.nonce)),
: of(createType<Index>('Index', options.nonce)),
// if we have an era provided already or eraLength is <= 0 (immortal)
// don't get the latest block, just pass null, handle in mergeMap
(isUndefined(options.era) || (isNumber(options.era) && options.era > 0))
+5 -3
View File
@@ -4,12 +4,14 @@
// Simple non-runnable checks to test type definitions in the editor itself
import { Index } from '@polkadot/types/srml/types';
import { ApiPromise } from '@polkadot/api';
import { HeaderExtended } from '@polkadot/api-derive';
import { ConstantCodec } from '@polkadot/api-metadata/consts/types';
import testKeyring from '@polkadot/keyring/testingPairs';
import { IExtrinsic, IMethod } from '@polkadot/types/types';
import { Header, Nonce } from '@polkadot/types';
import { Header } from '@polkadot/types';
import { SubmittableResult } from './';
@@ -65,7 +67,7 @@ export default async function test (): Promise<void> {
console.log('hash:', (await transfer.signAndSend(keyring.alice)).toHex());
// passing options, but waiting for hash
const nonce = await api.query.system.accountNonce<Nonce>(keyring.alice.address);
const nonce = await api.query.system.accountNonce<Index>(keyring.alice.address);
(await api.tx.balances
.transfer(keyring.bob.address, 12345)
@@ -82,7 +84,7 @@ export default async function test (): Promise<void> {
});
// with options and the callback
const nonce2 = await api.query.system.accountNonce<Nonce>(keyring.alice.address);
const nonce2 = await api.query.system.accountNonce<Index>(keyring.alice.address);
const unsub2 = await api.tx.balances
.transfer(keyring.bob.address, 12345)
.signAndSend(keyring.alice, { nonce: nonce2 }, ({ status }: SubmittableResult): void => {
+2 -2
View File
@@ -2,8 +2,8 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Hash } from '@polkadot/types';
import Mock from '@polkadot/rpc-provider/mock/index';
import { createType } from '@polkadot/types';
import { ApiPromise } from '..';
import { ApiOptions } from '../types';
@@ -18,7 +18,7 @@ describe('Metadata queries', (): void => {
it('Create API instance with metadata map and makes the runtime, rpc, state & extrinsics available', async (): Promise<void> => {
const rpcData = await mock.send('state_getMetadata', []);
const genesisHash = new Hash(await mock.send('chain_getBlockHash', [])).toHex();
const genesisHash = createType('Hash', await mock.send('chain_getBlockHash', [])).toHex();
const specVersion = 0;
const metadata: any = {};
const key = `${genesisHash}-${specVersion}`;
+4 -2
View File
@@ -2,13 +2,15 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Hash } from '@polkadot/types/srml/types';
import { AnyFunction, Callback, Codec, CodecArg, IExtrinsic, RegistryTypes, SignatureOptions } from '@polkadot/types/types';
import BN from 'bn.js';
import { Observable } from 'rxjs';
import { DeriveCustom } from '@polkadot/api-derive';
import { Constants } from '@polkadot/api-metadata/consts/types';
import { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
import { Hash, RuntimeVersion, u64 as U64 } from '@polkadot/types';
import { AnyFunction, Callback, Codec, CodecArg, IExtrinsic, RegistryTypes, SignatureOptions } from '@polkadot/types/types';
import { RuntimeVersion, u64 as U64 } from '@polkadot/types';
import { MethodFunction } from '@polkadot/types/primitive/Method';
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
+7 -5
View File
@@ -2,12 +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 { BlockNumber } from '@polkadot/types/srml/types';
import BN from 'bn.js';
import ApiRx from '@polkadot/api/rx/Api';
import { HeaderExtended } from '@polkadot/api-derive';
import { DerivedBalances, DerivedContractFees, DerivedElectionsInfo, DerivedFees, DerivedSessionInfo } from '@polkadot/api-derive/types';
import { AccountId, AccountIndex, BlockNumber, Index } from '@polkadot/types';
import { AccountId, AccountIndex, ClassOf } from '@polkadot/types';
import { WsProvider } from '@polkadot/rpc-provider';
const WS = 'ws://127.0.0.1:9944/';
@@ -121,7 +123,7 @@ describe.skip('Api-RX derive e2e', (): void => {
api.derive.balances.all(ID).subscribe((balances: DerivedBalances): void => {
expect(balances).toEqual(expect.objectContaining({
accountId: expect.any(AccountId),
accountNonce: expect.any(Index),
accountNonce: expect.any(ClassOf('Index')),
availableBalance: expect.any(BN),
freeBalance: expect.any(BN),
lockedBalance: expect.any(BN),
@@ -154,7 +156,7 @@ describe.skip('Api-RX derive e2e', (): void => {
describe('bestNumber', (): void => {
it('Get the latest block number', async (done): Promise<void> => {
api.derive.chain.bestNumber().subscribe((blockNumber: BlockNumber): void => {
expect(blockNumber instanceof BlockNumber).toBe(true);
expect(blockNumber instanceof ClassOf('BlockNumber')).toBe(true);
expect(blockNumber.gten(0)).toBe(true);
done();
});
@@ -164,7 +166,7 @@ describe.skip('Api-RX derive e2e', (): void => {
describe('bestNumberFinalized', (): void => {
it('Get the latest finalised block number', async (done): Promise<void> => {
api.derive.chain.bestNumberFinalized().subscribe((blockNumber: BlockNumber): void => {
expect(blockNumber instanceof BlockNumber).toBe(true);
expect(blockNumber instanceof ClassOf('BlockNumber')).toBe(true);
expect(blockNumber.gten(0)).toBe(true);
done();
});
@@ -174,7 +176,7 @@ describe.skip('Api-RX derive e2e', (): void => {
describe('bestNumberLag', (): void => {
it('lag between finalised head and best head', async (done): Promise<void> => {
api.derive.chain.bestNumberLag().subscribe((numberLag: BlockNumber): void => {
expect(numberLag instanceof BlockNumber).toBe(true);
expect(numberLag instanceof ClassOf('BlockNumber')).toBe(true);
expect(numberLag.gten(0)).toBe(true);
done();
});
@@ -2,9 +2,8 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, EventRecord, Hash, Header, Option, Vector } from '@polkadot/types';
import WsProvider from '@polkadot/rpc-provider/ws';
import { AccountId, ClassOf, EventRecord, Header, Option, Vector } from '@polkadot/types';
import ApiPromise from '../../../src/promise';
import describeE2E from '../../util/describeE2E';
@@ -45,7 +44,7 @@ describeE2E({
it('Gets the hash of the last finalized header', async (done): Promise<() => void> => {
return (
api.rpc.chain.getFinalizedHead((head): void => {
expect(head instanceof Hash).toBe(true);
expect(head instanceof ClassOf('Hash')).toBe(true);
done();
})
);
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import WsProvider from '@polkadot/rpc-provider/ws';
import { BlockNumber } from '@polkadot/types';
import { ClassOf } from '@polkadot/types';
import ApiPromise from '../../../src/promise';
import describeE2E from '../../util/describeE2E';
@@ -25,7 +25,7 @@ describeE2E({
});
it('democracy.cooloffPeriod parameter type', (): void => {
expect(api.consts.democracy.cooloffPeriod).toBeInstanceOf(BlockNumber);
expect(api.consts.democracy.cooloffPeriod).toBeInstanceOf(ClassOf('BlockNumber'));
expect(
api.consts.democracy.cooloffPeriod.eq(432000) || // Substrate
api.consts.democracy.cooloffPeriod.eq(259200) // Polkadot
@@ -2,13 +2,15 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Hash } from '@polkadot/types/srml/types';
import fs from 'fs';
import path from 'path';
import { Abi } from '@polkadot/api-contract';
import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
import { Address, Hash } from '@polkadot/types';
import { Address } from '@polkadot/types';
import { SubmittableResult } from '../../../src';
import ApiPromise from '../../../src/promise';
@@ -2,12 +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 { Balance, Index } from '@polkadot/types/srml/types';
import BN from 'bn.js';
import { DerivedBalances } from '@polkadot/api-derive/types';
import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
import { Balance, Header, Index, Option, U32 } from '@polkadot/types';
import { Header, Option, U32, createType } from '@polkadot/types';
import ApiPromise from '../../../src/promise';
import describeE2E from '../../util/describeE2E';
@@ -157,7 +159,7 @@ describeE2E({
// assume the account Alice is only used in test(the balance of Alice does not change in this test case)
const key = api.query.balances.freeBalance.key(keyring.alice_stash.address);
const balanceData = await api.rpc.state.getStorage(key) as Option<any>;
const balanceRPC = new Balance(balanceData.unwrapOr(undefined));
const balanceRPC = createType<Balance>('Balance', balanceData.unwrapOr(undefined));
const balance = await api.query.balances.freeBalance(keyring.alice_stash.address);
@@ -2,12 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { SessionIndex } from '@polkadot/types/srml/session/types';
import { Hash, SessionIndex } from '@polkadot/types/srml/types';
import { HeaderExtended } from '@polkadot/api-derive';
import WsProvider from '@polkadot/rpc-provider/ws';
import { LinkageResult } from '@polkadot/types/codec/Linkage';
import { EventRecord, Hash, Header, Option, Vector, createType } from '@polkadot/types';
import { EventRecord, Header, Option, Vector, createType } from '@polkadot/types';
import ApiPromise from '../../../src/promise';
import describeE2E from '../../util/describeE2E';
+3 -1
View File
@@ -2,12 +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 { Hash, Index } from '@polkadot/types/srml/types';
import Keyring from '@polkadot/keyring';
import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
import { u8aToHex } from '@polkadot/util';
import { randomAsHex } from '@polkadot/util-crypto';
import { EventRecord, ExtrinsicEra, Hash, Header, Index, SignedBlock } from '@polkadot/types';
import { EventRecord, ExtrinsicEra, Header, SignedBlock } from '@polkadot/types';
import { SubmittableResult } from '../../../src';
import ApiPromise from '../../../src/promise';
+3 -1
View File
@@ -2,11 +2,13 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Balance } from '@polkadot/types/srml/types';
import BN from 'bn.js';
import { Observable } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { Balance, Header } from '@polkadot/types';
import { Header } from '@polkadot/types';
import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
+2 -1
View File
@@ -2,10 +2,11 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Index } from '@polkadot/types/srml/types';
import { Observable } from 'rxjs';
import { first, switchMap } from 'rxjs/operators';
import { Index } from '@polkadot/types';
import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
@@ -4,7 +4,7 @@
import storage from '@polkadot/api-metadata/storage/static';
import WsProvider from '@polkadot/rpc-provider/ws';
import { BlockNumber, Index, SignedBlock, StorageChangeSet } from '@polkadot/types';
import { ClassOf, SignedBlock, StorageChangeSet } from '@polkadot/types';
import Rpc from '@polkadot/rpc-core';
@@ -28,8 +28,8 @@ describe.skip('e2e Alexander - Polkadot', (): void => {
expect(data).toHaveLength(2);
expect(data).toEqual(
expect.arrayContaining([
expect.any(BlockNumber),
expect.any(Index)
expect.any(ClassOf('BlockNumber')),
expect.any(ClassOf('Index'))
])
);
+3 -1
View File
@@ -2,6 +2,8 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Balance, Hash } from '@polkadot/types/srml/types';
import fs from 'fs';
import path from 'path';
@@ -12,7 +14,7 @@ import { Abi } from '@polkadot/api-contract';
import testingPairs from '@polkadot/keyring/testingPairs';
import { KeyringPair } from '@polkadot/keyring/types';
import WsProvider from '@polkadot/rpc-provider/ws';
import { Balance, Bytes, Hash, Metadata, Moment, StorageData, StorageKey } from '@polkadot/types';
import { Bytes, Metadata, Moment, StorageData, StorageKey } from '@polkadot/types';
import Rpc from '@polkadot/rpc-core';
import flipperAbi from '../../../../api-contract/test/contracts/flipper.json';
+1 -1
View File
@@ -2,11 +2,11 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Balance } from '@polkadot/types/srml/types';
import { Codec } from '@polkadot/types/types';
import fromMetadata from '@polkadot/api-metadata/storage/fromMetadata';
import { Storage } from '@polkadot/api-metadata/storage/types';
import { Balance } from '@polkadot/types';
import Metadata from '@polkadot/types/Metadata';
import { injectDefinitions } from '@polkadot/types/srml';
import rpcMetadataV3 from '@polkadot/types/Metadata/v3/static';
+1
View File
@@ -20,6 +20,7 @@ const submitExtrinsic: RpcMethodOpt = {
params: [
createParam('extrinsic', 'Extrinsic')
],
// @ts-ignore srml types
type: 'Hash'
};
+6
View File
@@ -12,6 +12,7 @@ import createParam from './create/param';
const getHeader: RpcMethodOpt = {
description: 'Retrieves the header for a specific block',
params: [
// @ts-ignore srml types
createParam('hash', 'Hash', { isOptional: true })
],
type: 'Header'
@@ -20,6 +21,7 @@ const getHeader: RpcMethodOpt = {
const getBlock: RpcMethodOpt = {
description: 'Get header and body of a relay chain block',
params: [
// @ts-ignore srml types
createParam('hash', 'Hash', { isOptional: true })
],
type: 'SignedBlock'
@@ -28,20 +30,24 @@ const getBlock: RpcMethodOpt = {
const getBlockHash: RpcMethodOpt = {
description: 'Get the block hash for a specific block',
params: [
// @ts-ignore This whould be fixed if we can get types from srml strings
createParam('blockNumber', 'BlockNumber', { isOptional: true })
],
// @ts-ignore srml types
type: 'Hash'
};
const getFinalizedHead: RpcMethodOpt = {
description: 'Get hash of the last finalized block in the canon chain',
params: [],
// @ts-ignore srml types
type: 'Hash'
};
const getRuntimeVersion: RpcMethodOpt = {
description: 'Get the runtime version (alias of state_getRuntimeVersion)',
params: [
// @ts-ignore srml types
createParam('hash', 'Hash', { isOptional: true })
],
type: 'RuntimeVersion'
+15
View File
@@ -14,6 +14,7 @@ const call: RpcMethodOpt = {
params: [
createParam('method', 'Text'),
createParam('data', 'Bytes'),
// @ts-ignore srml types
createParam('block', 'Hash', { isOptional: true })
],
type: 'Bytes'
@@ -23,6 +24,7 @@ const getKeys: RpcMethodOpt = {
description: 'Retrieves the keys with a certain prefix',
params: [
createParam('prefix', 'StorageKey'),
// @ts-ignore srml types
createParam('block', 'Hash', { isOptional: true })
],
// @ts-ignore The Vec<> wrap is fine
@@ -33,6 +35,7 @@ const getStorage: RpcMethodOpt = {
description: 'Retrieves the storage for a key',
params: [
createParam('key', 'StorageKey'),
// @ts-ignore srml types
createParam('block', 'Hash', { isOptional: true })
],
type: 'StorageData'
@@ -42,8 +45,10 @@ const getStorageHash: RpcMethodOpt = {
description: 'Retrieves the storage hash',
params: [
createParam('key', 'StorageKey'),
// @ts-ignore srml types
createParam('block', 'Hash', { isOptional: true })
],
// @ts-ignore srml types
type: 'Hash'
};
@@ -51,6 +56,7 @@ const getStorageSize: RpcMethodOpt = {
description: 'Retrieves the storage size',
params: [
createParam('key', 'StorageKey'),
// @ts-ignore srml types
createParam('block', 'Hash', { isOptional: true })
],
type: 'u64'
@@ -61,6 +67,7 @@ const getChildKeys: RpcMethodOpt = {
params: [
createParam('childStorageKey', 'StorageKey'),
createParam('prefix', 'StorageKey'),
// @ts-ignore srml types
createParam('block', 'Hash', { isOptional: true })
],
// @ts-ignore The Vec<> wrap is fine
@@ -72,6 +79,7 @@ const getChildStorage: RpcMethodOpt = {
params: [
createParam('childStorageKey', 'StorageKey'),
createParam('key', 'StorageKey'),
// @ts-ignore srml types
createParam('block', 'Hash', { isOptional: true })
],
type: 'StorageData'
@@ -82,8 +90,10 @@ const getChildStorageHash: RpcMethodOpt = {
params: [
createParam('childStorageKey', 'StorageKey'),
createParam('key', 'StorageKey'),
// @ts-ignore srml types
createParam('block', 'Hash', { isOptional: true })
],
// @ts-ignore srml types
type: 'Hash'
};
@@ -92,6 +102,7 @@ const getChildStorageSize: RpcMethodOpt = {
params: [
createParam('childStorageKey', 'StorageKey'),
createParam('key', 'StorageKey'),
// @ts-ignore srml types
createParam('block', 'Hash', { isOptional: true })
],
type: 'u64'
@@ -100,6 +111,7 @@ const getChildStorageSize: RpcMethodOpt = {
const getMetadata: RpcMethodOpt = {
description: 'Returns the runtime metadata',
params: [
// @ts-ignore srml types
createParam('block', 'Hash', { isOptional: true })
],
type: 'Metadata'
@@ -108,6 +120,7 @@ const getMetadata: RpcMethodOpt = {
const getRuntimeVersion: RpcMethodOpt = {
description: 'Get the runtime version',
params: [
// @ts-ignore srml types
createParam('hash', 'Hash', { isOptional: true })
],
type: 'RuntimeVersion'
@@ -118,7 +131,9 @@ const queryStorage: RpcMethodOpt = {
params: [
// @ts-ignore The Vec<> wrap is fine
createParam('keys', 'Vec<StorageKey>'),
// @ts-ignore srml types
createParam('startBlock', 'Hash'),
// @ts-ignore srml types
createParam('block', 'Hash', { isOptional: true })
],
// @ts-ignore The Vec<> wrap is fine
+11 -5
View File
@@ -2,16 +2,22 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Balance, BlockNumber } from '../srml/runtime/types';
import BN from 'bn.js';
import Balance from '../primitive/Balance';
import createType, { ClassOf } from '../codec/createType';
import Moment from '../primitive/Moment';
import U32 from '../primitive/U32';
import BlockNumber from '../type/BlockNumber';
import { injectDefinitions } from '../srml';
import Compact from './Compact';
import UInt from './UInt';
describe('Compact', (): void => {
beforeEach((): void => {
injectDefinitions();
});
describe('encodeU8a', (): void => {
it('encodes short u8', (): void => {
expect(
@@ -63,7 +69,7 @@ describe('Compact', (): void => {
it('encondes a large balance', (): void => {
expect(
Compact.encodeU8a(new Balance('0x5af3107a4000'))
Compact.encodeU8a(createType<Balance>('Balance', '0x5af3107a4000'))
).toEqual(
new Uint8Array([
3 + ((6 - 4) << 2),
@@ -108,13 +114,13 @@ describe('Compact', (): void => {
describe('constructor', (): void => {
it('has the correct bitLength for constructor values (BlockNumber)', (): void => {
expect(
new Compact(BlockNumber, 0xfffffff9).bitLength()
new Compact(ClassOf<BlockNumber>('BlockNumber'), 0xfffffff9).bitLength()
).toEqual(64);
});
it('has the correct encodedLength for constructor values (BlockNumber)', (): void => {
expect(
new Compact(BlockNumber, 0xfffffff9).encodedLength
new Compact(ClassOf<BlockNumber>('BlockNumber'), 0xfffffff9).encodedLength
).toEqual(5);
});
@@ -6,8 +6,13 @@ import Enum from './Enum';
import Null from '../primitive/Null';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import { injectDefinitions } from '../srml';
describe('Enum', (): void => {
beforeEach((): void => {
injectDefinitions();
});
describe('typed enum (previously EnumType)', (): void => {
it('provides a clean toString() (value)', (): void => {
expect(
+14 -12
View File
@@ -2,18 +2,20 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ClassOf } from '../codec/createType';
import AccountId from '../primitive/AccountId';
import Balance from '../primitive/Balance';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import BlockNumber from '../type/BlockNumber';
import { injectDefinitions } from '../srml';
import { CodecTo } from '../types';
import Compact from './Compact';
import Option from './Option';
import Struct from './Struct';
import Vector from './Vector';
describe('Struct', (): void => {
beforeEach((): void => {
injectDefinitions();
});
describe('decoding', (): void => {
const testDecode = (type: string, input: any): void =>
it(`can decode from ${type}`, (): void => {
@@ -182,7 +184,7 @@ describe('Struct', (): void => {
// replicate https://github.com/polkadot-js/api/issues/640
expect(
new Struct({
blockNumber: Option.with(BlockNumber)
blockNumber: ClassOf('Option<BlockNumber>')
}, { blockNumber: '0x1234567890abcdef' }).toString()
).toEqual('{"blockNumber":"0x1234567890abcdef"}');
});
@@ -191,16 +193,16 @@ describe('Struct', (): void => {
expect(
new Struct({
accountId: AccountId,
balance: Balance,
blockNumber: BlockNumber,
compactNumber: Compact.with(BlockNumber),
optionNumber: Option.with(BlockNumber),
balanceCompact: ClassOf('Compact<Balance>'),
blockNumber: ClassOf('BlockNumber'),
compactNumber: ClassOf('Compact<BlockNumber>'),
optionNumber: ClassOf('Option<BlockNumber>'),
counter: U32,
vector: Vector.with(AccountId)
}).toRawType()
).toEqual(JSON.stringify({
accountId: 'AccountId',
balance: 'Balance',
balanceCompact: 'Compact<Balance>', // Override in Uint
blockNumber: 'u64',
compactNumber: 'Compact<u64>',
optionNumber: 'Option<u64>',
@@ -212,14 +214,14 @@ describe('Struct', (): void => {
it('generates sane toRawType (via with)', (): void => {
const Type = Struct.with({
accountId: AccountId,
balance: Balance
balance: ClassOf('Balance')
});
expect(
new Type().toRawType()
).toEqual(JSON.stringify({
accountId: 'AccountId',
balance: 'Balance'
balance: 'Balance' // Override in Uint
}));
});
});
+6 -6
View File
@@ -2,8 +2,8 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Proposal } from '../srml/democracy/types';
import { VoteThreshold } from '../srml/elections/types';
import { BlockNumber } from '../srml/runtime/types';
import { CodecTo } from '../types';
import extrinsics from '@polkadot/api-metadata/extrinsics/static';
@@ -13,7 +13,6 @@ import Method from '../primitive/Method';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import { injectDefinitions } from '../srml';
import BlockNumber from '../type/BlockNumber';
import Tuple from './Tuple';
describe('Tuple', (): void => {
@@ -60,7 +59,7 @@ describe('Tuple', (): void => {
Method.injectMethods(extrinsics);
const test = new (Tuple.with([
BlockNumber, ClassOf<Proposal>('Proposal'), ClassOf<VoteThreshold>('VoteThreshold')
ClassOf('BlockNumber'), ClassOf('Proposal'), ClassOf('VoteThreshold')
]
))('0x62190000000000000003507b0a092230783432223a202230783433220a7d0a01');
@@ -75,7 +74,8 @@ describe('Tuple', (): void => {
it('exposes the Types (object creation)', (): void => {
const test = new Tuple({
BlockNumber, VoteThreshold: ClassOf<VoteThreshold>('VoteThreshold')
BlockNumber: ClassOf('BlockNumber'),
VoteThreshold: ClassOf('VoteThreshold')
}, []);
expect(test.Types).toEqual(['BlockNumber', 'VoteThreshold']);
@@ -102,13 +102,13 @@ describe('Tuple', (): void => {
describe('toRawType', (): void => {
it('generates sane value with array types', (): void => {
expect(
new Tuple([U32, BlockNumber]).toRawType()
new Tuple([U32, ClassOf('BlockNumber')]).toRawType()
).toEqual('(u32,u64)');
});
it('generates sane value with object types', (): void => {
expect(
new Tuple({ number: U32, blockNumber: BlockNumber }).toRawType()
new Tuple({ number: U32, blockNumber: ClassOf('BlockNumber') }).toRawType()
).toEqual('(u32,u64)');
});
});
+7 -1
View File
@@ -6,6 +6,7 @@ import { AnyNumber } from '../types';
import { bnToHex, bnToU8a } from '@polkadot/util';
import { ClassOf } from './createType';
import AbstractInt, { DEFAULT_UINT_BITS, UIntBitLength } from './AbstractInt';
/**
@@ -46,7 +47,12 @@ export default class UInt extends AbstractInt {
* @description Returns the base runtime type name for this instance
*/
public toRawType (): string {
return `u${this._bitLength}`;
// NOTE In the case of balances, which have a special meaning on the UI
// and can be interpreted differently, return a specifc value for it so
// underlying it always matches (no matter which length it actually is)
return this instanceof ClassOf('Balance')
? 'Balance'
: `u${this._bitLength}`;
}
/**
+1 -2
View File
@@ -5,7 +5,6 @@
import { Codec, Constructor } from '../types';
import createType, { TypeDef, TypeDefInfo, createClass, getTypeClass, getTypeDef, typeSplit, ClassOf } from './createType';
import Balance from '../primitive/Balance';
import Text from '../primitive/Text';
import { injectDefinitions } from '../srml';
import CodecSet from './Set';
@@ -308,7 +307,7 @@ describe('createType', (): void => {
it('instanceof should work (primitive type)', (): void => {
const value = createType('Balance', 1234);
expect(value instanceof Balance).toBe(true);
expect(value instanceof ClassOf('Balance')).toBe(true);
});
it('instanceof should work (srml type)', (): void => {
-1
View File
@@ -11,4 +11,3 @@
export { default as Metadata } from './Metadata';
export * from './primitive';
export * from './rpc';
export * from './type';
@@ -68,11 +68,3 @@ export default class AccountId extends U8aFixed {
return 'AccountId';
}
}
/**
* @name AccountIdOf
* @description
* The Substrate AccountIdOf representation as a [[AccountId]].
*/
export class AccountIdOf extends AccountId {
}
@@ -1,35 +0,0 @@
// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import Struct from '../codec/Struct';
import Bytes from './Bytes';
import U64 from './U64';
/**
* @name AccountInfo
* @description
* An Account information structure for contracts
*/
export default class AccountInfo extends Struct {
public constructor (value: any) {
super({
trieId: Bytes,
currentMemStored: U64
}, value);
}
/**
* @description The size of stored value in octet
*/
public get currentMemStored (): U64 {
return this.get('currentMemStored') as U64;
}
/**
* @description Unique ID for the subtree encoded as a byte
*/
public get trieId (): Bytes {
return this.get('trieId') as Bytes;
}
}
-30
View File
@@ -1,30 +0,0 @@
// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import U128 from './U128';
/**
* @name Balance
* @description
* The Substrate Balance representation as a [[U128]].
*/
export default class Balance extends U128 {
/**
* @description Returns the base runtime type name for this instance
*/
public toRawType (): string {
// NOTE Balance we treat as a special case, don't return the base u128 - there
// is typically special processing downstream, i.e. different inputs, it gets
// treated as a primitive in this case
return 'Balance';
}
}
/**
* @name BalanceOf
* @description
* The Substrate BalanceOf representation as a [[Balance]].
*/
export class BalanceOf extends Balance {
}
@@ -1,15 +0,0 @@
// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import Compact from '../codec/Compact';
import Balance from './Balance';
/**
* @name BalanceCompact
* @description
* The Compact<Balance> or number of transactions sent by a specific account. Generally used
* with extrinsics to determine the order of execution.
*/
export default class BalanceCompact extends Compact.with(Balance) {
}
+5 -3
View File
@@ -2,12 +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 { Hash } from '../srml/runtime/types';
import { assert } from '@polkadot/util';
import createType, { ClassOf } from '../codec/createType';
import Enum from '../codec/Enum';
import Struct from '../codec/Struct';
import Vector from '../codec/Vector';
import Hash from './Hash';
import Event from './Event';
import Null from './Null';
import U32 from './U32';
@@ -106,7 +108,7 @@ export class EventRecord0to76 extends Struct {
* @description The [[Hash]] topics for this event (empty, compat)
*/
public get topics (): Vector<Hash> {
return new (Vector.with(Hash))();
return createType('Vec<Hash>', []);
}
}
@@ -121,7 +123,7 @@ export default class EventRecord extends Struct {
super({
phase: Phase,
event: Event,
topics: Vector.with(Hash)
topics: ClassOf('Vec<Hash>')
}, value);
}
@@ -2,19 +2,18 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Balance, Hash, Index } from '../../srml/runtime/types';
import { AnyU8a, ArgsDef, Codec, ExtrinsicPayloadValue, IExtrinsic, IHash, IKeyringPair, SignatureOptions } from '../../types';
import { assert, isHex, isU8a, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
import { blake2AsU8a } from '@polkadot/util-crypto';
import createType from '../../codec/createType';
import Base from '../../codec/Base';
import Compact from '../../codec/Compact';
import { FunctionMetadata } from '../../Metadata/v6/Calls';
import NonceCompact from '../../type/NonceCompact';
import { FunctionMetadata } from '../../Metadata/v7/Calls';
import Address from '../Address';
import BalanceCompact from '../BalanceCompact';
import Method from '../Method';
import Hash from '../Hash';
import ExtrinsicV1, { ExtrinsicValueV1 } from './v1/Extrinsic';
import ExtrinsicV2, { ExtrinsicValueV2 } from './v2/Extrinsic';
import ExtrinsicEra from './ExtrinsicEra';
@@ -143,9 +142,7 @@ export default class Extrinsic extends Base<ExtrinsicV1 | ExtrinsicV2> implement
* @description Convernience function, encodes the extrinsic and returns the actual hash
*/
public get hash (): Hash {
return new Hash(
blake2AsU8a(this.toU8a(), 256)
);
return createType('Hash', blake2AsU8a(this.toU8a(), 256));
}
/**
@@ -186,7 +183,7 @@ export default class Extrinsic extends Base<ExtrinsicV1 | ExtrinsicV2> implement
/**
* @description The nonce for this extrinsic
*/
public get nonce (): NonceCompact {
public get nonce (): Compact<Index> {
return this.raw.signature.nonce;
}
@@ -207,7 +204,7 @@ export default class Extrinsic extends Base<ExtrinsicV1 | ExtrinsicV2> implement
/**
* @description Forwards compat
*/
public get tip (): BalanceCompact {
public get tip (): Compact<Balance> {
return this.raw.signature.tip;
}
@@ -2,9 +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 { injectDefinitions } from '../../srml';
import ExtrinsicEra from './ExtrinsicEra';
describe('ExtrinsicEra', (): void => {
beforeEach((): void => {
injectDefinitions();
});
it('decodes an Extrinsic Era with immortal', (): void => {
const extrinsicEra = new ExtrinsicEra(new Uint8Array([0]));
@@ -2,15 +2,15 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Balance, Hash, Index } from '../../srml/runtime/types';
import { IKeyringPair } from '../../types';
import { u8aToHex } from '@polkadot/util';
import createType from '../../codec/createType';
import Base from '../../codec/Base';
import Compact from '../../codec/Compact';
import U8a from '../../codec/U8a';
import NonceCompact from '../../type/NonceCompact';
import BalanceCompact from '../BalanceCompact';
import Hash from '../Hash';
import SignaturePayloadV1, { SignaturePayloadValueV1 } from './v1/SignaturePayload';
import SignaturePayloadV2, { SignaturePayloadValueV2 } from './v2/SignaturePayload';
import ExtrinsicEra from './ExtrinsicEra';
@@ -67,17 +67,17 @@ export default class SignaturePayload extends Base<SignaturePayloadV1 | Signatur
}
/**
* @description The [[NonceCompact]]
* @description The [[Index]]
*/
public get nonce (): NonceCompact {
public get nonce (): Compact<Index> {
return this.raw.nonce;
}
/**
* @description The [[BalanceCompact]]
* @description The [[Balance]]
*/
public get tip (): BalanceCompact {
return (this.raw as SignaturePayloadV2).tip || new BalanceCompact(0);
public get tip (): Compact<Balance> {
return (this.raw as SignaturePayloadV2).tip || createType('Compact<Balance>', 0);
}
/**
@@ -0,0 +1,7 @@
// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
export { default as Extrinsic } from './Extrinsic';
export { default as ExtrinsicEra, MortalEra, ImmortalEra } from './ExtrinsicEra';
export { default as SignaturePayload } from './SignaturePayload';
@@ -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 { Balance, Index, Signature } from '../../../srml/runtime/types';
import { ExtrinsicPayloadValue, IExtrinsicSignature, IKeyringPair, SignatureOptions } from '../../../types';
import createType, { ClassOf } from '../../../codec/createType';
import Compact from '../../../codec/Compact';
import Struct from '../../../codec/Struct';
import Address from '../../Address';
import BalanceCompact from '../../BalanceCompact';
import Method from '../../Method';
import Signature from '../../Signature';
import NonceCompact from '../../../type/NonceCompact';
import ExtrinsicEra from '../ExtrinsicEra';
import { EMPTY_U8A, IMMORTAL_ERA } from '../constants';
import SignaturePayload from './SignaturePayload';
@@ -32,8 +32,8 @@ export default class ExtrinsicSignatureV1 extends Struct implements IExtrinsicSi
public constructor (value?: ExtrinsicSignatureV1 | Uint8Array, { isSigned }: ExtrinsicSignatureV1Options = {}) {
super({
signer: Address,
signature: Signature,
nonce: NonceCompact,
signature: ClassOf('Signature'),
nonce: ClassOf('Compact<Index>'),
era: ExtrinsicEra
}, ExtrinsicSignatureV1.decodeExtrinsicSignature(value, isSigned));
}
@@ -65,10 +65,10 @@ export default class ExtrinsicSignatureV1 extends Struct implements IExtrinsicSi
}
/**
* @description The [[Nonce]] for the signature
* @description The [[Index]] for the signature
*/
public get nonce (): NonceCompact {
return this.get('nonce') as NonceCompact;
public get nonce (): Compact<Index> {
return this.get('nonce') as Compact<Index>;
}
/**
@@ -88,8 +88,8 @@ export default class ExtrinsicSignatureV1 extends Struct implements IExtrinsicSi
/**
* @description Forwards compat
*/
public get tip (): BalanceCompact {
return new BalanceCompact(0);
public get tip (): Compact<Balance> {
return createType('Compact<Balance>', 0);
}
private injectSignature (signer: Address, signature: Signature, { era, nonce }: SignaturePayload): IExtrinsicSignature {
@@ -107,7 +107,7 @@ export default class ExtrinsicSignatureV1 extends Struct implements IExtrinsicSi
public addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, payload: ExtrinsicPayloadValue | Uint8Array | string): IExtrinsicSignature {
return this.injectSignature(
new Address(signer),
new Signature(signature),
createType('Signature', signature),
new SignaturePayload(payload)
);
}
@@ -123,7 +123,7 @@ export default class ExtrinsicSignatureV1 extends Struct implements IExtrinsicSi
era: era || IMMORTAL_ERA,
blockHash
});
const signature = new Signature(payload.sign(account));
const signature = createType<Signature>('Signature', payload.sign(account));
return this.injectSignature(signer, signature, payload);
}
@@ -2,12 +2,13 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Hash, Index } from '../../../srml/runtime/types';
import { AnyNumber, AnyU8a, ExtrinsicPayloadValue, IExtrinsicEra, IKeyringPair, IMethod } from '../../../types';
import { ClassOf } from '../../../codec/createType';
import Compact from '../../../codec/Compact';
import Struct from '../../../codec/Struct';
import U8a from '../../../codec/U8a';
import Hash from '../../Hash';
import NonceCompact from '../../../type/NonceCompact';
import ExtrinsicEra from '../ExtrinsicEra';
import { sign } from '../util';
@@ -32,10 +33,10 @@ export interface SignaturePayloadValueV1 {
export default class SignaturePayloadV1 extends Struct {
public constructor (value?: ExtrinsicPayloadValue | SignaturePayloadValueV1 | Uint8Array | string) {
super({
nonce: NonceCompact,
nonce: ClassOf('Compact<Index>'),
method: U8a,
era: ExtrinsicEra,
blockHash: Hash
blockHash: ClassOf('Hash')
}, value);
}
@@ -61,10 +62,10 @@ export default class SignaturePayloadV1 extends Struct {
}
/**
* @description The [[NonceCompact]]
* @description The [[Index]]
*/
public get nonce (): NonceCompact {
return this.get('nonce') as NonceCompact;
public get nonce (): Compact<Index> {
return this.get('nonce') as Compact<Index>;
}
/**
@@ -2,9 +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 { injectDefinitions } from '../../../srml';
import ExtrinsicExtra from './ExtrinsicExtra';
describe('ExtrinsicExtraV2', (): void => {
beforeEach((): void => {
injectDefinitions();
});
it('encodes to a sane Uint8Array (default construction)', (): void => {
expect(
new ExtrinsicExtra().toU8a()
@@ -2,13 +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 { Balance, Index } from '../../../srml/runtime/types';
import { AnyNumber } from '../../../types';
import { ClassOf } from '../../../codec/createType';
import Compact from '../../../codec/Compact';
import Struct from '../../../codec/Struct';
import Address from '../../Address';
import BalanceCompact from '../../BalanceCompact';
import ExtrinsicEra from '../ExtrinsicEra';
import NonceCompact from '../../../type/NonceCompact';
interface ExtrinsicExtraValueV2 {
era?: Uint8Array;
@@ -16,12 +17,6 @@ interface ExtrinsicExtraValueV2 {
tip?: AnyNumber;
}
export const extraDefinition = {
era: ExtrinsicEra,
nonce: NonceCompact,
tip: BalanceCompact
};
/**
* @name ExtrinsicExtraV2
* @description
@@ -29,7 +24,11 @@ export const extraDefinition = {
*/
export default class ExtrinsicExtraV2 extends Struct {
public constructor (value?: ExtrinsicExtraValueV2 | Uint8Array) {
super(extraDefinition, value);
super({
era: ExtrinsicEra,
nonce: ClassOf('Compact<Index>'),
tip: ClassOf('Compact<Balance>')
}, value);
}
/**
@@ -40,10 +39,10 @@ export default class ExtrinsicExtraV2 extends Struct {
}
/**
* @description The [[NonceCompact]] for the signature
* @description The [[Index]] for the signature
*/
public get nonce (): NonceCompact {
return this.get('nonce') as NonceCompact;
public get nonce (): Compact<Index> {
return this.get('nonce') as Compact<Index>;
}
/**
@@ -54,9 +53,9 @@ export default class ExtrinsicExtraV2 extends Struct {
}
/**
* @description The [[BalanceCompact]] tip
* @description The [[Balance]] tip
*/
public get tip (): BalanceCompact {
return this.get('tip') as BalanceCompact;
public get tip (): Compact<Balance> {
return this.get('tip') as Compact<Balance>;
}
}
@@ -2,9 +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 { injectDefinitions } from '../../../srml';
import ExtrinsicSignature from './ExtrinsicSignature';
describe('ExtrinsicSignatureV2', (): void => {
beforeEach((): void => {
injectDefinitions();
});
it('encodes to a sane Uint8Array', (): void => {
const u8a = new Uint8Array([
// signer as an AccountIndex
@@ -2,15 +2,15 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Balance, Index, Signature } from '../../../srml/runtime/types';
import { ExtrinsicPayloadValue, IExtrinsicSignature, IKeyringPair, SignatureOptions } from '../../../types';
import createType, { ClassOf } from '../../../codec/createType';
import Compact from '../../../codec/Compact';
import Struct from '../../../codec/Struct';
import Address from '../../Address';
import BalanceCompact from '../../BalanceCompact';
import Method from '../../Method';
import Signature from '../../Signature';
import ExtrinsicEra from '../ExtrinsicEra';
import NonceCompact from '../../../type/NonceCompact';
import SignaturePayload from './SignaturePayload';
import { EMPTY_U8A, IMMORTAL_ERA } from '../constants';
import ExtrinsicExtra from './ExtrinsicExtra';
@@ -28,7 +28,7 @@ export default class ExtrinsicSignatureV2 extends Struct implements IExtrinsicSi
public constructor (value: ExtrinsicSignatureV2 | Uint8Array | undefined, { isSigned }: ExtrinsicSignatureV2Options = {}) {
super({
signer: Address,
signature: Signature,
signature: ClassOf('Signature'),
extra: ExtrinsicExtra
}, ExtrinsicSignatureV2.decodeExtrinsicSignature(value, isSigned));
}
@@ -67,9 +67,9 @@ export default class ExtrinsicSignatureV2 extends Struct implements IExtrinsicSi
}
/**
* @description The [[NonceCompact]] for the signature
* @description The [[Index]] for the signature
*/
public get nonce (): NonceCompact {
public get nonce (): Compact<Index> {
return this.extra.nonce;
}
@@ -90,7 +90,7 @@ export default class ExtrinsicSignatureV2 extends Struct implements IExtrinsicSi
/**
* @description The [[Balance]] tip
*/
public get tip (): BalanceCompact {
public get tip (): Compact<Balance> {
return this.extra.tip;
}
@@ -111,7 +111,7 @@ export default class ExtrinsicSignatureV2 extends Struct implements IExtrinsicSi
public addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, payload: ExtrinsicPayloadValue | Uint8Array | string): IExtrinsicSignature {
return this.injectSignature(
new Address(signer),
new Signature(signature),
createType('Signature', signature),
new SignaturePayload(payload)
);
}
@@ -128,7 +128,7 @@ export default class ExtrinsicSignatureV2 extends Struct implements IExtrinsicSi
nonce,
tip: tip || 0
});
const signature = new Signature(payload.sign(account));
const signature = createType<Signature>('Signature', payload.sign(account));
return this.injectSignature(signer, signature, payload);
}
@@ -2,15 +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 { Balance, Hash, Index } from '../../../srml/runtime/types';
import { AnyNumber, AnyU8a, ExtrinsicPayloadValue, IExtrinsicEra, IKeyringPair, IMethod } from '../../../types';
import { ClassOf } from '../../../codec/createType';
import Compact from '../../../codec/Compact';
import Struct from '../../../codec/Struct';
import U8a from '../../../codec/U8a';
import BalanceCompact from '../../BalanceCompact';
import Hash from '../../Hash';
import NonceCompact from '../../../type/NonceCompact';
import ExtrinsicEra from '../ExtrinsicEra';
import { extraDefinition } from './ExtrinsicExtra';
import { sign } from '../util';
export interface SignaturePayloadValueV2 {
@@ -21,11 +20,6 @@ export interface SignaturePayloadValueV2 {
tip: AnyNumber;
}
const basePayload = {
...extraDefinition,
blockHash: Hash
};
/**
* @name SignaturePayloadV2
* @description
@@ -36,7 +30,10 @@ export default class SignaturePayloadV2 extends Struct {
public constructor (value?: ExtrinsicPayloadValue | SignaturePayloadValueV2 | Uint8Array | string) {
super({
method: U8a,
...basePayload
era: ExtrinsicEra,
nonce: ClassOf('Compact<Index>'),
tip: ClassOf('Compact<Balance>'),
blockHash: ClassOf('Hash')
}, value);
}
@@ -62,17 +59,17 @@ export default class SignaturePayloadV2 extends Struct {
}
/**
* @description The [[NonceCompact]]
* @description The [[Index]]
*/
public get nonce (): NonceCompact {
return this.get('nonce') as NonceCompact;
public get nonce (): Compact<Index> {
return this.get('nonce') as Compact<Index>;
}
/**
* @description The tip [[BalanceCompact]]
* @description The tip [[Balance]]
*/
public get tip (): BalanceCompact {
return this.get('tip') as BalanceCompact;
public get tip (): Compact<Balance> {
return this.get('tip') as Compact<Balance>;
}
/**
+2 -2
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AnyU8a } from '../types';
import { AnyU8a, IHash } from '../types';
import U8aFixed from '../codec/U8aFixed';
@@ -12,7 +12,7 @@ import U8aFixed from '../codec/U8aFixed';
* Hash containing 256 bits (32 bytes), typically used in blocks, extrinsics and
* as a sane default for fixed-length hash representations.
*/
export default class H256 extends U8aFixed {
export default class H256 extends U8aFixed implements IHash {
public constructor (value?: AnyU8a) {
super(value, 256);
}
-16
View File
@@ -1,16 +0,0 @@
// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { IHash } from '../types';
import H256 from './H256';
/**
* @name Hash
* @description
* The default hash that is used accross the system. It is basically just a thin
* wrapper around [[H256]], representing a 32-byte blake2b (Substrate) value
*/
export default class Hash extends H256 implements IHash {
}
@@ -6,8 +6,8 @@ import { AnyU8a } from '../types';
import Option from '../codec/Option';
import Tuple from '../codec/Tuple';
import StorageData from '../primitive/StorageData';
import StorageKey from '../primitive/StorageKey';
import StorageData from './StorageData';
import StorageKey from './StorageKey';
type KeyValueValue = [AnyU8a, AnyU8a];
+3 -5
View File
@@ -2,16 +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 { Hash } from '../srml/runtime/types';
import { AnyU8a, ArgsDef, Codec, IMethod } from '../types';
import { assert, isHex, isObject, isU8a, hexToU8a } from '@polkadot/util';
import { blake2AsU8a } from '@polkadot/util-crypto';
import { getTypeDef, getTypeClass } from '../codec/createType';
import createType, { getTypeDef, getTypeClass } from '../codec/createType';
import Struct from '../codec/Struct';
import U8aFixed from '../codec/U8aFixed';
import { FunctionMetadata as FunctionMetadataV7, FunctionArgumentMetadata } from '../Metadata/v7/Calls';
import Hash from './Hash';
interface DecodeMethodInput {
args: any;
@@ -210,9 +210,7 @@ export default class Method extends Struct implements IMethod {
* @description Convenience function, encodes the Method and returns the actual hash
*/
public get hash (): Hash {
return new Hash(
blake2AsU8a(this.toU8a(), 256)
);
return createType('Hash', blake2AsU8a(this.toU8a(), 256));
}
/**
-30
View File
@@ -1,30 +0,0 @@
// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import H512 from './H512';
/**
* @name Signature
* @description
* The default signature that is used accross the system. It is currectly defined
* as a 512-bit value, represented by a [[H512]].
*/
export default class Signature extends H512 {
}
/**
* @name Ed25519Signature
* @description
* The default Ed25519 that is used accross the system. It is currectly defined
* as a 512-bit value, represented by a [[H512]].
*/
export class Ed25519Signature extends Signature {}
/**
* @name Sr25519Signature
* @description
* The default Sr25519 signature that is used accross the system. It is currectly defined
* as a 512-bit value, represented by a [[H512]].
*/
export class Sr25519Signature extends Signature {}
-2
View File
@@ -54,8 +54,6 @@ export default class Type extends Text {
// alias () -> Null
Type._alias('\\(\\)', 'Null'),
// alias Vec<u8> -> Bytes
Type._alias('Compact<Index>', 'IndexCompact'),
// alias Vec<u8> -> Bytes
Type._alias('Vec<u8>', 'Bytes'),
// alias &[u8] -> Bytes
Type._alias('&\\[u8\\]', 'Bytes'),
-7
View File
@@ -17,11 +17,4 @@ export default class USize extends U32 {
throw new Error('The `usize` type should not be used. Since it is platform-specific, it creates incompatibilities between native (generally u64) and WASM (always u32) code. Use one of the `u32` or `u64` types explicitly.');
}
/**
* @description Returns the base runtime type name for this instance
*/
public toRawType (): string {
return 'usize';
}
}
@@ -23,7 +23,7 @@ export default class Unconstructable extends Null {
public constructor () {
super();
throw new Error(`Unabdle to construct ${JSON.stringify(typeDef)}`);
throw new Error(`Unable to construct ${JSON.stringify(typeDef)}`);
}
};
}
@@ -8,7 +8,7 @@ import { isBoolean, isNumber, isObject, isU8a, isUndefined } from '@polkadot/uti
import createType from '../codec/createType';
import U8a from '../codec/U8a';
import Bool from '../primitive/Bool';
import Bool from './Bool';
/**
* @name Vote
@@ -1,13 +0,0 @@
// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import Fixed64 from '../primitive/I64Fixed';
/**
* @name WeightMultiplier
* @description
* Representation of a weight multiplier. This represents how a fee value can be computed from a weighted transaction, extending [[Fixed64]]
*/
export default class WeightMultiplier extends Fixed64 {
}
+4 -12
View File
@@ -10,25 +10,18 @@
*/
// NOTE We are exporting Bool as bool to match with Rust (however also using Bool internally),
// so with the renamed versions, epose both cases, allowing createType to work
export { default as AccountId, AccountIdOf } from './AccountId';
export { default as AccountId } from './AccountId';
export { default as AccountIndex } from './AccountIndex';
export { default as AccountInfo } from './AccountInfo';
export { default as Address } from './Address';
// Balance is technically not a primitive, however since it is used in a number of interfaces
// and actually is problematic/impossible to be overridden, it is included here as well
export { default as Balance, BalanceOf } from './Balance';
export { default as Event, EventIndex } from './Event';
export { default as EventRecord, EventRecord0to76 } from './EventRecord';
export { default as Bool, default as bool } from './Bool';
export { default as Bytes } from './Bytes';
export { default as Data } from './Data';
export { default as Extrinsic } from './Extrinsic/Extrinsic';
export { default as ExtrinsicEra, MortalEra, ImmortalEra } from './Extrinsic/ExtrinsicEra';
export { default as SignaturePayload } from './Extrinsic/SignaturePayload';
export * from './Extrinsic';
export { default as H160 } from './H160';
export { default as H256 } from './H256';
export { default as H512 } from './H512';
export { default as Hash } from './Hash';
export { default as I8, default as i8 } from './I8';
export { default as I16, default as i16 } from './I16';
export { default as I32, default as i32 } from './I32';
@@ -36,11 +29,11 @@ export { default as I64, default as i64 } from './I64';
export { default as Fixed64 } from './I64Fixed';
export { default as I128, default as i128 } from './I128';
export { default as I256, default as i256 } from './I256';
export { default as KeyValue } from './KeyValue';
export { default as Method } from './Method';
export { default as Moment, MomentOf } from './Moment';
export { default as Null, Phantom } from './Null';
export { default as Origin } from './Origin';
export { default as Signature, Ed25519Signature, Sr25519Signature } from './Signature';
export { default as StorageData } from './StorageData';
export { default as StorageHasher } from './StorageHasher';
export { default as StorageKey } from './StorageKey';
@@ -53,5 +46,4 @@ export { default as U64, default as u64 } from './U64';
export { default as U128, default as u128 } from './U128';
export { default as U256, default as u256 } from './U256';
export { default as USize, default as usize } from './USize';
export { default as Weight } from './Weight';
export { default as WeightMultiplier } from './WeightMultiplier';
export { default as Vote } from './Vote';
+3 -5
View File
@@ -2,15 +2,15 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Hash } from '../srml/runtime/types';
import { AnyU8a } from '../types';
import { blake2AsU8a } from '@polkadot/util-crypto';
import { ClassOf } from '../codec/createType';
import createType, { ClassOf } from '../codec/createType';
import Extrinsic from '../primitive/Extrinsic/Extrinsic';
import Struct from '../codec/Struct';
import Vector from '../codec/Vector';
import Hash from '../primitive/Hash';
import Header, { HeaderValue } from './Header';
export interface BlockValue {
@@ -35,9 +35,7 @@ export default class Block extends Struct {
* @description Encodes a content [[Hash]] for the block
*/
public get contentHash (): Hash {
return new Hash(
blake2AsU8a(this.toU8a(), 256)
);
return createType('Hash', blake2AsU8a(this.toU8a(), 256));
}
/**
+5
View File
@@ -2,11 +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 { injectDefinitions } from '../srml';
import json3 from '../json/Header.003.json';
import block1 from '../json/SignedBlock.003.00.json';
import Digest, { ConsensusEngineId, CID_AURA, CID_BABE, CID_GRPA } from './Digest';
describe('Digest', (): void => {
beforeEach((): void => {
injectDefinitions();
});
it('decodes logs with consensus', (): void => {
const digest = new Digest(json3.result.digest);
+21 -34
View File
@@ -2,6 +2,8 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Hash, Signature } from '../srml/runtime/types';
import BN from 'bn.js';
import { assert, bnToBn } from '@polkadot/util';
@@ -10,13 +12,12 @@ import Struct from '../codec/Struct';
import Tuple from '../codec/Tuple';
import Vector from '../codec/Vector';
import Bytes from '../primitive/Bytes';
import Hash from '../primitive/Hash';
import Signature from '../primitive/Signature';
import U32 from '../primitive/U32';
import U64 from '../primitive/U64';
// Should import AuthorityId (however, move these to generated types)
import AuthorityId from '../primitive/AccountId';
import { ClassOf } from '../codec';
const CID_AURA = 0x61727561; // 'aura'
const CID_BABE = 0x65626162; // 'babe'
@@ -32,14 +33,6 @@ export { CID_AURA, CID_BABE, CID_GRPA };
export class AuthoritiesChange extends Vector.with(AuthorityId) {
}
/**
* @name ChangesTrieRoot
* @description
* Log for changes to the Trie root
*/
export class ChangesTrieRoot extends Hash {
}
/**
* @name ConsensusEngineId
* @description
@@ -145,7 +138,7 @@ export class SealV0 extends Tuple {
public constructor (value: any) {
super({
U64,
Signature
Signature: ClassOf<Signature>('Signature')
}, value);
}
@@ -181,7 +174,7 @@ export class Seal extends Tuple {
* @description The wrapped [[Bytes]]
*/
public get data (): Bytes {
return this[1] as Signature;
return this[1] as Bytes;
}
/**
@@ -235,20 +228,6 @@ export class PreRuntime extends Tuple {
}
}
// Note the ordering, it aligns with numbers to the Rust implementation
// (current and previous versions are included hjere, e.g. SealV0)
const DigestItemEnumMap = {
Other, // 0
AuthoritiesChange, // 1
ChangesTrieRoot, // 2
SealV0, // 3
Consensus, // 4
Seal, // 5
PreRuntime // 6
};
type DigestItemTypes = keyof typeof DigestItemEnumMap;
/**
* @name DigestItem
* @description
@@ -256,7 +235,15 @@ type DigestItemTypes = keyof typeof DigestItemEnumMap;
*/
export class DigestItem extends Enum {
public constructor (value: any) {
super(DigestItemEnumMap, value);
super({
Other, // 0
AuthoritiesChange, // 1
ChangesTrieRoot: ClassOf<Hash>('Hash'), // 2
SealV0, // 3
Consensus, // 4
Seal, // 5
PreRuntime // 6
}, value);
}
/**
@@ -271,10 +258,10 @@ export class DigestItem extends Enum {
/**
* @description Returns the item as a [[ChangesTrieRoot]]
*/
public get asChangesTrieRoot (): ChangesTrieRoot {
public get asChangesTrieRoot (): Hash {
assert(this.isChangesTrieRoot, `Cannot convert '${this.type}' via asChangesTrieRoot`);
return this.value as ChangesTrieRoot;
return this.value as Hash;
}
/**
@@ -379,10 +366,10 @@ export class DigestItem extends Enum {
}
/**
* @description Returns the type of engine, we just override here to get the typings correct
* @description Returns the type of engine
*/
public get type (): DigestItemTypes {
return super.type as DigestItemTypes;
public get type (): string {
return super.type;
}
}
@@ -408,14 +395,14 @@ export default class Digest extends Struct {
/**
* @description The [[DigestItem]] logs, filtered, filter items included. This is useful for derive functionality where only a certain type of log is to be returned.
*/
public logsWith (...include: DigestItemTypes[]): Vector<DigestItem> {
public logsWith (...include: string[]): Vector<DigestItem> {
return this.logs.filter(({ type }): boolean => include.includes(type)) as Vector<DigestItem>;
}
/**
* @description The [[DigestItem]] logs, filtered, filter items exluded. This is useful for stripping headers for eg. WASM runtime execution.
*/
public logsWithout (...exclude: DigestItemTypes[]): Vector<DigestItem> {
public logsWithout (...exclude: string[]): Vector<DigestItem> {
return this.logs.filter(({ type }): boolean => !exclude.includes(type)) as Vector<DigestItem>;
}
}
@@ -2,11 +2,18 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { injectDefinitions } from '../srml';
import rpc from '../json/ExtrinsicStatus.001.json';
import ExtrinsicStatus from './ExtrinsicStatus';
describe('ExtrinsicStatus', (): void => {
const status = new ExtrinsicStatus(rpc.params.result);
let status: ExtrinsicStatus;
beforeEach((): void => {
injectDefinitions();
status = new ExtrinsicStatus(rpc.params.result);
});
it('has the correct type', (): void => {
expect(
+24 -78
View File
@@ -2,70 +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 { Hash } from '../srml/types';
import { assert } from '@polkadot/util';
import { ClassOf } from '../codec/createType';
import Enum from '../codec/Enum';
import Vector from '../codec/Vector';
import Hash from '../primitive/Hash';
import Null from '../primitive/Null';
import Text from '../primitive/Text';
/**
* @name Broadcast
* @description
* An [[ExtrinsicStatus]] indicating that the [[Extrinsic]] has been boradcast to peers
*/
export class Broadcast extends Vector.with(Text) {
}
/**
* @name Dropped
* @description
* An [[ExtrinsicStatus]] indicating that the [[Extrinsic]] has been dropped
*/
export class Dropped extends Null {
}
/**
* @name Finalized
* @description
* An [[ExtrinsicStatus] indicating that the [[Extrinsic]]] has been finalized and included
*/
export class Finalized extends Hash {
}
/**
* @name Future
* @description
* An [[ExtrinsicStatus]] indicating that the [[Extrinsic]] has been added to the future queue
*/
export class Future extends Null {
}
/**
* @name Ready
* @description
* An [[ExtrinsicStatus]] indicating that the [[Extrinsic]] has been added to the ready queue
*/
export class Ready extends Null {
}
/**
* @name Invalid
* @description
* An [[ExtrinsicStatus]] indicating that the [[Extrinsic]] is invalid
*/
export class Invalid extends Null {
}
/**
* @name Usurped
* @description
* An [[ExtrinsicStatus]] indicating that the [[Extrinsic]] has been usurped
*/
export class Usurped extends Hash {
}
/**
* @name ExtrinsicStatus
* @description
@@ -74,77 +20,77 @@ export class Usurped extends Hash {
export default class ExtrinsicStatus extends Enum {
public constructor (value: any, index?: number) {
super({
Future,
Ready,
Finalized,
Usurped,
Broadcast,
Dropped,
Invalid
Future: Null,
Ready: Null,
Finalized: ClassOf('Hash'),
Usurped: ClassOf('Hash'),
Broadcast: Vector.with(Text),
Dropped: Null,
Invalid: Null
}, value, index);
}
/**
* @description Returns the item as a [[Broadcast]]
*/
public get asBroadcast (): Broadcast {
public get asBroadcast (): Vector<Text> {
assert(this.isBroadcast, `Cannot convert '${this.type}' via asBroadcast`);
return this.value as Broadcast;
return this.value as Vector<Text>;
}
/**
* @description Returns the item as a [[Dropped]]
*/
public get asDropped (): Dropped {
public get asDropped (): Null {
assert(this.isDropped, `Cannot convert '${this.type}' via asDropped`);
return this.value as Dropped;
return this.value as Null;
}
/**
* @description Returns the item as a [[Finalized]]
*/
public get asFinalized (): Finalized {
public get asFinalized (): Hash {
assert(this.isFinalized, `Cannot convert '${this.type}' via asFinalized`);
return this.value as Finalized;
return this.value as Hash;
}
/**
* @description Returns the item as a [[Future]]
*/
public get asFuture (): Future {
public get asFuture (): Null {
assert(this.isFuture, `Cannot convert '${this.type}' via asFuture`);
return this.value as Future;
return this.value as Null;
}
/**
* @description Returns the item as a [[Invalid]]
*/
public get asInvalid (): Invalid {
public get asInvalid (): Null {
assert(this.isInvalid, `Cannot convert '${this.type}' via asInvalid`);
return this.value as Invalid;
return this.value as Null;
}
/**
* @description Returns the item as a [[Ready]]
*/
public get asReady (): Ready {
public get asReady (): Null {
assert(this.isReady, `Cannot convert '${this.type}' via asReady`);
return this.value as Ready;
return this.value as Null;
}
/**
* @description Returns the item as a [[Usurped]]
*/
public get asUsurped (): Usurped {
public get asUsurped (): Hash {
assert(this.isUsurped, `Cannot convert '${this.type}' via asUsurped`);
return this.value as Usurped;
return this.value as Hash;
}
/**
+6 -1
View File
@@ -4,14 +4,19 @@
import BN from 'bn.js';
import Header from './Header';
import { injectDefinitions } from '../srml';
import json1 from '../json/Header.001.json';
import json2 from '../json/Header.002.json';
import json3 from '../json/Header.003.json';
import block00300 from '../json/SignedBlock.003.00.json';
import block00301 from '../json/SignedBlock.003.01.json';
import Header from './Header';
describe('Header', (): void => {
beforeEach((): void => {
injectDefinitions();
});
it('decodes an actual JSON response', (): void => {
const header = new Header(json1.result);
+7 -9
View File
@@ -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 { BlockNumber, Hash } from '../srml/runtime/types';
import { AnyNumber, AnyU8a } from '../types';
import { blake2AsU8a } from '@polkadot/util-crypto';
import createType, { ClassOf } from '../codec/createType';
import Compact from '../codec/Compact';
import Struct from '../codec/Struct';
import Hash from '../primitive/Hash';
import BlockNumber from '../type/BlockNumber';
import Digest, { DigestItem } from './Digest';
export interface HeaderValue {
@@ -28,10 +28,10 @@ export interface HeaderValue {
export default class Header extends Struct {
public constructor (value?: HeaderValue | Uint8Array | null) {
super({
parentHash: Hash,
number: Compact.with(BlockNumber),
stateRoot: Hash,
extrinsicsRoot: Hash,
parentHash: ClassOf('Hash'),
number: ClassOf('Compact<BlockNumber>'),
stateRoot: ClassOf('Hash'),
extrinsicsRoot: ClassOf('Hash'),
digest: Digest
}, value || {});
}
@@ -61,9 +61,7 @@ export default class Header extends Struct {
* @description Convenience method, encodes the header and calculates the [[Hash]]
*/
public get hash (): Hash {
return new Hash(
blake2AsU8a(this.toU8a(), 256)
);
return createType('Hash', blake2AsU8a(this.toU8a(), 256));
}
/**
+5 -4
View File
@@ -2,11 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { BlockNumber, Hash } from '../srml/runtime/types';
import { ClassOf } from '../codec/createType';
import Struct from '../codec/Struct';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import Hash from '../primitive/Hash';
import BlockNumber from '../type/BlockNumber';
/**
* @name PeerInfo
@@ -19,8 +20,8 @@ export default class PeerInfo extends Struct {
peerId: Text,
roles: Text,
protocolVersion: U32,
bestHash: Hash,
bestNumber: BlockNumber
bestHash: ClassOf('Hash'),
bestNumber: ClassOf('BlockNumber')
}, value);
}
+2 -3
View File
@@ -2,12 +2,11 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Justification } from '../srml/runtime/types';
import { Hash, Justification } from '../srml/runtime/types';
import { AnyU8a } from '../types';
import { ClassOf } from '../codec/createType';
import Struct from '../codec/Struct';
import Hash from '../primitive/Hash';
import Block, { BlockValue } from './Block';
interface SignedBlockValue {
@@ -24,7 +23,7 @@ export default class SignedBlock extends Struct {
public constructor (value?: SignedBlockValue | Uint8Array) {
super({
block: Block,
justification: ClassOf<Justification>('Justification')
justification: ClassOf('Justification')
}, value);
}
+4 -3
View File
@@ -2,12 +2,13 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Hash } from '../srml/runtime/types';
import { AnyU8a } from '../types';
import { ClassOf } from '../codec/createType';
import Struct from '../codec/Struct';
import Vector from '../codec/Vector';
import Hash from '../primitive/Hash';
import { KeyValueOption, KeyValueOptionValue } from '../type/KeyValue';
import { KeyValueOption, KeyValueOptionValue } from '../primitive/KeyValue';
interface StorageChangeSetValue {
block?: AnyU8a;
@@ -24,7 +25,7 @@ interface StorageChangeSetValue {
export default class StorageChangeSet extends Struct {
public constructor (value?: StorageChangeSetValue | Uint8Array) {
super({
block: Hash,
block: ClassOf('Hash'),
changes: Vector.with(KeyValueOption)
}, value);
}
+2 -11
View File
@@ -8,7 +8,6 @@ import { isString, stringCamelCase, stringUpperFirst } from '@polkadot/util';
import { getTypeDef, TypeDef, TypeDefInfo, TypeDefExtVecFixed } from '../codec/createType';
import * as codecClasses from '../codec';
import * as primitiveClasses from '../primitive';
import * as typeClasses from '../type';
import * as definitions from '../srml/definitions';
// these map all the codec and primitive types for import, see the TypeImports below. If
@@ -24,7 +23,6 @@ interface TypeImports {
localTypes: LocalExist;
ownTypes: string[];
primitiveTypes: TypeExist;
substrateTypes: TypeExist;
}
const HEADER = '/* eslint-disable @typescript-eslint/no-empty-interface */\n// Auto-generated via `yarn build:srmlTs`, do not edit\n\n';
@@ -32,7 +30,7 @@ const FOOTER = '\n';
// Maps the types as found to the source location. This is used to generate the
// imports in the output file, dep-duped and sorted
function setImports ({ codecTypes, localTypes, ownTypes, primitiveTypes, substrateTypes }: TypeImports, types: string[]): void {
function setImports ({ codecTypes, localTypes, ownTypes, primitiveTypes }: TypeImports, types: string[]): void {
types.forEach((type): void => {
if (ownTypes.includes(type)) {
// do nothing
@@ -40,8 +38,6 @@ function setImports ({ codecTypes, localTypes, ownTypes, primitiveTypes, substra
codecTypes[type] = true;
} else if ((primitiveClasses as any)[type]) {
primitiveTypes[type] = true;
} else if ((typeClasses as any)[type]) {
substrateTypes[type] = true;
} else {
// find this module inside the exports from the rest
const [moduleName] = Object.entries(definitions).find(([, { types }]): boolean =>
@@ -262,11 +258,10 @@ function generateTsDef (srmlName: string, { types }: { types: Record<string, any
}, {});
const ownTypes = Object.keys(types);
const primitiveTypes: TypeExist = {};
const substrateTypes: TypeExist = {};
const interfaces = Object.entries(types).map(([name, type]): [string, string] => {
const def = getTypeDef(isString(type) ? type.toString() : JSON.stringify(type), name);
return [name, generators[def.info](def, { codecTypes, localTypes, ownTypes, primitiveTypes, substrateTypes })];
return [name, generators[def.info](def, { codecTypes, localTypes, ownTypes, primitiveTypes })];
});
const sortedDefs = interfaces.sort((a, b): number => a[0].localeCompare(b[0])).map(([, definition]): string => definition).join('\n\n');
@@ -283,10 +278,6 @@ function generateTsDef (srmlName: string, { types }: { types: Record<string, any
file: '../primitive',
types: Object.keys(primitiveTypes)
},
{
file: '../type',
types: Object.keys(substrateTypes)
},
...Object.keys(localTypes).map((moduleName): { file: string; types: string[] } => ({
file: `${moduleName}/types`,
types: Object.keys(localTypes[moduleName])
+2 -2
View File
@@ -3,8 +3,8 @@
import { Codec } from '../../types';
import { Enum, Option } from '../../codec';
import { AccountId, Hash } from '../../primitive';
import { BlockNumber } from '../../type';
import { AccountId } from '../../primitive';
import { BlockNumber, Hash } from '../runtime/types';
export interface InclusionHeight extends BlockNumber {}
+9 -5
View File
@@ -1,11 +1,8 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
// Auto-generated via `yarn build:srmlTs`, do not edit
import { Struct } from '../../codec';
import { Balance } from '../../primitive';
import { BlockNumber } from '../../type';
import { LockIdentifier } from '../runtime/types';
import { WithdrawReasons } from '../staking/types';
import { Set, Struct } from '../../codec';
import { Balance, BlockNumber, LockIdentifier } from '../runtime/types';
export interface BalanceLock extends Struct {
readonly id: LockIdentifier;
@@ -18,3 +15,10 @@ export interface VestingSchedule extends Struct {
readonly offset: Balance;
readonly perBlock: Balance;
}
export interface WithdrawReasons extends Set {
readonly isTransactionPayment: boolean;
readonly isTransfer: boolean;
readonly isReserve: boolean;
readonly isFee: boolean;
}
+2 -2
View File
@@ -2,8 +2,8 @@
// Auto-generated via `yarn build:srmlTs`, do not edit
import { Compact, Enum, Option, Struct, Vector } from '../../codec';
import { Balance, Bool, Bytes, Hash, Null, u32, u64, u8 } from '../../primitive';
import { BlockNumber } from '../../type';
import { Bool, Bytes, Null, u32, u64, u8 } from '../../primitive';
import { Balance, BlockNumber, Hash } from '../runtime/types';
export interface AliveContractInfo extends Struct {
readonly trieId: TrieId;
+3 -4
View File
@@ -6,10 +6,7 @@
// layers can re-use types from higher layers as this is being injected. The
// injection order is critical.
// first do the deprecated types, these should be self-standing
export { default as deprecated } from './deprecated/definitions';
// runtime before balances, session
// runtime before everything else, these are base definitions
export { default as runtime } from './runtime/definitions';
// consensus before grandpa, imOnline
@@ -31,7 +28,9 @@ export { default as balances } from './balances/definitions';
export { default as collective } from './collective/definitions';
export { default as contracts } from './contracts/definitions';
export { default as democracy } from './democracy/definitions';
export { default as deprecated } from './deprecated/definitions';
export { default as imOnline } from './imOnline/definitions';
export { default as parachains } from './parachains/definitions';
export { default as staking } from './staking/definitions';
export { default as system } from './system/definitions';
export { default as treasury } from './treasury/definitions';
+1 -1
View File
@@ -3,7 +3,7 @@
import { Enum, Struct } from '../../codec';
import { Method, u32 } from '../../primitive';
import { BlockNumber } from '../../type';
import { BlockNumber } from '../runtime/types';
import { VoteThreshold } from '../elections/types';
export interface Conviction extends Enum {
@@ -15,6 +15,11 @@ export default {
AssetOf: 'u32',
// Metadata v3
// :: contracts
AccountInfo: {
trieId: 'Bytes',
currentMemStored: 'u64'
},
// :: democracy
LockPeriods: 'i8',
+8 -2
View File
@@ -1,8 +1,14 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
// Auto-generated via `yarn build:srmlTs`, do not edit
import { Enum } from '../../codec';
import { AccountId, Balance, Bytes, Null, i8, u32 } from '../../primitive';
import { Enum, Struct } from '../../codec';
import { AccountId, Bytes, Null, i8, u32, u64 } from '../../primitive';
import { Balance } from '../runtime/types';
export interface AccountInfo extends Struct {
readonly trieId: Bytes;
readonly currentMemStored: u64;
}
export interface Amount extends Balance {}
+2 -1
View File
@@ -2,7 +2,8 @@
// Auto-generated via `yarn build:srmlTs`, do not edit
import { Enum, Struct } from '../../codec';
import { Balance, u32 } from '../../primitive';
import { u32 } from '../../primitive';
import { Balance } from '../runtime/types';
export interface ApprovalFlag extends u32 {}
+1 -1
View File
@@ -4,7 +4,7 @@
import { Codec } from '../../types';
import { Enum, Struct, Vector } from '../../codec';
import { u64 } from '../../primitive';
import { BlockNumber } from '../../type';
import { BlockNumber } from '../runtime/types';
import { AuthorityId } from '../consensus/types';
export interface AuthorityWeight extends u64 {}
+1 -1
View File
@@ -3,7 +3,7 @@
import { Struct, Vector } from '../../codec';
import { Bytes } from '../../primitive';
import { BlockNumber } from '../../type';
import { BlockNumber } from '../runtime/types';
import { AuthorityId } from '../consensus/types';
import { SessionIndex } from '../session/types';
+2 -2
View File
@@ -3,8 +3,8 @@
import { Codec } from '../../types';
import { Enum, Struct, Vector } from '../../codec';
import { AccountId, BalanceOf, Bytes, Hash, Signature, u32, u64 } from '../../primitive';
import { BlockNumber } from '../../type';
import { AccountId, Bytes, u32, u64 } from '../../primitive';
import { BalanceOf, BlockNumber, Hash, Signature } from '../runtime/types';
export interface AttestedCandidate extends Struct {
readonly candidate: CandidateReceipt;
+14 -1
View File
@@ -4,12 +4,25 @@
export default {
types: {
AccountIdOf: 'AccountId',
Balance: 'u128',
BalanceOf: 'Balance',
BlockNumber: 'u64',
Hash: 'H256',
Justification: 'Bytes',
KeyTypeId: 'u32',
LockIdentifier: '[u8; 8]',
Index: 'u64',
Perbill: 'u32',
Permill: 'u32',
SessionKeys: {
ed25519: 'AccountId'
},
ValidatorId: 'AccountId'
Signature: 'H512',
Ed25519Signature: 'Signature',
Sr25519Signature: 'Signature',
ValidatorId: 'AccountId',
Weight: 'u32',
WeightMultiplier: 'Fixed64'
}
};
+27 -1
View File
@@ -2,7 +2,21 @@
// Auto-generated via `yarn build:srmlTs`, do not edit
import { Struct, Vector } from '../../codec';
import { AccountId, Bytes, u32, u8 } from '../../primitive';
import { AccountId, Bytes, Fixed64, H256, H512, u128, u32, u64, u8 } from '../../primitive';
export interface AccountIdOf extends AccountId {}
export interface Balance extends u128 {}
export interface BalanceOf extends Balance {}
export interface BlockNumber extends u64 {}
export interface Ed25519Signature extends Signature {}
export interface Hash extends H256 {}
export interface Index extends u64 {}
export interface Justification extends Bytes {}
@@ -10,8 +24,20 @@ export interface KeyTypeId extends u32 {}
export interface LockIdentifier extends Vector<u8> {}
export interface Perbill extends u32 {}
export interface Permill extends u32 {}
export interface SessionKeys extends Struct {
readonly ed25519: AccountId;
}
export interface Signature extends H512 {}
export interface Sr25519Signature extends Signature {}
export interface ValidatorId extends AccountId {}
export interface Weight extends u32 {}
export interface WeightMultiplier extends Fixed64 {}
@@ -25,6 +25,16 @@ export default {
'Controller'
]
},
UnlockChunk: {
value: 'Compact<Balance>',
era: 'Compact<BlockNumber>'
},
StakingLedger: {
stash: 'AccountId',
total: 'Compact<Balance>',
active: 'Compact<Balance>',
unlocking: 'Vec<UnlockChunk>'
},
ValidatorPrefs: {
unstakeThreshold: 'Compact<u32>',
validatorPayment: 'Compact<Balance>'
+15 -9
View File
@@ -1,8 +1,9 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
// Auto-generated via `yarn build:srmlTs`, do not edit
import { Compact, Enum, Set, Struct, Vector } from '../../codec';
import { AccountId, Balance, u32 } from '../../primitive';
import { Compact, Enum, Struct, Vector } from '../../codec';
import { AccountId, u32 } from '../../primitive';
import { Balance, BlockNumber } from '../runtime/types';
export interface EraIndex extends u32 {}
@@ -37,14 +38,19 @@ export interface RewardDestination extends Enum {
readonly isController: boolean;
}
export interface StakingLedger extends Struct {
readonly stash: AccountId;
readonly total: Compact<Balance>;
readonly active: Compact<Balance>;
readonly unlocking: Vector<UnlockChunk>;
}
export interface UnlockChunk extends Struct {
readonly value: Compact<Balance>;
readonly era: Compact<BlockNumber>;
}
export interface ValidatorPrefs extends Struct {
readonly unstakeThreshold: Compact<u32>;
readonly validatorPayment: Compact<Balance>;
}
export interface WithdrawReasons extends Set {
readonly isTransactionPayment: boolean;
readonly isTransfer: boolean;
readonly isReserve: boolean;
readonly isFee: boolean;
}
@@ -2,12 +2,8 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import U32 from './U32';
/**
* @name Weight
* @description
* Numeric range of a transaction weight.
*/
export default class Weight extends U32 {
}
export default {
types: {
Key: 'Bytes'
}
};
+6
View File
@@ -0,0 +1,6 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
// Auto-generated via `yarn build:srmlTs`, do not edit
import { Bytes } from '../../primitive';
export interface Key extends Bytes {}
+2 -1
View File
@@ -2,7 +2,8 @@
// Auto-generated via `yarn build:srmlTs`, do not edit
import { Struct } from '../../codec';
import { AccountId, Balance } from '../../primitive';
import { AccountId } from '../../primitive';
import { Balance } from '../runtime/types';
export interface TreasuryProposal extends Struct {
readonly proposer: AccountId;
+2 -1
View File
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
// Auto-generated via `yarn build:srmlTs`, do not edit
export * from './deprecated/types';
export * from './runtime/types';
export * from './consensus/types';
export * from './session/types';
@@ -13,7 +12,9 @@ export * from './balances/types';
export * from './collective/types';
export * from './contracts/types';
export * from './democracy/types';
export * from './deprecated/types';
export * from './imOnline/types';
export * from './parachains/types';
export * from './staking/types';
export * from './system/types';
export * from './treasury/types';

Some files were not shown because too many files have changed in this diff Show More