Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 3 additions & 8 deletions packages/api/src/graphql/modules/MempoolResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export class MempoolResolver extends GraphqlModule {
return decoded.hash().toString();
}

// TODO Add retrieval of pending messages somewhere as well
@Query(() => InclusionStatus, {
description: "Returns the state of a given transaction",
})
Expand All @@ -146,13 +147,6 @@ export class MempoolResolver extends GraphqlModule {
})
hash: string
): Promise<InclusionStatus> {
const txs = await this.mempool.getTxs();
const tx = txs.find((x) => x.hash().toString() === hash);

if (tx) {
return InclusionStatus.PENDING;
}

const dbTx = await this.transactionStorage.findTransaction(hash);

if (dbTx !== undefined) {
Expand All @@ -162,6 +156,7 @@ export class MempoolResolver extends GraphqlModule {
if (dbTx.block !== undefined) {
return InclusionStatus.INCLUDED;
}
return InclusionStatus.PENDING;
}

return InclusionStatus.UNKNOWN;
Expand All @@ -172,7 +167,7 @@ export class MempoolResolver extends GraphqlModule {
"Returns the hashes of all transactions that are currently inside the mempool",
})
public async transactions() {
const txs = await this.mempool.getTxs();
const txs = await this.transactionStorage.getPendingUserTransactions();
return txs.map((x) => x.hash().toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ export class InMemoryTransactionStorage implements TransactionStorage {
}
| undefined
> {
const pending = await this.getPendingUserTransactions();
const pendingResult = pending.find((tx) => tx.hash().toString() === hash);
if (pendingResult !== undefined) {
return {
transaction: pendingResult,
};
}

const tipHeight = await this.blockStorage.getCurrentBlockHeight();
const hashField = Field(hash);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ export interface TransactionStorage {

getPendingUserTransactions: () => Promise<PendingTransaction[]>;

/**
* Finds a transaction by its hash.
* It returns both pending transaction and already included transactions
* In case the transaction has been included, it also returns the block hash
* and batch number where applicable.
* @param hash
*/
findTransaction: (hash: string) => Promise<
| {
transaction: PendingTransaction;
Expand Down
Loading