]> Git Repo - VerusCoin.git/blob - src/wallet/asyncrpcoperation_sendmany.h
Reduce use of global pzcashParams with private member variable
[VerusCoin.git] / src / wallet / asyncrpcoperation_sendmany.h
1 // Copyright (c) 2016 The Zcash developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5 #ifndef ASYNCRPCOPERATION_SENDMANY_H
6 #define ASYNCRPCOPERATION_SENDMANY_H
7
8 #include "asyncrpcoperation.h"
9 #include "amount.h"
10 #include "base58.h"
11 #include "primitives/transaction.h"
12 #include "zcash/JoinSplit.hpp"
13 #include "zcash/Address.hpp"
14 #include "json/json_spirit_value.h"
15 #include "wallet.h"
16
17 #include <tuple>
18
19 // TODO: Compute fee based on a heuristic, e.g. (num tx output * dust threshold) + joinsplit bytes * ?
20 #define ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE   10000
21
22 using namespace libzcash;
23 using namespace json_spirit;
24
25 // A recipient is a tuple of address, amount, memo (optional if zaddr)
26 typedef std::tuple<std::string, CAmount, std::string> SendManyRecipient;
27
28 // Input UTXO is a tuple (quadruple) of txid, vout, amount, coinbase)
29 typedef std::tuple<uint256, int, CAmount, bool> SendManyInputUTXO;
30
31 // Input JSOP is a tuple of JSOutpoint, note and amount
32 typedef std::tuple<JSOutPoint, Note, CAmount> SendManyInputJSOP;
33
34 // Package of info which is passed to perform_joinsplit methods.
35 struct AsyncJoinSplitInfo
36 {
37     std::vector<JSInput> vjsin;
38     std::vector<JSOutput> vjsout;
39     std::vector<Note> notes;
40     CAmount vpub_old = 0;
41     CAmount vpub_new = 0;
42 };
43
44 class AsyncRPCOperation_sendmany : public AsyncRPCOperation {
45 public:
46     AsyncRPCOperation_sendmany(std::string fromAddress, std::vector<SendManyRecipient> tOutputs, std::vector<SendManyRecipient> zOutputs, int minDepth);
47     virtual ~AsyncRPCOperation_sendmany();
48     
49     // We don't want to be copied or moved around
50     AsyncRPCOperation_sendmany(AsyncRPCOperation_sendmany const&) = delete;             // Copy construct
51     AsyncRPCOperation_sendmany(AsyncRPCOperation_sendmany&&) = delete;                  // Move construct
52     AsyncRPCOperation_sendmany& operator=(AsyncRPCOperation_sendmany const&) = delete;  // Copy assign
53     AsyncRPCOperation_sendmany& operator=(AsyncRPCOperation_sendmany &&) = delete;      // Move assign
54     
55     virtual void main();
56
57     bool testmode = false;  // Set to true to disable sending txs and generating proofs
58
59 private:
60     friend class TEST_FRIEND_AsyncRPCOperation_sendmany;    // class for unit testing
61
62     int mindepth_;
63     std::string fromaddress_;
64     bool isfromtaddr_;
65     bool isfromzaddr_;
66     CBitcoinAddress fromtaddr_;
67     PaymentAddress frompaymentaddress_;
68     SpendingKey spendingkey_;
69     
70     uint256 joinSplitPubKey_;
71     unsigned char joinSplitPrivKey_[crypto_sign_SECRETKEYBYTES];
72     ZCJoinSplit *zcashParams_;
73         
74     std::vector<SendManyRecipient> t_outputs_;
75     std::vector<SendManyRecipient> z_outputs_;
76     std::vector<SendManyInputUTXO> t_inputs_;
77     std::vector<SendManyInputJSOP> z_inputs_;
78     
79     CTransaction tx_;
80    
81     void add_taddr_change_output_to_tx(CAmount amount);
82     void add_taddr_outputs_to_tx();
83     bool find_unspent_notes();
84     bool find_utxos(bool fAcceptCoinbase);
85     boost::array<unsigned char, ZC_MEMO_SIZE> get_memo_from_hex_string(std::string s);
86     bool main_impl();
87
88     // JoinSplit without any input notes to spend
89     Object perform_joinsplit(AsyncJoinSplitInfo &);
90
91     // JoinSplit with input notes to spend (JSOutPoints))
92     Object perform_joinsplit(AsyncJoinSplitInfo &, std::vector<JSOutPoint> & );
93
94     // JoinSplit where you have the witnesses and anchor
95     Object perform_joinsplit(
96         AsyncJoinSplitInfo & info,
97         std::vector<boost::optional < ZCIncrementalWitness>> witnesses,
98         uint256 anchor);
99
100     void sign_send_raw_transaction(Object obj);     // throws exception if there was an error
101
102 };
103
104
105 // To test private methods, a friend class can act as a proxy
106 class TEST_FRIEND_AsyncRPCOperation_sendmany {
107 public:
108     std::shared_ptr<AsyncRPCOperation_sendmany> delegate;
109     
110     TEST_FRIEND_AsyncRPCOperation_sendmany(std::shared_ptr<AsyncRPCOperation_sendmany> ptr) : delegate(ptr) {}
111     
112     CTransaction getTx() {
113         return delegate->tx_;
114     }
115     
116     void setTx(CTransaction tx) {
117         delegate->tx_ = tx;
118     }
119     
120     // Delegated methods
121     
122     void add_taddr_change_output_to_tx(CAmount amount) {
123         delegate->add_taddr_change_output_to_tx(amount);
124     }
125     
126     void add_taddr_outputs_to_tx() {
127         delegate->add_taddr_outputs_to_tx();
128     }
129     
130     bool find_unspent_notes() {
131         return delegate->find_unspent_notes();
132     }
133
134     bool find_utxos(bool fAcceptCoinbase) {
135         return delegate->find_utxos(fAcceptCoinbase);
136     }
137     
138     boost::array<unsigned char, ZC_MEMO_SIZE> get_memo_from_hex_string(std::string s) {
139         return delegate->get_memo_from_hex_string(s);
140     }
141     
142     bool main_impl() {
143         return delegate->main_impl();
144     }
145
146     Object perform_joinsplit(AsyncJoinSplitInfo &info) {
147         return delegate->perform_joinsplit(info);
148     }
149
150     Object perform_joinsplit(AsyncJoinSplitInfo &info, std::vector<JSOutPoint> &v ) {
151         return delegate->perform_joinsplit(info, v);
152     }
153
154     Object perform_joinsplit(
155         AsyncJoinSplitInfo & info,
156         std::vector<boost::optional < ZCIncrementalWitness>> witnesses,
157         uint256 anchor)
158     {
159         return delegate->perform_joinsplit(info, witnesses, anchor);
160     }
161
162     void sign_send_raw_transaction(Object obj) {
163         delegate->sign_send_raw_transaction(obj);
164     }
165 };
166
167
168 #endif /* ASYNCRPCOPERATION_SENDMANY_H */
169
This page took 0.029995 seconds and 4 git commands to generate.