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/box-resolver.ts b/src/graphql/resolvers/box-resolver.ts index de1992a..c378679 100644 --- a/src/graphql/resolvers/box-resolver.ts +++ b/src/graphql/resolvers/box-resolver.ts @@ -207,21 +207,19 @@ export class BoxResolver { take }); - const resultBoxIds = boxes.map((box) => box.boxId); - - const unconfirmedInputBoxIds = isFieldSelected(info, "beingSpent") - ? await context.repository.unconfirmedInputs.getUnconfirmedInputBoxIds(resultBoxIds) - : []; - - if (!isFieldSelected(info, "beingSpent")) { - return boxes; + if (isFieldSelected(info, "beingSpent") && boxes.length > 0) { + const resultBoxIds = boxes.map((box) => box.boxId); + const unconfirmedInputBoxIds = + await context.repository.unconfirmedInputs.getUnconfirmedInputBoxIds(resultBoxIds); + + return boxes.map((box) => { + return { + ...box, + beingSpent: unconfirmedInputBoxIds.indexOf(box.boxId) > -1 + }; + }); } - return boxes.map((box) => { - return { - ...box, - beingSpent: unconfirmedInputBoxIds.indexOf(box.boxId) > -1 - }; - }); + return boxes; } } diff --git a/src/graphql/resolvers/mempool-resolver.ts b/src/graphql/resolvers/mempool-resolver.ts index 513680a..4781878 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,22 @@ export class MempoolResolver { skip, take }); + + if (isFieldSelected(info, "beingSpent") && boxes.length > 0) { + const resultBoxIds = boxes.map((box) => box.boxId); + const unconfirmedBoxIds = + await context.repository.unconfirmedInputs.getUnconfirmedInputBoxIds(resultBoxIds); + console.log("being"); + + return boxes.map((box) => { + return { + ...box, + beingSpent: unconfirmedBoxIds.indexOf(box.boxId) > -1 + }; + }); + } + + return boxes; } @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!