Generic Asset module type definitions (#1229)
* Fix missing type import for generated code * Add GenericAsset module type definations * eslint --fix
This commit is contained in:
committed by
Jaco Greeff
parent
56e8ef6ebb
commit
0323b27da4
@@ -2,7 +2,7 @@
|
||||
|
||||
import { Compact, Option, Vec } from './codec';
|
||||
import { Bytes, Data, Fixed64, H160, H256, H512, Null, StorageHasher, StorageKey, Text, Type, 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, Call, Consensus, ConsensusEngineId, Digest, DigestItem, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, Hash, Header, ImmortalEra, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, Moment, MortalEra, Origin, Perbill, Permill, Phantom, PreRuntime, Seal, SealV0, Signature, SignedBlock, Sr25519Signature, StorageData, ValidatorId, Weight, WeightMultiplier } from './interfaces/runtime';
|
||||
import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, Consensus, ConsensusEngineId, Digest, DigestItem, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, Hash, Header, ImmortalEra, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, Moment, MortalEra, Origin, Perbill, Permill, Phantom, PreRuntime, Seal, SealV0, 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';
|
||||
@@ -14,6 +14,7 @@ import { MemberCount, ProposalIndex, Votes } from './interfaces/collective';
|
||||
import { AliveContractInfo, CodeHash, ContractInfo, ContractStorageKey, Gas, PrefabWasmModule, PrefabWasmModuleReserved, Schedule, SeedOf, TombstoneContractInfo, TrieId } from './interfaces/contracts';
|
||||
import { Conviction, PropIndex, Proposal, ReferendumIndex, ReferendumInfo } from './interfaces/democracy';
|
||||
import { AccountInfo, Amount, AssetOf, InherentOfflineReport, LockPeriods, NewAccountOutcome, OpaqueKey, SessionKey } from './interfaces/deprecated';
|
||||
import { AssetOptions, Owner, PermissionLatest, PermissionVersions, PermissionsV1 } from './interfaces/genericAsset';
|
||||
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';
|
||||
@@ -117,6 +118,10 @@ export interface InterfaceRegistry {
|
||||
Address: Address;
|
||||
'Option<Address>': Option<Address>;
|
||||
'Vec<Address>': Vec<Address>;
|
||||
AssetId: AssetId;
|
||||
'Compact<AssetId>': Compact<AssetId>;
|
||||
'Option<AssetId>': Option<AssetId>;
|
||||
'Vec<AssetId>': Vec<AssetId>;
|
||||
Balance: Balance;
|
||||
'Compact<Balance>': Compact<Balance>;
|
||||
'Option<Balance>': Option<Balance>;
|
||||
@@ -403,6 +408,21 @@ export interface InterfaceRegistry {
|
||||
OpaqueKey: OpaqueKey;
|
||||
'Option<OpaqueKey>': Option<OpaqueKey>;
|
||||
'Vec<OpaqueKey>': Vec<OpaqueKey>;
|
||||
AssetOptions: AssetOptions;
|
||||
'Option<AssetOptions>': Option<AssetOptions>;
|
||||
'Vec<AssetOptions>': Vec<AssetOptions>;
|
||||
PermissionsV1: PermissionsV1;
|
||||
'Option<PermissionsV1>': Option<PermissionsV1>;
|
||||
'Vec<PermissionsV1>': Vec<PermissionsV1>;
|
||||
Owner: Owner;
|
||||
'Option<Owner>': Option<Owner>;
|
||||
'Vec<Owner>': Vec<Owner>;
|
||||
PermissionVersions: PermissionVersions;
|
||||
'Option<PermissionVersions>': Option<PermissionVersions>;
|
||||
'Vec<PermissionVersions>': Vec<PermissionVersions>;
|
||||
PermissionLatest: PermissionLatest;
|
||||
'Option<PermissionLatest>': Option<PermissionLatest>;
|
||||
'Vec<PermissionLatest>': Vec<PermissionLatest>;
|
||||
OpaqueMultiaddr: OpaqueMultiaddr;
|
||||
'Option<OpaqueMultiaddr>': Option<OpaqueMultiaddr>;
|
||||
'Vec<OpaqueMultiaddr>': Vec<OpaqueMultiaddr>;
|
||||
|
||||
@@ -29,6 +29,7 @@ export { default as collective } from './collective/definitions';
|
||||
export { default as contracts } from './contracts/definitions';
|
||||
export { default as democracy } from './democracy/definitions';
|
||||
export { default as deprecated } from './deprecated/definitions';
|
||||
export { default as genericAsset } from './genericAsset/definitions';
|
||||
export { default as imOnline } from './imOnline/definitions';
|
||||
export { default as parachains } from './parachains/definitions';
|
||||
export { default as staking } from './staking/definitions';
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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: {
|
||||
Owner: {
|
||||
_enum: {
|
||||
None: 'Null',
|
||||
Address: 'AccountId'
|
||||
}
|
||||
},
|
||||
PermissionsV1: {
|
||||
update: 'Owner',
|
||||
mint: 'Owner',
|
||||
burn: 'Owner'
|
||||
},
|
||||
PermissionVersions: {
|
||||
_enum: {
|
||||
V1: 'PermissionsV1'
|
||||
}
|
||||
},
|
||||
PermissionLatest: 'PermissionsV1',
|
||||
AssetOptions: {
|
||||
initalIssuance: 'Balance',
|
||||
permissions: 'PermissionLatest'
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
export * from './types';
|
||||
@@ -0,0 +1,43 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { Enum, Struct } from '../../codec';
|
||||
import { AccountId, Balance } from '../runtime';
|
||||
|
||||
/** Struct */
|
||||
export interface AssetOptions extends Struct {
|
||||
/** Balance */
|
||||
readonly initalIssuance: Balance;
|
||||
/** PermissionLatest */
|
||||
readonly permissions: PermissionLatest;
|
||||
}
|
||||
|
||||
/** Enum */
|
||||
export interface Owner extends Enum {
|
||||
/** 0:: None */
|
||||
readonly isNone: boolean;
|
||||
/** 1:: Address(AccountId) */
|
||||
readonly isAddress: boolean;
|
||||
/** AccountId */
|
||||
readonly asAddress: AccountId;
|
||||
}
|
||||
|
||||
/** PermissionsV1 */
|
||||
export type PermissionLatest = PermissionsV1;
|
||||
|
||||
/** Struct */
|
||||
export interface PermissionsV1 extends Struct {
|
||||
/** Owner */
|
||||
readonly update: Owner;
|
||||
/** Owner */
|
||||
readonly mint: Owner;
|
||||
/** Owner */
|
||||
readonly burn: Owner;
|
||||
}
|
||||
|
||||
/** Enum */
|
||||
export interface PermissionVersions extends Enum {
|
||||
/** 0:: V1(PermissionsV1) */
|
||||
readonly isV1: boolean;
|
||||
/** PermissionsV1 */
|
||||
readonly asV1: PermissionsV1;
|
||||
}
|
||||
@@ -8,6 +8,7 @@ export default {
|
||||
AccountIdOf: 'AccountId',
|
||||
AccountIndex: 'GenericAccountIndex',
|
||||
Address: 'GenericAddress',
|
||||
AssetId: 'u32',
|
||||
Balance: 'u128',
|
||||
BalanceOf: 'Balance',
|
||||
BlockNumber: 'u64',
|
||||
|
||||
@@ -16,6 +16,9 @@ export type AccountIndex = GenericAccountIndex;
|
||||
/** GenericAddress */
|
||||
export type Address = GenericAddress;
|
||||
|
||||
/** u32 */
|
||||
export type AssetId = u32;
|
||||
|
||||
/** u128 */
|
||||
export type Balance = u128;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ export * from './collective/types';
|
||||
export * from './contracts/types';
|
||||
export * from './democracy/types';
|
||||
export * from './deprecated/types';
|
||||
export * from './genericAsset/types';
|
||||
export * from './imOnline/types';
|
||||
export * from './parachains/types';
|
||||
export * from './staking/types';
|
||||
|
||||
@@ -81,7 +81,8 @@ function exportType (name: string = '', base: string): string {
|
||||
}
|
||||
|
||||
// helper to generate a `readonly <Name>: <Type>;` getter
|
||||
function createGetter (name: string = '', type: string, doc?: string): string {
|
||||
function createGetter (name: string = '', type: string, imports: TypeImports, doc?: string): string {
|
||||
setImports(imports, [type]);
|
||||
return ` /** ${doc || type} */\n readonly ${name}: ${type};\n`;
|
||||
}
|
||||
|
||||
@@ -112,8 +113,8 @@ function tsEnum ({ name: enumName, sub }: TypeDef, imports: TypeImports): string
|
||||
const getter = stringUpperFirst(stringCamelCase(name.replace(' ', '_')));
|
||||
const [enumType, asGetter] = type === 'Null'
|
||||
? ['', '']
|
||||
: [`(${type})`, createGetter(`as${getter}`, type)];
|
||||
const isGetter = createGetter(`is${getter}`, 'boolean', `${index}:: ${name}${enumType}`);
|
||||
: [`(${type})`, createGetter(`as${getter}`, type, imports)];
|
||||
const isGetter = createGetter(`is${getter}`, 'boolean', imports, `${index}:: ${name}${enumType}`);
|
||||
|
||||
switch (info) {
|
||||
case TypeDefInfo.Plain:
|
||||
@@ -186,7 +187,7 @@ function tsSet ({ name: setName, sub }: TypeDef, imports: TypeImports): string {
|
||||
setImports(imports, ['Set']);
|
||||
|
||||
const types = (sub as TypeDef[]).map(({ name }): string =>
|
||||
createGetter(`is${name}`, 'boolean')
|
||||
createGetter(`is${name}`, 'boolean', imports)
|
||||
);
|
||||
|
||||
return exportInterface(setName, 'Set', types.join(''));
|
||||
@@ -198,7 +199,7 @@ function tsStruct ({ name: structName, sub }: TypeDef, imports: TypeImports): st
|
||||
|
||||
setImports(imports, ['Struct', embedType]);
|
||||
|
||||
return createGetter(typedef.name, returnType);
|
||||
return createGetter(typedef.name, returnType, imports);
|
||||
});
|
||||
|
||||
return exportInterface(structName, 'Struct', keys.join(''));
|
||||
|
||||
Reference in New Issue
Block a user