Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add beingSpent to mempool #77

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading