Cleanup CompactAssignments (alignment) (#1917)

* Cleanup CompactAssignments (alignment)

* Remove CompactAssignment

* Add CompactScore
This commit is contained in:
Jaco Greeff
2020-02-21 13:33:21 +01:00
committed by GitHub
parent 877aa33efa
commit 2de9317b30
4 changed files with 72 additions and 33 deletions
+4 -1
View File
@@ -24,7 +24,7 @@ import { Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter }
import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
import { FullIdentification, IdentificationTuple, Keys, SessionIndex, SessionKeys1, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6 } from '@polkadot/types/interfaces/session';
import { Bid, BidKind, BidKindVouch, SocietyJudgement, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
import { CompactAssignments, ElectionCompute, ElectionResult, ElectionStatus, EraIndex, EraPoints, EraRewards, Exposure, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, PhragmenScore, Points, RewardDestination, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking';
import { CompactAssignments, CompactScore, ElectionCompute, ElectionResult, ElectionStatus, EraIndex, EraPoints, EraRewards, Exposure, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, PhragmenScore, Points, RewardDestination, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking';
import { AccountInfo, DigestOf, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, EventRecordTo76, Key, Phase, RefCount } from '@polkadot/types/interfaces/system';
import { OpenTip, OpenTipFinder, OpenTipTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
@@ -727,6 +727,9 @@ export interface InterfaceRegistry {
CompactAssignments: CompactAssignments;
'Option<CompactAssignments>': Option<CompactAssignments>;
'Vec<CompactAssignments>': Vec<CompactAssignments>;
CompactScore: CompactScore;
'Option<CompactScore>': Option<CompactScore>;
'Vec<CompactScore>': Vec<CompactScore>;
ElectionCompute: ElectionCompute;
'Option<ElectionCompute>': Option<ElectionCompute>;
'Vec<ElectionCompute>': Vec<ElectionCompute>;
@@ -0,0 +1,32 @@
// Copyright 2017-2020 @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 { TypeRegistry, createType, createTypeUnsafe } from '../../create';
describe('CompactAssignments', (): void => {
const registry = new TypeRegistry();
const votes2 = [['5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', [['5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y', 123456]], '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty']];
const test = createType(registry, 'CompactAssignments', {
votes1: [['5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', [], '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty']],
votes2
});
it('has a valid vote1 ([Type; <number>] equivalency)', (): void => {
expect(test.votes1.toHex()).toEqual(
createTypeUnsafe(registry, 'Vec<(AccountId, AccountId)>', [[
['5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty']
]]).toHex()
);
});
it('hash valid vot2 (actual tuple values)', (): void => {
expect(test.votes2.toHex()).toEqual(
createTypeUnsafe(registry, 'Vec<(AccountId, [(AccountId, u128); 1], AccountId)>', [votes2]).toHex()
);
});
it('has a proper decoded toHuman() available', (): void => {
expect(test.votes2.toHuman()).toEqual([['5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', [['5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y', '123,456']], '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty']]);
});
});
@@ -5,23 +5,24 @@
export default {
types: {
CompactAssignments: {
votes1: 'Vec<(AccountId, AccountId)>',
votes2: 'Vec<(AccountId, (AccountId, u128), AccountId)>',
votes3: 'Vec<(AccountId, [(AccountId, u128); 2], AccountId)>',
votes4: 'Vec<(AccountId, [(AccountId, u128); 3], AccountId)>',
votes5: 'Vec<(AccountId, [(AccountId, u128); 4], AccountId)>',
votes6: 'Vec<(AccountId, [(AccountId, u128); 5], AccountId)>',
votes7: 'Vec<(AccountId, [(AccountId, u128); 6], AccountId)>',
votes8: 'Vec<(AccountId, [(AccountId, u128); 7], AccountId)>',
votes9: 'Vec<(AccountId, [(AccountId, u128); 8], AccountId)>',
votes10: 'Vec<(AccountId, [(AccountId, u128); 9], AccountId)>',
votes11: 'Vec<(AccountId, [(AccountId, u128); 10], AccountId)>',
votes12: 'Vec<(AccountId, [(AccountId, u128); 11], AccountId)>',
votes13: 'Vec<(AccountId, [(AccountId, u128); 12], AccountId)>',
votes14: 'Vec<(AccountId, [(AccountId, u128); 13], AccountId)>',
votes15: 'Vec<(AccountId, [(AccountId, u128); 14], AccountId)>',
votes16: 'Vec<(AccountId, [(AccountId, u128); 15], AccountId)>',
votes1: 'Vec<(AccountId, [CompactScore; 0], AccountId)>',
votes2: 'Vec<(AccountId, [CompactScore; 1], AccountId)>',
votes3: 'Vec<(AccountId, [CompactScore; 2], AccountId)>',
votes4: 'Vec<(AccountId, [CompactScore; 3], AccountId)>',
votes5: 'Vec<(AccountId, [CompactScore; 4], AccountId)>',
votes6: 'Vec<(AccountId, [CompactScore; 5], AccountId)>',
votes7: 'Vec<(AccountId, [CompactScore; 6], AccountId)>',
votes8: 'Vec<(AccountId, [CompactScore; 7], AccountId)>',
votes9: 'Vec<(AccountId, [CompactScore; 8], AccountId)>',
votes10: 'Vec<(AccountId, [CompactScore; 9], AccountId)>',
votes11: 'Vec<(AccountId, [CompactScore; 10], AccountId)>',
votes12: 'Vec<(AccountId, [CompactScore; 11], AccountId)>',
votes13: 'Vec<(AccountId, [CompactScore; 12], AccountId)>',
votes14: 'Vec<(AccountId, [CompactScore; 13], AccountId)>',
votes15: 'Vec<(AccountId, [CompactScore; 14], AccountId)>',
votes16: 'Vec<(AccountId, [CompactScore; 15], AccountId)>'
},
CompactScore: '(AccountId, u128)',
ElectionCompute: {
_enum: ['OnChain', 'Signed', 'Authority']
},
+19 -16
View File
@@ -8,24 +8,27 @@ import { AccountId, Balance, BlockNumber, Moment, Perbill } from '@polkadot/type
/** @name CompactAssignments */
export interface CompactAssignments extends Struct {
readonly votes1: Vec<ITuple<[AccountId, AccountId]>>;
readonly votes2: Vec<ITuple<[AccountId, ITuple<[AccountId, u128]>, AccountId]>>;
readonly votes3: Vec<ITuple<[AccountId, Vec<ITuple<[AccountId, u128]>>, AccountId]>>;
readonly votes4: Vec<ITuple<[AccountId, Vec<ITuple<[AccountId, u128]>>, AccountId]>>;
readonly votes5: Vec<ITuple<[AccountId, Vec<ITuple<[AccountId, u128]>>, AccountId]>>;
readonly votes6: Vec<ITuple<[AccountId, Vec<ITuple<[AccountId, u128]>>, AccountId]>>;
readonly votes7: Vec<ITuple<[AccountId, Vec<ITuple<[AccountId, u128]>>, AccountId]>>;
readonly votes8: Vec<ITuple<[AccountId, Vec<ITuple<[AccountId, u128]>>, AccountId]>>;
readonly votes9: Vec<ITuple<[AccountId, Vec<ITuple<[AccountId, u128]>>, AccountId]>>;
readonly votes10: Vec<ITuple<[AccountId, Vec<ITuple<[AccountId, u128]>>, AccountId]>>;
readonly votes11: Vec<ITuple<[AccountId, Vec<ITuple<[AccountId, u128]>>, AccountId]>>;
readonly votes12: Vec<ITuple<[AccountId, Vec<ITuple<[AccountId, u128]>>, AccountId]>>;
readonly votes13: Vec<ITuple<[AccountId, Vec<ITuple<[AccountId, u128]>>, AccountId]>>;
readonly votes14: Vec<ITuple<[AccountId, Vec<ITuple<[AccountId, u128]>>, AccountId]>>;
readonly votes15: Vec<ITuple<[AccountId, Vec<ITuple<[AccountId, u128]>>, AccountId]>>;
readonly votes16: Vec<ITuple<[AccountId, Vec<ITuple<[AccountId, u128]>>, AccountId]>>;
readonly votes1: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes2: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes3: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes4: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes5: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes6: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes7: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes8: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes9: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes10: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes11: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes12: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes13: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes14: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes15: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
readonly votes16: Vec<ITuple<[AccountId, Vec<CompactScore>, AccountId]>>;
}
/** @name CompactScore */
export interface CompactScore extends ITuple<[AccountId, u128]> {}
/** @name ElectionCompute */
export interface ElectionCompute extends Enum {
readonly isOnChain: boolean;