Skip to content

Commit

Permalink
fix: properly toggle grace period on contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanVerstraete committed Aug 31, 2022
1 parent 3c2ef27 commit 0815006
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 44 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.4.0
apiVersion: v2
appVersion: "2.5.10"
appVersion: "2.5.11"
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.5.9",
"version": "2.5.11",
"description": "GraphQL server and Substrate indexer. Generated with ♥ by Hydra-CLI",
"author": "",
"license": "ISC",
Expand Down
2 changes: 1 addition & 1 deletion processor-chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v2
name: tfchain-processor
description: A chart for the tfchain graphql processor and query node
version: 1.0.4
appVersion: "2.5.10"
appVersion: "2.5.11"
77 changes: 38 additions & 39 deletions src/mappings/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,28 +351,27 @@ export async function contractGracePeriodStarted(ctx: EventHandlerContext) {
contractID = contractGracePeriodStartedEvent.asV105.contractId
}

let savedContract
savedContract = await ctx.store.get(NodeContract, { where: { contractID } })

if (!savedContract) {
savedContract = await ctx.store.get(RentContract, { where: { contractID } })
if (!savedContract) {
savedContract = await ctx.store.get(NameContract, { where: { contractID } })
if (!savedContract) return
else {
savedContract.state = ContractState.GracePeriod
await ctx.store.save<NameContract>(savedContract)
}
} else {
savedContract.state = ContractState.GracePeriod
await ctx.store.save<RentContract>(savedContract)
}
} else {
savedContract.state = ContractState.GracePeriod
await ctx.store.save<NodeContract>(savedContract)
const savedNodeContract = await ctx.store.get(NodeContract, { where: { contractID } })
if (savedNodeContract) {
savedNodeContract.state = ContractState.GracePeriod
await ctx.store.save<NodeContract>(savedNodeContract)
return
}

const savedRentContract = await ctx.store.get(RentContract, { where: { contractID } })
if (savedRentContract) {
savedRentContract.state = ContractState.GracePeriod
await ctx.store.save<RentContract>(savedRentContract)
return
}
}

const savedNameContract = await ctx.store.get(NameContract, { where: { contractID } })
if (savedNameContract) {
savedNameContract.state = ContractState.GracePeriod
await ctx.store.save<NameContract>(savedNameContract)
return
}
}

export async function contractGracePeriodEnded(ctx: EventHandlerContext) {
let contractID = BigInt(0)
Expand All @@ -384,24 +383,24 @@ export async function contractGracePeriodEnded(ctx: EventHandlerContext) {
contractID = contractGracePeriodEnded.asV105.contractId
}

let savedContract
savedContract = await ctx.store.get(NodeContract, { where: { contractID } })

if (!savedContract) {
savedContract = await ctx.store.get(RentContract, { where: { contractID } })
if (!savedContract) {
savedContract = await ctx.store.get(NameContract, { where: { contractID } })
if (!savedContract) return
else {
savedContract.state = ContractState.GracePeriod
await ctx.store.save<NameContract>(savedContract)
}
} else {
savedContract.state = ContractState.GracePeriod
await ctx.store.save<RentContract>(savedContract)
}
} else {
savedContract.state = ContractState.GracePeriod
await ctx.store.save<NodeContract>(savedContract)
const savedNodeContract = await ctx.store.get(NodeContract, { where: { contractID } })
if (savedNodeContract) {
savedNodeContract.state = ContractState.Created
await ctx.store.save<NodeContract>(savedNodeContract)
return
}

const savedRentContract = await ctx.store.get(RentContract, { where: { contractID } })
if (savedRentContract) {
savedRentContract.state = ContractState.Created
await ctx.store.save<RentContract>(savedRentContract)
return
}

const savedNameContract = await ctx.store.get(NameContract, { where: { contractID } })
if (savedNameContract) {
savedNameContract.state = ContractState.Created
await ctx.store.save<NameContract>(savedNameContract)
return
}
}

0 comments on commit 0815006

Please sign in to comment.