Skip to content

fix: ensure only one from_block field is set in subscribeToTransactionsWithProofs #2537

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

Open
wants to merge 1 commit into
base: v2.0-dev
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function subscribeToTransactionsWithProofsFactory(grpcTransport) {
...options,
};

if (options.fromBlockHeight === 0) {
if ('fromBlockHeight' in options && options.fromBlockHeight === 0) {
throw new DAPIClientError('Invalid argument: minimum value for `fromBlockHeight` is 1');
}
Comment on lines +42 to 44
Copy link
Collaborator Author

@thephez thephez Apr 10, 2025

Choose a reason for hiding this comment

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

If we added something like this, it could prevent confusion and unexpected behavior. I guess that would be a breaking change though.

Suggested change
if ('fromBlockHeight' in options && options.fromBlockHeight === 0) {
throw new DAPIClientError('Invalid argument: minimum value for `fromBlockHeight` is 1');
}
if ('fromBlockHash' in options && 'fromBlockHeight' in options) {
throw new DAPIClientError('Only one of fromBlockHash or fromBlockHeight may be provided');
}
if ('fromBlockHeight' in options && options.fromBlockHeight === 0) {
throw new DAPIClientError('Invalid argument: minimum value for `fromBlockHeight` is 1');
}

Copy link
Member

Choose a reason for hiding this comment

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

0 is default value for integer in protobuf event if this field is omitted.

Copy link
Collaborator Author

@thephez thephez Apr 14, 2025

Choose a reason for hiding this comment

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

I found/fixed an issue in the code I was trying to use dapi-client with. However, dapi-client's handling of these options is still misleading. Someone should only provide either a height or a hash, but it's possible to provide both and it's not very obvious that the height is ignored in that case. Wouldn't it make sense to notify the dev they should only be passing one of the two so they don't waste time debugging expected behavior?


Expand All @@ -59,14 +59,14 @@ function subscribeToTransactionsWithProofsFactory(grpcTransport) {
const request = new TransactionsWithProofsRequest();
request.setBloomFilter(bloomFilterMessage);

if (options.fromBlockHeight !== undefined) {
request.setFromBlockHeight(options.fromBlockHeight);
}

if (options.fromBlockHash) {
if ('fromBlockHash' in options) {
request.setFromBlockHash(
Buffer.from(options.fromBlockHash, 'hex'),
Buffer.isBuffer(options.fromBlockHash)
? options.fromBlockHash
: Buffer.from(options.fromBlockHash, 'hex'),
);
} else if ('fromBlockHeight' in options) {
request.setFromBlockHeight(options.fromBlockHeight);
}

request.setCount(options.count);
Expand Down
Loading