Browse Source

Terminate the bounty when it is removed

Theophile Sandoz 3 years ago
parent
commit
fb0c6cd1d1
2 changed files with 27 additions and 4 deletions
  1. 2 0
      query-node/manifest.yml
  2. 25 4
      query-node/mappings/src/bounty.ts

+ 2 - 0
query-node/manifest.yml

@@ -871,6 +871,8 @@ mappings:
       handler: bounty_BountyFundingWithdrawal
     - event: bounty.BountyCreatorCherryWithdrawal
       handler: bounty_BountyCreatorCherryWithdrawal
+    - event: bounty.BountyRemoved
+      handler: bounty_BountyRemoved
   extrinsicHandlers:
     # infer defaults here
     #- extrinsic: Balances.Transfer

+ 25 - 4
query-node/mappings/src/bounty.ts

@@ -14,6 +14,7 @@ import {
   BountyFundingPerpetual,
   BountyFundingWithdrawalEvent,
   BountyMaxFundingReachedEvent,
+  BountyRemovedEvent,
   BountyStage,
   BountyVetoedEvent,
   ForumThread,
@@ -281,9 +282,9 @@ export async function bounty_BountyFundingWithdrawal({ event, store }: EventCont
   await store.save<Bounty>(bounty)
 
   // Record the event
-  const withdrawalInEvent = new BountyFundingWithdrawalEvent({ ...genericEventFields(event), contribution })
+  const withdrawnInEvent = new BountyFundingWithdrawalEvent({ ...genericEventFields(event), contribution })
 
-  await store.save<BountyFundingWithdrawalEvent>(withdrawalInEvent)
+  await store.save<BountyFundingWithdrawalEvent>(withdrawnInEvent)
 }
 
 export async function bounty_BountyCreatorCherryWithdrawal({
@@ -302,7 +303,27 @@ export async function bounty_BountyCreatorCherryWithdrawal({
   await store.save<Bounty>(bounty)
 
   // Record the event
-  const withdrawalInEvent = new BountyCreatorCherryWithdrawalEvent({ ...genericEventFields(event), bounty })
+  const withdrawnInEvent = new BountyCreatorCherryWithdrawalEvent({ ...genericEventFields(event), bounty })
 
-  await store.save<BountyCreatorCherryWithdrawalEvent>(withdrawalInEvent)
+  await store.save<BountyCreatorCherryWithdrawalEvent>(withdrawnInEvent)
+}
+
+export async function bounty_BountyRemoved({ event, store }: EventContext & StoreContext): Promise<void> {
+  const bountyRemovedEvent = new BountyEvents.BountyRemovedEvent(event)
+  const [bountyId] = bountyRemovedEvent.params
+  const eventTime = new Date(event.blockTimestamp)
+
+  const bounty = await getBounty(store, bountyId)
+
+  // Terminate the bounty
+  bounty.updatedAt = eventTime
+  bounty.deletedAt = eventTime
+  bounty.stage = BountyStage.Terminated
+
+  await store.save<Bounty>(bounty)
+
+  // Record the event
+  const removedInEvent = new BountyRemovedEvent({ ...genericEventFields(event), bounty })
+
+  await store.save<BountyRemovedEvent>(removedInEvent)
 }