Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions src/mappings/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,38 +394,6 @@ export function collectContractBillReports(ctx: Ctx): ContractBillReport[] {
return list
}

export async function contractBilled(
ctx: Ctx,
item: EventItem<'SmartContractModule.ContractBilled', { event: { args: true } }>,
) {
const contract_billed_event = new SmartContractModuleContractBilledEvent(ctx, item.event).asV9

const newContractBilledReport = new ContractBillReport()

newContractBilledReport.id = item.event.id
newContractBilledReport.contractID = contract_billed_event.contractId

let level = DiscountLevel.None
switch (contract_billed_event.discountLevel.__kind) {
case 'None': break
case 'Default':
level = DiscountLevel.Default
break
case 'Bronze':
level = DiscountLevel.Bronze
break
case 'Silver':
level = DiscountLevel.Silver
break
case 'Gold': level = DiscountLevel.Gold
}
newContractBilledReport.discountReceived = level
newContractBilledReport.amountBilled = contract_billed_event.amountBilled
newContractBilledReport.timestamp = contract_billed_event.timestamp

await ctx.store.save<ContractBillReport>(newContractBilledReport)
}

export async function contractUpdateUsedResources(
ctx: Ctx,
item: EventItem<'SmartContractModule.UpdatedUsedResources', { event: { args: true } }>,
Expand Down
31 changes: 9 additions & 22 deletions src/mappings/farms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import { validateString } from "./nodes"

import * as ipaddr from 'ipaddr.js';

export function parseFarmCertification(kind: string): FarmCertification {
switch (kind) {
case 'Gold': return FarmCertification.Gold
default: return FarmCertification.NotCertified
}
}

export class FarmWithIPs {
constructor(farmID: number, ips: PublicIp[]) {
this.farmID = farmID
Expand Down Expand Up @@ -58,8 +65,6 @@ export async function farmStored(
: false
newFarm.certification = FarmCertification.NotCertified

newFarm.publicIPs = []

await ctx.store.save<Farm>(newFarm)

const ipPromises = farmStoredEventParsed.publicIps.map((ip, index) => {
Expand Down Expand Up @@ -146,11 +151,7 @@ export async function farmUpdated(
const rawArgs = item.event.args as any
rawArgs.dedicatedFarm = rawArgs['dedicatedFarm:'] ?? rawArgs.dedicatedFarm ?? false
farmUpdatedEventParsed = farmUpdatedEvent.asV63
switch (farmUpdatedEvent.asV63.certification.__kind) {
case "Gold": {
certification = FarmCertification.Gold
}
}
certification = parseFarmCertification(farmUpdatedEvent.asV63.certification.__kind)
}

if (!farmUpdatedEventParsed) {
Expand Down Expand Up @@ -196,10 +197,6 @@ export async function farmUpdated(
newIP.contractId = ip.contractId
newIP.farm = savedFarm
await ctx.store.save<PublicIp>(newIP)
if (!savedFarm.publicIPs) {
savedFarm.publicIPs = []
}
savedFarm.publicIPs.push(newIP)
ctx.log.debug({ eventName: item.name, ip: ip.ip.toString() }, `PublicIP: ${ip.ip.toString()} added with farm id: ${savedFarm.farmID}`);
}
}
Expand Down Expand Up @@ -267,16 +264,6 @@ export async function farmCertificationSet(
return
}

let certType = FarmCertification.NotCertified
switch (certification.__kind.toString()) {
case 'NotCertified':
certType = FarmCertification.NotCertified
break
case 'Gold':
certType = FarmCertification.Gold
break
}

savedFarm.certification = certType
savedFarm.certification = parseFarmCertification(certification.__kind.toString())
await ctx.store.save<Farm>(savedFarm)
}
97 changes: 20 additions & 77 deletions src/mappings/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import { PublicConfig as V105PublicConfig } from '../types/v105'

import { Ctx } from '../processor'
import assert from "assert";
import { allowedNodeEnvironmentFlags } from "process";

export function parseNodeCertification(kind: string): NodeCertification {
switch (kind) {
case 'Certified': return NodeCertification.Certified
default: return NodeCertification.Diy
}
}

export async function nodeStored(
ctx: Ctx,
Expand Down Expand Up @@ -137,8 +143,6 @@ export async function nodeStored(
resourcesTotal.cru = nodeEvent.resources.cru
await ctx.store.save<NodeResourcesTotal>(resourcesTotal)

newNode.interfaces = []

const interfacesPromisses = nodeEvent.interfaces.map(async (intf, index) => {
const newInterface = new Interfaces()
newInterface.id = item.event.id + '-' + index
Expand Down Expand Up @@ -226,21 +230,9 @@ export async function nodeUpdated(
savedNode.country = validateString(ctx, nodeAsV28.country.toString())
savedNode.city = validateString(ctx, nodeAsV28.city.toString())

if (nodeAsV28.certificationType) {
const certificationTypeAsString = nodeAsV28.certificationType.__kind.toString()
let certType = NodeCertification.Diy
switch (certificationTypeAsString) {
case 'Diy':
certType = NodeCertification.Diy
break
case 'Certified':
certType = NodeCertification.Certified
break
}
savedNode.certification = certType
} else {
savedNode.certification = NodeCertification.Diy
}
savedNode.certification = nodeAsV28.certificationType
? parseNodeCertification(nodeAsV28.certificationType.__kind.toString())
: NodeCertification.Diy
}

if (node.isV43) {
Expand All @@ -250,21 +242,9 @@ export async function nodeUpdated(
savedNode.secure = nodeAsV43.secureBoot ? true : false
savedNode.virtualized = nodeAsV43.virtualized ? true : false
savedNode.serialNumber = validateString(ctx, nodeAsV43.serialNumber.toString())
if (nodeAsV43.certificationType) {
const certificationTypeAsString = nodeAsV43.certificationType.__kind.toString()
let certType = NodeCertification.Diy
switch (certificationTypeAsString) {
case 'Diy':
certType = NodeCertification.Diy
break
case 'Certified':
certType = NodeCertification.Certified
break
}
savedNode.certification = certType
} else {
savedNode.certification = NodeCertification.Diy
}
savedNode.certification = nodeAsV43.certificationType
? parseNodeCertification(nodeAsV43.certificationType.__kind.toString())
: NodeCertification.Diy
}

if (node.isV63 || node.isV105) {
Expand All @@ -281,21 +261,9 @@ export async function nodeUpdated(
savedNode.secure = nodeEvent.secureBoot ? true : false
savedNode.virtualized = nodeEvent.virtualized ? true : false
savedNode.serialNumber = validateString(ctx, nodeEvent.serialNumber.toString())
if (nodeEvent.certification) {
const certificationTypeAsString = nodeEvent.certification.__kind.toString()
let certType = NodeCertification.Diy
switch (certificationTypeAsString) {
case 'Diy':
certType = NodeCertification.Diy
break
case 'Certified':
certType = NodeCertification.Certified
break
}
savedNode.certification = certType
} else {
savedNode.certification = NodeCertification.Diy
}
savedNode.certification = nodeEvent.certification
? parseNodeCertification(nodeEvent.certification.__kind.toString())
: NodeCertification.Diy
}

if (node.isV118) {
Expand All @@ -306,21 +274,9 @@ export async function nodeUpdated(
savedNode.secure = nodeEvent.secureBoot ? true : false
savedNode.virtualized = nodeEvent.virtualized ? true : false
savedNode.serialNumber = nodeEvent.serialNumber ? validateString(ctx, nodeEvent.serialNumber.toString()) : 'Unknown'
if (nodeEvent.certification) {
const certificationTypeAsString = nodeEvent.certification.__kind.toString()
let certType = NodeCertification.Diy
switch (certificationTypeAsString) {
case 'Diy':
certType = NodeCertification.Diy
break
case 'Certified':
certType = NodeCertification.Certified
break
}
savedNode.certification = certType
} else {
savedNode.certification = NodeCertification.Diy
}
savedNode.certification = nodeEvent.certification
? parseNodeCertification(nodeEvent.certification.__kind.toString())
: NodeCertification.Diy
}

// First remove all ifs
Expand All @@ -337,7 +293,6 @@ export async function nodeUpdated(
newInterface.node = savedNode
await ctx.store.save<Interfaces>(newInterface)

savedNode.interfaces.push(newInterface)
}))

await ctx.store.save<Node>(savedNode)
Expand Down Expand Up @@ -499,17 +454,7 @@ export async function nodeCertificationSet(
const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID }, relations: { location: true, interfaces: true } })
if (!savedNode) return

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

savedNode.certification = certType
savedNode.certification = parseNodeCertification(certification.__kind.toString())

await ctx.store.save<Node>(savedNode)
}
Expand Down Expand Up @@ -669,8 +614,6 @@ function getNodePublicConfig(ctx: Ctx, node: TfgridModuleNodeStoredEvent): NodeP
if (nodeEvent.publicConfig.domain) {
domain = nodeEvent.publicConfig.domain.toString()
}
let h = nodeEvent.publicConfig?.ip6?.ip.toString();
let r = nodeEvent.publicConfig?.ip4.ip.toString();
return {
ip4: validateString(ctx, nodeEvent.publicConfig?.ip4.ip.toString()),
gw4: validateString(ctx, nodeEvent.publicConfig?.ip4.gw.toString()),
Expand Down
55 changes: 8 additions & 47 deletions src/mappings/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
TfgridModulePricingPolicyStoredEvent, TfgridModuleFarmingPolicyStoredEvent,
TfgridModuleFarmingPolicyUpdatedEvent
} from "../types/events";
import { validateString } from "./nodes"
import { validateString, parseNodeCertification } from "./nodes"
import { parseFarmCertification } from "./farms"

export async function pricingPolicyStored(
ctx: Ctx,
Expand Down Expand Up @@ -109,29 +110,9 @@ export async function farmingPolicyStored(
newFarmingPolicy.immutable = farmingPolicyStoredEvent.immutable
newFarmingPolicy.default = farmingPolicyStoredEvent.default

const certificationTypeAsString = farmingPolicyStoredEvent.nodeCertification.__kind.toString()
let nodeCertType = NodeCertification.Diy
switch (certificationTypeAsString) {
case 'Diy':
nodeCertType = NodeCertification.Diy
break
case 'Certified':
nodeCertType = NodeCertification.Certified
break
}
newFarmingPolicy.nodeCertification = nodeCertType

const farmCertificationTypeAsString = farmingPolicyStoredEvent.farmCertification.__kind.toString()
let farmCertType = FarmCertification.NotCertified
switch (farmCertificationTypeAsString) {
case 'NotCertified':
farmCertType = FarmCertification.NotCertified
break
case 'Gold':
farmCertType = FarmCertification.Gold
break
}
newFarmingPolicy.farmCertification = farmCertType
newFarmingPolicy.nodeCertification = parseNodeCertification(farmingPolicyStoredEvent.nodeCertification.__kind.toString())

newFarmingPolicy.farmCertification = parseFarmCertification(farmingPolicyStoredEvent.farmCertification.__kind.toString())

await ctx.store.save<FarmingPolicy>(newFarmingPolicy)
}
Expand Down Expand Up @@ -165,29 +146,9 @@ export async function farmingPolicyUpdated(
savedPolicy.immutable = farmingPolicyUpdatedEvent.immutable
savedPolicy.default = farmingPolicyUpdatedEvent.default

const certificationTypeAsString = farmingPolicyUpdatedEvent.nodeCertification.__kind.toString()
let nodeCertType = NodeCertification.Diy
switch (certificationTypeAsString) {
case 'Diy':
nodeCertType = NodeCertification.Diy
break
case 'Certified':
nodeCertType = NodeCertification.Certified
break
}
savedPolicy.nodeCertification = nodeCertType

const farmCertificationTypeAsString = farmingPolicyUpdatedEvent.farmCertification.__kind.toString()
let farmCertType = FarmCertification.NotCertified
switch (farmCertificationTypeAsString) {
case 'NotCertified':
farmCertType = FarmCertification.NotCertified
break
case 'Gold':
farmCertType = FarmCertification.Gold
break
}
savedPolicy.farmCertification = farmCertType
savedPolicy.nodeCertification = parseNodeCertification(farmingPolicyUpdatedEvent.nodeCertification.__kind.toString())

savedPolicy.farmCertification = parseFarmCertification(farmingPolicyUpdatedEvent.farmCertification.__kind.toString())

await ctx.store.save<FarmingPolicy>(savedPolicy)
}
2 changes: 0 additions & 2 deletions src/mappings/tftPrice.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Store } from '@subsquid/typeorm-store'
import { Ctx } from '../processor'
import { SubstrateBlock } from '@subsquid/substrate-processor';
import { EventItem } from '@subsquid/substrate-processor/lib/interfaces/dataSelection'
import { In } from 'typeorm'
import { TftPriceModulePriceStoredEvent, TftPriceModuleAveragePriceStoredEvent } from '../types/events';
import { PriceStored, AveragePriceStored } from '../model';
import { ParserFixPointFn, parseI16F16 } from '@encointer/util'
Expand Down
Loading
Loading