-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add calculate_fee and calculate_fee_rate on wallet
- Loading branch information
Showing
10 changed files
with
120 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::bitcoin::OutPoint; | ||
|
||
use bdk::chain::tx_graph::CalculateFeeError as BdkCalculateFeeError; | ||
|
||
use std::fmt; | ||
|
||
#[derive(Debug)] | ||
pub enum CalculateFeeError { | ||
MissingTxOut { out_points: Vec<OutPoint> }, | ||
NegativeFee { fee: i64 }, | ||
} | ||
|
||
impl fmt::Display for CalculateFeeError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
CalculateFeeError::MissingTxOut { out_points } => { | ||
write!(f, "Missing transaction output: {:?}", out_points) | ||
} | ||
CalculateFeeError::NegativeFee { fee } => write!(f, "Negative fee value: {}", fee), | ||
} | ||
} | ||
} | ||
|
||
impl From<BdkCalculateFeeError> for CalculateFeeError { | ||
fn from(error: BdkCalculateFeeError) -> Self { | ||
match error { | ||
BdkCalculateFeeError::MissingTxOut(out_points) => CalculateFeeError::MissingTxOut { | ||
out_points: out_points.iter().map(|op| op.into()).collect(), | ||
}, | ||
BdkCalculateFeeError::NegativeFee(fee) => CalculateFeeError::NegativeFee { fee }, | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for CalculateFeeError {} |
This file contains 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 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 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 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 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 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