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
feat: watch-only wallet #1045
Conversation
31c32fe
to
25bd085
Compare
25bd085
to
2a9d000
Compare
2a9d000
to
9a94f10
Compare
9a94f10
to
9bd8b0f
Compare
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) |
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.
This is great!
pub fn balance(&self) -> NanoTokens { | ||
self.wallet.balance() | ||
self.watchonly_wallet.balance() | ||
} |
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.
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?
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.
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.
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) | ||
} |
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.
Same here, let's get rid of all that nesting
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.
see comment above, you are missing something
9bd8b0f
to
2d0e5e8
Compare
2d0e5e8
to
0985e88
Compare
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.
LGTM
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 thefiles_cmds
function, theFiles
constructor, and theupload_files
function. Theclient
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 aWatchOnlyWallet
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 theWatchOnlyWallet
struct to thewallet
module. This struct is now available for use in the API.The file
error.rs
has a new variantPubKeyMismatch
added to theError
enum, with a custom error message that includes the path of the wallet.The file
cashnote.rs
has changes related to theCashNote
struct. A new methodderived_pubkey
has been added, and the existing methodderivation_index
now has a specified return type.The file
main.rs
has changes related to the variablesjoins_gossip
andjoins_gossipsub
, as well as the functionfiles_cmds
. These changes indicate updates to the usage of gossipsub and more efficient usage of theclient
object.The file
wallet_file.rs
has changes related to thestore_created_cash_notes
function, which now accepts a generic iterator and returns aResult<()>
instead ofResult<()>
. This allows for more flexibility in accepting different types of iterators.The file
error.rs
has changes related to the addition of theMainPubkeyMismatch
variant to theError
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 theMainPubkey
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 calledwatch_only
and the implementation of aWatchOnlyWallet
struct. It also includes a new method calledbalance
in theKeyLessWallet
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.