2017-12-11 08:43:09 -08:00
|
|
|
// Copyright (c) 2017 The Zcash developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2019-07-18 07:16:09 -07:00
|
|
|
// file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
2017-12-11 08:43:09 -08:00
|
|
|
|
2020-10-27 04:46:32 -07:00
|
|
|
#ifndef ZCASH_WALLET_ASYNCRPCOPERATION_MERGETOADDRESS_H
|
|
|
|
#define ZCASH_WALLET_ASYNCRPCOPERATION_MERGETOADDRESS_H
|
2017-12-11 08:43:09 -08:00
|
|
|
|
|
|
|
#include "amount.h"
|
|
|
|
#include "asyncrpcoperation.h"
|
|
|
|
#include "primitives/transaction.h"
|
2018-10-18 14:37:58 -07:00
|
|
|
#include "transaction_builder.h"
|
2017-12-11 08:43:09 -08:00
|
|
|
#include "wallet.h"
|
2019-03-05 13:04:23 -08:00
|
|
|
#include "wallet/paymentdisclosure.h"
|
2017-12-11 08:43:09 -08:00
|
|
|
#include "zcash/Address.hpp"
|
|
|
|
#include "zcash/JoinSplit.hpp"
|
|
|
|
|
2018-05-03 03:53:51 -07:00
|
|
|
#include <array>
|
2020-10-20 17:39:13 -07:00
|
|
|
#include <optional>
|
2017-12-11 08:43:09 -08:00
|
|
|
#include <tuple>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include <univalue.h>
|
|
|
|
|
2020-07-31 07:15:04 -07:00
|
|
|
#include <rust/ed25519/types.h>
|
|
|
|
|
2017-12-11 08:43:09 -08:00
|
|
|
using namespace libzcash;
|
|
|
|
|
2018-10-18 14:37:58 -07:00
|
|
|
// Input UTXO is a tuple of txid, vout, amount, script
|
|
|
|
typedef std::tuple<COutPoint, CAmount, CScript> MergeToAddressInputUTXO;
|
2017-12-11 08:43:09 -08:00
|
|
|
|
|
|
|
// Input JSOP is a tuple of JSOutpoint, note, amount, spending key
|
2018-10-18 14:37:58 -07:00
|
|
|
typedef std::tuple<JSOutPoint, SproutNote, CAmount, SproutSpendingKey> MergeToAddressInputSproutNote;
|
|
|
|
|
|
|
|
typedef std::tuple<SaplingOutPoint, SaplingNote, CAmount, SaplingExpandedSpendingKey> MergeToAddressInputSaplingNote;
|
2017-12-11 08:43:09 -08:00
|
|
|
|
|
|
|
// A recipient is a tuple of address, memo (optional if zaddr)
|
|
|
|
typedef std::tuple<std::string, std::string> MergeToAddressRecipient;
|
|
|
|
|
|
|
|
// Package of info which is passed to perform_joinsplit methods.
|
|
|
|
struct MergeToAddressJSInfo {
|
|
|
|
std::vector<JSInput> vjsin;
|
|
|
|
std::vector<JSOutput> vjsout;
|
2018-04-24 21:20:01 -07:00
|
|
|
std::vector<SproutNote> notes;
|
2018-04-25 18:51:17 -07:00
|
|
|
std::vector<SproutSpendingKey> zkeys;
|
2017-12-11 08:43:09 -08:00
|
|
|
CAmount vpub_old = 0;
|
|
|
|
CAmount vpub_new = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A struct to help us track the witness and anchor for a given JSOutPoint
|
|
|
|
struct MergeToAddressWitnessAnchorData {
|
2020-10-20 17:44:15 -07:00
|
|
|
std::optional<SproutWitness> witness;
|
2017-12-11 08:43:09 -08:00
|
|
|
uint256 anchor;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AsyncRPCOperation_mergetoaddress : public AsyncRPCOperation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AsyncRPCOperation_mergetoaddress(
|
2020-10-20 17:44:15 -07:00
|
|
|
std::optional<TransactionBuilder> builder,
|
2017-12-11 08:43:09 -08:00
|
|
|
CMutableTransaction contextualTx,
|
|
|
|
std::vector<MergeToAddressInputUTXO> utxoInputs,
|
2018-10-18 14:37:58 -07:00
|
|
|
std::vector<MergeToAddressInputSproutNote> sproutNoteInputs,
|
|
|
|
std::vector<MergeToAddressInputSaplingNote> saplingNoteInputs,
|
2017-12-11 08:43:09 -08:00
|
|
|
MergeToAddressRecipient recipient,
|
2020-12-17 11:39:58 -08:00
|
|
|
CAmount fee = DEFAULT_FEE,
|
2017-12-11 08:43:09 -08:00
|
|
|
UniValue contextInfo = NullUniValue);
|
|
|
|
virtual ~AsyncRPCOperation_mergetoaddress();
|
|
|
|
|
|
|
|
// We don't want to be copied or moved around
|
|
|
|
AsyncRPCOperation_mergetoaddress(AsyncRPCOperation_mergetoaddress const&) = delete; // Copy construct
|
|
|
|
AsyncRPCOperation_mergetoaddress(AsyncRPCOperation_mergetoaddress&&) = delete; // Move construct
|
|
|
|
AsyncRPCOperation_mergetoaddress& operator=(AsyncRPCOperation_mergetoaddress const&) = delete; // Copy assign
|
|
|
|
AsyncRPCOperation_mergetoaddress& operator=(AsyncRPCOperation_mergetoaddress&&) = delete; // Move assign
|
|
|
|
|
|
|
|
virtual void main();
|
|
|
|
|
|
|
|
virtual UniValue getStatus() const;
|
|
|
|
|
|
|
|
bool testmode = false; // Set to true to disable sending txs and generating proofs
|
|
|
|
|
|
|
|
bool paymentDisclosureMode = false; // Set to true to save esk for encrypted notes in payment disclosure database.
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class TEST_FRIEND_AsyncRPCOperation_mergetoaddress; // class for unit testing
|
|
|
|
|
|
|
|
UniValue contextinfo_; // optional data to include in return value from getStatus()
|
2020-12-17 11:39:58 -08:00
|
|
|
|
2018-10-18 14:37:58 -07:00
|
|
|
bool isUsingBuilder_; // Indicates that no Sprout addresses are involved
|
2017-12-11 08:43:09 -08:00
|
|
|
uint32_t consensusBranchId_;
|
|
|
|
CAmount fee_;
|
|
|
|
int mindepth_;
|
|
|
|
MergeToAddressRecipient recipient_;
|
|
|
|
bool isToTaddr_;
|
|
|
|
bool isToZaddr_;
|
2018-04-20 07:09:23 -07:00
|
|
|
CTxDestination toTaddr_;
|
2017-12-11 08:43:09 -08:00
|
|
|
PaymentAddress toPaymentAddress_;
|
|
|
|
|
2020-07-31 07:15:04 -07:00
|
|
|
Ed25519VerificationKey joinSplitPubKey_;
|
|
|
|
Ed25519SigningKey joinSplitPrivKey_;
|
2017-12-11 08:43:09 -08:00
|
|
|
|
|
|
|
// The key is the result string from calling JSOutPoint::ToString()
|
|
|
|
std::unordered_map<std::string, MergeToAddressWitnessAnchorData> jsopWitnessAnchorMap;
|
|
|
|
|
|
|
|
std::vector<MergeToAddressInputUTXO> utxoInputs_;
|
2018-10-18 14:37:58 -07:00
|
|
|
std::vector<MergeToAddressInputSproutNote> sproutNoteInputs_;
|
|
|
|
std::vector<MergeToAddressInputSaplingNote> saplingNoteInputs_;
|
2017-12-11 08:43:09 -08:00
|
|
|
|
2018-10-18 14:37:58 -07:00
|
|
|
TransactionBuilder builder_;
|
2017-12-11 08:43:09 -08:00
|
|
|
CTransaction tx_;
|
|
|
|
|
2018-05-03 03:53:51 -07:00
|
|
|
std::array<unsigned char, ZC_MEMO_SIZE> get_memo_from_hex_string(std::string s);
|
2017-12-11 08:43:09 -08:00
|
|
|
bool main_impl();
|
|
|
|
|
|
|
|
// JoinSplit without any input notes to spend
|
|
|
|
UniValue perform_joinsplit(MergeToAddressJSInfo&);
|
|
|
|
|
|
|
|
// JoinSplit with input notes to spend (JSOutPoints))
|
|
|
|
UniValue perform_joinsplit(MergeToAddressJSInfo&, std::vector<JSOutPoint>&);
|
|
|
|
|
|
|
|
// JoinSplit where you have the witnesses and anchor
|
|
|
|
UniValue perform_joinsplit(
|
|
|
|
MergeToAddressJSInfo& info,
|
2020-10-20 17:44:15 -07:00
|
|
|
std::vector<std::optional<SproutWitness>> witnesses,
|
2017-12-11 08:43:09 -08:00
|
|
|
uint256 anchor);
|
|
|
|
|
|
|
|
void lock_utxos();
|
|
|
|
|
|
|
|
void unlock_utxos();
|
|
|
|
|
2018-03-15 14:58:31 -07:00
|
|
|
void lock_notes();
|
|
|
|
|
|
|
|
void unlock_notes();
|
|
|
|
|
2017-12-11 08:43:09 -08:00
|
|
|
// payment disclosure!
|
|
|
|
std::vector<PaymentDisclosureKeyInfo> paymentDisclosureData_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// To test private methods, a friend class can act as a proxy
|
|
|
|
class TEST_FRIEND_AsyncRPCOperation_mergetoaddress
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::shared_ptr<AsyncRPCOperation_mergetoaddress> delegate;
|
|
|
|
|
|
|
|
TEST_FRIEND_AsyncRPCOperation_mergetoaddress(std::shared_ptr<AsyncRPCOperation_mergetoaddress> ptr) : delegate(ptr) {}
|
|
|
|
|
|
|
|
CTransaction getTx()
|
|
|
|
{
|
|
|
|
return delegate->tx_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTx(CTransaction tx)
|
|
|
|
{
|
|
|
|
delegate->tx_ = tx;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delegated methods
|
|
|
|
|
2018-05-03 03:53:51 -07:00
|
|
|
std::array<unsigned char, ZC_MEMO_SIZE> get_memo_from_hex_string(std::string s)
|
2017-12-11 08:43:09 -08:00
|
|
|
{
|
|
|
|
return delegate->get_memo_from_hex_string(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool main_impl()
|
|
|
|
{
|
|
|
|
return delegate->main_impl();
|
|
|
|
}
|
|
|
|
|
|
|
|
UniValue perform_joinsplit(MergeToAddressJSInfo& info)
|
|
|
|
{
|
|
|
|
return delegate->perform_joinsplit(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
UniValue perform_joinsplit(MergeToAddressJSInfo& info, std::vector<JSOutPoint>& v)
|
|
|
|
{
|
|
|
|
return delegate->perform_joinsplit(info, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
UniValue perform_joinsplit(
|
|
|
|
MergeToAddressJSInfo& info,
|
2020-10-20 17:44:15 -07:00
|
|
|
std::vector<std::optional<SproutWitness>> witnesses,
|
2017-12-11 08:43:09 -08:00
|
|
|
uint256 anchor)
|
|
|
|
{
|
|
|
|
return delegate->perform_joinsplit(info, witnesses, anchor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_state(OperationStatus state)
|
|
|
|
{
|
|
|
|
delegate->state_.store(state);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-10-27 04:46:32 -07:00
|
|
|
#endif // ZCASH_WALLET_ASYNCRPCOPERATION_MERGETOADDRESS_H
|