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(wallets): add get_wallet_names rpc #2202

Merged
merged 11 commits into from
Sep 25, 2024
Merged

feat(wallets): add get_wallet_names rpc #2202

merged 11 commits into from
Sep 25, 2024

Conversation

shamardy
Copy link
Collaborator

@shamardy shamardy commented Aug 28, 2024

This PR introduces the get_wallet_names RPC method, which allows clients to retrieve information about all wallet names and the currently active one.

  • get_wallet_names Method: Retrieves all wallet names and the active wallet's name if there is an active one. If there is no active wallet (no-login mode), it returns null for the active wallet's name.

Example Request and Responses:

Request:

{
    "userpass": "{{userpass}}",
    "mmrpc": "2.0",
    "method": "get_wallet_names"
}

No-Login Mode Response:

{
    "mmrpc": "2.0",
    "result": {
        "wallet_names": ["Test 1", "Test 2"],
        "activated_wallet": null
    },
    "id": null
}

Activated Wallet Response:

{
    "mmrpc": "2.0",
    "result": {
        "wallet_names": ["Test 1", "Test 2"],
        "activated_wallet": "Test 1"
    },
    "id": null
}

To Test: @KomodoPlatform/qa
Example request and responses are above, I already tested this and @CharlVS probably did too, so it's not a high priority.

@shamardy shamardy added the in progress Changes will be made from the author label Aug 28, 2024
@shamardy shamardy added under review and removed in progress Changes will be made from the author labels Aug 28, 2024
@shamardy shamardy requested review from laruh and CharlVS August 28, 2024 03:25
Copy link
Member

@laruh laruh left a comment

Choose a reason for hiding this comment

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

I have question

Comment on lines +540 to +542
let activated_wallet = ctx.wallet_name.ok_or(GetWalletsError::Internal(
"`wallet_name` not initialized yet!".to_string(),
))?;
Copy link
Member

Choose a reason for hiding this comment

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

could you explain please, how you get Ok result in non-login mode with null activated_wallet, if you return Err when wallet_name None?

No-Login Mode Response from pr info

{
    "mmrpc": "2.0",
    "result": {
        "wallet_names": ["Test 1", "Test 2"],
        "activated_wallet": null
    },
    "id": null
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok_or is for Constructible not Option

/// Wallet name for this mm2 instance. Optional for backwards compatibility.
pub wallet_name: Constructible<Option<String>>,

Copy link
Member

Choose a reason for hiding this comment

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

Ah, exactly

Copy link
Member

Choose a reason for hiding this comment

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

I just ran into the same issue :) Maybe we should make it more explicit with some helpful comments?

(Unresolving the topic to make it visible - feel free to re-resolve the topic once you see it)

Copy link
Collaborator Author

@shamardy shamardy Sep 19, 2024

Choose a reason for hiding this comment

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

Added comment here 704305d

CharlVS
CharlVS previously approved these changes Aug 30, 2024
Copy link
Member

@CharlVS CharlVS left a comment

Choose a reason for hiding this comment

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

Thanks. I've implemented it into the KDF Flutter SDK and confirmed it's working and fits the GUI's needs.

The only point I want to make you aware of, @shamardy, is that I have to do a workaround where I spin up and a non-auth instance so that I can query the list of wallets and then stop, and (attempt to) restart it when user tries to sign in.

Long-term, it would be ideal if we can change auth states using RPCs while KDF is already running.

image

The SDK example app above provides basic wallet functionality with 0 GUI storage for authentication or seed generation. I will share a demo site link.

@shamardy
Copy link
Collaborator Author

shamardy commented Aug 30, 2024

The only point I want to make you aware of, @shamardy, is that I have to do a workaround where I spin up and a non-auth instance so that I can query the list of wallets and then stop

I thought we already do that in komodo wallet GUI (web). AFAIK, web GUI starts in no-login mode so that any user can see orderbooks, etc..

@CharlVS
Copy link
Member

CharlVS commented Aug 30, 2024

The only point I want to make you aware of, @shamardy, is that I have to do a workaround where I spin up and a non-auth instance so that I can query the list of wallets and then stop

I thought we already do that in komodo wallet GUI (web). AFAIK, web GUI starts in no-login mode so that any user can see orderbooks, etc..

We're starting fresh for the Frontend SDK. There's a lot of things that aren't ideal with the current GUI project KDF integration. One pain point in particular for the above is it's unreliable/messy to sift through the logs to parse for exceptions we need to throw in the GUI. At least with an RPC, we will know the result as soon as it's determined, and a response payload would be easier and more reliable for parsing in the UI.

This isn't urgent or something that has to be addressed now since the latered SDK architecture means it can be addressed without major refactoring in the future.

Copy link
Member

@laruh laruh left a comment

Choose a reason for hiding this comment

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

All is good, just one question/suggestion and one note

mm2src/mm2_io/src/fs.rs Outdated Show resolved Hide resolved
mm2src/mm2_io/src/fs.rs Outdated Show resolved Hide resolved
laruh
laruh previously approved these changes Sep 17, 2024
Copy link
Member

@laruh laruh left a comment

Choose a reason for hiding this comment

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

LGTM!

@onur-ozkan
Copy link
Member

get_wallet_names Method: Retrieves all wallet names and the active wallet's name if there is an active one. If there is no active wallet (no-login mode), it returns null for the active wallet's name.

What happens when we connect to an external wallet?

Copy link
Member

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

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

Any chance for adding test coverage for this implementation?

mm2src/mm2_io/src/fs.rs Outdated Show resolved Hide resolved
mm2src/mm2_io/src/fs.rs Outdated Show resolved Hide resolved
Comment on lines +540 to +542
let activated_wallet = ctx.wallet_name.ok_or(GetWalletsError::Internal(
"`wallet_name` not initialized yet!".to_string(),
))?;
Copy link
Member

Choose a reason for hiding this comment

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

I just ran into the same issue :) Maybe we should make it more explicit with some helpful comments?

(Unresolving the topic to make it visible - feel free to re-resolve the topic once you see it)

mariocynicys
mariocynicys previously approved these changes Sep 18, 2024
Copy link
Collaborator

@mariocynicys mariocynicys left a comment

Choose a reason for hiding this comment

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

Only some nits, LGTM otherwise!

mm2src/mm2_main/src/lp_wallet/mnemonics_storage.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_wallet/mnemonics_wasm_db.rs Outdated Show resolved Hide resolved
@shamardy
Copy link
Collaborator Author

shamardy commented Sep 19, 2024

What happens when we connect to an external wallet?

@onur-ozkan External wallet connection is done through coins activation as these wallets are coin dependant. This PR is for wallet names related to KDF mnemonic or passphrase that we init KDF with.

I guess we can add an option in another PR to start mm2 using an external wallet and delay crypto ctx initialization until it's needed for certain coins. It will be a big refactor but will make komodo wallet as a Dapp (e.g. Keplr integration) much smoother and will lead to better UX.

Edit: Opened issue for this #2225

@shamardy
Copy link
Collaborator Author

Any chance for adding test coverage for this implementation?

Sure, will try to add some tests.

@shamardy shamardy dismissed stale reviews from mariocynicys and laruh via 704305d September 19, 2024 01:24
@shamardy
Copy link
Collaborator Author

Any chance for adding test coverage for this implementation?

Tests added here 1a7c003

Copy link
Member

@borngraced borngraced left a comment

Choose a reason for hiding this comment

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

Great work... just small notes

mm2src/mm2_io/src/fs.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_wallet/mnemonics_storage.rs Outdated Show resolved Hide resolved
mm2src/mm2_io/src/fs.rs Outdated Show resolved Hide resolved
borngraced
borngraced previously approved these changes Sep 24, 2024
Copy link
Member

@borngraced borngraced left a comment

Choose a reason for hiding this comment

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

Welldone!

onur-ozkan
onur-ozkan previously approved these changes Sep 25, 2024
Copy link
Member

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

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

Just minor notes. LGTM

mm2src/mm2_core/src/lib.rs Show resolved Hide resolved
@shamardy shamardy dismissed stale reviews from onur-ozkan and borngraced via 4e46c35 September 25, 2024 12:37
@shamardy shamardy merged commit ab23c11 into dev Sep 25, 2024
28 of 29 checks passed
@shamardy shamardy deleted the feat-get-wallet-rpc branch September 25, 2024 17:05
dimxy added a commit that referenced this pull request Oct 4, 2024
* dev:
  fix(orders): fix cancel order race condition using time-based cache (#2232)
  fix(legacy-swap): taker failed spend maker payment marked as failed (#2199)
  chore(adex-cli): deprecate adex-cli (#2234)
  feat(new-RPC): connection healthcheck implementation for peers  (#2194)
  fix(proxy-signature): add message lifetime overflows (#2233)
  feat(CI): handle remote files in a safer way (#2217)
  chore(doc): update issue address in README (#2227)
  fix(merge): remove duplicated db_root function (#2229)
  feat(wallets): add `get_wallet_names` rpc (#2202)
  chore(tests): don't use `.wait()` and use `block_on` instead (#2220)
  fix(native-rpc): remove escaped response body (#2219)
  fix(clippy): fix coins mod clippy warnings in wasm (#2224)
  feat(core): handling CTRL-C signal with graceful shutdown (#2213)
  docs(README): fix typos (#2212)
  remove the non-sense arguments (#2216)
  fix(db): stop creating the all-zeroes dir on KDF start (#2218)
dimxy added a commit that referenced this pull request Oct 4, 2024
* dev:
  fix(orders): fix cancel order race condition using time-based cache (#2232)
  fix(legacy-swap): taker failed spend maker payment marked as failed (#2199)
  chore(adex-cli): deprecate adex-cli (#2234)
  feat(new-RPC): connection healthcheck implementation for peers  (#2194)
  fix(proxy-signature): add message lifetime overflows (#2233)
  feat(CI): handle remote files in a safer way (#2217)
  chore(doc): update issue address in README (#2227)
  fix(merge): remove duplicated db_root function (#2229)
  feat(wallets): add `get_wallet_names` rpc (#2202)
  chore(tests): don't use `.wait()` and use `block_on` instead (#2220)
  fix(native-rpc): remove escaped response body (#2219)
  fix(clippy): fix coins mod clippy warnings in wasm (#2224)
  feat(core): handling CTRL-C signal with graceful shutdown (#2213)
  docs(README): fix typos (#2212)
  remove the non-sense arguments (#2216)
  fix(db): stop creating the all-zeroes dir on KDF start (#2218)
dimxy added a commit that referenced this pull request Oct 17, 2024
* dev:
  fix(cosmos): fix tx broadcasting error (#2238)
  chore(solana): remove solana implementation (#2239)
  chore(cli): remove leftover subcommands from help message (#2235)
  fix(orders): fix cancel order race condition using time-based cache (#2232)
  fix(legacy-swap): taker failed spend maker payment marked as failed (#2199)
  chore(adex-cli): deprecate adex-cli (#2234)
  feat(new-RPC): connection healthcheck implementation for peers  (#2194)
  fix(proxy-signature): add message lifetime overflows (#2233)
  feat(CI): handle remote files in a safer way (#2217)
  chore(doc): update issue address in README (#2227)
  fix(merge): remove duplicated db_root function (#2229)
  feat(wallets): add `get_wallet_names` rpc (#2202)
  chore(tests): don't use `.wait()` and use `block_on` instead (#2220)
  fix(native-rpc): remove escaped response body (#2219)
  fix(clippy): fix coins mod clippy warnings in wasm (#2224)
  feat(core): handling CTRL-C signal with graceful shutdown (#2213)
  docs(README): fix typos (#2212)
  remove the non-sense arguments (#2216)
  fix(db): stop creating the all-zeroes dir on KDF start (#2218)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants