Browse Source

Map `BountyCanceledEvent` and `BountyVetoedEvent`

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

+ 4 - 0
query-node/manifest.yml

@@ -859,6 +859,10 @@ mappings:
     # Bounty
     - event: bounty.BountyCreated
       handler: bounty_BountyCreated
+    - event: bounty.BountyCanceled
+      handler: bounty_BountyCanceled
+    - event: bounty.BountyVetoed
+      handler: bounty_BountyVetoed
   extrinsicHandlers:
     # infer defaults here
     #- extrinsic: Balances.Transfer

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

@@ -3,12 +3,14 @@ import { BountyMetadata } from '@joystream/metadata-protobuf'
 import { AssuranceContractType, BountyActor, FundingType } from '@joystream/types/augment'
 import {
   Bounty,
+  BountyCanceledEvent,
   BountyContractClosed,
   BountyContractOpen,
   BountyCreatedEvent,
   BountyFundingLimited,
   BountyFundingPerpetual,
   BountyStage,
+  BountyVetoedEvent,
   ForumThread,
   Membership,
 } from 'query-node/dist/model'
@@ -106,6 +108,7 @@ function endWorkingPeriod(store: DatabaseManager, bounty: Bounty): Promise<void>
  * Event handlers
  */
 
+// Store new bounties and their creation event
 export async function bounty_BountyCreated({ event, store }: EventContext & StoreContext): Promise<void> {
   const createdEvent = new BountyEvents.BountyCreatedEvent(event)
   const [bountyId, bountyParams, metadataBytes] = createdEvent.params
@@ -171,3 +174,25 @@ export async function bounty_BountyCreated({ event, store }: EventContext & Stor
     }
   }
 }
+
+// Store bounty canceled events
+export async function bounty_BountyCanceled({ event, store }: EventContext & StoreContext): Promise<void> {
+  const bountyCanceledEvent = new BountyEvents.BountyCanceledEvent(event)
+  const [bountyId] = bountyCanceledEvent.params
+
+  const bounty = new Bounty({ id: String(bountyId) })
+  const canceledEvent = new BountyCanceledEvent({ ...genericEventFields(event), bounty })
+
+  await store.save<BountyCanceledEvent>(canceledEvent)
+}
+
+// Store bounty vetoed events
+export async function bounty_BountyVetoed({ event, store }: EventContext & StoreContext): Promise<void> {
+  const bountyVetoedEvent = new BountyEvents.BountyVetoedEvent(event)
+  const [bountyId] = bountyVetoedEvent.params
+  const bounty = new Bounty({ id: String(bountyId) })
+  const vetoedEvent = new BountyVetoedEvent({ ...genericEventFields(event), bounty })
+
+  await store.save<BountyVetoedEvent>(vetoedEvent)
+}
+