Decode JSON justifications for blocks (#137)
This commit is contained in:
Vendored
+10
-1
@@ -33,10 +33,19 @@ export type BlockExtrinsicDecoded = {
|
||||
signature: Uint8Array
|
||||
}
|
||||
|
||||
export type BlockJustificationDecoded = {
|
||||
hash: Uint8Array,
|
||||
round: BN,
|
||||
signatures: Array<{
|
||||
address: string,
|
||||
signature: Uint8Array
|
||||
}>
|
||||
}
|
||||
|
||||
export type BlockDecoded = {
|
||||
header: Header,
|
||||
extrinsics: Array<BlockExtrinsicDecoded>,
|
||||
justification: any
|
||||
justification: BlockJustificationDecoded
|
||||
};
|
||||
|
||||
export type KeyValue = {
|
||||
|
||||
@@ -9,16 +9,16 @@ import toU8a from '@polkadot/util/u8a/toU8a';
|
||||
|
||||
import decodeExtrinsic from '../extrinsic/decode';
|
||||
import decodeHeader from '../header/decode';
|
||||
import decodeJustification from '../justification/decode';
|
||||
|
||||
export default function blockDecode ({ block: { extrinsics, header }, justification }: JsonBlock): BlockDecoded {
|
||||
return {
|
||||
// TODO We should decode the justifications (and change type from any)
|
||||
justification,
|
||||
header: decodeHeader(header),
|
||||
extrinsics: extrinsics.map((extrinsic) =>
|
||||
decodeExtrinsic(
|
||||
toU8a(extrinsic as any)
|
||||
)
|
||||
)
|
||||
),
|
||||
header: decodeHeader(header),
|
||||
justification: decodeJustification(justification)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright 2017-2018 @polkadot/primitives authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { BlockJustificationDecoded } from '@polkadot/params/types';
|
||||
import { JsonJustification } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import toU8a from '@polkadot/util/u8a/toU8a';
|
||||
import addressEncode from '@polkadot/util-keyring/address/encode';
|
||||
|
||||
export default function justificcationDecode ({ hash, round_number, signatures }: JsonJustification): BlockJustificationDecoded {
|
||||
return {
|
||||
hash: toU8a(hash),
|
||||
round: new BN(round_number),
|
||||
signatures: signatures.map(([address, signature]) => ({
|
||||
address: addressEncode(toU8a(address)),
|
||||
signature: toU8a(signature)
|
||||
}))
|
||||
};
|
||||
}
|
||||
+5
-1
@@ -46,7 +46,11 @@ export type JsonHeader = {
|
||||
digest: JsonDigest
|
||||
};
|
||||
|
||||
export type JsonJustification = {};
|
||||
export type JsonJustification = {
|
||||
hash: string,
|
||||
round_number: number,
|
||||
signatures: Array<[string, string]>
|
||||
};
|
||||
|
||||
export type JsonBlock = {
|
||||
block: {
|
||||
|
||||
Reference in New Issue
Block a user