Move Event, Address, AccountId, AccountIndex to generic (#1202)
* Move Event, Address, AccountId, AccountIndex to generic * Move AccountId, AccountIndex, Address & Event to generic * Move Vote
This commit is contained in:
@@ -3,7 +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/interfaces';
|
||||
import { AccountId, Address, Hash } from '@polkadot/types/interfaces';
|
||||
import { IKeyringPair } from '@polkadot/types/types';
|
||||
import { ContractABI } from './types';
|
||||
|
||||
@@ -11,7 +11,7 @@ import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiRx } from '@polkadot/api';
|
||||
import { createType, AccountId, Address } from '@polkadot/types';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
import Abi from './Abi';
|
||||
import RxBase from './RxBase';
|
||||
|
||||
@@ -3,7 +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/interfaces';
|
||||
import { AccountId, Address, Hash } from '@polkadot/types/interfaces';
|
||||
import { IKeyringPair } from '@polkadot/types/types';
|
||||
import { ContractABI } from './types';
|
||||
|
||||
@@ -11,7 +11,6 @@ import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiRx } from '@polkadot/api';
|
||||
import { AccountId, Address } from '@polkadot/types';
|
||||
import { compactAddLength, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import Abi from './Abi';
|
||||
|
||||
@@ -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 { ContractABI, ContractABIFn, InterfaceContract, InterfaceContractCalls } from './types';
|
||||
import { AccountId, Address } from '@polkadot/types/interfaces';
|
||||
import { IKeyringPair } from '@polkadot/types/types';
|
||||
import { ContractABI, ContractABIFn, InterfaceContract, InterfaceContractCalls } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ApiRx } from '@polkadot/api';
|
||||
import { SubmittableResult } from '@polkadot/api/SubmittableExtrinsic';
|
||||
import { AccountId, Address } from '@polkadot/types';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
import Abi from './Abi';
|
||||
import RxBase from './RxBase';
|
||||
|
||||
@@ -31,7 +31,7 @@ export default class RxContract extends RxBase implements InterfaceContract {
|
||||
public constructor (api: ApiRx, abi: ContractABI | Abi, address: string | AccountId | Address) {
|
||||
super(api, abi);
|
||||
|
||||
this.address = new Address(address);
|
||||
this.address = createType('Address', address);
|
||||
|
||||
Object.entries(abi.messages).forEach(([name]): void => {
|
||||
this.calls[name] = (fn: ContractABIFn): CallResult =>
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { SubmittableModuleExtrinsics } from '@polkadot/api/types';
|
||||
import { Address } from '@polkadot/types/interfaces';
|
||||
import { CodecArg } from '@polkadot/types/types';
|
||||
|
||||
import { ApiPromise, ApiRx } from '@polkadot/api';
|
||||
import { Address } from '@polkadot/types';
|
||||
|
||||
export type ApiObject<ApiType> = ApiType extends 'rxjs'
|
||||
? ApiRx
|
||||
|
||||
@@ -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 { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, startWith } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, AccountIndex, Address } from '@polkadot/types';
|
||||
import { isU8a } from '@polkadot/util';
|
||||
import { decodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
import { idToIndex } from './idToIndex';
|
||||
import { indexToId } from './indexToId';
|
||||
import { drr } from '../util/drr';
|
||||
@@ -37,7 +38,7 @@ export function idAndIndex (api: ApiInterfaceRx): (address?: Address | AccountId
|
||||
: decodeAddress((address || '').toString());
|
||||
|
||||
if (decoded.length === 32) {
|
||||
const accountId = new AccountId(decoded);
|
||||
const accountId = createType('AccountId', decoded);
|
||||
|
||||
return idToIndex(api)(accountId).pipe(
|
||||
startWith(undefined),
|
||||
@@ -46,7 +47,7 @@ export function idAndIndex (api: ApiInterfaceRx): (address?: Address | AccountId
|
||||
);
|
||||
}
|
||||
|
||||
const accountIndex = new AccountIndex(decoded);
|
||||
const accountIndex = createType('AccountIndex', decoded);
|
||||
|
||||
return indexToId(api)(accountIndex).pipe(
|
||||
startWith(undefined),
|
||||
|
||||
@@ -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 { AccountId, AccountIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, startWith } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, AccountIndex } from '@polkadot/types';
|
||||
|
||||
import { indexes, AccountIndexes } from './indexes';
|
||||
import { drr } from '../util/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 { AccountId, AccountIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, startWith } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/primitive/AccountIndex';
|
||||
import { AccountId, AccountIndex, Vec } from '@polkadot/types';
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/primitive/Generic/AccountIndex';
|
||||
import { createType, ClassOf, Vec } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
@@ -26,9 +28,9 @@ import { drr } from '../util/drr';
|
||||
export function indexToId (api: ApiInterfaceRx): (accountIndex: AccountIndex | string) => Observable<AccountId | undefined> {
|
||||
return (_accountIndex: AccountIndex | string): Observable<AccountId | undefined> => {
|
||||
const querySection = api.query.indices || api.query.balances;
|
||||
const accountIndex = _accountIndex instanceof AccountIndex
|
||||
const accountIndex = _accountIndex instanceof ClassOf('AccountIndex')
|
||||
? _accountIndex
|
||||
: new AccountIndex(_accountIndex);
|
||||
: createType('AccountIndex', _accountIndex);
|
||||
|
||||
return (querySection.enumSet<Vec<AccountId>>(accountIndex.div(ENUMSET_SIZE)))
|
||||
.pipe(
|
||||
|
||||
@@ -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 { AccountId, AccountIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/primitive/AccountIndex';
|
||||
import { AccountId, AccountIndex } from '@polkadot/types';
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/primitive/Generic/AccountIndex';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
@@ -47,7 +49,7 @@ export function indexes (api: ApiInterfaceRx): () => Observable<AccountIndexes>
|
||||
// 64 (0..63 in first) is [1][0] (the first index value in set 2)
|
||||
const index = (outerIndex * enumsetSize) + innerIndex;
|
||||
|
||||
result[accountId.toString()] = new AccountIndex(index);
|
||||
result[accountId.toString()] = createType('AccountIndex', index);
|
||||
});
|
||||
|
||||
return result;
|
||||
|
||||
@@ -2,14 +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 { BalanceLock, VestingSchedule } from '@polkadot/types/interfaces/balances';
|
||||
import { Balance, BlockNumber, Index } from '@polkadot/types/interfaces/runtime';
|
||||
import { AccountId, AccountIndex, Address, Balance, BalanceLock, BlockNumber, Index, VestingSchedule } from '@polkadot/types/interfaces';
|
||||
|
||||
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, ClassOf, Option, createType } from '@polkadot/types';
|
||||
import { ClassOf, Option, createType } from '@polkadot/types';
|
||||
import { bnMax } from '@polkadot/util';
|
||||
|
||||
import { idAndIndex } from '../accounts/idAndIndex';
|
||||
@@ -19,7 +18,7 @@ import { drr } from '../util/drr';
|
||||
|
||||
type Result = [AccountId | undefined, BlockNumber | undefined, [Balance?, Balance?, BalanceLock[]?, Option<VestingSchedule>?, Index?]];
|
||||
|
||||
const EMPTY_ACCOUNT = new AccountId();
|
||||
const EMPTY_ACCOUNT = createType('AccountId');
|
||||
const ZERO = createType('Balance', 0);
|
||||
|
||||
function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalance = ZERO, reservedBalance = ZERO, locks = [], vesting = new Option<VestingSchedule>(ClassOf('VestingSchedule'), null), accountNonce = ZERO]]: Result): DerivedBalances {
|
||||
|
||||
@@ -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 { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
||||
|
||||
import { combineLatest, Observable, of } from 'rxjs';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, AccountIndex, Address } from '@polkadot/types';
|
||||
|
||||
import { DerivedBalances } from '../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 { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, AccountIndex, Address, Vec } from '@polkadot/types';
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
import { idAndIndex } from '../accounts/idAndIndex';
|
||||
import { DerivedBalances } from '../types';
|
||||
|
||||
@@ -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 { Header } from '@polkadot/types/interfaces';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Header } from '@polkadot/types/interfaces';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { filter, map, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId } from '@polkadot/types';
|
||||
|
||||
import { HeaderExtended } from '../type';
|
||||
import { drr } from '../util/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 { AccountId, Vote } from '@polkadot/types/interfaces';
|
||||
|
||||
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, Vec, Vote, createType } from '@polkadot/types';
|
||||
import { Vec, createType } from '@polkadot/types';
|
||||
|
||||
import { DerivedBalances, DerivedReferendumVote } from '../types';
|
||||
import { drr } from '../util/drr';
|
||||
@@ -26,8 +28,8 @@ export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | nu
|
||||
map(([votersFor, votes, balances]): DerivedReferendumVote[] =>
|
||||
votersFor.map((accountId, index): DerivedReferendumVote => ({
|
||||
accountId,
|
||||
balance: balances[index].votingBalance || createType('Balance', 0),
|
||||
vote: votes[index] || new Vote(0)
|
||||
balance: balances[index].votingBalance || createType('Balance'),
|
||||
vote: votes[index] || createType('Vote')
|
||||
} as unknown as DerivedReferendumVote))
|
||||
),
|
||||
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 { AccountId, Vote } from '@polkadot/types/interfaces';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Vec, Vote } from '@polkadot/types';
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
|
||||
@@ -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 { ApprovalFlag, SetIndex } from '@polkadot/types/interfaces/elections';
|
||||
import { AccountId, ApprovalFlag, SetIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AccountId, Vec } from '@polkadot/types';
|
||||
import { Vec } from '@polkadot/types';
|
||||
import { switchMap, map } from 'rxjs/operators';
|
||||
import { approvalFlagsToBools } from '../util/approvalFlagsToBools';
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
@@ -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 { ApprovalFlag, SetIndex } from '@polkadot/types/interfaces/elections';
|
||||
import { AccountId, ApprovalFlag, SetIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AccountId, Vec } from '@polkadot/types';
|
||||
import { Vec } from '@polkadot/types';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { approvalFlagsToBools } from '../util/approvalFlagsToBools';
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
@@ -2,14 +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 { SetIndex, VoteIndex } from '@polkadot/types/interfaces/elections';
|
||||
import { BlockNumber } from '@polkadot/types/interfaces';
|
||||
import { AccountId, BlockNumber, SetIndex, VoteIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId } from '@polkadot/types';
|
||||
|
||||
import { DerivedElectionsInfo } from '../types';
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { SetIndex } from '@polkadot/types/interfaces/elections';
|
||||
import { AccountId, SetIndex } from '@polkadot/types/interfaces';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Vec, Option, createType } from '@polkadot/types';
|
||||
import { Vec, Option, createType } from '@polkadot/types';
|
||||
import { DerivedVoterPositions } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Vec } from '@polkadot/types';
|
||||
import { AccountId } from '@polkadot/types/interfaces';
|
||||
import { DerivedVoterPositions } from '../types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { createType, Vec } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
import { voterPositions } from './voterPositions';
|
||||
|
||||
@@ -28,11 +30,11 @@ export function voters (api: ApiInterfaceRx): () => Observable<Vec<AccountId>> {
|
||||
voterPositions(api)().pipe(
|
||||
map(
|
||||
(voterPositions: DerivedVoterPositions): Vec<AccountId> =>
|
||||
new Vec(
|
||||
AccountId,
|
||||
createType(
|
||||
'Vec<AccountId>',
|
||||
Object.entries(voterPositions)
|
||||
.sort((a, b): 0 | 1 | -1 => a[1].globalIndex.cmp(b[1].globalIndex))
|
||||
.map(([accountId]): AccountId => new AccountId(accountId))
|
||||
.map(([accountId]): AccountId => createType('AccountId', accountId))
|
||||
)
|
||||
),
|
||||
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 { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Option } from '@polkadot/types';
|
||||
import { Option } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
|
||||
@@ -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 { BlockNumber } from '@polkadot/types/interfaces/runtime';
|
||||
import { AccountId, BlockNumber } from '@polkadot/types/interfaces/runtime';
|
||||
import { Keys } from '@polkadot/types/interfaces/session';
|
||||
import { Exposure, RewardDestination, StakingLedger, UnlockChunk, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
|
||||
|
||||
@@ -12,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 { createType, AccountId, Option, Tuple, Vec } from '@polkadot/types';
|
||||
import { createType, Option, Tuple, Vec } from '@polkadot/types';
|
||||
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
|
||||
@@ -199,7 +199,7 @@ function withControllerLedger (api: ApiInterfaceRx, accountId: AccountId, stakin
|
||||
*/
|
||||
export function info (api: ApiInterfaceRx): (_accountId: Uint8Array | string) => Observable<DerivedStaking> {
|
||||
return (_accountId: Uint8Array | string): Observable<DerivedStaking> => {
|
||||
const accountId = new AccountId(_accountId);
|
||||
const accountId = createType('AccountId', _accountId);
|
||||
|
||||
return (
|
||||
api.queryMulti([
|
||||
|
||||
@@ -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 { Header } from '@polkadot/types/interfaces';
|
||||
import { AccountId, Header } from '@polkadot/types/interfaces';
|
||||
|
||||
import { AnyJsonObject } from '@polkadot/types/types';
|
||||
|
||||
import { AccountId, u64, ClassOf } from '@polkadot/types';
|
||||
import { u64, ClassOf } from '@polkadot/types';
|
||||
|
||||
/**
|
||||
* @name HeaderExtended
|
||||
|
||||
@@ -2,12 +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 { SetIndex, VoteIndex } from '@polkadot/types/interfaces/elections';
|
||||
import { Balance, BlockNumber, Index } from '@polkadot/types/interfaces/runtime';
|
||||
import { Exposure, RewardDestination, StakingLedger, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
|
||||
import { AccountId, Balance, BlockNumber, Exposure, Index, RewardDestination, SetIndex, StakingLedger, ValidatorPrefs, Vote, VoteIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { AccountId, Vote } from '@polkadot/types';
|
||||
|
||||
export interface DerivedBalances {
|
||||
accountId: AccountId;
|
||||
|
||||
@@ -23,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, Metadata, Method, Null, u64 } from '@polkadot/types';
|
||||
import { getTypeRegistry, GenericEvent, Metadata, Method, 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';
|
||||
@@ -533,7 +533,7 @@ export default abstract class ApiBase<ApiType> {
|
||||
|
||||
// only inject if we are not a clone (global init)
|
||||
if (!this._options.source) {
|
||||
Event.injectMetadata(this.runtimeMetadata);
|
||||
GenericEvent.injectMetadata(this.runtimeMetadata);
|
||||
Method.injectMethods(extrinsics);
|
||||
|
||||
// detect the extrinsic version in-use based on the last block
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Balance, BlockNumber, Hash, Index } from '@polkadot/types/interfaces';
|
||||
import { Address, Balance, BlockNumber, Hash, Index } from '@polkadot/types/interfaces';
|
||||
import { SignerPayload as ISignerPayload } from './types';
|
||||
|
||||
import { Address, ClassOf, Compact, ExtrinsicEra, Struct, u8, Method } from '@polkadot/types';
|
||||
import { ClassOf, Compact, ExtrinsicEra, Struct, u8, Method } from '@polkadot/types';
|
||||
|
||||
export interface SignerPayloadType {
|
||||
address: Address;
|
||||
@@ -20,7 +20,7 @@ export interface SignerPayloadType {
|
||||
}
|
||||
|
||||
export default class SignerPayload extends Struct.with({
|
||||
address: Address,
|
||||
address: ClassOf('Address'),
|
||||
blockHash: ClassOf('Hash'),
|
||||
blockNumber: ClassOf('BlockNumber'),
|
||||
era: ExtrinsicEra,
|
||||
|
||||
@@ -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 { ExtrinsicStatus, EventRecord, Hash, Header, Index, SignedBlock } from '@polkadot/types/interfaces';
|
||||
import { AccountId, Address, ExtrinsicStatus, EventRecord, Hash, Header, Index, SignedBlock } from '@polkadot/types/interfaces';
|
||||
import { AnyNumber, AnyU8a, Callback, Codec, IExtrinsic, IExtrinsicEra, IKeyringPair, SignatureOptions } from '@polkadot/types/types';
|
||||
import { ApiInterfaceRx, ApiTypes } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { first, map, mergeMap, switchMap, tap } from 'rxjs/operators';
|
||||
import { createType, AccountId, Address, getTypeRegistry, Method, Vec, ExtrinsicEra } from '@polkadot/types';
|
||||
import { createType, ClassOf, Method, Vec, ExtrinsicEra } from '@polkadot/types';
|
||||
import { isBn, isFunction, isNumber, isUndefined } from '@polkadot/util';
|
||||
|
||||
import filterEvents from './util/filterEvents';
|
||||
@@ -113,7 +113,7 @@ export default function createSubmittableExtrinsic<ApiType> (
|
||||
extrinsic: Method | Uint8Array | string,
|
||||
trackingCb?: Callback<ISubmittableResult>
|
||||
): SubmittableExtrinsic<ApiType> {
|
||||
const _extrinsic = new (getTypeRegistry().getOrThrow('Extrinsic'))(extrinsic, { version: api.extrinsicType }) as SubmittableExtrinsic<ApiType>;
|
||||
const _extrinsic = new (ClassOf('Extrinsic'))(extrinsic, { version: api.extrinsicType }) as unknown as SubmittableExtrinsic<ApiType>;
|
||||
const _noStatusCb = type === 'rxjs';
|
||||
|
||||
function updateSigner (updateId: number, status: Hash | ISubmittableResult): void {
|
||||
|
||||
@@ -9,7 +9,7 @@ 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, ClassOf } from '@polkadot/types';
|
||||
import { createType, ClassOf } from '@polkadot/types';
|
||||
import { WsProvider } from '@polkadot/rpc-provider';
|
||||
|
||||
const WS = 'ws://127.0.0.1:9944/';
|
||||
@@ -74,7 +74,7 @@ describe.skip('Api-RX derive e2e', (): void => {
|
||||
api.derive.accounts.indexToId(IX).subscribe((accountId): void => {
|
||||
// The first emitted value for accountId is undefined when passing the IX
|
||||
if (accountId) {
|
||||
expect(accountId instanceof AccountId).toBe(true);
|
||||
expect(accountId instanceof ClassOf('AccountId')).toBe(true);
|
||||
expect(accountId.toString()).toEqual(ID);
|
||||
} else {
|
||||
expect(accountId).toEqual(undefined);
|
||||
@@ -90,7 +90,7 @@ describe.skip('Api-RX derive e2e', (): void => {
|
||||
api.derive.accounts.idToIndex(ID).subscribe((accountIndex): void => {
|
||||
// The first emitted value for AccountIndex is undefined when passing the ID
|
||||
if (accountIndex) {
|
||||
expect(accountIndex instanceof AccountIndex).toBe(true);
|
||||
expect(accountIndex instanceof ClassOf('AccountIndex')).toBe(true);
|
||||
expect(accountIndex.toString()).toEqual(IX);
|
||||
} else {
|
||||
expect(accountIndex).toEqual(undefined);
|
||||
@@ -107,7 +107,7 @@ describe.skip('Api-RX derive e2e', (): void => {
|
||||
// A local dev chain should have the AccountIndex of Alice
|
||||
expect(accountIndexes).toHaveProperty(
|
||||
ID,
|
||||
new AccountIndex(IX)
|
||||
createType('AccountIndex', IX)
|
||||
);
|
||||
done();
|
||||
});
|
||||
@@ -122,7 +122,7 @@ describe.skip('Api-RX derive e2e', (): void => {
|
||||
it('It returns an object with all relevant balance information of an account', async (done): Promise<void> => {
|
||||
api.derive.balances.all(ID).subscribe((balances: DerivedBalances): void => {
|
||||
expect(balances).toEqual(expect.objectContaining({
|
||||
accountId: expect.any(AccountId),
|
||||
accountId: expect.any(ClassOf('AccountId')),
|
||||
accountNonce: expect.any(ClassOf('Index')),
|
||||
availableBalance: expect.any(BN),
|
||||
freeBalance: expect.any(BN),
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { EventRecord, Header } from '@polkadot/types/interfaces';
|
||||
import { AccountId, EventRecord, Header } from '@polkadot/types/interfaces';
|
||||
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { AccountId, ClassOf, Option, Vec } from '@polkadot/types';
|
||||
import { ClassOf, Option, Vec } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
|
||||
@@ -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 { Hash } from '@polkadot/types/interfaces';
|
||||
import { Address, Hash } from '@polkadot/types/interfaces';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@@ -10,7 +10,6 @@ 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 } from '@polkadot/types';
|
||||
|
||||
import { SubmittableResult } from '../../../src';
|
||||
import ApiPromise from '../../../src/promise';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import MockProvider from '@polkadot/rpc-provider/mock';
|
||||
import { AccountId } from '@polkadot/types';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
import Rpc from '.';
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('Cached Observables', (): void => {
|
||||
|
||||
it('creates a single observable (multiple calls, different arguments that should be cached together)', (): void => {
|
||||
const observable1 = rpc.chain.subscribeNewHead(keyring.alice.address);
|
||||
const observable2 = rpc.chain.subscribeNewHead(new AccountId(keyring.alice.address));
|
||||
const observable2 = rpc.chain.subscribeNewHead(createType('AccountId', keyring.alice.address));
|
||||
|
||||
expect(observable2).toBe(observable1);
|
||||
});
|
||||
|
||||
@@ -246,7 +246,7 @@ export default class Rpc implements RpcInterface {
|
||||
length: false,
|
||||
// Normalize args so that different args that should be cached
|
||||
// together are cached together.
|
||||
// E.g.: `query.my.method('abc') === query.my.method(new AccountId('abc'));`
|
||||
// E.g.: `query.my.method('abc') === query.my.method(createType('AccountId', 'abc'));`
|
||||
normalizer: JSON.stringify
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import '../injector';
|
||||
|
||||
import { ClassOf } from '../codec/createType';
|
||||
import AccountId from '../primitive/AccountId';
|
||||
import AccountId from '../primitive/Generic/AccountId';
|
||||
import Text from '../primitive/Text';
|
||||
import U32 from '../primitive/U32';
|
||||
import { CodecTo } from '../types';
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Codec, CodecTo } from '../types';
|
||||
|
||||
import extrinsics from '@polkadot/api-metadata/extrinsics/static';
|
||||
|
||||
import AccountId from '../primitive/AccountId';
|
||||
import AccountId from '../primitive/Generic/AccountId';
|
||||
import Method from '../primitive/Method';
|
||||
import Text from '../primitive/Text';
|
||||
import { createTypeUnsafe } from './createType';
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { Compact, Option, Vec } from './codec';
|
||||
import { AccountId, AccountIndex, Address, Bool, Bytes, Data, Event, Extrinsic, ExtrinsicEra, Fixed64, GenericBlock, GenericConsensusEngineId, GenericDigest, GenericDigestItem, H160, H256, H512, I128, I16, I256, I32, I64, I8, ImmortalEra, Method, Moment, MortalEra, Null, Origin, SignaturePayload, StorageHasher, StorageKey, Text, Type, U128, U16, U256, U32, U64, U8, Vote, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from './primitive';
|
||||
import { AccountIdOf, Balance, BalanceOf, Block, BlockNumber, Consensus, ConsensusEngineId, Digest, DigestItem, Ed25519Signature, Hash, Header, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, Perbill, Permill, Phantom, PreRuntime, Seal, SealV0, SessionKeys, Signature, SignedBlock, Sr25519Signature, StorageData, ValidatorId, Weight, WeightMultiplier } from './interfaces/runtime';
|
||||
import { Bytes, Data, Extrinsic, ExtrinsicEra, Fixed64, GenericAccountId, GenericAccountIndex, GenericAddress, GenericBlock, GenericConsensusEngineId, GenericDigest, GenericDigestItem, GenericEvent, GenericVote, H160, H256, H512, I128, I16, I256, I32, I64, I8, ImmortalEra, Method, Moment, MortalEra, Null, Origin, SignaturePayload, StorageHasher, StorageKey, Text, Type, U128, U16, U256, U32, U64, U8, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from './primitive';
|
||||
import { AccountId, AccountIdOf, AccountIndex, Address, Balance, BalanceOf, Block, BlockNumber, Consensus, ConsensusEngineId, Digest, DigestItem, Ed25519Signature, Hash, Header, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, Perbill, Permill, Phantom, PreRuntime, Seal, SealV0, SessionKeys, Signature, SignedBlock, Sr25519Signature, StorageData, ValidatorId, Weight, WeightMultiplier } from './interfaces/runtime';
|
||||
import { AuthorityId } from './interfaces/consensus';
|
||||
import { Keys, SessionIndex } from './interfaces/session';
|
||||
import { AuthorityWeight, NextAuthority, PendingPause, PendingResume, StoredPendingChange, StoredState } from './interfaces/grandpa';
|
||||
import { ApprovalFlag, SetIndex, VoteIndex, VoteThreshold, VoterInfo } from './interfaces/elections';
|
||||
import { ApprovalFlag, SetIndex, Vote, VoteIndex, VoteThreshold, VoterInfo } from './interfaces/elections';
|
||||
import { InclusionHeight, Uncle, UncleEntryItem } from './interfaces/authorship';
|
||||
import { BabeWeight } from './interfaces/babe';
|
||||
import { BalanceLock, VestingSchedule, WithdrawReasons } from './interfaces/balances';
|
||||
@@ -17,27 +17,11 @@ import { AccountInfo, Amount, AssetOf, InherentOfflineReport, LockPeriods, NewAc
|
||||
import { Heartbeat, OpaqueMultiaddr, OpaqueNetworkState, OpaquePeerId } from './interfaces/imOnline';
|
||||
import { AttestedCandidate, AuctionIndex, BalanceUpload, Bidder, CandidateReceipt, CollatorSignature, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParachainDispatchOrigin, SlotRange, SubId, UpwardMessage, ValidatorIndex, ValidityAttestation, ValidityVote, WinningData, WinningDataEntry } from './interfaces/parachains';
|
||||
import { EraIndex, EraRewards, Exposure, IndividualExposure, MomentOf, RewardDestination, StakingLedger, UnlockChunk, ValidatorPrefs } from './interfaces/staking';
|
||||
import { DigestOf, EventId, EventIndex, EventRecord, EventRecord0to76, Key, Phase } from './interfaces/system';
|
||||
import { DigestOf, Event, EventId, EventIndex, EventRecord, EventRecord0to76, Key, Phase } from './interfaces/system';
|
||||
import { TreasuryProposal } from './interfaces/treasury';
|
||||
import { ApiId, ChainProperties, ExtrinsicStatus, Health, KeyValueOption, NetworkState, PeerInfo, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from './interfaces/rpc';
|
||||
|
||||
export interface InterfaceRegistry {
|
||||
AccountId: AccountId;
|
||||
'Option<AccountId>': Option<AccountId>;
|
||||
'Vec<AccountId>': Vec<AccountId>;
|
||||
AccountIndex: AccountIndex;
|
||||
'Compact<AccountIndex>': Compact<AccountIndex>;
|
||||
'Option<AccountIndex>': Option<AccountIndex>;
|
||||
'Vec<AccountIndex>': Vec<AccountIndex>;
|
||||
Address: Address;
|
||||
'Option<Address>': Option<Address>;
|
||||
'Vec<Address>': Vec<Address>;
|
||||
Event: Event;
|
||||
'Option<Event>': Option<Event>;
|
||||
'Vec<Event>': Vec<Event>;
|
||||
Bool: Bool;
|
||||
'Option<Bool>': Option<Bool>;
|
||||
'Vec<Bool>': Vec<Bool>;
|
||||
bool: bool;
|
||||
'Option<bool>': Option<bool>;
|
||||
'Vec<bool>': Vec<bool>;
|
||||
@@ -172,9 +156,6 @@ export interface InterfaceRegistry {
|
||||
'Compact<usize>': Compact<usize>;
|
||||
'Option<usize>': Option<usize>;
|
||||
'Vec<usize>': Vec<usize>;
|
||||
Vote: Vote;
|
||||
'Option<Vote>': Option<Vote>;
|
||||
'Vec<Vote>': Vec<Vote>;
|
||||
Extrinsic: Extrinsic;
|
||||
'Option<Extrinsic>': Option<Extrinsic>;
|
||||
'Vec<Extrinsic>': Vec<Extrinsic>;
|
||||
@@ -190,6 +171,16 @@ export interface InterfaceRegistry {
|
||||
SignaturePayload: SignaturePayload;
|
||||
'Option<SignaturePayload>': Option<SignaturePayload>;
|
||||
'Vec<SignaturePayload>': Vec<SignaturePayload>;
|
||||
GenericAccountId: GenericAccountId;
|
||||
'Option<GenericAccountId>': Option<GenericAccountId>;
|
||||
'Vec<GenericAccountId>': Vec<GenericAccountId>;
|
||||
GenericAccountIndex: GenericAccountIndex;
|
||||
'Compact<GenericAccountIndex>': Compact<GenericAccountIndex>;
|
||||
'Option<GenericAccountIndex>': Option<GenericAccountIndex>;
|
||||
'Vec<GenericAccountIndex>': Vec<GenericAccountIndex>;
|
||||
GenericAddress: GenericAddress;
|
||||
'Option<GenericAddress>': Option<GenericAddress>;
|
||||
'Vec<GenericAddress>': Vec<GenericAddress>;
|
||||
GenericBlock: GenericBlock;
|
||||
'Option<GenericBlock>': Option<GenericBlock>;
|
||||
'Vec<GenericBlock>': Vec<GenericBlock>;
|
||||
@@ -197,15 +188,31 @@ export interface InterfaceRegistry {
|
||||
'Compact<GenericConsensusEngineId>': Compact<GenericConsensusEngineId>;
|
||||
'Option<GenericConsensusEngineId>': Option<GenericConsensusEngineId>;
|
||||
'Vec<GenericConsensusEngineId>': Vec<GenericConsensusEngineId>;
|
||||
GenericEvent: GenericEvent;
|
||||
'Option<GenericEvent>': Option<GenericEvent>;
|
||||
'Vec<GenericEvent>': Vec<GenericEvent>;
|
||||
GenericDigest: GenericDigest;
|
||||
'Option<GenericDigest>': Option<GenericDigest>;
|
||||
'Vec<GenericDigest>': Vec<GenericDigest>;
|
||||
GenericDigestItem: GenericDigestItem;
|
||||
'Option<GenericDigestItem>': Option<GenericDigestItem>;
|
||||
'Vec<GenericDigestItem>': Vec<GenericDigestItem>;
|
||||
GenericVote: GenericVote;
|
||||
'Option<GenericVote>': Option<GenericVote>;
|
||||
'Vec<GenericVote>': Vec<GenericVote>;
|
||||
AccountId: AccountId;
|
||||
'Option<AccountId>': Option<AccountId>;
|
||||
'Vec<AccountId>': Vec<AccountId>;
|
||||
AccountIdOf: AccountIdOf;
|
||||
'Option<AccountIdOf>': Option<AccountIdOf>;
|
||||
'Vec<AccountIdOf>': Vec<AccountIdOf>;
|
||||
AccountIndex: AccountIndex;
|
||||
'Compact<AccountIndex>': Compact<AccountIndex>;
|
||||
'Option<AccountIndex>': Option<AccountIndex>;
|
||||
'Vec<AccountIndex>': Vec<AccountIndex>;
|
||||
Address: Address;
|
||||
'Option<Address>': Option<Address>;
|
||||
'Vec<Address>': Vec<Address>;
|
||||
Balance: Balance;
|
||||
'Compact<Balance>': Compact<Balance>;
|
||||
'Option<Balance>': Option<Balance>;
|
||||
@@ -341,6 +348,9 @@ export interface InterfaceRegistry {
|
||||
'Compact<SetIndex>': Compact<SetIndex>;
|
||||
'Option<SetIndex>': Option<SetIndex>;
|
||||
'Vec<SetIndex>': Vec<SetIndex>;
|
||||
Vote: Vote;
|
||||
'Option<Vote>': Option<Vote>;
|
||||
'Vec<Vote>': Vec<Vote>;
|
||||
VoteIndex: VoteIndex;
|
||||
'Compact<VoteIndex>': Compact<VoteIndex>;
|
||||
'Option<VoteIndex>': Option<VoteIndex>;
|
||||
@@ -596,6 +606,9 @@ export interface InterfaceRegistry {
|
||||
Phase: Phase;
|
||||
'Option<Phase>': Option<Phase>;
|
||||
'Vec<Phase>': Vec<Phase>;
|
||||
Event: Event;
|
||||
'Option<Event>': Option<Event>;
|
||||
'Vec<Event>': Vec<Event>;
|
||||
EventRecord0to76: EventRecord0to76;
|
||||
'Option<EventRecord0to76>': Option<EventRecord0to76>;
|
||||
'Vec<EventRecord0to76>': Vec<EventRecord0to76>;
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
import { Codec } from '../../types';
|
||||
import { Enum, Option } from '../../codec';
|
||||
import { AccountId } from '../../primitive';
|
||||
import { BlockNumber, Hash } from '../runtime';
|
||||
import { AccountId, BlockNumber, Hash } from '../runtime';
|
||||
|
||||
/** BlockNumber */
|
||||
export type InclusionHeight = BlockNumber;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { Struct, Vec } from '../../codec';
|
||||
import { AccountId, u32, u64 } from '../../primitive';
|
||||
import { u32, u64 } from '../../primitive';
|
||||
import { AccountId } from '../runtime';
|
||||
|
||||
/** u64 */
|
||||
export type MemberCount = u64;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { AccountId } from '../../primitive';
|
||||
import { AccountId } from '../runtime';
|
||||
|
||||
/** AccountId */
|
||||
export type AuthorityId = AccountId;
|
||||
|
||||
@@ -45,7 +45,7 @@ export default {
|
||||
maxEventTopics: 'u32',
|
||||
maxStackHeight: 'u32',
|
||||
maxMemoryPages: 'u32',
|
||||
enablePrintln: 'Bool',
|
||||
enablePrintln: 'bool',
|
||||
maxSubjectLen: 'u32'
|
||||
},
|
||||
SeedOf: 'Hash'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { Compact, Enum, Option, Struct, Vec } from '../../codec';
|
||||
import { Bool, Bytes, Null, u32, u64, u8 } from '../../primitive';
|
||||
import { Bytes, Null, bool, u32, u64, u8 } from '../../primitive';
|
||||
import { Balance, BlockNumber, Hash } from '../runtime';
|
||||
|
||||
/** Struct */
|
||||
@@ -86,8 +86,8 @@ export interface Schedule extends Struct {
|
||||
readonly maxStackHeight: u32;
|
||||
/** u32 */
|
||||
readonly maxMemoryPages: u32;
|
||||
/** Bool */
|
||||
readonly enablePrintln: Bool;
|
||||
/** bool */
|
||||
readonly enablePrintln: bool;
|
||||
/** u32 */
|
||||
readonly maxSubjectLen: u32;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { Enum, Struct } from '../../codec';
|
||||
import { AccountId, Bytes, Null, i8, u32, u64 } from '../../primitive';
|
||||
import { Balance } from '../runtime';
|
||||
import { Bytes, Null, i8, u32, u64 } from '../../primitive';
|
||||
import { AccountId, Balance } from '../runtime';
|
||||
|
||||
/** Struct */
|
||||
export interface AccountInfo extends Struct {
|
||||
|
||||
@@ -6,6 +6,7 @@ export default {
|
||||
types: {
|
||||
ApprovalFlag: 'u32',
|
||||
SetIndex: 'u32',
|
||||
Vote: 'GenericVote',
|
||||
VoteIndex: 'u32',
|
||||
VoterInfo: {
|
||||
lastActive: 'VoteIndex',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { Enum, Struct } from '../../codec';
|
||||
import { u32 } from '../../primitive';
|
||||
import { GenericVote, u32 } from '../../primitive';
|
||||
import { Balance } from '../runtime';
|
||||
|
||||
/** u32 */
|
||||
@@ -10,6 +10,9 @@ export type ApprovalFlag = u32;
|
||||
/** u32 */
|
||||
export type SetIndex = u32;
|
||||
|
||||
/** GenericVote */
|
||||
export type Vote = GenericVote;
|
||||
|
||||
/** u32 */
|
||||
export type VoteIndex = u32;
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
import { Codec } from '../../types';
|
||||
import { Enum, Struct, Vec } from '../../codec';
|
||||
import { AccountId, Bytes, u32, u64 } from '../../primitive';
|
||||
import { BalanceOf, BlockNumber, Hash, Signature } from '../runtime';
|
||||
import { Bytes, u32, u64 } from '../../primitive';
|
||||
import { AccountId, BalanceOf, BlockNumber, Hash, Signature } from '../runtime';
|
||||
|
||||
/** Struct */
|
||||
export interface AttestedCandidate extends Struct {
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
|
||||
export default {
|
||||
types: {
|
||||
AccountId: 'GenericAccountId',
|
||||
AccountIdOf: 'AccountId',
|
||||
AccountIndex: 'GenericAccountIndex',
|
||||
Address: 'GenericAddress',
|
||||
Balance: 'u128',
|
||||
BalanceOf: 'Balance',
|
||||
BlockNumber: 'u64',
|
||||
|
||||
@@ -2,11 +2,20 @@
|
||||
|
||||
import { Codec } from '../../types';
|
||||
import { Compact, Struct, Vec } from '../../codec';
|
||||
import { AccountId, Bytes, Fixed64, GenericBlock, GenericConsensusEngineId, GenericDigest, GenericDigestItem, H256, H512, Null, StorageKey, u128, u32, u64, u8 } from '../../primitive';
|
||||
import { Bytes, Fixed64, GenericAccountId, GenericAccountIndex, GenericAddress, GenericBlock, GenericConsensusEngineId, GenericDigest, GenericDigestItem, H256, H512, Null, StorageKey, u128, u32, u64, u8 } from '../../primitive';
|
||||
|
||||
/** GenericAccountId */
|
||||
export type AccountId = GenericAccountId;
|
||||
|
||||
/** AccountId */
|
||||
export type AccountIdOf = AccountId;
|
||||
|
||||
/** GenericAccountIndex */
|
||||
export type AccountIndex = GenericAccountIndex;
|
||||
|
||||
/** GenericAddress */
|
||||
export type Address = GenericAddress;
|
||||
|
||||
/** u128 */
|
||||
export type Balance = u128;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { Compact, Enum, Struct, Vec } from '../../codec';
|
||||
import { AccountId, Moment, u32 } from '../../primitive';
|
||||
import { Balance, BlockNumber } from '../runtime';
|
||||
import { Moment, u32 } from '../../primitive';
|
||||
import { AccountId, Balance, BlockNumber } from '../runtime';
|
||||
|
||||
/** u32 */
|
||||
export type EraIndex = u32;
|
||||
|
||||
@@ -10,7 +10,7 @@ import createType from '../../codec/createType';
|
||||
import Vec from '../../codec/Vec';
|
||||
import json1 from '../../json/EventRecord.001.json';
|
||||
import json3 from '../../json/EventRecord.003.json';
|
||||
import Event from '../../primitive/Event';
|
||||
import GenericEvent from '../../primitive/Generic/Event';
|
||||
import Metadata from '../../Metadata';
|
||||
import metadataV0 from '../../Metadata/v0/static';
|
||||
import metadata from '../../Metadata/static';
|
||||
@@ -18,7 +18,7 @@ import metadata from '../../Metadata/static';
|
||||
describe('EventRecord', (): void => {
|
||||
describe('EventRecord_0_76', (): void => {
|
||||
beforeEach((): void => {
|
||||
Event.injectMetadata(
|
||||
GenericEvent.injectMetadata(
|
||||
new Metadata(metadataV0)
|
||||
);
|
||||
});
|
||||
@@ -33,7 +33,7 @@ describe('EventRecord', (): void => {
|
||||
|
||||
describe('EventRecord (current)', (): void => {
|
||||
beforeEach((): void => {
|
||||
Event.injectMetadata(
|
||||
GenericEvent.injectMetadata(
|
||||
new Metadata(metadata)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ export default {
|
||||
Finalization: 'Null'
|
||||
}
|
||||
},
|
||||
Event: 'GenericEvent',
|
||||
EventRecord0to76: {
|
||||
phase: 'Phase',
|
||||
event: 'Event'
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { Enum, Struct, Vec } from '../../codec';
|
||||
import { Bytes, Event, u32, u8 } from '../../primitive';
|
||||
import { Bytes, GenericEvent, u32, u8 } from '../../primitive';
|
||||
import { Digest, Hash } from '../runtime';
|
||||
|
||||
/** Digest */
|
||||
export type DigestOf = Digest;
|
||||
|
||||
/** GenericEvent */
|
||||
export type Event = GenericEvent;
|
||||
|
||||
/** Vec<u8> */
|
||||
export type EventId = Vec<u8>;
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { Struct } from '../../codec';
|
||||
import { AccountId } from '../../primitive';
|
||||
import { Balance } from '../runtime';
|
||||
import { AccountId, Balance } from '../runtime';
|
||||
|
||||
/** Struct */
|
||||
export interface TreasuryProposal extends Struct {
|
||||
|
||||
@@ -1,51 +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 { Hash } from '../interfaces/runtime';
|
||||
import { Phase } from '../interfaces/system';
|
||||
|
||||
import { ClassOf } from '../codec/createType';
|
||||
import Struct from '../codec/Struct';
|
||||
import Vec from '../codec/Vec';
|
||||
import Event from './Event';
|
||||
|
||||
/**
|
||||
* @name EventRecord
|
||||
* @description
|
||||
* A record for an [[Event]] (as specified by [[Metadata]]) with the specific [[Phase]] of
|
||||
* application.
|
||||
*/
|
||||
export default class EventRecord extends Struct {
|
||||
public constructor (value: any) {
|
||||
super({
|
||||
phase: ClassOf('Phase'),
|
||||
event: Event,
|
||||
topics: ClassOf('Vec<Hash>')
|
||||
}, value);
|
||||
}
|
||||
|
||||
// TODO We want these injected by createType
|
||||
public static Fallback = ClassOf('EventRecord0to76');
|
||||
|
||||
/**
|
||||
* @description The [[Event]] this record refers to
|
||||
*/
|
||||
public get event (): Event {
|
||||
return this.get('event') as Event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Phase]] where the event was generated
|
||||
*/
|
||||
public get phase (): Phase {
|
||||
return this.get('phase') as Phase;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Hash]] topics for this event
|
||||
*/
|
||||
public get topics (): Vec<Hash> {
|
||||
return this.get('topics') as Vec<Hash>;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import { assert, isHex, isU8a, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/u
|
||||
import Base from '../../codec/Base';
|
||||
import Compact from '../../codec/Compact';
|
||||
import { FunctionMetadata } from '../../Metadata/v7/Calls';
|
||||
import Address from '../Address';
|
||||
import Address from '../Generic/Address';
|
||||
import Method from '../Method';
|
||||
import ExtrinsicV1, { ExtrinsicValueV1 } from './v1/Extrinsic';
|
||||
import ExtrinsicV2, { ExtrinsicValueV2 } from './v2/Extrinsic';
|
||||
|
||||
@@ -8,7 +8,7 @@ import { isU8a } from '@polkadot/util';
|
||||
|
||||
import Struct from '../../../codec/Struct';
|
||||
import Method from '../../Method';
|
||||
import Address from '../../Address';
|
||||
import Address from '../../Generic/Address';
|
||||
import ExtrinsicSignature from './ExtrinsicSignature';
|
||||
|
||||
export interface ExtrinsicValueV1 {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ExtrinsicPayloadValue, IExtrinsicSignature, IKeyringPair, SignatureOpti
|
||||
import createType, { ClassOf } from '../../../codec/createType';
|
||||
import Compact from '../../../codec/Compact';
|
||||
import Struct from '../../../codec/Struct';
|
||||
import Address from '../../Address';
|
||||
import Address from '../../Generic/Address';
|
||||
import Method from '../../Method';
|
||||
import ExtrinsicEra from '../ExtrinsicEra';
|
||||
import { EMPTY_U8A, IMMORTAL_ERA } from '../constants';
|
||||
@@ -106,7 +106,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),
|
||||
createType('Address', signer),
|
||||
createType('Signature', signature),
|
||||
new SignaturePayload(payload)
|
||||
);
|
||||
@@ -116,7 +116,7 @@ export default class ExtrinsicSignatureV1 extends Struct implements IExtrinsicSi
|
||||
* @description Generate a payload and pplies the signature from a keypair
|
||||
*/
|
||||
public sign (method: Method, account: IKeyringPair, { blockHash, era, nonce }: SignatureOptions): IExtrinsicSignature {
|
||||
const signer = new Address(account.publicKey);
|
||||
const signer = createType('Address', account.publicKey);
|
||||
const payload = new SignaturePayload({
|
||||
nonce,
|
||||
method: method.toU8a(),
|
||||
|
||||
@@ -8,7 +8,7 @@ import { isU8a } from '@polkadot/util';
|
||||
|
||||
import Struct from '../../../codec/Struct';
|
||||
import Method from '../../Method';
|
||||
import Address from '../../Address';
|
||||
import Address from '../../Generic/Address';
|
||||
import ExtrinsicSignature from './ExtrinsicSignature';
|
||||
|
||||
const TRANSACTION_VERSION = 2;
|
||||
|
||||
@@ -8,7 +8,7 @@ import { AnyNumber } from '../../../types';
|
||||
import { ClassOf } from '../../../codec/createType';
|
||||
import Compact from '../../../codec/Compact';
|
||||
import Struct from '../../../codec/Struct';
|
||||
import Address from '../../Address';
|
||||
import Address from '../../Generic/Address';
|
||||
import ExtrinsicEra from '../ExtrinsicEra';
|
||||
|
||||
interface ExtrinsicExtraValueV2 {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ExtrinsicPayloadValue, IExtrinsicSignature, IKeyringPair, SignatureOpti
|
||||
import createType, { ClassOf } from '../../../codec/createType';
|
||||
import Compact from '../../../codec/Compact';
|
||||
import Struct from '../../../codec/Struct';
|
||||
import Address from '../../Address';
|
||||
import Address from '../../Generic/Address';
|
||||
import Method from '../../Method';
|
||||
import ExtrinsicEra from '../ExtrinsicEra';
|
||||
import SignaturePayload from './SignaturePayload';
|
||||
@@ -110,7 +110,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),
|
||||
createType('Address', signer),
|
||||
createType('Signature', signature),
|
||||
new SignaturePayload(payload)
|
||||
);
|
||||
@@ -120,7 +120,7 @@ export default class ExtrinsicSignatureV2 extends Struct implements IExtrinsicSi
|
||||
* @description Generate a payload and pplies the signature from a keypair
|
||||
*/
|
||||
public sign (method: Method, account: IKeyringPair, { blockHash, era, nonce, tip }: SignatureOptions): IExtrinsicSignature {
|
||||
const signer = new Address(account.publicKey);
|
||||
const signer = createType('Address', account.publicKey);
|
||||
const payload = new SignaturePayload({
|
||||
blockHash,
|
||||
era: era || IMMORTAL_ERA,
|
||||
|
||||
+10
-11
@@ -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 '../injector';
|
||||
import '../../injector';
|
||||
|
||||
import { setAddressPrefix } from '@polkadot/util-crypto';
|
||||
|
||||
import createType from '../codec/createType';
|
||||
import U8a from '../codec/U8a';
|
||||
import Vec from '../codec/Vec';
|
||||
import jsonVec from '../json/AccountIdVec.001.json';
|
||||
import createType from '../../codec/createType';
|
||||
import U8a from '../../codec/U8a';
|
||||
import jsonVec from '../../json/AccountIdVec.001.json';
|
||||
import AccountId from './AccountId';
|
||||
|
||||
describe('AccountId', (): void => {
|
||||
describe('defaults', (): void => {
|
||||
const id = new AccountId();
|
||||
const id = createType('AccountId');
|
||||
|
||||
it('has a 32-byte length', (): void => {
|
||||
expect(id).toHaveLength(32);
|
||||
@@ -32,13 +31,13 @@ describe('AccountId', (): void => {
|
||||
describe('decoding', (): void => {
|
||||
const testDecode = (type: string, input: Uint8Array | string | AccountId, expected: string): void =>
|
||||
it(`can decode from ${type}`, (): void => {
|
||||
const a = new AccountId(input);
|
||||
const a = createType('AccountId', input);
|
||||
expect(a.toString()).toBe(expected);
|
||||
});
|
||||
|
||||
testDecode(
|
||||
'AccountId',
|
||||
new AccountId('0x0102030405060708010203040506070801020304050607080102030405060708'),
|
||||
createType('AccountId', '0x0102030405060708010203040506070801020304050607080102030405060708'),
|
||||
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'
|
||||
);
|
||||
testDecode('hex', '0x0102030405060708010203040506070801020304050607080102030405060708', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF');
|
||||
@@ -64,7 +63,7 @@ describe('AccountId', (): void => {
|
||||
describe('encoding', (): void => {
|
||||
const testEncode = (to: 'toHex' | 'toJSON' | 'toString' | 'toU8a', expected: Uint8Array | string, input: string = '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'): void =>
|
||||
it(`can encode ${to}`, (): void => {
|
||||
const a = new AccountId(input);
|
||||
const a = createType('AccountId', input);
|
||||
|
||||
expect(a[to]()).toEqual(expected);
|
||||
});
|
||||
@@ -79,7 +78,7 @@ describe('AccountId', (): void => {
|
||||
]));
|
||||
|
||||
it('decodes to a non-empty value', (): void => {
|
||||
expect(new AccountId('7qT1BvpawNbqb3BZaBTMFMMAKrpJKLPf1LmEHR1JyarWJdMX').isEmpty).toBe(false);
|
||||
expect(createType('AccountId', '7qT1BvpawNbqb3BZaBTMFMMAKrpJKLPf1LmEHR1JyarWJdMX').isEmpty).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -88,7 +87,7 @@ describe('AccountId', (): void => {
|
||||
setAddressPrefix(68);
|
||||
|
||||
const data = createType('StorageData', jsonVec.params.result.changes[0][1]);
|
||||
const list = new Vec(AccountId, data).map((accountId): string => accountId.toString());
|
||||
const list = createType('Vec<AccountId>', data).map((accountId): string => accountId.toString());
|
||||
|
||||
expect(list).toEqual([
|
||||
'7qVJujLF3EDbZt5WfQXWvueFedMS4Vfk2Hb4GyR8jwksTLup',
|
||||
+2
-2
@@ -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 { AnyString, AnyU8a } from '../types';
|
||||
import { AnyString, AnyU8a } from '../../types';
|
||||
|
||||
import { hexToU8a, isHex, isString, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
import U8aFixed from '../codec/U8aFixed';
|
||||
import U8aFixed from '../../codec/U8aFixed';
|
||||
|
||||
/**
|
||||
* @name AccountId
|
||||
+10
-6
@@ -2,40 +2,44 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import '../../injector';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import createType from '../../codec/createType';
|
||||
import AccountIndex from './AccountIndex';
|
||||
|
||||
describe('AccountIndex', (): void => {
|
||||
it('creates a BN representation', (): void => {
|
||||
expect(
|
||||
new AccountIndex(new Uint8Array([17, 18, 19, 20])).toNumber()
|
||||
createType('AccountIndex', new Uint8Array([17, 18, 19, 20])).toNumber()
|
||||
).toEqual(336794129);
|
||||
});
|
||||
|
||||
it('creates a BN representation (from ss-58)', (): void => {
|
||||
expect(
|
||||
new AccountIndex('Mwz15xP2').toNumber()
|
||||
createType('AccountIndex', 'Mwz15xP2').toNumber()
|
||||
).toEqual(336794129);
|
||||
});
|
||||
|
||||
it('constructs 2-byte from number', (): void => {
|
||||
expect(
|
||||
new AccountIndex(256 * 1).toString()
|
||||
createType('AccountIndex', 256 * 1).toString()
|
||||
).toEqual('25GUyv');
|
||||
});
|
||||
|
||||
it('constructs from number', (): void => {
|
||||
expect(
|
||||
new AccountIndex(new BN(336794129)).toString()
|
||||
createType('AccountIndex', new BN(336794129)).toString()
|
||||
).toEqual('Mwz15xP2');
|
||||
});
|
||||
|
||||
it('compares ss-58 values', (): void => {
|
||||
expect(new AccountIndex(256 * 1).eq('25GUyv')).toBe(true);
|
||||
expect(createType('AccountIndex', 256 * 1).eq('25GUyv')).toBe(true);
|
||||
});
|
||||
|
||||
it('compares numbers', (): void => {
|
||||
expect(new AccountIndex('2jpAFn').eq(256 * 1)).toBe(true);
|
||||
expect(createType('AccountIndex', '2jpAFn').eq(256 * 1)).toBe(true);
|
||||
});
|
||||
|
||||
describe('calcLength', (): void => {
|
||||
+4
-3
@@ -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 { AnyNumber } from '../types';
|
||||
import { AnyNumber } from '../../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { bnToBn, isBn, isNumber, isU8a, isHex } from '@polkadot/util';
|
||||
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
import U32 from './U32';
|
||||
import createType from '../../codec/createType';
|
||||
import U32 from '../U32';
|
||||
|
||||
export const ENUMSET_SIZE = new BN(64);
|
||||
|
||||
@@ -92,7 +93,7 @@ export default class AccountIndex extends U32 {
|
||||
}
|
||||
|
||||
// convert and compare
|
||||
return super.eq(new AccountIndex(other));
|
||||
return super.eq(createType('AccountIndex', other));
|
||||
}
|
||||
|
||||
/**
|
||||
+11
-8
@@ -2,6 +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 '../../injector';
|
||||
|
||||
import createType from '../../codec/createType';
|
||||
import AccountId from './AccountId';
|
||||
import AccountIndex from './AccountIndex';
|
||||
import Address from './Address';
|
||||
@@ -9,7 +12,7 @@ import Address from './Address';
|
||||
describe('Address', (): void => {
|
||||
const testDecode = (type: string, input: Address | AccountId | AccountIndex | number[] | Uint8Array, expected: string): void =>
|
||||
it(`can decode from ${type}`, (): void => {
|
||||
const a = new Address(input);
|
||||
const a = createType('Address', input);
|
||||
expect(a.toString()).toBe(expected);
|
||||
});
|
||||
|
||||
@@ -17,35 +20,35 @@ describe('Address', (): void => {
|
||||
it('equals on AccountId', (): void => {
|
||||
const addr = '5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5jzo';
|
||||
|
||||
expect(new Address(addr).eq(addr)).toBe(true);
|
||||
expect(createType('Address', addr).eq(addr)).toBe(true);
|
||||
});
|
||||
|
||||
it('equals on AccountIndex', (): void => {
|
||||
// see the test below - these are equivalent (with different prefix encoding)
|
||||
expect(new Address('2jpAFn').eq('25GUyv')).toBe(true);
|
||||
expect(createType('Address', '2jpAFn').eq('25GUyv')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('decoding', (): void => {
|
||||
testDecode(
|
||||
'Address',
|
||||
new Address('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'),
|
||||
createType('Address', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'),
|
||||
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'
|
||||
);
|
||||
testDecode(
|
||||
'AccountId',
|
||||
new AccountId('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'),
|
||||
createType('AccountId', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'),
|
||||
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'
|
||||
);
|
||||
testDecode(
|
||||
'AccountIndex (mixed prefixes)',
|
||||
new Address('2jpAFn'),
|
||||
createType('Address', '2jpAFn'),
|
||||
// NOTE Expected adress here is encoded with prefix 42, input above with 68
|
||||
'25GUyv'
|
||||
);
|
||||
testDecode(
|
||||
'AccountIndex (hex)',
|
||||
new AccountIndex('0x0100'),
|
||||
createType('AccountIndex', '0x0100'),
|
||||
'25GUyv'
|
||||
);
|
||||
testDecode(
|
||||
@@ -94,7 +97,7 @@ describe('Address', (): void => {
|
||||
describe('encoding', (): void => {
|
||||
const testEncode = (to: 'toHex' | 'toString' | 'toU8a', expected: string | Uint8Array): void =>
|
||||
it(`can encode ${to}`, (): void => {
|
||||
const a = new Address('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF');
|
||||
const a = createType('Address', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF');
|
||||
expect(a[to]()).toEqual(expected);
|
||||
});
|
||||
|
||||
+8
-7
@@ -6,7 +6,8 @@ import BN from 'bn.js';
|
||||
import { hexToU8a, isBn, isHex, isNumber, isU8a, u8aConcat, u8aToHex, u8aToU8a, u8aToBn } from '@polkadot/util';
|
||||
import { decodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
import Base from '../codec/Base';
|
||||
import createType from '../../codec/createType';
|
||||
import Base from '../../codec/Base';
|
||||
import AccountId from './AccountId';
|
||||
import AccountIndex from './AccountIndex';
|
||||
|
||||
@@ -33,7 +34,7 @@ export default class Address extends Base<AccountId | AccountIndex> {
|
||||
if (value instanceof AccountId || value instanceof AccountIndex) {
|
||||
return value;
|
||||
} else if (isBn(value) || isNumber(value)) {
|
||||
return new AccountIndex(value);
|
||||
return createType('AccountIndex', value);
|
||||
} else if (value instanceof Address) {
|
||||
return value.raw;
|
||||
} else if (Array.isArray(value)) {
|
||||
@@ -42,14 +43,14 @@ export default class Address extends Base<AccountId | AccountIndex> {
|
||||
// This allows us to instantiate an address with a raw publicKey. Do this first before
|
||||
// we checking the first byte, otherwise we may split an already-existent valid address
|
||||
if (value.length === 32) {
|
||||
return new AccountId(value);
|
||||
return createType('AccountId', value);
|
||||
} else if (value[0] === 0xff) {
|
||||
return new AccountId(value.subarray(1));
|
||||
return createType('AccountId', value.subarray(1));
|
||||
}
|
||||
|
||||
const [offset, length] = AccountIndex.readLength(value);
|
||||
|
||||
return new AccountIndex(u8aToBn(value.subarray(offset, offset + length), true));
|
||||
return createType('AccountIndex', u8aToBn(value.subarray(offset, offset + length), true));
|
||||
} else if (isHex(value)) {
|
||||
return Address.decodeAddress(hexToU8a(value));
|
||||
}
|
||||
@@ -57,8 +58,8 @@ export default class Address extends Base<AccountId | AccountIndex> {
|
||||
const decoded = decodeAddress(value);
|
||||
|
||||
return decoded.length === 32
|
||||
? new AccountId(decoded)
|
||||
: new AccountIndex(u8aToBn(decoded, true));
|
||||
? createType('AccountId', decoded)
|
||||
: createType('AccountIndex', u8aToBn(decoded, true));
|
||||
}
|
||||
|
||||
/**
|
||||
+9
-9
@@ -2,18 +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 { EventId } from '../interfaces/system';
|
||||
import { Constructor, Codec } from '../types';
|
||||
import { EventId } from '../../interfaces/system';
|
||||
import { Constructor, Codec } from '../../types';
|
||||
|
||||
import { assert, isUndefined, stringCamelCase, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { ClassOf, TypeDef, getTypeClass, getTypeDef } from '../codec/createType';
|
||||
import Struct from '../codec/Struct';
|
||||
import Tuple from '../codec/Tuple';
|
||||
import Metadata from '../Metadata';
|
||||
import { EventMetadata as EventMetadataV7 } from '../Metadata/v7/Events';
|
||||
import Null from './Null';
|
||||
import Unconstructable from './Unconstructable';
|
||||
import { ClassOf, TypeDef, getTypeClass, getTypeDef } from '../../codec/createType';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Tuple from '../../codec/Tuple';
|
||||
import Metadata from '../../Metadata';
|
||||
import { EventMetadata as EventMetadataV7 } from '../../Metadata/v7/Events';
|
||||
import Null from '../Null';
|
||||
import Unconstructable from '../Unconstructable';
|
||||
|
||||
const EventTypes: Record<string, Constructor<EventData>> = {};
|
||||
|
||||
+1
-1
@@ -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 '../injector';
|
||||
import '../../injector';
|
||||
|
||||
import Vote from './Vote';
|
||||
|
||||
+11
-7
@@ -2,13 +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 { Conviction } from '../interfaces/democracy';
|
||||
import { Conviction } from '../../interfaces/democracy';
|
||||
|
||||
import { isBoolean, isNumber, isObject, isU8a, isUndefined } from '@polkadot/util';
|
||||
|
||||
import createType from '../codec/createType';
|
||||
import U8a from '../codec/U8a';
|
||||
import Bool from './Bool';
|
||||
import createType from '../../codec/createType';
|
||||
import U8a from '../../codec/U8a';
|
||||
import Bool from '../Bool';
|
||||
|
||||
/**
|
||||
* @name Vote
|
||||
@@ -36,7 +36,9 @@ export default class Vote extends U8a {
|
||||
}
|
||||
|
||||
private static decodeVote (value?: any): Uint8Array {
|
||||
if (isBoolean(value)) {
|
||||
if (isUndefined(value)) {
|
||||
return new Uint8Array([0]);
|
||||
} else if (isBoolean(value)) {
|
||||
return value
|
||||
? new Uint8Array([0b10000000])
|
||||
: new Uint8Array([0b0]);
|
||||
@@ -53,8 +55,10 @@ export default class Vote extends U8a {
|
||||
const result = convictionIndex | (aye.eq(true) ? 0b1 << 7 : 0b0);
|
||||
|
||||
return new Uint8Array([result]);
|
||||
} else if (isU8a(value) && value.length > 0) {
|
||||
return value;
|
||||
} else if (isU8a(value)) {
|
||||
return value.length
|
||||
? value
|
||||
: new Uint8Array([0]);
|
||||
}
|
||||
|
||||
throw new Error(`Unable to convert input ${value} to Vote`);
|
||||
@@ -2,6 +2,11 @@
|
||||
// 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 GenericAccountId } from './AccountId';
|
||||
export { default as GenericAccountIndex } from './AccountIndex';
|
||||
export { default as GenericAddress } from './Address';
|
||||
export { default as GenericBlock } from './Block';
|
||||
export { default as GenericConsensusEngineId } from './ConsensusEngineId';
|
||||
export { default as GenericEvent } from './Event';
|
||||
export { default as GenericDigest, DigestItem as GenericDigestItem } from './Digest';
|
||||
export { default as GenericVote } from './Vote';
|
||||
|
||||
@@ -10,11 +10,7 @@
|
||||
*/
|
||||
// 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 } from './AccountId';
|
||||
export { default as AccountIndex } from './AccountIndex';
|
||||
export { default as Address } from './Address';
|
||||
export { default as Event } from './Event';
|
||||
export { default as Bool, default as bool } from './Bool';
|
||||
export { default as bool } from './Bool';
|
||||
export { default as Bytes } from './Bytes';
|
||||
export { default as Data } from './Data';
|
||||
export * from './Extrinsic';
|
||||
@@ -44,4 +40,3 @@ 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 } from './USize';
|
||||
export { default as Vote } from './Vote';
|
||||
|
||||
@@ -10,7 +10,7 @@ import Compact from './codec/Compact';
|
||||
import U8a from './codec/U8a';
|
||||
import { FunctionMetadata } from './Metadata/v7/Calls';
|
||||
import Method from './primitive/Method';
|
||||
import Address from './primitive/Address';
|
||||
import Address from './primitive/Generic/Address';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
||||
export interface IKeyringPair {
|
||||
|
||||
Reference in New Issue
Block a user