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: tvf #5630

Merged
merged 5 commits into from
Feb 11, 2025
Merged

feat: tvf #5630

merged 5 commits into from
Feb 11, 2025

Conversation

ganchoradkov
Copy link
Member

Description

Implemented automatic parsing and adding of TVF params to relay message payloads on both peer sides. These params are assigned on a few selected rpc methods as per specs

Type of change

  • Chore (non-breaking change that addresses non-functional tasks, maintenance, or code quality improvements)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Draft PR (breaking/non-breaking change which needs more work for having a proper functionality [Mark this PR as ready to review only when completely ready])
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How has this been tested?

tests

Checklist

  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Additional Information (Optional)

Please include any additional information that may be useful for the reviewer.

@arein arein added the accepted label Feb 3, 2025
Copy link
Contributor

@Cali93 Cali93 left a comment

Choose a reason for hiding this comment

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

LGTM, feel free to merge when all comments are resolved, specially the one for more test cases for the unhappy path.

packages/sign-client/src/controllers/engine.ts Outdated Show resolved Hide resolved
try {
record = await this.client.core.history.get(topic, id);
const request = record.request;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we validate/parse the request to avoid having to cast the method to JsonRpcTypes.WcMethod?

Copy link
Member Author

Choose a reason for hiding this comment

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

request.methodtype is string so i'm casting it to predefined set of protocol methods to be more intuitive of the values. I can try to refactor the type JsonRpcRecord that history returns but it might cause unexpected breaking changes in the types

Comment on lines 2982 to 2989
if (!params) return false;
if (protocolMethod !== "wc_sessionRequest") return false;
const { request, chainId } = params;
const namespace = parseChainId(chainId).namespace;
if (!(namespace in TVF_METHODS)) return false;
const tvfMethods = TVF_METHODS[namespace as keyof typeof TVF_METHODS];
if (!tvfMethods) return false;
return tvfMethods.includes(request.method);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it'd make sense to introduce a validation library with clear schemas for handling validation ?

Copy link
Member Author

Choose a reason for hiding this comment

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

the parsing is simplified now so probably overkill to export it into its own library. if we expand the handling at later point, why not

Comment on lines +3009 to +3012
} catch (e) {
this.client.logger.warn("Error getting TVF params", e);
}
return {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why you're adopting this pattern of returning outside of the catch ?

Copy link
Member Author

Choose a reason for hiding this comment

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

seems easier to read whats going on in the fx

@@ -493,6 +493,91 @@ describe("Sign Client Integration", () => {
await throttle(1_000);
await deleteClients(clients);
});

it("can set tvf params", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that the only test case we need ? What about checking validation errors etc ?

Copy link
Member Author

Choose a reason for hiding this comment

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

added extra validations for the different namespaces and result structures. Validation errors are tested with the other tests where different methods/values are used and don't assign tvf

@ganchoradkov ganchoradkov merged commit 153d6aa into v2.0 Feb 11, 2025
8 checks passed
@ganchoradkov ganchoradkov deleted the feat/tvf branch February 11, 2025 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants