Skip to content

Commit

Permalink
add bengSpent to mempool
Browse files Browse the repository at this point in the history
  • Loading branch information
SepehrGanji committed Oct 30, 2023
1 parent b4f24ab commit 7a85644
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/graphql/objects/unconfirmed-box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ export class UnconfirmedBox extends IBox {
assetsResolver() {
return orderBy(this.assets, (asset) => asset.index);
}

@Field(() => Boolean)
beingSpent!: boolean;
}
17 changes: 16 additions & 1 deletion src/graphql/resolvers/mempool-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ type UnconfirmedBox implements IBox {
additionalRegisters: JSONObject!
address: String!
assets: [UnconfirmedAsset!]!
beingSpent: Boolean!
boxId: String!
creationHeight: Int!
ergoTree: String!
Expand Down

0 comments on commit 7a85644

Please sign in to comment.