diff --git a/src/graphql/objects/unconfirmed-box.ts b/src/graphql/objects/unconfirmed-box.ts index a015913..28585bd 100644 --- a/src/graphql/objects/unconfirmed-box.ts +++ b/src/graphql/objects/unconfirmed-box.ts @@ -14,4 +14,7 @@ export class UnconfirmedBox extends IBox { assetsResolver() { return orderBy(this.assets, (asset) => asset.index); } + + @Field(() => Boolean) + beingSpent!: boolean; } diff --git a/src/graphql/resolvers/mempool-resolver.ts b/src/graphql/resolvers/mempool-resolver.ts index 513680a..7be494c 100644 --- a/src/graphql/resolvers/mempool-resolver.ts +++ b/src/graphql/resolvers/mempool-resolver.ts @@ -151,7 +151,7 @@ export class MempoolResolver { @Ctx() context: GraphQLContext, @Info() info: GraphQLResolveInfo ) { - return context.repository.unconfirmedBoxes.find({ + const boxes = await context.repository.unconfirmedBoxes.find({ resolverInfo: info, where: removeUndefined({ boxId, transactionId, address, ergoTree, ergoTreeTemplateHash }), boxIds, @@ -161,6 +161,21 @@ export class MempoolResolver { skip, take }); + const resultBoxIds = boxes.map((box) => box.boxId); + const isBeingSpentSelected = isFieldSelected(info, "beingSpent"); + const unconfirmedBoxIds = isBeingSpentSelected ? + await context.repository.unconfirmedInputs.getUnconfirmedInputBoxIds(resultBoxIds) : []; + + if(!isBeingSpentSelected) { + return boxes; + } + + return boxes.map((box) => { + return { + ...box, + beingSpent: unconfirmedBoxIds.indexOf(box.boxId) > -1 + }; + }); } @FieldResolver() diff --git a/src/graphql/schema.graphql b/src/graphql/schema.graphql index a645623..dc403cc 100644 --- a/src/graphql/schema.graphql +++ b/src/graphql/schema.graphql @@ -333,6 +333,7 @@ type UnconfirmedBox implements IBox { additionalRegisters: JSONObject! address: String! assets: [UnconfirmedAsset!]! + beingSpent: Boolean! boxId: String! creationHeight: Int! ergoTree: String!