Identity types (#1658)
* Identity types * Refine findMeta* error outputs * Cleanups, don't return crappy info, fail * Revert callIndex with size alloc
This commit is contained in:
@@ -14,11 +14,6 @@ import { createClass } from './createClass';
|
||||
import { getTypeClass } from './getTypeClass';
|
||||
import { getTypeDef } from './getTypeDef';
|
||||
|
||||
const FN_UNKNOWN: Partial<CallFunction> = {
|
||||
method: 'unknown',
|
||||
section: 'unknown'
|
||||
};
|
||||
|
||||
// create event classes from metadata
|
||||
function decorateEvents (registry: Registry, metadata: RegistryMetadata, metadataEvents: Record<string, Constructor<EventData>>): void {
|
||||
// decorate the events
|
||||
@@ -86,20 +81,19 @@ export class TypeRegistry implements Registry {
|
||||
}
|
||||
|
||||
public findMetaCall (callIndex: Uint8Array): CallFunction {
|
||||
assert(Object.keys(this._metadataCalls).length > 0, 'Calling registry.findMetaCall before metadata has been attached.');
|
||||
|
||||
const hexIndex = u8aToHex(callIndex);
|
||||
const fn = this._metadataCalls[hexIndex];
|
||||
|
||||
return this._metadataCalls[hexIndex] || FN_UNKNOWN;
|
||||
assert(!isUndefined(fn), `findMetaCall: Unable to find Call with index ${hexIndex}/[${callIndex}]`);
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
||||
public findMetaEvent (eventIndex: Uint8Array): Constructor<EventData> {
|
||||
assert(Object.keys(this._metadataEvents).length > 0, 'Calling registry.findMetaEvent before metadata has been attached.');
|
||||
|
||||
const hexIndex = u8aToHex(eventIndex);
|
||||
const Event = this._metadataEvents[hexIndex];
|
||||
|
||||
assert(!isUndefined(Event), `Unable to find Event with index ${hexIndex}`);
|
||||
assert(!isUndefined(Event), `findMetaEvent: Unable to find Event with index ${hexIndex}/[${eventIndex}]`);
|
||||
|
||||
return Event;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import { AccountInfo, Amount, AssetOf, InherentOfflineReport, LockPeriods, NewAc
|
||||
import { ApprovalFlag, SetIndex, Vote, VoteIndex, VoteThreshold, VoterInfo } from '@polkadot/types/interfaces/elections';
|
||||
import { AssetOptions, Owner, PermissionLatest, PermissionVersions, PermissionsV1 } from '@polkadot/types/interfaces/genericAsset';
|
||||
import { AuthorityIndex, AuthorityList, AuthorityWeight, NextAuthority, PendingPause, PendingResume, SetId, StoredPendingChange, StoredState } from '@polkadot/types/interfaces/grandpa';
|
||||
import { Data, IdentityFields, IdentityInfo, IdentityInfoAdditional, Judgement, RegistrarIndex, RegistrarInfo, Registration, RegistrationJudgement } from '@polkadot/types/interfaces/identity';
|
||||
import { AuthIndex, AuthoritySignature, Heartbeat, OpaqueMultiaddr, OpaqueNetworkState, OpaquePeerId } from '@polkadot/types/interfaces/imOnline';
|
||||
import { Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from '@polkadot/types/interfaces/offences';
|
||||
import { FullIdentification, IdentificationTuple, Keys, SessionIndex, SessionKeys1, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6 } from '@polkadot/types/interfaces/session';
|
||||
@@ -534,6 +535,34 @@ export interface InterfaceRegistry {
|
||||
StoredState: StoredState;
|
||||
'Option<StoredState>': Option<StoredState>;
|
||||
'Vec<StoredState>': Vec<StoredState>;
|
||||
Data: Data;
|
||||
'Option<Data>': Option<Data>;
|
||||
'Vec<Data>': Vec<Data>;
|
||||
IdentityFields: IdentityFields;
|
||||
'Option<IdentityFields>': Option<IdentityFields>;
|
||||
'Vec<IdentityFields>': Vec<IdentityFields>;
|
||||
IdentityInfoAdditional: IdentityInfoAdditional;
|
||||
'Option<IdentityInfoAdditional>': Option<IdentityInfoAdditional>;
|
||||
'Vec<IdentityInfoAdditional>': Vec<IdentityInfoAdditional>;
|
||||
IdentityInfo: IdentityInfo;
|
||||
'Option<IdentityInfo>': Option<IdentityInfo>;
|
||||
'Vec<IdentityInfo>': Vec<IdentityInfo>;
|
||||
Judgement: Judgement;
|
||||
'Option<Judgement>': Option<Judgement>;
|
||||
'Vec<Judgement>': Vec<Judgement>;
|
||||
RegistrationJudgement: RegistrationJudgement;
|
||||
'Option<RegistrationJudgement>': Option<RegistrationJudgement>;
|
||||
'Vec<RegistrationJudgement>': Vec<RegistrationJudgement>;
|
||||
Registration: Registration;
|
||||
'Option<Registration>': Option<Registration>;
|
||||
'Vec<Registration>': Vec<Registration>;
|
||||
RegistrarIndex: RegistrarIndex;
|
||||
'Compact<RegistrarIndex>': Compact<RegistrarIndex>;
|
||||
'Option<RegistrarIndex>': Option<RegistrarIndex>;
|
||||
'Vec<RegistrarIndex>': Vec<RegistrarIndex>;
|
||||
RegistrarInfo: RegistrarInfo;
|
||||
'Option<RegistrarInfo>': Option<RegistrarInfo>;
|
||||
'Vec<RegistrarInfo>': Vec<RegistrarInfo>;
|
||||
AuthIndex: AuthIndex;
|
||||
'Compact<AuthIndex>': Compact<AuthIndex>;
|
||||
'Option<AuthIndex>': Option<AuthIndex>;
|
||||
|
||||
@@ -18,6 +18,7 @@ export { default as deprecated } from './deprecated/definitions';
|
||||
export { default as elections } from './elections/definitions';
|
||||
export { default as genericAsset } from './genericAsset/definitions';
|
||||
export { default as grandpa } from './grandpa/definitions';
|
||||
export { default as identity } from './identity/definitions';
|
||||
export { default as imOnline } from './imOnline/definitions';
|
||||
export { default as offences } from './offences/definitions';
|
||||
export { default as session } from './session/definitions';
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export default {
|
||||
types: {
|
||||
Data: {
|
||||
_enum: {
|
||||
None: 'Null',
|
||||
Raw: 'Bytes',
|
||||
BlakeTwo256: 'H256',
|
||||
Sha256: 'H256',
|
||||
Keccak256: 'H256',
|
||||
ShaThree256: 'H256'
|
||||
}
|
||||
},
|
||||
IdentityFields: {
|
||||
_set: {
|
||||
Display: 0b0000000000000000000000000000000000000000000000000000000000000001,
|
||||
Legal: 0b0000000000000000000000000000000000000000000000000000000000000010,
|
||||
Web: 0b0000000000000000000000000000000000000000000000000000000000000100,
|
||||
Riot: 0b0000000000000000000000000000000000000000000000000000000000001000,
|
||||
Email: 0b0000000000000000000000000000000000000000000000000000000000010000,
|
||||
PgpFingerprint: 0b0000000000000000000000000000000000000000000000000000000000100000,
|
||||
Image: 0b0000000000000000000000000000000000000000000000000000000001000000
|
||||
}
|
||||
},
|
||||
IdentityInfoAdditional: '(Data, Data)',
|
||||
IdentityInfo: {
|
||||
additional: 'Vec<IdentityInfoAdditional>',
|
||||
display: 'Data',
|
||||
legal: 'Data',
|
||||
web: 'Data',
|
||||
riot: 'Data',
|
||||
email: 'Data',
|
||||
pgpFingerprint: 'Option<H160>',
|
||||
image: 'Data'
|
||||
},
|
||||
Judgement: {
|
||||
_enum: {
|
||||
Unknown: 'Null',
|
||||
FeePaid: 'Balance',
|
||||
Reasonable: 'Null',
|
||||
KnownGood: 'Null',
|
||||
OutOfDate: 'Null',
|
||||
LowQuality: 'Null',
|
||||
Erroneous: 'Null'
|
||||
}
|
||||
},
|
||||
RegistrationJudgement: '(RegistrarIndex, Judgement)',
|
||||
Registration: {
|
||||
judgements: 'Vec<RegistrationJudgement>',
|
||||
deposit: 'Balance',
|
||||
info: 'IdentityInfo'
|
||||
},
|
||||
RegistrarIndex: 'u32',
|
||||
RegistrarInfo: {
|
||||
account: 'AccountId',
|
||||
fee: 'Balance',
|
||||
fields: 'IdentityFields'
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
export * from './types';
|
||||
@@ -0,0 +1,120 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
import { Enum, Option, Set, Struct, Vec } from '@polkadot/types/codec';
|
||||
import { Bytes, H160, H256, u32 } from '@polkadot/types/primitive';
|
||||
import { AccountId, Balance } from '@polkadot/types/interfaces/runtime';
|
||||
|
||||
/** Enum */
|
||||
export interface Data extends Enum {
|
||||
/** 0:: None */
|
||||
readonly isNone: boolean;
|
||||
/** 1:: Raw(Bytes) */
|
||||
readonly isRaw: boolean;
|
||||
/** Bytes */
|
||||
readonly asRaw: Bytes;
|
||||
/** 2:: BlakeTwo256(H256) */
|
||||
readonly isBlakeTwo256: boolean;
|
||||
/** H256 */
|
||||
readonly asBlakeTwo256: H256;
|
||||
/** 3:: Sha256(H256) */
|
||||
readonly isSha256: boolean;
|
||||
/** H256 */
|
||||
readonly asSha256: H256;
|
||||
/** 4:: Keccak256(H256) */
|
||||
readonly isKeccak256: boolean;
|
||||
/** H256 */
|
||||
readonly asKeccak256: H256;
|
||||
/** 5:: ShaThree256(H256) */
|
||||
readonly isShaThree256: boolean;
|
||||
/** H256 */
|
||||
readonly asShaThree256: H256;
|
||||
}
|
||||
|
||||
/** Set */
|
||||
export interface IdentityFields extends Set {
|
||||
/** boolean */
|
||||
readonly isDisplay: boolean;
|
||||
/** boolean */
|
||||
readonly isLegal: boolean;
|
||||
/** boolean */
|
||||
readonly isWeb: boolean;
|
||||
/** boolean */
|
||||
readonly isRiot: boolean;
|
||||
/** boolean */
|
||||
readonly isEmail: boolean;
|
||||
/** boolean */
|
||||
readonly isPgpFingerprint: boolean;
|
||||
/** boolean */
|
||||
readonly isImage: boolean;
|
||||
}
|
||||
|
||||
/** Struct */
|
||||
export interface IdentityInfo extends Struct {
|
||||
/** Vec<IdentityInfoAdditional> */
|
||||
readonly additional: Vec<IdentityInfoAdditional>;
|
||||
/** Data */
|
||||
readonly display: Data;
|
||||
/** Data */
|
||||
readonly legal: Data;
|
||||
/** Data */
|
||||
readonly web: Data;
|
||||
/** Data */
|
||||
readonly riot: Data;
|
||||
/** Data */
|
||||
readonly email: Data;
|
||||
/** Option<H160> */
|
||||
readonly pgpFingerprint: Option<H160>;
|
||||
/** Data */
|
||||
readonly image: Data;
|
||||
}
|
||||
|
||||
/** ITuple<[Data, Data]> */
|
||||
export interface IdentityInfoAdditional extends ITuple<[Data, Data]> {}
|
||||
|
||||
/** Enum */
|
||||
export interface Judgement extends Enum {
|
||||
/** 0:: Unknown */
|
||||
readonly isUnknown: boolean;
|
||||
/** 1:: FeePaid(Balance) */
|
||||
readonly isFeePaid: boolean;
|
||||
/** Balance */
|
||||
readonly asFeePaid: Balance;
|
||||
/** 2:: Reasonable */
|
||||
readonly isReasonable: boolean;
|
||||
/** 3:: KnownGood */
|
||||
readonly isKnownGood: boolean;
|
||||
/** 4:: OutOfDate */
|
||||
readonly isOutOfDate: boolean;
|
||||
/** 5:: LowQuality */
|
||||
readonly isLowQuality: boolean;
|
||||
/** 6:: Erroneous */
|
||||
readonly isErroneous: boolean;
|
||||
}
|
||||
|
||||
/** u32 */
|
||||
export interface RegistrarIndex extends u32 {}
|
||||
|
||||
/** Struct */
|
||||
export interface RegistrarInfo extends Struct {
|
||||
/** AccountId */
|
||||
readonly account: AccountId;
|
||||
/** Balance */
|
||||
readonly fee: Balance;
|
||||
/** IdentityFields */
|
||||
readonly fields: IdentityFields;
|
||||
}
|
||||
|
||||
/** Struct */
|
||||
export interface Registration extends Struct {
|
||||
/** Vec<RegistrationJudgement> */
|
||||
readonly judgements: Vec<RegistrationJudgement>;
|
||||
/** Balance */
|
||||
readonly deposit: Balance;
|
||||
/** IdentityInfo */
|
||||
readonly info: IdentityInfo;
|
||||
}
|
||||
|
||||
/** ITuple<[RegistrarIndex, Judgement]> */
|
||||
export interface RegistrationJudgement extends ITuple<[RegistrarIndex, Judgement]> {}
|
||||
@@ -42,7 +42,7 @@ describe('SignedBlock', (): void => {
|
||||
const indexes = s.block.extrinsics.map(({ method: { callIndex } }): Uint8Array => callIndex);
|
||||
|
||||
expect(indexes).toEqual([
|
||||
new Uint8Array([0x02, 0x00]),
|
||||
new Uint8Array([0x03, 0x00]),
|
||||
new Uint8Array([0x0c, 0x00])
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ export * from './deprecated/types';
|
||||
export * from './elections/types';
|
||||
export * from './genericAsset/types';
|
||||
export * from './grandpa/types';
|
||||
export * from './identity/types';
|
||||
export * from './imOnline/types';
|
||||
export * from './offences/types';
|
||||
export * from './session/types';
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"result": {
|
||||
"block": {
|
||||
"extrinsics": [
|
||||
"0x010200b0b1c85b00000000"
|
||||
"0x010300b0b1c85b00000000"
|
||||
],
|
||||
"header": {
|
||||
"digest": {
|
||||
@@ -55,4 +55,4 @@
|
||||
}
|
||||
},
|
||||
"id": 8
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"jsonrpc":"2.0","result":{"block":{"extrinsics":["0x280202000b868d92346c01","0x14020c008151"],"header":{"digest":{"logs":["0x0642414245c101a5cb8138000000000000000000000000549baa911a66f7bab6318a6930380bfd015713f77b6775d2df467d37dadd224dda0a80881cfbddc580d45b3b7358f28e4990d950df4508590543d39d635b3402822279397c1d55449b201710c706ce5de3fd3cb2e269bea6ba89c71e4446fd06","0x05424142450101e4e9f32bb0e72821032f752422c6dc23e8acd5388eb17cbe009d7e3764a0625b38c1b90ec6f19bb5d8c093deeddf9df01845352ac6fefad49601be1f726cea09"]},"extrinsicsRoot":"0x794ff5dde3eaa27d56cc760dd18774c883d51ed9206ff93c9a7e7d6a8a6dca11","number":"0x1461","parentHash":"0x28cda71a46766fe3cf64475b566916d367617d14627e895067f4186e65609d0e","stateRoot":"0xc7803b39c1b30a87566ec9d95890db76cf2eee7034faee4c8a0997759e7bcb7e"}},"justification":null},"id":29}
|
||||
{"jsonrpc":"2.0","result":{"block":{"extrinsics":["0x280203000b868d92346c01","0x14020c008151"],"header":{"digest":{"logs":["0x0642414245c101a5cb8138000000000000000000000000549baa911a66f7bab6318a6930380bfd015713f77b6775d2df467d37dadd224dda0a80881cfbddc580d45b3b7358f28e4990d950df4508590543d39d635b3402822279397c1d55449b201710c706ce5de3fd3cb2e269bea6ba89c71e4446fd06","0x05424142450101e4e9f32bb0e72821032f752422c6dc23e8acd5388eb17cbe009d7e3764a0625b38c1b90ec6f19bb5d8c093deeddf9df01845352ac6fefad49601be1f726cea09"]},"extrinsicsRoot":"0x794ff5dde3eaa27d56cc760dd18774c883d51ed9206ff93c9a7e7d6a8a6dca11","number":"0x1461","parentHash":"0x28cda71a46766fe3cf64475b566916d367617d14627e895067f4186e65609d0e","stateRoot":"0xc7803b39c1b30a87566ec9d95890db76cf2eee7034faee4c8a0997759e7bcb7e"}},"justification":null},"id":29}
|
||||
|
||||
@@ -93,8 +93,10 @@ export default class Call extends Struct implements IMethod {
|
||||
}
|
||||
|
||||
private static decodeCallViaU8a (registry: Registry, value: Uint8Array, _meta?: FunctionMetadataLatest): DecodedMethod {
|
||||
// The first 2 bytes are the callIndex
|
||||
const callIndex = value.subarray(0, 2);
|
||||
// We need 2 bytes for the callIndex
|
||||
const callIndex = new Uint8Array(2);
|
||||
|
||||
callIndex.set(value.subarray(0, 2), 0);
|
||||
|
||||
// Find metadata with callIndex
|
||||
const meta = _meta || registry.findMetaCall(callIndex).meta;
|
||||
|
||||
Reference in New Issue
Block a user