Perbill formatting with rawType equality (#2646)
* Perbill formatting with rawType equality * Balance toHuman() check * Formatter lookup * typing * Merge * Better Compact detection
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
"@polkadot/api": "1.35.0-beta.8",
|
||||
"@polkadot/rpc-core": "1.35.0-beta.8",
|
||||
"@polkadot/types": "1.35.0-beta.8",
|
||||
"@polkadot/util": "^3.5.0-beta.12",
|
||||
"@polkadot/util": "^3.5.0-beta.13",
|
||||
"bn.js": "^5.1.3",
|
||||
"rxjs": "^6.6.3"
|
||||
}
|
||||
|
||||
@@ -32,13 +32,13 @@
|
||||
"@polkadot/rpc-core": "1.35.0-beta.8",
|
||||
"@polkadot/rpc-provider": "1.35.0-beta.8",
|
||||
"@polkadot/types": "1.35.0-beta.8",
|
||||
"@polkadot/util": "^3.5.0-beta.12",
|
||||
"@polkadot/util-crypto": "^3.5.0-beta.12",
|
||||
"@polkadot/util": "^3.5.0-beta.13",
|
||||
"@polkadot/util-crypto": "^3.5.0-beta.13",
|
||||
"bn.js": "^5.1.3",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.6.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.5.0-beta.12"
|
||||
"@polkadot/keyring": "^3.5.0-beta.13"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,19 +28,19 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/api-derive": "1.35.0-beta.8",
|
||||
"@polkadot/keyring": "^3.5.0-beta.12",
|
||||
"@polkadot/keyring": "^3.5.0-beta.13",
|
||||
"@polkadot/metadata": "1.35.0-beta.8",
|
||||
"@polkadot/rpc-core": "1.35.0-beta.8",
|
||||
"@polkadot/rpc-provider": "1.35.0-beta.8",
|
||||
"@polkadot/types": "1.35.0-beta.8",
|
||||
"@polkadot/types-known": "1.35.0-beta.8",
|
||||
"@polkadot/util": "^3.5.0-beta.12",
|
||||
"@polkadot/util-crypto": "^3.5.0-beta.12",
|
||||
"@polkadot/util": "^3.5.0-beta.13",
|
||||
"@polkadot/util-crypto": "^3.5.0-beta.13",
|
||||
"bn.js": "^5.1.3",
|
||||
"eventemitter3": "^4.0.7",
|
||||
"rxjs": "^6.6.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.5.0-beta.12"
|
||||
"@polkadot/keyring": "^3.5.0-beta.13"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,11 @@
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/types": "1.35.0-beta.8",
|
||||
"@polkadot/types-known": "1.35.0-beta.8",
|
||||
"@polkadot/util": "^3.5.0-beta.12",
|
||||
"@polkadot/util-crypto": "^3.5.0-beta.12",
|
||||
"@polkadot/util": "^3.5.0-beta.13",
|
||||
"@polkadot/util-crypto": "^3.5.0-beta.13",
|
||||
"bn.js": "^5.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.5.0-beta.12"
|
||||
"@polkadot/keyring": "^3.5.0-beta.13"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@
|
||||
"@polkadot/metadata": "1.35.0-beta.8",
|
||||
"@polkadot/rpc-provider": "1.35.0-beta.8",
|
||||
"@polkadot/types": "1.35.0-beta.8",
|
||||
"@polkadot/util": "^3.5.0-beta.12",
|
||||
"@polkadot/util": "^3.5.0-beta.13",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.6.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.5.0-beta.12"
|
||||
"@polkadot/keyring": "^3.5.0-beta.13"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,15 +29,15 @@
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/metadata": "1.35.0-beta.8",
|
||||
"@polkadot/types": "1.35.0-beta.8",
|
||||
"@polkadot/util": "^3.5.0-beta.12",
|
||||
"@polkadot/util-crypto": "^3.5.0-beta.12",
|
||||
"@polkadot/util": "^3.5.0-beta.13",
|
||||
"@polkadot/util-crypto": "^3.5.0-beta.13",
|
||||
"@polkadot/x-fetch": "^0.3.2",
|
||||
"@polkadot/x-ws": "^0.3.2",
|
||||
"bn.js": "^5.1.3",
|
||||
"eventemitter3": "^4.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.5.0-beta.12",
|
||||
"@polkadot/keyring": "^3.5.0-beta.13",
|
||||
"mock-socket": "^9.0.3",
|
||||
"nock": "^13.0.4"
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
"@polkadot/metadata": "1.35.0-beta.8",
|
||||
"@polkadot/rpc-provider": "1.35.0-beta.8",
|
||||
"@polkadot/types": "1.35.0-beta.8",
|
||||
"@polkadot/util": "^3.5.0-beta.12",
|
||||
"@polkadot/util": "^3.5.0-beta.13",
|
||||
"handlebars": "^4.7.6",
|
||||
"websocket": "^1.0.32",
|
||||
"yargs": "^16.0.3"
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import Handlebars from 'handlebars';
|
||||
|
||||
import Raw from '@polkadot/types/codec/Raw';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import * as defaultDefinitions from '@polkadot/types/interfaces/definitions';
|
||||
import * as defaultPrimitives from '@polkadot/types/primitive';
|
||||
|
||||
@@ -20,6 +21,8 @@ const generateInterfaceTypesTemplate = Handlebars.compile(template);
|
||||
|
||||
/** @internal */
|
||||
export function generateInterfaceTypes (importDefinitions: { [importPath: string]: Record<string, ModuleTypes> }, dest: string): void {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
writeFile(dest, (): string => {
|
||||
Object.entries(importDefinitions).reduce((acc, def) => Object.assign(acc, def), {});
|
||||
|
||||
@@ -34,7 +37,7 @@ export function generateInterfaceTypes (importDefinitions: { [importPath: string
|
||||
.forEach((primitiveName) => {
|
||||
setImports(definitions, imports, [primitiveName]);
|
||||
|
||||
items.push(...getDerivedTypes(definitions, primitiveName, primitiveName, imports));
|
||||
items.push(...getDerivedTypes(registry, definitions, primitiveName, primitiveName, imports));
|
||||
});
|
||||
|
||||
const existingTypes: Record<string, boolean> = {};
|
||||
@@ -47,7 +50,7 @@ export function generateInterfaceTypes (importDefinitions: { [importPath: string
|
||||
uniqueTypes.forEach((type) => {
|
||||
existingTypes[type] = true;
|
||||
|
||||
items.push(...getDerivedTypes(definitions, type, types[type] as string, imports));
|
||||
items.push(...getDerivedTypes(registry, definitions, type, types[type] as string, imports));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ function entrySignature (allDefs: Record<string, ModuleTypes>, registry: Registr
|
||||
return ['', formatType(allDefs, outputType, imports)];
|
||||
} else if (storageEntry.type.isMap) {
|
||||
// Find similar types of the `key` type
|
||||
const similarTypes = getSimilarTypes(allDefs, registry, storageEntry.type.asMap.key.toString(), imports);
|
||||
const similarTypes = getSimilarTypes(registry, allDefs, storageEntry.type.asMap.key.toString(), imports);
|
||||
|
||||
setImports(allDefs, imports, [
|
||||
...similarTypes,
|
||||
@@ -41,8 +41,8 @@ function entrySignature (allDefs: Record<string, ModuleTypes>, registry: Registr
|
||||
];
|
||||
} else if (storageEntry.type.isDoubleMap) {
|
||||
// Find similar types of `key1` and `key2` types
|
||||
const similarTypes1 = getSimilarTypes(allDefs, registry, storageEntry.type.asDoubleMap.key1.toString(), imports);
|
||||
const similarTypes2 = getSimilarTypes(allDefs, registry, storageEntry.type.asDoubleMap.key2.toString(), imports);
|
||||
const similarTypes1 = getSimilarTypes(registry, allDefs, storageEntry.type.asDoubleMap.key1.toString(), imports);
|
||||
const similarTypes2 = getSimilarTypes(registry, allDefs, storageEntry.type.asDoubleMap.key2.toString(), imports);
|
||||
|
||||
setImports(allDefs, imports, [
|
||||
...similarTypes1,
|
||||
|
||||
@@ -69,7 +69,7 @@ export function generateRpcTypes (importDefinitions: { [importPath: string]: Rec
|
||||
setImports(allDefs, imports, [def.type]);
|
||||
|
||||
args = def.params.map((param) => {
|
||||
const similarTypes = getSimilarTypes(definitions, registry, param.type, imports);
|
||||
const similarTypes = getSimilarTypes(registry, definitions, param.type, imports);
|
||||
|
||||
setImports(allDefs, imports, [param.type, ...similarTypes]);
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
|
||||
const params = args
|
||||
.map(({ name, type }) => {
|
||||
const typeStr = type.toString();
|
||||
const similarTypes = getSimilarTypes(allDefs, registry, typeStr, imports).map((type): string => formatType(allDefs, type, imports));
|
||||
const similarTypes = getSimilarTypes(registry, allDefs, typeStr, imports).map((type): string => formatType(allDefs, type, imports));
|
||||
const nameStr = mapName(name);
|
||||
|
||||
setImports(allDefs, imports, [...similarTypes.filter((type): boolean => !type.startsWith('(') && !type.startsWith('{')), typeStr]);
|
||||
|
||||
@@ -33,9 +33,9 @@ const voteConvictions = arrayToStrType(AllConvictions);
|
||||
|
||||
// From `T`, generate `Compact<T>, Option<T>, Vec<T>`
|
||||
/** @internal */
|
||||
export function getDerivedTypes (definitions: Record<string, ModuleTypes>, type: string, primitiveName: string, imports: TypeImports): string[] {
|
||||
export function getDerivedTypes (registry: Registry, definitions: Record<string, ModuleTypes>, type: string, primitiveName: string, imports: TypeImports): string[] {
|
||||
// `primitiveName` represents the actual primitive type our type is mapped to
|
||||
const isCompact = isCompactEncodable((primitiveClasses as Record<string, any>)[primitiveName]);
|
||||
const isCompact = isCompactEncodable((primitiveClasses as Record<string, any>)[primitiveName] || ClassOfUnsafe(registry, type));
|
||||
const def = getTypeDef(type);
|
||||
|
||||
setImports(definitions, imports, ['Option', 'Vec', isCompact ? 'Compact' : '']);
|
||||
@@ -72,7 +72,7 @@ export function getDerivedTypes (definitions: Record<string, ModuleTypes>, type:
|
||||
// - if param instanceof AbstractInt, then param: u64 | Uint8array | AnyNumber
|
||||
// etc
|
||||
/** @internal */
|
||||
export function getSimilarTypes (definitions: Record<string, ModuleTypes>, registry: Registry, _type: string, imports: TypeImports): string[] {
|
||||
export function getSimilarTypes (registry: Registry, definitions: Record<string, ModuleTypes>, _type: string, imports: TypeImports): string[] {
|
||||
const typeParts = _type.split('::');
|
||||
const type = typeParts[typeParts.length - 1];
|
||||
const possibleTypes = [type];
|
||||
@@ -97,10 +97,10 @@ export function getSimilarTypes (definitions: Record<string, ModuleTypes>, regis
|
||||
// this could be that we define a Vec type and refer to it by name
|
||||
if (subDef) {
|
||||
if (subDef.info === TypeDefInfo.Plain) {
|
||||
possibleTypes.push(`(${getSimilarTypes(definitions, registry, subDef.type, imports).join(' | ')})[]`);
|
||||
possibleTypes.push(`(${getSimilarTypes(registry, definitions, subDef.type, imports).join(' | ')})[]`);
|
||||
} else if (subDef.info === TypeDefInfo.Tuple) {
|
||||
const subs = (subDef.sub as TypeDef[]).map(({ type }): string =>
|
||||
getSimilarTypes(definitions, registry, type, imports).join(' | ')
|
||||
getSimilarTypes(registry, definitions, type, imports).join(' | ')
|
||||
);
|
||||
|
||||
possibleTypes.push(`([${subs.join(', ')}])[]`);
|
||||
@@ -149,7 +149,7 @@ export function getSimilarTypes (definitions: Record<string, ModuleTypes>, regis
|
||||
|
||||
// this could be that we define a Tuple type and refer to it by name
|
||||
if (Array.isArray(subDef)) {
|
||||
const subs = subDef.map(({ type }) => getSimilarTypes(definitions, registry, type, imports).join(' | '));
|
||||
const subs = subDef.map(({ type }) => getSimilarTypes(registry, definitions, type, imports).join(' | '));
|
||||
|
||||
possibleTypes.push(`[${subs.join(', ')}]`);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/types": "1.35.0-beta.8",
|
||||
"@polkadot/util": "^3.5.0-beta.12",
|
||||
"@polkadot/util": "^3.5.0-beta.13",
|
||||
"bn.js": "^5.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -28,15 +28,15 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/metadata": "1.35.0-beta.8",
|
||||
"@polkadot/util": "^3.5.0-beta.12",
|
||||
"@polkadot/util-crypto": "^3.5.0-beta.12",
|
||||
"@polkadot/util": "^3.5.0-beta.13",
|
||||
"@polkadot/util-crypto": "^3.5.0-beta.13",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^5.1.3",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.6.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.5.0-beta.12",
|
||||
"@polkadot/keyring": "^3.5.0-beta.13",
|
||||
"@types/memoizee": "^0.4.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +137,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<FixedI64>': Option<FixedI64>;
|
||||
'Vec<FixedI64>': Vec<FixedI64>;
|
||||
FixedU64: FixedU64;
|
||||
'Compact<FixedU64>': Compact<FixedU64>;
|
||||
'Option<FixedU64>': Option<FixedU64>;
|
||||
'Vec<FixedU64>': Vec<FixedU64>;
|
||||
Fixed128: Fixed128;
|
||||
@@ -146,12 +147,14 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<FixedI128>': Option<FixedI128>;
|
||||
'Vec<FixedI128>': Vec<FixedI128>;
|
||||
FixedU128: FixedU128;
|
||||
'Compact<FixedU128>': Compact<FixedU128>;
|
||||
'Option<FixedU128>': Option<FixedU128>;
|
||||
'Vec<FixedU128>': Vec<FixedU128>;
|
||||
I32F32: I32F32;
|
||||
'Option<I32F32>': Option<I32F32>;
|
||||
'Vec<I32F32>': Vec<I32F32>;
|
||||
U32F32: U32F32;
|
||||
'Compact<U32F32>': Compact<U32F32>;
|
||||
'Option<U32F32>': Option<U32F32>;
|
||||
'Vec<U32F32>': Vec<U32F32>;
|
||||
PerU16: PerU16;
|
||||
@@ -181,6 +184,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<AccountIdOf>': Option<AccountIdOf>;
|
||||
'Vec<AccountIdOf>': Vec<AccountIdOf>;
|
||||
AccountIndex: AccountIndex;
|
||||
'Compact<AccountIndex>': Compact<AccountIndex>;
|
||||
'Option<AccountIndex>': Option<AccountIndex>;
|
||||
'Vec<AccountIndex>': Vec<AccountIndex>;
|
||||
Address: Address;
|
||||
@@ -195,6 +199,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<Balance>': Option<Balance>;
|
||||
'Vec<Balance>': Vec<Balance>;
|
||||
BalanceOf: BalanceOf;
|
||||
'Compact<BalanceOf>': Compact<BalanceOf>;
|
||||
'Option<BalanceOf>': Option<BalanceOf>;
|
||||
'Vec<BalanceOf>': Vec<BalanceOf>;
|
||||
Block: Block;
|
||||
@@ -217,6 +222,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<ChangesTrieConfiguration>': Option<ChangesTrieConfiguration>;
|
||||
'Vec<ChangesTrieConfiguration>': Vec<ChangesTrieConfiguration>;
|
||||
ConsensusEngineId: ConsensusEngineId;
|
||||
'Compact<ConsensusEngineId>': Compact<ConsensusEngineId>;
|
||||
'Option<ConsensusEngineId>': Option<ConsensusEngineId>;
|
||||
'Vec<ConsensusEngineId>': Vec<ConsensusEngineId>;
|
||||
Digest: Digest;
|
||||
@@ -855,6 +861,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<SchedulePeriod>': Option<SchedulePeriod>;
|
||||
'Vec<SchedulePeriod>': Vec<SchedulePeriod>;
|
||||
SchedulePriority: SchedulePriority;
|
||||
'Compact<SchedulePriority>': Compact<SchedulePriority>;
|
||||
'Option<SchedulePriority>': Option<SchedulePriority>;
|
||||
'Vec<SchedulePriority>': Vec<SchedulePriority>;
|
||||
Scheduled: Scheduled;
|
||||
@@ -980,6 +987,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<KeyType>': Option<KeyType>;
|
||||
'Vec<KeyType>': Vec<KeyType>;
|
||||
MomentOf: MomentOf;
|
||||
'Compact<MomentOf>': Compact<MomentOf>;
|
||||
'Option<MomentOf>': Option<MomentOf>;
|
||||
'Vec<MomentOf>': Vec<MomentOf>;
|
||||
Nominations: Nominations;
|
||||
@@ -993,6 +1001,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<NominatorIndexCompact>': Option<NominatorIndexCompact>;
|
||||
'Vec<NominatorIndexCompact>': Vec<NominatorIndexCompact>;
|
||||
OffchainAccuracy: OffchainAccuracy;
|
||||
'Compact<OffchainAccuracy>': Compact<OffchainAccuracy>;
|
||||
'Option<OffchainAccuracy>': Option<OffchainAccuracy>;
|
||||
'Vec<OffchainAccuracy>': Vec<OffchainAccuracy>;
|
||||
OffchainAccuracyCompact: OffchainAccuracyCompact;
|
||||
@@ -1301,9 +1310,11 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<IncomingParachainDeploy>': Option<IncomingParachainDeploy>;
|
||||
'Vec<IncomingParachainDeploy>': Vec<IncomingParachainDeploy>;
|
||||
LeasePeriod: LeasePeriod;
|
||||
'Compact<LeasePeriod>': Compact<LeasePeriod>;
|
||||
'Option<LeasePeriod>': Option<LeasePeriod>;
|
||||
'Vec<LeasePeriod>': Vec<LeasePeriod>;
|
||||
LeasePeriodOf: LeasePeriodOf;
|
||||
'Compact<LeasePeriodOf>': Compact<LeasePeriodOf>;
|
||||
'Option<LeasePeriodOf>': Option<LeasePeriodOf>;
|
||||
'Vec<LeasePeriodOf>': Vec<LeasePeriodOf>;
|
||||
LocalValidationData: LocalValidationData;
|
||||
@@ -1329,6 +1340,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<ParaScheduling>': Option<ParaScheduling>;
|
||||
'Vec<ParaScheduling>': Vec<ParaScheduling>;
|
||||
RelayChainBlockNumber: RelayChainBlockNumber;
|
||||
'Compact<RelayChainBlockNumber>': Compact<RelayChainBlockNumber>;
|
||||
'Option<RelayChainBlockNumber>': Option<RelayChainBlockNumber>;
|
||||
'Vec<RelayChainBlockNumber>': Vec<RelayChainBlockNumber>;
|
||||
Remark: Remark;
|
||||
|
||||
@@ -13,10 +13,15 @@ export type UIntBitLength = 8 | 16 | 32 | 64 | 128 | 256;
|
||||
|
||||
export const DEFAULT_UINT_BITS = 64;
|
||||
|
||||
const PER_B = new BN(1_000_000_000);
|
||||
const PER_M = new BN(1_000_000);
|
||||
const MUL_P = new BN(1_00_00);
|
||||
|
||||
const FORMATTERS: [string, BN][] = [
|
||||
['Perquintill', new BN(1_000_000_000_000)],
|
||||
['Perbill', new BN(1_000_000_000)],
|
||||
['Permill', new BN(1_000_000)],
|
||||
['Percent', new BN(100)]
|
||||
];
|
||||
|
||||
function toPercentage (value: BN, divisor: BN): string {
|
||||
return `${(value.mul(MUL_P).div(divisor).toNumber() / 100).toFixed(2)}%`;
|
||||
}
|
||||
@@ -168,16 +173,19 @@ export default abstract class AbstractInt extends BN implements Codec {
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public toHuman (isExpanded?: boolean): string {
|
||||
// FIXME we need proper expansion here
|
||||
return this instanceof this.registry.createClass('Balance')
|
||||
? this.isMax()
|
||||
const rawType = this.toRawType();
|
||||
|
||||
if (rawType === 'Balance') {
|
||||
return this.isMax()
|
||||
? 'everything'
|
||||
: formatBalance(this, { decimals: this.registry.chainDecimals, withSi: true, withUnit: this.registry.chainToken })
|
||||
: this instanceof this.registry.createClass('Perbill')
|
||||
? toPercentage(this, PER_B)
|
||||
: this instanceof this.registry.createClass('Permill')
|
||||
? toPercentage(this, PER_M)
|
||||
: formatNumber(this);
|
||||
: formatBalance(this, { decimals: this.registry.chainDecimals, withSi: true, withUnit: this.registry.chainToken });
|
||||
}
|
||||
|
||||
const [, divisor] = FORMATTERS.find(([type]) => type === rawType) || [];
|
||||
|
||||
return divisor
|
||||
? toPercentage(this, divisor)
|
||||
: formatNumber(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -119,5 +119,12 @@ describe('UInt', (): void => {
|
||||
new (UInt.with(64, 'SomethingElse'))(registry).toRawType()
|
||||
).toEqual('SomethingElse');
|
||||
});
|
||||
|
||||
it('has proper toHuman() for PerMill/PerBill/Percent/Balance', (): void => {
|
||||
expect(registry.createType('Perbill', 12_340_000).toHuman()).toEqual('1.23%');
|
||||
expect(registry.createType('Percent', 12).toHuman()).toEqual('12.00%');
|
||||
expect(registry.createType('Permill', 16_900).toHuman()).toEqual('1.69%');
|
||||
expect(registry.createType('Balance', '123456789012345').toHuman()).toEqual('123.456 Unit');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,11 +15,11 @@ const numberTypes = {
|
||||
FixedU128: 'UInt<128, FixedU128>',
|
||||
I32F32: 'Int<64, I32F32>',
|
||||
U32F32: 'UInt<64, U32F32>',
|
||||
PerU16: 'u16',
|
||||
Perbill: 'u32',
|
||||
Percent: 'u8',
|
||||
Permill: 'u32',
|
||||
Perquintill: 'u64'
|
||||
PerU16: 'UInt<16, PerU16>',
|
||||
Perbill: 'UInt<32, Perbill>',
|
||||
Percent: 'UInt<8, Percent>',
|
||||
Permill: 'UInt<32, Permill>',
|
||||
Perquintill: 'UInt<64, Perquintill>'
|
||||
};
|
||||
|
||||
export default {
|
||||
@@ -31,7 +31,7 @@ export default {
|
||||
AccountIndex: 'GenericAccountIndex',
|
||||
Address: 'GenericAddress',
|
||||
AssetId: 'u32',
|
||||
Balance: 'u128',
|
||||
Balance: 'UInt<128, Balance>',
|
||||
BalanceOf: 'Balance',
|
||||
Block: 'GenericBlock',
|
||||
BlockNumber: 'u32',
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
import { Compact, Enum, Int, Struct, U8aFixed, UInt, Vec } from '@polkadot/types/codec';
|
||||
import { GenericAccountId, GenericAccountIndex, GenericBlock, GenericCall, GenericConsensusEngineId, GenericLookupSource } from '@polkadot/types/generic';
|
||||
import { Bytes, DoNotConstruct, Null, StorageKey, u128, u16, u32, u64, u8 } from '@polkadot/types/primitive';
|
||||
import { Bytes, DoNotConstruct, Null, StorageKey, u32, u64 } from '@polkadot/types/primitive';
|
||||
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
|
||||
import { Signature } from '@polkadot/types/interfaces/extrinsics';
|
||||
|
||||
@@ -24,7 +24,7 @@ export interface Address extends GenericAddress {}
|
||||
export interface AssetId extends u32 {}
|
||||
|
||||
/** @name Balance */
|
||||
export interface Balance extends u128 {}
|
||||
export interface Balance extends UInt {}
|
||||
|
||||
/** @name BalanceOf */
|
||||
export interface BalanceOf extends Balance {}
|
||||
@@ -170,19 +170,19 @@ export interface Pays extends Enum {
|
||||
}
|
||||
|
||||
/** @name Perbill */
|
||||
export interface Perbill extends u32 {}
|
||||
export interface Perbill extends UInt {}
|
||||
|
||||
/** @name Percent */
|
||||
export interface Percent extends u8 {}
|
||||
export interface Percent extends UInt {}
|
||||
|
||||
/** @name Permill */
|
||||
export interface Permill extends u32 {}
|
||||
export interface Permill extends UInt {}
|
||||
|
||||
/** @name Perquintill */
|
||||
export interface Perquintill extends u64 {}
|
||||
export interface Perquintill extends UInt {}
|
||||
|
||||
/** @name PerU16 */
|
||||
export interface PerU16 extends u16 {}
|
||||
export interface PerU16 extends UInt {}
|
||||
|
||||
/** @name Phantom */
|
||||
export interface Phantom extends Null {}
|
||||
|
||||
@@ -2759,7 +2759,7 @@ __metadata:
|
||||
"@polkadot/api": 1.35.0-beta.8
|
||||
"@polkadot/rpc-core": 1.35.0-beta.8
|
||||
"@polkadot/types": 1.35.0-beta.8
|
||||
"@polkadot/util": ^3.5.0-beta.12
|
||||
"@polkadot/util": ^3.5.0-beta.13
|
||||
bn.js: ^5.1.3
|
||||
rxjs: ^6.6.3
|
||||
languageName: unknown
|
||||
@@ -2771,12 +2771,12 @@ __metadata:
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.11.2
|
||||
"@polkadot/api": 1.35.0-beta.8
|
||||
"@polkadot/keyring": ^3.5.0-beta.12
|
||||
"@polkadot/keyring": ^3.5.0-beta.13
|
||||
"@polkadot/rpc-core": 1.35.0-beta.8
|
||||
"@polkadot/rpc-provider": 1.35.0-beta.8
|
||||
"@polkadot/types": 1.35.0-beta.8
|
||||
"@polkadot/util": ^3.5.0-beta.12
|
||||
"@polkadot/util-crypto": ^3.5.0-beta.12
|
||||
"@polkadot/util": ^3.5.0-beta.13
|
||||
"@polkadot/util-crypto": ^3.5.0-beta.13
|
||||
bn.js: ^5.1.3
|
||||
memoizee: ^0.4.14
|
||||
rxjs: ^6.6.3
|
||||
@@ -2789,14 +2789,14 @@ __metadata:
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.11.2
|
||||
"@polkadot/api-derive": 1.35.0-beta.8
|
||||
"@polkadot/keyring": ^3.5.0-beta.12
|
||||
"@polkadot/keyring": ^3.5.0-beta.13
|
||||
"@polkadot/metadata": 1.35.0-beta.8
|
||||
"@polkadot/rpc-core": 1.35.0-beta.8
|
||||
"@polkadot/rpc-provider": 1.35.0-beta.8
|
||||
"@polkadot/types": 1.35.0-beta.8
|
||||
"@polkadot/types-known": 1.35.0-beta.8
|
||||
"@polkadot/util": ^3.5.0-beta.12
|
||||
"@polkadot/util-crypto": ^3.5.0-beta.12
|
||||
"@polkadot/util": ^3.5.0-beta.13
|
||||
"@polkadot/util-crypto": ^3.5.0-beta.13
|
||||
bn.js: ^5.1.3
|
||||
eventemitter3: ^4.0.7
|
||||
rxjs: ^6.6.3
|
||||
@@ -2899,14 +2899,14 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/keyring@npm:^3.5.0-beta.12":
|
||||
version: 3.5.0-beta.12
|
||||
resolution: "@polkadot/keyring@npm:3.5.0-beta.12"
|
||||
"@polkadot/keyring@npm:^3.5.0-beta.13":
|
||||
version: 3.5.0-beta.13
|
||||
resolution: "@polkadot/keyring@npm:3.5.0-beta.13"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.11.2
|
||||
"@polkadot/util": 3.5.0-beta.12
|
||||
"@polkadot/util-crypto": 3.5.0-beta.12
|
||||
checksum: 63a1d8cff1f982b4936e6bfb1d8b98920f6f47924f0b231de63d419d3974f31dd8a34716f444837647564bde44a332495ae66b806f4439fc661ff7ac72f8b47c
|
||||
"@polkadot/util": 3.5.0-beta.13
|
||||
"@polkadot/util-crypto": 3.5.0-beta.13
|
||||
checksum: bbdeaa9e334d271c882e14368403b9e460a37d34e7f086ed104d7df0c8fdd10eb152223f4e43e761cd0e63b058bf616b4e37fd25284c66a39fd7a23686b773ca
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2915,11 +2915,11 @@ __metadata:
|
||||
resolution: "@polkadot/metadata@workspace:packages/metadata"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.11.2
|
||||
"@polkadot/keyring": ^3.5.0-beta.12
|
||||
"@polkadot/keyring": ^3.5.0-beta.13
|
||||
"@polkadot/types": 1.35.0-beta.8
|
||||
"@polkadot/types-known": 1.35.0-beta.8
|
||||
"@polkadot/util": ^3.5.0-beta.12
|
||||
"@polkadot/util-crypto": ^3.5.0-beta.12
|
||||
"@polkadot/util": ^3.5.0-beta.13
|
||||
"@polkadot/util-crypto": ^3.5.0-beta.13
|
||||
bn.js: ^5.1.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
@@ -2929,11 +2929,11 @@ __metadata:
|
||||
resolution: "@polkadot/rpc-core@workspace:packages/rpc-core"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.11.2
|
||||
"@polkadot/keyring": ^3.5.0-beta.12
|
||||
"@polkadot/keyring": ^3.5.0-beta.13
|
||||
"@polkadot/metadata": 1.35.0-beta.8
|
||||
"@polkadot/rpc-provider": 1.35.0-beta.8
|
||||
"@polkadot/types": 1.35.0-beta.8
|
||||
"@polkadot/util": ^3.5.0-beta.12
|
||||
"@polkadot/util": ^3.5.0-beta.13
|
||||
memoizee: ^0.4.14
|
||||
rxjs: ^6.6.3
|
||||
languageName: unknown
|
||||
@@ -2944,11 +2944,11 @@ __metadata:
|
||||
resolution: "@polkadot/rpc-provider@workspace:packages/rpc-provider"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.11.2
|
||||
"@polkadot/keyring": ^3.5.0-beta.12
|
||||
"@polkadot/keyring": ^3.5.0-beta.13
|
||||
"@polkadot/metadata": 1.35.0-beta.8
|
||||
"@polkadot/types": 1.35.0-beta.8
|
||||
"@polkadot/util": ^3.5.0-beta.12
|
||||
"@polkadot/util-crypto": ^3.5.0-beta.12
|
||||
"@polkadot/util": ^3.5.0-beta.13
|
||||
"@polkadot/util-crypto": ^3.5.0-beta.13
|
||||
"@polkadot/x-fetch": ^0.3.2
|
||||
"@polkadot/x-ws": ^0.3.2
|
||||
bn.js: ^5.1.3
|
||||
@@ -2978,7 +2978,7 @@ __metadata:
|
||||
"@polkadot/metadata": 1.35.0-beta.8
|
||||
"@polkadot/rpc-provider": 1.35.0-beta.8
|
||||
"@polkadot/types": 1.35.0-beta.8
|
||||
"@polkadot/util": ^3.5.0-beta.12
|
||||
"@polkadot/util": ^3.5.0-beta.13
|
||||
"@types/websocket": ^1.0.1
|
||||
"@types/yargs": ^15.0.7
|
||||
handlebars: ^4.7.6
|
||||
@@ -2999,7 +2999,7 @@ __metadata:
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.11.2
|
||||
"@polkadot/types": 1.35.0-beta.8
|
||||
"@polkadot/util": ^3.5.0-beta.12
|
||||
"@polkadot/util": ^3.5.0-beta.13
|
||||
"@types/bn.js": ^4.11.6
|
||||
bn.js: ^5.1.3
|
||||
languageName: unknown
|
||||
@@ -3010,10 +3010,10 @@ __metadata:
|
||||
resolution: "@polkadot/types@workspace:packages/types"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.11.2
|
||||
"@polkadot/keyring": ^3.5.0-beta.12
|
||||
"@polkadot/keyring": ^3.5.0-beta.13
|
||||
"@polkadot/metadata": 1.35.0-beta.8
|
||||
"@polkadot/util": ^3.5.0-beta.12
|
||||
"@polkadot/util-crypto": ^3.5.0-beta.12
|
||||
"@polkadot/util": ^3.5.0-beta.13
|
||||
"@polkadot/util-crypto": ^3.5.0-beta.13
|
||||
"@types/bn.js": ^4.11.6
|
||||
"@types/memoizee": ^0.4.4
|
||||
bn.js: ^5.1.3
|
||||
@@ -3022,12 +3022,12 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/util-crypto@npm:3.5.0-beta.12, @polkadot/util-crypto@npm:^3.5.0-beta.12":
|
||||
version: 3.5.0-beta.12
|
||||
resolution: "@polkadot/util-crypto@npm:3.5.0-beta.12"
|
||||
"@polkadot/util-crypto@npm:3.5.0-beta.13, @polkadot/util-crypto@npm:^3.5.0-beta.13":
|
||||
version: 3.5.0-beta.13
|
||||
resolution: "@polkadot/util-crypto@npm:3.5.0-beta.13"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.11.2
|
||||
"@polkadot/util": 3.5.0-beta.12
|
||||
"@polkadot/util": 3.5.0-beta.13
|
||||
"@polkadot/wasm-crypto": ^1.4.1
|
||||
base-x: ^3.0.8
|
||||
bip39: ^3.0.2
|
||||
@@ -3039,13 +3039,13 @@ __metadata:
|
||||
scryptsy: ^2.1.0
|
||||
tweetnacl: ^1.0.3
|
||||
xxhashjs: ^0.2.2
|
||||
checksum: f366a1826fd05e4396e1adb97353b0bf18a26cb94c7786115c7096f735e528db56fa83b106e3785cd1672c6c44cda3bb4d1c03046d8416c7ee1a7196be6e8800
|
||||
checksum: db9222d3b067f349ec9ee711af115be5e035c4b7a30e9b11f9f2a26b0ecc17d38f79f15896ec9f7445475c7cfa0a8b78170f1d8bd55bdfaadfa03c8ada4f778c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/util@npm:3.5.0-beta.12, @polkadot/util@npm:^3.5.0-beta.12":
|
||||
version: 3.5.0-beta.12
|
||||
resolution: "@polkadot/util@npm:3.5.0-beta.12"
|
||||
"@polkadot/util@npm:3.5.0-beta.13, @polkadot/util@npm:^3.5.0-beta.13":
|
||||
version: 3.5.0-beta.13
|
||||
resolution: "@polkadot/util@npm:3.5.0-beta.13"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.11.2
|
||||
"@polkadot/x-textdecoder": ^0.3.2
|
||||
@@ -3055,7 +3055,7 @@ __metadata:
|
||||
camelcase: ^5.3.1
|
||||
chalk: ^4.1.0
|
||||
ip-regex: ^4.1.0
|
||||
checksum: ad4513479c9b9ed20cb06eae999663c98b1fddf7c2116d7c57d02d722264cb8be100561aa9a2bd6c12cde1f464e4c410f9f1a3d8a1a4c7c1696e35e68c9f7b4d
|
||||
checksum: c720fa6410a8b7e8771bb12f39eab703f49b207fc19a8c654d455381594f6bd22151d7193fc74a6177622f47bfc6a20122823d94a3ea10ed2606b6d42f0ba88b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in New Issue
Block a user