-
Notifications
You must be signed in to change notification settings - Fork 15
Feat/sync specific vtxo #66
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,16 +43,34 @@ where | |
{ | ||
/// Lift all pending VTXOs and boarding outputs into the Ark, converting them into new, | ||
/// confirmed VTXOs. We do this by "joining the next round". | ||
pub async fn board<R>(&self, rng: &mut R) -> Result<(), Error> | ||
pub async fn settle_all<R>(&self, rng: &mut R) -> Result<(), Error> | ||
where | ||
R: Rng + CryptoRng + Clone, | ||
{ | ||
// Get off-chain address and send all funds to this address, no change output 🦄 | ||
let (to_address, _) = self.get_offchain_address()?; | ||
|
||
let (boarding_inputs, vtxo_inputs, total_amount) = | ||
self.fetch_round_transaction_inputs().await?; | ||
|
||
self.settle(rng, boarding_inputs, vtxo_inputs, total_amount) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Lift all pending VTXOs and boarding outputs into the Ark, converting them into new, | ||
/// confirmed VTXOs. We do this by "joining the next round". | ||
Comment on lines
+59
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we should document this function differently. |
||
pub async fn settle<R>( | ||
&self, | ||
rng: &mut R, | ||
boarding_inputs: Vec<round::OnChainInput>, | ||
vtxo_inputs: Vec<round::VtxoInput>, | ||
total_amount: Amount, | ||
) -> Result<(), Error> | ||
where | ||
R: Rng + CryptoRng + Clone, | ||
{ | ||
// Get off-chain address and send all funds to this address, no change output 🦄 | ||
let (to_address, _) = self.get_offchain_address()?; | ||
|
||
tracing::debug!( | ||
offchain_adress = %to_address.encode(), | ||
?boarding_inputs, | ||
|
@@ -153,11 +171,8 @@ where | |
Ok(txid) | ||
} | ||
|
||
/// Get all the [`round::OnChainInput`]s and [`round::VtxoInput`]s that can be used to join an | ||
/// upcoming round. | ||
async fn fetch_round_transaction_inputs( | ||
&self, | ||
) -> Result<(Vec<round::OnChainInput>, Vec<round::VtxoInput>, Amount), Error> { | ||
/// Get all the [`round::OnChainInput`]s that can be used to join an upcoming round. | ||
pub async fn fetch_boarding_inputs(&self) -> Result<(Vec<round::OnChainInput>, Amount), Error> { | ||
// Get all known boarding outputs. | ||
let boarding_outputs = self.inner.wallet.get_boarding_outputs()?; | ||
|
||
|
@@ -194,6 +209,13 @@ where | |
} | ||
} | ||
|
||
Ok((boarding_inputs, total_amount)) | ||
} | ||
|
||
/// Get all [`round::VtxoInput`]s that can be used to join an upcoming round. | ||
pub async fn fetch_pending_vtxos(&self) -> Result<(Vec<round::VtxoInput>, Amount), Error> { | ||
let mut total_amount = Amount::ZERO; | ||
|
||
let spendable_vtxos = self.spendable_vtxos().await?; | ||
|
||
for (vtxo_outpoints, _) in spendable_vtxos.iter() { | ||
|
@@ -218,7 +240,22 @@ where | |
}) | ||
.collect::<Vec<_>>(); | ||
|
||
Ok((boarding_inputs, vtxo_inputs, total_amount)) | ||
Ok((vtxo_inputs, total_amount)) | ||
} | ||
|
||
/// Get all the [`round::OnChainInput`]s and [`round::VtxoInput`]s that can be used to join an | ||
/// upcoming round. | ||
async fn fetch_round_transaction_inputs( | ||
&self, | ||
) -> Result<(Vec<round::OnChainInput>, Vec<round::VtxoInput>, Amount), Error> { | ||
let (boarding_inputs, boarding_input_amount) = self.fetch_boarding_inputs().await?; | ||
let (vtxo_inputs, vtxo_input_amount) = self.fetch_pending_vtxos().await?; | ||
|
||
Ok(( | ||
boarding_inputs, | ||
vtxo_inputs, | ||
boarding_input_amount + vtxo_input_amount, | ||
)) | ||
} | ||
|
||
async fn join_next_ark_round<R>( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we be running doc tests in CI?