From 78e0955dd781d4e91d0dec7d0b6550f6a0de970b Mon Sep 17 00:00:00 2001 From: Sameh Abouel-saad Date: Mon, 13 May 2024 20:52:22 +0300 Subject: [PATCH] fmt: fix inconsistent use of spaces in indentation (#168) --- src/mappings/contracts.ts | 874 ++++++++++----------- src/mappings/farms.ts | 636 +++++++-------- src/mappings/nodes.ts | 1214 ++++++++++++++--------------- src/mappings/policies.ts | 306 ++++---- src/mappings/solutionProviders.ts | 56 +- src/mappings/twins.ts | 356 ++++----- src/types/v101.ts | 174 ++--- src/types/v105.ts | 174 ++--- src/types/v118.ts | 72 +- src/types/v12.ts | 10 +- src/types/v122.ts | 36 +- src/types/v25.ts | 46 +- src/types/v28.ts | 58 +- src/types/v43.ts | 64 +- src/types/v49.ts | 234 +++--- src/types/v50.ts | 72 +- src/types/v51.ts | 38 +- src/types/v59.ts | 52 +- src/types/v63.ts | 136 ++-- src/types/v9.ts | 244 +++--- 20 files changed, 2426 insertions(+), 2426 deletions(-) diff --git a/src/mappings/contracts.ts b/src/mappings/contracts.ts index dd91c75..595dbf1 100644 --- a/src/mappings/contracts.ts +++ b/src/mappings/contracts.ts @@ -4,530 +4,530 @@ import { EventItem } from '@subsquid/substrate-processor/lib/interfaces/dataSele import { In } from 'typeorm' import { - ContractState, PublicIp, NameContract, - NodeContract, ContractBillReport, DiscountLevel, - ContractResources, Node, RentContract, NruConsumption + ContractState, PublicIp, NameContract, + NodeContract, ContractBillReport, DiscountLevel, + ContractResources, Node, RentContract, NruConsumption } from "../model"; import { - SmartContractModuleContractCreatedEvent, SmartContractModuleContractUpdatedEvent, - SmartContractModuleNodeContractCanceledEvent, SmartContractModuleNameContractCanceledEvent, - SmartContractModuleContractBilledEvent, SmartContractModuleUpdatedUsedResourcesEvent, - SmartContractModuleNruConsumptionReportReceivedEvent, SmartContractModuleRentContractCanceledEvent, - SmartContractModuleContractGracePeriodStartedEvent, SmartContractModuleContractGracePeriodEndedEvent + SmartContractModuleContractCreatedEvent, SmartContractModuleContractUpdatedEvent, + SmartContractModuleNodeContractCanceledEvent, SmartContractModuleNameContractCanceledEvent, + SmartContractModuleContractBilledEvent, SmartContractModuleUpdatedUsedResourcesEvent, + SmartContractModuleNruConsumptionReportReceivedEvent, SmartContractModuleRentContractCanceledEvent, + SmartContractModuleContractGracePeriodStartedEvent, SmartContractModuleContractGracePeriodEndedEvent } from "../types/events"; import { validateString } from "./nodes" export async function contractCreated( - ctx: Ctx, - item: EventItem<'SmartContractModule.ContractCreated', { event: { args: true } }>, - timestamp: bigint + ctx: Ctx, + item: EventItem<'SmartContractModule.ContractCreated', { event: { args: true } }>, + timestamp: bigint ): Promise { - let contractCreatedEvent = new SmartContractModuleContractCreatedEvent(ctx, item.event) - - let contractEvent - if (contractCreatedEvent.isV9) { - contractEvent = contractCreatedEvent.asV9 - } else if (contractCreatedEvent.isV25) { - contractEvent = contractCreatedEvent.asV25 - } else if (contractCreatedEvent.isV50) { - contractEvent = contractCreatedEvent.asV50 - } else if (contractCreatedEvent.isV59) { - contractEvent = contractCreatedEvent.asV59 - } else if (contractCreatedEvent.isV101) { - contractEvent = contractCreatedEvent.asV101 - } else if (contractCreatedEvent.isV105) { - contractEvent = contractCreatedEvent.asV105 - } else if (contractCreatedEvent.isV147) { - contractEvent = contractCreatedEvent.asV147 - } else if (contractCreatedEvent.isV148) { - contractEvent = contractCreatedEvent.asV148 - } - - if (!contractEvent) { - ctx.log.error(`found contract with unknown version! make sure types are updated`); - return - } - - let state = ContractState.Created - - let contract - if (contractEvent.contractType.__kind === "NameContract") { - let newNameContract = new NameContract() - newNameContract.id = item.event.id - contract = contractEvent.contractType.value - newNameContract.name = validateString(ctx, contract.name.toString()) - newNameContract.contractID = contractEvent.contractId - newNameContract.gridVersion = contractEvent.version - newNameContract.twinID = contractEvent.twinId - newNameContract.state = state - newNameContract.createdAt = timestamp - if (contractCreatedEvent.isV105) { - contractEvent = contractCreatedEvent.asV105 - newNameContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 - } - if (contractCreatedEvent.isV147) { - contractEvent = contractCreatedEvent.asV147 - newNameContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 - } - if (contractCreatedEvent.isV148) { - contractEvent = contractCreatedEvent.asV148 - newNameContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 - } - await ctx.store.save(newNameContract) - } - else if (contractEvent.contractType.__kind === "NodeContract") { - let newNodeContract = new NodeContract() - newNodeContract.id = item.event.id - - contract = contractEvent.contractType.value - - newNodeContract.contractID = contractEvent.contractId - newNodeContract.gridVersion = contractEvent.version - newNodeContract.twinID = contractEvent.twinId - newNodeContract.nodeID = contract.nodeId - newNodeContract.numberOfPublicIPs = contract.publicIps - - - newNodeContract.deploymentData = validateString(ctx, contract.deploymentData.toString()) - newNodeContract.deploymentHash = validateString(ctx, contract.deploymentHash.toString()) - - // newNodeContract.deploymentHash = contract.deploymentHash.toString() - newNodeContract.state = state - newNodeContract.createdAt = timestamp - if (contractCreatedEvent.isV105) { - contractEvent = contractCreatedEvent.asV105 - newNodeContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 - } - if (contractCreatedEvent.isV147) { - contractEvent = contractCreatedEvent.asV147 - newNodeContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 - } - if (contractCreatedEvent.isV148) { - contractEvent = contractCreatedEvent.asV148 - newNodeContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 - } - // Gather IPS and update them - let touchedIps: PublicIp[] = await ctx.store.find(PublicIp, { - where: { - ip: In([...new Set(contract.publicIpsList.map(ip => ip.ip.toString())).keys()]) - }, relations: { farm: true } - }) - - touchedIps = touchedIps.map(ip => { - ip.contractId = newNodeContract.contractID - return ip - }) - - if (contract.publicIps > 0 && touchedIps.length == 0) { - console.log(`something went wrong with contract ${contractEvent.contractId}`) - console.log(`ips: ${contract.publicIpsList}`) + let contractCreatedEvent = new SmartContractModuleContractCreatedEvent(ctx, item.event) + + let contractEvent + if (contractCreatedEvent.isV9) { + contractEvent = contractCreatedEvent.asV9 + } else if (contractCreatedEvent.isV25) { + contractEvent = contractCreatedEvent.asV25 + } else if (contractCreatedEvent.isV50) { + contractEvent = contractCreatedEvent.asV50 + } else if (contractCreatedEvent.isV59) { + contractEvent = contractCreatedEvent.asV59 + } else if (contractCreatedEvent.isV101) { + contractEvent = contractCreatedEvent.asV101 + } else if (contractCreatedEvent.isV105) { + contractEvent = contractCreatedEvent.asV105 + } else if (contractCreatedEvent.isV147) { + contractEvent = contractCreatedEvent.asV147 + } else if (contractCreatedEvent.isV148) { + contractEvent = contractCreatedEvent.asV148 } - if (newNodeContract.contractID === BigInt(17661)) { - console.log('contract found') - console.log(touchedIps) + if (!contractEvent) { + ctx.log.error(`found contract with unknown version! make sure types are updated`); + return } - await ctx.store.save(touchedIps) - await ctx.store.save(newNodeContract) - } else if (contractEvent.contractType.__kind === "RentContract") { - let newRentContract = new RentContract() - newRentContract.id = item.event.id - - contract = contractEvent.contractType.value - - newRentContract.contractID = contractEvent.contractId - newRentContract.gridVersion = contractEvent.version - newRentContract.twinID = contractEvent.twinId - newRentContract.nodeID = contract.nodeId - newRentContract.state = state - newRentContract.createdAt = timestamp - if (contractCreatedEvent.isV105) { - contractEvent = contractCreatedEvent.asV105 - newRentContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 - } - if (contractCreatedEvent.isV147) { - contractEvent = contractCreatedEvent.asV147 - newRentContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 - } - if (contractCreatedEvent.isV148) { - contractEvent = contractCreatedEvent.asV148 - newRentContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 + let state = ContractState.Created + + let contract + if (contractEvent.contractType.__kind === "NameContract") { + let newNameContract = new NameContract() + newNameContract.id = item.event.id + contract = contractEvent.contractType.value + newNameContract.name = validateString(ctx, contract.name.toString()) + newNameContract.contractID = contractEvent.contractId + newNameContract.gridVersion = contractEvent.version + newNameContract.twinID = contractEvent.twinId + newNameContract.state = state + newNameContract.createdAt = timestamp + if (contractCreatedEvent.isV105) { + contractEvent = contractCreatedEvent.asV105 + newNameContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 + } + if (contractCreatedEvent.isV147) { + contractEvent = contractCreatedEvent.asV147 + newNameContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 + } + if (contractCreatedEvent.isV148) { + contractEvent = contractCreatedEvent.asV148 + newNameContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 + } + await ctx.store.save(newNameContract) } - await ctx.store.save(newRentContract) + else if (contractEvent.contractType.__kind === "NodeContract") { + let newNodeContract = new NodeContract() + newNodeContract.id = item.event.id - // Update node to dedicated if it is rented - const savedNode = await ctx.store.get(Node, { where: { nodeID: contract.nodeId }, relations: { location: true, interfaces: true } }) - if (savedNode) { - savedNode.dedicated = true - await ctx.store.save(savedNode) + contract = contractEvent.contractType.value + + newNodeContract.contractID = contractEvent.contractId + newNodeContract.gridVersion = contractEvent.version + newNodeContract.twinID = contractEvent.twinId + newNodeContract.nodeID = contract.nodeId + newNodeContract.numberOfPublicIPs = contract.publicIps + + + newNodeContract.deploymentData = validateString(ctx, contract.deploymentData.toString()) + newNodeContract.deploymentHash = validateString(ctx, contract.deploymentHash.toString()) + + // newNodeContract.deploymentHash = contract.deploymentHash.toString() + newNodeContract.state = state + newNodeContract.createdAt = timestamp + if (contractCreatedEvent.isV105) { + contractEvent = contractCreatedEvent.asV105 + newNodeContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 + } + if (contractCreatedEvent.isV147) { + contractEvent = contractCreatedEvent.asV147 + newNodeContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 + } + if (contractCreatedEvent.isV148) { + contractEvent = contractCreatedEvent.asV148 + newNodeContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 + } + // Gather IPS and update them + let touchedIps: PublicIp[] = await ctx.store.find(PublicIp, { + where: { + ip: In([...new Set(contract.publicIpsList.map(ip => ip.ip.toString())).keys()]) + }, relations: { farm: true } + }) + + touchedIps = touchedIps.map(ip => { + ip.contractId = newNodeContract.contractID + return ip + }) + + if (contract.publicIps > 0 && touchedIps.length == 0) { + console.log(`something went wrong with contract ${contractEvent.contractId}`) + console.log(`ips: ${contract.publicIpsList}`) + } + + if (newNodeContract.contractID === BigInt(17661)) { + console.log('contract found') + console.log(touchedIps) + } + + await ctx.store.save(touchedIps) + await ctx.store.save(newNodeContract) + } else if (contractEvent.contractType.__kind === "RentContract") { + let newRentContract = new RentContract() + newRentContract.id = item.event.id + + contract = contractEvent.contractType.value + + newRentContract.contractID = contractEvent.contractId + newRentContract.gridVersion = contractEvent.version + newRentContract.twinID = contractEvent.twinId + newRentContract.nodeID = contract.nodeId + newRentContract.state = state + newRentContract.createdAt = timestamp + if (contractCreatedEvent.isV105) { + contractEvent = contractCreatedEvent.asV105 + newRentContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 + } + if (contractCreatedEvent.isV147) { + contractEvent = contractCreatedEvent.asV147 + newRentContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 + } + if (contractCreatedEvent.isV148) { + contractEvent = contractCreatedEvent.asV148 + newRentContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0 + } + await ctx.store.save(newRentContract) + + // Update node to dedicated if it is rented + const savedNode = await ctx.store.get(Node, { where: { nodeID: contract.nodeId }, relations: { location: true, interfaces: true } }) + if (savedNode) { + savedNode.dedicated = true + await ctx.store.save(savedNode) + } } - } } export async function contractUpdated( - ctx: Ctx, - item: EventItem<'SmartContractModule.ContractUpdated', { event: { args: true } }>, + ctx: Ctx, + item: EventItem<'SmartContractModule.ContractUpdated', { event: { args: true } }>, ) { - const contractUpdatedEvent = new SmartContractModuleContractUpdatedEvent(ctx, item.event) - - let contractEvent - if (contractUpdatedEvent.isV9) { - contractEvent = contractUpdatedEvent.asV9 - } else if (contractUpdatedEvent.isV25) { - contractEvent = contractUpdatedEvent.asV25 - } else if (contractUpdatedEvent.isV50) { - contractEvent = contractUpdatedEvent.asV50 - } else if (contractUpdatedEvent.isV59) { - contractEvent = contractUpdatedEvent.asV59 - } else if (contractUpdatedEvent.isV101) { - contractEvent = contractUpdatedEvent.asV101 - } else if (contractUpdatedEvent.isV105) { - contractEvent = contractUpdatedEvent.asV105 - } else if (contractUpdatedEvent.isV147) { - contractEvent = contractUpdatedEvent.asV147 - } else if (contractUpdatedEvent.isV148) { - contractEvent = contractUpdatedEvent.asV148 - } - - if (!contractEvent) { - ctx.log.error(`found contract with unknown version! make sure types are updated`); - return - } - - const SavedNodeContract = await ctx.store.get(NodeContract, { where: { contractID: contractEvent.contractId } }) - if (SavedNodeContract) { - await updateNodeContract(ctx, contractEvent, SavedNodeContract, ctx.store) - } - - const SavedNameContract = await ctx.store.get(NameContract, { where: { contractID: contractEvent.contractId } }) - if (SavedNameContract) { - await updateNameContract(ctx, contractEvent, SavedNameContract, ctx.store) - } + const contractUpdatedEvent = new SmartContractModuleContractUpdatedEvent(ctx, item.event) + + let contractEvent + if (contractUpdatedEvent.isV9) { + contractEvent = contractUpdatedEvent.asV9 + } else if (contractUpdatedEvent.isV25) { + contractEvent = contractUpdatedEvent.asV25 + } else if (contractUpdatedEvent.isV50) { + contractEvent = contractUpdatedEvent.asV50 + } else if (contractUpdatedEvent.isV59) { + contractEvent = contractUpdatedEvent.asV59 + } else if (contractUpdatedEvent.isV101) { + contractEvent = contractUpdatedEvent.asV101 + } else if (contractUpdatedEvent.isV105) { + contractEvent = contractUpdatedEvent.asV105 + } else if (contractUpdatedEvent.isV147) { + contractEvent = contractUpdatedEvent.asV147 + } else if (contractUpdatedEvent.isV148) { + contractEvent = contractUpdatedEvent.asV148 + } + + if (!contractEvent) { + ctx.log.error(`found contract with unknown version! make sure types are updated`); + return + } + + const SavedNodeContract = await ctx.store.get(NodeContract, { where: { contractID: contractEvent.contractId } }) + if (SavedNodeContract) { + await updateNodeContract(ctx, contractEvent, SavedNodeContract, ctx.store) + } + + const SavedNameContract = await ctx.store.get(NameContract, { where: { contractID: contractEvent.contractId } }) + if (SavedNameContract) { + await updateNameContract(ctx, contractEvent, SavedNameContract, ctx.store) + } } async function updateNodeContract(ctx: Ctx, ctr: any, contract: NodeContract, store: Store) { - if (ctr.contractType.__kind !== "NodeContract") return - - const parsedNodeContract = ctr.contractType.value - - contract.contractID = ctr.contractId - contract.gridVersion = ctr.version - contract.twinID = ctr.twinId - contract.nodeID = parsedNodeContract.nodeId - contract.numberOfPublicIPs = parsedNodeContract.publicIps - - contract.deploymentData = validateString(ctx, parsedNodeContract.deploymentData.toString()) - contract.deploymentHash = validateString(ctx, parsedNodeContract.deploymentHash.toString()) - - let state = ContractState.OutOfFunds - switch (ctr.state.__kind) { - case 'Created': - state = ContractState.Created - break - case 'Deleted': - state = ContractState.Deleted - break - } - contract.state = state - await store.save(contract) + if (ctr.contractType.__kind !== "NodeContract") return + + const parsedNodeContract = ctr.contractType.value + + contract.contractID = ctr.contractId + contract.gridVersion = ctr.version + contract.twinID = ctr.twinId + contract.nodeID = parsedNodeContract.nodeId + contract.numberOfPublicIPs = parsedNodeContract.publicIps + + contract.deploymentData = validateString(ctx, parsedNodeContract.deploymentData.toString()) + contract.deploymentHash = validateString(ctx, parsedNodeContract.deploymentHash.toString()) + + let state = ContractState.OutOfFunds + switch (ctr.state.__kind) { + case 'Created': + state = ContractState.Created + break + case 'Deleted': + state = ContractState.Deleted + break + } + contract.state = state + await store.save(contract) } async function updateNameContract(ctx: Ctx, ctr: any, contract: NameContract, store: Store) { - if (ctr.contractType.__kind !== "NameContract") return - - const parsedNameContract = ctr.contractType.value - - contract.contractID = ctr.contractId - contract.gridVersion = ctr.version - contract.twinID = ctr.twinId - contract.name = validateString(ctx, parsedNameContract.name.toString()) - - let state = ContractState.OutOfFunds - switch (ctr.state.__kind) { - case 'Created': - state = ContractState.Created - break - case 'Deleted': - state = ContractState.Deleted - break - } - contract.state = state - await store.save(contract) + if (ctr.contractType.__kind !== "NameContract") return + + const parsedNameContract = ctr.contractType.value + + contract.contractID = ctr.contractId + contract.gridVersion = ctr.version + contract.twinID = ctr.twinId + contract.name = validateString(ctx, parsedNameContract.name.toString()) + + let state = ContractState.OutOfFunds + switch (ctr.state.__kind) { + case 'Created': + state = ContractState.Created + break + case 'Deleted': + state = ContractState.Deleted + break + } + contract.state = state + await store.save(contract) } export async function nodeContractCanceled( - ctx: Ctx, - item: EventItem<'SmartContractModule.NodeContractCanceled', { event: { args: true } }>, + ctx: Ctx, + item: EventItem<'SmartContractModule.NodeContractCanceled', { event: { args: true } }>, ) { - let cancel = new SmartContractModuleNodeContractCanceledEvent(ctx, item.event) + let cancel = new SmartContractModuleNodeContractCanceledEvent(ctx, item.event) - let contractID = BigInt(0) - if (cancel.isV49) { - contractID = cancel.asV49[0] - } else if (cancel.isV105) { - contractID = cancel.asV105.contractId - } + let contractID = BigInt(0) + if (cancel.isV49) { + contractID = cancel.asV49[0] + } else if (cancel.isV105) { + contractID = cancel.asV105.contractId + } - if (contractID === BigInt(0)) return + if (contractID === BigInt(0)) return - const savedContract = await ctx.store.get(NodeContract, { where: { contractID } }) - if (!savedContract) return + const savedContract = await ctx.store.get(NodeContract, { where: { contractID } }) + if (!savedContract) return - savedContract.state = ContractState.Deleted - await ctx.store.save(savedContract) + savedContract.state = ContractState.Deleted + await ctx.store.save(savedContract) - const savedPublicIP = await ctx.store.get(PublicIp, { where: { contractId: contractID }, relations: { farm: true } }) - if (savedPublicIP) { - savedPublicIP.contractId = BigInt(0) - await ctx.store.save(savedPublicIP) - } + const savedPublicIP = await ctx.store.get(PublicIp, { where: { contractId: contractID }, relations: { farm: true } }) + if (savedPublicIP) { + savedPublicIP.contractId = BigInt(0) + await ctx.store.save(savedPublicIP) + } } export async function nameContractCanceled( - ctx: Ctx, - item: EventItem<'SmartContractModule.NameContractCanceled', { event: { args: true } }>, + ctx: Ctx, + item: EventItem<'SmartContractModule.NameContractCanceled', { event: { args: true } }>, ) { - const cancel = new SmartContractModuleNameContractCanceledEvent(ctx, item.event) + const cancel = new SmartContractModuleNameContractCanceledEvent(ctx, item.event) - let contractID = BigInt(0) - if (cancel.isV49) { - contractID = cancel.asV49 - } else if (cancel.isV105) { - contractID = cancel.asV105.contractId - } + let contractID = BigInt(0) + if (cancel.isV49) { + contractID = cancel.asV49 + } else if (cancel.isV105) { + contractID = cancel.asV105.contractId + } - if (contractID === BigInt(0)) return + if (contractID === BigInt(0)) return - const savedContract = await ctx.store.get(NameContract, { where: { contractID } }) + const savedContract = await ctx.store.get(NameContract, { where: { contractID } }) - if (!savedContract) return + if (!savedContract) return - savedContract.state = ContractState.Deleted + savedContract.state = ContractState.Deleted - await ctx.store.save(savedContract) + await ctx.store.save(savedContract) } export async function rentContractCanceled( - ctx: Ctx, - item: EventItem<'SmartContractModule.RentContractCanceled', { event: { args: true } }>, + ctx: Ctx, + item: EventItem<'SmartContractModule.RentContractCanceled', { event: { args: true } }>, ) { - const cancel = new SmartContractModuleRentContractCanceledEvent(ctx, item.event) + const cancel = new SmartContractModuleRentContractCanceledEvent(ctx, item.event) - let contractID = BigInt(0) - if (cancel.isV50) { - contractID = cancel.asV50 - } else if (cancel.isV105) { - contractID = cancel.asV105.contractId - } + let contractID = BigInt(0) + if (cancel.isV50) { + contractID = cancel.asV50 + } else if (cancel.isV105) { + contractID = cancel.asV105.contractId + } - if (contractID === BigInt(0)) return + if (contractID === BigInt(0)) return - const savedContract = await ctx.store.get(RentContract, { where: { contractID } }) + const savedContract = await ctx.store.get(RentContract, { where: { contractID } }) - if (!savedContract) return + if (!savedContract) return - savedContract.state = ContractState.Deleted + savedContract.state = ContractState.Deleted - await ctx.store.save(savedContract) + await ctx.store.save(savedContract) - // Update node dedicated status, if the node has an extra fee set, it means it's dedicated - const savedNode = await ctx.store.get(Node, { where: { nodeID: savedContract.nodeID }, relations: { location: true, interfaces: true } }) - if (savedNode) { - savedNode.dedicated = savedNode.extraFee !== null - await ctx.store.save(savedNode) - } + // Update node dedicated status, if the node has an extra fee set, it means it's dedicated + const savedNode = await ctx.store.get(Node, { where: { nodeID: savedContract.nodeID }, relations: { location: true, interfaces: true } }) + if (savedNode) { + savedNode.dedicated = savedNode.extraFee !== null + await ctx.store.save(savedNode) + } } export function collectContractBillReports(ctx: Ctx): ContractBillReport[] { - let list: ContractBillReport[] = [] - for (let block of ctx.blocks) { - for (let item of block.items) { - if (item.name === "SmartContractModule.ContractBilled") { - const contractBilledEvent = new SmartContractModuleContractBilledEvent(ctx, item.event).asV9 + let list: ContractBillReport[] = [] + for (let block of ctx.blocks) { + for (let item of block.items) { + if (item.name === "SmartContractModule.ContractBilled") { + const contractBilledEvent = new SmartContractModuleContractBilledEvent(ctx, item.event).asV9 + + const newContractBilledReport = new ContractBillReport() + + newContractBilledReport.id = item.event.id + newContractBilledReport.contractID = contractBilledEvent.contractId + + let level = DiscountLevel.None + switch (contractBilledEvent.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 = contractBilledEvent.amountBilled + newContractBilledReport.timestamp = contractBilledEvent.timestamp + + list.push(newContractBilledReport) + } + } + } + + 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() + const newContractBilledReport = new ContractBillReport() - newContractBilledReport.id = item.event.id - newContractBilledReport.contractID = contractBilledEvent.contractId + newContractBilledReport.id = item.event.id + newContractBilledReport.contractID = contract_billed_event.contractId - let level = DiscountLevel.None - switch (contractBilledEvent.discountLevel.__kind) { - case 'None': break - case 'Default': + let level = DiscountLevel.None + switch (contract_billed_event.discountLevel.__kind) { + case 'None': break + case 'Default': level = DiscountLevel.Default break - case 'Bronze': + case 'Bronze': level = DiscountLevel.Bronze break - case 'Silver': + case 'Silver': level = DiscountLevel.Silver break - case 'Gold': level = DiscountLevel.Gold - } - newContractBilledReport.discountReceived = level - newContractBilledReport.amountBilled = contractBilledEvent.amountBilled - newContractBilledReport.timestamp = contractBilledEvent.timestamp - - list.push(newContractBilledReport) - } + case 'Gold': level = DiscountLevel.Gold } - } + newContractBilledReport.discountReceived = level + newContractBilledReport.amountBilled = contract_billed_event.amountBilled + newContractBilledReport.timestamp = contract_billed_event.timestamp - return list + await ctx.store.save(newContractBilledReport) } -export async function contractBilled( - ctx: Ctx, - item: EventItem<'SmartContractModule.ContractBilled', { event: { args: true } }>, +export async function contractUpdateUsedResources( + ctx: Ctx, + item: EventItem<'SmartContractModule.UpdatedUsedResources', { 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(newContractBilledReport) + const usedResources = new SmartContractModuleUpdatedUsedResourcesEvent(ctx, item.event).asV49 + + const contractUsedResources = new ContractResources() + + const savedContract = await ctx.store.get(NodeContract, { where: { contractID: usedResources.contractId } }) + if (!savedContract) return + + const savedContractResources = await ctx.store.get(ContractResources, { where: { contract: { contractID: savedContract.contractID } }, relations: { contract: true } }) + if (savedContractResources) { + savedContractResources.cru = usedResources.used.cru + savedContractResources.sru = usedResources.used.sru + savedContractResources.hru = usedResources.used.hru + savedContractResources.mru = usedResources.used.mru + await ctx.store.save(savedContractResources) + + savedContract.resourcesUsed = savedContractResources + await ctx.store.save(savedContract) + } else { + contractUsedResources.id = item.event.id + contractUsedResources.cru = usedResources.used.cru + contractUsedResources.sru = usedResources.used.sru + contractUsedResources.hru = usedResources.used.hru + contractUsedResources.mru = usedResources.used.mru + contractUsedResources.contract = savedContract + await ctx.store.save(contractUsedResources) + + savedContract.resourcesUsed = contractUsedResources + await ctx.store.save(savedContract) + } } -export async function contractUpdateUsedResources( - ctx: Ctx, - item: EventItem<'SmartContractModule.UpdatedUsedResources', { event: { args: true } }>, +export async function nruConsumptionReportReceived( + ctx: Ctx, + item: EventItem<'SmartContractModule.NruConsumptionReportReceived', { event: { args: true } }>, ) { - const usedResources = new SmartContractModuleUpdatedUsedResourcesEvent(ctx, item.event).asV49 - - const contractUsedResources = new ContractResources() + const nruConsumptionReportEvent = new SmartContractModuleNruConsumptionReportReceivedEvent(ctx, item.event).asV49 - const savedContract = await ctx.store.get(NodeContract, { where: { contractID: usedResources.contractId } }) - if (!savedContract) return + const nruConsumption = new NruConsumption() - const savedContractResources = await ctx.store.get(ContractResources, { where: { contract: { contractID: savedContract.contractID } }, relations: { contract: true } }) - if (savedContractResources) { - savedContractResources.cru = usedResources.used.cru - savedContractResources.sru = usedResources.used.sru - savedContractResources.hru = usedResources.used.hru - savedContractResources.mru = usedResources.used.mru - await ctx.store.save(savedContractResources) + nruConsumption.id = item.event.id + nruConsumption.contractID = nruConsumptionReportEvent.contractId + nruConsumption.nru = nruConsumptionReportEvent.nru + nruConsumption.timestamp = nruConsumptionReportEvent.timestamp + nruConsumption.window = nruConsumptionReportEvent.window - savedContract.resourcesUsed = savedContractResources - await ctx.store.save(savedContract) - } else { - contractUsedResources.id = item.event.id - contractUsedResources.cru = usedResources.used.cru - contractUsedResources.sru = usedResources.used.sru - contractUsedResources.hru = usedResources.used.hru - contractUsedResources.mru = usedResources.used.mru - contractUsedResources.contract = savedContract - await ctx.store.save(contractUsedResources) - - savedContract.resourcesUsed = contractUsedResources - await ctx.store.save(savedContract) - } + await ctx.store.save(nruConsumption) } -export async function nruConsumptionReportReceived( - ctx: Ctx, - item: EventItem<'SmartContractModule.NruConsumptionReportReceived', { event: { args: true } }>, +export async function contractGracePeriodStarted( + ctx: Ctx, + item: EventItem<'SmartContractModule.ContractGracePeriodStarted', { event: { args: true } }>, ) { - const nruConsumptionReportEvent = new SmartContractModuleNruConsumptionReportReceivedEvent(ctx, item.event).asV49 + const contractGracePeriodStartedEvent = new SmartContractModuleContractGracePeriodStartedEvent(ctx, item.event) + let contractID - const nruConsumption = new NruConsumption() + if (contractGracePeriodStartedEvent.isV59) { + contractID = contractGracePeriodStartedEvent.asV59[0] + } else if (contractGracePeriodStartedEvent.isV105) { + contractID = contractGracePeriodStartedEvent.asV105.contractId + } - nruConsumption.id = item.event.id - nruConsumption.contractID = nruConsumptionReportEvent.contractId - nruConsumption.nru = nruConsumptionReportEvent.nru - nruConsumption.timestamp = nruConsumptionReportEvent.timestamp - nruConsumption.window = nruConsumptionReportEvent.window + const savedNodeContract = await ctx.store.get(NodeContract, { where: { contractID } }) + if (savedNodeContract) { + savedNodeContract.state = ContractState.GracePeriod + await ctx.store.save(savedNodeContract) + return + } - await ctx.store.save(nruConsumption) -} + const savedRentContract = await ctx.store.get(RentContract, { where: { contractID } }) + if (savedRentContract) { + savedRentContract.state = ContractState.GracePeriod + await ctx.store.save(savedRentContract) + return + } -export async function contractGracePeriodStarted( - ctx: Ctx, - item: EventItem<'SmartContractModule.ContractGracePeriodStarted', { event: { args: true } }>, -) { - const contractGracePeriodStartedEvent = new SmartContractModuleContractGracePeriodStartedEvent(ctx, item.event) - let contractID - - if (contractGracePeriodStartedEvent.isV59) { - contractID = contractGracePeriodStartedEvent.asV59[0] - } else if (contractGracePeriodStartedEvent.isV105) { - contractID = contractGracePeriodStartedEvent.asV105.contractId - } - - const savedNodeContract = await ctx.store.get(NodeContract, { where: { contractID } }) - if (savedNodeContract) { - savedNodeContract.state = ContractState.GracePeriod - await ctx.store.save(savedNodeContract) - return - } - - const savedRentContract = await ctx.store.get(RentContract, { where: { contractID } }) - if (savedRentContract) { - savedRentContract.state = ContractState.GracePeriod - await ctx.store.save(savedRentContract) - return - } - - const savedNameContract = await ctx.store.get(NameContract, { where: { contractID } }) - if (savedNameContract) { - savedNameContract.state = ContractState.GracePeriod - await ctx.store.save(savedNameContract) - return - } + const savedNameContract = await ctx.store.get(NameContract, { where: { contractID } }) + if (savedNameContract) { + savedNameContract.state = ContractState.GracePeriod + await ctx.store.save(savedNameContract) + return + } } export async function contractGracePeriodEnded( - ctx: Ctx, - item: EventItem<'SmartContractModule.ContractGracePeriodEnded', { event: { args: true } }>, + ctx: Ctx, + item: EventItem<'SmartContractModule.ContractGracePeriodEnded', { event: { args: true } }>, ) { - const contractGracePeriodEnded = new SmartContractModuleContractGracePeriodEndedEvent(ctx, item.event) - let contractID - - if (contractGracePeriodEnded.isV59) { - contractID = contractGracePeriodEnded.asV59[0] - } else if (contractGracePeriodEnded.isV105) { - contractID = contractGracePeriodEnded.asV105.contractId - } - - const savedNodeContract = await ctx.store.get(NodeContract, { where: { contractID } }) - if (savedNodeContract) { - savedNodeContract.state = ContractState.Created - await ctx.store.save(savedNodeContract) - return - } - - const savedRentContract = await ctx.store.get(RentContract, { where: { contractID } }) - if (savedRentContract) { - savedRentContract.state = ContractState.Created - await ctx.store.save(savedRentContract) - return - } - - const savedNameContract = await ctx.store.get(NameContract, { where: { contractID } }) - if (savedNameContract) { - savedNameContract.state = ContractState.Created - await ctx.store.save(savedNameContract) - return - } + const contractGracePeriodEnded = new SmartContractModuleContractGracePeriodEndedEvent(ctx, item.event) + let contractID + + if (contractGracePeriodEnded.isV59) { + contractID = contractGracePeriodEnded.asV59[0] + } else if (contractGracePeriodEnded.isV105) { + contractID = contractGracePeriodEnded.asV105.contractId + } + + const savedNodeContract = await ctx.store.get(NodeContract, { where: { contractID } }) + if (savedNodeContract) { + savedNodeContract.state = ContractState.Created + await ctx.store.save(savedNodeContract) + return + } + + const savedRentContract = await ctx.store.get(RentContract, { where: { contractID } }) + if (savedRentContract) { + savedRentContract.state = ContractState.Created + await ctx.store.save(savedRentContract) + return + } + + const savedNameContract = await ctx.store.get(NameContract, { where: { contractID } }) + if (savedNameContract) { + savedNameContract.state = ContractState.Created + await ctx.store.save(savedNameContract) + return + } } diff --git a/src/mappings/farms.ts b/src/mappings/farms.ts index f36a305..16244c1 100644 --- a/src/mappings/farms.ts +++ b/src/mappings/farms.ts @@ -7,381 +7,381 @@ import * as v63 from '../types/v63' import { validateString } from "./nodes" export class FarmWithIPs { - constructor(farmID: number, ips: PublicIp[]) { - this.farmID = farmID - this.publicIPs = ips - } + constructor(farmID: number, ips: PublicIp[]) { + this.farmID = farmID + this.publicIPs = ips + } - farmID: number; - publicIPs: PublicIp[]; + farmID: number; + publicIPs: PublicIp[]; } export async function farmStored( - ctx: Ctx, - item: EventItem<'TfgridModule.FarmStored', { event: { args: true } }> + ctx: Ctx, + item: EventItem<'TfgridModule.FarmStored', { event: { args: true } }> ) { - const farmStoredEvent = new TfgridModuleFarmStoredEvent(ctx, item.event) - - let farmStoredEventParsed - if (farmStoredEvent.isV9) { - farmStoredEventParsed = farmStoredEvent.asV9 - } else if (farmStoredEvent.isV50) { - farmStoredEventParsed = farmStoredEvent.asV50 - } else if (farmStoredEvent.isV63) { - farmStoredEventParsed = farmStoredEvent.asV63 - } else if (farmStoredEvent.isV101) { - let eventValue = item.event.args as v63.Farm - eventValue.dedicatedFarm = false - farmStoredEventParsed = farmStoredEvent.asV101 - } + const farmStoredEvent = new TfgridModuleFarmStoredEvent(ctx, item.event) + + let farmStoredEventParsed + if (farmStoredEvent.isV9) { + farmStoredEventParsed = farmStoredEvent.asV9 + } else if (farmStoredEvent.isV50) { + farmStoredEventParsed = farmStoredEvent.asV50 + } else if (farmStoredEvent.isV63) { + farmStoredEventParsed = farmStoredEvent.asV63 + } else if (farmStoredEvent.isV101) { + let eventValue = item.event.args as v63.Farm + eventValue.dedicatedFarm = false + farmStoredEventParsed = farmStoredEvent.asV101 + } - if (!farmStoredEventParsed) return + if (!farmStoredEventParsed) return - const newFarm = new Farm() + const newFarm = new Farm() - newFarm.id = item.event.id - newFarm.gridVersion = farmStoredEventParsed.version - newFarm.farmID = farmStoredEventParsed.id - newFarm.name = validateString(ctx, farmStoredEventParsed.name.toString()) - newFarm.twinID = farmStoredEventParsed.twinId - newFarm.pricingPolicyID = farmStoredEventParsed.pricingPolicyId - newFarm.dedicatedFarm = false - newFarm.certification = FarmCertification.NotCertified + newFarm.id = item.event.id + newFarm.gridVersion = farmStoredEventParsed.version + newFarm.farmID = farmStoredEventParsed.id + newFarm.name = validateString(ctx, farmStoredEventParsed.name.toString()) + newFarm.twinID = farmStoredEventParsed.twinId + newFarm.pricingPolicyID = farmStoredEventParsed.pricingPolicyId + newFarm.dedicatedFarm = false + newFarm.certification = FarmCertification.NotCertified - newFarm.publicIPs = [] + newFarm.publicIPs = [] - await ctx.store.save(newFarm) + await ctx.store.save(newFarm) - const ipPromises = farmStoredEventParsed.publicIps.map(ip => { - const newIP = new PublicIp() + const ipPromises = farmStoredEventParsed.publicIps.map(ip => { + const newIP = new PublicIp() - newIP.id = item.event.id + newIP.id = item.event.id - newIP.ip = validateString(ctx, ip.ip.toString()) - newIP.gateway = validateString(ctx, ip.gateway.toString()) + newIP.ip = validateString(ctx, ip.ip.toString()) + newIP.gateway = validateString(ctx, ip.gateway.toString()) - newIP.contractId = ip.contractId - newIP.farm = newFarm + newIP.contractId = ip.contractId + newIP.farm = newFarm - newFarm.publicIPs?.push(newIP) + newFarm.publicIPs?.push(newIP) - return ctx.store.save(newIP) - }) - await Promise.all(ipPromises) - await ctx.store.save(newFarm) + return ctx.store.save(newIP) + }) + await Promise.all(ipPromises) + await ctx.store.save(newFarm) } export async function farmUpdated( - ctx: Ctx, - item: EventItem<'TfgridModule.FarmUpdated', { event: { args: true } }> + ctx: Ctx, + item: EventItem<'TfgridModule.FarmUpdated', { event: { args: true } }> ) { - const farmUpdatedEvent = new TfgridModuleFarmUpdatedEvent(ctx, item.event) - - let certification = FarmCertification.NotCertified - - let farmUpdatedEventParsed - if (farmUpdatedEvent.isV9) { - farmUpdatedEventParsed = farmUpdatedEvent.asV9 - } else if (farmUpdatedEvent.isV50) { - farmUpdatedEventParsed = farmUpdatedEvent.asV50 - } else if (farmUpdatedEvent.isV63) { - farmUpdatedEventParsed = farmUpdatedEvent.asV63 - switch (farmUpdatedEvent.asV101.certification.__kind) { - case "Gold": { - certification = FarmCertification.Gold - } - } - } else if (farmUpdatedEvent.isV101) { - let eventValue = item.event.args as v63.Farm - eventValue.dedicatedFarm = false - farmUpdatedEventParsed = farmUpdatedEvent.asV101 - switch (farmUpdatedEvent.asV101.certification.__kind) { - case "Gold": { - certification = FarmCertification.Gold - } + const farmUpdatedEvent = new TfgridModuleFarmUpdatedEvent(ctx, item.event) + + let certification = FarmCertification.NotCertified + + let farmUpdatedEventParsed + if (farmUpdatedEvent.isV9) { + farmUpdatedEventParsed = farmUpdatedEvent.asV9 + } else if (farmUpdatedEvent.isV50) { + farmUpdatedEventParsed = farmUpdatedEvent.asV50 + } else if (farmUpdatedEvent.isV63) { + farmUpdatedEventParsed = farmUpdatedEvent.asV63 + switch (farmUpdatedEvent.asV101.certification.__kind) { + case "Gold": { + certification = FarmCertification.Gold + } + } + } else if (farmUpdatedEvent.isV101) { + let eventValue = item.event.args as v63.Farm + eventValue.dedicatedFarm = false + farmUpdatedEventParsed = farmUpdatedEvent.asV101 + switch (farmUpdatedEvent.asV101.certification.__kind) { + case "Gold": { + certification = FarmCertification.Gold + } + } } - } - if (!farmUpdatedEventParsed) return + if (!farmUpdatedEventParsed) return - const savedFarm = await ctx.store.get(Farm, { where: { farmID: farmUpdatedEventParsed.id } }) - if (!savedFarm) return + const savedFarm = await ctx.store.get(Farm, { where: { farmID: farmUpdatedEventParsed.id } }) + if (!savedFarm) return - savedFarm.gridVersion = farmUpdatedEventParsed.version - savedFarm.name = validateString(ctx, farmUpdatedEventParsed.name.toString()) - savedFarm.twinID = farmUpdatedEventParsed.twinId - // reason for commented the below line is that update_farm on-chain isnever meant to change the pricing policy attached to a farm - // see here https://github.com/threefoldtech/tfchain_graphql/issues/96#issuecomment-2068325597 - // savedFarm.pricingPolicyID = farmUpdatedEventParsed.pricingPolicyId - savedFarm.certification = certification + savedFarm.gridVersion = farmUpdatedEventParsed.version + savedFarm.name = validateString(ctx, farmUpdatedEventParsed.name.toString()) + savedFarm.twinID = farmUpdatedEventParsed.twinId + // reason for commented the below line is that update_farm on-chain isnever meant to change the pricing policy attached to a farm + // see here https://github.com/threefoldtech/tfchain_graphql/issues/96#issuecomment-2068325597 + // savedFarm.pricingPolicyID = farmUpdatedEventParsed.pricingPolicyId + savedFarm.certification = certification - let eventPublicIPs = farmUpdatedEventParsed.publicIps + let eventPublicIPs = farmUpdatedEventParsed.publicIps - await farmUpdatedEventParsed.publicIps.forEach(async ip => { - if (ip.ip.toString().indexOf('\x00') >= 0) { - return - } - const savedIP = await ctx.store.get(PublicIp, { where: { ip: ip.ip.toString() }, relations: { farm: true } }) - // ip is already there in storage, don't save it again - if (savedIP) { - savedIP.ip = validateString(ctx, ip.ip.toString()) // not effective, but for since we already check for \x00 - savedIP.gateway = validateString(ctx, ip.gateway.toString()) - await ctx.store.save(savedIP) - } else { - const newIP = new PublicIp() - newIP.id = item.event.id - newIP.ip = validateString(ctx, ip.ip.toString()) - newIP.gateway = validateString(ctx, ip.gateway.toString()) - newIP.contractId = ip.contractId - newIP.farm = savedFarm - - await ctx.store.save(newIP) - if (!savedFarm.publicIPs) { - savedFarm.publicIPs = [] - } - savedFarm.publicIPs.push(newIP) - } - }) + await farmUpdatedEventParsed.publicIps.forEach(async ip => { + if (ip.ip.toString().indexOf('\x00') >= 0) { + return + } + const savedIP = await ctx.store.get(PublicIp, { where: { ip: ip.ip.toString() }, relations: { farm: true } }) + // ip is already there in storage, don't save it again + if (savedIP) { + savedIP.ip = validateString(ctx, ip.ip.toString()) // not effective, but for since we already check for \x00 + savedIP.gateway = validateString(ctx, ip.gateway.toString()) + await ctx.store.save(savedIP) + } else { + const newIP = new PublicIp() + newIP.id = item.event.id + newIP.ip = validateString(ctx, ip.ip.toString()) + newIP.gateway = validateString(ctx, ip.gateway.toString()) + newIP.contractId = ip.contractId + newIP.farm = savedFarm + + await ctx.store.save(newIP) + if (!savedFarm.publicIPs) { + savedFarm.publicIPs = [] + } + savedFarm.publicIPs.push(newIP) + } + }) - await ctx.store.save(savedFarm) + await ctx.store.save(savedFarm) - const publicIPsOfFarm = await ctx.store.find(PublicIp, { where: { farm: { id: savedFarm.id } }, relations: { farm: true } }) - publicIPsOfFarm.forEach(async ip => { - if (eventPublicIPs.filter(eventIp => validateString(ctx, eventIp.ip.toString()) === ip.ip).length === 0) { - // IP got removed from farm - await ctx.store.remove(ip) - } - }) + const publicIPsOfFarm = await ctx.store.find(PublicIp, { where: { farm: { id: savedFarm.id } }, relations: { farm: true } }) + publicIPsOfFarm.forEach(async ip => { + if (eventPublicIPs.filter(eventIp => validateString(ctx, eventIp.ip.toString()) === ip.ip).length === 0) { + // IP got removed from farm + await ctx.store.remove(ip) + } + }) - let farm = item.event.args as Farm - if (farm.dedicatedFarm) { - savedFarm.dedicatedFarm = farm.dedicatedFarm - await ctx.store.save(savedFarm) - } + let farm = item.event.args as Farm + if (farm.dedicatedFarm) { + savedFarm.dedicatedFarm = farm.dedicatedFarm + await ctx.store.save(savedFarm) + } } export async function farmDeleted( - ctx: Ctx, - item: EventItem<'TfgridModule.FarmDeleted', { event: { args: true } }> + ctx: Ctx, + item: EventItem<'TfgridModule.FarmDeleted', { event: { args: true } }> ) { - const farmID = new TfgridModuleFarmDeletedEvent(ctx, item.event).asV49 + const farmID = new TfgridModuleFarmDeletedEvent(ctx, item.event).asV49 - const savedFarm = await ctx.store.get(Farm, { where: { farmID: farmID } }) + const savedFarm = await ctx.store.get(Farm, { where: { farmID: farmID } }) - if (savedFarm) { - await ctx.store.remove(savedFarm) - } + if (savedFarm) { + await ctx.store.remove(savedFarm) + } } export async function farmPayoutV2AddressRegistered( - ctx: Ctx, - item: EventItem<'TfgridModule.FarmPayoutV2AddressRegistered', { event: { args: true } }> + ctx: Ctx, + item: EventItem<'TfgridModule.FarmPayoutV2AddressRegistered', { event: { args: true } }> ) { - const [farmID, stellarAddress] = new TfgridModuleFarmPayoutV2AddressRegisteredEvent(ctx, item.event).asV49 + const [farmID, stellarAddress] = new TfgridModuleFarmPayoutV2AddressRegisteredEvent(ctx, item.event).asV49 - const savedFarm = await ctx.store.get(Farm, { where: { farmID: farmID } }) + const savedFarm = await ctx.store.get(Farm, { where: { farmID: farmID } }) - if (savedFarm) { - let address = '' - if (!stellarAddress.includes(0)) { - address = validateString(ctx, stellarAddress.toString()) - } + if (savedFarm) { + let address = '' + if (!stellarAddress.includes(0)) { + address = validateString(ctx, stellarAddress.toString()) + } - savedFarm.stellarAddress = address - await ctx.store.save(savedFarm) - } + savedFarm.stellarAddress = address + await ctx.store.save(savedFarm) + } } export async function farmCertificationSet( - ctx: Ctx, - item: EventItem<'TfgridModule.FarmCertificationSet', { event: { args: true } }> + ctx: Ctx, + item: EventItem<'TfgridModule.FarmCertificationSet', { event: { args: true } }> ) { - const [farmID, certification] = new TfgridModuleFarmCertificationSetEvent(ctx, item.event).asV63 - - const savedFarm = await ctx.store.get(Farm, { where: { farmID: farmID } }) - - if (!savedFarm) { - return - } - - let certType = FarmCertification.NotCertified - switch (certification.__kind.toString()) { - case 'NotCertified': - certType = FarmCertification.NotCertified - break - case 'Gold': - certType = FarmCertification.Gold - break - } - - savedFarm.certification = certType - await ctx.store.save(savedFarm) -} - -export async function farmCreateOrUpdateOrDelete(ctx: Ctx): Promise<[Farm[], Farm[], Farm[], FarmWithIPs[]]> { - let newFarms: Farm[] = [] - let updatedFarms: Farm[] = [] - let deletedFarms: Farm[] = [] - let publicIPs: FarmWithIPs[] = [] - - for (let block of ctx.blocks) { - for (let item of block.items) { - if (item.name === "TfgridModule.FarmStored") { - const farmStoredEvent = new TfgridModuleFarmStoredEvent(ctx, item.event) - let farmStoredEventParsed - if (farmStoredEvent.isV9) { - farmStoredEventParsed = farmStoredEvent.asV9 - } else if (farmStoredEvent.isV50) { - farmStoredEventParsed = farmStoredEvent.asV50 - } else if (farmStoredEvent.isV63) { - farmStoredEventParsed = farmStoredEvent.asV63 - } else if (farmStoredEvent.isV101) { - farmStoredEventParsed = farmStoredEvent.asV101 - } - - if (!farmStoredEventParsed) continue - - const newFarm = new Farm() - - let eventID = item.event.id - - newFarm.id = eventID - newFarm.gridVersion = farmStoredEventParsed.version - newFarm.farmID = farmStoredEventParsed.id - newFarm.name = validateString(ctx, farmStoredEventParsed.name.toString()) - newFarm.twinID = farmStoredEventParsed.twinId - newFarm.pricingPolicyID = farmStoredEventParsed.pricingPolicyId - newFarm.dedicatedFarm = false - newFarm.certification = FarmCertification.NotCertified + const [farmID, certification] = new TfgridModuleFarmCertificationSetEvent(ctx, item.event).asV63 - newFarm.publicIPs = [] + const savedFarm = await ctx.store.get(Farm, { where: { farmID: farmID } }) - let ips: PublicIp[] = [] - farmStoredEventParsed.publicIps.forEach(ip => { - // ctx.log.info("storing ips") - const newIP = new PublicIp() - - newIP.id = eventID - - newIP.ip = validateString(ctx, ip.ip.toString()) - newIP.gateway = validateString(ctx, ip.gateway.toString()) - - newIP.contractId = ip.contractId - newIP.farm = newFarm - - ips.push(newIP) - }) - - // ctx.log.info(`storing farm: ${newFarm.id}`) - - newFarms.push(newFarm) - publicIPs.push(new FarmWithIPs(newFarm.farmID, ips)) - } - if (item.name === "TfgridModule.FarmUpdated") { - const farmUpdatedEvent = new TfgridModuleFarmUpdatedEvent(ctx, item.event) - - let farmUpdatedEventParsed: any - if (farmUpdatedEvent.isV9) { - farmUpdatedEventParsed = farmUpdatedEvent.asV9 - } else if (farmUpdatedEvent.isV50) { - farmUpdatedEventParsed = farmUpdatedEvent.asV50 - } else if (farmUpdatedEvent.isV63) { - farmUpdatedEventParsed = farmUpdatedEvent.asV63 - } else if (farmUpdatedEvent.isV101) { - farmUpdatedEventParsed = farmUpdatedEvent.asV101 - } - - if (!farmUpdatedEventParsed) { - ctx.log.error('cannot parse farm updated event') - continue - } - - const eventID = item.event.id - - const foundInNewListIndex: number = newFarms.findIndex(t => t.farmID == farmUpdatedEventParsed.id) - if (foundInNewListIndex != -1) { - const savedFarm: Farm = newFarms[foundInNewListIndex] - savedFarm.gridVersion = farmUpdatedEventParsed.version - savedFarm.name = validateString(ctx, farmUpdatedEventParsed.name.toString()) - savedFarm.twinID = farmUpdatedEventParsed.twinId - savedFarm.pricingPolicyID = farmUpdatedEventParsed.pricingPolicyId - // const pubIps = updatePublicIPs(ctx, farmUpdatedEventParsed.publicIps, eventID, savedFarm) - newFarms[foundInNewListIndex] = savedFarm - - publicIPs = getPublicIPs(ctx, savedFarm, publicIPs, farmUpdatedEventParsed.publicIps, eventID) - - continue - } - - const foundInUpdatedListIndex: number = updatedFarms.findIndex(t => t.farmID == farmUpdatedEventParsed.id) - if (foundInUpdatedListIndex != -1) { - let savedFarm: Farm = updatedFarms[foundInUpdatedListIndex] - savedFarm.gridVersion = farmUpdatedEventParsed.version - savedFarm.name = validateString(ctx, farmUpdatedEventParsed.name.toString()) - savedFarm.twinID = farmUpdatedEventParsed.twinId - savedFarm.pricingPolicyID = farmUpdatedEventParsed.pricingPolicyId - updatedFarms[foundInUpdatedListIndex] = savedFarm - - publicIPs = getPublicIPs(ctx, savedFarm, publicIPs, farmUpdatedEventParsed.publicIps, eventID) - - continue - } - - const savedFarm = await ctx.store.get(Farm, { where: { farmID: farmUpdatedEventParsed.id } }) - if (!savedFarm) continue - - savedFarm.gridVersion = farmUpdatedEventParsed.version - savedFarm.name = validateString(ctx, farmUpdatedEventParsed.name.toString()) - savedFarm.twinID = farmUpdatedEventParsed.twinId - savedFarm.pricingPolicyID = farmUpdatedEventParsed.pricingPolicyId + if (!savedFarm) { + return + } - // ctx.log.info(`updating farm: ${savedFarm.id}`) + let certType = FarmCertification.NotCertified + switch (certification.__kind.toString()) { + case 'NotCertified': + certType = FarmCertification.NotCertified + break + case 'Gold': + certType = FarmCertification.Gold + break + } - publicIPs = getPublicIPs(ctx, savedFarm, publicIPs, farmUpdatedEventParsed.publicIps, eventID) + savedFarm.certification = certType + await ctx.store.save(savedFarm) +} - updatedFarms.push(savedFarm) - } - if (item.name === "TfgridModule.FarmDeleted") { - const farmID = new TfgridModuleFarmDeletedEvent(ctx, item.event).asV49 - const savedFarm = await ctx.store.get(Farm, { where: { farmID: farmID } }) - if (savedFarm) { - deletedFarms.push(savedFarm) +export async function farmCreateOrUpdateOrDelete(ctx: Ctx): Promise<[Farm[], Farm[], Farm[], FarmWithIPs[]]> { + let newFarms: Farm[] = [] + let updatedFarms: Farm[] = [] + let deletedFarms: Farm[] = [] + let publicIPs: FarmWithIPs[] = [] + + for (let block of ctx.blocks) { + for (let item of block.items) { + if (item.name === "TfgridModule.FarmStored") { + const farmStoredEvent = new TfgridModuleFarmStoredEvent(ctx, item.event) + let farmStoredEventParsed + if (farmStoredEvent.isV9) { + farmStoredEventParsed = farmStoredEvent.asV9 + } else if (farmStoredEvent.isV50) { + farmStoredEventParsed = farmStoredEvent.asV50 + } else if (farmStoredEvent.isV63) { + farmStoredEventParsed = farmStoredEvent.asV63 + } else if (farmStoredEvent.isV101) { + farmStoredEventParsed = farmStoredEvent.asV101 + } + + if (!farmStoredEventParsed) continue + + const newFarm = new Farm() + + let eventID = item.event.id + + newFarm.id = eventID + newFarm.gridVersion = farmStoredEventParsed.version + newFarm.farmID = farmStoredEventParsed.id + newFarm.name = validateString(ctx, farmStoredEventParsed.name.toString()) + newFarm.twinID = farmStoredEventParsed.twinId + newFarm.pricingPolicyID = farmStoredEventParsed.pricingPolicyId + newFarm.dedicatedFarm = false + newFarm.certification = FarmCertification.NotCertified + + newFarm.publicIPs = [] + + let ips: PublicIp[] = [] + farmStoredEventParsed.publicIps.forEach(ip => { + // ctx.log.info("storing ips") + const newIP = new PublicIp() + + newIP.id = eventID + + newIP.ip = validateString(ctx, ip.ip.toString()) + newIP.gateway = validateString(ctx, ip.gateway.toString()) + + newIP.contractId = ip.contractId + newIP.farm = newFarm + + ips.push(newIP) + }) + + // ctx.log.info(`storing farm: ${newFarm.id}`) + + newFarms.push(newFarm) + publicIPs.push(new FarmWithIPs(newFarm.farmID, ips)) + } + if (item.name === "TfgridModule.FarmUpdated") { + const farmUpdatedEvent = new TfgridModuleFarmUpdatedEvent(ctx, item.event) + + let farmUpdatedEventParsed: any + if (farmUpdatedEvent.isV9) { + farmUpdatedEventParsed = farmUpdatedEvent.asV9 + } else if (farmUpdatedEvent.isV50) { + farmUpdatedEventParsed = farmUpdatedEvent.asV50 + } else if (farmUpdatedEvent.isV63) { + farmUpdatedEventParsed = farmUpdatedEvent.asV63 + } else if (farmUpdatedEvent.isV101) { + farmUpdatedEventParsed = farmUpdatedEvent.asV101 + } + + if (!farmUpdatedEventParsed) { + ctx.log.error('cannot parse farm updated event') + continue + } + + const eventID = item.event.id + + const foundInNewListIndex: number = newFarms.findIndex(t => t.farmID == farmUpdatedEventParsed.id) + if (foundInNewListIndex != -1) { + const savedFarm: Farm = newFarms[foundInNewListIndex] + savedFarm.gridVersion = farmUpdatedEventParsed.version + savedFarm.name = validateString(ctx, farmUpdatedEventParsed.name.toString()) + savedFarm.twinID = farmUpdatedEventParsed.twinId + savedFarm.pricingPolicyID = farmUpdatedEventParsed.pricingPolicyId + // const pubIps = updatePublicIPs(ctx, farmUpdatedEventParsed.publicIps, eventID, savedFarm) + newFarms[foundInNewListIndex] = savedFarm + + publicIPs = getPublicIPs(ctx, savedFarm, publicIPs, farmUpdatedEventParsed.publicIps, eventID) + + continue + } + + const foundInUpdatedListIndex: number = updatedFarms.findIndex(t => t.farmID == farmUpdatedEventParsed.id) + if (foundInUpdatedListIndex != -1) { + let savedFarm: Farm = updatedFarms[foundInUpdatedListIndex] + savedFarm.gridVersion = farmUpdatedEventParsed.version + savedFarm.name = validateString(ctx, farmUpdatedEventParsed.name.toString()) + savedFarm.twinID = farmUpdatedEventParsed.twinId + savedFarm.pricingPolicyID = farmUpdatedEventParsed.pricingPolicyId + updatedFarms[foundInUpdatedListIndex] = savedFarm + + publicIPs = getPublicIPs(ctx, savedFarm, publicIPs, farmUpdatedEventParsed.publicIps, eventID) + + continue + } + + const savedFarm = await ctx.store.get(Farm, { where: { farmID: farmUpdatedEventParsed.id } }) + if (!savedFarm) continue + + savedFarm.gridVersion = farmUpdatedEventParsed.version + savedFarm.name = validateString(ctx, farmUpdatedEventParsed.name.toString()) + savedFarm.twinID = farmUpdatedEventParsed.twinId + savedFarm.pricingPolicyID = farmUpdatedEventParsed.pricingPolicyId + + // ctx.log.info(`updating farm: ${savedFarm.id}`) + + publicIPs = getPublicIPs(ctx, savedFarm, publicIPs, farmUpdatedEventParsed.publicIps, eventID) + + updatedFarms.push(savedFarm) + } + if (item.name === "TfgridModule.FarmDeleted") { + const farmID = new TfgridModuleFarmDeletedEvent(ctx, item.event).asV49 + const savedFarm = await ctx.store.get(Farm, { where: { farmID: farmID } }) + if (savedFarm) { + deletedFarms.push(savedFarm) + } + } } - } } - } - return [newFarms, updatedFarms, deletedFarms, publicIPs] + return [newFarms, updatedFarms, deletedFarms, publicIPs] } function getPublicIPs(ctx: Ctx, farm: Farm, savedFarmIps: FarmWithIPs[], newIps: PublicIp[], eventID: any): FarmWithIPs[] { - let toModify = savedFarmIps.filter(f => f.farmID === farm.farmID) - if (toModify.length === 0) { - return [] - } - - // For every IP in the updated event: - // Check if it's already in the savedFarmIps to be saved, if so, update the value - // If it's not there, add it - newIps.forEach((ip: PublicIp) => { - let foundIdx = toModify[0].publicIPs.findIndex(pubip => pubip.ip === ip.ip.toString()) - // console.log(`found index: ${foundIdx}`) - if (foundIdx !== -1) { - toModify[0].publicIPs[foundIdx].contractId = ip.contractId - toModify[0].publicIPs[foundIdx].ip = validateString(ctx, ip.ip.toString()) - toModify[0].publicIPs[foundIdx].gateway = validateString(ctx, ip.gateway.toString()) - } else { - const newIP = new PublicIp() - newIP.id = eventID - newIP.ip = ip.ip.toString() - newIP.gateway = validateString(ctx, ip.gateway.toString()) - newIP.contractId = ip.contractId - newIP.farm = farm - // ctx.log.info(`saving new ip: ${newIP.ip}`) - // ctx.log.warn(`farm ips: ${toModify[0].publicIPs}`) - toModify[0].publicIPs.push(newIP) + let toModify = savedFarmIps.filter(f => f.farmID === farm.farmID) + if (toModify.length === 0) { + return [] } - }) - return savedFarmIps + // For every IP in the updated event: + // Check if it's already in the savedFarmIps to be saved, if so, update the value + // If it's not there, add it + newIps.forEach((ip: PublicIp) => { + let foundIdx = toModify[0].publicIPs.findIndex(pubip => pubip.ip === ip.ip.toString()) + // console.log(`found index: ${foundIdx}`) + if (foundIdx !== -1) { + toModify[0].publicIPs[foundIdx].contractId = ip.contractId + toModify[0].publicIPs[foundIdx].ip = validateString(ctx, ip.ip.toString()) + toModify[0].publicIPs[foundIdx].gateway = validateString(ctx, ip.gateway.toString()) + } else { + const newIP = new PublicIp() + newIP.id = eventID + newIP.ip = ip.ip.toString() + newIP.gateway = validateString(ctx, ip.gateway.toString()) + newIP.contractId = ip.contractId + newIP.farm = farm + // ctx.log.info(`saving new ip: ${newIP.ip}`) + // ctx.log.warn(`farm ips: ${toModify[0].publicIPs}`) + toModify[0].publicIPs.push(newIP) + } + }) + + return savedFarmIps } diff --git a/src/mappings/nodes.ts b/src/mappings/nodes.ts index b2cc85a..f0cc481 100644 --- a/src/mappings/nodes.ts +++ b/src/mappings/nodes.ts @@ -1,10 +1,10 @@ import { Node, Location, PublicConfig, NodeCertification, Interfaces, UptimeEvent, NodeResourcesTotal, NodePower, PowerState, Power, PowerTargetReport, PowerStateReport } from "../model"; import { - TfgridModuleNodeCertificationSetEvent, TfgridModuleNodeDeletedEvent, - TfgridModuleNodePublicConfigStoredEvent, TfgridModuleNodeStoredEvent, - TfgridModuleNodeUpdatedEvent, TfgridModuleNodeUptimeReportedEvent, - TfgridModulePowerStateChangedEvent, TfgridModulePowerTargetChangedEvent, - SmartContractModuleNodeExtraFeeSetEvent + TfgridModuleNodeCertificationSetEvent, TfgridModuleNodeDeletedEvent, + TfgridModuleNodePublicConfigStoredEvent, TfgridModuleNodeStoredEvent, + TfgridModuleNodeUpdatedEvent, TfgridModuleNodeUptimeReportedEvent, + TfgridModulePowerStateChangedEvent, TfgridModulePowerTargetChangedEvent, + SmartContractModuleNodeExtraFeeSetEvent } from "../types/events"; import { SubstrateBlock } from '@subsquid/substrate-processor'; import { In } from 'typeorm' @@ -16,695 +16,695 @@ import assert from "assert"; import { allowedNodeEnvironmentFlags } from "process"; export async function nodeStored( - ctx: Ctx, - item: EventItem<'TfgridModule.NodeStored', { event: { args: true } }>, - timestamp: bigint + ctx: Ctx, + item: EventItem<'TfgridModule.NodeStored', { event: { args: true } }>, + timestamp: bigint ) { - const node = new TfgridModuleNodeStoredEvent(ctx, item.event) - - let nodeEvent - if (node.isV9) { - nodeEvent = node.asV9 - } else if (node.isV28) { - nodeEvent = node.asV28 - } else if (node.isV43) { - nodeEvent = node.asV43 - } else if (node.isV63) { - nodeEvent = node.asV63 - } else if (node.isV101) { - nodeEvent = node.asV101 - } else if (node.isV105) { - nodeEvent = node.asV105 - } else if (node.isV118) { - nodeEvent = node.asV118 - } - - if (!nodeEvent) { - return - } - - const newNode = new Node() - newNode.id = item.event.id - newNode.gridVersion = nodeEvent.version - newNode.farmID = nodeEvent.farmId - newNode.nodeID = nodeEvent.id - newNode.twinID = nodeEvent.twinId - newNode.dedicated = false - - newNode.createdAt = timestamp - newNode.updatedAt = timestamp - - if (node.isV9) { - nodeEvent = node.asV9 - newNode.country = validateString(ctx, nodeEvent.country.toString()) - newNode.city = validateString(ctx, nodeEvent.city.toString()) - } - if (node.isV28) { - nodeEvent = node.asV28 - newNode.country = validateString(ctx, nodeEvent.country.toString()) - newNode.city = validateString(ctx, nodeEvent.city.toString()) - } - - newNode.created = Number(nodeEvent.created) - newNode.farmingPolicyId = nodeEvent.farmingPolicyId - newNode.certification = NodeCertification.Diy - - const newLocation = new Location() - newLocation.id = item.event.id - newLocation.latitude = validateString(ctx, nodeEvent.location.latitude.toString()) - newLocation.longitude = validateString(ctx, nodeEvent.location.longitude.toString()) - await ctx.store.save(newLocation) - - newNode.location = newLocation - - await ctx.store.save(newNode) - - const pubConfig = getNodePublicConfig(ctx, node) - const newPubConfig = new PublicConfig() - newPubConfig.id = item.event.id - newPubConfig.ipv4 = pubConfig?.ip4 - newPubConfig.gw4 = pubConfig?.gw4 - newPubConfig.ipv6 = pubConfig?.ip6 - newPubConfig.gw6 = pubConfig?.gw6 - newPubConfig.node = newNode - - if (node.isV43) { - const nodeAsV43 = node.asV43 - newNode.country = validateString(ctx, nodeAsV43.country.toString()) - newNode.city = validateString(ctx, nodeAsV43.city.toString()) - newNode.secure = nodeAsV43.secureBoot ? true : false - newNode.virtualized = nodeAsV43.virtualized ? true : false - newNode.serialNumber = validateString(ctx, nodeAsV43.serialNumber.toString()) - } - - if (node.isV105 || node.isV101 || node.isV63) { + const node = new TfgridModuleNodeStoredEvent(ctx, item.event) + let nodeEvent - if (node.isV101) { - nodeEvent = node.asV101 + if (node.isV9) { + nodeEvent = node.asV9 + } else if (node.isV28) { + nodeEvent = node.asV28 + } else if (node.isV43) { + nodeEvent = node.asV43 } else if (node.isV63) { - nodeEvent = node.asV63 + nodeEvent = node.asV63 + } else if (node.isV101) { + nodeEvent = node.asV101 } else if (node.isV105) { - nodeEvent = node.asV105 - } else { - return + nodeEvent = node.asV105 + } else if (node.isV118) { + nodeEvent = node.asV118 } - newNode.country = validateString(ctx, nodeEvent.country.toString()) - newNode.city = validateString(ctx, nodeEvent.city.toString()) - newNode.secure = nodeEvent.secureBoot ? true : false - newNode.virtualized = nodeEvent.virtualized ? true : false - newNode.serialNumber = validateString(ctx, nodeEvent.serialNumber.toString()) - newNode.connectionPrice = nodeEvent.connectionPrice - } - - if (node.isV118) { - let nodeEvent = node.asV118 - newNode.country = validateString(ctx, nodeEvent.location.country.toString()) - newNode.city = validateString(ctx, nodeEvent.location.city.toString()) - newNode.secure = nodeEvent.secureBoot ? true : false - newNode.virtualized = nodeEvent.virtualized ? true : false - newNode.serialNumber = nodeEvent.serialNumber ? validateString(ctx, nodeEvent.serialNumber.toString()) : 'Unknown' - newNode.connectionPrice = nodeEvent.connectionPrice - } - - await ctx.store.save(newNode) - - const resourcesTotal = new NodeResourcesTotal() - resourcesTotal.node = newNode - resourcesTotal.id = item.event.id - resourcesTotal.sru = nodeEvent.resources.sru - resourcesTotal.hru = nodeEvent.resources.hru - resourcesTotal.mru = nodeEvent.resources.mru - resourcesTotal.cru = nodeEvent.resources.cru - await ctx.store.save(resourcesTotal) - - newNode.interfaces = [] - - const interfacesPromisses = nodeEvent.interfaces.map(async intf => { - const newInterface = new Interfaces() - newInterface.id = item.event.id - newInterface.node = newNode - newInterface.name = validateString(ctx, intf.name.toString()) - newInterface.mac = validateString(ctx, intf.mac.toString()) - newInterface.ips = intf.ips.map(ip => validateString(ctx, ip.toString())).join(',') - await ctx.store.save(newInterface) - }) - - await Promise.all(interfacesPromisses) -} -export async function nodeUpdated( - ctx: Ctx, - item: EventItem<'TfgridModule.NodeUpdated', { event: { args: true } }>, - timestamp: bigint -) { - const node = new TfgridModuleNodeUpdatedEvent(ctx, item.event) - - let nodeEvent - if (node.isV9) { - nodeEvent = node.asV9 - } else if (node.isV28) { - nodeEvent = node.asV28 - } else if (node.isV43) { - nodeEvent = node.asV43 - } else if (node.isV63) { - nodeEvent = node.asV63 - } else if (node.isV101) { - nodeEvent = node.asV101 - } else if (node.isV105) { - nodeEvent = node.asV105 - } else if (node.isV118) { - nodeEvent = node.asV118 - } - - if (!nodeEvent) return - - const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeEvent.id }, relations: { location: true, interfaces: true } }) - - if (!savedNode) return - - savedNode.gridVersion = nodeEvent.version - savedNode.farmID = nodeEvent.farmId - savedNode.nodeID = nodeEvent.id - savedNode.twinID = nodeEvent.twinId - savedNode.updatedAt = timestamp - savedNode.farmingPolicyId = nodeEvent.farmingPolicyId - - // Recalculate total / free resoures when a node get's updated - let resourcesTotal = await ctx.store.get(NodeResourcesTotal, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } }) - if (resourcesTotal) { + if (!nodeEvent) { + return + } + + const newNode = new Node() + newNode.id = item.event.id + newNode.gridVersion = nodeEvent.version + newNode.farmID = nodeEvent.farmId + newNode.nodeID = nodeEvent.id + newNode.twinID = nodeEvent.twinId + newNode.dedicated = false + + newNode.createdAt = timestamp + newNode.updatedAt = timestamp + + if (node.isV9) { + nodeEvent = node.asV9 + newNode.country = validateString(ctx, nodeEvent.country.toString()) + newNode.city = validateString(ctx, nodeEvent.city.toString()) + } + if (node.isV28) { + nodeEvent = node.asV28 + newNode.country = validateString(ctx, nodeEvent.country.toString()) + newNode.city = validateString(ctx, nodeEvent.city.toString()) + } + + newNode.created = Number(nodeEvent.created) + newNode.farmingPolicyId = nodeEvent.farmingPolicyId + newNode.certification = NodeCertification.Diy + + const newLocation = new Location() + newLocation.id = item.event.id + newLocation.latitude = validateString(ctx, nodeEvent.location.latitude.toString()) + newLocation.longitude = validateString(ctx, nodeEvent.location.longitude.toString()) + await ctx.store.save(newLocation) + + newNode.location = newLocation + + await ctx.store.save(newNode) + + const pubConfig = getNodePublicConfig(ctx, node) + const newPubConfig = new PublicConfig() + newPubConfig.id = item.event.id + newPubConfig.ipv4 = pubConfig?.ip4 + newPubConfig.gw4 = pubConfig?.gw4 + newPubConfig.ipv6 = pubConfig?.ip6 + newPubConfig.gw6 = pubConfig?.gw6 + newPubConfig.node = newNode + + if (node.isV43) { + const nodeAsV43 = node.asV43 + newNode.country = validateString(ctx, nodeAsV43.country.toString()) + newNode.city = validateString(ctx, nodeAsV43.city.toString()) + newNode.secure = nodeAsV43.secureBoot ? true : false + newNode.virtualized = nodeAsV43.virtualized ? true : false + newNode.serialNumber = validateString(ctx, nodeAsV43.serialNumber.toString()) + } + + if (node.isV105 || node.isV101 || node.isV63) { + let nodeEvent + if (node.isV101) { + nodeEvent = node.asV101 + } else if (node.isV63) { + nodeEvent = node.asV63 + } else if (node.isV105) { + nodeEvent = node.asV105 + } else { + return + } + newNode.country = validateString(ctx, nodeEvent.country.toString()) + newNode.city = validateString(ctx, nodeEvent.city.toString()) + newNode.secure = nodeEvent.secureBoot ? true : false + newNode.virtualized = nodeEvent.virtualized ? true : false + newNode.serialNumber = validateString(ctx, nodeEvent.serialNumber.toString()) + newNode.connectionPrice = nodeEvent.connectionPrice + } + + if (node.isV118) { + let nodeEvent = node.asV118 + newNode.country = validateString(ctx, nodeEvent.location.country.toString()) + newNode.city = validateString(ctx, nodeEvent.location.city.toString()) + newNode.secure = nodeEvent.secureBoot ? true : false + newNode.virtualized = nodeEvent.virtualized ? true : false + newNode.serialNumber = nodeEvent.serialNumber ? validateString(ctx, nodeEvent.serialNumber.toString()) : 'Unknown' + newNode.connectionPrice = nodeEvent.connectionPrice + } + + await ctx.store.save(newNode) + + const resourcesTotal = new NodeResourcesTotal() + resourcesTotal.node = newNode + resourcesTotal.id = item.event.id resourcesTotal.sru = nodeEvent.resources.sru resourcesTotal.hru = nodeEvent.resources.hru resourcesTotal.mru = nodeEvent.resources.mru resourcesTotal.cru = nodeEvent.resources.cru await ctx.store.save(resourcesTotal) - } - - if (node.isV9) { - nodeEvent = node.asV9 - savedNode.country = validateString(ctx, nodeEvent.country.toString()) - savedNode.city = validateString(ctx, nodeEvent.city.toString()) - } - - if (node.isV118) { - nodeEvent = node.asV118 - savedNode.country = validateString(ctx, nodeEvent.location.country.toString()) - savedNode.city = validateString(ctx, nodeEvent.location.city.toString()) - } - - if (savedNode.location) { - const location = await ctx.store.get(Location, { where: { id: savedNode.location.id } }) - if (location) { - location.latitude = validateString(ctx, nodeEvent.location.latitude.toString()) - location.longitude = validateString(ctx, nodeEvent.location.longitude.toString()) - await ctx.store.save(location) - savedNode.location = location - } - } - if (node.isV28) { - const nodeAsV28 = node.asV28 - savedNode.country = validateString(ctx, nodeAsV28.country.toString()) - savedNode.city = validateString(ctx, nodeAsV28.city.toString()) + newNode.interfaces = [] - 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 - } - } - - if (node.isV43) { - const nodeAsV43 = node.asV43 - savedNode.country = validateString(ctx, nodeAsV43.country.toString()) - savedNode.city = validateString(ctx, nodeAsV43.city.toString()) - 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 - } - } + const interfacesPromisses = nodeEvent.interfaces.map(async intf => { + const newInterface = new Interfaces() + newInterface.id = item.event.id + newInterface.node = newNode + newInterface.name = validateString(ctx, intf.name.toString()) + newInterface.mac = validateString(ctx, intf.mac.toString()) + newInterface.ips = intf.ips.map(ip => validateString(ctx, ip.toString())).join(',') + await ctx.store.save(newInterface) + }) + + await Promise.all(interfacesPromisses) +} + +export async function nodeUpdated( + ctx: Ctx, + item: EventItem<'TfgridModule.NodeUpdated', { event: { args: true } }>, + timestamp: bigint +) { + const node = new TfgridModuleNodeUpdatedEvent(ctx, item.event) - if (node.isV105 || node.isV101 || node.isV63) { let nodeEvent - if (node.isV101) { - nodeEvent = node.asV101 + if (node.isV9) { + nodeEvent = node.asV9 + } else if (node.isV28) { + nodeEvent = node.asV28 + } else if (node.isV43) { + nodeEvent = node.asV43 } else if (node.isV63) { - nodeEvent = node.asV63 + nodeEvent = node.asV63 + } else if (node.isV101) { + nodeEvent = node.asV101 } else if (node.isV105) { - nodeEvent = node.asV105 - } else { - return + nodeEvent = node.asV105 + } else if (node.isV118) { + nodeEvent = node.asV118 } - savedNode.country = validateString(ctx, nodeEvent.country.toString()) - savedNode.city = validateString(ctx, nodeEvent.city.toString()) - 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 + + if (!nodeEvent) return + + const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeEvent.id }, relations: { location: true, interfaces: true } }) + + if (!savedNode) return + + savedNode.gridVersion = nodeEvent.version + savedNode.farmID = nodeEvent.farmId + savedNode.nodeID = nodeEvent.id + savedNode.twinID = nodeEvent.twinId + savedNode.updatedAt = timestamp + savedNode.farmingPolicyId = nodeEvent.farmingPolicyId + + // Recalculate total / free resoures when a node get's updated + let resourcesTotal = await ctx.store.get(NodeResourcesTotal, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } }) + if (resourcesTotal) { + resourcesTotal.sru = nodeEvent.resources.sru + resourcesTotal.hru = nodeEvent.resources.hru + resourcesTotal.mru = nodeEvent.resources.mru + resourcesTotal.cru = nodeEvent.resources.cru + await ctx.store.save(resourcesTotal) } - } - - if (node.isV118) { - const nodeEvent = node.asV118 - - savedNode.country = validateString(ctx, nodeEvent.location.country.toString()) - savedNode.city = validateString(ctx, nodeEvent.location.city.toString()) - 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 + + if (node.isV9) { + nodeEvent = node.asV9 + savedNode.country = validateString(ctx, nodeEvent.country.toString()) + savedNode.city = validateString(ctx, nodeEvent.city.toString()) + } + + if (node.isV118) { + nodeEvent = node.asV118 + savedNode.country = validateString(ctx, nodeEvent.location.country.toString()) + savedNode.city = validateString(ctx, nodeEvent.location.city.toString()) + } + + if (savedNode.location) { + const location = await ctx.store.get(Location, { where: { id: savedNode.location.id } }) + if (location) { + location.latitude = validateString(ctx, nodeEvent.location.latitude.toString()) + location.longitude = validateString(ctx, nodeEvent.location.longitude.toString()) + await ctx.store.save(location) + savedNode.location = location + } } - } - - // First remove all ifs - const nodeIfs = await ctx.store.find(Interfaces, { where: { node: { nodeID: savedNode.nodeID } } }) - await ctx.store.remove(nodeIfs) - - // Save ones from update event - await Promise.all(nodeEvent.interfaces.map(async intf => { - const newInterface = new Interfaces() - newInterface.id = item.event.id + validateString(ctx, intf.name.toString()) - newInterface.name = validateString(ctx, intf.name.toString()) - newInterface.mac = validateString(ctx, intf.mac.toString()) - newInterface.ips = intf.ips.map(ip => validateString(ctx, ip.toString())).join(',') - newInterface.node = savedNode - await ctx.store.save(newInterface) - - savedNode.interfaces.push(newInterface) - })) - - await ctx.store.save(savedNode) + + if (node.isV28) { + const nodeAsV28 = node.asV28 + 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 + } + } + + if (node.isV43) { + const nodeAsV43 = node.asV43 + savedNode.country = validateString(ctx, nodeAsV43.country.toString()) + savedNode.city = validateString(ctx, nodeAsV43.city.toString()) + 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 + } + } + + if (node.isV105 || node.isV101 || node.isV63) { + let nodeEvent + if (node.isV101) { + nodeEvent = node.asV101 + } else if (node.isV63) { + nodeEvent = node.asV63 + } else if (node.isV105) { + nodeEvent = node.asV105 + } else { + return + } + savedNode.country = validateString(ctx, nodeEvent.country.toString()) + savedNode.city = validateString(ctx, nodeEvent.city.toString()) + 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 + } + } + + if (node.isV118) { + const nodeEvent = node.asV118 + + savedNode.country = validateString(ctx, nodeEvent.location.country.toString()) + savedNode.city = validateString(ctx, nodeEvent.location.city.toString()) + 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 + } + } + + // First remove all ifs + const nodeIfs = await ctx.store.find(Interfaces, { where: { node: { nodeID: savedNode.nodeID } } }) + await ctx.store.remove(nodeIfs) + + // Save ones from update event + await Promise.all(nodeEvent.interfaces.map(async intf => { + const newInterface = new Interfaces() + newInterface.id = item.event.id + validateString(ctx, intf.name.toString()) + newInterface.name = validateString(ctx, intf.name.toString()) + newInterface.mac = validateString(ctx, intf.mac.toString()) + newInterface.ips = intf.ips.map(ip => validateString(ctx, ip.toString())).join(',') + newInterface.node = savedNode + await ctx.store.save(newInterface) + + savedNode.interfaces.push(newInterface) + })) + + await ctx.store.save(savedNode) } export async function nodeDeleted( - ctx: Ctx, - item: EventItem<'TfgridModule.NodeDeleted', { event: { args: true } }>, + ctx: Ctx, + item: EventItem<'TfgridModule.NodeDeleted', { event: { args: true } }>, ) { - const nodeID = new TfgridModuleNodeDeletedEvent(ctx, item.event).asV49 + const nodeID = new TfgridModuleNodeDeletedEvent(ctx, item.event).asV49 - const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID }, relations: { location: true, interfaces: true } }) + const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID }, relations: { location: true, interfaces: true } }) - if (savedNode) { - const resourcesTotal = await ctx.store.find(NodeResourcesTotal, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } }) - if (resourcesTotal) { - const p = resourcesTotal.map(r => ctx.store.remove(r)) - await Promise.all(p) - } + if (savedNode) { + const resourcesTotal = await ctx.store.find(NodeResourcesTotal, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } }) + if (resourcesTotal) { + const p = resourcesTotal.map(r => ctx.store.remove(r)) + await Promise.all(p) + } - const pubConfig = await ctx.store.get(PublicConfig, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } }) - if (pubConfig) { - await ctx.store.remove(pubConfig) - } + const pubConfig = await ctx.store.get(PublicConfig, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } }) + if (pubConfig) { + await ctx.store.remove(pubConfig) + } - const intfs = await ctx.store.find(Interfaces, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } }) - const promises = intfs.map(intf => { - return ctx.store.remove(intf) - }) - await Promise.all(promises) + const intfs = await ctx.store.find(Interfaces, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } }) + const promises = intfs.map(intf => { + return ctx.store.remove(intf) + }) + await Promise.all(promises) - await ctx.store.remove(savedNode) - } + await ctx.store.remove(savedNode) + } } export async function nodeUptimeReported(ctx: Ctx): Promise { - let uptimes = collectUptimeEvents(ctx) - - let touchedNodes = new Map( - (await ctx.store.find(Node, { - where: { - nodeID: In([...new Set(uptimes.map(up => up.event.nodeID)).keys()]) - }, relations: { location: true, interfaces: true } - })).map(n => [n.nodeID, n]) - ) - - for (let up of uptimes) { - let node = touchedNodes.get(up.event.nodeID) - if (node) { - node.uptime = up.event.uptime - node.updatedAt = BigInt(up.block.timestamp) / BigInt(1000) + let uptimes = collectUptimeEvents(ctx) + + let touchedNodes = new Map( + (await ctx.store.find(Node, { + where: { + nodeID: In([...new Set(uptimes.map(up => up.event.nodeID)).keys()]) + }, relations: { location: true, interfaces: true } + })).map(n => [n.nodeID, n]) + ) + + for (let up of uptimes) { + let node = touchedNodes.get(up.event.nodeID) + if (node) { + node.uptime = up.event.uptime + node.updatedAt = BigInt(up.block.timestamp) / BigInt(1000) + } } - } - await ctx.store.save(uptimes.map(up => up.event)) - await ctx.store.save([...touchedNodes.values()]) + await ctx.store.save(uptimes.map(up => up.event)) + await ctx.store.save([...touchedNodes.values()]) } function collectUptimeEvents(ctx: Ctx): { block: SubstrateBlock, event: UptimeEvent }[] { - let list: { block: SubstrateBlock, event: UptimeEvent }[] = [] - for (let block of ctx.blocks) { - for (let item of block.items) { - if (item.name === "TfgridModule.NodeUptimeReported") { - const [nodeID, now, uptime] = new TfgridModuleNodeUptimeReportedEvent(ctx, item.event).asV49 - const event = new UptimeEvent() - event.id = item.event.id - event.nodeID = nodeID - event.timestamp = now - event.uptime = uptime - list.push({ - block: block.header, - event - }) - } + let list: { block: SubstrateBlock, event: UptimeEvent }[] = [] + for (let block of ctx.blocks) { + for (let item of block.items) { + if (item.name === "TfgridModule.NodeUptimeReported") { + const [nodeID, now, uptime] = new TfgridModuleNodeUptimeReportedEvent(ctx, item.event).asV49 + const event = new UptimeEvent() + event.id = item.event.id + event.nodeID = nodeID + event.timestamp = now + event.uptime = uptime + list.push({ + block: block.header, + event + }) + } + } } - } - return list + return list } export async function nodePublicConfigStored( - ctx: Ctx, - item: EventItem<'TfgridModule.NodePublicConfigStored', { event: { args: true } }> + ctx: Ctx, + item: EventItem<'TfgridModule.NodePublicConfigStored', { event: { args: true } }> ) { - const storedEvent = new TfgridModuleNodePublicConfigStoredEvent(ctx, item.event) - - let nodeID, config - let ipv4, ipv6, gw4, gw6, domain - - if (storedEvent.isV49) { - [nodeID, config] = storedEvent.asV49 - ipv4 = validateString(ctx, config.ipv4.toString()) - ipv6 = validateString(ctx, config.ipv6.toString()) - gw4 = validateString(ctx, config.gw4.toString()) - gw6 = validateString(ctx, config.gw6.toString()) - domain = config.domain.toString() - } else if (storedEvent.isV105) { - [nodeID, config] = storedEvent.asV105 - return await handlePublicConfigV105(ctx, item.event.id, nodeID, config) - } else { - return - } - - const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID }, relations: { location: true, interfaces: true } }) - if (!savedNode) return - - let publicConfig = await ctx.store.get(PublicConfig, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } }) - - if (!publicConfig) { - publicConfig = new PublicConfig() - publicConfig.id = item.event.id - publicConfig.node = savedNode - } - - publicConfig.ipv4 = ipv4 - publicConfig.ipv6 = ipv6 - publicConfig.gw4 = gw4 - publicConfig.gw6 = gw6 - publicConfig.domain = domain || '' - - await ctx.store.save(publicConfig) + const storedEvent = new TfgridModuleNodePublicConfigStoredEvent(ctx, item.event) + + let nodeID, config + let ipv4, ipv6, gw4, gw6, domain + + if (storedEvent.isV49) { + [nodeID, config] = storedEvent.asV49 + ipv4 = validateString(ctx, config.ipv4.toString()) + ipv6 = validateString(ctx, config.ipv6.toString()) + gw4 = validateString(ctx, config.gw4.toString()) + gw6 = validateString(ctx, config.gw6.toString()) + domain = config.domain.toString() + } else if (storedEvent.isV105) { + [nodeID, config] = storedEvent.asV105 + return await handlePublicConfigV105(ctx, item.event.id, nodeID, config) + } else { + return + } + + const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID }, relations: { location: true, interfaces: true } }) + if (!savedNode) return + + let publicConfig = await ctx.store.get(PublicConfig, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } }) + + if (!publicConfig) { + publicConfig = new PublicConfig() + publicConfig.id = item.event.id + publicConfig.node = savedNode + } + + publicConfig.ipv4 = ipv4 + publicConfig.ipv6 = ipv6 + publicConfig.gw4 = gw4 + publicConfig.gw6 = gw6 + publicConfig.domain = domain || '' + + await ctx.store.save(publicConfig) } async function handlePublicConfigV105(ctx: Ctx, eventID: string, nodeID: number, config: V105PublicConfig | undefined) { - if (!config) { - const pubConfig = await ctx.store.get(PublicConfig, { where: { node: { nodeID } }, relations: { node: true } }) - if (pubConfig) { - return await ctx.store.remove(pubConfig) + if (!config) { + const pubConfig = await ctx.store.get(PublicConfig, { where: { node: { nodeID } }, relations: { node: true } }) + if (pubConfig) { + return await ctx.store.remove(pubConfig) + } } - } - const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID }, relations: { location: true, interfaces: true } }) - if (!savedNode) return + const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID }, relations: { location: true, interfaces: true } }) + if (!savedNode) return - let publicConfig = await ctx.store.get(PublicConfig, { where: { node: { nodeID } }, relations: { node: true } }) + let publicConfig = await ctx.store.get(PublicConfig, { where: { node: { nodeID } }, relations: { node: true } }) - if (!publicConfig) { - publicConfig = new PublicConfig() - publicConfig.id = eventID - publicConfig.node = savedNode - } + if (!publicConfig) { + publicConfig = new PublicConfig() + publicConfig.id = eventID + publicConfig.node = savedNode + } - publicConfig.ipv4 = config?.ip4.ip ? validateString(ctx, config?.ip4.ip.toString()) : null - publicConfig.gw4 = config?.ip4.gw ? validateString(ctx, config?.ip4.gw.toString()) : null - publicConfig.ipv6 = config?.ip6?.ip ? validateString(ctx, config?.ip6?.ip.toString()) : null - publicConfig.gw6 = config?.ip6?.gw ? validateString(ctx, config?.ip6?.gw.toString()) : null - publicConfig.domain = config?.domain ? validateString(ctx, config.domain.toString()) : null + publicConfig.ipv4 = config?.ip4.ip ? validateString(ctx, config?.ip4.ip.toString()) : null + publicConfig.gw4 = config?.ip4.gw ? validateString(ctx, config?.ip4.gw.toString()) : null + publicConfig.ipv6 = config?.ip6?.ip ? validateString(ctx, config?.ip6?.ip.toString()) : null + publicConfig.gw6 = config?.ip6?.gw ? validateString(ctx, config?.ip6?.gw.toString()) : null + publicConfig.domain = config?.domain ? validateString(ctx, config.domain.toString()) : null - await ctx.store.save(publicConfig) + await ctx.store.save(publicConfig) } export async function nodeCertificationSet( - ctx: Ctx, - item: EventItem<'TfgridModule.NodeCertificationSet', { event: { args: true } }> + ctx: Ctx, + item: EventItem<'TfgridModule.NodeCertificationSet', { event: { args: true } }> ) { - const [nodeID, certification] = new TfgridModuleNodeCertificationSetEvent(ctx, item.event).asV63 + const [nodeID, certification] = new TfgridModuleNodeCertificationSetEvent(ctx, item.event).asV63 - const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID }, relations: { location: true, interfaces: true } }) - if (!savedNode) return + 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 - } + 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 = certType - await ctx.store.save(savedNode) + await ctx.store.save(savedNode) } export async function powerTargetChanged( - ctx: Ctx, - item: EventItem<'TfgridModule.PowerTargetChanged', { event: { args: true } }>, - timestamp: bigint, - block: SubstrateBlock + ctx: Ctx, + item: EventItem<'TfgridModule.PowerTargetChanged', { event: { args: true } }>, + timestamp: bigint, + block: SubstrateBlock ) { - const { farmId, nodeId, powerTarget } = new TfgridModulePowerTargetChangedEvent(ctx, item.event).asV125 - - let target = Power.Up - switch (powerTarget.__kind) { - case 'Up': - target = Power.Up - break - case 'Down': - target = Power.Down - break - } - let powerReported = new PowerTargetReport() - powerReported.id = item.event.id - powerReported.farmID = farmId - powerReported.nodeID = nodeId - powerReported.newPowerTarget = target - powerReported.block = block.height - powerReported.timestamp = timestamp - - const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeId }, relations: { location: true, interfaces: true } }) - if (!savedNode) return - - assert(savedNode.farmID === farmId) - assert(savedNode.nodeID === nodeId) - - if (!savedNode.power) { - savedNode.power = new NodePower() - savedNode.power.state = PowerState.Up - } - savedNode.power.target = target - await ctx.store.save(savedNode) - await ctx.store.save(powerReported) + const { farmId, nodeId, powerTarget } = new TfgridModulePowerTargetChangedEvent(ctx, item.event).asV125 + + let target = Power.Up + switch (powerTarget.__kind) { + case 'Up': + target = Power.Up + break + case 'Down': + target = Power.Down + break + } + let powerReported = new PowerTargetReport() + powerReported.id = item.event.id + powerReported.farmID = farmId + powerReported.nodeID = nodeId + powerReported.newPowerTarget = target + powerReported.block = block.height + powerReported.timestamp = timestamp + + const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeId }, relations: { location: true, interfaces: true } }) + if (!savedNode) return + + assert(savedNode.farmID === farmId) + assert(savedNode.nodeID === nodeId) + + if (!savedNode.power) { + savedNode.power = new NodePower() + savedNode.power.state = PowerState.Up + } + savedNode.power.target = target + await ctx.store.save(savedNode) + await ctx.store.save(powerReported) } export async function powerStateChanged( - ctx: Ctx, - item: EventItem<'TfgridModule.PowerStateChanged', { event: { args: true } }>, - timestamp: bigint, - block: SubstrateBlock + ctx: Ctx, + item: EventItem<'TfgridModule.PowerStateChanged', { event: { args: true } }>, + timestamp: bigint, + block: SubstrateBlock ) { - const { farmId, nodeId, powerState } = new TfgridModulePowerStateChangedEvent(ctx, item.event).asV125 - - let state = PowerState.Up - switch (powerState.__kind) { - case 'Up': - state = PowerState.Up - break - case 'Down': - state = PowerState.Down - break - } - - let powerReported = new PowerStateReport() - powerReported.id = item.event.id - powerReported.farmID = farmId - powerReported.nodeID = nodeId - powerReported.newPowerState = state - powerReported.block = block.height - powerReported.timestamp = timestamp - - const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeId }, relations: { location: true, interfaces: true } }) - if (!savedNode) return - - if (!savedNode.power) { - savedNode.power = new NodePower() - savedNode.power.target = Power.Up - } - savedNode.power.state = state - await ctx.store.save(savedNode) - await ctx.store.save(powerReported) + const { farmId, nodeId, powerState } = new TfgridModulePowerStateChangedEvent(ctx, item.event).asV125 + + let state = PowerState.Up + switch (powerState.__kind) { + case 'Up': + state = PowerState.Up + break + case 'Down': + state = PowerState.Down + break + } + + let powerReported = new PowerStateReport() + powerReported.id = item.event.id + powerReported.farmID = farmId + powerReported.nodeID = nodeId + powerReported.newPowerState = state + powerReported.block = block.height + powerReported.timestamp = timestamp + + const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeId }, relations: { location: true, interfaces: true } }) + if (!savedNode) return + + if (!savedNode.power) { + savedNode.power = new NodePower() + savedNode.power.target = Power.Up + } + savedNode.power.state = state + await ctx.store.save(savedNode) + await ctx.store.save(powerReported) } export async function nodeExtraFeeSet( - ctx: Ctx, - item: EventItem<'SmartContractModule.NodeExtraFeeSet', { event: { args: true } }> + ctx: Ctx, + item: EventItem<'SmartContractModule.NodeExtraFeeSet', { event: { args: true } }> ) { - const { nodeId, extraFee } = new SmartContractModuleNodeExtraFeeSetEvent(ctx, item.event).asV134 + const { nodeId, extraFee } = new SmartContractModuleNodeExtraFeeSetEvent(ctx, item.event).asV134 - const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeId }, relations: { location: true, interfaces: true } }) - if (!savedNode) return + const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeId }, relations: { location: true, interfaces: true } }) + if (!savedNode) return - savedNode.extraFee = extraFee - // Also mark the node as dedicated if the fee is not 0 - savedNode.dedicated = extraFee > 0 + savedNode.extraFee = extraFee + // Also mark the node as dedicated if the fee is not 0 + savedNode.dedicated = extraFee > 0 - await ctx.store.save(savedNode) + await ctx.store.save(savedNode) } interface NodePublicConfig { - ip4: string - gw4: string - ip6: string - gw6: string - domain: string + ip4: string + gw4: string + ip6: string + gw6: string + domain: string } function getNodePublicConfig(ctx: Ctx, node: TfgridModuleNodeStoredEvent): NodePublicConfig | null | undefined { - let nodeEvent - if (node.isV9) { - nodeEvent = node.asV9 - if (nodeEvent.publicConfig) { - return { - ip4: validateString(ctx, nodeEvent.publicConfig?.ipv4.toString()), - gw4: validateString(ctx, nodeEvent.publicConfig?.gw4.toString()), - ip6: validateString(ctx, nodeEvent.publicConfig?.ipv6.toString()), - gw6: validateString(ctx, nodeEvent.publicConfig?.gw6.toString()), - domain: validateString(ctx, nodeEvent.publicConfig?.domain.toString()) - } - } - } else if (node.isV28) { - nodeEvent = node.asV28 - if (nodeEvent.publicConfig) { - return { - ip4: validateString(ctx, nodeEvent.publicConfig?.ipv4.toString()), - gw4: validateString(ctx, nodeEvent.publicConfig?.gw4.toString()), - ip6: validateString(ctx, nodeEvent.publicConfig?.ipv6.toString()), - gw6: validateString(ctx, nodeEvent.publicConfig?.gw6.toString()), - domain: validateString(ctx, nodeEvent.publicConfig?.domain.toString()) - } - } - } else if (node.isV43) { - nodeEvent = node.asV43 - if (nodeEvent.publicConfig) { - return { - ip4: validateString(ctx, nodeEvent.publicConfig?.ipv4.toString()), - gw4: validateString(ctx, nodeEvent.publicConfig?.gw4.toString()), - ip6: validateString(ctx, nodeEvent.publicConfig?.ipv6.toString()), - gw6: validateString(ctx, nodeEvent.publicConfig?.gw6.toString()), - domain: validateString(ctx, nodeEvent.publicConfig?.domain.toString()) - } - } - } else if (node.isV63) { - nodeEvent = node.asV63 - if (nodeEvent.publicConfig) { - return { - ip4: validateString(ctx, nodeEvent.publicConfig?.ipv4.toString()), - gw4: validateString(ctx, nodeEvent.publicConfig?.gw4.toString()), - ip6: validateString(ctx, nodeEvent.publicConfig?.ipv6.toString()), - gw6: validateString(ctx, nodeEvent.publicConfig?.gw6.toString()), - domain: validateString(ctx, nodeEvent.publicConfig?.domain.toString()) - } - } - } else if (node.isV101) { - nodeEvent = node.asV101 - if (nodeEvent.publicConfig) { - return { - ip4: validateString(ctx, nodeEvent.publicConfig?.ipv4.toString()), - gw4: validateString(ctx, nodeEvent.publicConfig?.gw4.toString()), - ip6: validateString(ctx, nodeEvent.publicConfig?.ipv6.toString()), - gw6: validateString(ctx, nodeEvent.publicConfig?.gw6.toString()), - domain: validateString(ctx, nodeEvent.publicConfig?.domain.toString()) - } - } - } else if (node.isV105) { - nodeEvent = node.asV105 - if (nodeEvent.publicConfig) { - let domain = '' - 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()), - ip6: validateString(ctx, nodeEvent.publicConfig?.ip6?.ip.toString() || ''), - gw6: validateString(ctx, nodeEvent.publicConfig?.ip6?.gw.toString() || ''), - domain - } + let nodeEvent + if (node.isV9) { + nodeEvent = node.asV9 + if (nodeEvent.publicConfig) { + return { + ip4: validateString(ctx, nodeEvent.publicConfig?.ipv4.toString()), + gw4: validateString(ctx, nodeEvent.publicConfig?.gw4.toString()), + ip6: validateString(ctx, nodeEvent.publicConfig?.ipv6.toString()), + gw6: validateString(ctx, nodeEvent.publicConfig?.gw6.toString()), + domain: validateString(ctx, nodeEvent.publicConfig?.domain.toString()) + } + } + } else if (node.isV28) { + nodeEvent = node.asV28 + if (nodeEvent.publicConfig) { + return { + ip4: validateString(ctx, nodeEvent.publicConfig?.ipv4.toString()), + gw4: validateString(ctx, nodeEvent.publicConfig?.gw4.toString()), + ip6: validateString(ctx, nodeEvent.publicConfig?.ipv6.toString()), + gw6: validateString(ctx, nodeEvent.publicConfig?.gw6.toString()), + domain: validateString(ctx, nodeEvent.publicConfig?.domain.toString()) + } + } + } else if (node.isV43) { + nodeEvent = node.asV43 + if (nodeEvent.publicConfig) { + return { + ip4: validateString(ctx, nodeEvent.publicConfig?.ipv4.toString()), + gw4: validateString(ctx, nodeEvent.publicConfig?.gw4.toString()), + ip6: validateString(ctx, nodeEvent.publicConfig?.ipv6.toString()), + gw6: validateString(ctx, nodeEvent.publicConfig?.gw6.toString()), + domain: validateString(ctx, nodeEvent.publicConfig?.domain.toString()) + } + } + } else if (node.isV63) { + nodeEvent = node.asV63 + if (nodeEvent.publicConfig) { + return { + ip4: validateString(ctx, nodeEvent.publicConfig?.ipv4.toString()), + gw4: validateString(ctx, nodeEvent.publicConfig?.gw4.toString()), + ip6: validateString(ctx, nodeEvent.publicConfig?.ipv6.toString()), + gw6: validateString(ctx, nodeEvent.publicConfig?.gw6.toString()), + domain: validateString(ctx, nodeEvent.publicConfig?.domain.toString()) + } + } + } else if (node.isV101) { + nodeEvent = node.asV101 + if (nodeEvent.publicConfig) { + return { + ip4: validateString(ctx, nodeEvent.publicConfig?.ipv4.toString()), + gw4: validateString(ctx, nodeEvent.publicConfig?.gw4.toString()), + ip6: validateString(ctx, nodeEvent.publicConfig?.ipv6.toString()), + gw6: validateString(ctx, nodeEvent.publicConfig?.gw6.toString()), + domain: validateString(ctx, nodeEvent.publicConfig?.domain.toString()) + } + } + } else if (node.isV105) { + nodeEvent = node.asV105 + if (nodeEvent.publicConfig) { + let domain = '' + 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()), + ip6: validateString(ctx, nodeEvent.publicConfig?.ip6?.ip.toString() || ''), + gw6: validateString(ctx, nodeEvent.publicConfig?.ip6?.gw.toString() || ''), + domain + } + } + } else { + return null } - } else { - return null - } - return null + return null } // validateString checks if the string includes '\x00' which is not accepted by postgres // if so, it replaces the string with invalid and logs the error export function validateString(ctx: Ctx, str: string): string { - if (str.includes('\x00')) { - ctx.log.error(`invalid string containing "\\x00": ${str}`) - return "invalid" - } + if (str.includes('\x00')) { + ctx.log.error(`invalid string containing "\\x00": ${str}`) + return "invalid" + } - return str + return str } \ No newline at end of file diff --git a/src/mappings/policies.ts b/src/mappings/policies.ts index ec11763..95c802d 100644 --- a/src/mappings/policies.ts +++ b/src/mappings/policies.ts @@ -3,187 +3,187 @@ import { Ctx } from "../processor"; import { EventItem } from '@subsquid/substrate-processor/lib/interfaces/dataSelection' import { - PricingPolicy, FarmingPolicy, - Policy, FarmCertification, - NodeCertification + PricingPolicy, FarmingPolicy, + Policy, FarmCertification, + NodeCertification } from "../model"; import { - TfgridModulePricingPolicyStoredEvent, TfgridModuleFarmingPolicyStoredEvent, - TfgridModuleFarmingPolicyUpdatedEvent + TfgridModulePricingPolicyStoredEvent, TfgridModuleFarmingPolicyStoredEvent, + TfgridModuleFarmingPolicyUpdatedEvent } from "../types/events"; import { validateString } from "./nodes" export async function pricingPolicyStored( - ctx: Ctx, - item: EventItem<'TfgridModule.PricingPolicyStored', { event: { args: true } }>, + ctx: Ctx, + item: EventItem<'TfgridModule.PricingPolicyStored', { event: { args: true } }>, ) { - let pricingPolicyEvent = new TfgridModulePricingPolicyStoredEvent(ctx, item.event) + let pricingPolicyEvent = new TfgridModulePricingPolicyStoredEvent(ctx, item.event) - let pricingPolicyEventParsed + let pricingPolicyEventParsed - if (pricingPolicyEvent.isV49) { - pricingPolicyEventParsed = pricingPolicyEvent.asV49 - } else if (pricingPolicyEvent.isV51) { - pricingPolicyEventParsed = pricingPolicyEvent.asV51 - } else if (pricingPolicyEvent.isV101) { - pricingPolicyEventParsed = pricingPolicyEvent.asV101 - } + if (pricingPolicyEvent.isV49) { + pricingPolicyEventParsed = pricingPolicyEvent.asV49 + } else if (pricingPolicyEvent.isV51) { + pricingPolicyEventParsed = pricingPolicyEvent.asV51 + } else if (pricingPolicyEvent.isV101) { + pricingPolicyEventParsed = pricingPolicyEvent.asV101 + } - if (!pricingPolicyEventParsed) return + if (!pricingPolicyEventParsed) return - let pricingPolicy = new PricingPolicy() - pricingPolicy.id = item.event.id + let pricingPolicy = new PricingPolicy() + pricingPolicy.id = item.event.id - const savedPolicy = await ctx.store.get(PricingPolicy, { where: { pricingPolicyID: pricingPolicyEventParsed.id } }) - if (savedPolicy) { - pricingPolicy = savedPolicy - } + const savedPolicy = await ctx.store.get(PricingPolicy, { where: { pricingPolicyID: pricingPolicyEventParsed.id } }) + if (savedPolicy) { + pricingPolicy = savedPolicy + } - pricingPolicy.gridVersion = pricingPolicyEventParsed.version - pricingPolicy.pricingPolicyID = pricingPolicyEventParsed.id - pricingPolicy.name = validateString(ctx, pricingPolicyEventParsed.name.toString()) - pricingPolicy.dedicatedNodeDiscount = 0 + pricingPolicy.gridVersion = pricingPolicyEventParsed.version + pricingPolicy.pricingPolicyID = pricingPolicyEventParsed.id + pricingPolicy.name = validateString(ctx, pricingPolicyEventParsed.name.toString()) + pricingPolicy.dedicatedNodeDiscount = 0 - const foundationAccount = ss58.codec("substrate").encode(pricingPolicyEventParsed.foundationAccount); - const certifiedSalesAccount = ss58.codec("substrate").encode(pricingPolicyEventParsed.certifiedSalesAccount); + const foundationAccount = ss58.codec("substrate").encode(pricingPolicyEventParsed.foundationAccount); + const certifiedSalesAccount = ss58.codec("substrate").encode(pricingPolicyEventParsed.certifiedSalesAccount); - pricingPolicy.foundationAccount = foundationAccount - pricingPolicy.certifiedSalesAccount = certifiedSalesAccount + pricingPolicy.foundationAccount = foundationAccount + pricingPolicy.certifiedSalesAccount = certifiedSalesAccount - const suPolicy = new Policy() - suPolicy.value = pricingPolicyEventParsed.su.value - suPolicy.unit = validateString(ctx, pricingPolicyEventParsed.su.unit.toString()) + const suPolicy = new Policy() + suPolicy.value = pricingPolicyEventParsed.su.value + suPolicy.unit = validateString(ctx, pricingPolicyEventParsed.su.unit.toString()) - const nuPolicy = new Policy() - nuPolicy.value = pricingPolicyEventParsed.nu.value - nuPolicy.unit = validateString(ctx, pricingPolicyEventParsed.nu.unit.toString()) + const nuPolicy = new Policy() + nuPolicy.value = pricingPolicyEventParsed.nu.value + nuPolicy.unit = validateString(ctx, pricingPolicyEventParsed.nu.unit.toString()) - const cuPolicy = new Policy() - cuPolicy.value = pricingPolicyEventParsed.cu.value - cuPolicy.unit = validateString(ctx, pricingPolicyEventParsed.cu.unit.toString()) + const cuPolicy = new Policy() + cuPolicy.value = pricingPolicyEventParsed.cu.value + cuPolicy.unit = validateString(ctx, pricingPolicyEventParsed.cu.unit.toString()) - const IpuPolicy = new Policy() - IpuPolicy.value = pricingPolicyEventParsed.ipu.value - IpuPolicy.unit = validateString(ctx, pricingPolicyEventParsed.ipu.unit.toString()) + const IpuPolicy = new Policy() + IpuPolicy.value = pricingPolicyEventParsed.ipu.value + IpuPolicy.unit = validateString(ctx, pricingPolicyEventParsed.ipu.unit.toString()) - pricingPolicy.su = suPolicy - pricingPolicy.cu = cuPolicy - pricingPolicy.nu = nuPolicy - pricingPolicy.ipu = IpuPolicy + pricingPolicy.su = suPolicy + pricingPolicy.cu = cuPolicy + pricingPolicy.nu = nuPolicy + pricingPolicy.ipu = IpuPolicy - if (pricingPolicyEvent.isV51) { - let policyAsV50 = pricingPolicyEvent.asV51 - pricingPolicy.dedicatedNodeDiscount = policyAsV50.discountForDedicatedNodes - } + if (pricingPolicyEvent.isV51) { + let policyAsV50 = pricingPolicyEvent.asV51 + pricingPolicy.dedicatedNodeDiscount = policyAsV50.discountForDedicatedNodes + } - await ctx.store.save(pricingPolicy) + await ctx.store.save(pricingPolicy) } export async function farmingPolicyStored( - ctx: Ctx, - item: EventItem<'TfgridModule.FarmingPolicyStored', { event: { args: true } }>, + ctx: Ctx, + item: EventItem<'TfgridModule.FarmingPolicyStored', { event: { args: true } }>, ) { - const farmingPolicyEvent = new TfgridModuleFarmingPolicyStoredEvent(ctx, item.event) - - if (!farmingPolicyEvent.isV63) { - return - } - - const farmingPolicyStoredEvent = farmingPolicyEvent.asV63 - - const newFarmingPolicy = new FarmingPolicy() - newFarmingPolicy.id = item.event.id - newFarmingPolicy.gridVersion = farmingPolicyStoredEvent.version - newFarmingPolicy.farmingPolicyID = farmingPolicyStoredEvent.id - newFarmingPolicy.name = validateString(ctx, farmingPolicyStoredEvent.name.toString()) - - newFarmingPolicy.cu = farmingPolicyStoredEvent.cu - newFarmingPolicy.su = farmingPolicyStoredEvent.su - newFarmingPolicy.nu = farmingPolicyStoredEvent.nu - newFarmingPolicy.ipv4 = farmingPolicyStoredEvent.ipv4 - newFarmingPolicy.policyCreated = farmingPolicyStoredEvent.policyCreated - newFarmingPolicy.policyEnd = farmingPolicyStoredEvent.policyEnd - 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 - - await ctx.store.save(newFarmingPolicy) + const farmingPolicyEvent = new TfgridModuleFarmingPolicyStoredEvent(ctx, item.event) + + if (!farmingPolicyEvent.isV63) { + return + } + + const farmingPolicyStoredEvent = farmingPolicyEvent.asV63 + + const newFarmingPolicy = new FarmingPolicy() + newFarmingPolicy.id = item.event.id + newFarmingPolicy.gridVersion = farmingPolicyStoredEvent.version + newFarmingPolicy.farmingPolicyID = farmingPolicyStoredEvent.id + newFarmingPolicy.name = validateString(ctx, farmingPolicyStoredEvent.name.toString()) + + newFarmingPolicy.cu = farmingPolicyStoredEvent.cu + newFarmingPolicy.su = farmingPolicyStoredEvent.su + newFarmingPolicy.nu = farmingPolicyStoredEvent.nu + newFarmingPolicy.ipv4 = farmingPolicyStoredEvent.ipv4 + newFarmingPolicy.policyCreated = farmingPolicyStoredEvent.policyCreated + newFarmingPolicy.policyEnd = farmingPolicyStoredEvent.policyEnd + 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 + + await ctx.store.save(newFarmingPolicy) } export async function farmingPolicyUpdated( - ctx: Ctx, - item: EventItem<'TfgridModule.FarmingPolicyUpdated', { event: { args: true } }>, + ctx: Ctx, + item: EventItem<'TfgridModule.FarmingPolicyUpdated', { event: { args: true } }>, ) { - const farmingPolicyEvent = new TfgridModuleFarmingPolicyUpdatedEvent(ctx, item.event) - - if (!farmingPolicyEvent.isV63) { - return - } - - const farmingPolicyUpdatedEvent = farmingPolicyEvent.asV63 - - const savedPolicy = await ctx.store.get(FarmingPolicy, { where: { farmingPolicyID: farmingPolicyUpdatedEvent.id } }) - if (!savedPolicy) return - - savedPolicy.gridVersion = farmingPolicyUpdatedEvent.version - savedPolicy.farmingPolicyID = farmingPolicyUpdatedEvent.id - savedPolicy.name = validateString(ctx, farmingPolicyUpdatedEvent.name.toString()) - - savedPolicy.cu = farmingPolicyUpdatedEvent.cu - savedPolicy.su = farmingPolicyUpdatedEvent.su - savedPolicy.nu = farmingPolicyUpdatedEvent.nu - savedPolicy.ipv4 = farmingPolicyUpdatedEvent.ipv4 - savedPolicy.policyCreated = farmingPolicyUpdatedEvent.policyCreated - savedPolicy.policyEnd = farmingPolicyUpdatedEvent.policyEnd - 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 - - await ctx.store.save(savedPolicy) + const farmingPolicyEvent = new TfgridModuleFarmingPolicyUpdatedEvent(ctx, item.event) + + if (!farmingPolicyEvent.isV63) { + return + } + + const farmingPolicyUpdatedEvent = farmingPolicyEvent.asV63 + + const savedPolicy = await ctx.store.get(FarmingPolicy, { where: { farmingPolicyID: farmingPolicyUpdatedEvent.id } }) + if (!savedPolicy) return + + savedPolicy.gridVersion = farmingPolicyUpdatedEvent.version + savedPolicy.farmingPolicyID = farmingPolicyUpdatedEvent.id + savedPolicy.name = validateString(ctx, farmingPolicyUpdatedEvent.name.toString()) + + savedPolicy.cu = farmingPolicyUpdatedEvent.cu + savedPolicy.su = farmingPolicyUpdatedEvent.su + savedPolicy.nu = farmingPolicyUpdatedEvent.nu + savedPolicy.ipv4 = farmingPolicyUpdatedEvent.ipv4 + savedPolicy.policyCreated = farmingPolicyUpdatedEvent.policyCreated + savedPolicy.policyEnd = farmingPolicyUpdatedEvent.policyEnd + 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 + + await ctx.store.save(savedPolicy) } \ No newline at end of file diff --git a/src/mappings/solutionProviders.ts b/src/mappings/solutionProviders.ts index 661fc4a..d0b2db4 100644 --- a/src/mappings/solutionProviders.ts +++ b/src/mappings/solutionProviders.ts @@ -4,47 +4,47 @@ import { EventItem } from '@subsquid/substrate-processor/lib/interfaces/dataSele import { Provider, SolutionProvider } from "../model" import { - SmartContractModuleSolutionProviderApprovedEvent, - SmartContractModuleSolutionProviderCreatedEvent + SmartContractModuleSolutionProviderApprovedEvent, + SmartContractModuleSolutionProviderCreatedEvent } from "../types/events" import { validateString } from "./nodes"; export async function solutionProviderCreated( - ctx: Ctx, - item: EventItem<'SmartContractModule.SolutionProviderCreated', { event: { args: true } }>, + ctx: Ctx, + item: EventItem<'SmartContractModule.SolutionProviderCreated', { event: { args: true } }>, ) { - let providerCreatedEvent = new SmartContractModuleSolutionProviderCreatedEvent(ctx, item.event).asV105 + let providerCreatedEvent = new SmartContractModuleSolutionProviderCreatedEvent(ctx, item.event).asV105 - let provider = new SolutionProvider() + let provider = new SolutionProvider() - provider.id = item.event.id - provider.solutionProviderID = providerCreatedEvent.solutionProviderId - provider.description = validateString(ctx, providerCreatedEvent.description.toString()) - provider.link = validateString(ctx, providerCreatedEvent.link.toString()) - provider.approved = false - provider.providers = [] + provider.id = item.event.id + provider.solutionProviderID = providerCreatedEvent.solutionProviderId + provider.description = validateString(ctx, providerCreatedEvent.description.toString()) + provider.link = validateString(ctx, providerCreatedEvent.link.toString()) + provider.approved = false + provider.providers = [] - await ctx.store.save(provider) + await ctx.store.save(provider) - provider.providers = providerCreatedEvent.providers.map(p => { - let prov = new Provider() - prov.take = p.take - prov.who = ss58.codec("substrate").encode(p.who) - return prov - }) + provider.providers = providerCreatedEvent.providers.map(p => { + let prov = new Provider() + prov.take = p.take + prov.who = ss58.codec("substrate").encode(p.who) + return prov + }) - await ctx.store.save(provider) + await ctx.store.save(provider) } export async function solutionProviderApproved( - ctx: Ctx, - item: EventItem<'SmartContractModule.SolutionProviderApproved', { event: { args: true } }>, + ctx: Ctx, + item: EventItem<'SmartContractModule.SolutionProviderApproved', { event: { args: true } }>, ) { - let providerApprovedEvent = new SmartContractModuleSolutionProviderApprovedEvent(ctx, item.event).asV105 + let providerApprovedEvent = new SmartContractModuleSolutionProviderApprovedEvent(ctx, item.event).asV105 - const savedProvider = await ctx.store.get(SolutionProvider, { where: { solutionProviderID: providerApprovedEvent[0] } }) - if (savedProvider) { - savedProvider.approved = true - await ctx.store.save(savedProvider) - } + const savedProvider = await ctx.store.get(SolutionProvider, { where: { solutionProviderID: providerApprovedEvent[0] } }) + if (savedProvider) { + savedProvider.approved = true + await ctx.store.save(savedProvider) + } } \ No newline at end of file diff --git a/src/mappings/twins.ts b/src/mappings/twins.ts index e02cb1c..fa954f7 100644 --- a/src/mappings/twins.ts +++ b/src/mappings/twins.ts @@ -8,220 +8,220 @@ import { TfgridModuleTwinStoredEvent, TfgridModuleTwinDeletedEvent, TfgridModule import { validateString } from "./nodes"; export async function twinStored( - ctx: Ctx, - item: EventItem<'TfgridModule.TwinStored', { event: { args: true } }> + ctx: Ctx, + item: EventItem<'TfgridModule.TwinStored', { event: { args: true } }> ) { - const twin = getTwinCreate(ctx, item) + const twin = getTwinCreate(ctx, item) - const newTwin = new Twin() + const newTwin = new Twin() - newTwin.id = item.event.id - newTwin.gridVersion = twin.version - newTwin.twinID = twin.twinID - newTwin.accountID = twin.accountID - newTwin.relay = twin.relay - newTwin.publicKey = twin.pk + newTwin.id = item.event.id + newTwin.gridVersion = twin.version + newTwin.twinID = twin.twinID + newTwin.accountID = twin.accountID + newTwin.relay = twin.relay + newTwin.publicKey = twin.pk - await ctx.store.save(newTwin) + await ctx.store.save(newTwin) } export async function twinUpdated( - ctx: Ctx, - item: EventItem<'TfgridModule.TwinUpdated', { event: { args: true } }> + ctx: Ctx, + item: EventItem<'TfgridModule.TwinUpdated', { event: { args: true } }> ) { - const twin = getTwinUpdate(ctx, item) + const twin = getTwinUpdate(ctx, item) - const savedTwin: any = await ctx.store.get(Twin, { where: { twinID: twin.twinID } }) - if (!savedTwin) return + const savedTwin: any = await ctx.store.get(Twin, { where: { twinID: twin.twinID } }) + if (!savedTwin) return - savedTwin.relay = twin.relay - savedTwin.publicKey = twin.pk - savedTwin.gridVersion = twin.version + savedTwin.relay = twin.relay + savedTwin.publicKey = twin.pk + savedTwin.gridVersion = twin.version - await ctx.store.save(savedTwin) + await ctx.store.save(savedTwin) } export async function twinDeleted( - ctx: Ctx, - item: EventItem<'TfgridModule.TwinDeleted', { event: { args: true } }> + ctx: Ctx, + item: EventItem<'TfgridModule.TwinDeleted', { event: { args: true } }> ) { - const twinDeletedEvent = new TfgridModuleTwinDeletedEvent(ctx, item.event).asV49 + const twinDeletedEvent = new TfgridModuleTwinDeletedEvent(ctx, item.event).asV49 - const savedTwin: any = await ctx.store.get(Twin, { where: { twinID: twinDeletedEvent } }) - if (!savedTwin) return + const savedTwin: any = await ctx.store.get(Twin, { where: { twinID: twinDeletedEvent } }) + if (!savedTwin) return - await ctx.store.remove(savedTwin) + await ctx.store.remove(savedTwin) } export async function twinCreateOrUpdateOrDelete(ctx: Ctx): Promise<[Twin[], Twin[], Twin[]]> { - let newTwins = [] - let updatedTwins = [] - let deletedTwins = [] - for (let block of ctx.blocks) { - for (let item of block.items) { - if (item.name === "TfgridModule.TwinStored") { - const twin = getTwinCreate(ctx, item) - - const newTwin = new Twin() - - newTwin.id = item.event.id - newTwin.gridVersion = twin.version - newTwin.twinID = twin.twinID - newTwin.accountID = twin.accountID - newTwin.relay = twin.relay - newTwin.publicKey = twin.pk - - newTwins.push(newTwin) - } - if (item.name === "TfgridModule.TwinUpdated") { - const twin = getTwinUpdate(ctx, item) - - const foundInNewListIndex: number = newTwins.findIndex(t => t.twinID == twin.twinID); - if (foundInNewListIndex != -1) { - const savedTwin: Twin = newTwins[foundInNewListIndex] - savedTwin.relay = twin.relay - savedTwin.publicKey = twin.pk - savedTwin.gridVersion = twin.version - newTwins[foundInNewListIndex] = savedTwin - continue + let newTwins = [] + let updatedTwins = [] + let deletedTwins = [] + for (let block of ctx.blocks) { + for (let item of block.items) { + if (item.name === "TfgridModule.TwinStored") { + const twin = getTwinCreate(ctx, item) + + const newTwin = new Twin() + + newTwin.id = item.event.id + newTwin.gridVersion = twin.version + newTwin.twinID = twin.twinID + newTwin.accountID = twin.accountID + newTwin.relay = twin.relay + newTwin.publicKey = twin.pk + + newTwins.push(newTwin) + } + if (item.name === "TfgridModule.TwinUpdated") { + const twin = getTwinUpdate(ctx, item) + + const foundInNewListIndex: number = newTwins.findIndex(t => t.twinID == twin.twinID); + if (foundInNewListIndex != -1) { + const savedTwin: Twin = newTwins[foundInNewListIndex] + savedTwin.relay = twin.relay + savedTwin.publicKey = twin.pk + savedTwin.gridVersion = twin.version + newTwins[foundInNewListIndex] = savedTwin + continue + } + + const foundInUpdatedListIndex: number = updatedTwins.findIndex(t => t.twinID == twin.twinID); + if (foundInUpdatedListIndex != -1) { + let savedTwin: Twin = updatedTwins[foundInUpdatedListIndex] + savedTwin.relay = twin.relay + savedTwin.publicKey = twin.pk + savedTwin.gridVersion = twin.version + updatedTwins[foundInUpdatedListIndex] = savedTwin + continue + } + + const savedTwin: any = await ctx.store.get(Twin, { where: { twinID: twin.twinID } }) + if (!savedTwin) continue + savedTwin.relay = twin.relay + savedTwin.publicKey = twin.pk + savedTwin.gridVersion = twin.version + updatedTwins.push(savedTwin) + } + if (item.name === "TfgridModule.TwinDeleted") { + const twinDeletedEvent = new TfgridModuleTwinDeletedEvent(ctx, item.event).asV49 + + const savedTwin = await ctx.store.get(Twin, { where: { twinID: twinDeletedEvent } }) + if (savedTwin) { + deletedTwins.push(savedTwin) + } + } } - - const foundInUpdatedListIndex: number = updatedTwins.findIndex(t => t.twinID == twin.twinID); - if (foundInUpdatedListIndex != -1) { - let savedTwin: Twin = updatedTwins[foundInUpdatedListIndex] - savedTwin.relay = twin.relay - savedTwin.publicKey = twin.pk - savedTwin.gridVersion = twin.version - updatedTwins[foundInUpdatedListIndex] = savedTwin - continue - } - - const savedTwin: any = await ctx.store.get(Twin, { where: { twinID: twin.twinID } }) - if (!savedTwin) continue - savedTwin.relay = twin.relay - savedTwin.publicKey = twin.pk - savedTwin.gridVersion = twin.version - updatedTwins.push(savedTwin) - } - if (item.name === "TfgridModule.TwinDeleted") { - const twinDeletedEvent = new TfgridModuleTwinDeletedEvent(ctx, item.event).asV49 - - const savedTwin = await ctx.store.get(Twin, { where: { twinID: twinDeletedEvent } }) - if (savedTwin) { - deletedTwins.push(savedTwin) - } - } } - } - return [newTwins, updatedTwins, deletedTwins] + return [newTwins, updatedTwins, deletedTwins] } function getTwinCreate( - ctx: Ctx, - item: EventItem<'TfgridModule.TwinStored', { event: { args: true } }> + ctx: Ctx, + item: EventItem<'TfgridModule.TwinStored', { event: { args: true } }> ): TwinEvent { - let id = "" - let twinID = 0 - let version = 0 - let relay = "" - let accountID = "" - let pk = "" - - const twinEvent = new TfgridModuleTwinStoredEvent(ctx, item.event) - let twin - if (twinEvent.isV49) { - twin = twinEvent.asV49 - id = item.event.id - twinID = twin.id - version = twin.version - relay = validateString(ctx, twin.ip.toString()) - accountID = ss58.codec("substrate").encode(twin.accountId) - } else if (twinEvent.isV101) { - twin = twinEvent.asV101 - id = item.event.id - twinID = twin.id - version = twin.version - relay = validateString(ctx, twin.ip.toString()) - accountID = ss58.codec("substrate").encode(twin.accountId) - } else if (twinEvent.isV124) { - twin = twinEvent.asV124 - id = item.event.id - twinID = twin.id - if (twin.relay) { - relay = validateString(ctx, twin.relay?.toString()) + let id = "" + let twinID = 0 + let version = 0 + let relay = "" + let accountID = "" + let pk = "" + + const twinEvent = new TfgridModuleTwinStoredEvent(ctx, item.event) + let twin + if (twinEvent.isV49) { + twin = twinEvent.asV49 + id = item.event.id + twinID = twin.id + version = twin.version + relay = validateString(ctx, twin.ip.toString()) + accountID = ss58.codec("substrate").encode(twin.accountId) + } else if (twinEvent.isV101) { + twin = twinEvent.asV101 + id = item.event.id + twinID = twin.id + version = twin.version + relay = validateString(ctx, twin.ip.toString()) + accountID = ss58.codec("substrate").encode(twin.accountId) + } else if (twinEvent.isV124) { + twin = twinEvent.asV124 + id = item.event.id + twinID = twin.id + if (twin.relay) { + relay = validateString(ctx, twin.relay?.toString()) + } + accountID = ss58.codec("substrate").encode(twin.accountId) + if (twin.pk) { + pk = '0x' + Buffer.from(twin.pk).toString('hex'); + } } - accountID = ss58.codec("substrate").encode(twin.accountId) - if (twin.pk) { - pk = '0x' + Buffer.from(twin.pk).toString('hex'); + + return { + id, + twinID, + version, + relay, + accountID, + pk } - } - - return { - id, - twinID, - version, - relay, - accountID, - pk - } } function getTwinUpdate( - ctx: Ctx, - item: EventItem<'TfgridModule.TwinUpdated', { event: { args: true } }> + ctx: Ctx, + item: EventItem<'TfgridModule.TwinUpdated', { event: { args: true } }> ): TwinEvent { - let id = "" - let twinID = 0 - let version = 0 - let relay = "" - let accountID = "" - let pk = "" - - const twinEvent = new TfgridModuleTwinUpdatedEvent(ctx, item.event) - let twin - if (twinEvent.isV49) { - twin = twinEvent.asV49 - id = item.event.id - twinID = twin.id - version = twin.version - relay = validateString(ctx, twin.ip.toString()) - accountID = ss58.codec("substrate").encode(twin.accountId) - } else if (twinEvent.isV101) { - twin = twinEvent.asV101 - id = item.event.id - twinID = twin.id - version = twin.version - relay = validateString(ctx, twin.ip.toString()) - accountID = ss58.codec("substrate").encode(twin.accountId) - } else if (twinEvent.isV124) { - twin = twinEvent.asV124 - id = item.event.id - twinID = twin.id - if (twin.relay) { - relay = validateString(ctx, twin.relay?.toString()) + let id = "" + let twinID = 0 + let version = 0 + let relay = "" + let accountID = "" + let pk = "" + + const twinEvent = new TfgridModuleTwinUpdatedEvent(ctx, item.event) + let twin + if (twinEvent.isV49) { + twin = twinEvent.asV49 + id = item.event.id + twinID = twin.id + version = twin.version + relay = validateString(ctx, twin.ip.toString()) + accountID = ss58.codec("substrate").encode(twin.accountId) + } else if (twinEvent.isV101) { + twin = twinEvent.asV101 + id = item.event.id + twinID = twin.id + version = twin.version + relay = validateString(ctx, twin.ip.toString()) + accountID = ss58.codec("substrate").encode(twin.accountId) + } else if (twinEvent.isV124) { + twin = twinEvent.asV124 + id = item.event.id + twinID = twin.id + if (twin.relay) { + relay = validateString(ctx, twin.relay?.toString()) + } + accountID = ss58.codec("substrate").encode(twin.accountId) + if (twin.pk) { + pk = validateString(ctx, '0x' + Buffer.from(twin.pk).toString('hex')); + } } - accountID = ss58.codec("substrate").encode(twin.accountId) - if (twin.pk) { - pk = validateString(ctx, '0x' + Buffer.from(twin.pk).toString('hex')); + + return { + id, + twinID, + version, + relay, + accountID, + pk } - } - - return { - id, - twinID, - version, - relay, - accountID, - pk - } } interface TwinEvent { - id: string - twinID: number - version: number - relay: string - accountID: string - pk: string + id: string + twinID: number + version: number + relay: string + accountID: string + pk: string } \ No newline at end of file diff --git a/src/types/v101.ts b/src/types/v101.ts index 24fc620..c50a717 100644 --- a/src/types/v101.ts +++ b/src/types/v101.ts @@ -1,183 +1,183 @@ export interface Contract { - version: number - state: ContractState - contractId: bigint - twinId: number - contractType: ContractData + version: number + state: ContractState + contractId: bigint + twinId: number + contractType: ContractData } export interface Node { - version: number - id: number - farmId: number - twinId: number - resources: Resources - location: Location - country: Uint8Array - city: Uint8Array - publicConfig: (PublicConfig | undefined) - created: bigint - farmingPolicyId: number - interfaces: Interface[] - certification: NodeCertification - secureBoot: boolean - virtualized: boolean - serialNumber: Uint8Array - connectionPrice: number + version: number + id: number + farmId: number + twinId: number + resources: Resources + location: Location + country: Uint8Array + city: Uint8Array + publicConfig: (PublicConfig | undefined) + created: bigint + farmingPolicyId: number + interfaces: Interface[] + certification: NodeCertification + secureBoot: boolean + virtualized: boolean + serialNumber: Uint8Array + connectionPrice: number } export interface PricingPolicy { - version: number - id: number - name: Uint8Array - su: Policy - cu: Policy - nu: Policy - ipu: Policy - uniqueName: Policy - domainName: Policy - foundationAccount: Uint8Array - certifiedSalesAccount: Uint8Array - discountForDedicationNodes: number + version: number + id: number + name: Uint8Array + su: Policy + cu: Policy + nu: Policy + ipu: Policy + uniqueName: Policy + domainName: Policy + foundationAccount: Uint8Array + certifiedSalesAccount: Uint8Array + discountForDedicationNodes: number } export interface Twin { - version: number - id: number - accountId: Uint8Array - ip: Uint8Array - entities: EntityProof[] + version: number + id: number + accountId: Uint8Array + ip: Uint8Array + entities: EntityProof[] } export type ContractState = ContractState_Created | ContractState_Deleted | ContractState_GracePeriod export interface ContractState_Created { - __kind: 'Created' + __kind: 'Created' } export interface ContractState_Deleted { - __kind: 'Deleted' - value: Cause + __kind: 'Deleted' + value: Cause } export interface ContractState_GracePeriod { - __kind: 'GracePeriod' - value: bigint + __kind: 'GracePeriod' + value: bigint } export type ContractData = ContractData_NodeContract | ContractData_NameContract | ContractData_RentContract export interface ContractData_NodeContract { - __kind: 'NodeContract' - value: NodeContract + __kind: 'NodeContract' + value: NodeContract } export interface ContractData_NameContract { - __kind: 'NameContract' - value: NameContract + __kind: 'NameContract' + value: NameContract } export interface ContractData_RentContract { - __kind: 'RentContract' - value: RentContract + __kind: 'RentContract' + value: RentContract } export interface Resources { - hru: bigint - sru: bigint - cru: bigint - mru: bigint + hru: bigint + sru: bigint + cru: bigint + mru: bigint } export interface Location { - longitude: Uint8Array - latitude: Uint8Array + longitude: Uint8Array + latitude: Uint8Array } export interface PublicConfig { - ipv4: Uint8Array - ipv6: Uint8Array - gw4: Uint8Array - gw6: Uint8Array - domain: Uint8Array + ipv4: Uint8Array + ipv6: Uint8Array + gw4: Uint8Array + gw6: Uint8Array + domain: Uint8Array } export interface Interface { - name: Uint8Array - mac: Uint8Array - ips: Uint8Array[] + name: Uint8Array + mac: Uint8Array + ips: Uint8Array[] } export type NodeCertification = NodeCertification_Diy | NodeCertification_Certified export interface NodeCertification_Diy { - __kind: 'Diy' + __kind: 'Diy' } export interface NodeCertification_Certified { - __kind: 'Certified' + __kind: 'Certified' } export interface Policy { - value: number - unit: Unit + value: number + unit: Unit } export interface EntityProof { - entityId: number - signature: Uint8Array + entityId: number + signature: Uint8Array } export type Cause = Cause_CanceledByUser | Cause_OutOfFunds export interface Cause_CanceledByUser { - __kind: 'CanceledByUser' + __kind: 'CanceledByUser' } export interface Cause_OutOfFunds { - __kind: 'OutOfFunds' + __kind: 'OutOfFunds' } export interface NodeContract { - nodeId: number - deploymentData: Uint8Array - deploymentHash: Uint8Array - publicIps: number - publicIpsList: PublicIP[] + nodeId: number + deploymentData: Uint8Array + deploymentHash: Uint8Array + publicIps: number + publicIpsList: PublicIP[] } export interface NameContract { - name: Uint8Array + name: Uint8Array } export interface RentContract { - nodeId: number + nodeId: number } export type Unit = Unit_Bytes | Unit_Kilobytes | Unit_Megabytes | Unit_Gigabytes | Unit_Terrabytes export interface Unit_Bytes { - __kind: 'Bytes' + __kind: 'Bytes' } export interface Unit_Kilobytes { - __kind: 'Kilobytes' + __kind: 'Kilobytes' } export interface Unit_Megabytes { - __kind: 'Megabytes' + __kind: 'Megabytes' } export interface Unit_Gigabytes { - __kind: 'Gigabytes' + __kind: 'Gigabytes' } export interface Unit_Terrabytes { - __kind: 'Terrabytes' + __kind: 'Terrabytes' } export interface PublicIP { - ip: Uint8Array - gateway: Uint8Array - contractId: bigint + ip: Uint8Array + gateway: Uint8Array + contractId: bigint } diff --git a/src/types/v105.ts b/src/types/v105.ts index c2f90e5..2803110 100644 --- a/src/types/v105.ts +++ b/src/types/v105.ts @@ -1,184 +1,184 @@ export interface Contract { - version: number - state: ContractState - contractId: bigint - twinId: number - contractType: ContractData - solutionProviderId: (bigint | undefined) + version: number + state: ContractState + contractId: bigint + twinId: number + contractType: ContractData + solutionProviderId: (bigint | undefined) } export interface SolutionProvider { - solutionProviderId: bigint - providers: Provider[] - description: Uint8Array - link: Uint8Array - approved: boolean + solutionProviderId: bigint + providers: Provider[] + description: Uint8Array + link: Uint8Array + approved: boolean } export type ContractState = ContractState_Created | ContractState_Deleted | ContractState_GracePeriod export interface ContractState_Created { - __kind: 'Created' + __kind: 'Created' } export interface ContractState_Deleted { - __kind: 'Deleted' - value: Cause + __kind: 'Deleted' + value: Cause } export interface ContractState_GracePeriod { - __kind: 'GracePeriod' - value: bigint + __kind: 'GracePeriod' + value: bigint } export type ContractData = ContractData_NodeContract | ContractData_NameContract | ContractData_RentContract export interface ContractData_NodeContract { - __kind: 'NodeContract' - value: NodeContract + __kind: 'NodeContract' + value: NodeContract } export interface ContractData_NameContract { - __kind: 'NameContract' - value: NameContract + __kind: 'NameContract' + value: NameContract } export interface ContractData_RentContract { - __kind: 'RentContract' - value: RentContract + __kind: 'RentContract' + value: RentContract } export interface Provider { - who: AccountId32 - take: number + who: AccountId32 + take: number } export type Cause = Cause_CanceledByUser | Cause_OutOfFunds export interface Cause_CanceledByUser { - __kind: 'CanceledByUser' + __kind: 'CanceledByUser' } export interface Cause_OutOfFunds { - __kind: 'OutOfFunds' + __kind: 'OutOfFunds' } export interface NodeContract { - nodeId: number - deploymentHash: H256 - deploymentData: Uint8Array - publicIps: number - publicIpsList: PublicIP[] + nodeId: number + deploymentHash: H256 + deploymentData: Uint8Array + publicIps: number + publicIpsList: PublicIP[] } export interface NameContract { - name: Uint8Array + name: Uint8Array } export interface RentContract { - nodeId: number + nodeId: number } export type AccountId32 = Uint8Array export interface PublicIP { - ip: Uint8Array - gateway: Uint8Array - contractId: bigint + ip: Uint8Array + gateway: Uint8Array + contractId: bigint } export interface Contract { - version: number - state: ContractState - contractId: bigint - twinId: number - contractType: ContractData - solutionProviderId: (bigint | undefined) + version: number + state: ContractState + contractId: bigint + twinId: number + contractType: ContractData + solutionProviderId: (bigint | undefined) } export interface PublicConfig { - ip4: IP - ip6: (IP | undefined) - domain: (Domain | undefined) + ip4: IP + ip6: (IP | undefined) + domain: (Domain | undefined) } export interface Node { - version: number - id: number - farmId: number - twinId: number - resources: Resources - location: Location - country: Uint8Array - city: Uint8Array - publicConfig: (PublicConfig | undefined) - created: bigint - farmingPolicyId: number - interfaces: Interface[] - certification: NodeCertification - secureBoot: boolean - virtualized: boolean - serialNumber: Uint8Array - connectionPrice: number + version: number + id: number + farmId: number + twinId: number + resources: Resources + location: Location + country: Uint8Array + city: Uint8Array + publicConfig: (PublicConfig | undefined) + created: bigint + farmingPolicyId: number + interfaces: Interface[] + certification: NodeCertification + secureBoot: boolean + virtualized: boolean + serialNumber: Uint8Array + connectionPrice: number } export interface IP { - ip: IP4 - gw: GW4 + ip: IP4 + gw: GW4 } export type Domain = Uint8Array export interface Resources { - hru: bigint - sru: bigint - cru: bigint - mru: bigint + hru: bigint + sru: bigint + cru: bigint + mru: bigint } export interface Location { - longitude: Uint8Array - latitude: Uint8Array + longitude: Uint8Array + latitude: Uint8Array } export interface Interface { - name: InterfaceName - mac: InterfaceMac - ips: InterfaceIp[] + name: InterfaceName + mac: InterfaceMac + ips: InterfaceIp[] } export type NodeCertification = NodeCertification_Diy | NodeCertification_Certified export interface NodeCertification_Diy { - __kind: 'Diy' + __kind: 'Diy' } export interface NodeCertification_Certified { - __kind: 'Certified' + __kind: 'Certified' } export interface Cause_CanceledByUser { - __kind: 'CanceledByUser' + __kind: 'CanceledByUser' } export interface Cause_OutOfFunds { - __kind: 'OutOfFunds' + __kind: 'OutOfFunds' } export interface NodeContract { - nodeId: number - deploymentHash: H256 - deploymentData: Uint8Array - publicIps: number - publicIpsList: PublicIP[] + nodeId: number + deploymentHash: H256 + deploymentData: Uint8Array + publicIps: number + publicIpsList: PublicIP[] } export interface NameContract { - name: NameContractName + name: NameContractName } export interface RentContract { - nodeId: number + nodeId: number } export type IP4 = Uint8Array @@ -194,9 +194,9 @@ export type InterfaceIp = Uint8Array export type H256 = Uint8Array export interface PublicIP { - ip: Uint8Array - gateway: GatewayIP - contractId: bigint + ip: Uint8Array + gateway: GatewayIP + contractId: bigint } export type NameContractName = Uint8Array diff --git a/src/types/v118.ts b/src/types/v118.ts index 0873c23..0c57d4d 100644 --- a/src/types/v118.ts +++ b/src/types/v118.ts @@ -1,61 +1,61 @@ export type NodeCertification = NodeCertification_Diy | NodeCertification_Certified export interface NodeCertification_Diy { - __kind: 'Diy' + __kind: 'Diy' } export interface NodeCertification_Certified { - __kind: 'Certified' + __kind: 'Certified' } export interface PublicConfig { - ip4: IP - ip6: (IP | undefined) - domain: (Domain | undefined) + ip4: IP + ip6: (IP | undefined) + domain: (Domain | undefined) } export interface Node { - version: number - id: number - farmId: number - twinId: number - resources: Resources - location: Location - publicConfig: (PublicConfig | undefined) - created: bigint - farmingPolicyId: number - interfaces: Interface[] - certification: NodeCertification - secureBoot: boolean - virtualized: boolean - serialNumber: (SerialNumber | undefined) - connectionPrice: number + version: number + id: number + farmId: number + twinId: number + resources: Resources + location: Location + publicConfig: (PublicConfig | undefined) + created: bigint + farmingPolicyId: number + interfaces: Interface[] + certification: NodeCertification + secureBoot: boolean + virtualized: boolean + serialNumber: (SerialNumber | undefined) + connectionPrice: number } export interface Interface { - name: InterfaceName - mac: InterfaceMac - ips: InterfaceIp[] + name: InterfaceName + mac: InterfaceMac + ips: InterfaceIp[] } export interface Resources { - hru: bigint - sru: bigint - cru: bigint - mru: bigint + hru: bigint + sru: bigint + cru: bigint + mru: bigint } export type FarmName = Uint8Array export interface PublicIP { - ip: Uint8Array - gateway: GatewayIP - contractId: bigint + ip: Uint8Array + gateway: GatewayIP + contractId: bigint } export interface IP { - ip: IP4 - gw: GW4 + ip: IP4 + gw: GW4 } export type Domain = Uint8Array @@ -79,9 +79,9 @@ export type InterfaceMac = Uint8Array export type InterfaceIp = Uint8Array export interface Location { - city: CityName - country: CountryName - latitude: Uint8Array - longitude: Uint8Array + city: CityName + country: CountryName + latitude: Uint8Array + longitude: Uint8Array } diff --git a/src/types/v12.ts b/src/types/v12.ts index 55c45e0..bae102a 100644 --- a/src/types/v12.ts +++ b/src/types/v12.ts @@ -1,7 +1,7 @@ export interface PublicConfig { - ipv4: Uint8Array - ipv6: Uint8Array - gw4: Uint8Array - gw6: Uint8Array - domain: Uint8Array + ipv4: Uint8Array + ipv6: Uint8Array + gw4: Uint8Array + gw6: Uint8Array + domain: Uint8Array } diff --git a/src/types/v122.ts b/src/types/v122.ts index de5122d..52499a9 100644 --- a/src/types/v122.ts +++ b/src/types/v122.ts @@ -1,42 +1,42 @@ export interface ServiceContract { - serviceContractId: bigint - serviceTwinId: number - consumerTwinId: number - baseFee: bigint - variableFee: bigint - metadata: Uint8Array - acceptedByService: boolean - acceptedByConsumer: boolean - lastBill: bigint - state: ServiceContractState + serviceContractId: bigint + serviceTwinId: number + consumerTwinId: number + baseFee: bigint + variableFee: bigint + metadata: Uint8Array + acceptedByService: boolean + acceptedByConsumer: boolean + lastBill: bigint + state: ServiceContractState } export interface ServiceContractBill { - variableAmount: bigint - window: bigint - metadata: Uint8Array + variableAmount: bigint + window: bigint + metadata: Uint8Array } export type ServiceContractState = ServiceContractState_Created | ServiceContractState_AgreementReady | ServiceContractState_ApprovedByBoth export interface ServiceContractState_Created { - __kind: 'Created' + __kind: 'Created' } export interface ServiceContractState_AgreementReady { - __kind: 'AgreementReady' + __kind: 'AgreementReady' } export interface ServiceContractState_ApprovedByBoth { - __kind: 'ApprovedByBoth' + __kind: 'ApprovedByBoth' } export type Cause = Cause_CanceledByUser | Cause_OutOfFunds export interface Cause_CanceledByUser { - __kind: 'CanceledByUser' + __kind: 'CanceledByUser' } export interface Cause_OutOfFunds { - __kind: 'OutOfFunds' + __kind: 'OutOfFunds' } \ No newline at end of file diff --git a/src/types/v25.ts b/src/types/v25.ts index 6233fb9..a7d9278 100644 --- a/src/types/v25.ts +++ b/src/types/v25.ts @@ -1,58 +1,58 @@ export interface Contract { - version: number - state: ContractState - contractId: bigint - twinId: number - contractType: ContractData + version: number + state: ContractState + contractId: bigint + twinId: number + contractType: ContractData } export type ContractState = ContractState_Created | ContractState_Deleted export interface ContractState_Created { - __kind: 'Created' + __kind: 'Created' } export interface ContractState_Deleted { - __kind: 'Deleted' - value: Cause + __kind: 'Deleted' + value: Cause } export type ContractData = ContractData_NodeContract | ContractData_NameContract export interface ContractData_NodeContract { - __kind: 'NodeContract' - value: NodeContract + __kind: 'NodeContract' + value: NodeContract } export interface ContractData_NameContract { - __kind: 'NameContract' - value: NameContract + __kind: 'NameContract' + value: NameContract } export type Cause = Cause_CanceledByUser | Cause_OutOfFunds export interface Cause_CanceledByUser { - __kind: 'CanceledByUser' + __kind: 'CanceledByUser' } export interface Cause_OutOfFunds { - __kind: 'OutOfFunds' + __kind: 'OutOfFunds' } export interface NodeContract { - nodeId: number - deploymentData: Uint8Array - deploymentHash: Uint8Array - publicIps: number - publicIpsList: PublicIP[] + nodeId: number + deploymentData: Uint8Array + deploymentHash: Uint8Array + publicIps: number + publicIpsList: PublicIP[] } export interface NameContract { - name: Uint8Array + name: Uint8Array } export interface PublicIP { - ip: Uint8Array - gateway: Uint8Array - contractId: bigint + ip: Uint8Array + gateway: Uint8Array + contractId: bigint } diff --git a/src/types/v28.ts b/src/types/v28.ts index 0825d5b..9433783 100644 --- a/src/types/v28.ts +++ b/src/types/v28.ts @@ -1,51 +1,51 @@ export interface Node { - version: number - id: number - farmId: number - twinId: number - resources: Resources - location: Location - country: Uint8Array - city: Uint8Array - publicConfig: (PublicConfig | undefined) - created: bigint - farmingPolicyId: number - interfaces: Interface[] - certificationType: CertificationType + version: number + id: number + farmId: number + twinId: number + resources: Resources + location: Location + country: Uint8Array + city: Uint8Array + publicConfig: (PublicConfig | undefined) + created: bigint + farmingPolicyId: number + interfaces: Interface[] + certificationType: CertificationType } export interface Resources { - hru: bigint - sru: bigint - cru: bigint - mru: bigint + hru: bigint + sru: bigint + cru: bigint + mru: bigint } export interface Location { - longitude: Uint8Array - latitude: Uint8Array + longitude: Uint8Array + latitude: Uint8Array } export interface PublicConfig { - ipv4: Uint8Array - ipv6: Uint8Array - gw4: Uint8Array - gw6: Uint8Array - domain: Uint8Array + ipv4: Uint8Array + ipv6: Uint8Array + gw4: Uint8Array + gw6: Uint8Array + domain: Uint8Array } export interface Interface { - name: Uint8Array - mac: Uint8Array - ips: Uint8Array[] + name: Uint8Array + mac: Uint8Array + ips: Uint8Array[] } export type CertificationType = CertificationType_Diy | CertificationType_Certified export interface CertificationType_Diy { - __kind: 'Diy' + __kind: 'Diy' } export interface CertificationType_Certified { - __kind: 'Certified' + __kind: 'Certified' } diff --git a/src/types/v43.ts b/src/types/v43.ts index bfd65f5..9eae569 100644 --- a/src/types/v43.ts +++ b/src/types/v43.ts @@ -1,54 +1,54 @@ export interface Node { - version: number - id: number - farmId: number - twinId: number - resources: Resources - location: Location - country: Uint8Array - city: Uint8Array - publicConfig: (PublicConfig | undefined) - created: bigint - farmingPolicyId: number - interfaces: Interface[] - certificationType: CertificationType - secureBoot: boolean - virtualized: boolean - serialNumber: Uint8Array + version: number + id: number + farmId: number + twinId: number + resources: Resources + location: Location + country: Uint8Array + city: Uint8Array + publicConfig: (PublicConfig | undefined) + created: bigint + farmingPolicyId: number + interfaces: Interface[] + certificationType: CertificationType + secureBoot: boolean + virtualized: boolean + serialNumber: Uint8Array } export interface Resources { - hru: bigint - sru: bigint - cru: bigint - mru: bigint + hru: bigint + sru: bigint + cru: bigint + mru: bigint } export interface Location { - longitude: Uint8Array - latitude: Uint8Array + longitude: Uint8Array + latitude: Uint8Array } export interface PublicConfig { - ipv4: Uint8Array - ipv6: Uint8Array - gw4: Uint8Array - gw6: Uint8Array - domain: Uint8Array + ipv4: Uint8Array + ipv6: Uint8Array + gw4: Uint8Array + gw6: Uint8Array + domain: Uint8Array } export interface Interface { - name: Uint8Array - mac: Uint8Array - ips: Uint8Array[] + name: Uint8Array + mac: Uint8Array + ips: Uint8Array[] } export type CertificationType = CertificationType_Diy | CertificationType_Certified export interface CertificationType_Diy { - __kind: 'Diy' + __kind: 'Diy' } export interface CertificationType_Certified { - __kind: 'Certified' + __kind: 'Certified' } diff --git a/src/types/v49.ts b/src/types/v49.ts index 981a6ad..de52aa5 100644 --- a/src/types/v49.ts +++ b/src/types/v49.ts @@ -1,239 +1,239 @@ export interface ContractBill { - contractId: bigint - timestamp: bigint - discountLevel: DiscountLevel - amountBilled: bigint + contractId: bigint + timestamp: bigint + discountLevel: DiscountLevel + amountBilled: bigint } export interface Contract { - version: number - state: ContractState - contractId: bigint - twinId: number - contractType: ContractData + version: number + state: ContractState + contractId: bigint + twinId: number + contractType: ContractData } export interface NruConsumption { - contractId: bigint - timestamp: bigint - window: bigint - nru: bigint + contractId: bigint + timestamp: bigint + window: bigint + nru: bigint } export interface ContractResources { - contractId: bigint - used: Resources + contractId: bigint + used: Resources } export interface Entity { - version: number - id: number - name: Uint8Array - accountId: Uint8Array - country: Uint8Array - city: Uint8Array + version: number + id: number + name: Uint8Array + accountId: Uint8Array + country: Uint8Array + city: Uint8Array } export interface Farm { - version: number - id: number - name: Uint8Array - twinId: number - pricingPolicyId: number - certificationType: CertificationType - publicIps: PublicIP[] + version: number + id: number + name: Uint8Array + twinId: number + pricingPolicyId: number + certificationType: CertificationType + publicIps: PublicIP[] } export interface FarmingPolicy { - version: number - id: number - name: Uint8Array - cu: number - su: number - nu: number - ipv4: number - timestamp: bigint - certificationType: CertificationType + version: number + id: number + name: Uint8Array + cu: number + su: number + nu: number + ipv4: number + timestamp: bigint + certificationType: CertificationType } export interface PublicConfig { - ipv4: Uint8Array - ipv6: Uint8Array - gw4: Uint8Array - gw6: Uint8Array - domain: Uint8Array + ipv4: Uint8Array + ipv6: Uint8Array + gw4: Uint8Array + gw6: Uint8Array + domain: Uint8Array } export interface Node { - version: number - id: number - farmId: number - twinId: number - resources: Resources - location: Location - country: Uint8Array - city: Uint8Array - publicConfig: (PublicConfig | undefined) - created: bigint - farmingPolicyId: number - interfaces: Interface[] - certificationType: CertificationType - secureBoot: boolean - virtualized: boolean - serialNumber: Uint8Array + version: number + id: number + farmId: number + twinId: number + resources: Resources + location: Location + country: Uint8Array + city: Uint8Array + publicConfig: (PublicConfig | undefined) + created: bigint + farmingPolicyId: number + interfaces: Interface[] + certificationType: CertificationType + secureBoot: boolean + virtualized: boolean + serialNumber: Uint8Array } export interface PricingPolicy { - version: number - id: number - name: Uint8Array - su: Policy - cu: Policy - nu: Policy - ipu: Policy - uniqueName: Policy - domainName: Policy - foundationAccount: Uint8Array - certifiedSalesAccount: Uint8Array + version: number + id: number + name: Uint8Array + su: Policy + cu: Policy + nu: Policy + ipu: Policy + uniqueName: Policy + domainName: Policy + foundationAccount: Uint8Array + certifiedSalesAccount: Uint8Array } export interface Twin { - id: number - ip: Uint8Array - version: number - entities: EntityProof[] - accountId: Uint8Array + id: number + ip: Uint8Array + version: number + entities: EntityProof[] + accountId: Uint8Array } export type DiscountLevel = DiscountLevel_None | DiscountLevel_Default | DiscountLevel_Bronze | DiscountLevel_Silver | DiscountLevel_Gold export interface DiscountLevel_None { - __kind: 'None' + __kind: 'None' } export interface DiscountLevel_Default { - __kind: 'Default' + __kind: 'Default' } export interface DiscountLevel_Bronze { - __kind: 'Bronze' + __kind: 'Bronze' } export interface DiscountLevel_Silver { - __kind: 'Silver' + __kind: 'Silver' } export interface DiscountLevel_Gold { - __kind: 'Gold' + __kind: 'Gold' } export type ContractState = ContractState_Created | ContractState_Deleted export interface ContractState_Created { - __kind: 'Created' + __kind: 'Created' } export interface ContractState_Deleted { - __kind: 'Deleted' - value: Cause + __kind: 'Deleted' + value: Cause } export type ContractData = ContractData_NodeContract | ContractData_NameContract export interface ContractData_NodeContract { - __kind: 'NodeContract' - value: NodeContract + __kind: 'NodeContract' + value: NodeContract } export interface ContractData_NameContract { - __kind: 'NameContract' - value: NameContract + __kind: 'NameContract' + value: NameContract } export interface Resources { - hru: bigint - sru: bigint - cru: bigint - mru: bigint + hru: bigint + sru: bigint + cru: bigint + mru: bigint } export type CertificationType = CertificationType_Diy | CertificationType_Certified export interface CertificationType_Diy { - __kind: 'Diy' + __kind: 'Diy' } export interface CertificationType_Certified { - __kind: 'Certified' + __kind: 'Certified' } export interface PublicIP { - ip: Uint8Array - gateway: Uint8Array - contractId: bigint + ip: Uint8Array + gateway: Uint8Array + contractId: bigint } export interface Location { - longitude: Uint8Array - latitude: Uint8Array + longitude: Uint8Array + latitude: Uint8Array } export interface Interface { - name: Uint8Array - mac: Uint8Array - ips: Uint8Array[] + name: Uint8Array + mac: Uint8Array + ips: Uint8Array[] } export interface Policy { - value: number - unit: Unit + value: number + unit: Unit } export interface EntityProof { - entityId: number - signature: Uint8Array + entityId: number + signature: Uint8Array } export type Cause = Cause_CanceledByUser | Cause_OutOfFunds export interface Cause_CanceledByUser { - __kind: 'CanceledByUser' + __kind: 'CanceledByUser' } export interface Cause_OutOfFunds { - __kind: 'OutOfFunds' + __kind: 'OutOfFunds' } export interface NodeContract { - nodeId: number - deploymentData: Uint8Array - deploymentHash: Uint8Array - publicIps: number - publicIpsList: PublicIP[] + nodeId: number + deploymentData: Uint8Array + deploymentHash: Uint8Array + publicIps: number + publicIpsList: PublicIP[] } export interface NameContract { - name: Uint8Array + name: Uint8Array } export type Unit = Unit_Bytes | Unit_Kilobytes | Unit_Megabytes | Unit_Gigabytes | Unit_Terrabytes export interface Unit_Bytes { - __kind: 'Bytes' + __kind: 'Bytes' } export interface Unit_Kilobytes { - __kind: 'Kilobytes' + __kind: 'Kilobytes' } export interface Unit_Megabytes { - __kind: 'Megabytes' + __kind: 'Megabytes' } export interface Unit_Gigabytes { - __kind: 'Gigabytes' + __kind: 'Gigabytes' } export interface Unit_Terrabytes { - __kind: 'Terrabytes' + __kind: 'Terrabytes' } diff --git a/src/types/v50.ts b/src/types/v50.ts index a216969..6593aae 100644 --- a/src/types/v50.ts +++ b/src/types/v50.ts @@ -1,88 +1,88 @@ export interface Contract { - version: number - state: ContractState - contractId: bigint - twinId: number - contractType: ContractData + version: number + state: ContractState + contractId: bigint + twinId: number + contractType: ContractData } export interface Farm { - version: number - id: number - name: Uint8Array - twinId: number - pricingPolicyId: number - certificationType: CertificationType - publicIps: PublicIP[] - dedicatedFarm: boolean + version: number + id: number + name: Uint8Array + twinId: number + pricingPolicyId: number + certificationType: CertificationType + publicIps: PublicIP[] + dedicatedFarm: boolean } export type ContractState = ContractState_Created | ContractState_Deleted export interface ContractState_Created { - __kind: 'Created' + __kind: 'Created' } export interface ContractState_Deleted { - __kind: 'Deleted' - value: Cause + __kind: 'Deleted' + value: Cause } export type ContractData = ContractData_NodeContract | ContractData_NameContract | ContractData_RentContract export interface ContractData_NodeContract { - __kind: 'NodeContract' - value: NodeContract + __kind: 'NodeContract' + value: NodeContract } export interface ContractData_NameContract { - __kind: 'NameContract' - value: NameContract + __kind: 'NameContract' + value: NameContract } export interface ContractData_RentContract { - __kind: 'RentContract' - value: RentContract + __kind: 'RentContract' + value: RentContract } export type CertificationType = CertificationType_Diy | CertificationType_Certified export interface CertificationType_Diy { - __kind: 'Diy' + __kind: 'Diy' } export interface CertificationType_Certified { - __kind: 'Certified' + __kind: 'Certified' } export interface PublicIP { - ip: Uint8Array - gateway: Uint8Array - contractId: bigint + ip: Uint8Array + gateway: Uint8Array + contractId: bigint } export type Cause = Cause_CanceledByUser | Cause_OutOfFunds export interface Cause_CanceledByUser { - __kind: 'CanceledByUser' + __kind: 'CanceledByUser' } export interface Cause_OutOfFunds { - __kind: 'OutOfFunds' + __kind: 'OutOfFunds' } export interface NodeContract { - nodeId: number - deploymentData: Uint8Array - deploymentHash: Uint8Array - publicIps: number - publicIpsList: PublicIP[] + nodeId: number + deploymentData: Uint8Array + deploymentHash: Uint8Array + publicIps: number + publicIpsList: PublicIP[] } export interface NameContract { - name: Uint8Array + name: Uint8Array } export interface RentContract { - nodeId: number + nodeId: number } diff --git a/src/types/v51.ts b/src/types/v51.ts index 85044ee..bc72fe5 100644 --- a/src/types/v51.ts +++ b/src/types/v51.ts @@ -1,41 +1,41 @@ export interface PricingPolicy { - version: number - id: number - name: Uint8Array - su: Policy - cu: Policy - nu: Policy - ipu: Policy - uniqueName: Policy - domainName: Policy - foundationAccount: Uint8Array - certifiedSalesAccount: Uint8Array - discountForDedicatedNodes: number + version: number + id: number + name: Uint8Array + su: Policy + cu: Policy + nu: Policy + ipu: Policy + uniqueName: Policy + domainName: Policy + foundationAccount: Uint8Array + certifiedSalesAccount: Uint8Array + discountForDedicatedNodes: number } export interface Policy { - value: number - unit: Unit + value: number + unit: Unit } export type Unit = Unit_Bytes | Unit_Kilobytes | Unit_Megabytes | Unit_Gigabytes | Unit_Terrabytes export interface Unit_Bytes { - __kind: 'Bytes' + __kind: 'Bytes' } export interface Unit_Kilobytes { - __kind: 'Kilobytes' + __kind: 'Kilobytes' } export interface Unit_Megabytes { - __kind: 'Megabytes' + __kind: 'Megabytes' } export interface Unit_Gigabytes { - __kind: 'Gigabytes' + __kind: 'Gigabytes' } export interface Unit_Terrabytes { - __kind: 'Terrabytes' + __kind: 'Terrabytes' } diff --git a/src/types/v59.ts b/src/types/v59.ts index dfb28cb..70c7921 100644 --- a/src/types/v59.ts +++ b/src/types/v59.ts @@ -1,65 +1,65 @@ export interface Contract { - version: number - state: ContractState - contractId: bigint - twinId: number - contractType: ContractData + version: number + state: ContractState + contractId: bigint + twinId: number + contractType: ContractData } export type ContractState = ContractState_Created | ContractState_Deleted | ContractState_OutOfFunds | ContractState_GracePeriod export interface ContractState_Created { - __kind: 'Created' + __kind: 'Created' } export interface ContractState_Deleted { - __kind: 'Deleted' + __kind: 'Deleted' } export interface ContractState_OutOfFunds { - __kind: 'OutOfFunds' + __kind: 'OutOfFunds' } export interface ContractState_GracePeriod { - __kind: 'GracePeriod' - value: bigint + __kind: 'GracePeriod' + value: bigint } export type ContractData = ContractData_NodeContract | ContractData_NameContract | ContractData_RentContract export interface ContractData_NodeContract { - __kind: 'NodeContract' - value: NodeContract + __kind: 'NodeContract' + value: NodeContract } export interface ContractData_NameContract { - __kind: 'NameContract' - value: NameContract + __kind: 'NameContract' + value: NameContract } export interface ContractData_RentContract { - __kind: 'RentContract' - value: RentContract + __kind: 'RentContract' + value: RentContract } export interface NodeContract { - nodeId: number - deploymentData: Uint8Array - deploymentHash: Uint8Array - publicIps: number - publicIpsList: PublicIP[] + nodeId: number + deploymentData: Uint8Array + deploymentHash: Uint8Array + publicIps: number + publicIpsList: PublicIP[] } export interface NameContract { - name: Uint8Array + name: Uint8Array } export interface RentContract { - nodeId: number + nodeId: number } export interface PublicIP { - ip: Uint8Array - gateway: Uint8Array - contractId: bigint + ip: Uint8Array + gateway: Uint8Array + contractId: bigint } diff --git a/src/types/v63.ts b/src/types/v63.ts index a2d3827..a7a61d4 100644 --- a/src/types/v63.ts +++ b/src/types/v63.ts @@ -1,110 +1,110 @@ export type FarmCertification = FarmCertification_NotCertified | FarmCertification_Gold export interface FarmCertification_NotCertified { - __kind: 'NotCertified' + __kind: 'NotCertified' } export interface FarmCertification_Gold { - __kind: 'Gold' + __kind: 'Gold' } export interface Farm { - version: number - id: number - name: Uint8Array - twinId: number - pricingPolicyId: number - certification: FarmCertification - publicIps: PublicIP[] - dedicatedFarm: boolean - farmingPolicyLimits: (FarmingPolicyLimit | undefined) + version: number + id: number + name: Uint8Array + twinId: number + pricingPolicyId: number + certification: FarmCertification + publicIps: PublicIP[] + dedicatedFarm: boolean + farmingPolicyLimits: (FarmingPolicyLimit | undefined) } export interface FarmingPolicyLimit { - farmingPolicyId: number - cu: (bigint | undefined) - su: (bigint | undefined) - end: (bigint | undefined) - nodeCount: (number | undefined) - nodeCertification: boolean + farmingPolicyId: number + cu: (bigint | undefined) + su: (bigint | undefined) + end: (bigint | undefined) + nodeCount: (number | undefined) + nodeCertification: boolean } export interface FarmingPolicy { - version: number - id: number - name: Uint8Array - cu: number - su: number - nu: number - ipv4: number - minimalUptime: number - policyCreated: number - policyEnd: number - immutable: boolean - default: boolean - nodeCertification: NodeCertification - farmCertification: FarmCertification + version: number + id: number + name: Uint8Array + cu: number + su: number + nu: number + ipv4: number + minimalUptime: number + policyCreated: number + policyEnd: number + immutable: boolean + default: boolean + nodeCertification: NodeCertification + farmCertification: FarmCertification } export type NodeCertification = NodeCertification_Diy | NodeCertification_Certified export interface NodeCertification_Diy { - __kind: 'Diy' + __kind: 'Diy' } export interface NodeCertification_Certified { - __kind: 'Certified' + __kind: 'Certified' } export interface Node { - version: number - id: number - farmId: number - twinId: number - resources: Resources - location: Location - country: Uint8Array - city: Uint8Array - publicConfig: (PublicConfig | undefined) - created: bigint - farmingPolicyId: number - interfaces: Interface[] - certification: NodeCertification - secureBoot: boolean - virtualized: boolean - serialNumber: Uint8Array - dedicated: boolean - connectionPrice: number + version: number + id: number + farmId: number + twinId: number + resources: Resources + location: Location + country: Uint8Array + city: Uint8Array + publicConfig: (PublicConfig | undefined) + created: bigint + farmingPolicyId: number + interfaces: Interface[] + certification: NodeCertification + secureBoot: boolean + virtualized: boolean + serialNumber: Uint8Array + dedicated: boolean + connectionPrice: number } export interface PublicIP { - ip: Uint8Array - gateway: Uint8Array - contractId: bigint + ip: Uint8Array + gateway: Uint8Array + contractId: bigint } export interface Resources { - hru: bigint - sru: bigint - cru: bigint - mru: bigint + hru: bigint + sru: bigint + cru: bigint + mru: bigint } export interface Location { - longitude: Uint8Array - latitude: Uint8Array + longitude: Uint8Array + latitude: Uint8Array } export interface PublicConfig { - ipv4: Uint8Array - ipv6: Uint8Array - gw4: Uint8Array - gw6: Uint8Array - domain: Uint8Array + ipv4: Uint8Array + ipv6: Uint8Array + gw4: Uint8Array + gw6: Uint8Array + domain: Uint8Array } export interface Interface { - name: Uint8Array - mac: Uint8Array - ips: Uint8Array[] + name: Uint8Array + mac: Uint8Array + ips: Uint8Array[] } diff --git a/src/types/v9.ts b/src/types/v9.ts index aa58e81..01759d5 100644 --- a/src/types/v9.ts +++ b/src/types/v9.ts @@ -1,245 +1,245 @@ export interface ContractBill { - contractId: bigint - timestamp: bigint - discountLevel: DiscountLevel - amountBilled: bigint + contractId: bigint + timestamp: bigint + discountLevel: DiscountLevel + amountBilled: bigint } export interface Contract { - version: number - state: ContractState - contractId: bigint - twinId: number - contractType: ContractData + version: number + state: ContractState + contractId: bigint + twinId: number + contractType: ContractData } export interface Entity { - version: number - id: number - name: Uint8Array - accountId: Uint8Array - country: Uint8Array - city: Uint8Array + version: number + id: number + name: Uint8Array + accountId: Uint8Array + country: Uint8Array + city: Uint8Array } export interface Farm { - version: number - id: number - name: Uint8Array - twinId: number - pricingPolicyId: number - certificationType: CertificationType - publicIps: PublicIP[] + version: number + id: number + name: Uint8Array + twinId: number + pricingPolicyId: number + certificationType: CertificationType + publicIps: PublicIP[] } export interface FarmingPolicy { - version: number - id: number - name: Uint8Array - cu: number - su: number - nu: number - ipv4: number - timestamp: bigint - certificationType: CertificationType + version: number + id: number + name: Uint8Array + cu: number + su: number + nu: number + ipv4: number + timestamp: bigint + certificationType: CertificationType } export interface Node { - version: number - id: number - farmId: number - twinId: number - resources: Resources - location: Location - country: Uint8Array - city: Uint8Array - publicConfig: (PublicConfig | undefined) - created: bigint - farmingPolicyId: number - interfaces: Interface[] + version: number + id: number + farmId: number + twinId: number + resources: Resources + location: Location + country: Uint8Array + city: Uint8Array + publicConfig: (PublicConfig | undefined) + created: bigint + farmingPolicyId: number + interfaces: Interface[] } export interface PricingPolicy { - version: number - id: number - name: Uint8Array - su: Policy - cu: Policy - nu: Policy - ipu: Policy - uniqueName: Policy - domainName: Policy - foundationAccount: Uint8Array - certifiedSalesAccount: Uint8Array + version: number + id: number + name: Uint8Array + su: Policy + cu: Policy + nu: Policy + ipu: Policy + uniqueName: Policy + domainName: Policy + foundationAccount: Uint8Array + certifiedSalesAccount: Uint8Array } export interface Twin { - id: number - ip: Uint8Array - version: number - entities: EntityProof[] - accountId: Uint8Array + id: number + ip: Uint8Array + version: number + entities: EntityProof[] + accountId: Uint8Array } export interface BurnTransaction { - block: number - amount: bigint - target: Uint8Array - signatures: StellarSignature[] - sequenceNumber: bigint + block: number + amount: bigint + target: Uint8Array + signatures: StellarSignature[] + sequenceNumber: bigint } export interface MintTransaction { - amount: bigint - target: Uint8Array - block: number - votes: number + amount: bigint + target: Uint8Array + block: number + votes: number } export interface RefundTransaction { - block: number - amount: bigint - target: Uint8Array - txHash: Uint8Array - signatures: StellarSignature[] - sequenceNumber: bigint + block: number + amount: bigint + target: Uint8Array + txHash: Uint8Array + signatures: StellarSignature[] + sequenceNumber: bigint } export type DiscountLevel = DiscountLevel_None | DiscountLevel_Default | DiscountLevel_Bronze | DiscountLevel_Silver | DiscountLevel_Gold export interface DiscountLevel_None { - __kind: 'None' + __kind: 'None' } export interface DiscountLevel_Default { - __kind: 'Default' + __kind: 'Default' } export interface DiscountLevel_Bronze { - __kind: 'Bronze' + __kind: 'Bronze' } export interface DiscountLevel_Silver { - __kind: 'Silver' + __kind: 'Silver' } export interface DiscountLevel_Gold { - __kind: 'Gold' + __kind: 'Gold' } export type ContractState = ContractState_Created | ContractState_Deleted | ContractState_OutOfFunds export interface ContractState_Created { - __kind: 'Created' + __kind: 'Created' } export interface ContractState_Deleted { - __kind: 'Deleted' + __kind: 'Deleted' } export interface ContractState_OutOfFunds { - __kind: 'OutOfFunds' + __kind: 'OutOfFunds' } export type ContractData = ContractData_NodeContract | ContractData_NameContract export interface ContractData_NodeContract { - __kind: 'NodeContract' - value: NodeContract + __kind: 'NodeContract' + value: NodeContract } export interface ContractData_NameContract { - __kind: 'NameContract' - value: NameContract + __kind: 'NameContract' + value: NameContract } export type CertificationType = CertificationType_Diy | CertificationType_Certified export interface CertificationType_Diy { - __kind: 'Diy' + __kind: 'Diy' } export interface CertificationType_Certified { - __kind: 'Certified' + __kind: 'Certified' } export interface PublicIP { - ip: Uint8Array - gateway: Uint8Array - contractId: bigint + ip: Uint8Array + gateway: Uint8Array + contractId: bigint } export interface Resources { - hru: bigint - sru: bigint - cru: bigint - mru: bigint + hru: bigint + sru: bigint + cru: bigint + mru: bigint } export interface Location { - longitude: Uint8Array - latitude: Uint8Array + longitude: Uint8Array + latitude: Uint8Array } export interface PublicConfig { - ipv4: Uint8Array - ipv6: Uint8Array - gw4: Uint8Array - gw6: Uint8Array - domain: Uint8Array + ipv4: Uint8Array + ipv6: Uint8Array + gw4: Uint8Array + gw6: Uint8Array + domain: Uint8Array } export interface Interface { - name: Uint8Array - mac: Uint8Array - ips: Uint8Array[] + name: Uint8Array + mac: Uint8Array + ips: Uint8Array[] } export interface Policy { - value: number - unit: Unit + value: number + unit: Unit } export interface EntityProof { - entityId: number - signature: Uint8Array + entityId: number + signature: Uint8Array } export interface StellarSignature { - signature: Uint8Array - stellarPubkey: Uint8Array + signature: Uint8Array + stellarPubkey: Uint8Array } export interface NodeContract { - nodeId: number - deploymentData: Uint8Array - deploymentHash: Uint8Array - publicIps: number - publicIpsList: PublicIP[] + nodeId: number + deploymentData: Uint8Array + deploymentHash: Uint8Array + publicIps: number + publicIpsList: PublicIP[] } export interface NameContract { - name: Uint8Array + name: Uint8Array } export type Unit = Unit_Bytes | Unit_Kilobytes | Unit_Megabytes | Unit_Gigabytes | Unit_Terrabytes export interface Unit_Bytes { - __kind: 'Bytes' + __kind: 'Bytes' } export interface Unit_Kilobytes { - __kind: 'Kilobytes' + __kind: 'Kilobytes' } export interface Unit_Megabytes { - __kind: 'Megabytes' + __kind: 'Megabytes' } export interface Unit_Gigabytes { - __kind: 'Gigabytes' + __kind: 'Gigabytes' } export interface Unit_Terrabytes { - __kind: 'Terrabytes' + __kind: 'Terrabytes' }