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

feat(connection.ts): implement getTransactions #23633

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions web3.js/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3304,6 +3304,34 @@ export class Connection {
return res;
}

/**
* Fetch transaction details for a batch of confirmed transactions.
* Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
*/
async getTransactions(
signatures: TransactionSignature[],
commitment?: Finality,
): Promise<(TransactionResponse | null)[]> {
const batch = signatures.map(signature => {
const args = this._buildArgsAtLeastConfirmed([signature], commitment);
return {
methodName: 'getTransaction',
args,
};
});

const unsafeRes = await this._rpcBatchRequest(batch);
const res = unsafeRes.map((unsafeRes: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow, the type of res here is any, despite TypeScript knowing the type of res.result.

image

Fixed in #26099.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is because both variables are named the same, and one shadows the other.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If true, we should definitely install the no-shadow linter. https://eslint.org/docs/rules/no-shadow

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured out why this happened. We had insufficient type coverage here, so you missed this error. #26102

const res = create(unsafeRes, GetTransactionRpcResult);
if ('error' in res) {
throw new Error('failed to get transactions: ' + res.error.message);
}
return res.result;
});

return res;
}

/**
* Fetch a list of Transactions and transaction statuses from the cluster
* for a confirmed block.
Expand Down