Expose abci query proofs in tendermint
This commit is contained in:
parent
7f5269d6f8
commit
a6e0cdee10
@ -161,6 +161,8 @@ export class QueryClient {
|
||||
throw new Error(`Response key ${toHex(response.key)} doesn't match query key ${toHex(key)}`);
|
||||
}
|
||||
|
||||
assert(response.proof);
|
||||
|
||||
// TODO: implement proof verification
|
||||
// https://github.com/CosmWasm/cosmjs/issues/347
|
||||
|
||||
|
||||
@ -25,9 +25,20 @@ export interface AbciInfoResponse {
|
||||
readonly lastBlockAppHash?: Uint8Array;
|
||||
}
|
||||
|
||||
export interface ProofOp {
|
||||
readonly type: string;
|
||||
readonly key: Uint8Array;
|
||||
readonly data: Uint8Array;
|
||||
}
|
||||
|
||||
export interface QueryProof {
|
||||
readonly ops: readonly ProofOp[];
|
||||
}
|
||||
|
||||
export interface AbciQueryResponse {
|
||||
readonly key: Uint8Array;
|
||||
readonly value: Uint8Array;
|
||||
readonly proof?: QueryProof;
|
||||
readonly height?: number;
|
||||
readonly index?: number;
|
||||
readonly code?: number; // non-falsy for errors
|
||||
|
||||
@ -25,6 +25,7 @@ import * as responses from "../responses";
|
||||
import { SubscriptionEvent } from "../rpcclients";
|
||||
import { IpPortString, TxBytes, TxHash, ValidatorPubkey, ValidatorSignature } from "../types";
|
||||
import { hashTx } from "./hasher";
|
||||
import { isArgon2idOptions } from "@cosmjs/crypto";
|
||||
|
||||
interface AbciInfoResult {
|
||||
readonly response: RpcAbciInfoResponse;
|
||||
@ -48,10 +49,30 @@ interface AbciQueryResult {
|
||||
readonly response: RpcAbciQueryResponse;
|
||||
}
|
||||
|
||||
export interface RpcProofOp {
|
||||
readonly type: string;
|
||||
readonly key: Base64String;
|
||||
readonly data: Base64String;
|
||||
}
|
||||
|
||||
export interface RpcQueryProof {
|
||||
readonly ops: readonly RpcProofOp[];
|
||||
}
|
||||
|
||||
function decodeQueryProof(data: RpcQueryProof): responses.QueryProof {
|
||||
return {
|
||||
ops: data.ops.map((op) => ({
|
||||
type: op.type,
|
||||
key: Base64.decode(op.key),
|
||||
data: Base64.decode(op.data),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
interface RpcAbciQueryResponse {
|
||||
readonly key: Base64String;
|
||||
readonly value?: Base64String;
|
||||
readonly proof?: Base64String;
|
||||
readonly proof?: RpcQueryProof;
|
||||
readonly height?: IntegerString;
|
||||
readonly index?: IntegerString;
|
||||
readonly code?: IntegerString; // only for errors
|
||||
@ -62,7 +83,7 @@ function decodeAbciQuery(data: RpcAbciQueryResponse): responses.AbciQueryRespons
|
||||
return {
|
||||
key: Base64.decode(optional(data.key, "" as Base64String)),
|
||||
value: Base64.decode(optional(data.value, "" as Base64String)),
|
||||
// proof: may(Base64.decode, data.proof),
|
||||
proof: may(decodeQueryProof, data.proof),
|
||||
height: may(Integer.parse, data.height),
|
||||
code: may(Integer.parse, data.code),
|
||||
index: may(Integer.parse, data.index),
|
||||
|
||||
9
packages/tendermint-rpc/types/responses.d.ts
vendored
9
packages/tendermint-rpc/types/responses.d.ts
vendored
@ -21,9 +21,18 @@ export interface AbciInfoResponse {
|
||||
readonly lastBlockHeight?: number;
|
||||
readonly lastBlockAppHash?: Uint8Array;
|
||||
}
|
||||
export interface ProofOp {
|
||||
readonly type: string;
|
||||
readonly key: Uint8Array;
|
||||
readonly data: Uint8Array;
|
||||
}
|
||||
export interface QueryProof {
|
||||
readonly ops: readonly ProofOp[];
|
||||
}
|
||||
export interface AbciQueryResponse {
|
||||
readonly key: Uint8Array;
|
||||
readonly value: Uint8Array;
|
||||
readonly proof?: QueryProof;
|
||||
readonly height?: number;
|
||||
readonly index?: number;
|
||||
readonly code?: number;
|
||||
|
||||
@ -1,6 +1,15 @@
|
||||
import { JsonRpcSuccessResponse } from "@cosmjs/json-rpc";
|
||||
import { Base64String } from "../encodings";
|
||||
import * as responses from "../responses";
|
||||
import { SubscriptionEvent } from "../rpcclients";
|
||||
export interface RpcProofOp {
|
||||
readonly type: string;
|
||||
readonly key: Base64String;
|
||||
readonly data: Base64String;
|
||||
}
|
||||
export interface RpcQueryProof {
|
||||
readonly ops: readonly RpcProofOp[];
|
||||
}
|
||||
export declare class Responses {
|
||||
static decodeAbciInfo(response: JsonRpcSuccessResponse): responses.AbciInfoResponse;
|
||||
static decodeAbciQuery(response: JsonRpcSuccessResponse): responses.AbciQueryResponse;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user