소스 검색

Fix `BountyContractClosed.whitelist`

Theophile Sandoz 3 년 전
부모
커밋
d662dd532c
3개의 변경된 파일19개의 추가작업 그리고 27개의 파일을 삭제
  1. 8 11
      query-node/mappings/src/bounty.ts
  2. 7 16
      query-node/schemas/bounty.graphql
  3. 4 0
      query-node/schemas/membership.graphql

+ 8 - 11
query-node/mappings/src/bounty.ts

@@ -1,15 +1,15 @@
 import { DatabaseManager, EventContext, StoreContext, SubstrateEvent } from '@joystream/hydra-common'
 import { BountyMetadata } from '@joystream/metadata-protobuf'
 import { AssuranceContractType, BountyActor, BountyId, EntryId, FundingType } from '@joystream/types/augment'
+import { MemberId } from '@joystream/types/common'
 import { BN } from '@polkadot/util'
 import {
   Bounty,
   BountyCanceledEvent,
-  BountyContractClosed,
-  BountyContractOpen,
   BountyContribution,
   BountyCreatedEvent,
   BountyCreatorCherryWithdrawalEvent,
+  BountyEntrantWhitelist,
   BountyEntry,
   BountyEntryStatusCashedOut,
   BountyEntryStatusPassed,
@@ -215,6 +215,7 @@ export async function bounty_BountyCreated({ event, store }: EventContext & Stor
     creator: bountyActorToMembership(bountyParams.creator),
     oracle: bountyActorToMembership(bountyParams.oracle),
     fundingType: asFundingType(bountyParams.funding_type),
+    entrantWhitelist: asEntrantWhitelist(bountyParams.contract_type),
     workPeriod: asInt32(bountyParams.work_period),
     judgingPeriod: asInt32(bountyParams.judging_period),
 
@@ -244,15 +245,11 @@ export async function bounty_BountyCreated({ event, store }: EventContext & Stor
     }
   }
 
-  function asContractType(assuranceContract: AssuranceContractType) {
-    if (assuranceContract.isOpen) {
-      return new BountyContractOpen()
-    } else {
-      const closedContract = new BountyContractClosed()
-      closedContract.whitelist = [...assuranceContract.asClosed.values()].map(
-        (id) => new Membership({ id: String(id) })
-      )
-      return closedContract
+  function asEntrantWhitelist(assuranceContract: AssuranceContractType) {
+    if (assuranceContract.isClosed) {
+      const toMembership = (id: MemberId) => new Membership({ id: String(id) })
+      const members = [...assuranceContract.asClosed.values()].map(toMembership)
+      return new BountyEntrantWhitelist({ members })
     }
   }
 }

+ 7 - 16
query-node/schemas/bounty.graphql

@@ -1,20 +1,11 @@
-"Any member can submit work entries to the bounty"
-type BountyContractOpen @variant {
-  # no properties
-
-  # TODO: remove me - variant needs to have at least 1 property now
-  dummy: Int
-}
+type BountyEntrantWhitelist @entity {
+  # Prevents "GraphQLError: Input Object type BountyEntrantWhitelistCreateInput must define one or more fields."
+  _phantom: Int
 
-"Only preselected members can submit work entries to the bounty"
-type BountyContractClosed @variant {
-  # Members authorized to submit entries to the bounty
-  whitelist: [Membership!]!
+  "Members authorized to submit entries to the bounty"
+  members: [Membership!]!
 }
 
-"Valid of type assurance contract"
-union BountyContractType = BountyContractOpen | BountyContractClosed
-
 type BountyFundingPerpetual @variant {
   "Desired funding"
   target: BigInt!
@@ -74,8 +65,8 @@ type Bounty @entity {
   "Bounty funding type"
   fundingType: BountyFundingType!
 
-  "Bounty assurance contract type"
-  contractType: BountyContractType!
+  "If specified only members listed in BountyEntrantWhitelist are allowed to submit work to the bounty"
+  entrantWhitelist: BountyEntrantWhitelist
 
   "Number of blocks from end of funding period until people can no longer submit bounty submissions"
   workPeriod: Int!

+ 4 - 0
query-node/schemas/membership.graphql

@@ -93,6 +93,10 @@ type Membership @entity {
   "List of proposal thread whitelists the member is part of"
   whitelistedIn: [ProposalDiscussionWhitelist!] @derivedFrom(field: "members")
 
+  # Required for BountyEntrantWhitelist->members Many-to-Many relationship
+  "List of bounty entrant whitelists the member is part of"
+  whitelistedInBounties: [BountyEntrantWhitelist!] @derivedFrom(field: "members")
+
   "Content channels the member owns"
   channels: [Channel!] @derivedFrom(field: "ownerMember")