Skip to content

Commit

Permalink
fix: timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanVerstraete committed Jan 25, 2023
1 parent 204f032 commit 137b8fd
Show file tree
Hide file tree
Showing 8 changed files with 5,543 additions and 5,444 deletions.
2 changes: 1 addition & 1 deletion indexer/chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: tfchainindexer
description: Helm Chart for the tfchain hydra indexer
version: 2.7.6
apiVersion: v2
appVersion: '2.8.0-rc8'
appVersion: '2.8.0-rc9'
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "graphql_tfgrid",
"private": "true",
"version": "2.8.0-rc8",
"version": "2.8.0-rc9",
"description": "GraphQL server and Substrate indexer. Generated with ♥ by Hydra-CLI",
"author": "",
"license": "ISC",
Expand Down
2 changes: 1 addition & 1 deletion processor-chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v2
name: tfchain-processor
description: A chart for the tfchain graphql processor and query node
version: 1.0.5
appVersion: '2.8.0-rc8'
appVersion: '2.8.0-rc9'
39 changes: 19 additions & 20 deletions src/mappings/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import { Store } from '@subsquid/typeorm-store'
import { Ctx } from '../processor'
import { EventItem } from '@subsquid/substrate-processor/lib/interfaces/dataSelection'

import {
ContractState, PublicIp, NameContract,
NodeContract, ContractBillReport, DiscountLevel,
ContractResources, Node, RentContract, NruConsumption
import {
ContractState, PublicIp, NameContract,
NodeContract, ContractBillReport, DiscountLevel,
ContractResources, Node, RentContract, NruConsumption
} from "../model";
import {
SmartContractModuleContractCreatedEvent, SmartContractModuleContractUpdatedEvent,
SmartContractModuleNodeContractCanceledEvent, SmartContractModuleNameContractCanceledEvent,
SmartContractModuleContractBilledEvent, SmartContractModuleUpdatedUsedResourcesEvent,
SmartContractModuleNruConsumptionReportReceivedEvent, SmartContractModuleRentContractCanceledEvent,
SmartContractModuleContractGracePeriodStartedEvent, SmartContractModuleContractGracePeriodEndedEvent
import {
SmartContractModuleContractCreatedEvent, SmartContractModuleContractUpdatedEvent,
SmartContractModuleNodeContractCanceledEvent, SmartContractModuleNameContractCanceledEvent,
SmartContractModuleContractBilledEvent, SmartContractModuleUpdatedUsedResourcesEvent,
SmartContractModuleNruConsumptionReportReceivedEvent, SmartContractModuleRentContractCanceledEvent,
SmartContractModuleContractGracePeriodStartedEvent, SmartContractModuleContractGracePeriodEndedEvent
} from "../types/events";

export async function contractCreated(
ctx: Ctx,
item: EventItem<'SmartContractModule.ContractCreated', { event: { args: true } }>,
timestamp: number
timestamp: bigint
): Promise<void> {
let contractCreatedEvent = new SmartContractModuleContractCreatedEvent(ctx, item.event)

Expand Down Expand Up @@ -51,7 +51,7 @@ export async function contractCreated(
newNameContract.gridVersion = contractEvent.version
newNameContract.twinID = contractEvent.twinId
newNameContract.state = state
newNameContract.createdAt = BigInt(timestamp)
newNameContract.createdAt = timestamp
if (contractCreatedEvent.isV105) {
contractEvent = contractCreatedEvent.asV105
newNameContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0
Expand All @@ -75,15 +75,15 @@ export async function contractCreated(
} else {
newNodeContract.deploymentData = contract.deploymentData.toString()
}
if (contract.deploymentHash.toString().indexOf('\x00') >= 0) {
if (contract.deploymentHash.toString().indexOf('\x00') >= 0) {
newNodeContract.deploymentHash = ""
} else {
newNodeContract.deploymentHash = contract.deploymentHash.toString()
}

// newNodeContract.deploymentHash = contract.deploymentHash.toString()
newNodeContract.state = state
newNodeContract.createdAt = BigInt(timestamp)
newNodeContract.createdAt = timestamp
if (contractCreatedEvent.isV105) {
contractEvent = contractCreatedEvent.asV105
newNodeContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0
Expand All @@ -93,7 +93,7 @@ export async function contractCreated(
if (ip.ip.toString().indexOf('\x00') >= 0) {
return
}
const savedIp = await ctx.store.get(PublicIp, { where: { ip: ip.ip.toString() } ,relations: { farm: true } })
const savedIp = await ctx.store.get(PublicIp, { where: { ip: ip.ip.toString() }, relations: { farm: true } })

if (savedIp) {
savedIp.contractId = newNodeContract.contractID
Expand All @@ -115,7 +115,7 @@ export async function contractCreated(
newRentContract.twinID = contractEvent.twinId
newRentContract.nodeID = contract.nodeId
newRentContract.state = state
newRentContract.createdAt = BigInt(timestamp)
newRentContract.createdAt = timestamp
if (contractCreatedEvent.isV105) {
contractEvent = contractCreatedEvent.asV105
newRentContract.solutionProviderID = Number(contractEvent.solutionProviderId) || 0
Expand All @@ -127,7 +127,6 @@ export async function contractCreated(
export async function contractUpdated(
ctx: Ctx,
item: EventItem<'SmartContractModule.ContractUpdated', { event: { args: true } }>,
timestamp: number
) {
const contractUpdatedEvent = new SmartContractModuleContractUpdatedEvent(ctx, item.event)

Expand Down Expand Up @@ -173,7 +172,7 @@ async function updateNodeContract(ctr: any, contract: NodeContract, store: Store
} else {
contract.deploymentData = contract.deploymentData.toString()
}
if (contract.deploymentHash.toString().indexOf('\x00') >= 0) {
if (contract.deploymentHash.toString().indexOf('\x00') >= 0) {
contract.deploymentHash = ""
} else {
contract.deploymentHash = contract.deploymentHash.toString()
Expand Down Expand Up @@ -295,7 +294,7 @@ export async function rentContractCanceled(
await ctx.store.save<RentContract>(savedContract)
}

export function collectContractBillReports (ctx: Ctx): ContractBillReport[] {
export function collectContractBillReports(ctx: Ctx): ContractBillReport[] {
let list: ContractBillReport[] = []
for (let block of ctx.blocks) {
for (let item of block.items) {
Expand All @@ -306,7 +305,7 @@ export function collectContractBillReports (ctx: Ctx): ContractBillReport[] {

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

let level = DiscountLevel.None
switch (contractBilledEvent.discountLevel.__kind) {
case 'None': break
Expand Down
10 changes: 5 additions & 5 deletions src/mappings/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Ctx } from '../processor'
export async function nodeStored(
ctx: Ctx,
item: EventItem<'TfgridModule.NodeStored', { event: { args: true } }>,
timestamp: number
timestamp: bigint
) {
const node = new TfgridModuleNodeStoredEvent(ctx, item.event)

Expand Down Expand Up @@ -41,8 +41,8 @@ export async function nodeStored(
newNode.nodeID = nodeEvent.id
newNode.twinID = nodeEvent.twinId

newNode.createdAt = BigInt(timestamp)
newNode.updatedAt = BigInt(timestamp)
newNode.createdAt = timestamp
newNode.updatedAt = timestamp

if (node.isV9) {
nodeEvent = node.asV9
Expand Down Expand Up @@ -147,7 +147,7 @@ export async function nodeStored(
export async function nodeUpdated(
ctx: Ctx,
item: EventItem<'TfgridModule.NodeUpdated', { event: { args: true } }>,
timestamp: number
timestamp: bigint
) {
const node = new TfgridModuleNodeUpdatedEvent(ctx, item.event)

Expand Down Expand Up @@ -178,7 +178,7 @@ export async function nodeUpdated(
savedNode.farmID = nodeEvent.farmId
savedNode.nodeID = nodeEvent.id
savedNode.twinID = nodeEvent.twinId
savedNode.updatedAt = BigInt(timestamp)
savedNode.updatedAt = timestamp
savedNode.farmingPolicyId = nodeEvent.farmingPolicyId

// Recalculate total / free resoures when a node get's updated
Expand Down
4 changes: 2 additions & 2 deletions src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ export type Item = BatchProcessorItem<typeof processor>
export type Ctx = BatchContext<Store, Item>

async function handleEvents(ctx: Ctx, block: SubstrateBlock, item: Item) {
let timestamp = block.timestamp / 1000 // unix seconds
let timestamp = BigInt(block.timestamp) / BigInt(1000) // unix seconds
switch (item.name) {
// Contracts
case 'SmartContractModule.ContractCreated': return contractCreated(ctx, item, timestamp)
case 'SmartContractModule.ContractUpdated': return contractUpdated(ctx, item, timestamp)
case 'SmartContractModule.ContractUpdated': return contractUpdated(ctx, item)
case 'SmartContractModule.NodeContractCanceled': return nodeContractCanceled(ctx, item)
case 'SmartContractModule.NameContractCanceled': return nameContractCanceled(ctx, item)
case 'SmartContractModule.RentContractCanceled': return rentContractCanceled(ctx, item)
Expand Down
Loading

0 comments on commit 137b8fd

Please sign in to comment.