11import db from "src/db" ;
22import logger from "src/utils/logger-handler" ;
33import { EventsProcessed , EventsQuery , } from "src/interfaces/block-chain-service" ;
4- import { DB_BOUNTY_NOT_FOUND , NETWORK_NOT_FOUND } from "../utils/messages.const" ;
4+ import { DB_BOUNTY_ALREADY_CLOSED , DB_BOUNTY_NOT_FOUND , NETWORK_NOT_FOUND } from "../utils/messages.const" ;
55import { updateCuratorProposalParams } from "src/modules/handle-curators" ;
66import { updateLeaderboardBounties , updateLeaderboardNfts , updateLeaderboardProposals } from "src/modules/leaderboard" ;
77import { DecodedLog } from "../interfaces/block-sniffer" ;
@@ -12,6 +12,7 @@ import {updateBountiesHeader} from "src/modules/handle-header-information";
1212import { Push } from "../services/analytics/push" ;
1313import { AnalyticEventName } from "../services/analytics/types/events" ;
1414import updateSeoCardBounty from "src/modules/handle-seo-card" ;
15+ import { savePointEvent } from "../modules/points-system/save-point-event" ;
1516
1617export const name = "getBountyClosedEvents" ;
1718export const schedule = "*/12 * * * *" ;
@@ -44,6 +45,8 @@ export async function action(block: DecodedLog, query?: EventsQuery): Promise<Ev
4445 const eventsProcessed : EventsProcessed = { } ;
4546 const { returnValues : { id, proposalId} , connection, address, chainId} = block ;
4647
48+ const transaction = await connection . eth . getTransaction ( block . transactionHash ) ;
49+
4750 const bounty = await getBountyFromChain ( connection , address , id , name ) ;
4851 if ( ! bounty )
4952 return eventsProcessed ;
@@ -67,6 +70,11 @@ export async function action(block: DecodedLog, query?: EventsQuery): Promise<Ev
6770 return eventsProcessed ;
6871 }
6972
73+ if ( dbBounty . state === "closed" ) {
74+ logger . warn ( DB_BOUNTY_ALREADY_CLOSED ( name , bounty . cid , network . id ) )
75+ return eventsProcessed ;
76+ }
77+
7078 const dbProposal = await db . merge_proposals . findOne ( {
7179 where : {
7280 issueId : dbBounty . id ,
@@ -80,7 +88,12 @@ export async function action(block: DecodedLog, query?: EventsQuery): Promise<Ev
8088 return eventsProcessed ;
8189 }
8290
83- const deliverable = await db . deliverables . findOne ( { where : { id : dbProposal . deliverableId } } ) ;
91+ const deliverable = await db . deliverables . findOne ( {
92+ where : { id : dbProposal . deliverableId } ,
93+ include : [
94+ { association : "user" }
95+ ]
96+ } ) ;
8497 if ( ! deliverable ) {
8598 logger . debug ( `mergeProposal() has no deliverable on database` ) ;
8699 return eventsProcessed ;
@@ -102,7 +115,19 @@ export async function action(block: DecodedLog, query?: EventsQuery): Promise<Ev
102115 updateLeaderboardProposals ( "accepted" ) ;
103116 updateBountiesHeader ( ) ;
104117 updateSeoCardBounty ( dbBounty . id , name ) ;
105-
118+ savePointEvent ( "accepted_proposal" , transaction . from , {
119+ taskId : dbBounty . id ,
120+ proposalId : dbProposal . id ,
121+ merger : transaction . from
122+ } ) ;
123+ savePointEvent ( "created_proposal" , dbProposal . creator ! , {
124+ taskId : dbBounty . id ,
125+ proposalId : dbProposal . id ,
126+ } ) ;
127+ savePointEvent ( "created_deliverable" , deliverable . user . address ! , {
128+ taskId : dbBounty . id ,
129+ deliverableId : deliverable . id ,
130+ } ) ;
106131
107132 eventsProcessed [ network . name ! ] = {
108133 [ dbBounty . id ! . toString ( ) ] : { bounty : dbBounty , eventBlock : parseLogWithContext ( block ) }
0 commit comments