Rename get_spendable -> get_unspent

This commit is contained in:
Kris Nuttycombe 2021-02-12 16:57:44 -07:00
parent ca3e3a4595
commit a3bc1e3e63
6 changed files with 28 additions and 32 deletions

View File

@ -165,16 +165,16 @@ pub trait WalletRead {
/// with which they are associated.
fn get_nullifiers(&self) -> Result<Vec<(AccountId, Nullifier)>, Self::Error>;
/// Return all spendable notes.
fn get_spendable_sapling_notes(
/// Return all unspent notes.
fn get_unspent_sapling_notes(
&self,
account: AccountId,
anchor_height: BlockHeight,
) -> Result<Vec<SpendableNote>, Self::Error>;
/// Returns a list of spendable notes sufficient to cover the specified
/// Returns a list of unspent notes sufficient to cover the specified
/// target value, if possible.
fn select_spendable_sapling_notes(
fn select_unspent_sapling_notes(
&self,
account: AccountId,
target_value: Amount,
@ -182,7 +182,7 @@ pub trait WalletRead {
) -> Result<Vec<SpendableNote>, Self::Error>;
#[cfg(feature = "transparent-inputs")]
fn get_spendable_transparent_utxos(
fn get_unspent_transparent_utxos(
&self,
address: &TransparentAddress,
anchor_height: BlockHeight,
@ -395,7 +395,7 @@ pub mod testing {
Ok(Vec::new())
}
fn get_spendable_sapling_notes(
fn get_unspent_sapling_notes(
&self,
_account: AccountId,
_anchor_height: BlockHeight,
@ -403,7 +403,7 @@ pub mod testing {
Ok(Vec::new())
}
fn select_spendable_sapling_notes(
fn select_unspent_sapling_notes(
&self,
_account: AccountId,
_target_value: Amount,
@ -413,7 +413,7 @@ pub mod testing {
}
#[cfg(feature = "transparent-inputs")]
fn get_spendable_transparent_utxos(
fn get_unspent_transparent_utxos(
&self,
_address: &TransparentAddress,
_anchor_height: BlockHeight,

View File

@ -191,7 +191,7 @@ where
let target_value = value + DEFAULT_FEE;
let spendable_notes =
wallet_db.select_spendable_sapling_notes(account, target_value, anchor_height)?;
wallet_db.select_unspent_sapling_notes(account, target_value, anchor_height)?;
// Confirm we were able to select sufficient value
let selected_value = spendable_notes.iter().map(|n| n.note_value).sum();
@ -296,7 +296,7 @@ where
let ovk = exfvk.fvk.ovk;
// get UTXOs from DB
let utxos = wallet_db.get_spendable_transparent_utxos(&taddr, latest_anchor)?;
let utxos = wallet_db.get_unspent_transparent_utxos(&taddr, latest_anchor)?;
let total_amount = utxos.iter().map(|utxo| utxo.value).sum::<Amount>();
let fee = DEFAULT_FEE;

View File

@ -75,6 +75,7 @@ pub fn derive_secret_key_from_seed<P: consensus::Parameters>(
}
#[cfg(feature = "transparent-inputs")]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Wif(pub String);
#[cfg(feature = "transparent-inputs")]
@ -94,7 +95,7 @@ impl Wif {
}
#[cfg(feature = "transparent-inputs")]
impl TryInto<SecretKey> for Wif {
impl<'a> TryInto<SecretKey> for &'a Wif {
type Error = Bs58Error;
fn try_into(self) -> Result<SecretKey, Self::Error> {
@ -153,7 +154,7 @@ mod tests {
#[test]
fn sk_wif_to_taddr() {
let sk_wif = Wif("L4BvDC33yLjMRxipZvdiUmdYeRfZmR8viziwsVwe72zJdGbiJPv2".to_string());
let sk: SecretKey = sk_wif.try_into().expect("invalid wif");
let sk: SecretKey = (&sk_wif).try_into().expect("invalid wif");
let taddr = derive_transparent_address_from_secret_key(sk);
assert_eq!(
taddr.encode(&MAIN_NETWORK),

View File

@ -263,35 +263,30 @@ impl<P: consensus::Parameters> WalletRead for WalletDb<P> {
wallet::get_nullifiers(&self)
}
fn get_spendable_sapling_notes(
fn get_unspent_sapling_notes(
&self,
account: AccountId,
anchor_height: BlockHeight,
) -> Result<Vec<SpendableNote>, Self::Error> {
wallet::transact::get_spendable_sapling_notes(&self, account, anchor_height)
wallet::transact::get_unspent_sapling_notes(&self, account, anchor_height)
}
fn select_spendable_sapling_notes(
fn select_unspent_sapling_notes(
&self,
account: AccountId,
target_value: Amount,
anchor_height: BlockHeight,
) -> Result<Vec<SpendableNote>, Self::Error> {
wallet::transact::select_spendable_sapling_notes(
&self,
account,
target_value,
anchor_height,
)
wallet::transact::select_unspent_sapling_notes(&self, account, target_value, anchor_height)
}
#[cfg(feature = "transparent-inputs")]
fn get_spendable_transparent_utxos(
fn get_unspent_transparent_utxos(
&self,
address: &TransparentAddress,
anchor_height: BlockHeight,
) -> Result<Vec<WalletTransparentOutput>, Self::Error> {
wallet::get_spendable_transparent_utxos(&self, address, anchor_height)
wallet::get_unspent_transparent_utxos(&self, address, anchor_height)
}
}
@ -396,33 +391,33 @@ impl<'a, P: consensus::Parameters> WalletRead for DataConnStmtCache<'a, P> {
self.wallet_db.get_nullifiers()
}
fn get_spendable_sapling_notes(
fn get_unspent_sapling_notes(
&self,
account: AccountId,
anchor_height: BlockHeight,
) -> Result<Vec<SpendableNote>, Self::Error> {
self.wallet_db
.get_spendable_sapling_notes(account, anchor_height)
.get_unspent_sapling_notes(account, anchor_height)
}
fn select_spendable_sapling_notes(
fn select_unspent_sapling_notes(
&self,
account: AccountId,
target_value: Amount,
anchor_height: BlockHeight,
) -> Result<Vec<SpendableNote>, Self::Error> {
self.wallet_db
.select_spendable_sapling_notes(account, target_value, anchor_height)
.select_unspent_sapling_notes(account, target_value, anchor_height)
}
#[cfg(feature = "transparent-inputs")]
fn get_spendable_transparent_utxos(
fn get_unspent_transparent_utxos(
&self,
address: &TransparentAddress,
anchor_height: BlockHeight,
) -> Result<Vec<WalletTransparentOutput>, Self::Error> {
self.wallet_db
.get_spendable_transparent_utxos(address, anchor_height)
.get_unspent_transparent_utxos(address, anchor_height)
}
}

View File

@ -599,7 +599,7 @@ pub fn get_nullifiers<P>(
}
#[cfg(feature = "transparent-inputs")]
pub fn get_spendable_transparent_utxos<P: consensus::Parameters>(
pub fn get_unspent_transparent_utxos<P: consensus::Parameters>(
wdb: &WalletDb<P>,
address: &TransparentAddress,
anchor_height: BlockHeight,

View File

@ -59,7 +59,7 @@ fn to_spendable_note(row: &Row) -> Result<SpendableNote, SqliteClientError> {
})
}
pub fn get_spendable_sapling_notes<P>(
pub fn get_unspent_sapling_notes<P>(
wdb: &WalletDb<P>,
account: AccountId,
anchor_height: BlockHeight,
@ -87,7 +87,7 @@ pub fn get_spendable_sapling_notes<P>(
notes.collect::<Result<_, _>>()
}
pub fn select_spendable_sapling_notes<P>(
pub fn select_unspent_sapling_notes<P>(
wdb: &WalletDb<P>,
account: AccountId,
target_value: Amount,