Commit Graph

75 Commits

Author SHA1 Message Date
Daira Emma Hopwood 6bb8c60f41 Use the new `examine` macro to replace all instances of
`std::visit(match {...}, specimen)`, improving code readability.

For ease of review, this commit includes only obviously correct
transformations that all follow the same pattern.

Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-04-04 21:26:39 +01:00
Kris Nuttycombe 2bc8713925
Use WalletTxBuilder for z_sendmany 2023-03-09 13:04:16 -07:00
Jack Grigg df08281f25 Migrate BLAKE2b Rust FFI to `cxx` 2022-05-27 20:15:05 +00:00
Steven Smith 9993d948ef Load previously persisted sent transaction recipient metadata back into the wallet.
This completes some unfinished work from #5549
2022-03-18 08:03:12 -06:00
Jack Grigg d4078c8d25 Select Orchard receivers preferentially from UAs
The addition of `OrchardRawAddress` to `RecipientAddress` drives most of
the changes in this commit, which enable `z_sendmany` to send funds to
addresses in the Orchard pool once NU5 activates.
2022-02-25 00:52:52 +00:00
Jack Grigg bb4e792c84 Merge branch 'master' into feature/wallet_orchard-orchard_sendmany 2022-02-25 00:33:28 +00:00
Kris Nuttycombe 258f0fc72f Add Orchard components to unified full viewing keys
Co-authored-by: Jack Grigg <jack@z.cash>
2022-02-22 21:08:10 +00:00
therealyingtong 1dae16a41c WriteRecipientMapping: Check that receiver exists in UA.
Co-authored-by: Kris Nuttycombe <kris@nutty.land>
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2022-02-22 11:53:23 +08:00
Kris Nuttycombe 1a1522a4f1 Add Orchard components to unified address
Co-authored-by: Jack Grigg <jack@z.cash>
2022-02-21 17:04:27 +00:00
Kris Nuttycombe d08c992b5e Move parsing of unified addresses to UnifiedAddress.
In cases where we want to be able to decode a string that
is known to be a unified address, it doesn't make sense to have
to route through KeyIO::DecodePaymentAddress and then return
an error depending upon the result type, when it's possible to
provide unified address parsing more directly.

KeyIO::DecodePaymentAddress has been modified to delegate
to UnifiedAddress::Parse
2022-02-17 18:27:15 -07:00
therealyingtong 94ab8e4c77 Implement read and write for (txid, recipient) -> ua mapping.
Co-authored-by: Kris Nuttycombe <kris@nutty.land>
Co-authored-by: Jack Grigg <jack@z.cash>
2022-02-16 20:15:07 +08:00
Kris Nuttycombe 67e871a40c Add test vectors for UFVK derivation
Also update test vectors for unified addresses.
2022-02-12 15:07:05 -07:00
Kris Nuttycombe bf79be2b57 Replace z_getbalanceforaddress with z_getbalanceforviewingkey 2022-02-09 16:58:55 -07:00
Kris Nuttycombe bdcb12e445 Add a first-class type for transparent full viewing keys. 2022-01-27 21:27:43 -07:00
Kris Nuttycombe c21ffff790 Add correct selection of change addresses to z_sendmany
This also alters `TransactionBuilder::SendChangeTo` to take a
`libzcash::ChangeAddress` value and thus avoids the invalid
t-addr case of CTxDestination.
2022-01-27 21:27:43 -07:00
Kris Nuttycombe b93155c460 Add documentation for `UnifiedAddress::GetPreferredRecipientAddress` 2022-01-25 09:15:51 -07:00
Kris Nuttycombe babc11eb52 Use libzcash::RecipientAddress for z_sendmany recipients. 2022-01-24 13:10:31 -07:00
Kris Nuttycombe 0abe07c73b Add RecipientAddress type. 2022-01-24 13:10:31 -07:00
Kris Nuttycombe e419899a29 Add support for unified addresses to CWallet::ToZTXOSelector 2022-01-19 13:53:33 -07:00
Kris Nuttycombe cc392c70a6 Merge branch 'master' into feature/wallet_unified_addresses 2022-01-12 16:54:12 -07:00
Kris Nuttycombe f9477a4499 Use transaction builder for asyncrpcoperation_sendmany.
This replaces the old implementation of asyncrpcoperation_sendmany
with one where all transaction construction is delegated to the
transaction builder. The capabilities of z_sendmany are somewhat
modified in the process:

* z_sendmany now permits sending funds from a Sprout address to
  both transparent and Sapling addresses. PRIVACY NOTE: When
  user sends a Sprout->Sapling transaction, the amount of the
  transaction is publicly revealed.
* z_sendmany no longer supports transactions sending funds into
  the Sprout pool, with the exception of change amounts when
  sending from a Sprout address.
* When sending transparent coinbase funds to a set of shielded
  addresses, the amount sent to recipients must fully consume
  the input value and no change is permitted. This is a slightly
  weaker constraint than was previously implemented; in the past,
  only a single shielded recipient was allowed.
2022-01-11 13:28:34 -07:00
Kris Nuttycombe f5d4f6fef1 Remove `RawAddress`
This adds a new `AddrSet` type for use in note retrieval
as a filter, in place of a heterogeneous list of `RawAddress`
values. `RawAddress` will complicate the handling of addresses
within the wallet after the addition of unified addresses,
because it does not contain transparent receiver types, and
if we retain this polymorphism it means a lot of invalid states
are represented in places we don't want them to be. It's better
to figure out what types of addresses we're working with as soon
as possible after parsing, and use monomorphic calls from there
on in.
2022-01-06 22:29:41 -07:00
Kris Nuttycombe 890e1d841d Add raw transparent address types to PaymentAddress
The addition of `UnifiedAddress` to the `PaymentAddress` type
introduced the need for methods that interact with payment addresses
to support transparent receivers as shielded ones, which is somewhat
inconsistent with previous uses of the `PaymentAddress` type.

This commit adds both `CKeyID` and `CScriptID` as new variants
of the `PaymentAddress` type. Following commits will shift encoding
and decoding to use the `PaymentAddress` type exclusively wherever
possible, rather than the current mix of `CDestination` and
`PaymentAddress` that complicates the wallet codebase.
2022-01-06 13:44:45 -07:00
Kris Nuttycombe c35e2b4438 Remove spurious uses of HaveSpendingKeyForPaymentAddress
There's no need to dispatch through this visitor in cases where
the payment address type is already statically known.
2022-01-06 13:44:45 -07:00
Kris Nuttycombe 62b86d6afc Use CKeyID and CScriptID instead of new P2PKH/P2SHAddress classes. 2022-01-06 13:44:45 -07:00
Kris Nuttycombe b305ad2892 Remove the `InvalidEncoding` type from key & address variants.
The presence of this variant results in a situation where more
of the code than necessary needs to be aware of and handle
decoding failures. This change moves all handling of decoding
failures to the point of decoding.
2022-01-06 13:44:45 -07:00
Kris Nuttycombe 74e4bef6f2 Ensure that unified address metadata is always correctly populated.
This reworks the way that address metadata is added to the wallet
to make adding address metadata to the wallet's in-memory cache
the responsibility of a single method rather than distributed
across multiple places in the code.
2021-12-23 09:33:17 -07:00
Kris Nuttycombe 24e46a16f1 Only derive ZcashdUnifiedFullViewingKey from UnifiedFullViewingKey
This changes ZcashdUnifiedSpendingKey::ToUnifiedFullViewingKey
to return a `UnifiedFullViewingKey` object. This makes the
derivation of ZcashdUnifiedFullViewingKey values more regular,
removing the need to be able to construct these values directly
from the spending key.

This change also modifies ZcashdUnifiedSpendingKey to remove
the `std::optional` wrapper from its member keys. This
optionality is spurious, because it is always possible to
derive a "complete" spending key, and we do not support
import of unified spending keys.
2021-12-22 16:09:17 -07:00
Kris Nuttycombe 009ba76b0e Add test for wallet UA generation & detection. 2021-12-22 15:57:47 -07:00
Kris Nuttycombe ca20cf512c Add key metadata to walletdb. 2021-12-22 15:57:47 -07:00
Kris Nuttycombe e56f252a86 Add unified address tracking to KeyStore 2021-12-22 15:55:36 -07:00
Kris Nuttycombe 4966bf315a Compute key id for UFVKs. 2021-12-15 13:53:10 -07:00
Kris Nuttycombe d1890ebd24 Apply suggestions from code review
Co-authored-by: str4d <jack@electriccoin.co>
2021-12-13 21:03:36 -07:00
Kris Nuttycombe 217c56811d Add UnifiedFullViewingKey type.
This type is backed by the `zcash_address` implementaion of
unified full viewing keys. It is intended for serialization
and parsing of UFVKs, and provides conversion functions that
allow for construction to and from ZcashdUnifiedFullViewingKey
values.
2021-12-13 18:53:27 -07:00
Kris Nuttycombe a2f8e3b56c Use CKeyID and CScriptID instead of new P2PKH/P2SHAddress classes. 2021-11-30 11:24:37 -07:00
Kris Nuttycombe d65200c860 Refine structure of Zcash address generation.
This commit does not include functional changes; it merely
breaks up content previously included in `zcash/address/zip32.h`
into smaller and more focused components.
2021-11-30 11:22:37 -07:00
Kris Nuttycombe 59a4c84112 Adds Orchard Address, IncomingViewingKey, FullViewingKey, and SpendingKey types. 2021-11-24 19:08:17 -07:00
Jack Grigg 2aa9f766b2 Migrate to latest revisions of orchard and the zcash_* crates 2021-09-17 03:56:32 +01:00
Jack Grigg 776e9c5a4b Add support for decoding and encoding Unified Addresses 2021-07-13 03:22:47 +01:00
Jack Grigg 6f1a54cd16 Introduce libzcash::RawAddress type
Currently, `libzcash::PaymentAddress` serves two purposes: it represents
the result of parsing a string encoding provided by a user, and it holds
the possible shielded protocol addresses that can be used in transaction
outputs. In order to add support for Unified Addresses, we split these
purposes across two separate types.

We also add two new visitors to enable converting between these types:

- `RecipientForPaymentAddress` returns the "preferred protocol address"
  that should be used in transaction outputs, or `std::nullopt` if the
  payment address encoding was invalid.

- `GetRawAddresses` returns all protocol addresses contained within the
  given payment address, or an empty set if the payment address encoding
  was invalid.

For the existing address encodings, the implementations of these are
trivial.
2021-07-13 03:21:54 +01:00
Jack Grigg b521cb8932 scripted-diff: Migrate from boost::variant to std::variant
-BEGIN VERIFY SCRIPT-
sed -i 's/boost::variant/std::variant/' ./src/*.h ./src/*.cpp ./src/*/*.h* ./src/*/*.cpp ;
sed -i 's/boost::get<\(.*\)>(&/std::get_if<\1>(\&/' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ./src/*/*/*.cpp ;
sed -i 's/boost::get</std::get</' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ./src/*/*/*.cpp ;
sed -i 's/boost::apply_visitor(/std::visit(/' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ;
sed -i 's/class \(.*\)\b \?: public boost::static_visitor<.*>/class \1/' ./src/*.h ./src/*.cpp ./src/*/*.h* ./src/*/*.cpp ;
sed -i ':a;N;$!ba;s/#include <boost\/variant\(\/.*\)\?.hpp>\n//' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ;
sed -i ':a;N;$!ba;s/#include "boost\/variant\/.*.hpp"\n//' ./src/*/*.cpp ;
-END VERIFY SCRIPT-
2020-12-16 22:49:53 +00:00
Jack Grigg f68c79554f Add <variant> header to files that will need it 2020-12-16 22:48:21 +00:00
Alfredo Garcia 0a6ab8a5ab return address info in z_importviewingkey 2020-04-07 08:38:12 -03:00
Jack Grigg 3c7385bc8e Add encoding and decoding for Sapling extended full viewing keys 2020-02-21 00:59:27 +00:00
Jack Grigg 9658c87d4a Move ZIP 32 classes inside zcash/Address.hpp
This fixes the dependency graph between the general address-handling
logic, ZIP 32, and the core Sapling address classes.
2020-02-20 12:26:58 +00:00
Jack Grigg 42b423c3a5 Move Sprout and Sapling address logic into separate files 2020-02-20 12:26:58 +00:00
Alfredo Garcia 76a43b6790 Return address and type of imported key in z_importkey
Co-authored-by: Dagur Valberg Johannsson <dagurval@pvv.ntnu.no>
2020-01-22 14:41:02 -03:00
Jack Grigg 70b4ad2dcd
wallet: Switch from SaplingSpendingKey to SaplingExtendedSpendingKey
The wallet now only stores Sapling extended spending keys, and thus can
only be used with keys generated from an HDSeed via ZIP 32.

Note that not all Sapling keys in the wallet will correspond to the
wallet's HDSeed, as a standalone Sapling xsk can be imported via
z_importkey. However, it must have been generated from a seed itself,
and thus is more likely to be backed up elsewhere.
2018-09-03 10:45:37 +01:00
Jack Grigg 7614198f9d
ZIP 32 Sapling structs 2018-09-03 10:27:52 +01:00
Jack Grigg 74f5b010df
Rename Serialized*Size -> SerializedSprout*Size 2018-08-03 01:57:40 +01:00