s/UTXO/LocalUtxo/g

Since this struct has a "keychain" it is not a general "UTXO" but a
local wallet UTXO.
This commit is contained in:
LLFourn 2021-02-04 12:09:53 +11:00
parent 4ad0f54c30
commit a7183f34ef
No known key found for this signature in database
GPG Key ID: A27093B54DA11F65
10 changed files with 68 additions and 68 deletions

View File

@ -83,7 +83,7 @@ mod sync;
use super::{Blockchain, Capability, ConfigurableBlockchain, Progress}; use super::{Blockchain, Capability, ConfigurableBlockchain, Progress};
use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils}; use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils};
use crate::error::Error; use crate::error::Error;
use crate::types::{KeychainKind, TransactionDetails, UTXO}; use crate::types::{KeychainKind, LocalUtxo, TransactionDetails};
use crate::FeeRate; use crate::FeeRate;
use peer::*; use peer::*;
@ -194,7 +194,7 @@ impl CompactFiltersBlockchain {
database.get_path_from_script_pubkey(&output.script_pubkey)? database.get_path_from_script_pubkey(&output.script_pubkey)?
{ {
debug!("{} output #{} is mine, adding utxo", tx.txid(), i); debug!("{} output #{} is mine, adding utxo", tx.txid(), i);
updates.set_utxo(&UTXO { updates.set_utxo(&LocalUtxo {
outpoint: OutPoint::new(tx.txid(), i as u32), outpoint: OutPoint::new(tx.txid(), i as u32),
txout: output.clone(), txout: output.clone(),
keychain, keychain,

View File

@ -34,7 +34,7 @@ use bitcoin::{BlockHeader, OutPoint, Script, Transaction, Txid};
use super::*; use super::*;
use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils}; use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils};
use crate::error::Error; use crate::error::Error;
use crate::types::{KeychainKind, TransactionDetails, UTXO}; use crate::types::{KeychainKind, LocalUtxo, TransactionDetails};
use crate::wallet::time::Instant; use crate::wallet::time::Instant;
use crate::wallet::utils::ChunksIterator; use crate::wallet::utils::ChunksIterator;
@ -353,7 +353,7 @@ fn save_transaction_details_and_utxos<D: BatchDatabase>(
// this output is ours, we have a path to derive it // this output is ours, we have a path to derive it
if let Some((keychain, _child)) = db.get_path_from_script_pubkey(&output.script_pubkey)? { if let Some((keychain, _child)) = db.get_path_from_script_pubkey(&output.script_pubkey)? {
debug!("{} output #{} is mine, adding utxo", txid, i); debug!("{} output #{} is mine, adding utxo", txid, i);
updates.set_utxo(&UTXO { updates.set_utxo(&LocalUtxo {
outpoint: OutPoint::new(tx.txid(), i as u32), outpoint: OutPoint::new(tx.txid(), i as u32),
txout: output.clone(), txout: output.clone(),
keychain, keychain,

View File

@ -133,7 +133,7 @@ impl BatchOperations for AnyDatabase {
child child
) )
} }
fn set_utxo(&mut self, utxo: &UTXO) -> Result<(), Error> { fn set_utxo(&mut self, utxo: &LocalUtxo) -> Result<(), Error> {
impl_inner_method!(AnyDatabase, self, set_utxo, utxo) impl_inner_method!(AnyDatabase, self, set_utxo, utxo)
} }
fn set_raw_tx(&mut self, transaction: &Transaction) -> Result<(), Error> { fn set_raw_tx(&mut self, transaction: &Transaction) -> Result<(), Error> {
@ -165,7 +165,7 @@ impl BatchOperations for AnyDatabase {
) -> Result<Option<(KeychainKind, u32)>, Error> { ) -> Result<Option<(KeychainKind, u32)>, Error> {
impl_inner_method!(AnyDatabase, self, del_path_from_script_pubkey, script) impl_inner_method!(AnyDatabase, self, del_path_from_script_pubkey, script)
} }
fn del_utxo(&mut self, outpoint: &OutPoint) -> Result<Option<UTXO>, Error> { fn del_utxo(&mut self, outpoint: &OutPoint) -> Result<Option<LocalUtxo>, Error> {
impl_inner_method!(AnyDatabase, self, del_utxo, outpoint) impl_inner_method!(AnyDatabase, self, del_utxo, outpoint)
} }
fn del_raw_tx(&mut self, txid: &Txid) -> Result<Option<Transaction>, Error> { fn del_raw_tx(&mut self, txid: &Txid) -> Result<Option<Transaction>, Error> {
@ -201,7 +201,7 @@ impl Database for AnyDatabase {
fn iter_script_pubkeys(&self, keychain: Option<KeychainKind>) -> Result<Vec<Script>, Error> { fn iter_script_pubkeys(&self, keychain: Option<KeychainKind>) -> Result<Vec<Script>, Error> {
impl_inner_method!(AnyDatabase, self, iter_script_pubkeys, keychain) impl_inner_method!(AnyDatabase, self, iter_script_pubkeys, keychain)
} }
fn iter_utxos(&self) -> Result<Vec<UTXO>, Error> { fn iter_utxos(&self) -> Result<Vec<LocalUtxo>, Error> {
impl_inner_method!(AnyDatabase, self, iter_utxos) impl_inner_method!(AnyDatabase, self, iter_utxos)
} }
fn iter_raw_txs(&self) -> Result<Vec<Transaction>, Error> { fn iter_raw_txs(&self) -> Result<Vec<Transaction>, Error> {
@ -230,7 +230,7 @@ impl Database for AnyDatabase {
) -> Result<Option<(KeychainKind, u32)>, Error> { ) -> Result<Option<(KeychainKind, u32)>, Error> {
impl_inner_method!(AnyDatabase, self, get_path_from_script_pubkey, script) impl_inner_method!(AnyDatabase, self, get_path_from_script_pubkey, script)
} }
fn get_utxo(&self, outpoint: &OutPoint) -> Result<Option<UTXO>, Error> { fn get_utxo(&self, outpoint: &OutPoint) -> Result<Option<LocalUtxo>, Error> {
impl_inner_method!(AnyDatabase, self, get_utxo, outpoint) impl_inner_method!(AnyDatabase, self, get_utxo, outpoint)
} }
fn get_raw_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error> { fn get_raw_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error> {
@ -257,7 +257,7 @@ impl BatchOperations for AnyBatch {
) -> Result<(), Error> { ) -> Result<(), Error> {
impl_inner_method!(AnyBatch, self, set_script_pubkey, script, keychain, child) impl_inner_method!(AnyBatch, self, set_script_pubkey, script, keychain, child)
} }
fn set_utxo(&mut self, utxo: &UTXO) -> Result<(), Error> { fn set_utxo(&mut self, utxo: &LocalUtxo) -> Result<(), Error> {
impl_inner_method!(AnyBatch, self, set_utxo, utxo) impl_inner_method!(AnyBatch, self, set_utxo, utxo)
} }
fn set_raw_tx(&mut self, transaction: &Transaction) -> Result<(), Error> { fn set_raw_tx(&mut self, transaction: &Transaction) -> Result<(), Error> {
@ -283,7 +283,7 @@ impl BatchOperations for AnyBatch {
) -> Result<Option<(KeychainKind, u32)>, Error> { ) -> Result<Option<(KeychainKind, u32)>, Error> {
impl_inner_method!(AnyBatch, self, del_path_from_script_pubkey, script) impl_inner_method!(AnyBatch, self, del_path_from_script_pubkey, script)
} }
fn del_utxo(&mut self, outpoint: &OutPoint) -> Result<Option<UTXO>, Error> { fn del_utxo(&mut self, outpoint: &OutPoint) -> Result<Option<LocalUtxo>, Error> {
impl_inner_method!(AnyBatch, self, del_utxo, outpoint) impl_inner_method!(AnyBatch, self, del_utxo, outpoint)
} }
fn del_raw_tx(&mut self, txid: &Txid) -> Result<Option<Transaction>, Error> { fn del_raw_tx(&mut self, txid: &Txid) -> Result<Option<Transaction>, Error> {

View File

@ -51,7 +51,7 @@ macro_rules! impl_batch_operations {
Ok(()) Ok(())
} }
fn set_utxo(&mut self, utxo: &UTXO) -> Result<(), Error> { fn set_utxo(&mut self, utxo: &LocalUtxo) -> Result<(), Error> {
let key = MapKey::UTXO(Some(&utxo.outpoint)).as_map_key(); let key = MapKey::UTXO(Some(&utxo.outpoint)).as_map_key();
let value = json!({ let value = json!({
"t": utxo.txout, "t": utxo.txout,
@ -120,7 +120,7 @@ macro_rules! impl_batch_operations {
} }
} }
fn del_utxo(&mut self, outpoint: &OutPoint) -> Result<Option<UTXO>, Error> { fn del_utxo(&mut self, outpoint: &OutPoint) -> Result<Option<LocalUtxo>, Error> {
let key = MapKey::UTXO(Some(outpoint)).as_map_key(); let key = MapKey::UTXO(Some(outpoint)).as_map_key();
let res = self.remove(key); let res = self.remove(key);
let res = $process_delete!(res); let res = $process_delete!(res);
@ -132,7 +132,7 @@ macro_rules! impl_batch_operations {
let txout = serde_json::from_value(val["t"].take())?; let txout = serde_json::from_value(val["t"].take())?;
let keychain = serde_json::from_value(val["i"].take())?; let keychain = serde_json::from_value(val["i"].take())?;
Ok(Some(UTXO { outpoint: outpoint.clone(), txout, keychain })) Ok(Some(LocalUtxo { outpoint: outpoint.clone(), txout, keychain }))
} }
} }
} }
@ -234,7 +234,7 @@ impl Database for Tree {
.collect() .collect()
} }
fn iter_utxos(&self) -> Result<Vec<UTXO>, Error> { fn iter_utxos(&self) -> Result<Vec<LocalUtxo>, Error> {
let key = MapKey::UTXO(None).as_map_key(); let key = MapKey::UTXO(None).as_map_key();
self.scan_prefix(key) self.scan_prefix(key)
.map(|x| -> Result<_, Error> { .map(|x| -> Result<_, Error> {
@ -245,7 +245,7 @@ impl Database for Tree {
let txout = serde_json::from_value(val["t"].take())?; let txout = serde_json::from_value(val["t"].take())?;
let keychain = serde_json::from_value(val["i"].take())?; let keychain = serde_json::from_value(val["i"].take())?;
Ok(UTXO { Ok(LocalUtxo {
outpoint, outpoint,
txout, txout,
keychain, keychain,
@ -305,7 +305,7 @@ impl Database for Tree {
.transpose() .transpose()
} }
fn get_utxo(&self, outpoint: &OutPoint) -> Result<Option<UTXO>, Error> { fn get_utxo(&self, outpoint: &OutPoint) -> Result<Option<LocalUtxo>, Error> {
let key = MapKey::UTXO(Some(outpoint)).as_map_key(); let key = MapKey::UTXO(Some(outpoint)).as_map_key();
self.get(key)? self.get(key)?
.map(|b| -> Result<_, Error> { .map(|b| -> Result<_, Error> {
@ -313,7 +313,7 @@ impl Database for Tree {
let txout = serde_json::from_value(val["t"].take())?; let txout = serde_json::from_value(val["t"].take())?;
let keychain = serde_json::from_value(val["i"].take())?; let keychain = serde_json::from_value(val["i"].take())?;
Ok(UTXO { Ok(LocalUtxo {
outpoint: *outpoint, outpoint: *outpoint,
txout, txout,
keychain, keychain,

View File

@ -157,7 +157,7 @@ impl BatchOperations for MemoryDatabase {
Ok(()) Ok(())
} }
fn set_utxo(&mut self, utxo: &UTXO) -> Result<(), Error> { fn set_utxo(&mut self, utxo: &LocalUtxo) -> Result<(), Error> {
let key = MapKey::UTXO(Some(&utxo.outpoint)).as_map_key(); let key = MapKey::UTXO(Some(&utxo.outpoint)).as_map_key();
self.map self.map
.insert(key, Box::new((utxo.txout.clone(), utxo.keychain))); .insert(key, Box::new((utxo.txout.clone(), utxo.keychain)));
@ -223,7 +223,7 @@ impl BatchOperations for MemoryDatabase {
} }
} }
} }
fn del_utxo(&mut self, outpoint: &OutPoint) -> Result<Option<UTXO>, Error> { fn del_utxo(&mut self, outpoint: &OutPoint) -> Result<Option<LocalUtxo>, Error> {
let key = MapKey::UTXO(Some(outpoint)).as_map_key(); let key = MapKey::UTXO(Some(outpoint)).as_map_key();
let res = self.map.remove(&key); let res = self.map.remove(&key);
self.deleted_keys.push(key); self.deleted_keys.push(key);
@ -232,7 +232,7 @@ impl BatchOperations for MemoryDatabase {
None => Ok(None), None => Ok(None),
Some(b) => { Some(b) => {
let (txout, keychain) = b.downcast_ref().cloned().unwrap(); let (txout, keychain) = b.downcast_ref().cloned().unwrap();
Ok(Some(UTXO { Ok(Some(LocalUtxo {
outpoint: *outpoint, outpoint: *outpoint,
txout, txout,
keychain, keychain,
@ -316,14 +316,14 @@ impl Database for MemoryDatabase {
.collect() .collect()
} }
fn iter_utxos(&self) -> Result<Vec<UTXO>, Error> { fn iter_utxos(&self) -> Result<Vec<LocalUtxo>, Error> {
let key = MapKey::UTXO(None).as_map_key(); let key = MapKey::UTXO(None).as_map_key();
self.map self.map
.range::<Vec<u8>, _>((Included(&key), Excluded(&after(&key)))) .range::<Vec<u8>, _>((Included(&key), Excluded(&after(&key))))
.map(|(k, v)| { .map(|(k, v)| {
let outpoint = deserialize(&k[1..]).unwrap(); let outpoint = deserialize(&k[1..]).unwrap();
let (txout, keychain) = v.downcast_ref().cloned().unwrap(); let (txout, keychain) = v.downcast_ref().cloned().unwrap();
Ok(UTXO { Ok(LocalUtxo {
outpoint, outpoint,
txout, txout,
keychain, keychain,
@ -382,11 +382,11 @@ impl Database for MemoryDatabase {
})) }))
} }
fn get_utxo(&self, outpoint: &OutPoint) -> Result<Option<UTXO>, Error> { fn get_utxo(&self, outpoint: &OutPoint) -> Result<Option<LocalUtxo>, Error> {
let key = MapKey::UTXO(Some(outpoint)).as_map_key(); let key = MapKey::UTXO(Some(outpoint)).as_map_key();
Ok(self.map.get(&key).map(|b| { Ok(self.map.get(&key).map(|b| {
let (txout, keychain) = b.downcast_ref().cloned().unwrap(); let (txout, keychain) = b.downcast_ref().cloned().unwrap();
UTXO { LocalUtxo {
outpoint: *outpoint, outpoint: *outpoint,
txout, txout,
keychain, keychain,
@ -502,7 +502,7 @@ macro_rules! populate_test_db {
db.set_tx(&tx_details).unwrap(); db.set_tx(&tx_details).unwrap();
for (vout, out) in tx.output.iter().enumerate() { for (vout, out) in tx.output.iter().enumerate() {
db.set_utxo(&UTXO { db.set_utxo(&LocalUtxo {
txout: out.clone(), txout: out.clone(),
outpoint: OutPoint { outpoint: OutPoint {
txid, txid,

View File

@ -64,8 +64,8 @@ pub trait BatchOperations {
keychain: KeychainKind, keychain: KeychainKind,
child: u32, child: u32,
) -> Result<(), Error>; ) -> Result<(), Error>;
/// Store a [`UTXO`] /// Store a [`LocalUtxo`]
fn set_utxo(&mut self, utxo: &UTXO) -> Result<(), Error>; fn set_utxo(&mut self, utxo: &LocalUtxo) -> Result<(), Error>;
/// Store a raw transaction /// Store a raw transaction
fn set_raw_tx(&mut self, transaction: &Transaction) -> Result<(), Error>; fn set_raw_tx(&mut self, transaction: &Transaction) -> Result<(), Error>;
/// Store the metadata of a transaction /// Store the metadata of a transaction
@ -85,8 +85,8 @@ pub trait BatchOperations {
&mut self, &mut self,
script: &Script, script: &Script,
) -> Result<Option<(KeychainKind, u32)>, Error>; ) -> Result<Option<(KeychainKind, u32)>, Error>;
/// Delete a [`UTXO`] given its [`OutPoint`] /// Delete a [`LocalUtxo`] given its [`OutPoint`]
fn del_utxo(&mut self, outpoint: &OutPoint) -> Result<Option<UTXO>, Error>; fn del_utxo(&mut self, outpoint: &OutPoint) -> Result<Option<LocalUtxo>, Error>;
/// Delete a raw transaction given its [`Txid`] /// Delete a raw transaction given its [`Txid`]
fn del_raw_tx(&mut self, txid: &Txid) -> Result<Option<Transaction>, Error>; fn del_raw_tx(&mut self, txid: &Txid) -> Result<Option<Transaction>, Error>;
/// Delete the metadata of a transaction and optionally the raw transaction itself /// Delete the metadata of a transaction and optionally the raw transaction itself
@ -116,8 +116,8 @@ pub trait Database: BatchOperations {
/// Return the list of script_pubkeys /// Return the list of script_pubkeys
fn iter_script_pubkeys(&self, keychain: Option<KeychainKind>) -> Result<Vec<Script>, Error>; fn iter_script_pubkeys(&self, keychain: Option<KeychainKind>) -> Result<Vec<Script>, Error>;
/// Return the list of [`UTXO`]s /// Return the list of [`LocalUtxo`]s
fn iter_utxos(&self) -> Result<Vec<UTXO>, Error>; fn iter_utxos(&self) -> Result<Vec<LocalUtxo>, Error>;
/// Return the list of raw transactions /// Return the list of raw transactions
fn iter_raw_txs(&self) -> Result<Vec<Transaction>, Error>; fn iter_raw_txs(&self) -> Result<Vec<Transaction>, Error>;
/// Return the list of transactions metadata /// Return the list of transactions metadata
@ -134,8 +134,8 @@ pub trait Database: BatchOperations {
&self, &self,
script: &Script, script: &Script,
) -> Result<Option<(KeychainKind, u32)>, Error>; ) -> Result<Option<(KeychainKind, u32)>, Error>;
/// Fetch a [`UTXO`] given its [`OutPoint`] /// Fetch a [`LocalUtxo`] given its [`OutPoint`]
fn get_utxo(&self, outpoint: &OutPoint) -> Result<Option<UTXO>, Error>; fn get_utxo(&self, outpoint: &OutPoint) -> Result<Option<LocalUtxo>, Error>;
/// Fetch a raw transaction given its [`Txid`] /// Fetch a raw transaction given its [`Txid`]
fn get_raw_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error>; fn get_raw_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error>;
/// Fetch the transaction metadata and optionally also the raw transaction /// Fetch the transaction metadata and optionally also the raw transaction
@ -298,7 +298,7 @@ pub mod test {
value: 133742, value: 133742,
script_pubkey: script, script_pubkey: script,
}; };
let utxo = UTXO { let utxo = LocalUtxo {
txout, txout,
outpoint, outpoint,
keychain: KeychainKind::External, keychain: KeychainKind::External,

View File

@ -92,7 +92,7 @@ impl std::default::Default for FeeRate {
/// A wallet unspent output /// A wallet unspent output
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct UTXO { pub struct LocalUtxo {
/// Reference to a transaction output /// Reference to a transaction output
pub outpoint: OutPoint, pub outpoint: OutPoint,
/// Transaction output /// Transaction output

View File

@ -50,8 +50,8 @@
//! fn coin_select( //! fn coin_select(
//! &self, //! &self,
//! database: &D, //! database: &D,
//! required_utxos: Vec<(UTXO, usize)>, //! required_utxos: Vec<(LocalUtxo, usize)>,
//! optional_utxos: Vec<(UTXO, usize)>, //! optional_utxos: Vec<(LocalUtxo, usize)>,
//! fee_rate: FeeRate, //! fee_rate: FeeRate,
//! amount_needed: u64, //! amount_needed: u64,
//! fee_amount: f32, //! fee_amount: f32,
@ -99,7 +99,7 @@
use crate::database::Database; use crate::database::Database;
use crate::error::Error; use crate::error::Error;
use crate::types::{FeeRate, UTXO}; use crate::types::{FeeRate, LocalUtxo};
use rand::seq::SliceRandom; use rand::seq::SliceRandom;
#[cfg(not(test))] #[cfg(not(test))]
@ -122,7 +122,7 @@ pub(crate) const TXIN_BASE_WEIGHT: usize = (32 + 4 + 4 + 1) * 4;
#[derive(Debug)] #[derive(Debug)]
pub struct CoinSelectionResult { pub struct CoinSelectionResult {
/// List of outputs selected for use as inputs /// List of outputs selected for use as inputs
pub selected: Vec<UTXO>, pub selected: Vec<LocalUtxo>,
/// Sum of the selected inputs' value /// Sum of the selected inputs' value
pub selected_amount: u64, pub selected_amount: u64,
/// Total fee amount in satoshi /// Total fee amount in satoshi
@ -151,8 +151,8 @@ pub trait CoinSelectionAlgorithm<D: Database>: std::fmt::Debug {
fn coin_select( fn coin_select(
&self, &self,
database: &D, database: &D,
required_utxos: Vec<(UTXO, usize)>, required_utxos: Vec<(LocalUtxo, usize)>,
optional_utxos: Vec<(UTXO, usize)>, optional_utxos: Vec<(LocalUtxo, usize)>,
fee_rate: FeeRate, fee_rate: FeeRate,
amount_needed: u64, amount_needed: u64,
fee_amount: f32, fee_amount: f32,
@ -170,8 +170,8 @@ impl<D: Database> CoinSelectionAlgorithm<D> for LargestFirstCoinSelection {
fn coin_select( fn coin_select(
&self, &self,
_database: &D, _database: &D,
required_utxos: Vec<(UTXO, usize)>, required_utxos: Vec<(LocalUtxo, usize)>,
mut optional_utxos: Vec<(UTXO, usize)>, mut optional_utxos: Vec<(LocalUtxo, usize)>,
fee_rate: FeeRate, fee_rate: FeeRate,
amount_needed: u64, amount_needed: u64,
mut fee_amount: f32, mut fee_amount: f32,
@ -239,7 +239,7 @@ impl<D: Database> CoinSelectionAlgorithm<D> for LargestFirstCoinSelection {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
// Adds fee information to an UTXO. // Adds fee information to an UTXO.
struct OutputGroup { struct OutputGroup {
utxo: UTXO, utxo: LocalUtxo,
// weight needed to satisfy the UTXO, as described in `Descriptor::max_satisfaction_weight` // weight needed to satisfy the UTXO, as described in `Descriptor::max_satisfaction_weight`
satisfaction_weight: usize, satisfaction_weight: usize,
// Amount of fees for spending a certain utxo, calculated using a certain FeeRate // Amount of fees for spending a certain utxo, calculated using a certain FeeRate
@ -249,7 +249,7 @@ struct OutputGroup {
} }
impl OutputGroup { impl OutputGroup {
fn new(utxo: UTXO, satisfaction_weight: usize, fee_rate: FeeRate) -> Self { fn new(utxo: LocalUtxo, satisfaction_weight: usize, fee_rate: FeeRate) -> Self {
let fee = (TXIN_BASE_WEIGHT + satisfaction_weight) as f32 / 4.0 * fee_rate.as_sat_vb(); let fee = (TXIN_BASE_WEIGHT + satisfaction_weight) as f32 / 4.0 * fee_rate.as_sat_vb();
let effective_value = utxo.txout.value as i64 - fee.ceil() as i64; let effective_value = utxo.txout.value as i64 - fee.ceil() as i64;
OutputGroup { OutputGroup {
@ -291,8 +291,8 @@ impl<D: Database> CoinSelectionAlgorithm<D> for BranchAndBoundCoinSelection {
fn coin_select( fn coin_select(
&self, &self,
_database: &D, _database: &D,
required_utxos: Vec<(UTXO, usize)>, required_utxos: Vec<(LocalUtxo, usize)>,
optional_utxos: Vec<(UTXO, usize)>, optional_utxos: Vec<(LocalUtxo, usize)>,
fee_rate: FeeRate, fee_rate: FeeRate,
amount_needed: u64, amount_needed: u64,
fee_amount: f32, fee_amount: f32,
@ -535,10 +535,10 @@ mod test {
const P2WPKH_WITNESS_SIZE: usize = 73 + 33 + 2; const P2WPKH_WITNESS_SIZE: usize = 73 + 33 + 2;
fn get_test_utxos() -> Vec<(UTXO, usize)> { fn get_test_utxos() -> Vec<(LocalUtxo, usize)> {
vec![ vec![
( (
UTXO { LocalUtxo {
outpoint: OutPoint::from_str( outpoint: OutPoint::from_str(
"ebd9813ecebc57ff8f30797de7c205e3c7498ca950ea4341ee51a685ff2fa30a:0", "ebd9813ecebc57ff8f30797de7c205e3c7498ca950ea4341ee51a685ff2fa30a:0",
) )
@ -552,7 +552,7 @@ mod test {
P2WPKH_WITNESS_SIZE, P2WPKH_WITNESS_SIZE,
), ),
( (
UTXO { LocalUtxo {
outpoint: OutPoint::from_str( outpoint: OutPoint::from_str(
"65d92ddff6b6dc72c89624a6491997714b90f6004f928d875bc0fd53f264fa85:0", "65d92ddff6b6dc72c89624a6491997714b90f6004f928d875bc0fd53f264fa85:0",
) )
@ -568,11 +568,11 @@ mod test {
] ]
} }
fn generate_random_utxos(rng: &mut StdRng, utxos_number: usize) -> Vec<(UTXO, usize)> { fn generate_random_utxos(rng: &mut StdRng, utxos_number: usize) -> Vec<(LocalUtxo, usize)> {
let mut res = Vec::new(); let mut res = Vec::new();
for _ in 0..utxos_number { for _ in 0..utxos_number {
res.push(( res.push((
UTXO { LocalUtxo {
outpoint: OutPoint::from_str( outpoint: OutPoint::from_str(
"ebd9813ecebc57ff8f30797de7c205e3c7498ca950ea4341ee51a685ff2fa30a:0", "ebd9813ecebc57ff8f30797de7c205e3c7498ca950ea4341ee51a685ff2fa30a:0",
) )
@ -589,9 +589,9 @@ mod test {
res res
} }
fn generate_same_value_utxos(utxos_value: u64, utxos_number: usize) -> Vec<(UTXO, usize)> { fn generate_same_value_utxos(utxos_value: u64, utxos_number: usize) -> Vec<(LocalUtxo, usize)> {
let utxo = ( let utxo = (
UTXO { LocalUtxo {
outpoint: OutPoint::from_str( outpoint: OutPoint::from_str(
"ebd9813ecebc57ff8f30797de7c205e3c7498ca950ea4341ee51a685ff2fa30a:0", "ebd9813ecebc57ff8f30797de7c205e3c7498ca950ea4341ee51a685ff2fa30a:0",
) )
@ -607,7 +607,7 @@ mod test {
vec![utxo; utxos_number] vec![utxo; utxos_number]
} }
fn sum_random_utxos(mut rng: &mut StdRng, utxos: &mut Vec<(UTXO, usize)>) -> u64 { fn sum_random_utxos(mut rng: &mut StdRng, utxos: &mut Vec<(LocalUtxo, usize)>) -> u64 {
let utxos_picked_len = rng.gen_range(2, utxos.len() / 2); let utxos_picked_len = rng.gen_range(2, utxos.len() / 2);
utxos.shuffle(&mut rng); utxos.shuffle(&mut rng);
utxos[..utxos_picked_len] utxos[..utxos_picked_len]

View File

@ -199,13 +199,13 @@ where
/// ///
/// Note that this methods only operate on the internal database, which first needs to be /// Note that this methods only operate on the internal database, which first needs to be
/// [`Wallet::sync`] manually. /// [`Wallet::sync`] manually.
pub fn list_unspent(&self) -> Result<Vec<UTXO>, Error> { pub fn list_unspent(&self) -> Result<Vec<LocalUtxo>, Error> {
self.database.borrow().iter_utxos() self.database.borrow().iter_utxos()
} }
/// Returns the `UTXO` owned by this wallet corresponding to `outpoint` if it exists in the /// Returns the `UTXO` owned by this wallet corresponding to `outpoint` if it exists in the
/// wallet's database. /// wallet's database.
pub fn get_utxo(&self, outpoint: OutPoint) -> Result<Option<UTXO>, Error> { pub fn get_utxo(&self, outpoint: OutPoint) -> Result<Option<LocalUtxo>, Error> {
self.database.borrow().get_utxo(&outpoint) self.database.borrow().get_utxo(&outpoint)
} }
@ -699,7 +699,7 @@ where
} }
}; };
let utxo = UTXO { let utxo = LocalUtxo {
outpoint: txin.previous_output, outpoint: txin.previous_output,
txout, txout,
keychain, keychain,
@ -1016,7 +1016,7 @@ where
Ok(()) Ok(())
} }
fn get_available_utxos(&self) -> Result<Vec<(UTXO, usize)>, Error> { fn get_available_utxos(&self) -> Result<Vec<(LocalUtxo, usize)>, Error> {
Ok(self Ok(self
.list_unspent()? .list_unspent()?
.into_iter() .into_iter()
@ -1039,11 +1039,11 @@ where
&self, &self,
change_policy: tx_builder::ChangeSpendPolicy, change_policy: tx_builder::ChangeSpendPolicy,
unspendable: &HashSet<OutPoint>, unspendable: &HashSet<OutPoint>,
manually_selected: Vec<(UTXO, usize)>, manually_selected: Vec<(LocalUtxo, usize)>,
must_use_all_available: bool, must_use_all_available: bool,
manual_only: bool, manual_only: bool,
must_only_use_confirmed_tx: bool, must_only_use_confirmed_tx: bool,
) -> Result<(Vec<(UTXO, usize)>, Vec<(UTXO, usize)>), Error> { ) -> Result<(Vec<(LocalUtxo, usize)>, Vec<(LocalUtxo, usize)>), Error> {
// must_spend <- manually selected utxos // must_spend <- manually selected utxos
// may_spend <- all other available utxos // may_spend <- all other available utxos
let mut may_spend = self.get_available_utxos()?; let mut may_spend = self.get_available_utxos()?;
@ -1098,7 +1098,7 @@ where
fn complete_transaction( fn complete_transaction(
&self, &self,
tx: Transaction, tx: Transaction,
selected: Vec<UTXO>, selected: Vec<LocalUtxo>,
params: TxParams, params: TxParams,
) -> Result<PSBT, Error> { ) -> Result<PSBT, Error> {
use bitcoin::util::psbt::serialize::Serialize; use bitcoin::util::psbt::serialize::Serialize;

View File

@ -62,7 +62,7 @@ use miniscript::descriptor::DescriptorTrait;
use super::coin_selection::{CoinSelectionAlgorithm, DefaultCoinSelectionAlgorithm}; use super::coin_selection::{CoinSelectionAlgorithm, DefaultCoinSelectionAlgorithm};
use crate::{database::BatchDatabase, Error, Wallet}; use crate::{database::BatchDatabase, Error, Wallet};
use crate::{ use crate::{
types::{FeeRate, KeychainKind, UTXO}, types::{FeeRate, KeychainKind, LocalUtxo},
TransactionDetails, TransactionDetails,
}; };
/// Context in which the [`TxBuilder`] is valid /// Context in which the [`TxBuilder`] is valid
@ -150,7 +150,7 @@ pub(crate) struct TxParams {
pub(crate) fee_policy: Option<FeePolicy>, pub(crate) fee_policy: Option<FeePolicy>,
pub(crate) internal_policy_path: Option<BTreeMap<String, Vec<usize>>>, pub(crate) internal_policy_path: Option<BTreeMap<String, Vec<usize>>>,
pub(crate) external_policy_path: Option<BTreeMap<String, Vec<usize>>>, pub(crate) external_policy_path: Option<BTreeMap<String, Vec<usize>>>,
pub(crate) utxos: Vec<(UTXO, usize)>, pub(crate) utxos: Vec<(LocalUtxo, usize)>,
pub(crate) unspendable: HashSet<OutPoint>, pub(crate) unspendable: HashSet<OutPoint>,
pub(crate) manually_selected_only: bool, pub(crate) manually_selected_only: bool,
pub(crate) sighash: Option<SigHashType>, pub(crate) sighash: Option<SigHashType>,
@ -618,7 +618,7 @@ impl Default for ChangeSpendPolicy {
} }
impl ChangeSpendPolicy { impl ChangeSpendPolicy {
pub(crate) fn is_satisfied_by(&self, utxo: &UTXO) -> bool { pub(crate) fn is_satisfied_by(&self, utxo: &LocalUtxo) -> bool {
match self { match self {
ChangeSpendPolicy::ChangeAllowed => true, ChangeSpendPolicy::ChangeAllowed => true,
ChangeSpendPolicy::OnlyChange => utxo.keychain == KeychainKind::Internal, ChangeSpendPolicy::OnlyChange => utxo.keychain == KeychainKind::Internal,
@ -709,9 +709,9 @@ mod test {
assert_eq!(tx.output[2].script_pubkey, From::from(vec![0xAA, 0xEE])); assert_eq!(tx.output[2].script_pubkey, From::from(vec![0xAA, 0xEE]));
} }
fn get_test_utxos() -> Vec<UTXO> { fn get_test_utxos() -> Vec<LocalUtxo> {
vec![ vec![
UTXO { LocalUtxo {
outpoint: OutPoint { outpoint: OutPoint {
txid: Default::default(), txid: Default::default(),
vout: 0, vout: 0,
@ -719,7 +719,7 @@ mod test {
txout: Default::default(), txout: Default::default(),
keychain: KeychainKind::External, keychain: KeychainKind::External,
}, },
UTXO { LocalUtxo {
outpoint: OutPoint { outpoint: OutPoint {
txid: Default::default(), txid: Default::default(),
vout: 1, vout: 1,