Update metadata to latest (Amount & AssetOf types) (#726)
* Update metadata to latest (Amount & AssetOf types) * Allow derive fees to work with fees module
This commit is contained in:
@@ -18,7 +18,7 @@ describe('Metadata', () => {
|
||||
const str = JSON.stringify(metadata.toJSON());
|
||||
|
||||
console.error(str);
|
||||
console.error(metadata.getUniqTypes());
|
||||
console.error(metadata.getUniqTypes(true));
|
||||
|
||||
expect(metadata.version).toBe(1);
|
||||
expect(metadata.asV1.modules.length).not.toBe(0);
|
||||
@@ -30,7 +30,7 @@ describe('Metadata', () => {
|
||||
|
||||
// console.error(JSON.stringify(v0.toJSON()));
|
||||
|
||||
expect(metadata.getUniqTypes()).toEqual(v0.getUniqTypes());
|
||||
expect(metadata.getUniqTypes(true)).toEqual(v0.getUniqTypes(true));
|
||||
});
|
||||
|
||||
describe('storage with default values', () => {
|
||||
|
||||
@@ -106,7 +106,7 @@ export default class MetadataVersioned extends Struct implements MetadataInterfa
|
||||
return this.metadata.asV1;
|
||||
}
|
||||
|
||||
getUniqTypes (): Array<string> {
|
||||
return (this.metadata.value as any as MetadataInterface).getUniqTypes();
|
||||
getUniqTypes (throwError: boolean): Array<string> {
|
||||
return (this.metadata.value as any as MetadataInterface).getUniqTypes(throwError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export interface MetadataInterface {
|
||||
getUniqTypes (): Array<string>;
|
||||
getUniqTypes (throwError: boolean): Array<string>;
|
||||
}
|
||||
|
||||
@@ -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 { assert, isUndefined } from '@polkadot/util';
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
|
||||
import { getTypeDef, TypeDef, TypeDefInfo } from '../../codec/createType';
|
||||
import flattenUniq from './flattenUniq';
|
||||
|
||||
export default function validateTypes (types: Array<string>): void {
|
||||
export default function validateTypes (types: Array<string>, throwError: boolean): void {
|
||||
const extractTypes = (types: Array<string>): Array<any> => {
|
||||
return types.map((type) => {
|
||||
const decoded = getTypeDef(type);
|
||||
@@ -37,5 +37,13 @@ export default function validateTypes (types: Array<string>): void {
|
||||
isUndefined(allTypes[type])
|
||||
);
|
||||
|
||||
assert(missing.length === 0, `Unknown types found, no types for ${missing}`);
|
||||
if (missing.length !== 0) {
|
||||
const message = `Unknown types found, no types for ${missing}`;
|
||||
|
||||
if (throwError) {
|
||||
throw new Error(message);
|
||||
} else {
|
||||
console.error(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('Metadata', () => {
|
||||
const str = JSON.stringify(metadata.toJSON());
|
||||
|
||||
console.error(str);
|
||||
console.error(metadata.getUniqTypes());
|
||||
console.error(metadata.getUniqTypes(true));
|
||||
|
||||
expect(metadata.events.length).not.toBe(0);
|
||||
expect(str).toEqual(JSON.stringify(latestParsed));
|
||||
|
||||
@@ -106,10 +106,10 @@ export default class MetadataV0 extends Struct implements MetadataInterface {
|
||||
/**
|
||||
* @description Helper to retrieve a list of all type that are found, sorted and de-deuplicated
|
||||
*/
|
||||
getUniqTypes (): Array<string> {
|
||||
getUniqTypes (throwError: boolean): Array<string> {
|
||||
const types = flattenUniq([this.argNames, this.eventNames, this.storageNames]);
|
||||
|
||||
validateTypes(types);
|
||||
validateTypes(types, throwError);
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
@@ -120,10 +120,10 @@ export default class MetadataV1 extends Struct implements MetadataInterface {
|
||||
/**
|
||||
* @description Helper to retrieve a list of all type that are found, sorted and de-deuplicated
|
||||
*/
|
||||
getUniqTypes (): Array<string> {
|
||||
getUniqTypes (throwError: boolean): Array<string> {
|
||||
const types = flattenUniq([this.callNames, this.eventNames, this.storageNames]);
|
||||
|
||||
validateTypes(types);
|
||||
validateTypes(types, throwError);
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
@@ -451,28 +451,6 @@
|
||||
" `system::AccountNonce` is also deleted if `FreeBalance` is also zero (it also gets",
|
||||
" collapsed to zero if it ever becomes less than `ExistentialDeposit`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "TransactionBaseFee",
|
||||
"modifier": "Default",
|
||||
"type": {
|
||||
"PlainType": "Balance"
|
||||
},
|
||||
"fallback": "0x00000000000000000000000000000000",
|
||||
"docs": [
|
||||
" The fee to be paid for making a transaction; the base."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "TransactionByteFee",
|
||||
"modifier": "Default",
|
||||
"type": {
|
||||
"PlainType": "Balance"
|
||||
},
|
||||
"fallback": "0x00000000000000000000000000000000",
|
||||
"docs": [
|
||||
" The fee to be paid for making a transaction; the per-byte portion."
|
||||
]
|
||||
}
|
||||
],
|
||||
"calls": [
|
||||
@@ -2837,6 +2815,64 @@
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "fees",
|
||||
"prefix": "Fees",
|
||||
"storage": [
|
||||
{
|
||||
"name": "TransactionBaseFee",
|
||||
"modifier": "Default",
|
||||
"type": {
|
||||
"PlainType": "AssetOf"
|
||||
},
|
||||
"fallback": "0x00000000000000000000000000000000",
|
||||
"docs": [
|
||||
" The fee to be paid for making a transaction; the base."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "TransactionByteFee",
|
||||
"modifier": "Default",
|
||||
"type": {
|
||||
"PlainType": "AssetOf"
|
||||
},
|
||||
"fallback": "0x00000000000000000000000000000000",
|
||||
"docs": [
|
||||
" The fee to be paid for making a transaction; the per-byte portion."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CurrentTransactionFee",
|
||||
"modifier": "Default",
|
||||
"type": {
|
||||
"MapType": {
|
||||
"key": "u32",
|
||||
"value": "AssetOf"
|
||||
}
|
||||
},
|
||||
"fallback": "0x00000000000000000000000000000000",
|
||||
"docs": [
|
||||
" The `extrinsic_index => accumulated_fees` map, containing records to",
|
||||
" track the overall charged fees for each transaction.",
|
||||
"",
|
||||
" All records should be removed at finalise stage."
|
||||
]
|
||||
}
|
||||
],
|
||||
"calls": null,
|
||||
"events": [
|
||||
{
|
||||
"name": "Charged",
|
||||
"args": [
|
||||
"u32",
|
||||
"Amount"
|
||||
],
|
||||
"docs": [
|
||||
" Fee charged (extrinsic_index, fee_amount)"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,13 @@
|
||||
// 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 Balance from './Balance';
|
||||
|
||||
/**
|
||||
* @name Amount
|
||||
* @description
|
||||
* The Substrate Amount representation as a [[Balance]].
|
||||
*/
|
||||
export default class Amount extends Balance {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// 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 Balance from './Balance';
|
||||
|
||||
/**
|
||||
* @name AssetOf
|
||||
* @description
|
||||
* The Substrate AssetOf representation as a [[Balance]].
|
||||
*/
|
||||
export default class AssetOf extends Balance {
|
||||
}
|
||||
@@ -11,6 +11,8 @@
|
||||
export { default as AccountId, AccountIdOf } from './AccountId';
|
||||
export { default as AccountIndex } from './AccountIndex';
|
||||
export { default as Address } from './Address';
|
||||
export { default as Amount } from './Amount';
|
||||
export { default as AssetOf } from './AssetOf';
|
||||
export { default as AttestedCandidate } from './AttestedCandidate';
|
||||
export { default as AuthorityId } from './AuthorityId';
|
||||
export { default as Balance, BalanceOf } from './Balance';
|
||||
|
||||
Reference in New Issue
Block a user