@@ -341,15 +341,17 @@ function decodeHeader(data: RpcHeader): responses.Header {
341341 height : Integer . parse ( assertNotEmpty ( data . height ) ) ,
342342 time : fromRfc3339WithNanoseconds ( assertNotEmpty ( data . time ) ) ,
343343
344- lastBlockId : decodeBlockId ( data . last_block_id ) ,
344+ // When there is no last block ID (i.e. this block's height is 1), we get an empty structure like this:
345+ // { hash: '', parts: { total: 0, hash: '' } }
346+ lastBlockId : data . last_block_id . hash ? decodeBlockId ( data . last_block_id ) : null ,
345347
346- lastCommitHash : fromHex ( assertNotEmpty ( data . last_commit_hash ) ) ,
348+ lastCommitHash : fromHex ( assertSet ( data . last_commit_hash ) ) ,
347349 dataHash : fromHex ( assertSet ( data . data_hash ) ) ,
348350
349- validatorsHash : fromHex ( assertNotEmpty ( data . validators_hash ) ) ,
350- nextValidatorsHash : fromHex ( assertNotEmpty ( data . next_validators_hash ) ) ,
351- consensusHash : fromHex ( assertNotEmpty ( data . consensus_hash ) ) ,
352- appHash : fromHex ( assertNotEmpty ( data . app_hash ) ) ,
351+ validatorsHash : fromHex ( assertSet ( data . validators_hash ) ) ,
352+ nextValidatorsHash : fromHex ( assertSet ( data . next_validators_hash ) ) ,
353+ consensusHash : fromHex ( assertSet ( data . consensus_hash ) ) ,
354+ appHash : fromHex ( assertSet ( data . app_hash ) ) ,
353355 lastResultsHash : fromHex ( assertSet ( data . last_results_hash ) ) ,
354356
355357 evidenceHash : fromHex ( assertSet ( data . evidence_hash ) ) ,
@@ -765,7 +767,9 @@ interface RpcBlock {
765767function decodeBlock ( data : RpcBlock ) : responses . Block {
766768 return {
767769 header : decodeHeader ( assertObject ( data . header ) ) ,
768- lastCommit : decodeCommit ( assertObject ( data . last_commit ) ) ,
770+ // For the block at height 1, last commit is not set. This is represented in an empty object like this:
771+ // { height: '0', round: 0, block_id: { hash: '', parts: [Object] }, signatures: [] }
772+ lastCommit : data . last_commit . block_id . hash ? decodeCommit ( assertObject ( data . last_commit ) ) : null ,
769773 txs : data . data . txs ? assertArray ( data . data . txs ) . map ( fromBase64 ) : [ ] ,
770774 evidence : data . evidence && may ( decodeEvidences , data . evidence . evidence ) ,
771775 } ;
@@ -783,6 +787,18 @@ function decodeBlockResponse(data: RpcBlockResponse): responses.BlockResponse {
783787 } ;
784788}
785789
790+ interface RpcBlockSearchResponse {
791+ readonly blocks : readonly RpcBlockResponse [ ] ;
792+ readonly total_count : string ;
793+ }
794+
795+ function decodeBlockSearch ( data : RpcBlockSearchResponse ) : responses . BlockSearchResponse {
796+ return {
797+ totalCount : Integer . parse ( assertNotEmpty ( data . total_count ) ) ,
798+ blocks : assertArray ( data . blocks ) . map ( decodeBlockResponse ) ,
799+ } ;
800+ }
801+
786802export class Responses {
787803 public static decodeAbciInfo ( response : JsonRpcSuccessResponse ) : responses . AbciInfoResponse {
788804 return decodeAbciInfo ( assertObject ( ( response . result as AbciInfoResult ) . response ) ) ;
@@ -800,6 +816,10 @@ export class Responses {
800816 return decodeBlockResults ( response . result as RpcBlockResultsResponse ) ;
801817 }
802818
819+ public static decodeBlockSearch ( response : JsonRpcSuccessResponse ) : responses . BlockSearchResponse {
820+ return decodeBlockSearch ( response . result as RpcBlockSearchResponse ) ;
821+ }
822+
803823 public static decodeBlockchain ( response : JsonRpcSuccessResponse ) : responses . BlockchainResponse {
804824 return decodeBlockchain ( response . result as RpcBlockchainResponse ) ;
805825 }
0 commit comments