Support for new inherent digests (#973)

* Support for new inherent digests

* Latest metadata

* Pull in new council & democracy types

* Update tests for new digest

* Digest logsWith/Without

* Round-up e2e tests

* Remove stray debugging log

* Update CHANGELOG.md

Co-Authored-By: Amaury Martiny <amaury.martiny@protonmail.com>
This commit is contained in:
Jaco Greeff
2019-06-06 13:47:52 +02:00
committed by GitHub
co-authored by Amaury Martiny
parent b1e7a0e045
commit 3227ce20a2
19 changed files with 537 additions and 324 deletions
@@ -1197,6 +1197,10 @@
" Once the unlock period is done, you can call `withdraw_unbonded` to actually move",
" the funds out of management ready for transfer.",
"",
" No more than a limited number of unlocking chunks (see `MAX_UNLOCKING_CHUNKS`)",
" can co-exists at the same time. In that case, [`Call::withdraw_unbonded`] need",
" to be called first to remove some of the chunks (if possible).",
"",
" The dispatch origin for this call must be _Signed_ by the controller, not the stash.",
"",
" See also [`Call::withdraw_unbonded`]."
@@ -1440,61 +1444,6 @@
" Those who have locked a deposit."
]
},
{
"name": "LaunchPeriod",
"modifier": "Default",
"type": {
"PlainType": "BlockNumber"
},
"fallback": "0xe803000000000000",
"documentation": [
" How often (in blocks) new public referenda are launched."
]
},
{
"name": "MinimumDeposit",
"modifier": "Default",
"type": {
"PlainType": "BalanceOf"
},
"fallback": "0x00000000000000000000000000000000",
"documentation": [
" The minimum amount to be used as a deposit for a public referendum proposal."
]
},
{
"name": "PublicDelay",
"modifier": "Default",
"type": {
"PlainType": "BlockNumber"
},
"fallback": "0x0000000000000000",
"documentation": [
" The delay before enactment for all public referenda."
]
},
{
"name": "MaxLockPeriods",
"modifier": "Default",
"type": {
"PlainType": "LockPeriods"
},
"fallback": "0x00",
"documentation": [
" The maximum number of additional lock periods a voter may offer to strengthen their vote. Multiples of `PublicDelay`."
]
},
{
"name": "VotingPeriod",
"modifier": "Default",
"type": {
"PlainType": "BlockNumber"
},
"fallback": "0xe803000000000000",
"documentation": [
" How often (in blocks) to check for new votes."
]
},
{
"name": "ReferendumCount",
"modifier": "Default",
@@ -1578,9 +1527,10 @@
},
"fallback": "0x00",
"documentation": [
" Get the vote in a given referendum of a particular voter. The result is meaningful only if `voters_for` includes the",
" voter when called with the referendum (you'll get the default `Vote` value otherwise). If you don't want to check",
" `voters_for`, then you can also check for simple existence with `VoteOf::exists` first."
" Get the vote in a given referendum of a particular voter. The result is meaningful only",
" if `voters_for` includes the voter when called with the referendum (you'll get the",
" default `Vote` value otherwise). If you don't want to check `voters_for`, then you can",
" also check for simple existence with `VoteOf::exists` first."
]
},
{
@@ -1596,7 +1546,8 @@
},
"fallback": "0x00",
"documentation": [
" Who is able to vote for whom. Value is the fund-holding account, key is the vote-transaction-sending account."
" Who is able to vote for whom. Value is the fund-holding account, key is the",
" vote-transaction-sending account."
]
},
{
@@ -1606,7 +1557,7 @@
"MapType": {
"hasher": "Blake2_256",
"key": "AccountId",
"value": "(AccountId,LockPeriods)",
"value": "(AccountId,Conviction)",
"isLinked": true
}
},
@@ -1614,6 +1565,65 @@
"documentation": [
" Get the account (and lock periods) to which another account is delegating vote."
]
},
{
"name": "LastTabledWasExternal",
"modifier": "Default",
"type": {
"PlainType": "bool"
},
"fallback": "0x00",
"documentation": [
" True if the last referendum tabled was submitted externally. False if it was a public",
" proposal."
]
},
{
"name": "NextExternal",
"modifier": "Optional",
"type": {
"PlainType": "(Proposal,VoteThreshold)"
},
"fallback": "0x00",
"documentation": [
" The referendum to be tabled whenever it would be valid to table an external proposal.",
" This happens when a referendum needs to be tabled and one of two conditions are met:",
" - `LastTabledWasExternal` is `false`; or",
" - `PublicProps` is empty."
]
},
{
"name": "Blacklist",
"modifier": "Optional",
"type": {
"MapType": {
"hasher": "Blake2_256",
"key": "Hash",
"value": "(BlockNumber,Vec<AccountId>)",
"isLinked": false
}
},
"fallback": "0x00",
"documentation": [
" A record of who vetoed what. Maps proposal hash to a possible existent block number",
" (until when it may not be resubmitted) and who vetoed it."
]
},
{
"name": "Cancellations",
"modifier": "Default",
"type": {
"MapType": {
"hasher": "Blake2_256",
"key": "Hash",
"value": "bool",
"isLinked": false
}
},
"fallback": "0x00",
"documentation": [
" Record of all proposals that have been subject to emergency cancellation."
]
}
],
"calls": [
@@ -1675,12 +1685,12 @@
}
],
"documentation": [
" Vote in a referendum on behalf of a stash. If `vote.is_aye()`, the vote is to enact the proposal;",
" otherwise it is a vote to keep the status quo."
" Vote in a referendum on behalf of a stash. If `vote.is_aye()`, the vote is to enact",
" the proposal; otherwise it is a vote to keep the status quo."
]
},
{
"name": "start_referendum",
"name": "emergency_propose",
"args": [
{
"name": "proposal",
@@ -1690,13 +1700,73 @@
"name": "threshold",
"type": "VoteThreshold"
},
{
"name": "voting_period",
"type": "BlockNumber"
},
{
"name": "delay",
"type": "BlockNumber"
}
],
"documentation": [
" Start a referendum."
" Schedule an emergency referendum.",
"",
" This will create a new referendum for the `proposal`, approved as long as counted votes",
" exceed `threshold` and, if approved, enacted after the given `delay`.",
"",
" It may be called from either the Root or the Emergency origin."
]
},
{
"name": "emergency_cancel",
"args": [
{
"name": "ref_index",
"type": "ReferendumIndex"
}
],
"documentation": [
" Schedule an emergency cancellation of a referendum. Cannot happen twice to the same",
" referendum."
]
},
{
"name": "external_propose",
"args": [
{
"name": "proposal",
"type": "Proposal"
}
],
"documentation": [
" Schedule a referendum to be tabled once it is legal to schedule an external",
" referendum."
]
},
{
"name": "external_propose_majority",
"args": [
{
"name": "proposal",
"type": "Proposal"
}
],
"documentation": [
" Schedule a majority-carries referendum to be tabled next once it is legal to schedule",
" an external referendum."
]
},
{
"name": "veto_external",
"args": [
{
"name": "proposal_hash",
"type": "Hash"
}
],
"documentation": [
" Veto and blacklist the external proposal hash."
]
},
{
@@ -1721,6 +1791,10 @@
{
"name": "which",
"type": "Compact<u32>"
},
{
"name": "what",
"type": "Compact<ReferendumIndex>"
}
],
"documentation": [
@@ -1766,8 +1840,8 @@
"type": "AccountId"
},
{
"name": "lock_periods",
"type": "LockPeriods"
"name": "conviction",
"type": "Conviction"
}
],
"documentation": [
@@ -1800,6 +1874,11 @@
],
"documentation": []
},
{
"name": "ExternalTabled",
"args": [],
"documentation": []
},
{
"name": "Started",
"args": [
@@ -1851,6 +1930,15 @@
"AccountId"
],
"documentation": []
},
{
"name": "Vetoed",
"args": [
"AccountId",
"Hash",
"BlockNumber"
],
"documentation": []
}
]
},
@@ -2219,8 +2307,8 @@
],
"documentation": [
" Set the desired member count; if lower than the current count, then seats will not be up",
" election when they expire. If more, then a new vote will be started if one is not already",
" in progress."
" election when they expire. If more, then a new vote will be started if one is not",
" already in progress."
]
},
{
@@ -2232,9 +2320,10 @@
}
],
"documentation": [
" Remove a particular member. A tally will happen instantly (if not already in a presentation",
" period) to fill the seat if removal means that the desired members are not met.",
" This is effective immediately."
" Remove a particular member from the council. This is effective immediately.",
"",
" Note: A tally should happen instantly (if not already in a presentation",
" period) to fill the seat if removal means that the desired members are not met."
]
},
{
@@ -2305,190 +2394,6 @@
}
]
},
{
"name": "council_voting",
"prefix": "CouncilVoting",
"storage": [
{
"name": "CooloffPeriod",
"modifier": "Default",
"type": {
"PlainType": "BlockNumber"
},
"fallback": "0xe803000000000000",
"documentation": []
},
{
"name": "VotingPeriod",
"modifier": "Default",
"type": {
"PlainType": "BlockNumber"
},
"fallback": "0x0300000000000000",
"documentation": []
},
{
"name": "EnactDelayPeriod",
"modifier": "Default",
"type": {
"PlainType": "BlockNumber"
},
"fallback": "0x0000000000000000",
"documentation": [
" Number of blocks by which to delay enactment of successful, non-unanimous-council-instigated referendum proposals."
]
},
{
"name": "Proposals",
"modifier": "Default",
"type": {
"PlainType": "Vec<(BlockNumber,Hash)>"
},
"fallback": "0x00",
"documentation": []
},
{
"name": "ProposalOf",
"modifier": "Optional",
"type": {
"MapType": {
"hasher": "Blake2_256",
"key": "Hash",
"value": "Proposal",
"isLinked": false
}
},
"fallback": "0x00",
"documentation": []
},
{
"name": "ProposalVoters",
"modifier": "Default",
"type": {
"MapType": {
"hasher": "Blake2_256",
"key": "Hash",
"value": "Vec<AccountId>",
"isLinked": false
}
},
"fallback": "0x00",
"documentation": []
},
{
"name": "CouncilVoteOf",
"modifier": "Optional",
"type": {
"MapType": {
"hasher": "Blake2_256",
"key": "(Hash,AccountId)",
"value": "bool",
"isLinked": false
}
},
"fallback": "0x00",
"documentation": []
},
{
"name": "VetoedProposal",
"modifier": "Optional",
"type": {
"MapType": {
"hasher": "Blake2_256",
"key": "Hash",
"value": "(BlockNumber,Vec<AccountId>)",
"isLinked": false
}
},
"fallback": "0x00",
"documentation": []
}
],
"calls": [
{
"name": "propose",
"args": [
{
"name": "proposal",
"type": "Proposal"
}
],
"documentation": []
},
{
"name": "vote",
"args": [
{
"name": "proposal",
"type": "Hash"
},
{
"name": "approve",
"type": "bool"
}
],
"documentation": []
},
{
"name": "veto",
"args": [
{
"name": "proposal_hash",
"type": "Hash"
}
],
"documentation": []
},
{
"name": "set_cooloff_period",
"args": [
{
"name": "blocks",
"type": "Compact<BlockNumber>"
}
],
"documentation": []
},
{
"name": "set_voting_period",
"args": [
{
"name": "blocks",
"type": "Compact<BlockNumber>"
}
],
"documentation": []
}
],
"events": [
{
"name": "TallyCancelation",
"args": [
"Hash",
"u32",
"u32",
"u32"
],
"documentation": [
" A voting tally has happened for a referendum cancellation vote.",
" Last three are yes, no, abstain counts."
]
},
{
"name": "TallyReferendum",
"args": [
"Hash",
"u32",
"u32",
"u32"
],
"documentation": [
" A voting tally has happened for a referendum vote.",
" Last three are yes, no, abstain counts."
]
}
]
},
{
"name": "council_motions",
"prefix": "CouncilMotions",
@@ -2501,7 +2406,7 @@
},
"fallback": "0x00",
"documentation": [
" The (hashes of) the active proposals."
" The hashes of the active proposals."
]
},
{
@@ -2527,13 +2432,13 @@
"MapType": {
"hasher": "Blake2_256",
"key": "Hash",
"value": "(ProposalIndex,u32,Vec<AccountId>,Vec<AccountId>)",
"value": "Votes",
"isLinked": false
}
},
"fallback": "0x00",
"documentation": [
" Votes for a given proposal: (required_yes_votes, yes_voters, no_voters)."
" Votes on a given proposal, if it is ongoing."
]
},
{
@@ -2549,12 +2454,26 @@
}
],
"calls": [
{
"name": "execute",
"args": [
{
"name": "proposal",
"type": "Proposal"
}
],
"documentation": [
" Dispatch a proposal from a councilor using the `Member` origin.",
"",
" Origin must be a council member."
]
},
{
"name": "propose",
"args": [
{
"name": "threshold",
"type": "Compact<u32>"
"type": "Compact<MemberCount>"
},
{
"name": "proposal",
@@ -2589,10 +2508,11 @@
"AccountId",
"ProposalIndex",
"Hash",
"u32"
"MemberCount"
],
"documentation": [
" A motion (given hash) has been proposed (by given account) with a threshold (given u32)."
" A motion (given hash) has been proposed (by given account) with a threshold (given",
" `MemberCount`)."
]
},
{
@@ -2601,12 +2521,12 @@
"AccountId",
"Hash",
"bool",
"u32",
"u32"
"MemberCount",
"MemberCount"
],
"documentation": [
" A motion (given hash) has been voted on by given account, leaving",
" a tally (yes votes and no votes given as u32s respectively)."
" a tally (yes votes and no votes given respectively as `MemberCount`)."
]
},
{
@@ -2636,6 +2556,16 @@
"documentation": [
" A motion was executed; `bool` is true if returned without error."
]
},
{
"name": "MemberExecuted",
"args": [
"Hash",
"bool"
],
"documentation": [
" A single councillor did some action; `bool` is true if returned without error."
]
}
]
},
@@ -2721,8 +2651,8 @@
},
"fallback": "0x00000000",
"documentation": [
" Proportion of funds that should be bonded in order to place a proposal. An accepted",
" proposal gets these back. A rejected proposal doesn't."
" Fraction of a proposal's value that should be bonded in order to place the proposal.",
" An accepted proposal gets these back. A rejected proposal does not."
]
},
{
File diff suppressed because one or more lines are too long
+15
View File
@@ -0,0 +1,15 @@
{
"jsonrpc": "2.0",
"result": {
"digest": {
"logs": [
"0x0461757261210169c97e0f00000000479c09f7ace12ed3e1af2dba6cca6831e257e80feef56c7474d6c69bae6f4e8a6e0045a87afe14296992c38b7d55abcbe617c441cd35e8667abbcb1678f31802"
]
},
"extrinsicsRoot": "0x4133a7c2e9ab3d0c75f93bfba8730011668c697036adb2f22916a8731f68c2fa",
"number": "0x193046",
"parentHash": "0x596b8c3ced242052921135e9b44dba2ba3752b2a92f1cfa361d59b10016cb5b0",
"stateRoot": "0xd9d32d2f3f4af14c506aa59ff5a3132ca0fe5d7f82cdf1e4967a638042e849a6"
},
"id": 16
}
@@ -0,0 +1 @@
{"jsonrpc":"2.0","method":"chain_newHead","params":{"result":{"digest":{"logs":["0x06617572612089353e1700000000","0x05617572614e869ea59bb040ddd205f7c78ee668d9ca52c28333dc2831f761ed8085417093c42642f6a467e86ad7d81c6f02b8b0064d1a405ed857747d7d905a1fcde1510e"]},"extrinsicsRoot":"0xd2c75ad52726af9fe9aa769006074014afb6a34a541a4adb0604c09f425d7f8b","number":"0x2e2","parentHash":"0x49c071e46b0da9abd957daaff21c895dc5f883c322cf4c7436e99b68653d8bc8","stateRoot":"0x0904ec490acf2419ff90d9966ce8c77054d8f56bed1d2cee74608bf6a0eafccf"},"subscription":22}}
@@ -0,0 +1 @@
{"jsonrpc":"2.0","method":"chain_newHead","params":{"result":{"digest":{"logs":["0x0661757261208a353e1700000000","0x0561757261ae9c37c4b07e97ccb9b40fb966a55ef871ac0aadf7bc8de0b1de00287c7d11f7ce6526e2e1ba95b575a011b09ec4b032c3bb0e7267d613e03b0c9f4f8a7ae701"]},"extrinsicsRoot":"0xde21769bd74ac0fa167989d41b3f059b924da7625212848ca7103bde0413da8f","number":"0x2e3","parentHash":"0xbff2707a02125eb790f8252b96560bb8a7b3ae4f4f2f9d44ac44886d74dfd924","stateRoot":"0x820d7ef1dbbb070c96d340fdb25273f9f30ee8b804ba2804ab88891ed509ea58"},"subscription":22}}
@@ -0,0 +1 @@
{"jsonrpc":"2.0","method":"chain_newHead","params":{"result":{"digest":{"logs":["0x0661757261208b353e1700000000","0x05617572611cf036c978ad8da399e353a8328f2b0959080b12d7e05d45dcd1ff13160b60aecf4324698f4b21d0c056b86290a9197d0b3196a415036b0c7dda27fbeadf7c0f"]},"extrinsicsRoot":"0xc46db6f343b23828b0bf6f999bc13fdc9766d4e010a91a2af7a138d151f140ff","number":"0x2e4","parentHash":"0xec269aab57804cf6004b984c6f281610d2d2c94dc90bf3a8118bbf1e3c4d7f0e","stateRoot":"0xe660e4535a5ac25171dd9280dd8ba861a9c310bfc3bf643cc1229f23f13fd367"},"subscription":22}}
+1 -1
View File
@@ -24,7 +24,7 @@ describe('Block', () => {
stateRoot: 'H256',
extrinsicsRoot: 'H256',
digest: JSON.stringify({
logs: 'Vec<{"_enum":{"Other":"Bytes","AuthoritiesChange":"Vec<AccountId>","ChangesTrieRoot":"H256","Seal":"(u64,H512)","Consensus":"(u32,Bytes)"}}>'
logs: 'Vec<{"_enum":{"Other":"Bytes","AuthoritiesChange":"Vec<AccountId>","ChangesTrieRoot":"H256","SealV0":"(u64,H512)","Consensus":"(u32,Bytes)","Seal":"(u32,H512)","PreRuntime":"(u32,Bytes)"}}>'
})
}),
extrinsics: 'Vec<Extrinsic>'
+21 -6
View File
@@ -2,21 +2,36 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import json from '../json/Header.002.json';
import json3 from '../json/Header.003.json';
import json4 from '../json/Header.004.0x2e2.json';
import Digest from './Digest';
describe('Digest', () => {
it('decodes logs with seals', () => {
const digest = new Digest(json.result.digest);
it('decodes logs with consensus', () => {
const digest = new Digest(json3.result.digest);
expect(digest.logs.length).toEqual(1);
const log = digest.logs[0];
expect(log.type).toBe('Seal');
expect(log.type).toBe('Consensus');
expect(log.value.toJSON()).toEqual([
256804359,
'0x2c0e0ee8a5d1a073da3f8db002b8eaebcd7b1a7eb25662e09f9ef0ac58d96bf17896256cd5f0bc672f96aab49fe5163ca5cb4c1a0f047dc39e89cd4a9eb2ea05'
1634891105,
'0x69c97e0f00000000479c09f7ace12ed3e1af2dba6cca6831e257e80feef56c7474d6c69bae6f4e8a6e0045a87afe14296992c38b7d55abcbe617c441cd35e8667abbcb1678f31802'
]);
});
it('filters logs, excluding items', () => {
const logs = new Digest(json4.params.result.digest).logsWith('PreRuntime');
expect(logs.length).toEqual(1);
expect(logs[0].type).toEqual('PreRuntime');
});
it('filters logs, including items', () => {
const logs = new Digest(json4.params.result.digest).logsWithout('PreRuntime');
expect(logs.length).toEqual(1);
expect(logs[0].type).toEqual('Seal');
});
});
+161 -40
View File
@@ -32,39 +32,11 @@ export class ChangesTrieRoot extends Hash {
}
/**
* @name Other
* @name ConsensusEngineId
* @description
* Log item that is just a stream of [[Bytes]]
* A 4-byte identifier (actually a [u8; 4]) identifying the engine, e.g. for Aura it would be [b'a', b'u', b'r', b'a']
*/
export class Other extends Bytes {
}
/**
* @name Seal
* @description
* Log item indicating a sealing event
*/
export class Seal extends Tuple {
constructor (value: any) {
super({
U64,
Signature
}, value);
}
/**
* @description The wrapped [[Signature]]
*/
get signature (): Signature {
return this[1] as Signature;
}
/**
* @description The wrapped [[U64]] slot
*/
get slot (): U64 {
return this[0] as U64;
}
export class ConsensusEngineId extends U32 {
}
/**
@@ -75,7 +47,7 @@ export class Seal extends Tuple {
export class Consensus extends Tuple {
constructor (value: any) {
super({
U32, // actually a [u8; 4]
ConsensusEngineId,
Bytes
}, value);
}
@@ -88,10 +60,10 @@ export class Consensus extends Tuple {
}
/**
* @description The wrapped engine [[U32]]
* @description The wrapped engine [[ConsensusEngineId]]
*/
get engine (): U32 {
return this[0] as U32;
get engine (): ConsensusEngineId {
return this[0] as ConsensusEngineId;
}
/**
@@ -116,6 +88,98 @@ export class Consensus extends Tuple {
}
}
/**
* @name SealV0
* @description
* Log item indicating a sealing event. This has been replaced in later versions with a renamed [[Seal]], we however have kept compatibility with the old version
*/
export class SealV0 extends Tuple {
constructor (value: any) {
super({
U64,
Signature
}, value);
}
/**
* @description The wrapped [[Signature]]
*/
get signature (): Signature {
return this[1] as Signature;
}
/**
* @description The wrapped [[U64]] slot
*/
get slot (): U64 {
return this[0] as U64;
}
}
/**
* @name Seal
* @description
* Log item indicating a sealing event.
*/
export class Seal extends Tuple {
constructor (value: any) {
super({
ConsensusEngineId,
Signature
}, value);
}
/**
* @description The wrapped [[Signature]]
*/
get signature (): Signature {
return this[1] as Signature;
}
/**
* @description The wrapped [[U64]] slot
*/
get slot (): U64 {
return this[0] as U64;
}
}
/**
* @name Other
* @description
* Log item that is just a stream of [[Bytes]]
*/
export class Other extends Bytes {
}
/**
* @name PreRuntime
* @description
* These are messages from the consensus engine to the runtime, although the consensus engine the consensus engine can (and should) read them itself to avoid ode and state duplication.
*/
export class PreRuntime extends Tuple {
constructor (value: any) {
super({
ConsensusEngineId,
Bytes
}, value);
}
/**
* @description The wrapped [[ConsensusEngineId]]
*/
get engine (): ConsensusEngineId {
return this[0] as ConsensusEngineId;
}
/**
* @description The wrapped [[Bytes]]
*/
get data (): Bytes {
return this[1] as Bytes;
}
}
/**
* @name DigestItem
* @description
@@ -123,12 +187,16 @@ export class Consensus extends Tuple {
*/
export class DigestItem extends Enum {
constructor (value: any) {
// Note the ordering, it aligns with numbers to the Rust implementation
// (current and previous versions)
super({
Other, // Position 0, as per Rust (encoding control)
AuthoritiesChange,
ChangesTrieRoot,
Seal,
Consensus
Other, // 0
AuthoritiesChange, // 1
ChangesTrieRoot, // 2
SealV0, // 3
Consensus, // 4
Seal, // 5
PreRuntime // 6
}, value);
}
@@ -168,6 +236,15 @@ export class DigestItem extends Enum {
return this.value as Other;
}
/**
* @description Returns the item as a [[PreRuntime]]
*/
get asPreRuntime (): PreRuntime {
assert(this.isPreRuntime, `Cannot convert '${this.type}' via asPreRuntime`);
return this.value as PreRuntime;
}
/**
* @description Returns the item as a [[Seal]]
*/
@@ -177,6 +254,15 @@ export class DigestItem extends Enum {
return this.value as Seal;
}
/**
* @description Returns the item as a [[SealV0]]
*/
get asSealV0 (): SealV0 {
assert(this.isSealV0, `Cannot convert '${this.type}' via asSealV0`);
return this.value as SealV0;
}
/**
* @description Returns true on [[AuthoritiesChange]]
*/
@@ -205,12 +291,33 @@ export class DigestItem extends Enum {
return this.type === 'Other';
}
/**
* @description Returns true on [[PreRuntime]]
*/
get isPreRuntime (): boolean {
return this.type === 'PreRuntime';
}
/**
* @description Returns true on [[Seal]]
*/
get isSeal (): boolean {
return this.type === 'Seal';
}
/**
* @description Returns true on [[SealV0]]
*/
get isSealV0 (): boolean {
return this.type === 'SealV0';
}
/**
* @description Converts the Object to JSON, typically used for RPC transfers. For logs, we overrides to produce the hex version (sligning with substrate gives in actual JSON responses)
*/
toJSON (): any {
return this.toHex();
}
}
/**
@@ -231,4 +338,18 @@ export default class Digest extends Struct {
get logs (): Vector<DigestItem> {
return this.get('logs') as Vector<DigestItem>;
}
/**
* @description The [[DigestItem]] logs, filtered, filter items included. This is useful for derive functionality where only a certain type of log is to be returned.
*/
logsWith (...include: Array<string>): Vector<DigestItem> {
return this.logs.filter(({ type }) => include.includes(type)) as Vector<DigestItem>;
}
/**
* @description The [[DigestItem]] logs, filtered, filter items exluded. This is useful for stripping headers for eg. WASM runtime execution.
*/
logsWithout (...exclude: Array<string>): Vector<DigestItem> {
return this.logs.filter(({ type }) => !exclude.includes(type)) as Vector<DigestItem>;
}
}
+25 -4
View File
@@ -7,6 +7,10 @@ import BN from 'bn.js';
import Header from './Header';
import json1 from '../json/Header.001.json';
import json2 from '../json/Header.002.json';
import json3 from '../json/Header.003.json';
import json4x2e2 from '../json/Header.004.0x2e2.json';
import json4x2e3 from '../json/Header.004.0x2e3.json';
import json4x2e4 from '../json/Header.004.0x2e4.json';
describe('Header', () => {
it('decodes an actual JSON response', () => {
@@ -29,14 +33,31 @@ describe('Header', () => {
).toEqual('[]');
});
it('creates a valid hash (incl. digest & compact)', () => {
it('parses old-style JSON headers (deprecated)', () => {
const header = new Header(json2.result);
expect(
header.hash.toHex()
).toEqual('0x63ccfdc044d3ff4c915ad01c0d57d2ff807f4eb7d60cd41584917363bc83a99f');
header.digest.logs
).toHaveLength(1);
});
it('creates a valid hash (incl. digest & compact)', () => {
const header = new Header(json3.result);
expect(
header.blockNumber.eq(new BN(2918))
header.hash.toHex()
).toEqual('0x464692ad0e225a74274a7ef411e045f1fc7c2639b5f780c7c18f91f4100f5e54');
expect(
header.blockNumber.eq(new BN(1650758))
).toBe(true);
});
it('correctly hashes headers with PreRuntime, aligning with substrate', () => {
const x2e2 = new Header(json4x2e2.params.result);
const x2e3 = new Header(json4x2e3.params.result);
const x2e4 = new Header(json4x2e4.params.result);
expect(x2e3.parentHash).toEqual(x2e2.hash);
expect(x2e4.parentHash).toEqual(x2e3.hash);
});
});
+29
View File
@@ -0,0 +1,29 @@
// 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 Enum from '../codec/Enum';
/**
* @name Conviction
* @description
* A value denoting the strength of conviction of a vote.
*/
export default class Conviction extends Enum {
constructor (value: any) {
super([
// 0.1x votes, unlocked.
'None',
// 1x votes, locked for an enactment period following a successful vote.
'Locked1x',
// 2x votes, locked for 2x enactment periods following a successful vote.
'Locked2x',
// 3x votes, locked for 4x...
'Locked3x',
// 4x votes, locked for 8x...
'Locked4x',
// 5x votes, locked for 16x...
'Locked5x'
], value);
}
}
+13
View File
@@ -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 MemberCount
* @description
* A number of council members as a [[U32]]. This also serves as a number of voting members, and since for motions, each council member may vote exactly once, therefore also the number of votes for any given motion.v
*/
export default class MemberCount extends U32 {
}
+48
View File
@@ -0,0 +1,48 @@
// 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 Vector from '../codec/Vector';
import AccountId from '../primitive/AccountId';
import MemberCount from './MemberCount';
import ProposalIndex from './ProposalIndex';
export default class Votes extends Struct {
constructor (value: any) {
super({
index: ProposalIndex,
threshold: MemberCount,
ayes: Vector.with(AccountId),
nays: Vector.with(AccountId)
});
}
/**
* @description The current set of voters that approved it.
*/
get ayes (): Vector<AccountId> {
return this.get('ayes') as Vector<AccountId>;
}
/**
* @description The proposal's unique index.
*/
get index (): ProposalIndex {
return this.get('index') as ProposalIndex;
}
/**
* @description The current set of voters that rejected it.
*/
get nays (): Vector<AccountId> {
return this.get('nays') as Vector<AccountId>;
}
/**
* @description The number of approval votes that are needed to pass the motion.
*/
get threshold (): MemberCount {
return this.get('threshold') as MemberCount;
}
}
+5 -2
View File
@@ -18,6 +18,7 @@ export { default as BalanceLock } from './BalanceLock';
// export * from './Bft;
export { default as BlockNumber } from './BlockNumber';
export { default as CodeHash } from './CodeHash';
export { default as Conviction } from './Conviction';
export { default as ContractInfo } from './ContractInfo';
export { default as ContractStorageKey } from './ContractStorageKey';
export { default as Exposure } from './Exposure';
@@ -33,12 +34,13 @@ export { default as Key } from './Key';
export { default as KeyValue } from './KeyValue';
export { default as LockIdentifier } from './LockIdentifier';
export { default as LockPeriods } from './LockPeriods';
export { default as MisbehaviorReport } from './MisbehaviorReport';
export { default as NewAccountOutcome } from './NewAccountOutcome';
// NOTE Nonce is renamed to Index
export { default as Index } from './Nonce';
export { default as IndexCompact } from './NonceCompact';
export { default as Justification } from './Justification';
export { default as MemberCount } from './MemberCount';
export { default as MisbehaviorReport } from './MisbehaviorReport';
export { default as NewAccountOutcome } from './NewAccountOutcome';
export { default as ParaId } from './ParaId';
export { default as Permill } from './Permill';
export { default as Perbill } from './Perbill';
@@ -61,6 +63,7 @@ export { default as UnlockChunk } from './UnlockChunk';
export { default as ValidatorPrefs } from './ValidatorPrefs';
export { default as VestingSchedule } from './VestingSchedule';
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 WithdrawReasons } from './WithdrawReasons';