From fa78a7460cd5da18da5f2ef279eb2527418f23db Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sat, 15 Feb 2020 15:44:12 +0100 Subject: [PATCH] Fix broken BlockResponse types --- packages/bcp/src/cosmwasmconnection.ts | 10 +++++----- packages/sdk/src/restclient.ts | 26 ++++++++++++++------------ packages/sdk/types/restclient.d.ts | 20 +++++++++----------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/packages/bcp/src/cosmwasmconnection.ts b/packages/bcp/src/cosmwasmconnection.ts index 5b37b935..53d415e5 100644 --- a/packages/bcp/src/cosmwasmconnection.ts +++ b/packages/bcp/src/cosmwasmconnection.ts @@ -218,12 +218,12 @@ export class CosmWasmConnection implements BlockchainConnection { public async getBlockHeader(height: number): Promise { // tslint:disable-next-line: deprecation - const { block_meta } = await this.restClient.blocks(height); + const { block_id, block } = await this.restClient.blocks(height); return { - id: block_meta.block_id.hash as BlockId, - height: block_meta.header.height, - time: new ReadonlyDate(block_meta.header.time), - transactionCount: block_meta.header.num_txs, + id: block_id.hash as BlockId, + height: parseInt(block.header.height, 10), + time: new ReadonlyDate(block.header.time), + transactionCount: block.data.txs?.length || 0, }; } diff --git a/packages/sdk/src/restclient.ts b/packages/sdk/src/restclient.ts index 61b8bb24..4377d315 100644 --- a/packages/sdk/src/restclient.ts +++ b/packages/sdk/src/restclient.ts @@ -22,20 +22,11 @@ interface NodeInfoResponse { readonly node_info: NodeInfo; } -export interface BlockMeta { - readonly header: { - readonly height: number; - readonly time: string; - readonly num_txs: number; - }; - readonly block_id: { - readonly hash: string; - }; -} - export interface BlockHeader { readonly height: string; readonly chain_id: string; + /** An RFC 3339 time string like e.g. '2020-02-15T10:39:10.4696305Z' */ + readonly time: string; // TODO: add all of those // header: { // version: [Object], @@ -57,10 +48,21 @@ export interface BlockHeader { export interface Block { readonly header: BlockHeader; + readonly data: { + /** Array of base64 encoded transactions */ + readonly txs: ReadonlyArray | null; + }; } export interface BlockResponse { - readonly block_meta: BlockMeta; + readonly block_id: { + readonly hash: string; + // TODO: here we also have this + // parts: { + // total: '1', + // hash: '7AF200C78FBF9236944E1AB270F4045CD60972B7C265E3A9DA42973397572931' + // } + }; readonly block: Block; } diff --git a/packages/sdk/types/restclient.d.ts b/packages/sdk/types/restclient.d.ts index a67bc175..b14fbd86 100644 --- a/packages/sdk/types/restclient.d.ts +++ b/packages/sdk/types/restclient.d.ts @@ -5,25 +5,23 @@ interface NodeInfo { interface NodeInfoResponse { readonly node_info: NodeInfo; } -export interface BlockMeta { - readonly header: { - readonly height: number; - readonly time: string; - readonly num_txs: number; - }; - readonly block_id: { - readonly hash: string; - }; -} export interface BlockHeader { readonly height: string; readonly chain_id: string; + /** An RFC 3339 time string like e.g. '2020-02-15T10:39:10.4696305Z' */ + readonly time: string; } export interface Block { readonly header: BlockHeader; + readonly data: { + /** Array of base64 encoded transactions */ + readonly txs: ReadonlyArray | null; + }; } export interface BlockResponse { - readonly block_meta: BlockMeta; + readonly block_id: { + readonly hash: string; + }; readonly block: Block; } interface AuthAccountsResponse {