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: watch-only wallet #1045

Merged
merged 6 commits into from Dec 6, 2023
Merged

Conversation

bochaco
Copy link
Member

@bochaco bochaco commented Dec 4, 2023

Description

Summary generated by Reviewpad on 04 Dec 23 13:39 UTC

This pull request includes the following changes:

  • The file sn_cli/src/subcommands/files/mod.rs has changes related to the files_cmds function, the Files constructor, and the upload_files function. The client parameter of these functions has been changed to a shared reference &Client.

  • A new file watch_only.rs has been added, which includes the implementation of a WatchOnlyWallet struct. This struct represents a watch-only wallet in a SAFE Network and has various methods for loading, storing, and manipulating wallet data.

  • The file lib.rs has changes related to adding the WatchOnlyWallet struct to the wallet module. This struct is now available for use in the API.

  • The file error.rs has a new variant PubKeyMismatch added to the Error enum, with a custom error message that includes the path of the wallet.

  • The file cashnote.rs has changes related to the CashNote struct. A new method derived_pubkey has been added, and the existing method derivation_index now has a specified return type.

  • The file main.rs has changes related to the variables joins_gossip and joins_gossipsub, as well as the function files_cmds. These changes indicate updates to the usage of gossipsub and more efficient usage of the client object.

  • The file wallet_file.rs has changes related to the store_created_cash_notes function, which now accepts a generic iterator and returns a Result<()> instead of Result<()>. This allows for more flexibility in accepting different types of iterators.

  • The file error.rs has changes related to the addition of the MainPubkeyMismatch variant to the Error enum. This variant handles the scenario where the main public key does not match.

  • The file wallet/mod.rs has changes related to the usage of the MainPubkey type and the addition of functions for storing and retrieving the main public key in the wallet directory.

  • The file wallet/mod.rs has changes related to the addition of a new module called watch_only and the implementation of a WatchOnlyWallet struct. It also includes a new method called balance in the KeyLessWallet struct.

Please review these changes to ensure they are correct and do not introduce any bugs or performance issues. Let me know if you need further assistance.

@reviewpad reviewpad bot added the Large Large sized PR label Dec 4, 2023
@bochaco bochaco marked this pull request as ready for review December 5, 2023 14:43
@reviewpad reviewpad bot requested a review from grumbach December 5, 2023 14:43
@bochaco bochaco changed the title Feat watch-only wallet feat: watch-only wallet Dec 5, 2023
@bochaco bochaco removed the request for review from grumbach December 5, 2023 14:46
@reviewpad reviewpad bot requested a review from grumbach December 5, 2023 14:46
@bochaco bochaco removed the request for review from grumbach December 5, 2023 15:10
@reviewpad reviewpad bot requested a review from grumbach December 5, 2023 15:10
@bochaco bochaco removed the request for review from grumbach December 5, 2023 15:11
@reviewpad reviewpad bot requested a review from grumbach December 5, 2023 15:11
Comment on lines -170 to +134
let (key, wallet, unconfirmed_spend_requests) = load_from_path(wallet_dir, main_key)?;
Ok(Self {
key,
wallet,
wallet_dir: wallet_dir.to_path_buf(),
unconfirmed_spend_requests,
})
Self::load_from_path_and_key(wallet_dir, main_key)
Copy link
Member

Choose a reason for hiding this comment

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

This is great!

Comment on lines 155 to 157
pub fn balance(&self) -> NanoTokens {
self.wallet.balance()
self.watchonly_wallet.balance()
}
Copy link
Member

@grumbach grumbach Dec 6, 2023

Choose a reason for hiding this comment

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

Any chance we can short circuit that one?
We have 4 functions named balance they call each other in a deep nested way that makes the code hard to navigate, any chance we can get rid of that LocalWallet middle man and directly call your new wallet?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are missing that the LocalWallet is a different type of wallet, it's like a hot-wallet (eventually we should rename it) which reuses the impl/features of a watch-only wallet. Nevertheless, a refactoring of the LocalWallet is out of the scope here.

Comment on lines 395 to 398
pub fn deposit_and_store_to_disk(&mut self, received_cash_notes: &Vec<CashNote>) -> Result<()> {
if received_cash_notes.is_empty() {
return Ok(());
}

// lock and load from disk to make sure we're up to date and others can't modify the wallet concurrently
let exclusive_access = self.lock()?;
self.reload()?;
trace!("Wallet locked and loaded!");

for cash_note in received_cash_notes {
let id = cash_note.unique_pubkey();

if self.wallet.spent_cash_notes.contains(&id) {
debug!("skipping: cash_note is spent");
continue;
}

if cash_note.derived_key(&self.key).is_err() {
debug!("skipping: cash_note is not our key");
continue;
}

let value = cash_note.value()?;
self.wallet.available_cash_notes.insert(id, value);

self.store_cash_notes_to_disk(vec![cash_note])?;
}

self.store(exclusive_access)?;

Ok(())
self.watchonly_wallet
.deposit_and_store_to_disk(received_cash_notes)
}
Copy link
Member

Choose a reason for hiding this comment

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

Same here, let's get rid of all that nesting

Copy link
Member Author

Choose a reason for hiding this comment

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

see comment above, you are missing something

Copy link
Member

@grumbach grumbach left a comment

Choose a reason for hiding this comment

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

LGTM

@bochaco bochaco added this pull request to the merge queue Dec 6, 2023
Merged via the queue into maidsafe:main with commit 9eb9532 Dec 6, 2023
28 checks passed
@bochaco bochaco deleted the feat-watch-only-wallet branch December 6, 2023 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Large Large sized PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants