import { ObservableChainQuery , ObservableChainQueryMap , } from "../../chain-query" ; import { Block } from "@cosmjs/tendermint-rpc" ; import { KVStore } from "@keplr-wallet/common" ; import { ChainGetter } from "../../../common" ; import { computed , makeObservable } from "mobx" ; import { Int } from "@keplr-wallet/unit" ; export class ObservableQueryBlockInner extends ObservableChainQuery < { block : Block ; } > { constructor ( kvStore , chainId , chainGetter , protected readonly paramHeight ) { super ( kvStore , chainId , chainGetter , `/blocks/${ paramHeight }` ) ; makeObservable ( this ) ; } /**
     * Return the block height.
     * If fetching is not completed or failed, return the 0 Int.
     */ @ computed get height ( ) : Int { if ( ! this . response ) { return new Int ( "0" ) ; } return new Int ( this . response . data . block . header . height ) ; } } export class ObservableQueryBlock extends ObservableChainQueryMap < { block : Block ; } > { constructor ( protected readonly kvStore , protected readonly chainId , protected readonly chainGetter ) { super ( kvStore , chainId , chainGetter , ( height ) => { const param = height === "latest" ? height : parseInt ( height ) ; return new ObservableQueryBlockInner ( this . kvStore , this . chainId , this . chainGetter , param ) ; } ) ; } getBlock ( height ) { return this . get ( height . toString ( ) ) as ObservableQueryBlockInner ; } }