|
@@ -1,6 +1,13 @@
|
|
import { DatabaseManager, EventContext, StoreContext, SubstrateEvent } from '@joystream/hydra-common'
|
|
import { DatabaseManager, EventContext, StoreContext, SubstrateEvent } from '@joystream/hydra-common'
|
|
import { BountyMetadata, BountyWorkData } from '@joystream/metadata-protobuf'
|
|
import { BountyMetadata, BountyWorkData } from '@joystream/metadata-protobuf'
|
|
-import { AssuranceContractType, BountyActor, BountyId, EntryId, FundingType } from '@joystream/types/augment'
|
|
|
|
|
|
+import {
|
|
|
|
+ AssuranceContractType,
|
|
|
|
+ BountyActor,
|
|
|
|
+ BountyId,
|
|
|
|
+ EntryId,
|
|
|
|
+ FundingType,
|
|
|
|
+ OracleWorkEntryJudgment,
|
|
|
|
+} from '@joystream/types/augment'
|
|
import { MemberId } from '@joystream/types/common'
|
|
import { MemberId } from '@joystream/types/common'
|
|
import { BN } from '@polkadot/util'
|
|
import { BN } from '@polkadot/util'
|
|
import {
|
|
import {
|
|
@@ -153,11 +160,11 @@ export const bountyScheduleWorkSubmissionEnd = scheduleBountyStageEnd(BountyStag
|
|
'entries',
|
|
'entries',
|
|
])
|
|
])
|
|
|
|
|
|
-export const bountyScheduleJudgmentEnd = scheduleBountyStageEnd(BountyStage.Judgment, async (store, bounty) => {
|
|
|
|
- bounty.updatedAt = new Date()
|
|
|
|
- bounty.stage = BountyStage.Failed
|
|
|
|
- await store.save<Bounty>(bounty)
|
|
|
|
-})
|
|
|
|
|
|
+export const bountyScheduleJudgmentEnd = scheduleBountyStageEnd(
|
|
|
|
+ BountyStage.Judgment,
|
|
|
|
+ (store, bounty) => endJudgmentPeriod(store, bounty, []),
|
|
|
|
+ ['entries']
|
|
|
|
+)
|
|
|
|
|
|
function endFundingPeriod(
|
|
function endFundingPeriod(
|
|
store: DatabaseManager,
|
|
store: DatabaseManager,
|
|
@@ -187,6 +194,38 @@ function endWorkingPeriod(store: DatabaseManager, bounty: Bounty, blockNumber: n
|
|
return store.save<Bounty>(bounty)
|
|
return store.save<Bounty>(bounty)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+type JudgmentEntries = [EntryId, OracleWorkEntryJudgment][]
|
|
|
|
+async function endJudgmentPeriod(
|
|
|
|
+ store: DatabaseManager,
|
|
|
|
+ bounty: Bounty,
|
|
|
|
+ entryJudgments: JudgmentEntries
|
|
|
|
+): Promise<void> {
|
|
|
|
+ // Update the bounty status
|
|
|
|
+ const hasWinners = entryJudgments.some(([, judgment]) => judgment.isWinner)
|
|
|
|
+ bounty.updatedAt = new Date()
|
|
|
|
+ bounty.stage = BountyStage[hasWinners ? 'Successful' : 'Failed']
|
|
|
|
+ await store.save<Bounty>(bounty)
|
|
|
|
+
|
|
|
|
+ // Update winner entries status
|
|
|
|
+ await Promise.all(
|
|
|
|
+ bounty.entries?.map((entry) => {
|
|
|
|
+ const judgment = entryJudgments.find(([entryId]) => String(entryId) === entry.id)?.[1]
|
|
|
|
+
|
|
|
|
+ if (!judgment) {
|
|
|
|
+ entry.status = new BountyEntryStatusPassed()
|
|
|
|
+ } else if (judgment?.isWinner) {
|
|
|
|
+ const status = new BountyEntryStatusWinner()
|
|
|
|
+ status.reward = asBN(judgment.asWinner.reward)
|
|
|
|
+ entry.status = status
|
|
|
|
+ } else {
|
|
|
|
+ entry.status = new BountyEntryStatusRejected()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return store.save<BountyEntry>(entry)
|
|
|
|
+ }) ?? []
|
|
|
|
+ )
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Event handlers
|
|
* Event handlers
|
|
*/
|
|
*/
|
|
@@ -448,32 +487,11 @@ export async function bounty_OracleJudgmentSubmitted({ event, store }: EventCont
|
|
const judgmentSubmittedEvent = new BountyEvents.OracleJudgmentSubmittedEvent(event)
|
|
const judgmentSubmittedEvent = new BountyEvents.OracleJudgmentSubmittedEvent(event)
|
|
const [bountyId, , bountyJudgment, rationale] = judgmentSubmittedEvent.params
|
|
const [bountyId, , bountyJudgment, rationale] = judgmentSubmittedEvent.params
|
|
|
|
|
|
|
|
+ const bounty = await getBounty(store, bountyId, ['entries'])
|
|
const entryJudgments = Array.from(bountyJudgment.entries())
|
|
const entryJudgments = Array.from(bountyJudgment.entries())
|
|
|
|
|
|
- // Update the bounty status
|
|
|
|
- const hasWinners = entryJudgments.some(([, judgment]) => judgment.isWinner)
|
|
|
|
- const bounty = await updateBounty(store, event, bountyId, ['entries'], () => ({
|
|
|
|
- stage: BountyStage[hasWinners ? 'Successful' : 'Failed'],
|
|
|
|
- }))
|
|
|
|
-
|
|
|
|
- // Update winner entries status
|
|
|
|
- await Promise.all(
|
|
|
|
- bounty.entries?.map((entry) => {
|
|
|
|
- const judgment = entryJudgments.find(([entryId]) => String(entryId) === entry.id)?.[1]
|
|
|
|
-
|
|
|
|
- if (!judgment) {
|
|
|
|
- entry.status = new BountyEntryStatusPassed()
|
|
|
|
- } else if (judgment?.isWinner) {
|
|
|
|
- const status = new BountyEntryStatusWinner()
|
|
|
|
- status.reward = asBN(judgment.asWinner.reward)
|
|
|
|
- entry.status = status
|
|
|
|
- } else {
|
|
|
|
- entry.status = new BountyEntryStatusRejected()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return store.save<BountyEntry>(entry)
|
|
|
|
- }) ?? []
|
|
|
|
- )
|
|
|
|
|
|
+ // Update the bounty status and winner entries status
|
|
|
|
+ endJudgmentPeriod(store, bounty, entryJudgments)
|
|
|
|
|
|
// Record the event
|
|
// Record the event
|
|
const judgmentEvent = new OracleJudgmentSubmittedEvent({
|
|
const judgmentEvent = new OracleJudgmentSubmittedEvent({
|