zcash_client_backend: Use globally unique identifiers for notes.
Update zcash_client_backend error types to use (TxId, output_index) as the identifier for notes instead of the internal database identifier.
This commit is contained in:
parent
74840829c8
commit
5b40ddf072
|
@ -18,6 +18,10 @@ and this library adheres to Rust's notion of
|
||||||
- The fields of `zcash_client_backend::wallet::ReceivedSaplingNote` are now
|
- The fields of `zcash_client_backend::wallet::ReceivedSaplingNote` are now
|
||||||
private. Use `ReceivedSaplingNote::from_parts` for construction instead.
|
private. Use `ReceivedSaplingNote::from_parts` for construction instead.
|
||||||
Accessor methods are provided for each previously-public field.
|
Accessor methods are provided for each previously-public field.
|
||||||
|
- `zcash_client_backend::data_api` changes:
|
||||||
|
- The `NoteMismatch` variant of `data_api::error::Error` now wraps a
|
||||||
|
`data_api::NoteId` instead of a backend-specific note identifier. The
|
||||||
|
related `NoteRef` type parameter has been removed from `data_api::error::Error`.
|
||||||
|
|
||||||
## [0.10.0] - 2023-09-25
|
## [0.10.0] - 2023-09-25
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,11 @@ use crate::data_api::wallet::input_selection::InputSelectorError;
|
||||||
#[cfg(feature = "transparent-inputs")]
|
#[cfg(feature = "transparent-inputs")]
|
||||||
use zcash_primitives::{legacy::TransparentAddress, zip32::DiversifierIndex};
|
use zcash_primitives::{legacy::TransparentAddress, zip32::DiversifierIndex};
|
||||||
|
|
||||||
|
use super::NoteId;
|
||||||
|
|
||||||
/// Errors that can occur as a consequence of wallet operations.
|
/// Errors that can occur as a consequence of wallet operations.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error<DataSourceError, CommitmentTreeError, SelectionError, FeeError, NoteRef> {
|
pub enum Error<DataSourceError, CommitmentTreeError, SelectionError, FeeError> {
|
||||||
/// An error occurred retrieving data from the underlying data source
|
/// An error occurred retrieving data from the underlying data source
|
||||||
DataSource(DataSourceError),
|
DataSource(DataSourceError),
|
||||||
|
|
||||||
|
@ -56,7 +58,7 @@ pub enum Error<DataSourceError, CommitmentTreeError, SelectionError, FeeError, N
|
||||||
|
|
||||||
/// A note being spent does not correspond to either the internal or external
|
/// A note being spent does not correspond to either the internal or external
|
||||||
/// full viewing key for an account.
|
/// full viewing key for an account.
|
||||||
NoteMismatch(NoteRef),
|
NoteMismatch(NoteId),
|
||||||
|
|
||||||
#[cfg(feature = "transparent-inputs")]
|
#[cfg(feature = "transparent-inputs")]
|
||||||
AddressNotRecognized(TransparentAddress),
|
AddressNotRecognized(TransparentAddress),
|
||||||
|
@ -65,13 +67,12 @@ pub enum Error<DataSourceError, CommitmentTreeError, SelectionError, FeeError, N
|
||||||
ChildIndexOutOfRange(DiversifierIndex),
|
ChildIndexOutOfRange(DiversifierIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DE, CE, SE, FE, N> fmt::Display for Error<DE, CE, SE, FE, N>
|
impl<DE, CE, SE, FE> fmt::Display for Error<DE, CE, SE, FE>
|
||||||
where
|
where
|
||||||
DE: fmt::Display,
|
DE: fmt::Display,
|
||||||
CE: fmt::Display,
|
CE: fmt::Display,
|
||||||
SE: fmt::Display,
|
SE: fmt::Display,
|
||||||
FE: fmt::Display,
|
FE: fmt::Display,
|
||||||
N: fmt::Display,
|
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match &self {
|
match &self {
|
||||||
|
@ -111,7 +112,7 @@ where
|
||||||
Error::ScanRequired => write!(f, "Must scan blocks first"),
|
Error::ScanRequired => write!(f, "Must scan blocks first"),
|
||||||
Error::Builder(e) => write!(f, "An error occurred building the transaction: {}", e),
|
Error::Builder(e) => write!(f, "An error occurred building the transaction: {}", e),
|
||||||
Error::MemoForbidden => write!(f, "It is not possible to send a memo to a transparent address."),
|
Error::MemoForbidden => write!(f, "It is not possible to send a memo to a transparent address."),
|
||||||
Error::NoteMismatch(n) => write!(f, "A note being spent ({}) does not correspond to either the internal or external full viewing key for the provided spending key.", n),
|
Error::NoteMismatch(n) => write!(f, "A note being spent ({:?}) does not correspond to either the internal or external full viewing key for the provided spending key.", n),
|
||||||
|
|
||||||
#[cfg(feature = "transparent-inputs")]
|
#[cfg(feature = "transparent-inputs")]
|
||||||
Error::AddressNotRecognized(_) => {
|
Error::AddressNotRecognized(_) => {
|
||||||
|
@ -129,13 +130,12 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DE, CE, SE, FE, N> error::Error for Error<DE, CE, SE, FE, N>
|
impl<DE, CE, SE, FE> error::Error for Error<DE, CE, SE, FE>
|
||||||
where
|
where
|
||||||
DE: Debug + Display + error::Error + 'static,
|
DE: Debug + Display + error::Error + 'static,
|
||||||
CE: Debug + Display + error::Error + 'static,
|
CE: Debug + Display + error::Error + 'static,
|
||||||
SE: Debug + Display + error::Error + 'static,
|
SE: Debug + Display + error::Error + 'static,
|
||||||
FE: Debug + Display + 'static,
|
FE: Debug + Display + 'static,
|
||||||
N: Debug + Display,
|
|
||||||
{
|
{
|
||||||
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||||
match &self {
|
match &self {
|
||||||
|
@ -148,19 +148,19 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DE, CE, SE, FE, N> From<builder::Error<FE>> for Error<DE, CE, SE, FE, N> {
|
impl<DE, CE, SE, FE> From<builder::Error<FE>> for Error<DE, CE, SE, FE> {
|
||||||
fn from(e: builder::Error<FE>) -> Self {
|
fn from(e: builder::Error<FE>) -> Self {
|
||||||
Error::Builder(e)
|
Error::Builder(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DE, CE, SE, FE, N> From<BalanceError> for Error<DE, CE, SE, FE, N> {
|
impl<DE, CE, SE, FE> From<BalanceError> for Error<DE, CE, SE, FE> {
|
||||||
fn from(e: BalanceError) -> Self {
|
fn from(e: BalanceError) -> Self {
|
||||||
Error::BalanceError(e)
|
Error::BalanceError(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DE, CE, SE, FE, N> From<InputSelectorError<DE, SE>> for Error<DE, CE, SE, FE, N> {
|
impl<DE, CE, SE, FE> From<InputSelectorError<DE, SE>> for Error<DE, CE, SE, FE> {
|
||||||
fn from(e: InputSelectorError<DE, SE>) -> Self {
|
fn from(e: InputSelectorError<DE, SE>) -> Self {
|
||||||
match e {
|
match e {
|
||||||
InputSelectorError::DataSource(e) => Error::DataSource(e),
|
InputSelectorError::DataSource(e) => Error::DataSource(e),
|
||||||
|
@ -177,19 +177,19 @@ impl<DE, CE, SE, FE, N> From<InputSelectorError<DE, SE>> for Error<DE, CE, SE, F
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DE, CE, SE, FE, N> From<sapling::builder::Error> for Error<DE, CE, SE, FE, N> {
|
impl<DE, CE, SE, FE> From<sapling::builder::Error> for Error<DE, CE, SE, FE> {
|
||||||
fn from(e: sapling::builder::Error) -> Self {
|
fn from(e: sapling::builder::Error) -> Self {
|
||||||
Error::Builder(builder::Error::SaplingBuild(e))
|
Error::Builder(builder::Error::SaplingBuild(e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DE, CE, SE, FE, N> From<transparent::builder::Error> for Error<DE, CE, SE, FE, N> {
|
impl<DE, CE, SE, FE> From<transparent::builder::Error> for Error<DE, CE, SE, FE> {
|
||||||
fn from(e: transparent::builder::Error) -> Self {
|
fn from(e: transparent::builder::Error) -> Self {
|
||||||
Error::Builder(builder::Error::TransparentBuild(e))
|
Error::Builder(builder::Error::TransparentBuild(e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DE, CE, SE, FE, N> From<ShardTreeError<CE>> for Error<DE, CE, SE, FE, N> {
|
impl<DE, CE, SE, FE> From<ShardTreeError<CE>> for Error<DE, CE, SE, FE> {
|
||||||
fn from(e: ShardTreeError<CE>) -> Self {
|
fn from(e: ShardTreeError<CE>) -> Self {
|
||||||
Error::CommitmentTree(e)
|
Error::CommitmentTree(e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ use crate::{
|
||||||
pub mod input_selection;
|
pub mod input_selection;
|
||||||
use input_selection::{GreedyInputSelector, GreedyInputSelectorError, InputSelector};
|
use input_selection::{GreedyInputSelector, GreedyInputSelectorError, InputSelector};
|
||||||
|
|
||||||
use super::ShieldedProtocol;
|
use super::{NoteId, ShieldedProtocol};
|
||||||
|
|
||||||
#[cfg(feature = "transparent-inputs")]
|
#[cfg(feature = "transparent-inputs")]
|
||||||
use {
|
use {
|
||||||
|
@ -206,7 +206,6 @@ pub fn create_spend_to_address<DbT, ParamsT>(
|
||||||
<DbT as WalletCommitmentTrees>::Error,
|
<DbT as WalletCommitmentTrees>::Error,
|
||||||
GreedyInputSelectorError<BalanceError, DbT::NoteRef>,
|
GreedyInputSelectorError<BalanceError, DbT::NoteRef>,
|
||||||
Infallible,
|
Infallible,
|
||||||
DbT::NoteRef,
|
|
||||||
>,
|
>,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
|
@ -309,7 +308,6 @@ pub fn spend<DbT, ParamsT, InputsT>(
|
||||||
<DbT as WalletCommitmentTrees>::Error,
|
<DbT as WalletCommitmentTrees>::Error,
|
||||||
InputsT::Error,
|
InputsT::Error,
|
||||||
<InputsT::FeeRule as FeeRule>::Error,
|
<InputsT::FeeRule as FeeRule>::Error,
|
||||||
DbT::NoteRef,
|
|
||||||
>,
|
>,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
|
@ -358,13 +356,7 @@ pub fn propose_transfer<DbT, ParamsT, InputsT, CommitmentTreeErrT>(
|
||||||
min_confirmations: NonZeroU32,
|
min_confirmations: NonZeroU32,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
Proposal<InputsT::FeeRule, DbT::NoteRef>,
|
Proposal<InputsT::FeeRule, DbT::NoteRef>,
|
||||||
Error<
|
Error<DbT::Error, CommitmentTreeErrT, InputsT::Error, <InputsT::FeeRule as FeeRule>::Error>,
|
||||||
DbT::Error,
|
|
||||||
CommitmentTreeErrT,
|
|
||||||
InputsT::Error,
|
|
||||||
<InputsT::FeeRule as FeeRule>::Error,
|
|
||||||
DbT::NoteRef,
|
|
||||||
>,
|
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
DbT: WalletWrite,
|
DbT: WalletWrite,
|
||||||
|
@ -395,13 +387,7 @@ pub fn propose_shielding<DbT, ParamsT, InputsT, CommitmentTreeErrT>(
|
||||||
min_confirmations: NonZeroU32,
|
min_confirmations: NonZeroU32,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
Proposal<InputsT::FeeRule, DbT::NoteRef>,
|
Proposal<InputsT::FeeRule, DbT::NoteRef>,
|
||||||
Error<
|
Error<DbT::Error, CommitmentTreeErrT, InputsT::Error, <InputsT::FeeRule as FeeRule>::Error>,
|
||||||
DbT::Error,
|
|
||||||
CommitmentTreeErrT,
|
|
||||||
InputsT::Error,
|
|
||||||
<InputsT::FeeRule as FeeRule>::Error,
|
|
||||||
DbT::NoteRef,
|
|
||||||
>,
|
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
ParamsT: consensus::Parameters,
|
ParamsT: consensus::Parameters,
|
||||||
|
@ -443,7 +429,6 @@ pub fn create_proposed_transaction<DbT, ParamsT, InputsErrT, FeeRuleT>(
|
||||||
<DbT as WalletCommitmentTrees>::Error,
|
<DbT as WalletCommitmentTrees>::Error,
|
||||||
InputsErrT,
|
InputsErrT,
|
||||||
FeeRuleT::Error,
|
FeeRuleT::Error,
|
||||||
DbT::NoteRef,
|
|
||||||
>,
|
>,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
|
@ -488,8 +473,7 @@ where
|
||||||
let mut builder = Builder::new(params.clone(), proposal.min_target_height(), None);
|
let mut builder = Builder::new(params.clone(), proposal.min_target_height(), None);
|
||||||
|
|
||||||
let checkpoint_depth = wallet_db.get_checkpoint_depth(min_confirmations)?;
|
let checkpoint_depth = wallet_db.get_checkpoint_depth(min_confirmations)?;
|
||||||
|
wallet_db.with_sapling_tree_mut::<_, _, Error<_, _, _, _>>(|sapling_tree| {
|
||||||
wallet_db.with_sapling_tree_mut::<_, _, Error<_, _, _, _, _>>(|sapling_tree| {
|
|
||||||
for selected in proposal.sapling_inputs() {
|
for selected in proposal.sapling_inputs() {
|
||||||
let (note, key, merkle_path) = select_key_for_note(
|
let (note, key, merkle_path) = select_key_for_note(
|
||||||
sapling_tree,
|
sapling_tree,
|
||||||
|
@ -498,7 +482,14 @@ where
|
||||||
&dfvk,
|
&dfvk,
|
||||||
checkpoint_depth,
|
checkpoint_depth,
|
||||||
)?
|
)?
|
||||||
.ok_or(Error::NoteMismatch(selected.internal_note_id().clone()))?;
|
.ok_or_else(|| {
|
||||||
|
Error::NoteMismatch(NoteId {
|
||||||
|
txid: *selected.txid(),
|
||||||
|
protocol: ShieldedProtocol::Sapling,
|
||||||
|
output_index: selected.output_index(),
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
builder.add_sapling_spend(key, selected.diversifier(), note, merkle_path)?;
|
builder.add_sapling_spend(key, selected.diversifier(), note, merkle_path)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -724,7 +715,6 @@ pub fn shield_transparent_funds<DbT, ParamsT, InputsT>(
|
||||||
<DbT as WalletCommitmentTrees>::Error,
|
<DbT as WalletCommitmentTrees>::Error,
|
||||||
InputsT::Error,
|
InputsT::Error,
|
||||||
<InputsT::FeeRule as FeeRule>::Error,
|
<InputsT::FeeRule as FeeRule>::Error,
|
||||||
DbT::NoteRef,
|
|
||||||
>,
|
>,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
|
|
|
@ -445,7 +445,6 @@ impl<Cache> TestState<Cache> {
|
||||||
commitment_tree::Error,
|
commitment_tree::Error,
|
||||||
GreedyInputSelectorError<BalanceError, ReceivedNoteId>,
|
GreedyInputSelectorError<BalanceError, ReceivedNoteId>,
|
||||||
Infallible,
|
Infallible,
|
||||||
ReceivedNoteId,
|
|
||||||
>,
|
>,
|
||||||
> {
|
> {
|
||||||
let params = self.network();
|
let params = self.network();
|
||||||
|
@ -478,7 +477,6 @@ impl<Cache> TestState<Cache> {
|
||||||
commitment_tree::Error,
|
commitment_tree::Error,
|
||||||
InputsT::Error,
|
InputsT::Error,
|
||||||
<InputsT::FeeRule as FeeRule>::Error,
|
<InputsT::FeeRule as FeeRule>::Error,
|
||||||
ReceivedNoteId,
|
|
||||||
>,
|
>,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
|
@ -512,7 +510,6 @@ impl<Cache> TestState<Cache> {
|
||||||
Infallible,
|
Infallible,
|
||||||
InputsT::Error,
|
InputsT::Error,
|
||||||
<InputsT::FeeRule as FeeRule>::Error,
|
<InputsT::FeeRule as FeeRule>::Error,
|
||||||
ReceivedNoteId,
|
|
||||||
>,
|
>,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
|
@ -546,7 +543,6 @@ impl<Cache> TestState<Cache> {
|
||||||
Infallible,
|
Infallible,
|
||||||
InputsT::Error,
|
InputsT::Error,
|
||||||
<InputsT::FeeRule as FeeRule>::Error,
|
<InputsT::FeeRule as FeeRule>::Error,
|
||||||
ReceivedNoteId,
|
|
||||||
>,
|
>,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
|
@ -578,7 +574,6 @@ impl<Cache> TestState<Cache> {
|
||||||
commitment_tree::Error,
|
commitment_tree::Error,
|
||||||
Infallible,
|
Infallible,
|
||||||
FeeRuleT::Error,
|
FeeRuleT::Error,
|
||||||
ReceivedNoteId,
|
|
||||||
>,
|
>,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
|
@ -615,7 +610,6 @@ impl<Cache> TestState<Cache> {
|
||||||
commitment_tree::Error,
|
commitment_tree::Error,
|
||||||
InputsT::Error,
|
InputsT::Error,
|
||||||
<InputsT::FeeRule as FeeRule>::Error,
|
<InputsT::FeeRule as FeeRule>::Error,
|
||||||
ReceivedNoteId,
|
|
||||||
>,
|
>,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
|
|
|
@ -986,7 +986,6 @@ pub(crate) mod tests {
|
||||||
commitment_tree::Error,
|
commitment_tree::Error,
|
||||||
GreedyInputSelectorError<BalanceError, ReceivedNoteId>,
|
GreedyInputSelectorError<BalanceError, ReceivedNoteId>,
|
||||||
Infallible,
|
Infallible,
|
||||||
ReceivedNoteId,
|
|
||||||
>,
|
>,
|
||||||
> {
|
> {
|
||||||
let txid = st.create_spend_to_address(
|
let txid = st.create_spend_to_address(
|
||||||
|
|
Loading…
Reference in New Issue