Fix npe and unrecognized error (#456)

This commit is contained in:
KirillPamPam
2024-04-19 13:46:29 +04:00
committed by GitHub
parent ef6913d2d6
commit 72dcedc38e
2 changed files with 39 additions and 37 deletions

View File

@@ -35,44 +35,46 @@ class Describe(
return requestMono.map { _ -> return requestMono.map { _ ->
val resp = BlockchainOuterClass.DescribeResponse.newBuilder() val resp = BlockchainOuterClass.DescribeResponse.newBuilder()
resp.buildInfoBuilder.version = Global.version resp.buildInfoBuilder.version = Global.version
multistreamHolder.getAvailable().forEach { chain -> multistreamHolder.getAvailable()
multistreamHolder.getUpstream(chain).let { chainUpstreams -> .filter { Common.ChainRef.forNumber(it.id) != null }
val status = subscribeStatus.chainStatus(chain, chainUpstreams.getStatus(), chainUpstreams) .forEach { chain ->
val targets = chainUpstreams.getMethods().getSupportedMethods() multistreamHolder.getUpstream(chain).let { chainUpstreams ->
val capabilities: MutableSet<Capability> = mutableSetOf() val status = subscribeStatus.chainStatus(chain, chainUpstreams.getStatus(), chainUpstreams)
val chainDescription = BlockchainOuterClass.DescribeChain.newBuilder() val targets = chainUpstreams.getMethods().getSupportedMethods()
.setChain(Common.ChainRef.forNumber(chain.id)) val capabilities: MutableSet<Capability> = mutableSetOf()
.addAllSupportedMethods(targets) val chainDescription = BlockchainOuterClass.DescribeChain.newBuilder()
.addAllSupportedSubscriptions(chainUpstreams.getEgressSubscription().getAvailableTopics()) .setChain(Common.ChainRef.forNumber(chain.id))
.setStatus(status) .addAllSupportedMethods(targets)
.setCurrentHeight(chainUpstreams.getHead().getCurrentHeight() ?: 0) .addAllSupportedSubscriptions(chainUpstreams.getEgressSubscription().getAvailableTopics())
chainUpstreams.getQuorumLabels() .setStatus(status)
.forEach { node -> .setCurrentHeight(chainUpstreams.getHead().getCurrentHeight() ?: 0)
val nodeDetails = BlockchainOuterClass.NodeDetails.newBuilder() chainUpstreams.getQuorumLabels()
.setQuorum(node.quorum) .forEach { node ->
.addAllLabels( val nodeDetails = BlockchainOuterClass.NodeDetails.newBuilder()
node.labels.entries.map { label -> .setQuorum(node.quorum)
BlockchainOuterClass.Label.newBuilder() .addAllLabels(
.setName(label.key) node.labels.entries.map { label ->
.setValue(label.value) BlockchainOuterClass.Label.newBuilder()
.build() .setName(label.key)
}, .setValue(label.value)
) .build()
chainDescription.addNodes(nodeDetails) },
} )
capabilities.addAll(chainUpstreams.getCapabilities()) chainDescription.addNodes(nodeDetails)
chainDescription.addAllCapabilities(
capabilities.map {
when (it) {
Capability.RPC -> BlockchainOuterClass.Capabilities.CAP_CALLS
Capability.BALANCE -> BlockchainOuterClass.Capabilities.CAP_BALANCE
Capability.WS_HEAD -> BlockchainOuterClass.Capabilities.CAP_WS_HEAD
} }
}, capabilities.addAll(chainUpstreams.getCapabilities())
) chainDescription.addAllCapabilities(
resp.addChains(chainDescription.build()) capabilities.map {
when (it) {
Capability.RPC -> BlockchainOuterClass.Capabilities.CAP_CALLS
Capability.BALANCE -> BlockchainOuterClass.Capabilities.CAP_BALANCE
Capability.WS_HEAD -> BlockchainOuterClass.Capabilities.CAP_WS_HEAD
}
},
)
resp.addChains(chainDescription.build())
}
} }
}
resp.build() resp.build()
} }
} }

View File

@@ -93,7 +93,7 @@ class StreamHead(
private fun toProtoLowerBoundType(type: LowerBoundType): BlockchainOuterClass.LowerBoundType { private fun toProtoLowerBoundType(type: LowerBoundType): BlockchainOuterClass.LowerBoundType {
return when (type) { return when (type) {
LowerBoundType.SLOT -> BlockchainOuterClass.LowerBoundType.LOWER_BOUND_SLOT LowerBoundType.SLOT -> BlockchainOuterClass.LowerBoundType.LOWER_BOUND_SLOT
LowerBoundType.UNKNOWN -> BlockchainOuterClass.LowerBoundType.UNRECOGNIZED LowerBoundType.UNKNOWN -> BlockchainOuterClass.LowerBoundType.LOWER_BOUND_UNSPECIFIED
LowerBoundType.STATE -> BlockchainOuterClass.LowerBoundType.LOWER_BOUND_STATE LowerBoundType.STATE -> BlockchainOuterClass.LowerBoundType.LOWER_BOUND_STATE
LowerBoundType.BLOCK -> BlockchainOuterClass.LowerBoundType.LOWER_BOUND_BLOCK LowerBoundType.BLOCK -> BlockchainOuterClass.LowerBoundType.LOWER_BOUND_BLOCK
} }