From 6771f9948bcdb9af4235c91970a523a172bd79e4 Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Wed, 12 Jun 2019 19:43:41 +0200 Subject: [PATCH] Added types for ApprovalFlag, SetIndex, VoterInfo (#996) * Added types for ApprovalFlag, SetIndex, VoterInfo * Delete VoterInfo * Fixed typo ApprovalIndex => ApprovalFlag * Added VoterInfo * newline & whitespace --- packages/types/README.md | 3 ++ packages/types/src/type/ApprovalFlag.ts | 13 ++++++ packages/types/src/type/SetIndex.ts | 13 ++++++ packages/types/src/type/VoterInfo.ts | 53 +++++++++++++++++++++++++ packages/types/src/type/index.ts | 3 ++ 5 files changed, 85 insertions(+) create mode 100644 packages/types/src/type/ApprovalFlag.ts create mode 100644 packages/types/src/type/SetIndex.ts create mode 100644 packages/types/src/type/VoterInfo.ts diff --git a/packages/types/README.md b/packages/types/README.md index ac523820d1..c3d2fbccfe 100644 --- a/packages/types/README.md +++ b/packages/types/README.md @@ -76,6 +76,7 @@ These custom types implement specific types that are found as part of the Substr | **Types** | | | --- | --- | | [[Amount]] | The Substrate Amount representation as a [[Balance]] | +| [[ApprovalFlag]] | Approval flag, implemented as a [[U32]] | | [[AssetOf]] | The Substrate AssetOf representation as a [[Balance]] | | [[AttestedCandidate]] | An attested candidate | | [[AuthorityId]] | Wrapper for a AuthorityId. Same as an normal AccountId | @@ -128,6 +129,7 @@ These custom types implement specific types that are found as part of the Substr | [[Seal]] | Log item indicating a sealing event | | [[SeedOf]] | The Substrate SeedOf representation as a [[Hash]] | | [[SessionKey]] | Wrapper for a SessionKey. Same as an normal [[AuthorityId]], i.e. a wrapper around publicKey | +| [[SetIndex]] | Set index, implemented as a [[U32]] | | [[Signature]] | The default signature that is used accross the system | | [[SignaturePayload]] | A signing payload for an [[Extrinsic]]. For the final encoding, it is variable length based on the contents included | | [[SignaturePayloadRaw]] | A version of the [[SignaturePayload]] where it doesn't rely on [[Method]] with metadata, rather it treats the values as a raw byte stream | @@ -140,6 +142,7 @@ These custom types implement specific types that are found as part of the Substr | [[Vote]] | A number of lock periods, plus a vote, one way or the other | | [[Votes]] | Info for keeping track of a council motion being voted on. | | [[VoteIndex]] | Voting index, implemented as a [[U32]] | +| [[VoterInfo]] | The activity status of a voter. | | [[VoteThreshold]] | Voting threshold, used inside proposals to set change the voting tally | | [[WithdrawReasons]] | The Substrate WithdrawReasons for staking | diff --git a/packages/types/src/type/ApprovalFlag.ts b/packages/types/src/type/ApprovalFlag.ts new file mode 100644 index 0000000000..7b51d54253 --- /dev/null +++ b/packages/types/src/type/ApprovalFlag.ts @@ -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 U32 from '../primitive/U32'; + +/** + * @name ApprovalFlag + * @description + * Approval Flag, implemented as a [[U32]] + */ +export default class ApprovalFlag extends U32 { +} diff --git a/packages/types/src/type/SetIndex.ts b/packages/types/src/type/SetIndex.ts new file mode 100644 index 0000000000..9fc49364b3 --- /dev/null +++ b/packages/types/src/type/SetIndex.ts @@ -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 U32 from '../primitive/U32'; + +/** + * @name SetIndex + * @description + * Set index, implemented as a [[U32]] + */ +export default class SetIndex extends U32 { +} diff --git a/packages/types/src/type/VoterInfo.ts b/packages/types/src/type/VoterInfo.ts new file mode 100644 index 0000000000..fe2bb791ef --- /dev/null +++ b/packages/types/src/type/VoterInfo.ts @@ -0,0 +1,53 @@ +// 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 Struct from '../codec/Struct'; +import Balance from './Balance'; +import VoteIndex from './VoteIndex'; + +/** + * @name VoterInfo + * @description + * The activity status of a voter. + */ + +export default class VoterInfo extends Struct { + constructor (value?: any) { + super({ + lastActive: VoteIndex, + lastWin: VoteIndex, + pot: Balance, + stake: Balance + }, value); + } + + /** + * @description Last VoteIndex in which this voter assigned (or initialized) approvals. + */ + get lastActive (): VoteIndex { + return this.get('lastActive') as VoteIndex; + } + + /** + * @description Last VoteIndex in which one of this voter's approvals won. + * Note that `last_win = N` indicates a last win at index `N-1`, hence `last_win = 0` means no win ever. + */ + get lastWin (): VoteIndex { + return this.get('lastWin') as VoteIndex; + } + + /** + * @description The amount of stored weight as a result of not winning but changing approvals. + */ + get pot (): Balance { + return this.get('pot') as Balance; + } + + /** + * @description Current staked amount. A lock equal to this value always exists. + */ + get stake (): Balance { + return this.get('stake') as Balance; + } +} diff --git a/packages/types/src/type/index.ts b/packages/types/src/type/index.ts index f23a7a27ae..8caa6d5909 100644 --- a/packages/types/src/type/index.ts +++ b/packages/types/src/type/index.ts @@ -9,6 +9,7 @@ * @summary Type definitions that are used in the system */ export { default as Amount } from './Amount'; +export { default as ApprovalFlag } from './ApprovalFlag'; export { default as AssetOf } from './AssetOf'; export { default as AttestedCandidate } from './AttestedCandidate'; export { default as AuthorityId } from './AuthorityId'; @@ -54,6 +55,7 @@ export { default as RewardDestination } from './RewardDestination'; export { default as Schedule } from './Schedule'; export { default as SeedOf } from './SeedOf'; export { default as SessionKey } from './SessionKey'; +export { default as SetIndex } from './SetIndex'; export { default as Signature, Ed25519Signature, Sr25519Signature } from './Signature'; export { default as SignaturePayload, SignaturePayloadRaw } from './SignaturePayload'; export { default as StakingLedger } from './StakingLedger'; @@ -66,4 +68,5 @@ export { default as Vote } from './Vote'; export { default as Votes } from './Votes'; export { default as VoteThreshold } from './VoteThreshold'; export { default as VoteIndex } from './VoteIndex'; +export { default as VoterInfo } from './VoterInfo'; export { default as WithdrawReasons } from './WithdrawReasons';