-
Notifications
You must be signed in to change notification settings - Fork 135
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
Refactor - Split WalletCommAdapter into multiple traits #180
Refactor - Split WalletCommAdapter into multiple traits #180
Conversation
03a9a57
to
f52a8d2
Compare
Did a bit of investigation on this and it looks like this feature warrants a new WalletCommAdapter. WalletCommAdapter currently exposes a [https://deterministic.space/elegant-apis-in-rust.html#dont-stringly-type-your-api](stringly typed api) where the 'addr' argument is a string that represents a different type depending the Implementer. I'm going to start by refactoring WalletCommAdapter, and refactoring implementors of WalletCommAdaptor to hold their address as struct fields. Not only will this make server authentication implementable, it will also be more strongly typed and will enable future efforts such as an i2p comm adaptor. |
This reverts commit f52a8d2.
WalletCommAdapter declares a listen method, but listen() is not implementable for all implementers of WalletCommAdapter. For example, it doesn't make sense for the FileWalletCommAdapter to listen(). Splitting the WalletCommAdapter trait in twain, or a similar solution, is next on my list after the task mentioned in the previous comment. |
Yes, that trait definitely needs a re-think. Slightly related, I'm going to propose that we make the grinbox spec a published open standard, and provide support for it in the default wallet. If you're able to look into that and have a think about it as part of all this work, I think it will be very valuable to help reduce the friction for the vast majority of transaction cases. |
Definitely agree. From what I can tell, grinbox comms can be implemented as another WalletCommAdapter. I'll keep grinbox support as an explicit end goal of these refactors. |
…ntors, visiting havok on automated tests, at least one of which is now out of date and failing
1. args, a stringly typed argument to put_tx 2. NullAdapter, which is no longer used
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.
Reviewing this myself. Read over the review for explanations of the changes.
@@ -116,12 +113,6 @@ pub struct ListenArgs { | |||
} | |||
|
|||
pub fn listen(config: &WalletConfig, args: &ListenArgs, g_args: &GlobalArgs) -> Result<(), Error> { | |||
let mut params = HashMap::new(); |
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 object was only serving to hold variables local to the function. The http adapter has no listen implementation, and the keybase adapter never uses it's "params" argument.
"file" => FileWalletCommAdapter::new(), | ||
"keybase" => KeybaseWalletCommAdapter::new(), | ||
"self" => NullWalletCommAdapter::new(), | ||
_ => NullWalletCommAdapter::new(), |
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.
After the changes in the pr, this general case (when method is not http, file, keybase, or self) now results in an error. Apart from that, previous behavior is preserved.
api.tx_lock_outputs(&slate, 0)?; | ||
if args.method == "self" { | ||
|
||
match args.method.as_str() { |
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.
With WalletCommAdapter split into several different traits, it makes sense to handle a different "methods" explicitly. Hopefully the new match statement is easier to read as well.
Reviewer, please read over this new match statement to double check that it is desired behavior.
@@ -346,8 +332,7 @@ pub fn receive( | |||
g_args: &GlobalArgs, | |||
args: ReceiveArgs, | |||
) -> Result<(), Error> { | |||
let adapter = FileWalletCommAdapter::new(); | |||
let mut slate = adapter.receive_tx_async(&args.input)?; | |||
let mut slate = PathToSlate((&args.input).into()).get_tx()?; |
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.
(&args.input).into()
creates a PathBuf from a String without taking ownership of said String.
// Send a slate to a keybase username then wait for a response for TTL seconds. | ||
fn send_tx_sync(&self, addr: &str, slate: &Slate) -> Result<Slate, Error> { | ||
// Limit only one recipient | ||
if addr.matches(",").count() > 0 { |
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.
Check moved to constructor.
/// Start a listener, passing received messages to the wallet api directly | ||
/// Takes a wallet config for now to avoid needing all sorts of awkward | ||
/// type parameters on this trait | ||
fn listen( | ||
&self, | ||
params: HashMap<String, String>, |
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.
Params was a) loosely typed, and b) unused.
} | ||
|
||
/// select a SlateSender based on method and dest fields from, e.g., SendArgs | ||
pub fn create_sender(method: &str, dest: &str) -> Result<Box<dyn SlateSender>, Error> { |
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.
If this method does not work in the context of I2P or public key based server authentication, it won't be much trouble to simply delete it. It's only used in two places.
@@ -1,59 +0,0 @@ | |||
// Copyright 2018 The Grin Developers |
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.
A null adapter is no longer needed and is never used.
@@ -344,55 +343,6 @@ impl LocalWalletClient { | |||
} | |||
} | |||
|
|||
impl WalletCommAdapter for LocalWalletClient { |
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 implementation was never used.
So far none of these changes have nothing to do with Public Key based server authentication. Instead the changes so far are general improvements paving the way for new comm adapters. I'm going to rename this pr, limiting scope to the refactor only. |
Requesting merge. Key changes:
New traits:
Implementation matrix:
|
All looks really good, thanks for doing this refactor and yes, the previous trait didn't make a lot of sense, this is much more coherent. I'm going to merge this into the |
* version bump for next potential release * Merge master into milestone/2.1.0 (#182) * Derive --version output dynamically from cargo package version (#174) * add --txid to the `wallet txs` command (#176) * add --txid to the `wallet txs` command * add test for `wallet txs` command with `--txid` parameter * Refactor - Split WalletCommAdapter into multiple traits (#180) * Derive --version output dynamically from cargo package version (#174) * add server auth argument to http client * Revert "add server auth argument to http client" This reverts commit f52a8d2. * modify WalletCommAdapter, moving dest argument into fields on implementors, visiting havok on automated tests, at least one of which is now out of date and failing * Split WalletCommAdapter into four traits, one for each of its intended behaviors. * Remove two vestigals 1. args, a stringly typed argument to put_tx 2. NullAdapter, which is no longer used * Remove unused "params" argument from listen method. * Re-add previously existing TODO comment * Fix non-test build * completely Fix non-test build * Full Lifecycle API Support (#184) * refactoring wallet lib traits * rustfmt * rustfmt * add new files * explicit lifetime specifiers on all wallet traits * rustfmt * modify apis to use new walletinst * rustfmt * converting controller crate * rustfmt * controller crate compiling * rustfmt * compilation * rustfmt * Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl * rustfmt * full compilation, changing recovery + init to new model * rustfmt * wallet initialisation working, init command output and flow identical to v2.0.0 wallet * rustfmt * fix listener and owner api startup * rustfmt * rustfmt * move encryption test * rustfmt * fix api doctests * rustfmt * fix for most tests in controller crate * rustfmt * fix for check tests in controller crate * fix main wallet tests * rustfmt * add explicit functions to handle mnemonic recovery, fix CLI recovery workflow * rustfmt * update keybase adapter to use new wallet format * rustfmt * test fix * remove debug output
* version bump for next potential release * Merge master into milestone/2.1.0 (mimblewimble#182) * Derive --version output dynamically from cargo package version (mimblewimble#174) * add --txid to the `wallet txs` command (mimblewimble#176) * add --txid to the `wallet txs` command * add test for `wallet txs` command with `--txid` parameter * Refactor - Split WalletCommAdapter into multiple traits (mimblewimble#180) * Derive --version output dynamically from cargo package version (mimblewimble#174) * add server auth argument to http client * Revert "add server auth argument to http client" This reverts commit f52a8d2. * modify WalletCommAdapter, moving dest argument into fields on implementors, visiting havok on automated tests, at least one of which is now out of date and failing * Split WalletCommAdapter into four traits, one for each of its intended behaviors. * Remove two vestigals 1. args, a stringly typed argument to put_tx 2. NullAdapter, which is no longer used * Remove unused "params" argument from listen method. * Re-add previously existing TODO comment * Fix non-test build * completely Fix non-test build * Full Lifecycle API Support (mimblewimble#184) * refactoring wallet lib traits * rustfmt * rustfmt * add new files * explicit lifetime specifiers on all wallet traits * rustfmt * modify apis to use new walletinst * rustfmt * converting controller crate * rustfmt * controller crate compiling * rustfmt * compilation * rustfmt * Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl * rustfmt * full compilation, changing recovery + init to new model * rustfmt * wallet initialisation working, init command output and flow identical to v2.0.0 wallet * rustfmt * fix listener and owner api startup * rustfmt * rustfmt * move encryption test * rustfmt * fix api doctests * rustfmt * fix for most tests in controller crate * rustfmt * fix for check tests in controller crate * fix main wallet tests * rustfmt * add explicit functions to handle mnemonic recovery, fix CLI recovery workflow * rustfmt * update keybase adapter to use new wallet format * rustfmt * test fix * remove debug output
* version bump for next potential release * Merge master into milestone/2.1.0 (mimblewimble#182) * Derive --version output dynamically from cargo package version (mimblewimble#174) * add --txid to the `wallet txs` command (mimblewimble#176) * add --txid to the `wallet txs` command * add test for `wallet txs` command with `--txid` parameter * Refactor - Split WalletCommAdapter into multiple traits (mimblewimble#180) * Derive --version output dynamically from cargo package version (mimblewimble#174) * add server auth argument to http client * Revert "add server auth argument to http client" This reverts commit f52a8d2. * modify WalletCommAdapter, moving dest argument into fields on implementors, visiting havok on automated tests, at least one of which is now out of date and failing * Split WalletCommAdapter into four traits, one for each of its intended behaviors. * Remove two vestigals 1. args, a stringly typed argument to put_tx 2. NullAdapter, which is no longer used * Remove unused "params" argument from listen method. * Re-add previously existing TODO comment * Fix non-test build * completely Fix non-test build * Full Lifecycle API Support (mimblewimble#184) * refactoring wallet lib traits * rustfmt * rustfmt * add new files * explicit lifetime specifiers on all wallet traits * rustfmt * modify apis to use new walletinst * rustfmt * converting controller crate * rustfmt * controller crate compiling * rustfmt * compilation * rustfmt * Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl * rustfmt * full compilation, changing recovery + init to new model * rustfmt * wallet initialisation working, init command output and flow identical to v2.0.0 wallet * rustfmt * fix listener and owner api startup * rustfmt * rustfmt * move encryption test * rustfmt * fix api doctests * rustfmt * fix for most tests in controller crate * rustfmt * fix for check tests in controller crate * fix main wallet tests * rustfmt * add explicit functions to handle mnemonic recovery, fix CLI recovery workflow * rustfmt * update keybase adapter to use new wallet format * rustfmt * test fix * remove debug output
This is WIP, consider it experimental for now.
Edit: Ready for merge