Skip to content

Commit

Permalink
fix: node public config
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanVerstraete committed Aug 18, 2022
1 parent e39ace0 commit 0fe7f0e
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 80 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "graphql_tfgrid",
"private": "true",
"version": "2.5.1",
"version": "2.5.2",
"description": "GraphQL server and Substrate indexer. Generated with ♥ by Hydra-CLI",
"author": "",
"license": "ISC",
Expand Down
2 changes: 1 addition & 1 deletion processor-chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v2
name: tfchain-processor
description: A chart for the tfchain graphql processor and query node
version: 1.0.4
appVersion: "2.5.1"
appVersion: "2.5.2"
147 changes: 88 additions & 59 deletions src/mappings/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Node, Location, PublicConfig, NodeCertification, Interfaces, UptimeEven
import { SmartContractModuleNodeMarkedAsDedicatedEvent, TfgridModuleNodeCertificationSetEvent, TfgridModuleNodeDeletedEvent, TfgridModuleNodePublicConfigStoredEvent, TfgridModuleNodeStoredEvent, TfgridModuleNodeUpdatedEvent, TfgridModuleNodeUptimeReportedEvent } from "../types/events";

export async function nodeStored(ctx: EventHandlerContext) {
const node = new TfgridModuleNodeStoredEvent(ctx)
const node = new TfgridModuleNodeStoredEvent(ctx)
let nodeEvent
if (node.isV9) {
nodeEvent = node.asV9
Expand All @@ -18,9 +18,9 @@ export async function nodeStored(ctx: EventHandlerContext) {
} else if (node.isV101) {
nodeEvent = node.asV101
}

if (!nodeEvent) return

const newNode = new Node()
newNode.id = ctx.event.id
newNode.gridVersion = nodeEvent.version
Expand Down Expand Up @@ -51,35 +51,35 @@ export async function nodeStored(ctx: EventHandlerContext) {
const certificationTypeAsString = nodeAsV28.certificationType.__kind.toString()
let certType = NodeCertification.Diy
switch (certificationTypeAsString) {
case 'Diy':
case 'Diy':
certType = NodeCertification.Diy
break
case 'Certified':
break
case 'Certified':
certType = NodeCertification.Certified
break
}
break
}
newNode.certification = certType
} else {
newNode.certification = NodeCertification.Diy
}
}

if (node.isV43) {
const nodeAsV43 = node.asV43
const nodeAsV43 = node.asV43
newNode.secure = nodeAsV43.secureBoot ? true : false
newNode.virtualized = nodeAsV43.virtualized ? true : false
newNode.serialNumber = nodeAsV43.serialNumber.toString()
if (nodeAsV43.certificationType) {
const certificationTypeAsString = nodeAsV43.certificationType.__kind.toString()
let certType = NodeCertification.Diy
switch (certificationTypeAsString) {
case 'Diy':
case 'Diy':
certType = NodeCertification.Diy
break
case 'Certified':
break
case 'Certified':
certType = NodeCertification.Certified
break
}
break
}
newNode.certification = certType
} else {
newNode.certification = NodeCertification.Diy
Expand All @@ -103,13 +103,13 @@ export async function nodeStored(ctx: EventHandlerContext) {
const certificationTypeAsString = nodeEvent.certification.__kind.toString()
let certType = NodeCertification.Diy
switch (certificationTypeAsString) {
case 'Diy':
case 'Diy':
certType = NodeCertification.Diy
break
case 'Certified':
break
case 'Certified':
certType = NodeCertification.Certified
break
}
break
}
newNode.certification = certType
} else {
newNode.certification = NodeCertification.Diy
Expand Down Expand Up @@ -160,7 +160,7 @@ export async function nodeStored(ctx: EventHandlerContext) {
}

export async function nodeUpdated(ctx: EventHandlerContext) {
const node = new TfgridModuleNodeUpdatedEvent(ctx)
const node = new TfgridModuleNodeUpdatedEvent(ctx)

let nodeEvent
if (node.isV9) {
Expand Down Expand Up @@ -213,35 +213,35 @@ export async function nodeUpdated(ctx: EventHandlerContext) {
const certificationTypeAsString = nodeAsV28.certificationType.__kind.toString()
let certType = NodeCertification.Diy
switch (certificationTypeAsString) {
case 'Diy':
case 'Diy':
certType = NodeCertification.Diy
break
case 'Certified':
break
case 'Certified':
certType = NodeCertification.Certified
break
}
break
}
savedNode.certification = certType
} else {
savedNode.certification = NodeCertification.Diy
}
}

if (node.isV43) {
const nodeAsV43 = node.asV43
const nodeAsV43 = node.asV43
savedNode.secure = nodeAsV43.secureBoot ? true : false
savedNode.virtualized = nodeAsV43.virtualized ? true : false
savedNode.serialNumber = nodeAsV43.serialNumber.toString()
if (nodeAsV43.certificationType) {
const certificationTypeAsString = nodeAsV43.certificationType.__kind.toString()
let certType = NodeCertification.Diy
switch (certificationTypeAsString) {
case 'Diy':
case 'Diy':
certType = NodeCertification.Diy
break
case 'Certified':
break
case 'Certified':
certType = NodeCertification.Certified
break
}
break
}
savedNode.certification = certType
} else {
savedNode.certification = NodeCertification.Diy
Expand All @@ -264,12 +264,12 @@ export async function nodeUpdated(ctx: EventHandlerContext) {
const certificationTypeAsString = nodeEvent.certification.__kind.toString()
let certType = NodeCertification.Diy
switch (certificationTypeAsString) {
case 'Diy':
case 'Diy':
certType = NodeCertification.Diy
break
case 'Certified':
break
case 'Certified':
certType = NodeCertification.Certified
break
break
}
savedNode.certification = certType
} else {
Expand All @@ -289,20 +289,20 @@ export async function nodeUpdated(ctx: EventHandlerContext) {
// if an interface with same name exists
const found = savedNode.interfaces.findIndex(interf => interf.name === intf.name.toString())
if (found > 0) {
newInterface = savedNode.interfaces[found]
newInterface = savedNode.interfaces[found]
} else {
newInterface = new Interfaces()
newInterface.id = ctx.event.id
newInterface.node = savedNode
}
}

if (!newInterface) return

newInterface.name = intf.name.toString()
newInterface.mac = intf.mac.toString()
newInterface.ips = intf.ips.map(ip => ip.toString()).join(',')

await ctx.store.save<Interfaces>(newInterface)
savedNode.interfaces.push(newInterface)
})
Expand All @@ -314,7 +314,7 @@ export async function nodeDeleted(ctx: EventHandlerContext) {
const nodeID = new TfgridModuleNodeDeletedEvent(ctx).asV9

const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID } })

if (savedNode) {
const resourcesTotal = await ctx.store.get(NodeResourcesTotal, { where: { node: savedNode } })
if (resourcesTotal) {
Expand All @@ -325,7 +325,7 @@ export async function nodeDeleted(ctx: EventHandlerContext) {
await ctx.store.remove(pubConfig)
}

const intfs = await ctx.store.find(Interfaces, { where: { node: savedNode }})
const intfs = await ctx.store.find(Interfaces, { where: { node: savedNode } })
const promises = intfs.map(intf => {
return ctx.store.remove(intf)
})
Expand Down Expand Up @@ -365,26 +365,55 @@ export async function nodeUptimeReported(ctx: EventHandlerContext) {
}

export async function nodePublicConfigStored(ctx: EventHandlerContext) {
const [nodeID, config] = new TfgridModuleNodePublicConfigStoredEvent(ctx).asV12
const storedEvent = new TfgridModuleNodePublicConfigStoredEvent(ctx)

const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID } })
if (!savedNode) return
let nodeID, config
if (storedEvent.isV12) {
nodeID = storedEvent.asV12[0]
config = storedEvent.asV12[1]

let publicConfig = await ctx.store.get(PublicConfig, { where: { node: savedNode }})
const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID } })
if (!savedNode) return

if (!publicConfig) {
publicConfig = new PublicConfig()
publicConfig.id = ctx.event.id
publicConfig.node = savedNode
}
let publicConfig = await ctx.store.get(PublicConfig, { where: { node: savedNode } })

if (!publicConfig) {
publicConfig = new PublicConfig()
publicConfig.id = ctx.event.id
publicConfig.node = savedNode
}

publicConfig.ipv4 = config.ipv4.toString()
publicConfig.ipv6 = config.ipv6.toString()
publicConfig.gw4 = config.gw4.toString()
publicConfig.gw6 = config.gw6.toString()
publicConfig.domain = config.domain.toString() || ''

publicConfig.ipv4 = config.ipv4.toString()
publicConfig.ipv6 = config.ipv6.toString()
publicConfig.gw4 = config.gw4.toString()
publicConfig.gw6 = config.gw6.toString()
publicConfig.domain = config.domain.toString() || ''
await ctx.store.save<PublicConfig>(publicConfig)

await ctx.store.save<PublicConfig>(publicConfig)
} else if (storedEvent.isV105) {
nodeID = storedEvent.asV105[0]
config = storedEvent.asV105[1]

const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID } })
if (!savedNode) return

let publicConfig = await ctx.store.get(PublicConfig, { where: { node: savedNode } })

if (!publicConfig) {
publicConfig = new PublicConfig()
publicConfig.id = ctx.event.id
publicConfig.node = savedNode
}

publicConfig.ipv4 = config?.ip4.ip.toString()
publicConfig.ipv6 = config?.ip6?.ip.toString()
publicConfig.gw4 = config?.ip4.gw.toString()
publicConfig.gw6 = config?.ip6?.gw.toString()
publicConfig.domain = config?.domain ? config.domain.toString() : ''

await ctx.store.save<PublicConfig>(publicConfig)
}
}

// export async function nodeMarkedAsDedicated(ctx: EventHandlerContext) {
Expand All @@ -405,12 +434,12 @@ export async function nodeCertificationSet(ctx: EventHandlerContext) {

let certType = NodeCertification.Diy
switch (certification.__kind.toString()) {
case 'Diy':
case 'Diy':
certType = NodeCertification.Diy
break
case 'Certified':
break
case 'Certified':
certType = NodeCertification.Certified
break
break
}

savedNode.certification = certType
Expand Down
Loading

0 comments on commit 0fe7f0e

Please sign in to comment.