Skip to content

Commit

Permalink
feat(hapi): save supported APIs in the node_info table
Browse files Browse the repository at this point in the history
  • Loading branch information
Torresmorah committed Jan 10, 2023
1 parent 790481f commit dfbae01
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
40 changes: 28 additions & 12 deletions hapi/src/services/node.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,16 @@ const updateNodeInfo = async nodes => {
}
`

const clearMutation = `
mutation {
delete_node_info(where: {_and: [{version: {_eq: ""}},{features: {_eq: {}}}]}) {
affected_rows
}
}
`

await hasuraUtil.request(upsertMutation, { nodes })
await hasuraUtil.request(clearMutation)
}

const getNodeEnpoints = node => {
Expand Down Expand Up @@ -113,11 +122,11 @@ const getFormatNode = node => {
node.features = [node.features]
}

if (node.features?.length || !!node.keys) {
if (endpoints.length || node.features?.length || !!node.keys) {
formatNode.node_info = {
data: {
version: '',
features: { list: node.features, keys: node.keys }
features: { list: node?.features, keys: node.keys }
}
}
}
Expand All @@ -128,16 +137,23 @@ const getFormatNode = node => {
const updateNodesInfo = async nodes => {
nodes = await Promise.all(
nodes.map(async (node) => {
if (
node?.type?.includes('query') &&
node?.endpoints?.length &&
!!node.node_info[0]
) {
const { nodeInfo } = await producerUtil.getNodeInfo(
node.endpoints[0].value
)

node.node_info[0].version = nodeInfo?.server_version_string || ''
if (node?.endpoints?.length && !!node.node_info[0]) {
const sslEndpoint = node.endpoints.find(
(endpoint) => endpoint.type === 'ssl'
)?.value

if (sslEndpoint) {
const { nodeInfo } = await producerUtil.getNodeInfo(sslEndpoint)
const { supportedAPIs } = await producerUtil.getSupportedAPIs(
sslEndpoint
)

node.node_info[0].version = nodeInfo?.server_version_string || ''
node.node_info[0].features = {
...node.node_info[0]?.features,
...(supportedAPIs && { supportedAPIs })
}
}

return node.node_info[0]
}
Expand Down
15 changes: 15 additions & 0 deletions hapi/src/utils/producer.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ const getNodeInfo = async (api) => {
}
}

const getSupportedAPIs = async (api) => {
let supportedAPIs

try {
const response = await axiosUtil.instance.get(
`${api}/v1/node/get_supported_apis`
)

supportedAPIs = response.data?.apis
} catch (error) {}

return { supportedAPIs }
}

const getEndpoints = (nodes) => {
if (!nodes?.length) {
return {
Expand Down Expand Up @@ -246,6 +260,7 @@ module.exports = {
getNodeInfo,
getEndpoints,
getExpectedRewards,
getSupportedAPIs,
getVotes,
jsonParse
}

0 comments on commit dfbae01

Please sign in to comment.