Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically add new provenances protos to JsonFormat.TypeRegistry #513

Merged
merged 9 commits into from
Mar 12, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements
* Updated Prov Protos to 1.18.0-rc2 [#510](https://github.com/provenance-io/explorer-service/issues/510)
* Automate the registration of Provenance protobuf module descriptors [#514](https://github.com/provenance-io/explorer-service/issues/514)

## [v5.7.0](https://github.com/provenance-io/explorer-service/releases/tag/v5.7.0) - 2023-11-14
### Release Name: Peter Fidler
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ object Versions {
const val ProvProto = "1.18.0-rc2"
const val Postgres = "42.2.23"
const val Protobuf = "3.21.9"
const val Reflections = "0.9.12"

// Testing
const val Jupiter = "5.9.1"
Expand Down Expand Up @@ -89,6 +90,7 @@ object Libraries {
const val KtorClientContentNeg = "io.ktor:ktor-client-content-negotiation:${Versions.Ktor}"
const val KaseChange = "net.pearx.kasechange:kasechange:${Versions.KaseChange}"
const val Json = "org.json:json:${Versions.Json}"
const val Reflections = "org.reflections:reflections:${Versions.Reflections}"

// Protobuf
const val GrpcNetty = "io.grpc:grpc-netty:${Versions.Grpc}"
Expand Down
1 change: 1 addition & 0 deletions service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies {
implementation(Libraries.KotlinStdlib)
implementation(Libraries.ProtobufKotlin)
implementation(Libraries.ProvenanceProto)
implementation(Libraries.Reflections)

implementation(Libraries.SpringBootStarterWeb)
implementation(Libraries.SpringBootStarterJdbc)
Expand Down
244 changes: 39 additions & 205 deletions service/src/main/kotlin/io/provenance/explorer/config/RestConfig.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.provenance.explorer.config

import com.google.protobuf.Descriptors
import com.google.protobuf.util.JsonFormat
import cosmos.auth.v1beta1.Auth
import cosmos.authz.v1beta1.Authz
Expand Down Expand Up @@ -47,107 +48,7 @@ import cosmwasm.wasm.v1.Proposal.UpdateInstantiateConfigProposal
import ibc.applications.interchain_accounts.v1.Account.InterchainAccount
import ibc.core.client.v1.Client
import ibc.lightclients.tendermint.v1.Tendermint
import io.provenance.attribute.v1.EventAttributeAdd
import io.provenance.attribute.v1.EventAttributeDelete
import io.provenance.attribute.v1.EventAttributeDistinctDelete
import io.provenance.attribute.v1.MsgAddAttributeRequest
import io.provenance.attribute.v1.MsgDeleteAttributeRequest
import io.provenance.attribute.v1.MsgDeleteDistinctAttributeRequest
import io.provenance.attribute.v1.MsgUpdateAttributeRequest
import io.provenance.marker.v1.AddMarkerProposal
import io.provenance.marker.v1.ChangeStatusProposal
import io.provenance.marker.v1.EventDenomUnit
import io.provenance.marker.v1.EventMarkerAccess
import io.provenance.marker.v1.EventMarkerActivate
import io.provenance.marker.v1.EventMarkerAdd
import io.provenance.marker.v1.EventMarkerAddAccess
import io.provenance.marker.v1.EventMarkerBurn
import io.provenance.marker.v1.EventMarkerCancel
import io.provenance.marker.v1.EventMarkerDelete
import io.provenance.marker.v1.EventMarkerDeleteAccess
import io.provenance.marker.v1.EventMarkerFinalize
import io.provenance.marker.v1.EventMarkerMint
import io.provenance.marker.v1.EventMarkerSetDenomMetadata
import io.provenance.marker.v1.EventMarkerTransfer
import io.provenance.marker.v1.EventMarkerWithdraw
import io.provenance.marker.v1.MarkerAccount
import io.provenance.marker.v1.MarkerTransferAuthorization
import io.provenance.marker.v1.MsgActivateRequest
import io.provenance.marker.v1.MsgAddAccessRequest
import io.provenance.marker.v1.MsgAddMarkerRequest
import io.provenance.marker.v1.MsgBurnRequest
import io.provenance.marker.v1.MsgCancelRequest
import io.provenance.marker.v1.MsgDeleteAccessRequest
import io.provenance.marker.v1.MsgDeleteRequest
import io.provenance.marker.v1.MsgFinalizeRequest
import io.provenance.marker.v1.MsgMintRequest
import io.provenance.marker.v1.MsgSetDenomMetadataRequest
import io.provenance.marker.v1.MsgTransferRequest
import io.provenance.marker.v1.MsgWithdrawRequest
import io.provenance.marker.v1.RemoveAdministratorProposal
import io.provenance.marker.v1.SetAdministratorProposal
import io.provenance.marker.v1.SetDenomMetadataProposal
import io.provenance.marker.v1.SupplyDecreaseProposal
import io.provenance.marker.v1.SupplyIncreaseProposal
import io.provenance.marker.v1.WithdrawEscrowProposal
import io.provenance.metadata.v1.EventContractSpecificationCreated
import io.provenance.metadata.v1.EventContractSpecificationDeleted
import io.provenance.metadata.v1.EventContractSpecificationUpdated
import io.provenance.metadata.v1.EventOSLocatorCreated
import io.provenance.metadata.v1.EventOSLocatorDeleted
import io.provenance.metadata.v1.EventOSLocatorUpdated
import io.provenance.metadata.v1.EventRecordCreated
import io.provenance.metadata.v1.EventRecordDeleted
import io.provenance.metadata.v1.EventRecordSpecificationCreated
import io.provenance.metadata.v1.EventRecordSpecificationDeleted
import io.provenance.metadata.v1.EventRecordSpecificationUpdated
import io.provenance.metadata.v1.EventRecordUpdated
import io.provenance.metadata.v1.EventScopeCreated
import io.provenance.metadata.v1.EventScopeDeleted
import io.provenance.metadata.v1.EventScopeSpecificationCreated
import io.provenance.metadata.v1.EventScopeSpecificationDeleted
import io.provenance.metadata.v1.EventScopeSpecificationUpdated
import io.provenance.metadata.v1.EventScopeUpdated
import io.provenance.metadata.v1.EventSessionCreated
import io.provenance.metadata.v1.EventSessionDeleted
import io.provenance.metadata.v1.EventSessionUpdated
import io.provenance.metadata.v1.EventTxCompleted
import io.provenance.metadata.v1.MsgAddContractSpecToScopeSpecRequest
import io.provenance.metadata.v1.MsgAddScopeDataAccessRequest
import io.provenance.metadata.v1.MsgAddScopeOwnerRequest
import io.provenance.metadata.v1.MsgBindOSLocatorRequest
import io.provenance.metadata.v1.MsgDeleteContractSpecFromScopeSpecRequest
import io.provenance.metadata.v1.MsgDeleteContractSpecificationRequest
import io.provenance.metadata.v1.MsgDeleteOSLocatorRequest
import io.provenance.metadata.v1.MsgDeleteRecordRequest
import io.provenance.metadata.v1.MsgDeleteRecordSpecificationRequest
import io.provenance.metadata.v1.MsgDeleteScopeDataAccessRequest
import io.provenance.metadata.v1.MsgDeleteScopeOwnerRequest
import io.provenance.metadata.v1.MsgDeleteScopeRequest
import io.provenance.metadata.v1.MsgDeleteScopeSpecificationRequest
import io.provenance.metadata.v1.MsgModifyOSLocatorRequest
import io.provenance.metadata.v1.MsgP8eMemorializeContractRequest
import io.provenance.metadata.v1.MsgWriteContractSpecificationRequest
import io.provenance.metadata.v1.MsgWriteP8eContractSpecRequest
import io.provenance.metadata.v1.MsgWriteRecordRequest
import io.provenance.metadata.v1.MsgWriteRecordSpecificationRequest
import io.provenance.metadata.v1.MsgWriteScopeRequest
import io.provenance.metadata.v1.MsgWriteScopeSpecificationRequest
import io.provenance.metadata.v1.MsgWriteSessionRequest
import io.provenance.msgfees.v1.AddMsgFeeProposal
import io.provenance.msgfees.v1.RemoveMsgFeeProposal
import io.provenance.msgfees.v1.UpdateConversionFeeDenomProposal
import io.provenance.msgfees.v1.UpdateMsgFeeProposal
import io.provenance.msgfees.v1.UpdateNhashPerUsdMilProposal
import io.provenance.name.v1.CreateRootNameProposal
import io.provenance.name.v1.EventNameBound
import io.provenance.name.v1.EventNameUnbound
import io.provenance.name.v1.MsgBindNameRequest
import io.provenance.name.v1.MsgDeleteNameRequest
import io.provenance.reward.v1.MsgClaimAllRewardsRequest
import io.provenance.reward.v1.MsgClaimRewardsRequest
import io.provenance.reward.v1.MsgCreateRewardProgramRequest
import io.provenance.reward.v1.MsgEndRewardProgramRequest
import org.reflections.Reflections
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary
Expand All @@ -169,6 +70,7 @@ class RestConfig {
.add(contentDescriptors())
.add(events())
.add(miscAnys())
.add(packageDescriptors())
.build()
return JsonFormat.printer().usingTypeRegistry(typeRegistry)
}
Expand All @@ -182,6 +84,7 @@ class RestConfig {
.add(contentDescriptors())
.add(events())
.add(miscAnys())
.add(packageDescriptors())
.build()
return JsonFormat.parser().usingTypeRegistry(typeRegistry)
}
Expand Down Expand Up @@ -214,7 +117,6 @@ class RestConfig {

fun accountDescriptors() =
listOf(
MarkerAccount.getDescriptor(),
Auth.BaseAccount.getDescriptor(),
Auth.ModuleAccount.getDescriptor(),
Vesting.BaseVestingAccount.getDescriptor(),
Expand All @@ -233,8 +135,8 @@ fun pubKeyDescriptors() =
cosmos.crypto.multisig.Keys.LegacyAminoPubKey.getDescriptor()
)

fun msgDescriptors() =
listOf(
fun msgDescriptors(): List<Descriptors.Descriptor> {
val descriptors = mutableListOf(
TxOuterClass.Tx.getDescriptor(),
Tx.MsgSend.getDescriptor(),
Tx.MsgMultiSend.getDescriptor(),
Expand All @@ -260,38 +162,6 @@ fun msgDescriptors() =
cosmos.staking.v1beta1.Tx.MsgUndelegate.getDescriptor(),
cosmos.vesting.v1beta1.Tx.MsgCreateVestingAccount.getDescriptor(),
MsgCancelUnbondingDelegation.getDescriptor(),
MsgWithdrawRequest.getDescriptor(),
MsgAddMarkerRequest.getDescriptor(),
MsgAddAccessRequest.getDescriptor(),
MsgDeleteAccessRequest.getDescriptor(),
MsgFinalizeRequest.getDescriptor(),
MsgActivateRequest.getDescriptor(),
MsgCancelRequest.getDescriptor(),
MsgDeleteRequest.getDescriptor(),
MsgMintRequest.getDescriptor(),
MsgBurnRequest.getDescriptor(),
MsgTransferRequest.getDescriptor(),
MsgSetDenomMetadataRequest.getDescriptor(),
MsgBindNameRequest.getDescriptor(),
MsgDeleteNameRequest.getDescriptor(),
MsgAddAttributeRequest.getDescriptor(),
MsgDeleteAttributeRequest.getDescriptor(),
MsgWriteP8eContractSpecRequest.getDescriptor(),
MsgP8eMemorializeContractRequest.getDescriptor(),
MsgWriteScopeRequest.getDescriptor(),
MsgDeleteScopeRequest.getDescriptor(),
MsgWriteSessionRequest.getDescriptor(),
MsgWriteRecordRequest.getDescriptor(),
MsgDeleteRecordRequest.getDescriptor(),
MsgWriteScopeSpecificationRequest.getDescriptor(),
MsgDeleteScopeSpecificationRequest.getDescriptor(),
MsgWriteContractSpecificationRequest.getDescriptor(),
MsgDeleteContractSpecificationRequest.getDescriptor(),
MsgWriteRecordSpecificationRequest.getDescriptor(),
MsgDeleteRecordSpecificationRequest.getDescriptor(),
MsgBindOSLocatorRequest.getDescriptor(),
MsgDeleteOSLocatorRequest.getDescriptor(),
MsgModifyOSLocatorRequest.getDescriptor(),
cosmwasm.wasm.v1.Tx.MsgStoreCode.getDescriptor(),
cosmwasm.wasm.v1.Tx.MsgInstantiateContract.getDescriptor(),
cosmwasm.wasm.v1.Tx.MsgExecuteContract.getDescriptor(),
Expand Down Expand Up @@ -324,14 +194,6 @@ fun msgDescriptors() =
ibc.core.connection.v1.Tx.MsgConnectionOpenTry.getDescriptor(),
ibc.core.connection.v1.Tx.MsgConnectionOpenAck.getDescriptor(),
ibc.core.connection.v1.Tx.MsgConnectionOpenConfirm.getDescriptor(),
MsgAddScopeDataAccessRequest.getDescriptor(),
MsgDeleteScopeDataAccessRequest.getDescriptor(),
MsgAddScopeOwnerRequest.getDescriptor(),
MsgDeleteScopeOwnerRequest.getDescriptor(),
MsgUpdateAttributeRequest.getDescriptor(),
MsgDeleteDistinctAttributeRequest.getDescriptor(),
MsgAddContractSpecToScopeSpecRequest.getDescriptor(),
MsgDeleteContractSpecFromScopeSpecRequest.getDescriptor(),
cosmos.authz.v1beta1.Tx.MsgGrant.getDescriptor(),
cosmos.authz.v1beta1.Tx.MsgExec.getDescriptor(),
cosmos.authz.v1beta1.Tx.MsgRevoke.getDescriptor(),
Expand All @@ -340,10 +202,6 @@ fun msgDescriptors() =
Ibc.MsgIBCSend.getDescriptor(),
Ibc.MsgIBCCloseChannel.getDescriptor(),
MsgSend.getDescriptor(),
MsgCreateRewardProgramRequest.getDescriptor(),
MsgEndRewardProgramRequest.getDescriptor(),
MsgClaimRewardsRequest.getDescriptor(),
MsgClaimAllRewardsRequest.getDescriptor(),
MsgCreateGroup.getDescriptor(),
MsgCreateGroupWithPolicy.getDescriptor(),
MsgCreateGroupPolicy.getDescriptor(),
Expand All @@ -359,6 +217,38 @@ fun msgDescriptors() =
MsgExec.getDescriptor(),
MsgLeaveGroup.getDescriptor()
)
return descriptors
}

fun packageDescriptors(): List<Descriptors.Descriptor> {
val descriptors = mutableListOf<Descriptors.Descriptor>()
descriptors.addAll(findDescriptorsInPackage("io.provenance.attribute.v1"))
descriptors.addAll(findDescriptorsInPackage("io.provenance.exchange.v1"))
descriptors.addAll(findDescriptorsInPackage("io.provenance.hold.v1"))
descriptors.addAll(findDescriptorsInPackage("io.provenance.ibchooks.v1"))
descriptors.addAll(findDescriptorsInPackage("io.provenance.ibcratelimit.v1"))
descriptors.addAll(findDescriptorsInPackage("io.provenance.marker.v1"))
descriptors.addAll(findDescriptorsInPackage("io.provenance.metadata.v1"))
descriptors.addAll(findDescriptorsInPackage("io.provenance.msgfees.v1"))
descriptors.addAll(findDescriptorsInPackage("io.provenance.name.v1"))
descriptors.addAll(findDescriptorsInPackage("io.provenance.oracle.v1"))
descriptors.addAll(findDescriptorsInPackage("io.provenance.reward.v1"))
descriptors.addAll(findDescriptorsInPackage("io.provenance.trigger.v1"))
return descriptors
}

private fun findDescriptorsInPackage(packageName: String): List<Descriptors.Descriptor> {
val reflections = Reflections(packageName)
val messageClasses = reflections.getSubTypesOf(com.google.protobuf.Message::class.java)

return messageClasses.mapNotNull {
try {
it.getMethod("getDescriptor").invoke(null) as Descriptors.Descriptor
} catch (e: Exception) {
null
}
}
}

fun contentDescriptors() =
listOf(
Expand All @@ -368,15 +258,6 @@ fun contentDescriptors() =
Upgrade.CancelSoftwareUpgradeProposal.getDescriptor(),
Distribution.CommunityPoolSpendProposal.getDescriptor(),
Distribution.CommunityPoolSpendProposalWithDeposit.getDescriptor(),
AddMarkerProposal.getDescriptor(),
SupplyIncreaseProposal.getDescriptor(),
SupplyDecreaseProposal.getDescriptor(),
SetAdministratorProposal.getDescriptor(),
RemoveAdministratorProposal.getDescriptor(),
ChangeStatusProposal.getDescriptor(),
WithdrawEscrowProposal.getDescriptor(),
SetDenomMetadataProposal.getDescriptor(),
CreateRootNameProposal.getDescriptor(),
Proposal.StoreCodeProposal.getDescriptor(),
Proposal.InstantiateContractProposal.getDescriptor(),
Proposal.MigrateContractProposal.getDescriptor(),
Expand All @@ -395,56 +276,10 @@ fun contentDescriptors() =
cosmwasm.wasm.v1beta1.Proposal.PinCodesProposal.getDescriptor(),
cosmwasm.wasm.v1beta1.Proposal.UnpinCodesProposal.getDescriptor(),
Client.ClientUpdateProposal.getDescriptor(),
Client.UpgradeProposal.getDescriptor(),
AddMsgFeeProposal.getDescriptor(),
UpdateMsgFeeProposal.getDescriptor(),
RemoveMsgFeeProposal.getDescriptor(),
UpdateNhashPerUsdMilProposal.getDescriptor(),
UpdateConversionFeeDenomProposal.getDescriptor()
Client.UpgradeProposal.getDescriptor()
)

fun events() = listOf(
EventNameBound.getDescriptor(),
EventNameUnbound.getDescriptor(),
EventMarkerAdd.getDescriptor(),
EventMarkerAddAccess.getDescriptor(),
EventMarkerAccess.getDescriptor(),
EventMarkerDeleteAccess.getDescriptor(),
EventMarkerFinalize.getDescriptor(),
EventMarkerActivate.getDescriptor(),
EventMarkerCancel.getDescriptor(),
EventMarkerDelete.getDescriptor(),
EventMarkerMint.getDescriptor(),
EventMarkerBurn.getDescriptor(),
EventMarkerWithdraw.getDescriptor(),
EventMarkerTransfer.getDescriptor(),
EventMarkerSetDenomMetadata.getDescriptor(),
EventDenomUnit.getDescriptor(),
EventTxCompleted.getDescriptor(),
EventScopeCreated.getDescriptor(),
EventScopeUpdated.getDescriptor(),
EventScopeDeleted.getDescriptor(),
EventSessionCreated.getDescriptor(),
EventSessionUpdated.getDescriptor(),
EventSessionDeleted.getDescriptor(),
EventRecordCreated.getDescriptor(),
EventRecordUpdated.getDescriptor(),
EventRecordDeleted.getDescriptor(),
EventScopeSpecificationCreated.getDescriptor(),
EventScopeSpecificationUpdated.getDescriptor(),
EventScopeSpecificationDeleted.getDescriptor(),
EventContractSpecificationCreated.getDescriptor(),
EventContractSpecificationUpdated.getDescriptor(),
EventContractSpecificationDeleted.getDescriptor(),
EventRecordSpecificationCreated.getDescriptor(),
EventRecordSpecificationUpdated.getDescriptor(),
EventRecordSpecificationDeleted.getDescriptor(),
EventOSLocatorCreated.getDescriptor(),
EventOSLocatorUpdated.getDescriptor(),
EventOSLocatorDeleted.getDescriptor(),
EventAttributeAdd.getDescriptor(),
EventAttributeDelete.getDescriptor(),
EventAttributeDistinctDelete.getDescriptor(),
Event.EventGrant.getDescriptor(),
Event.EventRevoke.getDescriptor(),
EventCreateGroup.getDescriptor(),
Expand All @@ -466,7 +301,6 @@ fun miscAnys() = listOf(
Feegrant.PeriodicAllowance.getDescriptor(),
Feegrant.AllowedMsgAllowance.getDescriptor(),
cosmos.staking.v1beta1.Authz.StakeAuthorization.getDescriptor(),
MarkerTransferAuthorization.getDescriptor(),
CountAuthorization.getDescriptor(),
GrantAuthorization.getDescriptor(),
ThresholdDecisionPolicy.getDescriptor(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,9 @@ class GovService(
list
}
}
}.map { mapProposalRecord(it) }
}.map {
mapProposalRecord(it)
}
.let {
val total = GovProposalRecord.getAllCount()
PagedResults(total.pageCountOfResults(count), it, total)
Expand Down
Loading