-
Notifications
You must be signed in to change notification settings - Fork 564
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
BREAKING: Transaction Insight API #642
Conversation
Codecov Report
@@ Coverage Diff @@
## main #642 +/- ##
==========================================
+ Coverage 85.75% 85.79% +0.04%
==========================================
Files 108 107 -1
Lines 3165 3197 +32
Branches 612 621 +9
==========================================
+ Hits 2714 2743 +29
- Misses 421 424 +3
Partials 30 30
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this approach makes sense. In addition to inline comments, a couple of things:
- We should consider how we're going to route messages when snaps are able to export objects with methods, like the keyring. We don't need to support that here, but we shouldn't make it more difficult to implement in the future.
- Only tangentially related to this PR, but do we throw an error if a snap exports something we don't recognize? We should create an issue for that if we don't.
Hmm, yeah I'm not entirely sure how we would do that 🤔 - Will think more about it.
We don't, but only the exports with the proper names are registered as available exports in the BaseSnapExecutor (as of this PR). Is there a reason to throw? |
a90587f
to
7ad2f0e
Compare
packages/controllers/src/services/iframe/IframeExecutionService.test.ts
Outdated
Show resolved
Hide resolved
packages/execution-environments/src/common/BaseSnapExecutor.test.ts
Outdated
Show resolved
Hide resolved
4234e36
to
b826e12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
// TODO: Add validation in cases. | ||
/** | ||
* Formats the arguments for the given handler. | ||
* | ||
* @param origin - The origin of the request. | ||
* @param handler - The handler to pass the request to. | ||
* @param request - The request object. | ||
* @returns The formatted arguments. | ||
*/ | ||
function getHandlerArguments( | ||
origin: Origin, | ||
handler: HandlerType, | ||
request: JsonRpcRequest<unknown[] | { [key: string]: unknown }>, | ||
): InvokeSnapArgs { | ||
switch (handler) { | ||
case HandlerType.OnTransaction: { | ||
const { transaction, chainId } = request.params as Record<string, any>; | ||
return { | ||
origin, | ||
transaction, | ||
chainId, | ||
}; | ||
} | ||
|
||
case HandlerType.OnRpcRequest: | ||
return { origin, request }; | ||
|
||
default: | ||
return assertExhaustive(handler); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future reference: Is there any reason not to have validation in these cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by validation? At the snapRpc
level we do a isHandler
check before passing on the handler to getHandlerArguments
.
@hmalik88 note that I removed the We should really just use |
Okay, I'm cool with the change. Can't use template string types for certain things though like the CAIP id. |
Adds support for multiple handlers/exports on the
BaseSnapExecutor
and adds a new export to be used for transaction insight. Also adds an endowment that will work as a flag to detect whether the snap wants to receive transaction insight requests.JS Implementation:
TS Implementation:
This PR is breaking because some exports are renamed and moved around. For example, `@metamask/execution-environments' no longer exports any enums.