-
Notifications
You must be signed in to change notification settings - Fork 101
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
[CT-1103] FNS subaccount WS support #2088
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,16 @@ func (ws *WebsocketServer) Handler(w http.ResponseWriter, r *http.Request) { | |
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
// Parse subaccountIds from query parameters | ||
subaccountIds, err := parseSubaccountIds(r) | ||
if err != nil { | ||
ws.logger.Error( | ||
"Error parsing subaccountIds", | ||
"err", err, | ||
) | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
|
||
websocketMessageSender := &WebsocketMessageSender{ | ||
cdc: ws.cdc, | ||
|
@@ -78,8 +88,7 @@ func (ws *WebsocketServer) Handler(w http.ResponseWriter, r *http.Request) { | |
|
||
err = ws.streamingManager.Subscribe( | ||
clobPairIds, | ||
// TODO@(wliu) add subaccount ids | ||
[]*satypes.SubaccountId{}, | ||
subaccountIds, | ||
websocketMessageSender, | ||
) | ||
if err != nil { | ||
|
@@ -91,11 +100,40 @@ func (ws *WebsocketServer) Handler(w http.ResponseWriter, r *http.Request) { | |
} | ||
} | ||
|
||
// parseSubaccountIds is a helper function to parse the subaccountIds from the query parameters. | ||
func parseSubaccountIds(r *http.Request) ([]*satypes.SubaccountId, error) { | ||
subaccountIdsParam := r.URL.Query().Get("subaccountIds") | ||
if subaccountIdsParam == "" { | ||
return nil, nil | ||
} | ||
|
||
idStrs := strings.Split(subaccountIdsParam, ",") | ||
subaccountIds := make([]*satypes.SubaccountId, len(idStrs)) | ||
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. pref zero-initialize to reduce error situations where an empty array initialized with len X has length X and we might check len(subaccounts) to determine success of parsing subaccount ids 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. done |
||
for i, idStr := range idStrs { | ||
parts := strings.Split(idStr, "/") | ||
if len(parts) != 2 { | ||
return nil, fmt.Errorf("invalid subaccountId format: %s, expected subaccount_id format: owner/number", idStr) | ||
} | ||
|
||
number, err := strconv.Atoi(parts[1]) | ||
if err != nil { | ||
return nil, fmt.Errorf("invalid subaccount number: %s, expected subaccount_id format: owner/number", parts[1]) | ||
} | ||
|
||
subaccountIds[i] = &satypes.SubaccountId{ | ||
Owner: parts[0], | ||
Number: uint32(number), | ||
} | ||
} | ||
|
||
return subaccountIds, nil | ||
} | ||
|
||
// parseClobPairIds is a helper function to parse the clobPairIds from the query parameters. | ||
func parseClobPairIds(r *http.Request) ([]uint32, error) { | ||
clobPairIdsParam := r.URL.Query().Get("clobPairIds") | ||
if clobPairIdsParam == "" { | ||
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. think we can remove this special case now that empty clobpair ids is valid, i think rest of code should result in nil, nil as well 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. done |
||
return nil, fmt.Errorf("missing clobPairIds parameter") | ||
return nil, nil | ||
} | ||
|
||
idStrs := strings.Split(clobPairIdsParam, ",") | ||
|
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.
ditto here, i think split on empty string probably returns empty array
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.
done