-
Notifications
You must be signed in to change notification settings - Fork 103
Initial implementation of wallet functionality #33
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
Conversation
5264c2a
to
cca2687
Compare
71c560d
to
a919af3
Compare
Now includes a custom |
7d54c61
to
4fd40d8
Compare
a05b1f0
to
35a25ff
Compare
7d7d108
to
c1c43f2
Compare
pub(crate) fn set_runtime(&self, tokio_runtime: Arc<tokio::runtime::Runtime>) { | ||
*self.tokio_runtime.write().unwrap() = Some(tokio_runtime); | ||
} | ||
|
||
pub(crate) fn drop_runtime(&self) { | ||
*self.tokio_runtime.write().unwrap() = None; | ||
} |
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.
Not sure how well this fits into the larger picture -- but related to #10 (comment) -- another approach to avoid these may be to have any functions needing a runtime take it as a parameter. For sync traits, implement them on something like (Wallet<D>, Arc<tokio::runtime::Runtime>)
if the implementation needs to call those functions.
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.
Unfortunately the latter wouldn't work I think, as we need to give the BroadcasterInterface
/ FeeEstimator
impls to ChannelManager
and ChainMonitor
. However, as we want to make parameters of them and/or Wallet
configurable (e.g., wallet entropy source, Filter
impl) based on chain data source, etc., we'd need to instantiate these in the Builder
, where we do however not have access to a tokio runtime.
src/wallet.rs
Outdated
// We double-check that no inputs try to spend non-witness outputs. As we use a SegWit | ||
// wallet descriptor this technically shouldn't ever happen, but better safe than sorry. |
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.
Where / how is this enforced?
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 guaranteed as we're using a Bip84
descriptor template for the BDK wallet, which happens currently in lib.rs
.
fn get_destination_script(&self) -> Script { | ||
let address = | ||
self.wallet.get_new_address().expect("Failed to retrieve new address from wallet."); | ||
address.script_pubkey() | ||
} |
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.
Wish there were a better way of doing this without needing all the boilerplate to override / delegate. Wonder if we should think about parameterizing KeysManager
in some way to make this simpler.
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.
Yes, I'm not a fan of this solution either, also because we now have an redundant unused key in KeysManager
, which could be used directly by any future code change. I'd be +1 to introducing some upstream changes to let us override that key.
However, last time I spoke to @TheBlueMatt about the matter he thought the current solution would be the cleanest way.
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.
Yea, if we're trying to wrap an inner
there's not much else we can do. If we wanted to drop the boilerplate we could have expose the KeysManager
to the user and have them use that when they need a NodeSigner
/EntropySource
, but that's maybe even worse.
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.
Seems like you could parameterize KeysManager
with a strategy for generating the scripts. Either from keys derived from the seed or from some other wallet. Then you wouldn't wrap at all but rather have Wallet
implement a trait that this new parameter is bounded by.
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.
Are we fine going ahead with the current version, until we decide on some upstream changes and have them implemented?
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.
Yes, that's fine by me.
829eab3
to
876403e
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.
The new commits on top of #10 look good in isolation.
} | ||
} | ||
|
||
pub(crate) fn set_runtime(&self, tokio_runtime: Arc<tokio::runtime::Runtime>) { |
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.
Curious to see how this works once we get everything landed :)
876403e
to
6fe5475
Compare
Uh, rebased. |
fn get_destination_script(&self) -> Script { | ||
let address = | ||
self.wallet.get_new_address().expect("Failed to retrieve new address from wallet."); | ||
address.script_pubkey() | ||
} |
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.
Seems like you could parameterize KeysManager
with a strategy for generating the scripts. Either from keys derived from the seed or from some other wallet. Then you wouldn't wrap at all but rather have Wallet
implement a trait that this new parameter is bounded by.
77ce8ce
to
bf9bcc2
Compare
a11268a
to
4728f13
Compare
Squashed without further changes. |
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 modulo some minor comments.
fn get_destination_script(&self) -> Script { | ||
let address = | ||
self.wallet.get_new_address().expect("Failed to retrieve new address from wallet."); | ||
address.script_pubkey() | ||
} |
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.
Yes, that's fine by me.
This implementation of `KeysInterface` allows to override the shutdown/destination scripts and forwards any other calls to an inner instance of `KeysManager` otherwise.
4728f13
to
97716a4
Compare
Squashed again with the following changes: > git diff-tree -U2 4728f13 97716a4
diff --git a/src/wallet.rs b/src/wallet.rs
index 598d627..dab6cdc 100644
--- a/src/wallet.rs
+++ b/src/wallet.rs
@@ -111,5 +111,10 @@ where
}
Err(e) => {
- log_error!(self.logger, "Failed to update fee rate estimation: {}", e);
+ log_error!(
+ self.logger,
+ "Failed to update fee rate estimation for {:?}: {}",
+ target,
+ e
+ );
}
}
@@ -223,5 +228,5 @@ where
D: BatchDatabase,
{
- /// Constructs a `WalletKeysManager` that
+ /// Constructs a `WalletKeysManager` that overrides the destination and shutdown scripts.
///
/// See [`KeysManager::new`] for more information on `seed`, `starting_time_secs`, and |
This PR implements the initial wallet functionality, which was previously included in
access.rs
.