Browse Source

Map announced entries

Theophile Sandoz 3 years ago
parent
commit
c8b5854011
2 changed files with 32 additions and 0 deletions
  1. 2 0
      query-node/manifest.yml
  2. 30 0
      query-node/mappings/src/bounty.ts

+ 2 - 0
query-node/manifest.yml

@@ -873,6 +873,8 @@ mappings:
       handler: bounty_BountyCreatorCherryWithdrawal
     - event: bounty.BountyRemoved
       handler: bounty_BountyRemoved
+    - event: bounty.WorkEntryAnnounced
+      handler: bounty_WorkEntryAnnounced
   extrinsicHandlers:
     # infer defaults here
     #- extrinsic: Balances.Transfer

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

@@ -9,6 +9,8 @@ import {
   BountyContribution,
   BountyCreatedEvent,
   BountyCreatorCherryWithdrawalEvent,
+  BountyEntry,
+  BountyEntryStatusWorking,
   BountyFundedEvent,
   BountyFundingLimited,
   BountyFundingPerpetual,
@@ -19,6 +21,7 @@ import {
   BountyVetoedEvent,
   ForumThread,
   Membership,
+  WorkEntryAnnouncedEvent,
 } from 'query-node/dist/model'
 import { Bounty as BountyEvents } from '../generated/types'
 import { deserializeMetadata, genericEventFields } from './common'
@@ -327,3 +330,30 @@ export async function bounty_BountyRemoved({ event, store }: EventContext & Stor
 
   await store.save<BountyRemovedEvent>(removedInEvent)
 }
+
+export async function bounty_WorkEntryAnnounced({ event, store }: EventContext & StoreContext): Promise<void> {
+  const entryAnnouncedEvent = new BountyEvents.WorkEntryAnnouncedEvent(event)
+  const [bountyId, entryId, memberId, accountId] = entryAnnouncedEvent.params
+  const eventTime = new Date(event.blockTimestamp)
+
+  const bounty = new Bounty({ id: String(bountyId) })
+
+  // Create the entry
+  const entry = new BountyEntry({
+    id: String(entryId),
+    createdAt: eventTime,
+    updatedAt: eventTime,
+    bounty,
+    worker: new Membership({ id: String(memberId) }),
+    stakingAccount: String(accountId),
+    workSubmitted: false,
+    status: new BountyEntryStatusWorking(),
+  })
+
+  await store.save<BountyEntry>(entry)
+
+  // Record the event
+  const announcedEvent = new WorkEntryAnnouncedEvent({ ...genericEventFields(event), entry })
+
+  await store.save<WorkEntryAnnouncedEvent>(announcedEvent)
+}