-
-
Notifications
You must be signed in to change notification settings - Fork 98
Fix isolated margin ntli encoding #150
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
boyi
wants to merge
4
commits into
sonirico:master
Choose a base branch
from
boyi:fix-update-isolated-margin-ntli-int
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,8 +147,8 @@ func (e *Exchange) signAgent( | |
| return SignAgent(e.privateKey, agentAddress, agentName, nonce, mainnet) | ||
| } | ||
|
|
||
| // executeAction executes an action and unmarshals the response into the given result | ||
| func (e *Exchange) executeAction(ctx context.Context, action, result any) error { | ||
| // signAndPost signs an L1 action and posts it, returning the raw response body. | ||
| func (e *Exchange) signAndPost(ctx context.Context, action any) ([]byte, error) { | ||
| nonce := e.nextNonce() | ||
|
|
||
| sig, err := e.signL1Action( | ||
|
|
@@ -159,20 +159,73 @@ func (e *Exchange) executeAction(ctx context.Context, action, result any) error | |
| e.expiresAfter, | ||
| e.client.baseURL == MainnetAPIURL, | ||
| ) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return e.postAction(ctx, action, sig, nonce) | ||
| } | ||
|
|
||
| // executeAction executes an action and unmarshals the response into the given result. | ||
| // The result type is responsible for reporting a rejected action; use | ||
| // executeActionChecked for result types that do not decode the status envelope. | ||
| func (e *Exchange) executeAction(ctx context.Context, action, result any) error { | ||
| resp, err := e.signAndPost(ctx, action) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| resp, err := e.postAction(ctx, action, sig, nonce) | ||
| return json.Unmarshal(resp, result) | ||
| } | ||
|
|
||
| // executeActionChecked is executeAction for result types that ignore the | ||
| // {"status":"err","response":"..."} envelope. Without this check such a | ||
| // response unmarshals into a zero-value result and reports no error. | ||
| func (e *Exchange) executeActionChecked(ctx context.Context, action, result any) error { | ||
| resp, err := e.signAndPost(ctx, action) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := json.Unmarshal(resp, result); err != nil { | ||
| if err := exchangeActionError(resp); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| return json.Unmarshal(resp, result) | ||
| } | ||
|
|
||
| // ExchangeActionError is returned when the exchange rejects an action, | ||
| // as opposed to the request failing to be sent or decoded. | ||
| type ExchangeActionError struct { | ||
| Message string | ||
| } | ||
|
|
||
| func (e *ExchangeActionError) Error() string { | ||
| return e.Message | ||
| } | ||
|
|
||
| // exchangeActionError reports the exchange's rejection of an action, or nil if | ||
| // the response is not a rejection. A body that does not parse as the envelope | ||
| // is left for the caller's json.Unmarshal to reject. | ||
| func exchangeActionError(resp []byte) error { | ||
| var envelope struct { | ||
| Status string `json:"status"` | ||
| Response json.RawMessage `json:"response"` | ||
| } | ||
| if err := json.Unmarshal(resp, &envelope); err != nil { | ||
| return nil | ||
| } | ||
| if envelope.Status != "err" { | ||
| return nil | ||
| } | ||
| var msg string | ||
| if err := json.Unmarshal(envelope.Response, &msg); err == nil && msg != "" { | ||
| return &ExchangeActionError{Message: msg} | ||
| } | ||
| if len(envelope.Response) > 0 { | ||
| return &ExchangeActionError{Message: string(envelope.Response)} | ||
| } | ||
| return &ExchangeActionError{Message: "exchange action failed"} | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not create structs for errors; Instead, let's use error sentinels var (
ErrExchangeAction = errors.New("exchange action failed")
)
// and then in some other place
if len(envelope.Response) > 0 {
return fmt.Errorf("%w, %s", ErrExchangeAction, envelope.Response)
} |
||
| } | ||
|
|
||
| func (e *Exchange) postAction( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
please rename to
parseExchangeActionError