Skip to content

Commit

Permalink
Merge pull request #77 from nautls/add-beingspent
Browse files Browse the repository at this point in the history
add beingSpent to mempool
  • Loading branch information
arobsn authored Oct 30, 2023
2 parents b4f24ab + d3c7edc commit 036c129
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
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;
}
26 changes: 12 additions & 14 deletions src/graphql/resolvers/box-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
18 changes: 17 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,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()
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 036c129

Please sign in to comment.