Skip to content

Commit

Permalink
add query parameters to API client (#488)
Browse files Browse the repository at this point in the history
* add query parameters to API client

* changelog

* lint

* lint
  • Loading branch information
benarena authored May 17, 2023
1 parent 231dbda commit 8e745f9
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 77 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Fixed `/api/v3/validators` url
* Now handling no fee amount in the tx
* Now handling Exec'd governance msgs, and properly handling weights from v1.Gov msgs
* Added object mapper and query parameters to `api-client` [#487](https://github.com/provenance-io/explorer-service/issues/487)

### Data
* Migration 1.88 - Add `block_time_spread`, `validator_metrics` #482
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.provenance.explorer.client
import feign.Headers
import feign.Param
import feign.RequestLine
import io.provenance.explorer.client.BaseRoutes.PAGE_PARAMETERS
import io.provenance.explorer.model.AccountDetail
import io.provenance.explorer.model.AccountFlags
import io.provenance.explorer.model.AccountRewards
Expand Down Expand Up @@ -40,7 +41,7 @@ interface AccountClient : BaseClient {
@RequestLine("GET ${AccountRoutes.ACCOUNT}")
fun account(@Param("address") address: String): AccountDetail

@RequestLine("GET ${AccountRoutes.DELEGATIONS}")
@RequestLine("GET ${AccountRoutes.DELEGATIONS}?$PAGE_PARAMETERS")
fun delegations(
@Param("address") address: String,
@Param("count") count: Int = 10,
Expand All @@ -56,27 +57,27 @@ interface AccountClient : BaseClient {
@RequestLine("GET ${AccountRoutes.REWARDS}")
fun rewards(@Param("address") address: String): AccountRewards

@RequestLine("GET ${AccountRoutes.BALANCES}")
@RequestLine("GET ${AccountRoutes.BALANCES}?$PAGE_PARAMETERS")
fun balances(
@Param("address") address: String,
@Param("count") count: Int = 10,
@Param("page") page: Int = 1
): PagedResults<DenomBalanceBreakdown>

@RequestLine("GET ${AccountRoutes.VESTING}")
@RequestLine("GET ${AccountRoutes.VESTING}?continuousPeriod={continuousPeriod}")
fun vestingSchedule(
@Param("address") address: String,
@Param("continuousPeriod") continuousPeriod: PeriodInSeconds = PeriodInSeconds.DAY
): AccountVestingInfo

@RequestLine("GET ${AccountRoutes.BALANCES_AT_HEIGHT}")
@RequestLine("GET ${AccountRoutes.BALANCES_AT_HEIGHT}?height={height}&denom={denom}")
fun balancesAtHeight(
@Param("address") address: String,
@Param("height") height: Int,
@Param("denom") denom: String? = null
): List<CoinStr>

@RequestLine("GET ${AccountRoutes.FEEPAYER_HISTORY}")
@RequestLine("GET ${AccountRoutes.FEEPAYER_HISTORY}?fromDate={fromDate}&toDate={toDate}&granularity={granularity}")
fun feepayerHistory(
@Param("address") address: String,
@Param("fromDate") fromDate: DateTime? = null,
Expand All @@ -85,7 +86,10 @@ interface AccountClient : BaseClient {
): List<TxHistoryChartData>

@RequestLine("GET ${AccountRoutes.BALANCES_BY_DENOM}")
fun balanceByDenom(@Param("address") address: String, @Param("denom") denom: String): DenomBalanceBreakdown
fun balanceByDenom(
@Param("address") address: String,
@Param("denom") denom: String
): DenomBalanceBreakdown

@RequestLine("GET ${AccountRoutes.BALANCES_BY_UTILITY_TOKEN}")
fun balanceByUtilityToken(@Param("address") address: String): DenomBalanceBreakdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode
import feign.Headers
import feign.Param
import feign.RequestLine
import io.provenance.explorer.client.BaseRoutes.PAGE_PARAMETERS
import io.provenance.explorer.model.AssetDetail
import io.provenance.explorer.model.AssetHolder
import io.provenance.explorer.model.AssetListed
Expand All @@ -24,7 +25,7 @@ object AssetRoutes {
@Headers(BaseClient.CT_JSON)
interface AssetClient : BaseClient {

@RequestLine("GET ${AssetRoutes.ALL}")
@RequestLine("GET ${AssetRoutes.ALL}?$PAGE_PARAMETERS&statuses={statuses}")
fun all(
@Param("statuses") statuses: List<MarkerStatus> = listOf(MarkerStatus.MARKER_STATUS_ACTIVE),
@Param("count") count: Int = 10,
Expand All @@ -37,13 +38,13 @@ interface AssetClient : BaseClient {
@RequestLine("GET ${AssetRoutes.DETAIL_IBC}")
fun ibcAsset(@Param("hash") hash: String): IbcDenomDetail

@RequestLine("GET ${AssetRoutes.HOLDERS}")
@RequestLine("GET ${AssetRoutes.HOLDERS}?$PAGE_PARAMETERS")
fun assetHolders(
@Param("denom") denom: String,
@Param("count") count: Int = 10,
@Param("page") page: Int = 1
): PagedResults<AssetHolder>

@RequestLine("GET ${AssetRoutes.METADATA}")
@RequestLine("GET ${AssetRoutes.METADATA}?denom={denom}")
fun metadata(@Param("denom") denom: String? = null): List<ObjectNode>
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import feign.jackson.JacksonEncoder
object BaseRoutes {
const val V2_BASE = "/api/v2"
const val V3_BASE = "/api/v3"
const val PAGE_PARAMETERS = "page={page}&count={count}"
}

interface BaseClient {
Expand All @@ -16,10 +17,13 @@ interface BaseClient {
}
}

class ExplorerClient(url: String) {
class ExplorerClient(
url: String,
objectMapper: ObjectMapper = ObjectMapper()
) {
companion object {
private fun builder(
withMapper: ObjectMapper = ObjectMapper(),
withMapper: ObjectMapper,
withBuilder: Feign.Builder =
Feign.builder()
.encoder(JacksonEncoder(withMapper))
Expand All @@ -28,17 +32,17 @@ class ExplorerClient(url: String) {
) = withBuilder
}

val accountClient = builder().target(AccountClient::class.java, url)
val assetClient = builder().target(AssetClient::class.java, url)
val blockClient = builder().target(BlockClient::class.java, url)
val generalClient = builder().target(GeneralClient::class.java, url)
val governanceClient = builder().target(GovernanceClient::class.java, url)
val grantsClient = builder().target(GrantsClient::class.java, url)
val ibcClient = builder().target(IbcClient::class.java, url)
val nameClient = builder().target(NameClient::class.java, url)
val nftClient = builder().target(NftClient::class.java, url)
val smartContractClient = builder().target(SmartContractClient::class.java, url)
val tokenClient = builder().target(TokenClient::class.java, url)
val transactionClient = builder().target(TransactionClient::class.java, url)
val validatorClient = builder().target(ValidatorClient::class.java, url)
val accountClient = builder(objectMapper).target(AccountClient::class.java, url)
val assetClient = builder(objectMapper).target(AssetClient::class.java, url)
val blockClient = builder(objectMapper).target(BlockClient::class.java, url)
val generalClient = builder(objectMapper).target(GeneralClient::class.java, url)
val governanceClient = builder(objectMapper).target(GovernanceClient::class.java, url)
val grantsClient = builder(objectMapper).target(GrantsClient::class.java, url)
val ibcClient = builder(objectMapper).target(IbcClient::class.java, url)
val nameClient = builder(objectMapper).target(NameClient::class.java, url)
val nftClient = builder(objectMapper).target(NftClient::class.java, url)
val smartContractClient = builder(objectMapper).target(SmartContractClient::class.java, url)
val tokenClient = builder(objectMapper).target(TokenClient::class.java, url)
val transactionClient = builder(objectMapper).target(TransactionClient::class.java, url)
val validatorClient = builder(objectMapper).target(ValidatorClient::class.java, url)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.provenance.explorer.client
import feign.Headers
import feign.Param
import feign.RequestLine
import io.provenance.explorer.client.BaseRoutes.PAGE_PARAMETERS
import io.provenance.explorer.model.BlockSummary
import io.provenance.explorer.model.base.PagedResults

Expand All @@ -16,8 +17,11 @@ object BlockRoutes {
@Headers(BaseClient.CT_JSON)
interface BlockClient : BaseClient {

@RequestLine("GET ${BlockRoutes.RECENT}")
fun recent(@Param("count") count: Int = 10, @Param("page") page: Int = 1): PagedResults<BlockSummary>
@RequestLine("GET ${BlockRoutes.RECENT}?$PAGE_PARAMETERS")
fun recent(
@Param("count") count: Int = 10,
@Param("page") page: Int = 1
): PagedResults<BlockSummary>

@RequestLine("GET ${BlockRoutes.CURRENT_HEIGHT}")
fun currentHeight(): BlockSummary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ interface GeneralClient : BaseClient {
@RequestLine("GET ${GeneralRoutes.SPOTLIGHT}")
fun spotlight(): Spotlight?

@RequestLine("GET ${GeneralRoutes.GAS_STATS}")
@RequestLine("GET ${GeneralRoutes.GAS_STATS}?fromDate={fromDate}&toDate={toDate}&granularity={granularity}&msgType={msgType}")
fun gasStats(
@Param("fromDate") fromDate: DateTime,
@Param("toDate") toDate: DateTime,
@Param("granularity") granularity: DateTruncGranularity = DateTruncGranularity.DAY,
@Param("msgType") msgType: String? = null
): List<GasStats>

@RequestLine("GET ${GeneralRoutes.GAS_VOLUME}")
@RequestLine("GET ${GeneralRoutes.GAS_VOLUME}?fromDate={fromDate}&toDate={toDate}&granularity={granularity}")
fun gasVolume(
@Param("fromDate") fromDate: DateTime,
@Param("toDate") toDate: DateTime,
Expand All @@ -59,14 +59,14 @@ interface GeneralClient : BaseClient {
@RequestLine("GET ${GeneralRoutes.CHAIN_ID}")
fun chainId(): String

@RequestLine("GET ${GeneralRoutes.CHAIN_MARKET_RATE_PERIOD}")
@RequestLine("GET ${GeneralRoutes.CHAIN_MARKET_RATE_PERIOD}?fromDate={fromDate}&toDate={toDate}&dayCount={dayCount}")
fun marketRateOverTime(
@Param("fromDate") fromDate: DateTime,
@Param("toDate") toDate: DateTime,
@Param("dayCount") dayCount: Int = 14
): List<ChainMarketRate>

@RequestLine("GET ${GeneralRoutes.CHAIN_MARKET_RATE}")
@RequestLine("GET ${GeneralRoutes.CHAIN_MARKET_RATE}?blockCount={blockCount}")
fun avgMarketRate(@Param("blockCount") blockCount: Int = 500): MarketRateAvg

@RequestLine("GET ${GeneralRoutes.CHAIN_UPGRADES}")
Expand All @@ -78,7 +78,7 @@ interface GeneralClient : BaseClient {
@RequestLine("GET ${GeneralRoutes.CHAIN_MSG_BASED_FEES}")
fun msgBasedFees(): List<MsgBasedFee>

@RequestLine("GET ${GeneralRoutes.CHAIN_AUM_LIST}")
@RequestLine("GET ${GeneralRoutes.CHAIN_AUM_LIST}?fromDate={fromDate}&toDate={toDate}&dayCount={dayCount}")
fun aumOverTime(
@Param("fromDate") fromDate: DateTime? = null,
@Param("toDate") toDate: DateTime? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.provenance.explorer.client
import feign.Headers
import feign.Param
import feign.RequestLine
import io.provenance.explorer.client.BaseRoutes.PAGE_PARAMETERS
import io.provenance.explorer.model.DepositRecord
import io.provenance.explorer.model.GovProposalDetail
import io.provenance.explorer.model.VoteRecord
Expand All @@ -21,7 +22,7 @@ object GovernanceRoutes {
@Headers(BaseClient.CT_JSON)
interface GovernanceClient : BaseClient {

@RequestLine("GET ${GovernanceRoutes.ALL}")
@RequestLine("GET ${GovernanceRoutes.ALL}?$PAGE_PARAMETERS")
fun allProposals(
@Param("count") count: Int = 10,
@Param("page") page: Int = 1
Expand All @@ -30,21 +31,21 @@ interface GovernanceClient : BaseClient {
@RequestLine("GET ${GovernanceRoutes.PROPOSAL}")
fun proposal(@Param("id") id: Long): GovProposalDetail

@RequestLine("GET ${GovernanceRoutes.DEPOSITS}")
@RequestLine("GET ${GovernanceRoutes.DEPOSITS}?$PAGE_PARAMETERS")
fun proposalDeposits(
@Param("id") id: Long,
@Param("count") count: Int = 10,
@Param("page") page: Int = 1
): PagedResults<DepositRecord>

@RequestLine("GET ${GovernanceRoutes.VOTES}")
@RequestLine("GET ${GovernanceRoutes.VOTES}?$PAGE_PARAMETERS")
fun proposalVotes(
@Param("id") id: Long,
@Param("count") count: Int = 10,
@Param("page") page: Int = 1
): PagedResults<VoteRecord>

@RequestLine("GET ${GovernanceRoutes.VOTES_BY_ADDRESS}")
@RequestLine("GET ${GovernanceRoutes.VOTES_BY_ADDRESS}?$PAGE_PARAMETERS")
fun votesByAddress(
@Param("address") address: String,
@Param("count") count: Int = 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.provenance.explorer.client
import feign.Headers
import feign.Param
import feign.RequestLine
import io.provenance.explorer.client.BaseRoutes.PAGE_PARAMETERS
import io.provenance.explorer.model.FeegrantData
import io.provenance.explorer.model.GrantData
import io.provenance.explorer.model.base.PagedResults
Expand All @@ -18,28 +19,28 @@ object GrantsRoutes {
@Headers(BaseClient.CT_JSON)
interface GrantsClient : BaseClient {

@RequestLine("GET ${GrantsRoutes.GRANTS_AS_GRANTEE}")
@RequestLine("GET ${GrantsRoutes.GRANTS_AS_GRANTEE}?$PAGE_PARAMETERS")
fun grantsAsGrantee(
@Param("address") address: String,
@Param("count") count: Int = 10,
@Param("page") page: Int = 1
): PagedResults<GrantData>

@RequestLine("GET ${GrantsRoutes.GRANTS_AS_GRANTER}")
@RequestLine("GET ${GrantsRoutes.GRANTS_AS_GRANTER}?$PAGE_PARAMETERS")
fun grantsAsGranter(
@Param("address") address: String,
@Param("count") count: Int = 10,
@Param("page") page: Int = 1
): PagedResults<GrantData>

@RequestLine("GET ${GrantsRoutes.FEEGRANTS_AS_GRANTEE}")
@RequestLine("GET ${GrantsRoutes.FEEGRANTS_AS_GRANTEE}?$PAGE_PARAMETERS")
fun feegrantsAsGrantee(
@Param("address") address: String,
@Param("count") count: Int = 10,
@Param("page") page: Int = 1
): PagedResults<FeegrantData>

@RequestLine("GET ${GrantsRoutes.FEEGRANTS_AS_GRANTER}")
@RequestLine("GET ${GrantsRoutes.FEEGRANTS_AS_GRANTER}?$PAGE_PARAMETERS")
fun feegrantsAsGranter(
@Param("address") address: String,
@Param("count") count: Int = 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import feign.Headers
import feign.Param
import feign.RequestLine
import ibc.core.channel.v1.ChannelOuterClass
import io.provenance.explorer.client.BaseRoutes.PAGE_PARAMETERS
import io.provenance.explorer.model.Balance
import io.provenance.explorer.model.BalancesByChain
import io.provenance.explorer.model.BalancesByChannel
Expand All @@ -17,18 +18,21 @@ object IbcRoutes {
const val ALL = "$IBC_V2/denoms"
const val CHANNELS = "$IBC_V2/channels/status"
const val BALANCES_BY_DENOM = "$IBC_V2/balances/denom"
const val BALANCES_BY_CHAIN = "$IBC_V2/channels/status"
const val BALANCES_BY_CHANNEL = "$IBC_V2/channels/status"
const val BALANCES_BY_CHAIN = "$IBC_V2/balances/chain"
const val BALANCES_BY_CHANNEL = "$IBC_V2/balances/channel"
const val RELAYERS_BY_CHANNEL = "$IBC_V2/channels/src_port/{srcPort}/src_channel/{srcChannel}/relayers"
}

@Headers(BaseClient.CT_JSON)
interface IbcClient : BaseClient {

@RequestLine("GET ${IbcRoutes.ALL}")
fun allDenoms(@Param("count") count: Int = 10, @Param("page") page: Int = 1): PagedResults<IbcDenomListed>
@RequestLine("GET ${IbcRoutes.ALL}?$PAGE_PARAMETERS")
fun allDenoms(
@Param("count") count: Int = 10,
@Param("page") page: Int = 1
): PagedResults<IbcDenomListed>

@RequestLine("GET ${IbcRoutes.CHANNELS}")
@RequestLine("GET ${IbcRoutes.CHANNELS}?status={status}")
fun channelsByStatus(
@Param("status") status: ChannelOuterClass.State = ChannelOuterClass.State.STATE_OPEN
): List<IbcChannelStatus>
Expand All @@ -39,7 +43,7 @@ interface IbcClient : BaseClient {
@RequestLine("GET ${IbcRoutes.BALANCES_BY_CHAIN}")
fun balancesByChain(): List<BalancesByChain>

@RequestLine("GET ${IbcRoutes.BALANCES_BY_CHANNEL}")
@RequestLine("GET ${IbcRoutes.BALANCES_BY_CHANNEL}?srcPort={srcPort}&srcChannel={srcChannel}")
fun balancesByChannel(
@Param("srcPort") srcPort: String? = null,
@Param("srcChannel") srcChannel: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.provenance.explorer.client
import feign.Headers
import feign.Param
import feign.RequestLine
import io.provenance.explorer.client.BaseRoutes.PAGE_PARAMETERS
import io.provenance.explorer.model.NameObj
import io.provenance.explorer.model.NameTreeResponse
import io.provenance.explorer.model.base.PagedResults
Expand All @@ -19,7 +20,7 @@ interface NameClient : BaseClient {
@RequestLine("GET ${NameRoutes.TREE}")
fun tree(): NameTreeResponse

@RequestLine("GET ${NameRoutes.OWNED}")
@RequestLine("GET ${NameRoutes.OWNED}?$PAGE_PARAMETERS")
fun ownedByAddress(
@Param("address") address: String,
@Param("count") count: Int = 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode
import feign.Headers
import feign.Param
import feign.RequestLine
import io.provenance.explorer.client.BaseRoutes.PAGE_PARAMETERS
import io.provenance.explorer.model.ScopeDetail
import io.provenance.explorer.model.ScopeListview
import io.provenance.explorer.model.ScopeRecord
Expand All @@ -25,7 +26,7 @@ interface NftClient : BaseClient {
@RequestLine("GET ${NftRoutes.SCOPE}")
fun scope(@Param("addr") addr: String): ScopeDetail

@RequestLine("GET ${NftRoutes.SCOPES_BY_OWNER}")
@RequestLine("GET ${NftRoutes.SCOPES_BY_OWNER}?$PAGE_PARAMETERS")
fun scopesByOwner(
@Param("address") address: String,
@Param("count") count: Int = 10,
Expand Down
Loading

0 comments on commit 8e745f9

Please sign in to comment.