2018-04-01 15:05:24 -07:00
|
|
|
// Copyright (c) 2016 The Zcash developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2018-08-01 23:30:45 -07:00
|
|
|
#ifndef BITCOIN_WALLET_ASYNCRPCOPERATION_SENDMANY_H
|
|
|
|
#define BITCOIN_WALLET_ASYNCRPCOPERATION_SENDMANY_H
|
2018-04-01 15:05:24 -07:00
|
|
|
|
2018-04-03 20:14:22 -07:00
|
|
|
#include <asyncrpcoperation.h>
|
|
|
|
#include <amount.h>
|
|
|
|
#include <base58.h>
|
|
|
|
#include <primitives/transaction.h>
|
|
|
|
#include <zcash/JoinSplit.hpp>
|
|
|
|
#include <zcash/Address.hpp>
|
2018-07-11 15:33:58 -07:00
|
|
|
#include <wallet/wallet.h>
|
2018-04-03 20:14:22 -07:00
|
|
|
#include <paymentdisclosure.h>
|
2018-04-01 15:05:24 -07:00
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
#include <univalue.h>
|
|
|
|
|
|
|
|
// Default transaction fee if caller does not specify one.
|
|
|
|
#define ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE 10000
|
2018-07-14 21:50:14 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
using namespace libzcash;
|
|
|
|
|
|
|
|
// A recipient is a tuple of address, amount, memo (optional if zaddr)
|
|
|
|
typedef std::tuple<std::string, CAmount, std::string> SendManyRecipient;
|
|
|
|
|
|
|
|
// Input UTXO is a tuple (quadruple) of txid, vout, amount, coinbase)
|
|
|
|
typedef std::tuple<uint256, int, CAmount, bool> SendManyInputUTXO;
|
|
|
|
|
|
|
|
// Input JSOP is a tuple of JSOutpoint, note and amount
|
|
|
|
typedef std::tuple<JSOutPoint, Note, CAmount> SendManyInputJSOP;
|
|
|
|
|
|
|
|
// Package of info which is passed to perform_joinsplit methods.
|
|
|
|
struct AsyncJoinSplitInfo
|
|
|
|
{
|
|
|
|
std::vector<JSInput> vjsin;
|
|
|
|
std::vector<JSOutput> vjsout;
|
|
|
|
std::vector<Note> notes;
|
|
|
|
CAmount vpub_old = 0;
|
|
|
|
CAmount vpub_new = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A struct to help us track the witness and anchor for a given JSOutPoint
|
|
|
|
struct WitnessAnchorData {
|
|
|
|
boost::optional<ZCIncrementalWitness> witness;
|
|
|
|
uint256 anchor;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AsyncRPCOperation_sendmany : public AsyncRPCOperation {
|
|
|
|
public:
|
|
|
|
AsyncRPCOperation_sendmany(CMutableTransaction contextualTx, std::string fromAddress, std::vector<SendManyRecipient> tOutputs, std::vector<SendManyRecipient> zOutputs, int minDepth, CAmount fee = ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE, UniValue contextInfo = NullUniValue);
|
|
|
|
virtual ~AsyncRPCOperation_sendmany();
|
2018-04-03 20:14:22 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
// We don't want to be copied or moved around
|
|
|
|
AsyncRPCOperation_sendmany(AsyncRPCOperation_sendmany const&) = delete; // Copy construct
|
|
|
|
AsyncRPCOperation_sendmany(AsyncRPCOperation_sendmany&&) = delete; // Move construct
|
|
|
|
AsyncRPCOperation_sendmany& operator=(AsyncRPCOperation_sendmany const&) = delete; // Copy assign
|
|
|
|
AsyncRPCOperation_sendmany& operator=(AsyncRPCOperation_sendmany &&) = delete; // Move assign
|
2018-04-03 20:14:22 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
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_sendmany; // class for unit testing
|
|
|
|
|
|
|
|
UniValue contextinfo_; // optional data to include in return value from getStatus()
|
|
|
|
|
|
|
|
uint32_t consensusBranchId_;
|
|
|
|
CAmount fee_;
|
|
|
|
int mindepth_;
|
|
|
|
std::string fromaddress_;
|
|
|
|
bool isfromtaddr_;
|
|
|
|
bool isfromzaddr_;
|
2018-06-04 11:51:36 -07:00
|
|
|
CTxDestination fromtaddr_;
|
2018-04-01 15:05:24 -07:00
|
|
|
PaymentAddress frompaymentaddress_;
|
|
|
|
SpendingKey spendingkey_;
|
2018-04-03 20:14:22 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
uint256 joinSplitPubKey_;
|
|
|
|
unsigned char joinSplitPrivKey_[crypto_sign_SECRETKEYBYTES];
|
|
|
|
|
|
|
|
// The key is the result string from calling JSOutPoint::ToString()
|
|
|
|
std::unordered_map<std::string, WitnessAnchorData> jsopWitnessAnchorMap;
|
|
|
|
|
|
|
|
std::vector<SendManyRecipient> t_outputs_;
|
|
|
|
std::vector<SendManyRecipient> z_outputs_;
|
|
|
|
std::vector<SendManyInputUTXO> t_inputs_;
|
|
|
|
std::vector<SendManyInputJSOP> z_inputs_;
|
2018-04-03 20:14:22 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
CTransaction tx_;
|
2018-04-03 20:14:22 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
void add_taddr_change_output_to_tx(CAmount amount);
|
|
|
|
void add_taddr_outputs_to_tx();
|
|
|
|
bool find_unspent_notes();
|
|
|
|
bool find_utxos(bool fAcceptCoinbase);
|
2018-04-03 20:14:22 -07:00
|
|
|
std::array<unsigned char, ZC_MEMO_SIZE> get_memo_from_hex_string(std::string s);
|
2018-04-01 15:05:24 -07:00
|
|
|
bool main_impl();
|
|
|
|
|
|
|
|
// JoinSplit without any input notes to spend
|
|
|
|
UniValue perform_joinsplit(AsyncJoinSplitInfo &);
|
|
|
|
|
|
|
|
// JoinSplit with input notes to spend (JSOutPoints))
|
|
|
|
UniValue perform_joinsplit(AsyncJoinSplitInfo &, std::vector<JSOutPoint> & );
|
|
|
|
|
|
|
|
// JoinSplit where you have the witnesses and anchor
|
|
|
|
UniValue perform_joinsplit(
|
|
|
|
AsyncJoinSplitInfo & info,
|
|
|
|
std::vector<boost::optional < ZCIncrementalWitness>> witnesses,
|
|
|
|
uint256 anchor);
|
|
|
|
|
|
|
|
void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error
|
|
|
|
|
|
|
|
// payment disclosure!
|
|
|
|
std::vector<PaymentDisclosureKeyInfo> paymentDisclosureData_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// To test private methods, a friend class can act as a proxy
|
|
|
|
class TEST_FRIEND_AsyncRPCOperation_sendmany {
|
|
|
|
public:
|
|
|
|
std::shared_ptr<AsyncRPCOperation_sendmany> delegate;
|
2018-04-03 20:14:22 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
TEST_FRIEND_AsyncRPCOperation_sendmany(std::shared_ptr<AsyncRPCOperation_sendmany> ptr) : delegate(ptr) {}
|
2018-04-03 20:14:22 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
CTransaction getTx() {
|
|
|
|
return delegate->tx_;
|
|
|
|
}
|
2018-04-03 20:14:22 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
void setTx(CTransaction tx) {
|
|
|
|
delegate->tx_ = tx;
|
|
|
|
}
|
2018-04-03 20:14:22 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
// Delegated methods
|
2018-04-03 20:14:22 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
void add_taddr_change_output_to_tx(CAmount amount) {
|
|
|
|
delegate->add_taddr_change_output_to_tx(amount);
|
|
|
|
}
|
2018-04-03 20:14:22 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
void add_taddr_outputs_to_tx() {
|
|
|
|
delegate->add_taddr_outputs_to_tx();
|
|
|
|
}
|
2018-04-03 20:14:22 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
bool find_unspent_notes() {
|
|
|
|
return delegate->find_unspent_notes();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool find_utxos(bool fAcceptCoinbase) {
|
|
|
|
return delegate->find_utxos(fAcceptCoinbase);
|
|
|
|
}
|
2018-04-03 20:14:22 -07:00
|
|
|
|
|
|
|
std::array<unsigned char, ZC_MEMO_SIZE> get_memo_from_hex_string(std::string s) {
|
2018-04-01 15:05:24 -07:00
|
|
|
return delegate->get_memo_from_hex_string(s);
|
|
|
|
}
|
2018-04-03 20:14:22 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
bool main_impl() {
|
|
|
|
return delegate->main_impl();
|
|
|
|
}
|
|
|
|
|
|
|
|
UniValue perform_joinsplit(AsyncJoinSplitInfo &info) {
|
|
|
|
return delegate->perform_joinsplit(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
UniValue perform_joinsplit(AsyncJoinSplitInfo &info, std::vector<JSOutPoint> &v ) {
|
|
|
|
return delegate->perform_joinsplit(info, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
UniValue perform_joinsplit(
|
|
|
|
AsyncJoinSplitInfo & info,
|
|
|
|
std::vector<boost::optional < ZCIncrementalWitness>> witnesses,
|
|
|
|
uint256 anchor)
|
|
|
|
{
|
|
|
|
return delegate->perform_joinsplit(info, witnesses, anchor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sign_send_raw_transaction(UniValue obj) {
|
|
|
|
delegate->sign_send_raw_transaction(obj);
|
|
|
|
}
|
2018-04-03 20:14:22 -07:00
|
|
|
|
2018-04-01 15:05:24 -07:00
|
|
|
void set_state(OperationStatus state) {
|
|
|
|
delegate->state_.store(state);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-08-01 23:43:37 -07:00
|
|
|
#endif // BITCOIN_WALLET_ASYNCRPCOPERATION_SENDMANY_H
|