Decode JSON justifications for blocks (#137)
This commit is contained in:
Vendored
+10
-1
@@ -33,10 +33,19 @@ export type BlockExtrinsicDecoded = {
|
|||||||
signature: Uint8Array
|
signature: Uint8Array
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type BlockJustificationDecoded = {
|
||||||
|
hash: Uint8Array,
|
||||||
|
round: BN,
|
||||||
|
signatures: Array<{
|
||||||
|
address: string,
|
||||||
|
signature: Uint8Array
|
||||||
|
}>
|
||||||
|
}
|
||||||
|
|
||||||
export type BlockDecoded = {
|
export type BlockDecoded = {
|
||||||
header: Header,
|
header: Header,
|
||||||
extrinsics: Array<BlockExtrinsicDecoded>,
|
extrinsics: Array<BlockExtrinsicDecoded>,
|
||||||
justification: any
|
justification: BlockJustificationDecoded
|
||||||
};
|
};
|
||||||
|
|
||||||
export type KeyValue = {
|
export type KeyValue = {
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ import toU8a from '@polkadot/util/u8a/toU8a';
|
|||||||
|
|
||||||
import decodeExtrinsic from '../extrinsic/decode';
|
import decodeExtrinsic from '../extrinsic/decode';
|
||||||
import decodeHeader from '../header/decode';
|
import decodeHeader from '../header/decode';
|
||||||
|
import decodeJustification from '../justification/decode';
|
||||||
|
|
||||||
export default function blockDecode ({ block: { extrinsics, header }, justification }: JsonBlock): BlockDecoded {
|
export default function blockDecode ({ block: { extrinsics, header }, justification }: JsonBlock): BlockDecoded {
|
||||||
return {
|
return {
|
||||||
// TODO We should decode the justifications (and change type from any)
|
|
||||||
justification,
|
|
||||||
header: decodeHeader(header),
|
|
||||||
extrinsics: extrinsics.map((extrinsic) =>
|
extrinsics: extrinsics.map((extrinsic) =>
|
||||||
decodeExtrinsic(
|
decodeExtrinsic(
|
||||||
toU8a(extrinsic as any)
|
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
|
digest: JsonDigest
|
||||||
};
|
};
|
||||||
|
|
||||||
export type JsonJustification = {};
|
export type JsonJustification = {
|
||||||
|
hash: string,
|
||||||
|
round_number: number,
|
||||||
|
signatures: Array<[string, string]>
|
||||||
|
};
|
||||||
|
|
||||||
export type JsonBlock = {
|
export type JsonBlock = {
|
||||||
block: {
|
block: {
|
||||||
|
|||||||
Reference in New Issue
Block a user