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

Add endpoint to get managed addresses #556

Merged
merged 4 commits into from
Feb 25, 2022
Merged

Add endpoint to get managed addresses #556

merged 4 commits into from
Feb 25, 2022

Conversation

arun-koshy
Copy link
Contributor

This is the second of a series of PR's that will implement the client service API described as part of the GDC Eng Deliverables

The endpoints that are included in this PR are:

Get Addresses: Retrieve all managed accounts.
curl --location --request GET 'http://localhost:5000/wallet/addresses'

Copy link
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

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

I left a few comments, but I like the size and direction of this!

sui/src/rest_server.rs Outdated Show resolved Hide resolved
sui/src/rest_server.rs Outdated Show resolved Hide resolved
sui/src/rest_server.rs Outdated Show resolved Hide resolved
sui/src/rest_server.rs Outdated Show resolved Hide resolved
rqctx: Arc<RequestContext<ServerContext>>,
) -> Result<HttpResponseOk<GetAddressResponse>, HttpError> {
let server_context = rqctx.context();
let wallet_context = server_context.wallet_context.lock().unwrap().take();
Copy link
Contributor

Choose a reason for hiding this comment

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

The good thing is after this line you now own the contents of wallet_context. The bad thing is you just replaced the original by None, so if you do an early return anywhere before you hit the line where you place the wallet_context back where you found it:

    *server_context.wallet_context.lock().unwrap() = Some(wallet_context);

then any further actions don't have a wallet_context any more!

This doesn't matter for the very next error (conditioned on wallet_context.is_none()), but the two following errors (out of get_or_create_client_state and sync_client_state) are a concern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran into just this issue yesterday in some other endpoints! I have been trying to find a solution where I don't have to add that line to every endpoints early exit scenario (which gets really repetitive in future endpoints). However have yet to find anything outside of take() that doesn't cause the function change we saw earlier.

I will add the line to put wallet context back on an early exit and add a todo to find a better solution for this.

sui/src/rest_server.rs Outdated Show resolved Hide resolved
sui/src/rest_server.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

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

Thanks a bunch!

@arun-koshy
Copy link
Contributor Author

Thanks a bunch!

Thank you for the continued pro rust tips!

@arun-koshy arun-koshy merged commit 3821c3c into main Feb 25, 2022
@arun-koshy arun-koshy deleted the arun/get-addresses branch February 25, 2022 20:58
mwtian pushed a commit that referenced this pull request Sep 12, 2022
mwtian pushed a commit to mwtian/sui that referenced this pull request Sep 29, 2022
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.

2 participants