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

Including optional time for isValid in server #780

Merged
merged 11 commits into from
Nov 23, 2023

Conversation

HughParry
Copy link
Contributor

No description provided.

Copy link

Pull Request Report

Hey there! I've generated a report for your pull request. Let's dive in!

Changes

  1. Added an optional maxVerifiedTime parameter to the isVerified function in server.ts (line 111).
  2. Added a comment to explain the purpose of the payload parameter (line 113).
  3. Added a comment to explain the purpose of the maxVerifiedTime parameter (line 114).

Suggestions

  1. Consider providing a more descriptive return type for the isVerified function (line 114).
  2. Consider adding a comment to explain the expected format of the returns section in the JSDoc (line 114).

Bugs

  1. Potential bug: In the isVerified function, the condition (maxVerifiedTime && blockNumber) should be updated to (maxVerifiedTime !== undefined && blockNumber !== undefined) to handle cases where maxVerifiedTime or blockNumber could be 0 (line 116).

Improvements

  1. The isVerified function could benefit from better variable naming. Consider using more descriptive names for variables like user, dapp, providerUrl, commitmentId, and blockNumber (line 118).
  2. The isVerified function could be refactored to improve readability. Here's a suggested code snippet:
public async isVerified(payload: ProcaptchaOutput, maxVerifiedTime?: number): Promise<boolean> {
    const { user, dapp, providerUrl, commitmentId, blockNumber } = payload;

    if (maxVerifiedTime !== undefined && blockNumber !== undefined) {
        const currentBlockNumber = (await this.getApi().rpc.chain.getBlock()).block.header.number.toNumber();
        const blockLength = this.getApi().consts.babe.expectedBlockTime.toNumber();

        if ((currentBlockNumber - blockNumber) * blockLength > maxVerifiedTime) {
            return false;
        }
    }

    const contractApi = await this.getContractApi();
    const block = (await this.getApi().rpc.chain.getBlockHash(blockNumber)) as BlockHash;
    const getRandomProviderResponse = await this.getContract().queryAtBlock<RandomProvider>(block, contractApi.query.getRandomProvider);

    // Rest of the code...
}

Rating

I would rate the code a 7 out of 10. The code has good readability and the added optional maxVerifiedTime parameter is a useful addition. However, there are a few areas for improvement, such as better variable naming and handling edge cases in the isVerified function.

That's it for the report! Let me know if you need any further assistance. Happy coding!

Copy link
Member

@forgetso forgetso left a comment

Choose a reason for hiding this comment

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

Looks good, could you stick the time stuff in a separate function?

packages/types/src/provider/api.ts Show resolved Hide resolved
packages/provider/src/tasks/tasks.ts Outdated Show resolved Hide resolved
packages/provider/src/tasks/tasks.ts Outdated Show resolved Hide resolved
@forgetso forgetso merged commit a1bca24 into main Nov 23, 2023
6 checks passed
@forgetso forgetso deleted the short-expiry-server-side-option branch November 23, 2023 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants