Skip to content

Commit

Permalink
placate clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph committed Nov 28, 2022
1 parent 53e458e commit b9fe6a1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
8 changes: 6 additions & 2 deletions src/subcommand/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fn list_unspent(options: &Options, index: &Index) -> Result<Vec<(OutPoint, Vec<(
.collect()
}

#[allow(dead_code)]
fn list_utxos(options: &Options) -> Result<BTreeMap<OutPoint, Amount>> {
let client = options.bitcoin_rpc_client()?;

Expand All @@ -39,13 +40,16 @@ fn list_utxos(options: &Options) -> Result<BTreeMap<OutPoint, Amount>> {
)
}

fn ordinal_to_satpoint(ordinal: Ordinal, utxos: BTreeMap<OutPoint, Vec<(u64, u64)>>) -> Option<SatPoint> {
fn ordinal_to_satpoint(
ordinal: Ordinal,
utxos: BTreeMap<OutPoint, Vec<(u64, u64)>>,
) -> Option<SatPoint> {
for (outpoint, ranges) in utxos {
let mut offset = 0;
for (start, end) in ranges {
if ordinal.0 >= start && ordinal.0 < end {
return Some(SatPoint {
outpoint: outpoint.clone(),
outpoint,
offset: offset + (ordinal.0 - start),
});
}
Expand Down
33 changes: 18 additions & 15 deletions src/subcommand/wallet/transaction_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use {

#[derive(Debug, PartialEq)]
pub(crate) enum Error {
NotInWallet(Ordinal),
// NotInWallet(Ordinal),
NotEnoughCardinalUtxos,
RareOrdinalLostToRecipient(Ordinal),
RareOrdinalLostToFee(Ordinal),
Expand All @@ -43,7 +43,7 @@ pub(crate) enum Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::NotInWallet(ordinal) => write!(f, "ordinal {ordinal} not in wallet"),
// Error::NotInWallet(ordinal) => write!(f, "ordinal {ordinal} not in wallet"),
Error::NotEnoughCardinalUtxos => write!(
f,
"wallet does not contain enough cardinal UTXOs, please add additional funds to wallet."
Expand Down Expand Up @@ -119,19 +119,19 @@ impl TransactionBuilder {
}

fn select_ordinal(mut self) -> Result<Self> {
// let (ordinal_outpoint, ranges) = self
// .ranges
// .iter()
// .find(|(_outpoint, ranges)| {
// ranges
// .iter()
// .any(|(start, end)| self.ordinal.0 < *end && self.ordinal.0 >= *start)
// })
// .map(|(outpoint, ranges)| (*outpoint, ranges.clone()))
// .ok_or(Error::NotInWallet(self.ordinal))?;
// let (ordinal_outpoint, ranges) = self
// .ranges
// .iter()
// .find(|(_outpoint, ranges)| {
// ranges
// .iter()
// .any(|(start, end)| self.ordinal.0 < *end && self.ordinal.0 >= *start)
// })
// .map(|(outpoint, ranges)| (*outpoint, ranges.clone()))
// .ok_or(Error::NotInWallet(self.ordinal))?;

self.utxos.remove(&self.satpoint.outpoint);
self.inputs.push(self.satpoint.outpoint.clone());
self.inputs.push(self.satpoint.outpoint);
self.outputs.push((
self.recipient.clone(),
Amount::from_sat(
Expand Down Expand Up @@ -531,7 +531,10 @@ mod tests {
use {super::Error, super::*};

fn satpoint(n: u64, offset: u64) -> SatPoint {
SatPoint{ outpoint: outpoint(n), offset }
SatPoint {
outpoint: outpoint(n),
offset,
}
}

#[test]
Expand Down Expand Up @@ -669,7 +672,7 @@ mod tests {
)
}

#[test]
#[test]
fn insufficient_padding_to_add_postage_no_utxos() {
let utxos = vec![(outpoint(1), vec![(10_000, 15_000)])];

Expand Down

0 comments on commit b9fe6a1

Please sign in to comment.