Update types parsing to latest metadata (#456)

* Remove useless whitespaces

* Update latest metadata

* Update latest metadata
This commit is contained in:
Amaury Martiny
2018-12-10 13:46:58 +00:00
committed by GitHub
parent 70bd74765f
commit 0c947a5905
4 changed files with 36 additions and 22 deletions
+13 -13
View File
@@ -1391,7 +1391,7 @@
{
"name": "PublicProps",
"modifier": 1,
"type": "Vec<(PropIndex, Proposal, AccountId)>",
"type": "Vec<(PropIndex,Proposal,AccountId)>",
"documentation": [
" The public proposals. Unsorted."
]
@@ -1401,7 +1401,7 @@
"modifier": 0,
"type": {
"key": "PropIndex",
"value": "(Balance, Vec<AccountId>)"
"value": "(Balance,Vec<AccountId>)"
},
"documentation": [
" Those who have locked a deposit."
@@ -1452,7 +1452,7 @@
"modifier": 0,
"type": {
"key": "ReferendumIndex",
"value": "(BlockNumber, Proposal, VoteThreshold)"
"value": "(BlockNumber,Proposal,VoteThreshold)"
},
"documentation": [
" Information concerning any given referendum."
@@ -1473,7 +1473,7 @@
"name": "VoteOf",
"modifier": 0,
"type": {
"key": "(ReferendumIndex, AccountId)",
"key": "( ReferendumIndex , AccountId )",
"value": "bool"
},
"documentation": [
@@ -1728,7 +1728,7 @@
{
"name": "ActiveCouncil",
"modifier": 1,
"type": "Vec<(AccountId, BlockNumber)>",
"type": "Vec<(AccountId,BlockNumber)>",
"documentation": [
" The current council. When there's a vote going on, this should still be used for executive",
" matters."
@@ -1758,7 +1758,7 @@
"modifier": 0,
"type": {
"key": "AccountId",
"value": "(VoteIndex, u32)"
"value": "(VoteIndex,u32)"
},
"documentation": [
" The vote index and list slot that the candidate `who` was registered or `None` if they are not",
@@ -1801,7 +1801,7 @@
{
"name": "NextFinalise",
"modifier": 0,
"type": "(BlockNumber, u32, Vec<AccountId>)",
"type": "(BlockNumber,u32,Vec<AccountId>)",
"documentation": [
" The accounts holding the seats that will become free on the next tally."
]
@@ -1817,7 +1817,7 @@
{
"name": "Leaderboard",
"modifier": 0,
"type": "Vec<(Balance, AccountId)>",
"type": "Vec<(Balance,AccountId)>",
"documentation": [
" Get the leaderboard if we;re in the presentation phase."
]
@@ -1912,7 +1912,7 @@
{
"name": "Proposals",
"modifier": 1,
"type": "Vec<(BlockNumber, Hash)>",
"type": "Vec<(BlockNumber,Hash)>",
"documentation": []
},
{
@@ -1937,7 +1937,7 @@
"name": "CouncilVoteOf",
"modifier": 0,
"type": {
"key": "(Hash, AccountId)",
"key": "( Hash , AccountId )",
"value": "bool"
},
"documentation": []
@@ -1947,7 +1947,7 @@
"modifier": 0,
"type": {
"key": "Hash",
"value": "(BlockNumber, Vec<AccountId>)"
"value": "(BlockNumber,Vec<AccountId>)"
},
"documentation": []
}
@@ -2025,7 +2025,7 @@
"modifier": 0,
"type": {
"key": "Hash",
"value": "(ProposalIndex, u32, Vec<AccountId>, Vec<AccountId>)"
"value": "(ProposalIndex,u32,Vec<AccountId>,Vec<AccountId>)"
},
"documentation": [
" Votes for a given proposal: (required_yes_votes, yes_voters, no_voters)."
@@ -2431,4 +2431,4 @@
}
]
}
}
}
+6
View File
@@ -30,6 +30,12 @@ describe('Type', () => {
).toEqual('(Bytes, AccountId, Bytes)');
});
it('removes whitespaces', () => {
expect(
new Type('T :: AccountId').toString()
).toEqual('AccountId');
});
it('changes PairOf<T> -> (T, T)', () => {
expect(
new Type('PairOf<T::Balance>').toString()
+12 -8
View File
@@ -37,21 +37,21 @@ export default class Type extends Text {
private static decodeType (value: string): string {
const mappings: Array<Mapper> = [
// <T::Balance as HasCompact>
this._cleanupCompact(),
Type._cleanupCompact(),
// Remove all the trait prefixes
this._removeTraits(),
Type._removeTraits(),
// remove PairOf<T> -> (T, T)
this._removePairOf(),
Type._removePairOf(),
// remove boxing, `Box<Proposal>` -> `Proposal`
this._removeWrap('Box'),
Type._removeWrap('Box'),
// remove generics, `MisbehaviorReport<Hash, BlockNumber>` -> `MisbehaviorReport`
this._removeGenerics(),
Type._removeGenerics(),
// alias String -> Text (compat with jsonrpc methods)
this._alias('String', 'Text'),
Type._alias('String', 'Text'),
// alias Vec<u8> -> Bytes
this._alias('Vec<u8>', 'Bytes'),
Type._alias('Vec<u8>', 'Bytes'),
// alias RawAddress -> Address
this._alias('RawAddress', 'Address')
Type._alias('RawAddress', 'Address')
// TODO Check these for possibly matching -
// `PropIndex` -> `ProposalIndex` (implementation looks the same, however meant as diff)
];
@@ -172,12 +172,16 @@ export default class Type extends Text {
private static _removeTraits (): Mapper {
return (value: string): string => {
return value
// `T :: AccountId` -> `T::AccountId` https://github.com/paritytech/substrate/issues/1244
.replace(/\s+::\s+/g, '::')
// anything `T::<type>` to end up as `<type>`
.replace(/T::/g, '')
// `system::` with `` - basically we find `<T as system::Trait>`
.replace(/system::/g, '')
// replace `<T as Trait>::` (possibly sanitised just above)
.replace(/<T as Trait>::/g, '')
// `<TasTrait>::type` -> `type` https://github.com/paritytech/substrate/issues/1244
.replace(/<TasTrait>::/g, '')
// replace `<...>::Type`
.replace(/::Type/g, '');
};
File diff suppressed because one or more lines are too long