Allow for balance/indices lookups (#596)
* Allow for balance/indices lookups * Latest metadata * Indices work * Update json with actual decoded * Update Type.ts * Some tests updated * Update final tests * Remove .only from derive e2e (really skip it)
This commit is contained in:
+11
-11
@@ -8,14 +8,14 @@ import { ApiInterface$Rx } from '@polkadot/api/types';
|
||||
import { decodeAddress } from '@polkadot/keyring';
|
||||
import { AccountId, AccountIndex } from '@polkadot/types/index';
|
||||
|
||||
import { accountIdToIndex } from './accountIdToIndex';
|
||||
import { accountIndexToId } from './accountIndexToId';
|
||||
import { idToIndex } from './idToIndex';
|
||||
import { indexToId } from './indexToId';
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
export type IdAndIndex = [AccountId?, AccountIndex?];
|
||||
export type AccountIdAndIndex = [AccountId?, AccountIndex?];
|
||||
|
||||
export function accountIdAndIndex (api: ApiInterface$Rx) {
|
||||
return (address?: AccountId | AccountIndex | string | null): Observable<IdAndIndex> => {
|
||||
export function idAndIndex (api: ApiInterface$Rx) {
|
||||
return (address?: AccountId | AccountIndex | string | null): Observable<AccountIdAndIndex> => {
|
||||
try {
|
||||
// yes, this can fail, don't care too much, catch will catch it
|
||||
const decoded = decodeAddress(address as any);
|
||||
@@ -23,20 +23,20 @@ export function accountIdAndIndex (api: ApiInterface$Rx) {
|
||||
if (decoded.length === 32) {
|
||||
const accountId = new AccountId(decoded);
|
||||
|
||||
return accountIdToIndex(api)(accountId).pipe(
|
||||
map((accountIndex) => [accountId, accountIndex] as IdAndIndex),
|
||||
return idToIndex(api)(accountId).pipe(
|
||||
map((accountIndex) => [accountId, accountIndex] as AccountIdAndIndex),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
|
||||
const accountIndex = new AccountIndex(address as string);
|
||||
const accountIndex = new AccountIndex(decoded);
|
||||
|
||||
return accountIndexToId(api)(accountIndex).pipe(
|
||||
map((accountId) => [accountId, accountIndex] as IdAndIndex),
|
||||
return indexToId(api)(accountIndex).pipe(
|
||||
map((accountId) => [accountId, accountIndex] as AccountIdAndIndex),
|
||||
drr()
|
||||
);
|
||||
} catch (error) {
|
||||
return of([undefined, undefined] as IdAndIndex).pipe(drr());
|
||||
return of([undefined, undefined] as AccountIdAndIndex).pipe(drr());
|
||||
}
|
||||
};
|
||||
}
|
||||
+3
-3
@@ -7,12 +7,12 @@ import { map } from 'rxjs/operators';
|
||||
import { ApiInterface$Rx } from '@polkadot/api/types';
|
||||
import { AccountId, AccountIndex } from '@polkadot/types/index';
|
||||
|
||||
import { accountIndexes, AccountIndexes } from './accountIndexes';
|
||||
import { indexes, AccountIndexes } from './indexes';
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
export function accountIdToIndex (api: ApiInterface$Rx) {
|
||||
export function idToIndex (api: ApiInterface$Rx) {
|
||||
return (accountId: AccountId | string): Observable<AccountIndex> =>
|
||||
accountIndexes(api)()
|
||||
indexes(api)()
|
||||
.pipe(
|
||||
map((indexes: AccountIndexes) => (indexes || {})[accountId.toString()]),
|
||||
drr()
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2019 @polkadot/api-derive 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 * from './idAndIndex';
|
||||
export * from './idToIndex';
|
||||
export * from './indexToId';
|
||||
export * from './indexes';
|
||||
+8
-7
@@ -11,15 +11,16 @@ import { AccountId, AccountIndex } from '@polkadot/types/index';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
export function accountIndexToId (api: ApiInterface$Rx) {
|
||||
return (accountIndex: AccountIndex | string): Observable<AccountId> => {
|
||||
const _accountIndex = accountIndex instanceof AccountIndex
|
||||
? accountIndex
|
||||
: new AccountIndex(accountIndex);
|
||||
export function indexToId (api: ApiInterface$Rx) {
|
||||
return (_accountIndex: AccountIndex | string): Observable<AccountId> => {
|
||||
const querySection = api.query.indices || api.query.balances;
|
||||
const accountIndex = _accountIndex instanceof AccountIndex
|
||||
? _accountIndex
|
||||
: new AccountIndex(_accountIndex);
|
||||
|
||||
return (api.query.balances.enumSet(accountIndex) as Observable<Vector<AccountId>>)
|
||||
return (querySection.enumSet(accountIndex.div(ENUMSET_SIZE)) as Observable<Vector<AccountId>>)
|
||||
.pipe(
|
||||
map((accounts) => (accounts || [])[_accountIndex.mod(ENUMSET_SIZE).toNumber()]),
|
||||
map((accounts) => (accounts || [])[accountIndex.mod(ENUMSET_SIZE).toNumber()]),
|
||||
drr()
|
||||
);
|
||||
};
|
||||
+8
-6
@@ -2,7 +2,6 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { combineLatest, Observable } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterface$Rx } from '@polkadot/api/types';
|
||||
@@ -13,17 +12,19 @@ import { drr } from '../util/drr';
|
||||
|
||||
export type AccountIndexes = { [index: string]: AccountIndex };
|
||||
|
||||
export function accountIndexes (api: ApiInterface$Rx) {
|
||||
return (): Observable<AccountIndexes> =>
|
||||
(api.query.balances.nextEnumSet() as Observable<AccountIndex>)
|
||||
export function indexes (api: ApiInterface$Rx) {
|
||||
return (): Observable<AccountIndexes> => {
|
||||
const querySection = api.query.indices || api.query.balances;
|
||||
|
||||
return (querySection.nextEnumSet() as Observable<AccountIndex>)
|
||||
.pipe(
|
||||
map((next: AccountIndex) => {
|
||||
const enumRange = [...Array((next || new BN(0)).div(ENUMSET_SIZE).toNumber() + 1).keys()];
|
||||
const enumRange = [...Array(next.div(ENUMSET_SIZE).toNumber() + 1).keys()];
|
||||
|
||||
return enumRange;
|
||||
}),
|
||||
switchMap((enumRange) => combineLatest(
|
||||
enumRange.map((index) => (api.query.balances.enumSet(index) as Observable<any>))
|
||||
enumRange.map((index) => (querySection.enumSet(index) as Observable<any>))
|
||||
)),
|
||||
map((all: Array<Array<AccountId> | undefined>) =>
|
||||
(all || []).reduce((result, list, outerIndex) => {
|
||||
@@ -37,4 +38,5 @@ export function accountIndexes (api: ApiInterface$Rx) {
|
||||
}, {} as AccountIndexes)),
|
||||
drr()
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -2,10 +2,6 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export * from './accountIdAndIndex';
|
||||
export * from './accountIdToIndex';
|
||||
export * from './accountIndexToId';
|
||||
export * from './accountIndexes';
|
||||
export * from './fees';
|
||||
export * from './validatingBalance';
|
||||
export * from './validatingBalances';
|
||||
|
||||
@@ -7,7 +7,7 @@ import { map, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterface$Rx } from '@polkadot/api/types';
|
||||
import { AccountId, AccountIndex, Balance } from '@polkadot/types/index';
|
||||
|
||||
import { accountIdAndIndex } from './accountIdAndIndex';
|
||||
import { idAndIndex } from '../accounts/idAndIndex';
|
||||
import { DerivedBalances } from '../types';
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
@@ -15,7 +15,7 @@ const EMPTY_ACCOUNT = new AccountId(new Uint8Array(32));
|
||||
|
||||
export function votingBalance (api: ApiInterface$Rx) {
|
||||
return (address: AccountIndex | AccountId | string): Observable<DerivedBalances> => {
|
||||
return accountIdAndIndex(api)(address).pipe(
|
||||
return idAndIndex(api)(address).pipe(
|
||||
switchMap(([accountId]) =>
|
||||
(accountId
|
||||
? combineLatest(
|
||||
@@ -26,9 +26,9 @@ export function votingBalance (api: ApiInterface$Rx) {
|
||||
: of([undefined, undefined, undefined])
|
||||
) as Observable<[AccountId?, Balance?, Balance?]>
|
||||
),
|
||||
map(([accountId, freeBalance = new Balance(0), reservedBalance = new Balance(0)]) => {
|
||||
map(([accountId = EMPTY_ACCOUNT, freeBalance = new Balance(0), reservedBalance = new Balance(0)]) => {
|
||||
return {
|
||||
accountId: accountId || EMPTY_ACCOUNT,
|
||||
accountId,
|
||||
freeBalance,
|
||||
nominatedBalance: new Balance(0),
|
||||
reservedBalance,
|
||||
|
||||
@@ -38,10 +38,11 @@ describe('derive', () => {
|
||||
|
||||
beforeAll((done) => api.isReady.subscribe(() => done()));
|
||||
|
||||
testFunction(api)('balances', 'accountIdAndIndex', []);
|
||||
testFunction(api)('balances', 'accountIdToIndex', []);
|
||||
testFunction(api)('balances', 'accountIndexes', []);
|
||||
testFunction(api)('balances', 'accountIndexToId', []);
|
||||
testFunction(api)('accounts', 'idAndIndex', []);
|
||||
testFunction(api)('accounts', 'idToIndex', []);
|
||||
testFunction(api)('accounts', 'indexes', []);
|
||||
testFunction(api)('accounts', 'indexToId', []);
|
||||
|
||||
testFunction(api)('balances', 'fees', []);
|
||||
testFunction(api)('balances', 'validatingBalance', []);
|
||||
testFunction(api)('balances', 'validatingBalances', []);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import { ApiInterface$Rx } from '@polkadot/api/types';
|
||||
|
||||
import * as accounts from './accounts';
|
||||
import * as balances from './balances';
|
||||
import * as chain from './chain';
|
||||
import * as democracy from './democracy';
|
||||
@@ -12,7 +13,7 @@ import * as staking from './staking';
|
||||
import { cache } from './util/cache';
|
||||
|
||||
// Put all derived functions in an object, for easier Object.keys()-ing.
|
||||
const functions = { balances, chain, democracy, session, staking };
|
||||
const functions = { accounts, balances, chain, democracy, session, staking };
|
||||
|
||||
/**
|
||||
* T represents the section here (chain, balances...), and P represents
|
||||
@@ -23,6 +24,7 @@ type ReturnTypes<T extends Record<keyof T, (...args: any[]) => any>> = {
|
||||
};
|
||||
|
||||
export interface Derive {
|
||||
accounts: ReturnTypes<typeof accounts>;
|
||||
balances: ReturnTypes<typeof balances>;
|
||||
chain: ReturnTypes<typeof chain>;
|
||||
democracy: ReturnTypes<typeof democracy>;
|
||||
|
||||
@@ -8,7 +8,8 @@ import { ApiInterface$Rx } from '@polkadot/api/types';
|
||||
import { BlockNumber } from '@polkadot/types/index';
|
||||
import { WsProvider } from '@polkadot/rpc-provider/index';
|
||||
|
||||
const WS = 'wss://poc3-rpc.polkadot.io/';
|
||||
const WS_LOCAL = 'ws://127.0.0.1:9944/';
|
||||
// const WS_POC3 = 'wss://poc3-rpc.polkadot.io/';
|
||||
|
||||
describe.skip('derive e2e', () => {
|
||||
let api: ApiInterface$Rx;
|
||||
@@ -18,7 +19,7 @@ describe.skip('derive e2e', () => {
|
||||
});
|
||||
|
||||
beforeEach(async (done) => {
|
||||
api = await ApiRx.create(new WsProvider(WS)).toPromise();
|
||||
api = await ApiRx.create(new WsProvider(WS_LOCAL)).toPromise();
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -44,6 +45,31 @@ describe.skip('derive e2e', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// these only work on localhost, not the poc-3 URL
|
||||
// (and it is assuming it sent at least 1 tx)
|
||||
describe('accounts', () => {
|
||||
const ID = '5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDtZ';
|
||||
const IX = 'F7Gh';
|
||||
|
||||
it('looks up id & index from id', async (done) => {
|
||||
// @ts-ignore silence warning until we have static types here
|
||||
api.derive.accounts.idAndIndex(ID).subscribe(([id, ix]) => {
|
||||
expect(id.toString()).toEqual(ID);
|
||||
expect(ix.toString()).toEqual(IX);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('looks up id & index from index', async (done) => {
|
||||
// @ts-ignore silence warning until we have static types here
|
||||
api.derive.accounts.idAndIndex(IX).subscribe(([id, ix]) => {
|
||||
expect(id.toString()).toEqual(ID);
|
||||
expect(ix.toString()).toEqual(IX);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
jest.setTimeout(5000);
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ describe('extrinsics', () => {
|
||||
extrinsics.balances.transfer(keyring.bob.publicKey(), 6969)
|
||||
).sign(keyring.alice, 0, '0xec7afaf1cca720ce88c1d1b689d81f0583cc15a97d621cf046dd9abf605ef22f').toU8a()
|
||||
).toEqual(new Uint8Array([
|
||||
37, 2, 129, 255, 209, 114, 167, 76, 218, 76, 134, 89, 18, 195, 43, 160, 168, 10, 87, 174, 105, 171, 174, 65, 14, 92, 203, 89, 222, 232, 78, 47, 68, 50, 219, 79, 148, 105, 162, 165, 130, 138, 239, 1, 131, 69, 7, 221, 50, 12, 137, 86, 22, 117, 195, 168, 94, 166, 49, 143, 78, 169, 34, 247, 161, 99, 134, 204, 95, 205, 47, 14, 216, 95, 190, 220, 24, 13, 75, 218, 172, 137, 229, 86, 11, 246, 111, 80, 204, 192, 213, 13, 101, 245, 230, 65, 33, 21, 129, 6, 0, 0, 2, 0, 255, 215, 86, 142, 95, 10, 126, 218, 103, 168, 38, 145, 255, 55, 154, 196, 187, 164, 249, 201, 184, 89, 254, 119, 155, 93, 70, 54, 59, 97, 173, 45, 185, 229, 108
|
||||
37, 2, 129, 255, 209, 114, 167, 76, 218, 76, 134, 89, 18, 195, 43, 160, 168, 10, 87, 174, 105, 171, 174, 65, 14, 92, 203, 89, 222, 232, 78, 47, 68, 50, 219, 79, 245, 228, 136, 9, 232, 31, 206, 95, 236, 20, 206, 189, 109, 251, 83, 198, 37, 79, 144, 90, 72, 33, 101, 250, 52, 0, 66, 80, 222, 78, 34, 124, 6, 101, 244, 44, 168, 225, 239, 153, 185, 58, 113, 221, 221, 136, 43, 237, 9, 6, 201, 17, 56, 110, 105, 78, 173, 109, 176, 100, 24, 78, 164, 15, 0, 0, 3, 0, 255, 215, 86, 142, 95, 10, 126, 218, 103, 168, 38, 145, 255, 55, 154, 196, 187, 164, 249, 201, 184, 89, 254, 119, 155, 93, 70, 54, 59, 97, 173, 45, 185, 229, 108
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -40,10 +40,7 @@ export default function createFunction (section: Text | string, method: Text | s
|
||||
assert(!isUndefined(arg) && !isNull(arg), `${meta.name} expects one argument`);
|
||||
|
||||
const type = meta.type.asMap.key.toString();
|
||||
|
||||
// encode with full encoding, indicating that this is a storage key to allow any
|
||||
// specific encoding to take place (and example here is AccountIndex)
|
||||
const param = createType(type, arg).toU8a(false, true);
|
||||
const param = createType(type, arg).toU8a(false);
|
||||
|
||||
key = u8aConcat(key, param);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { decodeAddress, encodeAddress } from '@polkadot/keyring';
|
||||
import { bnToBn, bnToU8a, isBn, isNumber, isU8a, isHex, hexToU8a, u8aToHex } from '@polkadot/util';
|
||||
import { bnToBn, isBn, isNumber, isU8a, isHex, hexToU8a, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { AnyNumber } from './types';
|
||||
import UInt from './codec/UInt';
|
||||
@@ -86,13 +86,6 @@ export default class AccountIndex extends U32 {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the BN representation of the AccountIndex
|
||||
*/
|
||||
toBn (): BN {
|
||||
return new BN(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns a hex string representation of the value
|
||||
*/
|
||||
@@ -117,21 +110,4 @@ export default class AccountIndex extends U32 {
|
||||
|
||||
return encodeAddress(this.toU8a().subarray(0, length));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Encodes the value as a Uint8Array as per the parity-codec specifications
|
||||
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
||||
* @param isStorageKey true when encoded as part of a key, taking case of specific logic
|
||||
*/
|
||||
toU8a (isBare?: boolean, isStorageKey?: boolean): Uint8Array {
|
||||
// HACK 15 Oct 2018 For isStorageKey assume that we are dealing with an AccountIndex
|
||||
// lookup (it is the only place where AccountIndex is used in such a manner to
|
||||
// construct a query). This is needed to get enumSet(AccountIndex) queries to
|
||||
// work in the way it was intended
|
||||
if (isStorageKey) {
|
||||
return bnToU8a(this.div(ENUMSET_SIZE), 32, true);
|
||||
}
|
||||
|
||||
return super.toU8a(isBare);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@ describe('EventRecord', () => {
|
||||
expect(er.phase.type).toEqual('ApplyExtrinsic');
|
||||
});
|
||||
|
||||
it('decodes more complex events', () => {
|
||||
// FIXME skipping this one, need an actual updated sample for the actual new types
|
||||
it.skip('decodes more complex events', () => {
|
||||
const records: Vector<EventRecord> = createType('Vec<EventRecord>', json2.params.result.changes[0][1]) as any;
|
||||
|
||||
expect(records).toHaveLength(4);
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import extrinsics from '@polkadot/extrinsics/static';
|
||||
import { hexToU8a, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import Compact from './codec/Compact';
|
||||
import Extrinsic from './Extrinsic';
|
||||
import Method from './Method';
|
||||
|
||||
@@ -22,35 +20,29 @@ describe('Extrinsic', () => {
|
||||
expect(extrinsic.data).toEqual(new Uint8Array([234, 81, 183, 91, 0, 0, 0, 0]));
|
||||
});
|
||||
|
||||
it('decodes an actual transaction with indexes', () => {
|
||||
const extrinsic = new Extrinsic('0x8110f8e1ebdd3cdef7423d24fe68f3863945ea21c190907d7f3394ddf153f633c77b894af36f7a36e7ec767f4593bfd8d084b66d805605905054327a08ff6041870804270e0200ff0e6422725af0e9aede3bef6eba77bc87afadf60b9735057ae93801f4c472ad7b00407a10f35a00000000000000000000');
|
||||
it('decodes an actual transaction (new format)', () => {
|
||||
const extrinsic = new Extrinsic('0x250281ffbfc823aa75c30058eeec21abe2c2d6b7247418a4af89d67a2084c2ac864da080c0aa4df3b4926c3cd78bbdced31d8bdccb8604b779b71b90e58b2848df4a9ad6b0aa1aae6be7a05c9413a172b0325e4d214e5ff2b25098028b30f1a50be9c90e0c000300ff4a83f1c09be797bc3d9adce29818368b276a84e6b545ced492c25c948978d7f8e5c0');
|
||||
|
||||
expect(extrinsic.isSigned).toEqual(true);
|
||||
expect(extrinsic.signature.signer.toU8a()).toEqual(new Uint8Array([0x10]));
|
||||
expect(extrinsic.signature.signature.toHex()).toEqual('0xf8e1ebdd3cdef7423d24fe68f3863945ea21c190907d7f3394ddf153f633c77b894af36f7a36e7ec767f4593bfd8d084b66d805605905054327a08ff60418708');
|
||||
expect(extrinsic.signature.nonce.toNumber()).toEqual(1);
|
||||
expect(extrinsic.signature.era.toU8a()).toEqual(new Uint8Array([0x27, 0x0e]));
|
||||
expect(extrinsic.callIndex).toEqual(new Uint8Array([2, 0]));
|
||||
expect(extrinsic.args[0].toString()).toEqual('5CPaGq4KcmntaboAxg5nyqGXdyzaBV2hj6PvhNA3syigiRg8');
|
||||
expect(extrinsic.signature.signer.toU8a()).toEqual(new Uint8Array([255, 191, 200, 35, 170, 117, 195, 0, 88, 238, 236, 33, 171, 226, 194, 214, 183, 36, 116, 24, 164, 175, 137, 214, 122, 32, 132, 194, 172, 134, 77, 160, 128]));
|
||||
expect(extrinsic.signature.signature.toHex()).toEqual('0xc0aa4df3b4926c3cd78bbdced31d8bdccb8604b779b71b90e58b2848df4a9ad6b0aa1aae6be7a05c9413a172b0325e4d214e5ff2b25098028b30f1a50be9c90e');
|
||||
expect(extrinsic.signature.nonce.toNumber()).toEqual(3);
|
||||
expect(extrinsic.signature.era.toU8a()).toEqual(new Uint8Array([0]));
|
||||
expect(extrinsic.callIndex).toEqual(new Uint8Array([3, 0]));
|
||||
expect(extrinsic.args[0].toString()).toEqual('5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5nni');
|
||||
});
|
||||
|
||||
it('decodes an actual transaction with indexes (new format)', () => {
|
||||
it('decodes an actual transaction (old format)', () => {
|
||||
const extrinsic = new Extrinsic(
|
||||
u8aToHex(
|
||||
Compact.addLengthPrefix(
|
||||
hexToU8a(
|
||||
'0x8110f8e1ebdd3cdef7423d24fe68f3863945ea21c190907d7f3394ddf153f633c77b894af36f7a36e7ec767f4593bfd8d084b66d805605905054327a08ff6041870804270e0200ff0e6422725af0e9aede3bef6eba77bc87afadf60b9735057ae93801f4c472ad7b00407a10f35a00000000000000000000'
|
||||
)
|
||||
)
|
||||
)
|
||||
'0x81ffbfc823aa75c30058eeec21abe2c2d6b7247418a4af89d67a2084c2ac864da080c0aa4df3b4926c3cd78bbdced31d8bdccb8604b779b71b90e58b2848df4a9ad6b0aa1aae6be7a05c9413a172b0325e4d214e5ff2b25098028b30f1a50be9c90e0c000300ff4a83f1c09be797bc3d9adce29818368b276a84e6b545ced492c25c948978d7f8e5c0'
|
||||
);
|
||||
|
||||
expect(extrinsic.isSigned).toEqual(true);
|
||||
expect(extrinsic.signature.signer.toU8a()).toEqual(new Uint8Array([0x10]));
|
||||
expect(extrinsic.signature.signature.toHex()).toEqual('0xf8e1ebdd3cdef7423d24fe68f3863945ea21c190907d7f3394ddf153f633c77b894af36f7a36e7ec767f4593bfd8d084b66d805605905054327a08ff60418708');
|
||||
expect(extrinsic.signature.nonce.toNumber()).toEqual(1);
|
||||
expect(extrinsic.signature.era.toU8a()).toEqual(new Uint8Array([0x27, 0x0e]));
|
||||
expect(extrinsic.callIndex).toEqual(new Uint8Array([2, 0]));
|
||||
expect(extrinsic.args[0].toString()).toEqual('5CPaGq4KcmntaboAxg5nyqGXdyzaBV2hj6PvhNA3syigiRg8');
|
||||
expect(extrinsic.signature.signer.toU8a()).toEqual(new Uint8Array([255, 191, 200, 35, 170, 117, 195, 0, 88, 238, 236, 33, 171, 226, 194, 214, 183, 36, 116, 24, 164, 175, 137, 214, 122, 32, 132, 194, 172, 134, 77, 160, 128]));
|
||||
expect(extrinsic.signature.signature.toHex()).toEqual('0xc0aa4df3b4926c3cd78bbdced31d8bdccb8604b779b71b90e58b2848df4a9ad6b0aa1aae6be7a05c9413a172b0325e4d214e5ff2b25098028b30f1a50be9c90e');
|
||||
expect(extrinsic.signature.nonce.toNumber()).toEqual(3);
|
||||
expect(extrinsic.signature.era.toU8a()).toEqual(new Uint8Array([0]));
|
||||
expect(extrinsic.callIndex).toEqual(new Uint8Array([3, 0]));
|
||||
expect(extrinsic.args[0].toString()).toEqual('5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5nni');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,6 +21,21 @@
|
||||
}
|
||||
]
|
||||
],
|
||||
[
|
||||
"indices",
|
||||
[
|
||||
{
|
||||
"name": "NewAccountIndex",
|
||||
"arguments": [
|
||||
"AccountId",
|
||||
"AccountIndex"
|
||||
],
|
||||
"documentation": [
|
||||
" A new account was created."
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
[
|
||||
"balances",
|
||||
[
|
||||
@@ -28,8 +43,7 @@
|
||||
"name": "NewAccount",
|
||||
"arguments": [
|
||||
"AccountId",
|
||||
"AccountIndex",
|
||||
"NewAccountOutcome"
|
||||
"Balance"
|
||||
],
|
||||
"documentation": [
|
||||
" A new account was created."
|
||||
@@ -384,27 +398,6 @@
|
||||
}
|
||||
]
|
||||
],
|
||||
[
|
||||
"upgrade_key",
|
||||
[
|
||||
{
|
||||
"name": "Upgraded",
|
||||
"arguments": [],
|
||||
"documentation": [
|
||||
" An upgrade just happened."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "KeyChanged",
|
||||
"arguments": [
|
||||
"AccountId"
|
||||
],
|
||||
"documentation": [
|
||||
" An upgrade just happened; old key is supplied as an argument."
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
[
|
||||
"sudo",
|
||||
[
|
||||
@@ -702,6 +695,42 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"prefix": "indices",
|
||||
"module": {
|
||||
"name": "Module",
|
||||
"call": {
|
||||
"name": "Call",
|
||||
"functions": []
|
||||
}
|
||||
},
|
||||
"storage": {
|
||||
"prefix": "Indices",
|
||||
"functions": [
|
||||
{
|
||||
"name": "NextEnumSet",
|
||||
"modifier": 1,
|
||||
"type": "AccountIndex",
|
||||
"default": "0x00000000",
|
||||
"documentation": [
|
||||
" The next free enumeration set."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "EnumSet",
|
||||
"modifier": 1,
|
||||
"type": {
|
||||
"key": "AccountIndex",
|
||||
"value": "Vec<AccountId>"
|
||||
},
|
||||
"default": "0x00",
|
||||
"documentation": [
|
||||
" The enumeration sets."
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"prefix": "balances",
|
||||
"module": {
|
||||
@@ -771,15 +800,6 @@
|
||||
" The minimum amount allowed to keep an account open."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ReclaimRebate",
|
||||
"modifier": 1,
|
||||
"type": "Balance",
|
||||
"default": "0x00000000000000000000000000000000",
|
||||
"documentation": [
|
||||
" The amount credited to a destination's account whose index was reclaimed."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "TransferFee",
|
||||
"modifier": 1,
|
||||
@@ -798,27 +818,6 @@
|
||||
" The fee required to create an account. At least as big as ReclaimRebate."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "NextEnumSet",
|
||||
"modifier": 1,
|
||||
"type": "AccountIndex",
|
||||
"default": "0x00000000",
|
||||
"documentation": [
|
||||
" The next free enumeration set."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "EnumSet",
|
||||
"modifier": 1,
|
||||
"type": {
|
||||
"key": "AccountIndex",
|
||||
"value": "Vec<AccountId>"
|
||||
},
|
||||
"default": "0x00",
|
||||
"documentation": [
|
||||
" The enumeration sets."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "FreeBalance",
|
||||
"modifier": 1,
|
||||
@@ -1493,11 +1492,11 @@
|
||||
"arguments": [
|
||||
{
|
||||
"name": "when",
|
||||
"type": "BlockNumber"
|
||||
"type": "Compact<BlockNumber>"
|
||||
},
|
||||
{
|
||||
"name": "which",
|
||||
"type": "u32"
|
||||
"type": "Compact<u32>"
|
||||
}
|
||||
],
|
||||
"documentation": [
|
||||
@@ -1888,7 +1887,7 @@
|
||||
"type": "VoteIndex",
|
||||
"default": "0x01000000",
|
||||
"documentation": [
|
||||
" How many votes need to go by after a voter's last vote before they can be reaped if their",
|
||||
" How many vote indexes need to go by after a target voter's last vote before they can be reaped if their",
|
||||
" approvals are moot."
|
||||
]
|
||||
},
|
||||
@@ -1926,7 +1925,9 @@
|
||||
"default": "0x00",
|
||||
"documentation": [
|
||||
" The current council. When there's a vote going on, this should still be used for executive",
|
||||
" matters."
|
||||
" matters. The block number (second element in the tuple) is the block that their position is",
|
||||
" active until (calculated by the sum of the block number when the council member was elected",
|
||||
" and their term duration)."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1947,7 +1948,8 @@
|
||||
},
|
||||
"default": "0x00",
|
||||
"documentation": [
|
||||
" The last cleared vote index that this voter was last active at."
|
||||
" A list of votes for each voter, respecting the last cleared vote index that this voter was",
|
||||
" last active at."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -2492,7 +2494,7 @@
|
||||
"arguments": [
|
||||
{
|
||||
"name": "dest",
|
||||
"type": "AccountId"
|
||||
"type": "Address"
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
@@ -2550,51 +2552,6 @@
|
||||
},
|
||||
"storage": null
|
||||
},
|
||||
{
|
||||
"prefix": "upgrade_key",
|
||||
"module": {
|
||||
"name": "Module",
|
||||
"call": {
|
||||
"name": "Call",
|
||||
"functions": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "upgrade",
|
||||
"arguments": [
|
||||
{
|
||||
"name": "new",
|
||||
"type": "Bytes"
|
||||
}
|
||||
],
|
||||
"documentation": []
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "set_key",
|
||||
"arguments": [
|
||||
{
|
||||
"name": "new",
|
||||
"type": "AccountId"
|
||||
}
|
||||
],
|
||||
"documentation": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"storage": {
|
||||
"prefix": "UpgradeKey",
|
||||
"functions": [
|
||||
{
|
||||
"name": "Key",
|
||||
"modifier": 1,
|
||||
"type": "AccountId",
|
||||
"default": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"documentation": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"prefix": "sudo",
|
||||
"module": {
|
||||
@@ -2619,7 +2576,7 @@
|
||||
"arguments": [
|
||||
{
|
||||
"name": "new",
|
||||
"type": "AccountId"
|
||||
"type": "Address"
|
||||
}
|
||||
],
|
||||
"documentation": []
|
||||
@@ -2654,59 +2611,59 @@
|
||||
"prefix": "consensus",
|
||||
"index": 1
|
||||
},
|
||||
{
|
||||
"name": "Indices",
|
||||
"prefix": "indices",
|
||||
"index": 2
|
||||
},
|
||||
{
|
||||
"name": "Balances",
|
||||
"prefix": "balances",
|
||||
"index": 2
|
||||
"index": 3
|
||||
},
|
||||
{
|
||||
"name": "Session",
|
||||
"prefix": "session",
|
||||
"index": 3
|
||||
"index": 4
|
||||
},
|
||||
{
|
||||
"name": "Staking",
|
||||
"prefix": "staking",
|
||||
"index": 4
|
||||
"index": 5
|
||||
},
|
||||
{
|
||||
"name": "Democracy",
|
||||
"prefix": "democracy",
|
||||
"index": 5
|
||||
"index": 6
|
||||
},
|
||||
{
|
||||
"name": "Council",
|
||||
"prefix": "council",
|
||||
"index": 6
|
||||
"index": 7
|
||||
},
|
||||
{
|
||||
"name": "CouncilVoting",
|
||||
"prefix": "council_voting",
|
||||
"index": 7
|
||||
"index": 8
|
||||
},
|
||||
{
|
||||
"name": "CouncilMotions",
|
||||
"prefix": "council_motions",
|
||||
"index": 8
|
||||
"index": 9
|
||||
},
|
||||
{
|
||||
"name": "Grandpa",
|
||||
"prefix": "grandpa",
|
||||
"index": 9
|
||||
"index": 10
|
||||
},
|
||||
{
|
||||
"name": "Treasury",
|
||||
"prefix": "treasury",
|
||||
"index": 10
|
||||
"index": 11
|
||||
},
|
||||
{
|
||||
"name": "Contract",
|
||||
"prefix": "contract",
|
||||
"index": 11
|
||||
},
|
||||
{
|
||||
"name": "UpgradeKey",
|
||||
"prefix": "upgrade_key",
|
||||
"index": 12
|
||||
},
|
||||
{
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -57,6 +57,10 @@ export default class Type extends Text {
|
||||
Type._alias('Vec<u8>', 'Bytes'),
|
||||
// alias RawAddress -> Address
|
||||
Type._alias('RawAddress', 'Address'),
|
||||
// alias Lookup::Source to Address (_could_ be AccountId on certain chains)
|
||||
Type._alias('Lookup::Source', 'Address'),
|
||||
// alias Lookup::Target to AccountId (always the case)
|
||||
Type._alias('Lookup::Target', 'AccountId'),
|
||||
// flattens tuples with one value, `(AccountId)` -> `AccountId`
|
||||
Type._flattenSingleTuple()
|
||||
];
|
||||
@@ -187,10 +191,16 @@ export default class Type extends Text {
|
||||
.replace(/\s/g, '')
|
||||
// anything `T::<type>` to end up as `<type>`
|
||||
.replace(/T::/g, '')
|
||||
// anything `Self::<type>` to end up as `<type>`
|
||||
.replace(/Self::/g, '')
|
||||
// `system::` with `` - basically we find `<T as system::Trait>`
|
||||
.replace(/system::/g, '')
|
||||
// replace `<T as Trait>::` (whitespaces were removed above)
|
||||
.replace(/<TasTrait>::/g, '')
|
||||
// replace `<Self as Trait>::` (whitespaces were removed above)
|
||||
.replace(/<SelfasTrait>::/g, '')
|
||||
// replace <Lookup as StaticLookup>
|
||||
.replace(/<LookupasStaticLookup>/g, 'Lookup')
|
||||
// replace `<...>::Type`
|
||||
.replace(/::Type/g, '');
|
||||
};
|
||||
|
||||
@@ -41,9 +41,8 @@ export interface Codec {
|
||||
/**
|
||||
* @description Encodes the value as a Uint8Array as per the parity-codec specifications
|
||||
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
||||
* @param isStorageKey true when encoded as part of a key, taking case of specific logic
|
||||
*/
|
||||
toU8a (isBare?: boolean, isStorageKey?: boolean): Uint8Array;
|
||||
toU8a (isBare?: boolean): Uint8Array;
|
||||
}
|
||||
|
||||
export type CodecTo = 'toHex' | 'toJSON' | 'toString' | 'toU8a';
|
||||
|
||||
Reference in New Issue
Block a user