Add DigestItem(Seal) for Aura (#361)
* Add DigestItem(Seal) for Aura * Re-add DigestItem export
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2017-2018 @polkadot/types authors & contributors
|
||||||
|
// This software may be modified and distributed under the terms
|
||||||
|
// of the ISC license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
import json from './json/Header.002.json';
|
||||||
|
import Digest from './Digest';
|
||||||
|
|
||||||
|
describe('Digest', () => {
|
||||||
|
it('decodes logs with seals', () => {
|
||||||
|
const digest = new Digest(json.result.digest);
|
||||||
|
|
||||||
|
expect(digest.logs.length).toEqual(1);
|
||||||
|
|
||||||
|
const log = digest.logs.get(0);
|
||||||
|
|
||||||
|
expect(log.type).toBe('Seal');
|
||||||
|
expect(log.value.toJSON()).toEqual([
|
||||||
|
256802739,
|
||||||
|
'0x7f8635f18fc5ecb82b39eca5b44b7e824e24870e2452ff4e71759ca673b422cbdc767fbb8bf9f7ab2a9b883ad14e62f56ae0c48ed405575a71bbb1e9d5c69301'
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -2,31 +2,52 @@
|
|||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the ISC license. See the LICENSE file for details.
|
// of the ISC license. See the LICENSE file for details.
|
||||||
|
|
||||||
import AuthorityId from './AuthorityId';
|
|
||||||
import EnumType from './codec/EnumType';
|
import EnumType from './codec/EnumType';
|
||||||
import Hash from './Hash';
|
|
||||||
import Null from './Null';
|
|
||||||
import Struct from './codec/Struct';
|
import Struct from './codec/Struct';
|
||||||
|
import Tuple from './codec/Tuple';
|
||||||
import Vector from './codec/Vector';
|
import Vector from './codec/Vector';
|
||||||
|
import AuthorityId from './AuthorityId';
|
||||||
|
import Bytes from './Bytes';
|
||||||
|
import Hash from './Hash';
|
||||||
|
import Signature from './Signature';
|
||||||
|
import U32 from './U32';
|
||||||
|
|
||||||
export class AuthoritiesChange extends Vector.with(AuthorityId) {
|
class AuthoritiesChange extends Vector.with(AuthorityId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ChangesTrieRoot extends Hash {
|
class ChangesTrieRoot extends Hash {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME Once we have Events, have a look on how to decode them
|
class Other extends Bytes {
|
||||||
export class Other extends Null {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DigestItem extends EnumType<AuthoritiesChange | ChangesTrieRoot | Other> {
|
class Seal extends Tuple {
|
||||||
constructor (value: any) {
|
constructor (value: any) {
|
||||||
super({
|
super({
|
||||||
0: Other,
|
slot: U32,
|
||||||
1: AuthoritiesChange,
|
signature: Signature
|
||||||
2: ChangesTrieRoot
|
|
||||||
}, value);
|
}, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get signature (): Signature {
|
||||||
|
return this.get('signature') as Signature;
|
||||||
|
}
|
||||||
|
|
||||||
|
get slot (): U32 {
|
||||||
|
return this.get('slot') as U32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DigestItem extends EnumType<AuthoritiesChange | ChangesTrieRoot | Other
|
||||||
|
| Seal> {
|
||||||
|
constructor (value: any) {
|
||||||
|
super([
|
||||||
|
Other, // Position 0, as per Rust (encoding control)
|
||||||
|
AuthoritiesChange,
|
||||||
|
ChangesTrieRoot,
|
||||||
|
Seal
|
||||||
|
], value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Digest extends Struct {
|
export default class Digest extends Struct {
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"result": {
|
||||||
|
"digest": {
|
||||||
|
"logs": [
|
||||||
|
{
|
||||||
|
"Seal": [
|
||||||
|
256802739,
|
||||||
|
"0x7f8635f18fc5ecb82b39eca5b44b7e824e24870e2452ff4e71759ca673b422cbdc767fbb8bf9f7ab2a9b883ad14e62f56ae0c48ed405575a71bbb1e9d5c69301"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"extrinsicsRoot": "0x48ef05ba1bd0d2c5b313a573b4584955819950e4412f88291c575ae66f9c4481",
|
||||||
|
"number": 1982,
|
||||||
|
"parentHash": "0x17430eedcdba0d19cbccb67480e0f6a1dc5dfca9d3e627238237184f1519abc6",
|
||||||
|
"stateRoot": "0xefc509cd3c747799770a824fb4331ab7ed6a99c5d873b84ee3428a42d7df14be"
|
||||||
|
},
|
||||||
|
"id": 1
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user