Commit Graph

305 Commits

Author SHA1 Message Date
Kris Nuttycombe 4a7dd2bed2 zcash_client_sqlite: Add receiving key scope information to received notes. 2023-12-05 10:49:35 -07:00
Kris Nuttycombe 214a3750c5 zcash_client_backend: Make `Balance` and `AccountBalance` fields private.
Public methods for mutation of these fields have been provided that
perform checking for overflow of the valid monetary range as part
of their operation.
2023-12-04 13:53:27 -07:00
Jack Grigg 0d06e561bb Update Sapling imports to migrate off re-exports at old paths 2023-11-28 03:40:41 +00:00
Kris Nuttycombe 33169719ce zcash_client_backend: Add serialization & parsing for protobuf Proposal representation. 2023-11-09 20:07:16 -07:00
Kris Nuttycombe 27f78d1894 zcash_client_backend: Add Orchard note commitment tree size to block metadata. 2023-11-08 16:46:44 -07:00
Kris Nuttycombe aa063ae3fd zcash_client_backend: Factor out input source traits from `WalletRead`
Prior to this change, it's necessary to implement the entirety of the
`WalletRead` trait in order to be able to use the input selection
functionality provided by `zcash_client_backend::data_api::input_selection`.
This change factors out the minimal operations required for transaction
proposal construction to better reflect the principle of least authority
and make the input selection code reusable in more contexts.

In order to minimize the operations of the newly-created `InputSource`
and `ShieldingSource` traits, this change also removes the
`min_confirmations` field from transaction proposals, in favor of
storing explicit target and anchor heights. This has the effect of
limiting the lifetime of transaction proposals to `PRUNING_DEPTH -
min_confirmations` blocks.
2023-11-08 12:41:49 -07:00
Kris Nuttycombe a0935b5ecd zcash_client_backend: remove `WalletRead::is_valid_account_extfvk` 2023-10-27 15:01:26 -06:00
Kris Nuttycombe f7527e14c9 Use `NonNegativeAmount` for note and utxo value fields 2023-10-23 12:59:26 -06:00
Kris Nuttycombe 29c676ff12
Merge pull request #1009 from tw0po1nt/fix_txn_builder_panic
Gracefully handle when given an Orchard-only UA
2023-10-12 18:15:36 -06:00
Matthew Watt a788cc4c4d Fix merge conflicts 2023-10-12 06:16:22 -05:00
Kris Nuttycombe 1447d8ea01 zcash_client_backend: Move change memos into the `ChangeValue` components of `Proposal`s.
The existing API limited change outputs to having only a single memo
repeated across each change output. This change makes it so that each
proposed change output can have its own associated memo, and leaves it
up to the input selector to determine how requested change memos are
associated with change outputs.
2023-10-11 14:15:19 -06:00
Kris Nuttycombe a2b5c2c784 zcash_client_backend: Use `NonNegativeAmount` for fee and change amounts.
In order to use `uint64` for amounts that must be nonnegative in the
`proposal.proto` file, it is useful to update fee and change computation
to use `NonNegativeAmount` where possible.
2023-10-10 16:12:47 -06:00
Matthew Watt 73f263682e Remove unnecessary local 2023-10-10 07:50:07 -05:00
Matthew Watt 2a4d9e06da Run fmt 2023-10-10 07:47:08 -05:00
Matthew Watt b548e00c10
Update zcash_client_sqlite/src/wallet.rs
Co-authored-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-10-10 06:36:40 -05:00
Matthew Watt 0e5a58b0b0
Update zcash_client_sqlite/src/wallet.rs
Co-authored-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-10-10 06:36:20 -05:00
Matthew Watt c4175342ac Cleanup 2023-10-09 06:46:12 -05:00
Matthew Watt 94f2240e08 Provide PoolType to UnsupportedPoolType case; stylistic changes 2023-10-08 19:05:50 -05:00
Jack Grigg f6d7714efe zcash_client_sqlite: Replace internal height tuples with `RangeInclusive`
We don't need to iterate over them, but the `*_extrema` internal methods
are semantically returning inclusive ranges, and using `RangeInclusive`
avoids bugs where the wrong half of the tuple is used (instead moving
the location of the tuple handling inside the `*_extrema` methods, which
cuts the number of occurrences from linear in the number of function
calls to constant).
2023-09-27 16:34:58 +00:00
Jack Grigg b76b028b3a zcash_client_sqlite: Set chain tip to truncation height when truncating
We don't know at truncation time what the latest chain tip is; the chain
might have reorged to a shorter heavier chain, or the reorg depth might
only be a few blocks. `WalletDb::chain_height` uses the scan queue as
its source of truth, so the `Verify` range we add during truncation
(to prioritise determining whether the rewind was sufficient) can't
extend beyond the block height we know to exist.

The next call to `WalletDb::update_chain_tip` will add additional ranges
beyond this height, which might include a `Verify` range that ends up
merging with the one added during truncation.
2023-09-22 21:09:23 +00:00
Jack Grigg 625a5ff594 zcash_client_sqlite: Remove is-mined checks from transparent balance
The `LEFT OUTER JOIN` was causing the `tx.block IS NULL` check to alias
two cases: an unspent transparent output, and a transparent output spent
in an unmined transaction. The latter only makes sense to include in the
UTXO count if the transaction is expired, and (due to limitations of the
transparent data model in the current wallet) if that expiry won't be
undone by a reorg. We now handle these two cases directly.

Partly reverts 8828276361.
Closes zcash/librustzcash#983.

Co-authored-by: Kris Nuttycombe <kris@nutty.land>
2023-09-22 21:09:23 +00:00
Jack Grigg cd6c962719 zcash_client_sqlite: Write a test for transparent balance behaviour 2023-09-22 17:20:10 +00:00
Jack Grigg 9e4fa96dd7 zcash_client_sqlite: Clean up existing transparent input test 2023-09-22 17:01:00 +00:00
Kris Nuttycombe 2131cd547e zcash_client_sqlite: Return a balance for every account from `get_wallet_summary`
Fixes #948
2023-09-07 11:02:59 -06:00
Kris Nuttycombe f56c5d8f4b Measure scan progress from wallet birthday, not the fully scanned height. 2023-09-06 12:07:18 -06:00
Kris Nuttycombe 65420f59df zcash_client_backend: Add `WalletRead::block_max_scanned`
Fixes #941
2023-09-06 08:49:43 -06:00
str4d 236e9f2cd0
Merge pull request #914 from nuttycom/sbs/nonlinear_sync_aware_balance
Add `get_wallet_summary` to `WalletRead`
2023-09-06 01:04:42 +01:00
str4d 1e12e9d0e6
Clarify zero-conf shielded note behaviour for `get_wallet_summary`
Co-authored-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-09-06 00:18:11 +01:00
Kris Nuttycombe 6cbb107c71 zcash_client_sqlite: allow zero-conf transactions in unshielded balance. 2023-09-05 16:49:36 -06:00
Kris Nuttycombe 7abd1324de Apply suggestions from code review
Co-authored-by: Daira Emma Hopwood <daira@jacaranda.org>
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2023-09-05 16:49:36 -06:00
Kris Nuttycombe f53ea2d778 Add `get_wallet_summary` to `WalletRead`
The intent of this API is to provide a single API which returns in a
single call:

* per-account balances, including pending values
* wallet sync progress

Fixes #865
Fixes #900
2023-09-05 16:06:55 -06:00
Kris Nuttycombe dd60f51d3c Address unresovled code review comments from #907 2023-09-05 09:30:17 -06:00
Kris Nuttycombe 5b3f544102 Apply suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
Co-authored-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-09-01 10:38:20 -06:00
Kris Nuttycombe 0b0274cdc1 zcash_client_backend: Make wallet and account birthday heights available via the data access API 2023-09-01 10:11:43 -06:00
Kris Nuttycombe 459dc49b54 zcash_client_backend: Accept account birthday as a parameter to `create_account`
This also removes the zcash_client_sqlite-specific database
initialization procedures in favor of a standardized approach using the
methods available via the data access API.
2023-09-01 10:08:17 -06:00
Kris Nuttycombe c99c0fc884 zcash_client_sqlite: Enable forced re-scanning of previously scanned ranges.
When `force_rescans` is set to `true` in a call to
`replace_queue_entries`, previously scanned ranges will have their
existing priority overwritten by the scan priority for a provided range;
otherwise, the existing scan priority dominance rule continues to be
enforced. This enables us to require previously scanned ranges be
re-scanned without interfering with higher-priority scan operations.
2023-09-01 08:13:11 -06:00
Kris Nuttycombe 8bcc3c1cc1 Fix unused imports. 2023-08-31 17:56:04 -06:00
Kris Nuttycombe ff8104fa75 zcash_client_sqlite: (testing) Initialize wallets using an `AccountBirthday` struct. 2023-08-28 19:25:52 -06:00
Jack Grigg 578eac15df zcash_client_sqlite: Rename `TestRunner` to `TestState` 2023-08-28 18:54:35 +00:00
Jack Grigg 84a5d5ca94 zcash_client_sqlite: Migrate all tests to `TestBuilder` 2023-08-28 16:55:51 +00:00
Jack Grigg 7ba36c7bd2 zcash_client_sqlite: Move testing helper functions into module 2023-08-25 23:16:37 +00:00
Kris Nuttycombe dee43854cb zcash_client_sqlite: Ensure that target and anchor heights are relative to the chain tip.
Prior to the scan-before-sync changes, the wallet was able to assume
that the maximum scanned block height at the time of the spend was
within a few blocks of the chain tip. However, under linear scanning
after the spend-before-sync changes this invariant no longer holds,
resulting in a situation where in linear sync conditions the wallet
could attempt to create transactions with already-past expiry heights.

This change separates the notion of "chain tip" from "max scanned
height", relying upon the `scan_queue` table to maintain the wallet's
view of the consensus chain height and using information from the
`blocks` table only in situations where the latest and/or earliest
scanned height is required.

As part of this change, the `WalletRead` interface is also modified to
disambiguate these concepts.
2023-08-16 11:53:24 -06:00
Kris Nuttycombe f602ec125d Apply suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
2023-08-07 11:28:28 -06:00
Kris Nuttycombe d3b7dffa3c zcash_client_backend: Restrict use of backend-specific note identifiers.
In general, it is preferable to use globally relevant identifiers where
possible. This PR removes the `WalletRead::TxRef` associated type in
favor of using `TxId` directly for the transaction identifier, and
restricts the use of the `NoteRef` type to those scenarios where the
result of one query is intended to be used directly as the input to
another query.

Closes #834
2023-08-07 11:27:38 -06:00
str4d d7bd566b21
Merge pull request #889 from nuttycom/avoid_checkpoint_add_conflict
zcash_client_sqlite: Ensure that re-adding the same checkpoint information does not cause a database conflict.
2023-08-07 18:18:53 +01:00
Kris Nuttycombe 522f1e4da0 Apply suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
2023-08-07 08:07:21 -06:00
Kris Nuttycombe 027b3c9af8 zcash_client_sqlite: Ensure that re-adding the same checkpoint information does not cause a database conflict.
The `add_checkpoint` method is intended to be idempotent. In the case
that we add a checkpoint at an already-checkpointed block height, we
should only raise an error in the case that the note commitment tree
position or the set of notes spent in the checkpointed block has
changed.
2023-08-04 15:12:04 -06:00
Kris Nuttycombe a5a8562ddd zcash_client_backend, zcash_client_sqlite: Ensure consistency between sent & stored memos. 2023-08-04 14:05:00 -06:00
Kris Nuttycombe f0b2fc3421 zcash_client_sqlite: Store the empty memo as a single 0xf6 byte. 2023-08-02 11:35:27 -06:00
Jack Grigg 0f6970aefd zcash_client_sqlite: Cache statement for `wallet::prune_nullifier_map` 2023-07-25 13:46:44 +00:00
Jack Grigg 0f2689b9c3 zcash_client_sqlite: Maintain a nullifier map from out-of-order scanning
Closes zcash/librustzcash#876.
2023-07-21 18:01:52 +00:00
Jack Grigg fab68d217e zcash_client_sqlite: Fix `WalletDb::block_fully_scanned` implementation 2023-07-21 15:25:39 +00:00
str4d c7b308b312 Rename `VALIDATION_DEPTH` constant to `VERIFY_LOOKAHEAD`
Co-authored-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-07-19 16:03:02 +00:00
Jack Grigg a87dca00e2 Documentation updates, fixes, and cleanups
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2023-07-19 14:54:01 +00:00
Jack Grigg e3aeb63e0a Fix off-by-one bugs with `ScanRange` end bounds
Maximum chain heights are end-inclusive, while `ScanRange` is
end-exclusive.

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2023-07-12 16:27:52 +00:00
Kris Nuttycombe 6fa0b46d8e Implement `suggest_scan_ranges` and `update_chain_tip`
This implements a priority queue backed by the wallet database for scan
range ordering. The scan queue is updated on each call to `put_blocks`
or to `update_chain_tip`.
2023-07-07 20:13:45 -06:00
Jack Grigg 8d792bb7b5 zcash_client_sqlite: Fix `WalletDb::get_transaction` for unmined txs 2023-07-06 22:24:59 +00:00
Kris Nuttycombe 1b5a24a655 Batch data store writes of `put_block`
Instead of calling `put_block` for each block scanned,
`scan_cached_blocks` will now defer the block writes until the scan of a
batch is complete and will perform the block writes and note commitment
tree updates all within a single transaction.

This should ordinarily be fine in terms of memory consumption, because
the block data being saved is pruned to only that spend an output
information that is related to transactions in the wallet, which will
normally be sparse enough that the block range size that is appropriate
for a given platform to run within a batch scanner adequately bounds the
memory consumption of this pruned representation.
2023-07-06 12:13:39 -06:00
Kris Nuttycombe 98147e0d7d Make `from_height` and `limit` parameters to `scan_cached_blocks` non-optional. 2023-07-05 18:56:19 -06:00
Kris Nuttycombe faccf56f04 Split `PoolType` enum into `PoolType` and `ShieldedProtocol`
There are cases where we wish to return informaiton that is relevant to
a specific shielded protocol and `Transparent` is an invalid case. This
is a minor preparatory refactoring that makes this distinction
expressible.
2023-07-05 18:20:43 -06:00
Kris Nuttycombe c13c8c6678 Address comments from code review. 2023-07-03 17:08:01 -06:00
Kris Nuttycombe e3aafdad19 Move chain continuity checks into `scan_block_with_runner`
In preparation for out-of-order range-based scanning, it is necessary
to ensure that the size of the Sapling note commitment tree is carried
along through the scan process and that stored blocks are always
persisted with the updated note commitment tree size.
2023-07-03 10:49:03 -06:00
Kris Nuttycombe e225a54d2e Use `NonZeroU32` for all `min_confirmations` values. 2023-06-30 12:37:41 -06:00
Kris Nuttycombe 8625e9a777 Handle parsing of the not-present `CommitmentTree` sentinel. 2023-06-30 12:08:06 -06:00
Kris Nuttycombe 45177a51e1 Fix off-by-one error in scan_block_with_runner. 2023-06-30 09:30:24 -06:00
Kris Nuttycombe d65b129b43 Apply changelog, documentation & style suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
2023-06-30 09:30:24 -06:00
Kris Nuttycombe 547634e210 zcash_client_sqlite: Move the SqliteShardStore implementation out of the `wallet::sapling` module. 2023-06-29 15:35:18 -06:00
Kris Nuttycombe 425b5e01d7 zcash_client_sqlite: Support shardtree checkpoint functionality 2023-06-29 15:35:18 -06:00
Kris Nuttycombe d11f3d2acc zcash_client_sqlite: Add shardtree truncation & checkpoint operations. 2023-06-29 15:35:18 -06:00
Kris Nuttycombe ade882d01c zcash_client_sqlite: Add shard & checkpoint insertion. 2023-06-29 15:35:18 -06:00
Kris Nuttycombe 3e358bc1c9 zcash_client_backend: Use `shardtree` for note commitments in block scanning.
Also adds a skeleton `zcash_client_sqlite` implementation of
`shardtree::ShardStore` and a skeleton migration for related
database changes.
2023-06-29 15:35:18 -06:00
Kris Nuttycombe 48434bb271 zcash_client_sqlite: Fix SQL identation errors. 2023-06-16 15:09:33 -06:00
Kris Nuttycombe 91f0f03d9d zcash_client_sqlite: Factor out common logic for the representation of stored memos. 2023-06-16 15:09:29 -06:00
Kris Nuttycombe 820e61caaa zcash_client_sqlite: Avoid swallowed errors in max-block-height queries. 2023-06-16 15:09:26 -06:00
Kris Nuttycombe 4b9180cb04 zcash_client_sqlite: Fix details of `put_sent_output` documentation.
Also address a minor naming issue from code review.
2023-06-16 15:09:19 -06:00
Kris Nuttycombe 2674209818 zcash_client_sqlite: Remove the remainder of DataConnStmtCache 2023-06-16 15:09:14 -06:00
Kris Nuttycombe 21f82e539f zcash_client_sqlite: Use cached prepared statements for transparent UTXO operations. 2023-06-16 15:09:02 -06:00
Kris Nuttycombe 9f6831ea75 zcash_client_sqlite: Use cached statements for `insert_address` 2023-06-16 15:08:57 -06:00
Kris Nuttycombe 2354c8b48d zcash_client_sqlite: Use upsert & automatic caching of prepared statements for `put_sent_output` 2023-06-16 15:08:52 -06:00
Kris Nuttycombe 7917effe82 zcash_client_sqlite: Use upsert & automatic caching of prepared statements for `put_received_note` 2023-06-16 15:08:44 -06:00
Kris Nuttycombe 8d86ffd9c4 zcash_client_sqlite: Use `prepare_cached` instead of manual statement caching.
`rusqlite` includes a mechanism for creating prepared statements that
automatically caches them and reuses the caches when possible. This
means that it's unnecessary for us to do our own caching, and also
offers a minor performance improvement in that we don't need to eagerly
prepare statements that we may not execute in the lifetime of a given
`WalletDb` object. It also improves code locality, because the prepared
statements are now adjacent in the code to the parameter assignment
blocks that correspond to those statements.

This also updates a number of `put_x` methods to use sqlite upsert
functionality via the `ON CONFLICT` clause, instead of having to perform
separate inserts and updates.
2023-06-16 15:08:34 -06:00
Kris Nuttycombe 92d08b8504 Move `zcash_client_sqlite` Sapling wallet functionality to a dedicated module. 2023-06-02 10:59:17 -06:00
Kris Nuttycombe d99b4d4d6e Update memo retrieval API to reflect that memos may not be present.
Memos may be absent for both sent and received notes in cases where only
compact block information has been used to populate the wallet database.
This fixes a potential crash in the case that we attempt to decode a
SQLite `NULL` as a byte array. It does, however, introduce a slight
semantic confusion that will need to be considered in the case of future
updates where a note may not have an associated memo; at present, the
only reason we might not have the memo is that we might not have
retrieved the full transaction information from the chain, but in the
future there might be other possible reasons for this absence.

Fixes #384
2023-05-16 10:27:40 -06:00
Kris Nuttycombe 6f2cbfc7de Factor serialization out from merkle tree data structures. 2023-05-04 12:21:47 -06:00
Kris Nuttycombe ec57d23115 Use const generics to set commitment tree & incremental witness depths.
This is in preparation for extraction into the `incrementalmerkletree`
crate, which is not Sapling-specific and therefore cannot hard-code
the depths of these data structures.
2023-05-04 12:16:09 -06:00
Kris Nuttycombe 8e8388a9f6 Add migration to enable storage of unmined change notes. 2023-04-27 17:26:11 -06:00
Kris Nuttycombe fa282695da Store change notes as received for internal transfers. 2023-04-27 14:41:26 -06:00
Kris Nuttycombe f3745c0cb5 Make the internal state of `SentTransactionOutput` private. 2023-04-27 13:07:34 -06:00
Kris Nuttycombe ac3439e65e Rename *rewind* to *truncate* in data_api methods.
This better reflects the semantics of wallet behavior. Also, this
adds a `zcash_client_backend::WalletRead::get_min_unspent_height`
method that replaces the deprecated & removed (and misleadingly
named) `get_rewind_height` method.
2023-04-27 09:12:07 -06:00
Kris Nuttycombe 7405d0cd69 Make internals of `WalletSaplingSpend` and `WalletSaplingOutput` private. 2023-04-26 14:47:10 -06:00
Kris Nuttycombe bfc5b9a5b3 Parameterize `DecryptedOutput` by note type. 2023-04-26 14:47:10 -06:00
Kris Nuttycombe 55c2de0066 Remove the redundant `WalletSaplingOutput::to` and `DecryptedOutput::to` fields. 2023-04-26 14:47:10 -06:00
Kris Nuttycombe c15a185454 Remove deprecated APIs & rename Sapling-specific data structures to include "Sapling"
This helps to clarify the Sapling-specific nature of a number of
operations in wallet code.
2023-04-26 14:47:10 -06:00
Kris Nuttycombe 7d18d1d02a Adds documentation for the `v_transactions` and `v_tx_outputs` views.
This change also settles on `account_value_delta` as the name of the
column in `v_transactions` that describes the transaction's effect on
the value of the associated account.
2023-04-14 14:16:16 -06:00
Jack Grigg 87d0bd7db1 Refactor `sapling::Note`
Its internals are now private, and it stores a `PaymentAddress` (and by
extension the diversifier) instead of `g_d`.
2023-01-24 15:02:27 +00:00
Kris Nuttycombe fff6983512 Replace a number of uses of `assert!(matches!(...))` with `assert_matches!(...)`
The remaining uses of `assert!(matches!(...))` are all in cases where
for some reason the `assert_matches` macro interferes with correct
type inference.
2022-12-08 12:17:14 -07:00
Kris Nuttycombe be4c19d82e Fix transparent balance error when the wallet is empty.
Fixes #724
2022-12-08 12:00:35 -07:00
Kris Nuttycombe 847ba49761 Add dust note detection to change selection.
The change selection algorithm has the most useful information for
determining whether or not a note is dust, so this adds a new error case
to `ChangeError` that allows the change selection to report the presence
of input notes without economic value back to its caller.
2022-11-10 12:18:30 -07:00
Kris Nuttycombe 9a7dc0db84 Add traits for fee estimation and input selection
This adds a set of abstractions that allow wallets to provide
independent strategies for fee estimation and note selection, and
implementations of these strategies that perform these operations in the
same fashion as the existing `spend` and `shield_transparent_funds`
functions.

This required a somewhat hefty rework of the error handling in
zcash_client_backend. It fixes an issue with the error types whereby
callees needed to have a bit too much information about the error
types produced by their callers.

Reflect the updated note selection and error handling in zcash_client_sqlite.
2022-11-10 12:17:59 -07:00
Francisco Gindre 60c153930d get_transparent_balances fails with `no such column`
Error message:

"Error while fetching transparent balances for AccountId(0): no such column: u.received_by_accountt"

Closes #686
2022-10-26 19:09:36 -03:00
Kris Nuttycombe 334383f363 Allow shielding from multiple taddrs within a single transaction. 2022-10-25 13:17:21 -06:00
Kris Nuttycombe efa95fcb39 Add `get_transparent_balances` to data api. 2022-10-25 12:53:54 -06:00
Kris Nuttycombe 8cb16d878e Require a source transparent address to shield transparent funds.
Previously, `shield_transparent_funds` was only shielding funds
associated with the legacy default transparent address. This meant
that transparent funds sent to unified addresses could not reliably
be shielded, as a unified address will frequently be constructed
using a diversifier index greater than zero.

This modifies the `get_transparent_receivers` method to return address
metadata containing the account ID and diversifier index used to derive
each address along with the receiver.
2022-10-25 12:53:54 -06:00
Kris Nuttycombe e13459bd31 Allow insertion of UTXOs associated with the legacy taddr.
The legacy transparent address is never added to the `addresses` table,
but we still need to be able to receive UTXOs sent to that address. So,
we add a special case for when a UTXO matches that legacy address, and
set the account ID to 0 manually.
2022-10-24 17:32:30 -06:00
Kris Nuttycombe c773ea3b3e Make the internals of `WalletTransparentOutput` private. 2022-10-14 12:38:55 -06:00
Kris Nuttycombe 306d37e706 Add a test verifying that update fails on missing associated address. 2022-10-13 09:13:14 -06:00
Kris Nuttycombe f1f9465f37 Remove `received_by_account` field from WalletTransparentOutput
Due to how the wallets retrieved unspent transparent outputs from the
light wallet server, the account associated with a particular UTXO may
not be known by the light wallet. Instead of requiring the caller to
perform a separate lookup and match the address of the received UTXO
with a known account, it's simpler to perform this lookup internally at
the time of insertion or update.

In order to make this operation more efficient, the `addresses_table`
migration is modified to add a column to cache the transparent receiver
so that it may be used in the joins in the UTXO insert and update
operations.
2022-10-12 23:11:39 -06:00
Kris Nuttycombe f7a3b9bda3
Merge pull request #661 from nuttycom/wallet/spend_with_usk
Use unified spending keys for spends & shielding.
2022-10-12 12:15:34 -06:00
Kris Nuttycombe 3c837381db Disallow invalid pool/address combinations with `Recipient`. 2022-10-11 12:52:44 -06:00
Kris Nuttycombe 56b2edd498 Simplify sqlite backend storage for sent notes & utxos.
The currently deprecated implementations of `insert_sent_utxo`,
`insert_sent_note`, `put_sent_utxo` and `put_sent_note` all store to the
same `sent_notes` table internally. Since there's no immediate plan to
change this arrangement, it's better to have a single pair of internal
`insert_sent_output` and `put_sent_output` methods instead.
2022-10-11 08:57:44 -06:00
Kris Nuttycombe 06e43a572a Track inputs sent to wallet-internal recipients.
Ensure that we're attempting trial-decryption with the internal IVK
and correctly track internal vs. external recipients in the wallet
database.
2022-10-11 08:56:22 -06:00
str4d 1dc3cfe724
Merge pull request #657 from nuttycom/wallet/upsert_utxos
Use upsert functionality for transparent UTXOs, rather than delete/repopulate.
2022-10-11 04:17:49 +01:00
Kris Nuttycombe c5b9219f00 Look up the account by the UFVK corresponding to the USK when spending. 2022-10-05 14:35:51 -06:00
Kris Nuttycombe e9406201d5
Merge pull request #663 from nuttycom/sapling_key_cleanup
Fix Sapling key organization.
2022-10-05 14:35:16 -06:00
Kris Nuttycombe 6df6fec860 Add utxo received_by_account data to WalletTransparentOutput
Also, this removes wallet::delete_utxos_above.
2022-10-04 13:34:52 -06:00
Kris Nuttycombe 14787f574f Add a migration to add account ID to the utxos table. 2022-10-04 12:25:56 -06:00
Kris Nuttycombe 60785a1d7a Fix Sapling key organization.
This change moves Sapling-specific key generation into a
submodule of `zip32`. Public reexports are used to keep the
existing API consistent.
2022-10-03 20:28:04 -06:00
Kris Nuttycombe f7aa7b2c84 Upgrade rusqlite to version 0.25 2022-10-03 08:12:37 -06:00
Jack Grigg e54e3f21e8 zcash_client_sqlite: Remove direct ff dependency 2022-10-02 23:16:44 +01:00
Kris Nuttycombe 2c16f78fee zcash_client_sqlite: fix wallet::get_max_account_id
This had the same bug as was fixed in 5b8ec380a0
2022-09-26 16:48:58 -06:00
Kris Nuttycombe 03c3370de8 Fix problems identified by clippy's beta lints 2022-09-17 08:57:37 -06:00
Kris Nuttycombe d0062a87d4 Add WalletWrite::create_account function 2022-09-13 18:58:28 -06:00
Kris Nuttycombe b5908dc964
Merge pull request #632 from nuttycom/data_api/get_next_address
Replace `get_address` with `get_current_address` and `get_next_available_address`
2022-09-12 18:43:38 -06:00
Kris Nuttycombe 03b0ff7e0a Replace `get_address` with `get_current_address` and `get_next_available_address`
This updates the data access API to provide diversified address
functionality. In order to support this change, the addresses table
is updated to store diversifier index information in big-endian order
to allow sorting by diversifier index, and account initialization
is updated to store the diversifier index accordingly. The currently
unreleased `addresses_table` migration is updated to reflect this
change.
2022-09-12 17:58:22 -06:00
Kris Nuttycombe 95610f7b4f Add fee to the transactions table & compute correct net_value in v_transactions. 2022-09-09 16:12:29 -06:00
Jack Grigg 7112ed9da5 zcash_client_backend: Add `WalletReadTransparent::get_transparent_receivers`
Co-authored-by: Kris Nuttycombe <kris@nutty.land>
2022-09-08 20:24:42 +00:00
Jack Grigg 154ef077b4 zcash_client_sqlite: Move address data to an `addresses` table
Closes zcash/librustzcash#489.
2022-09-08 18:50:18 +00:00
Jack Grigg 7d404d2747 zcash_client_sqlite: Fix `WalletRead::get_address` return value
Previously it would return an error if the account identifier did not
correspond to a known account.
2022-09-08 18:49:41 +00:00
Jack Grigg a32714043b zcash_client_backend: Change `WalletRead::get_address` to return UA 2022-09-08 18:49:13 +00:00
Jack Grigg 12e8c53310 zcash_client_sqlite: Add statement helper methods to `DataConnStmtCache`
These methods provide type-safe ways to interact with the prepared
statements.
2022-08-29 19:25:36 +00:00
Kris Nuttycombe 913d572087 Allow the seed to be an optional argument to database init.
This adds a new `WalletMigrationError` type so that we have
a good place to report whether or not the seed is required.
2022-08-18 16:03:20 -06:00
Kris Nuttycombe e9db8d5b01 Use `secrecy` when handling seed phrases in migrations code. 2022-08-18 10:15:58 -06:00
Kris Nuttycombe cdfaa57496 Add migrations to support using UFVKs instead of Sapling extfvks.
Fixes #594
2022-08-18 10:15:58 -06:00
Kris Nuttycombe 7c5b320108 Introduce wallet database schema migrations.
This replaces the current wallet initialization code with a migration
that brings the database up to the state produced by release 0.3.0.
A subsequent commit will add migrations that correctly produce the
database state as of zcash/librustzcash@602270cb1f.

Fixes #369
2022-08-18 10:15:58 -06:00
Jack Grigg 76d015ed11 zcash_client_backend: Fix `UnifiedFullViewingKey` Sapling item type
Per ZIP 316, the Sapling FVK Encoding only includes `(ak, nk, ovk, dk)`
which is a subset of the Sapling `ExtendedFullViewingKey`. We therefore
need to use `DiversifiableFullViewingKey` inside `UnifiedFullViewingKey`
in order to make it parseable from the UFVK string encoding.

`zcash_client_sqlite::wallet::get_extended_full_viewing_keys` has been
removed as a consequence of this change: we can no longer reconstruct
the correct `ExtendedFullViewingKey` from the `UnifiedFullViewingKey`.
2022-06-17 10:03:17 +00:00
Jack Grigg d8b860207d zcash_client_backend: Remove account from `UnifiedFullViewingKey`
The account number is not stored in the ZIP 316 UFVK encoding, and in
general won't necessarily be known (e.g. if a UFVK is being imported
into a wallet).

`zcash_client_sqlite::wallet::init::init_accounts_table` reverts to its
previous behaviour of requiring the provided `&[UnifiedFullViewingKey]`
to be indexed by account number.
2022-06-17 10:03:17 +00:00
Jack Grigg c0e8ee0fa0 zcash_client_backend: Return UFVKs from `WalletRead` instead of ExtFVKs 2022-06-17 10:03:17 +00:00
Jack Grigg 0d0527dbf3 zcash_client_sqlite: Store UFVK/UA instead of Sapling ExtFVK/address
This is a breaking change to the database format. We don't have support
for migrations yet, so existing wallets won't work after this commit
until zcash/librustzcash#489 is done.
2022-06-14 02:18:25 +00:00
Kris Nuttycombe e20de50b84 Make AccountId internal representation private. 2022-02-10 11:30:02 -07:00
Kris Nuttycombe a304c3953b Fix Clippy beta linting complaints. 2022-02-02 16:02:45 -07:00
Kris Nuttycombe 488d13fde3 Do not delete sent note data in rewind. 2022-02-02 12:48:22 -07:00
Kris Nuttycombe 9c2d485c80 Address comments from code review.
Co-authored-by: str4d <jack@electriccoin.co>
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2022-02-02 10:33:41 -07:00
Kris Nuttycombe 3d51c53d68 Address comments from code review.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2022-02-02 10:32:33 -07:00
Kris Nuttycombe 5a75c210f0 Fix order of note deletion relative to transactions being un-mined in rewind. 2022-02-02 10:30:07 -07:00
Kris Nuttycombe e8e5d94ea6 Mark functions that will be made crate-private as deprecated 2022-02-02 10:29:19 -07:00
Kris Nuttycombe 47fc12704b Fix doctest compilation. 2022-01-25 10:01:48 -07:00
Kris Nuttycombe f58d191439 Move transparent account keys to zcash_primitives. 2022-01-25 08:53:51 -07:00
Kris Nuttycombe 37e6d3a2bc Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
Co-authored-by: ying tong <yingtong@z.cash>
2022-01-20 16:43:57 -07:00
Kris Nuttycombe cc58a21ad7 Feature-flag transparent functionality in zcash_client_sqlite
This fixes the wasm32-wasi build issues by excluding the
hdwallet dependencies which are not wasm32-wasi compatible.
2021-10-04 16:53:55 -06:00
Kris Nuttycombe d49a20e6d2 Modify WalletTransparentOutput to wrap TxOut directly. 2021-10-01 11:42:04 -06:00