mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 13:47:12 +00:00
Merge pull request #1012 from cosmos/dont-parse-evidence
Avoid parsing evidence from Tendermint
This commit is contained in:
commit
5743d55229
@ -17,8 +17,13 @@ and this project adheres to
|
||||
|
||||
- @cosmjs/stargate: The error messages for missing types in `AminoTypes` now
|
||||
contain the type that was searched for ([#990]).
|
||||
- @cosmjs/tendermint-rpc: Change the `Evidence` type to `any` and avoid decoding
|
||||
it. The structure we had before was outdated and trying to decode it led to
|
||||
exceptions at runtime when a block with actual values was encountered.
|
||||
([#980])
|
||||
|
||||
[#990]: https://github.com/cosmos/cosmjs/pull/990
|
||||
[#980]: https://github.com/cosmos/cosmjs/issues/980
|
||||
|
||||
## [0.27.0] - 2022-01-10
|
||||
|
||||
|
@ -730,27 +730,9 @@ function decodeValidators(data: RpcValidatorsResponse): responses.ValidatorsResp
|
||||
};
|
||||
}
|
||||
|
||||
interface RpcEvidence {
|
||||
readonly type: string;
|
||||
readonly validator: RpcValidatorUpdate;
|
||||
readonly height: string;
|
||||
readonly time: string;
|
||||
readonly totalVotingPower: string;
|
||||
}
|
||||
|
||||
function decodeEvidence(data: RpcEvidence): responses.Evidence {
|
||||
return {
|
||||
type: assertNotEmpty(data.type),
|
||||
height: Integer.parse(assertNotEmpty(data.height)),
|
||||
time: Integer.parse(assertNotEmpty(data.time)),
|
||||
totalVotingPower: Integer.parse(assertNotEmpty(data.totalVotingPower)),
|
||||
validator: decodeValidatorUpdate(data.validator),
|
||||
};
|
||||
}
|
||||
|
||||
function decodeEvidences(ev: readonly RpcEvidence[]): readonly responses.Evidence[] {
|
||||
return assertArray(ev).map(decodeEvidence);
|
||||
}
|
||||
// We lost track on how the evidence structure actually looks like.
|
||||
// This is any now and passed to the caller untouched.
|
||||
type RpcEvidence = any;
|
||||
|
||||
interface RpcBlock {
|
||||
readonly header: RpcHeader;
|
||||
@ -759,6 +741,8 @@ interface RpcBlock {
|
||||
/** Raw tx bytes, base64 encoded */
|
||||
readonly txs?: readonly string[];
|
||||
};
|
||||
// It's currently unclear why the deep nesting is requied.
|
||||
// See https://github.com/tendermint/tendermint/issues/7697.
|
||||
readonly evidence?: {
|
||||
readonly evidence?: readonly RpcEvidence[];
|
||||
};
|
||||
@ -771,7 +755,9 @@ function decodeBlock(data: RpcBlock): responses.Block {
|
||||
// { height: '0', round: 0, block_id: { hash: '', parts: [Object] }, signatures: [] }
|
||||
lastCommit: data.last_commit.block_id.hash ? decodeCommit(assertObject(data.last_commit)) : null,
|
||||
txs: data.data.txs ? assertArray(data.data.txs).map(fromBase64) : [],
|
||||
evidence: data.evidence && may(decodeEvidences, data.evidence.evidence),
|
||||
// Lift up .evidence.evidence to just .evidence
|
||||
// See https://github.com/tendermint/tendermint/issues/7697
|
||||
evidence: data.evidence?.evidence,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -227,16 +227,17 @@ export interface Block {
|
||||
*/
|
||||
readonly lastCommit: Commit | null;
|
||||
readonly txs: readonly Uint8Array[];
|
||||
// This field becomes non-optional in 0.28 (https://github.com/cosmos/cosmjs/issues/1011)
|
||||
readonly evidence?: readonly Evidence[];
|
||||
}
|
||||
|
||||
export interface Evidence {
|
||||
readonly type: string;
|
||||
readonly validator: Validator;
|
||||
readonly height: number;
|
||||
readonly time: number;
|
||||
readonly totalVotingPower: number;
|
||||
}
|
||||
/**
|
||||
* We lost track on how the evidence structure actually looks like.
|
||||
* This is any now and passed to the caller untouched.
|
||||
*
|
||||
* See also https://github.com/cosmos/cosmjs/issues/980.
|
||||
*/
|
||||
export type Evidence = any;
|
||||
|
||||
export interface Commit {
|
||||
readonly blockId: BlockId;
|
||||
|
Loading…
x
Reference in New Issue
Block a user