/
rpcwallet.cpp
8429 lines (7435 loc) · 358 KB
/
rpcwallet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
// Copyright (c) 2016-2021 The Hush developers
// Distributed under the GPLv3 software license, see the accompanying
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#include "amount.h"
#include "consensus/upgrades.h"
#include "core_io.h"
#include "init.h"
#include "key_io.h"
#include "main.h"
#include "net.h"
#include "netbase.h"
#include "rpc/server.h"
#include "timedata.h"
#include "transaction_builder.h"
#include "util.h"
#include "utilmoneystr.h"
#include "wallet.h"
#include "walletdb.h"
#include "primitives/transaction.h"
#include "zcbenchmarks.h"
#include "script/interpreter.h"
#include "zcash/zip32.h"
#include "zcash/Note.hpp"
#include "utiltime.h"
#include "asyncrpcoperation.h"
#include "asyncrpcqueue.h"
#include "wallet/asyncrpcoperation_mergetoaddress.h"
#include "wallet/asyncrpcoperation_sendmany.h"
#include "wallet/asyncrpcoperation_shieldcoinbase.h"
#include "consensus/upgrades.h"
#include "sodium.h"
#include <stdint.h>
#include <boost/assign/list_of.hpp>
#include <utf8.h>
#include <univalue.h>
#include <numeric>
#include "hush_defs.h"
#include <string.h>
#include "rpchushwallet.h"
using namespace std;
using namespace libzcash;
extern char SMART_CHAIN_SYMBOL[HUSH_SMART_CHAIN_MAXLEN];
extern std::string ASSETCHAINS_OVERRIDE_PUBKEY;
const std::string ADDR_TYPE_SAPLING = "sapling";
const std::string ADDR_TYPE_AMNESIA = "amnesia";
extern int32_t HUSH_INSYNC;
uint32_t hush_segid32(char *coinaddr);
int32_t hush_dpowconfs(int32_t height,int32_t numconfs);
int32_t hush_isnotaryvout(char *coinaddr,uint32_t tiptime); // from ac_private chains only
CBlockIndex *hush_getblockindex(uint256 hash);
extern string randomSietchZaddr();
extern CAmount fConsolidationTxFee;
extern bool fZindex;
extern string randomSietchZaddr();
extern SendManyRecipient newSietchRecipient(string zaddr);
extern string newSietchZaddr();
int64_t nWalletUnlockTime;
static CCriticalSection cs_nWalletUnlockTime;
std::string CCerror;
char *uint256_str(char *dest,uint256 txid);
// Private method:
UniValue z_getoperationstatus_IMPL(const UniValue&, bool);
#define PLAN_NAME_MAX 8
#define VALID_PLAN_NAME(x) (strlen(x) <= PLAN_NAME_MAX)
#define THROW_IF_SYNCING(INSYNC) if (INSYNC == 0) { throw runtime_error(strprintf("%s: Extreme Privacy! Chain still syncing at height %d, aborting to prevent linkability analysis. Please wait until FULLY SYNCED and try again.",__FUNCTION__,chainActive.Tip()->GetHeight())); }
int tx_height( const uint256 &hash );
std::string HelpRequiringPassphrase()
{
return pwalletMain && pwalletMain->IsCrypted()
? "\nRequires wallet passphrase to be set with walletpassphrase call."
: "";
}
bool EnsureWalletIsAvailable(bool avoidException)
{
if (!pwalletMain)
{
if (!avoidException)
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)");
else
return false;
}
return true;
}
void EnsureWalletIsUnlocked()
{
if (pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
}
void Lock2NSPV(const CPubKey &pk)
{
if (!pk.IsValid())
{
ENTER_CRITICAL_SECTION(cs_main);
ENTER_CRITICAL_SECTION(pwalletMain->cs_wallet);
}
}
void Unlock2NSPV(const CPubKey &pk)
{
if (!pk.IsValid())
{
LEAVE_CRITICAL_SECTION(cs_main);
LEAVE_CRITICAL_SECTION(pwalletMain->cs_wallet);
}
}
void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry)
{
int confirms = wtx.GetDepthInMainChain();
entry.push_back(Pair("rawconfirmations", confirms));
if (wtx.IsCoinBase())
entry.push_back(Pair("generated", true));
if (confirms > 0)
{
entry.push_back(Pair("confirmations", hush_dpowconfs((int32_t)hush_blockheight(wtx.hashBlock),confirms)));
entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex()));
entry.push_back(Pair("blockindex", wtx.nIndex));
entry.push_back(Pair("blocktime", (uint64_t)hush_blocktime(wtx.hashBlock)));
entry.push_back(Pair("expiryheight", (int64_t)wtx.nExpiryHeight));
} else entry.push_back(Pair("confirmations", confirms));
uint256 hash = wtx.GetHash();
entry.push_back(Pair("txid", hash.GetHex()));
UniValue conflicts(UniValue::VARR);
BOOST_FOREACH(const uint256& conflict, wtx.GetConflicts())
conflicts.push_back(conflict.GetHex());
entry.push_back(Pair("walletconflicts", conflicts));
entry.push_back(Pair("time", wtx.GetTxTime()));
entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived));
BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue)
entry.push_back(Pair(item.first, item.second));
}
string AccountFromValue(const UniValue& value)
{
string strAccount = value.get_str();
//if (strAccount != "")
// throw JSONRPCError(RPC_WALLET_ACCOUNTS_UNSUPPORTED, "Accounts are unsupported");
return strAccount;
}
char *hush_chainname()
{
return(SMART_CHAIN_SYMBOL);
}
CAmount getBalanceZaddr(std::string address, int minDepth = 1, bool ignoreUnspendable=true) {
CAmount balance = 0;
std::vector<SaplingNoteEntry> saplingEntries;
LOCK2(cs_main, pwalletMain->cs_wallet);
pwalletMain->GetFilteredNotes(saplingEntries, address, minDepth, true, ignoreUnspendable);
for (auto & entry : saplingEntries) {
balance += CAmount(entry.note.value());
}
return balance;
}
void OS_randombytes(unsigned char *x,long xlen);
UniValue getnewaddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if ( HUSH_NSPV_FULLNODE && !EnsureWalletIsAvailable(fHelp) )
return NullUniValue;
if (fHelp || params.size() > 1)
throw runtime_error(
"getnewaddress ( \"account\" )\n"
"\nReturns a new " + strprintf("%s",hush_chainname()) + " address for receiving payments.\n"
"\nArguments:\n"
"1. \"account\" (string, optional) DEPRECATED. If provided, it MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n"
"\nResult:\n"
"\"" + strprintf("%s",hush_chainname()) + "_address\" (string) The new " + strprintf("%s",hush_chainname()) + " address\n"
"\nExamples:\n"
+ HelpExampleCli("getnewaddress", "")
+ HelpExampleRpc("getnewaddress", "")
);
if ( HUSH_NSPV_SUPERLITE )
{
UniValue result(UniValue::VOBJ); uint8_t priv32[32];
#ifndef __WIN32
OS_randombytes(priv32,sizeof(priv32));
#else
randombytes_buf(priv32,sizeof(priv32));
#endif
CKey key;
key.Set(&priv32[0],&priv32[32], true);
CPubKey pubkey = key.GetPubKey();
CKeyID vchAddress = pubkey.GetID();
result.push_back(Pair("wif",EncodeSecret(key)));
result.push_back(Pair("address",EncodeDestination(vchAddress)));
result.push_back(Pair("pubkey",HexStr(pubkey)));
return(result);
}
LOCK2(cs_main, pwalletMain->cs_wallet);
// Parse the account first so we don't generate a key if there's an error
string strAccount;
if (params.size() > 0)
strAccount = AccountFromValue(params[0]);
if (!pwalletMain->IsLocked())
pwalletMain->TopUpKeyPool();
// Generate a new key that is added to wallet
CPubKey newKey;
if (!pwalletMain->GetKeyFromPool(newKey))
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
CKeyID keyID = newKey.GetID();
pwalletMain->SetAddressBook(keyID, strAccount, "receive");
return EncodeDestination(keyID);
}
CTxDestination GetAccountAddress(std::string strAccount, bool bForceNew=false)
{
CWalletDB walletdb(pwalletMain->strWalletFile);
CAccount account;
walletdb.ReadAccount(strAccount, account);
bool bKeyUsed = false;
// Check if the current key has been used
if (account.vchPubKey.IsValid())
{
CScript scriptPubKey = GetScriptForDestination(account.vchPubKey.GetID());
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin();
it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid();
++it)
{
const CWalletTx& wtx = (*it).second;
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
if (txout.scriptPubKey == scriptPubKey)
bKeyUsed = true;
}
}
// Generate a new key
if (!account.vchPubKey.IsValid() || bForceNew || bKeyUsed)
{
if (!pwalletMain->GetKeyFromPool(account.vchPubKey))
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
pwalletMain->SetAddressBook(account.vchPubKey.GetID(), strAccount, "receive");
walletdb.WriteAccount(strAccount, account);
}
return account.vchPubKey.GetID();
}
UniValue getaccountaddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() != 1)
throw runtime_error(
"getaccountaddress \"account\"\n"
"\nDEPRECATED. Returns the current " + strprintf("%s",hush_chainname()) + " address for receiving payments to this account.\n"
"\nArguments:\n"
"1. \"account\" (string, required) MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n"
"\nResult:\n"
"\"" + strprintf("%s",hush_chainname()) + "_address\" (string) The account " + strprintf("%s",hush_chainname()) + " address\n"
"\nExamples:\n"
+ HelpExampleCli("getaccountaddress", "")
+ HelpExampleCli("getaccountaddress", "\"\"")
+ HelpExampleCli("getaccountaddress", "\"myaccount\"")
+ HelpExampleRpc("getaccountaddress", "\"myaccount\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
// Parse the account first so we don't generate a key if there's an error
string strAccount = AccountFromValue(params[0]);
UniValue ret(UniValue::VSTR);
ret = EncodeDestination(GetAccountAddress(strAccount));
return ret;
}
UniValue getrawchangeaddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() > 1)
throw runtime_error(
"getrawchangeaddress\n"
"\nReturns a new " + strprintf("%s",hush_chainname()) + " address, for receiving change.\n"
"This is for use with raw transactions, NOT normal use.\n"
"\nResult:\n"
"\"address\" (string) The address\n"
"\nExamples:\n"
+ HelpExampleCli("getrawchangeaddress", "")
+ HelpExampleRpc("getrawchangeaddress", "")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
if (!pwalletMain->IsLocked())
pwalletMain->TopUpKeyPool();
CReserveKey reservekey(pwalletMain);
CPubKey vchPubKey;
if (!reservekey.GetReservedKey(vchPubKey))
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
reservekey.KeepKey();
CKeyID keyID = vchPubKey.GetID();
return EncodeDestination(keyID);
}
UniValue setaccount(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
"setaccount \"" + strprintf("%s",hush_chainname()) + "_address\" \"account\"\n"
"\nDEPRECATED. Sets the account associated with the given address.\n"
"\nArguments:\n"
"1. \"" + strprintf("%s",hush_chainname()) + "_address\" (string, required) The " + strprintf("%s",hush_chainname()) + " address to be associated with an account.\n"
"2. \"account\" (string, required) MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n"
"\nExamples:\n"
+ HelpExampleCli("setaccount", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" \"tabby\"")
+ HelpExampleRpc("setaccount", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", \"tabby\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
CTxDestination dest = DecodeDestination(params[0].get_str());
if (!IsValidDestination(dest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Hush address!");
}
string strAccount;
if (params.size() > 1)
strAccount = AccountFromValue(params[1]);
// Only add the account if the address is yours.
if (IsMine(*pwalletMain, dest)) {
// Detect when changing the account of an address that is the 'unused current key' of another account:
if (pwalletMain->mapAddressBook.count(dest)) {
std::string strOldAccount = pwalletMain->mapAddressBook[dest].name;
if (dest == GetAccountAddress(strOldAccount)) {
GetAccountAddress(strOldAccount, true);
}
}
pwalletMain->SetAddressBook(dest, strAccount, "receive");
}
else
throw JSONRPCError(RPC_MISC_ERROR, "setaccount can only be used with own address");
return NullUniValue;
}
UniValue getaccount(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() != 1)
throw runtime_error(
"getaccount \"" + strprintf("%s",hush_chainname()) + "_address\"\n"
"\nDEPRECATED. Returns the account associated with the given address.\n"
"\nArguments:\n"
"1. \"" + strprintf("%s",hush_chainname()) + "_address\" (string, required) The " + strprintf("%s",hush_chainname()) + " address for account lookup.\n"
"\nResult:\n"
"\"accountname\" (string) the account address\n"
"\nExamples:\n"
+ HelpExampleCli("getaccount", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\"")
+ HelpExampleRpc("getaccount", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
CTxDestination dest = DecodeDestination(params[0].get_str());
if (!IsValidDestination(dest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Hush address!");
}
std::string strAccount;
std::map<CTxDestination, CAddressBookData>::iterator mi = pwalletMain->mapAddressBook.find(dest);
if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.name.empty()) {
strAccount = (*mi).second.name;
}
return strAccount;
}
UniValue listaddresses(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() != 0)
throw runtime_error(
"listaddresses\n"
"\nResult:\n"
"[ (json array of string)\n"
" \"" + strprintf("%s",hush_chainname()) + "_address\" (string) a " + strprintf("%s",hush_chainname()) + " address\n"
" ,...\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("listaddresses", "")
+ HelpExampleRpc("listaddresses", "")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
// Find all taddrs
UniValue ret(UniValue::VARR);
for (const std::pair<CTxDestination, CAddressBookData>& item : pwalletMain->mapAddressBook) {
const CTxDestination& dest = item.first;
const std::string& strName = item.second.name;
ret.push_back(EncodeDestination(dest));
}
return ret;
}
UniValue getaddressesbyaccount(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() != 1)
throw runtime_error(
"getaddressesbyaccount \"account\"\n"
"\nDEPRECATED. Returns the list of addresses for the given account.\n"
"\nArguments:\n"
"1. \"account\" (string, required) MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n"
"\nResult:\n"
"[ (json array of string)\n"
" \"" + strprintf("%s",hush_chainname()) + "_address\" (string) a " + strprintf("%s",hush_chainname()) + " address associated with the given account\n"
" ,...\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("getaddressesbyaccount", "\"\"")
+ HelpExampleRpc("getaddressesbyaccount", "\"\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
string strAccount = AccountFromValue(params[0]);
// Find all addresses that have the given account
UniValue ret(UniValue::VARR);
for (const std::pair<CTxDestination, CAddressBookData>& item : pwalletMain->mapAddressBook) {
const CTxDestination& dest = item.first;
const std::string& strName = item.second.name;
if (strName == strAccount) {
ret.push_back(EncodeDestination(dest));
}
}
return ret;
}
static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew,uint8_t *opretbuf,int32_t opretlen,long int opretValue)
{
CAmount curBalance = pwalletMain->GetBalance();
// Check amount
if (nValue <= 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount");
//fprintf(stderr,"nValue %.8f vs curBalance %.8f\n",(double)nValue/COIN,(double)curBalance/COIN);
if (nValue > curBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
// Parse Hush address
CScript scriptPubKey = GetScriptForDestination(address);
// Create and send the transaction
CReserveKey reservekey(pwalletMain);
CAmount nFeeRequired;
std::string strError;
vector<CRecipient> vecSend;
int nChangePosRet = -1;
CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount};
vecSend.push_back(recipient);
if ( opretlen > 0 && opretbuf != 0 )
{
CScript opretpubkey; int32_t i; uint8_t *ptr;
opretpubkey.resize(opretlen);
for (i=0; i<opretlen; i++)
{
opretpubkey[i] = opretbuf[i];
//printf("%02x",ptr[i]);
}
//printf(" opretbuf[%d]\n",opretlen);
CRecipient opret = { opretpubkey, opretValue, false };
vecSend.push_back(opret);
}
if (!pwalletMain->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strError)) {
if (!fSubtractFeeFromAmount && nValue + nFeeRequired > pwalletMain->GetBalance())
strError = strprintf("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!", FormatMoney(nFeeRequired));
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
if (!pwalletMain->CommitTransaction(wtxNew, reservekey))
throw JSONRPCError(RPC_WALLET_ERROR, "Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here.");
}
UniValue sendtoaddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() < 2 || params.size() > 5)
throw runtime_error(
"sendtoaddress \"" + strprintf("%s",hush_chainname()) + "_address\" amount ( \"comment\" \"comment-to\" subtractfeefromamount )\n"
"\nSend an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001\n"
+ HelpRequiringPassphrase() +
"\nArguments:\n"
"1. \"" + strprintf("%s",hush_chainname()) + "_address\" (string, required) The " + strprintf("%s",hush_chainname()) + " address to send to.\n"
"2. \"amount\" (numeric, required) The amount in " + strprintf("%s",hush_chainname()) + " to send. eg 0.1\n"
"3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
" This is not part of the transaction, just kept in your wallet.\n"
"4. \"comment-to\" (string, optional) A comment to store the name of the person or organization \n"
" to which you're sending the transaction. This is not part of the \n"
" transaction, just kept in your wallet.\n"
"5. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n"
" The recipient will receive less " + strprintf("%s",hush_chainname()) + " than you enter in the amount field.\n"
"\nResult:\n"
"\"transactionid\" (string) The transaction id.\n"
"\nExamples:\n"
+ HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1")
+ HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1 \"donation\" \"seans outpost\"")
+ HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1 \"\" \"\" true")
+ HelpExampleRpc("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 0.1, \"donation\", \"seans outpost\"")
);
if ( ASSETCHAINS_PRIVATE != 0 && AmountFromValue(params[1]) > 0 )
{
if ( hush_isnotaryvout((char *)params[0].get_str().c_str(),chainActive.LastTip()->nTime) == 0 )
{
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid " + strprintf("%s",hush_chainname()) + " address");
}
}
LOCK2(cs_main, pwalletMain->cs_wallet);
CTxDestination dest = DecodeDestination(params[0].get_str());
if (!IsValidDestination(dest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Hush address!");
}
// Amount
CAmount nAmount = AmountFromValue(params[1]);
if (nAmount <= 0)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
// Wallet comments
CWalletTx wtx;
if (params.size() > 2 && !params[2].isNull() && !params[2].get_str().empty())
wtx.mapValue["comment"] = params[2].get_str();
if (params.size() > 3 && !params[3].isNull() && !params[3].get_str().empty())
wtx.mapValue["to"] = params[3].get_str();
bool fSubtractFeeFromAmount = false;
if (params.size() > 4)
fSubtractFeeFromAmount = params[4].get_bool();
EnsureWalletIsUnlocked();
SendMoney(dest, nAmount, fSubtractFeeFromAmount, wtx,0,0,0);
return wtx.GetHash().GetHex();
}
#include "hush_defs.h"
#define HUSH_KVPROTECTED 1
#define HUSH_KVBINARY 2
#define HUSH_KVDURATION 1440
#define DRAGON_MAXSCRIPTSIZE 10001
uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pubkey37[37],char *coinaddr,int32_t height,char *base,int64_t fiatoshis);
int32_t hush_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen);
extern int32_t HUSH_PAX;
int32_t hush_is_issuer();
int32_t dragon_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp);
int32_t hush_isrealtime(int32_t *hushheightp);
int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base);
int32_t hush_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[DRAGON_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen);
int32_t hush_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize);
uint64_t hush_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen);
uint256 hush_kvsig(uint8_t *buf,int32_t len,uint256 privkey);
int32_t hush_kvduration(uint32_t flags);
uint256 hush_kvprivkey(uint256 *pubkeyp,char *passphrase);
int32_t hush_kvsigverify(uint8_t *buf,int32_t len,uint256 _pubkey,uint256 sig);
UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
static uint256 zeroes;
CWalletTx wtx; UniValue ret(UniValue::VOBJ);
uint8_t keyvalue[DRAGON_MAXSCRIPTSIZE*8],opretbuf[DRAGON_MAXSCRIPTSIZE*8]; int32_t i,coresize,haveprivkey,duration,opretlen,height; uint16_t keylen=0,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags,n; struct hush_kv *ptr; uint64_t fee; uint256 privkey,pubkey,refpubkey,sig;
if (fHelp || params.size() < 3 )
throw runtime_error(
"kvupdate key \"value\" days passphrase\n"
"\nStore a key value. This feature is only available for asset chains.\n"
"\nArguments:\n"
"1. key (string, required) key\n"
"2. \"value\" (string, required) value\n"
"3. days (numeric, required) amount of days(1440 blocks/day) before the key expires. Minimum 1 day\n"
"4. passphrase (string, optional) passphrase required to update this key\n"
"\nResult:\n"
"{\n"
" \"coin\": \"xxxxx\", (string) chain the key is stored on\n"
" \"height\": xxxxx, (numeric) height the key was stored at\n"
" \"expiration\": xxxxx, (numeric) height the key will expire\n"
" \"flags\": x, (string) amount of days the key will be stored \n"
" \"key\": \"xxxxx\", (numeric) stored key\n"
" \"keylen\": xxxxx, (numeric) length of the key\n"
" \"value\": \"xxxxx\" (numeric) stored value\n"
" \"valuesize\": xxxxx, (string) length of the stored value\n"
" \"fee\": xxxxx (string) transaction fee paid to store the key\n"
" \"txid\": \"xxxxx\" (string) transaction id\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("kvupdate", "examplekey \"examplevalue\" 2 examplepassphrase")
+ HelpExampleRpc("kvupdate", "\"examplekey\",\"examplevalue\",\"2\",\"examplepassphrase\"")
);
if (!EnsureWalletIsAvailable(fHelp))
return 0;
if ( SMART_CHAIN_SYMBOL[0] == 0 )
return(0);
haveprivkey = 0;
memset(&sig,0,sizeof(sig));
memset(&privkey,0,sizeof(privkey));
memset(&refpubkey,0,sizeof(refpubkey));
memset(&pubkey,0,sizeof(pubkey));
if ( (n= (int32_t)params.size()) >= 3 )
{
flags = atoi(params[2].get_str().c_str());
//printf("flags.%d (%s) n.%d\n",flags,params[2].get_str().c_str(),n);
} else flags = 0;
if ( n >= 4 )
privkey = hush_kvprivkey(&pubkey,(char *)(n >= 4 ? params[3].get_str().c_str() : "password"));
haveprivkey = 1;
flags |= 1;
/*for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&privkey)[i]);
printf(" priv, ");
for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&pubkey)[i]);
printf(" pubkey, privkey derived from (%s)\n",(char *)params[3].get_str().c_str());
*/
LOCK2(cs_main, pwalletMain->cs_wallet);
if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 )
{
key = (uint8_t *)params[0].get_str().c_str();
if ( n >= 2 && params[1].get_str().c_str() != 0 )
{
value = (uint8_t *)params[1].get_str().c_str();
valuesize = (int32_t)strlen(params[1].get_str().c_str());
}
memcpy(keyvalue,key,keylen);
if ( (refvaluesize= hush_kvsearch(&refpubkey,chainActive.LastTip()->GetHeight(),&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 )
{
if ( (tmpflags & HUSH_KVPROTECTED) != 0 )
{
if ( memcmp(&refpubkey,&pubkey,sizeof(refpubkey)) != 0 )
{
ret.push_back(Pair("error",(char *)"cant modify write once key without passphrase"));
return ret;
}
}
if ( keylen+refvaluesize <= sizeof(keyvalue) )
{
sig = hush_kvsig(keyvalue,keylen+refvaluesize,privkey);
if ( hush_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 )
{
ret.push_back(Pair("error",(char *)"error verifying sig, passphrase is probably wrong"));
printf("VERIFY ERROR\n");
return ret;
} // else printf("verified immediately\n");
}
}
//for (i=0; i<32; i++)
// printf("%02x",((uint8_t *)&sig)[i]);
//printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize);
ret.push_back(Pair("coin",(char *)(SMART_CHAIN_SYMBOL[0] == 0 ? "HUSH3" : SMART_CHAIN_SYMBOL)));
height = chainActive.LastTip()->GetHeight();
if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 )
ret.push_back(Pair("owner",refpubkey.GetHex()));
ret.push_back(Pair("height", (int64_t)height));
duration = hush_kvduration(flags); //((flags >> 2) + 1) * HUSH_KVDURATION;
ret.push_back(Pair("expiration", (int64_t)(height+duration)));
ret.push_back(Pair("flags",(int64_t)flags));
ret.push_back(Pair("key",params[0].get_str()));
ret.push_back(Pair("keylen",(int64_t)keylen));
if ( n >= 2 && params[1].get_str().c_str() != 0 )
{
ret.push_back(Pair("value",params[1].get_str()));
ret.push_back(Pair("valuesize",valuesize));
}
dragon_rwnum(1,&keyvalue[0],sizeof(keylen),&keylen);
dragon_rwnum(1,&keyvalue[2],sizeof(valuesize),&valuesize);
dragon_rwnum(1,&keyvalue[4],sizeof(height),&height);
dragon_rwnum(1,&keyvalue[8],sizeof(flags),&flags);
memcpy(&keyvalue[12],key,keylen);
if ( value != 0 )
memcpy(&keyvalue[12 + keylen],value,valuesize);
coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize);
if ( haveprivkey != 0 )
{
for (i=0; i<32; i++)
keyvalue[12 + keylen + valuesize + i] = ((uint8_t *)&pubkey)[i];
coresize += 32;
if ( refvaluesize >=0 )
{
for (i=0; i<32; i++)
keyvalue[12 + keylen + valuesize + 32 + i] = ((uint8_t *)&sig)[i];
coresize += 32;
}
}
if ( (opretlen= hush_opreturnscript(opretbuf,'K',keyvalue,coresize)) == 40 )
opretlen++;
//for (i=0; i<opretlen; i++)
// printf("%02x",opretbuf[i]);
//printf(" opretbuf keylen.%d valuesize.%d height.%d (%02x %02x %02x)\n",*(uint16_t *)&keyvalue[0],*(uint16_t *)&keyvalue[2],*(uint32_t *)&keyvalue[4],keyvalue[8],keyvalue[9],keyvalue[10]);
EnsureWalletIsUnlocked();
fee = hush_kvfee(flags,opretlen,keylen);
ret.push_back(Pair("fee",(double)fee/COIN));
CBitcoinAddress destaddress(CRYPTO555_HUSHADDR);
if (!destaddress.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid destination address!");
SendMoney(destaddress.Get(),10000,false,wtx,opretbuf,opretlen,fee);
ret.push_back(Pair("txid",wtx.GetHash().GetHex()));
} else ret.push_back(Pair("error",(char *)"null key"));
return ret;
}
UniValue paxdeposit(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
uint64_t available,deposited,issued,withdrawn,approved,redeemed,seed,puposhis = 0; int32_t height; char destaddr[64]; uint8_t i,pubkey37[33];
bool fSubtractFeeFromAmount = false;
if ( HUSH_PAX == 0 )
{
throw runtime_error("paxdeposit disabled without -pax");
}
if ( hush_is_issuer() != 0 )
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxdeposit only from KYC");
if (!EnsureWalletIsAvailable(fHelp))
throw runtime_error("paxdeposit needs wallet"); //return Value::null;
if (fHelp || params.size() != 3)
throw runtime_error("paxdeposit address fiatoshis base");
LOCK2(cs_main, pwalletMain->cs_wallet);
CBitcoinAddress address(params[0].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN;
std::string base = params[2].get_str();
std::string dest;
height = chainActive.LastTip()->GetHeight();
if ( pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,(char *)base.c_str()) != 0 || available < fiatoshis )
{
fprintf(stderr,"available %llu vs fiatoshis %llu\n",(long long)available,(long long)fiatoshis);
throw runtime_error("paxdeposit not enough available inventory");
}
puposhis = PAX_fiatdest(&seed,0,destaddr,pubkey37,(char *)params[0].get_str().c_str(),height,(char *)base.c_str(),fiatoshis);
dest.append(destaddr);
CBitcoinAddress destaddress(CRYPTO555_HUSHADDR);
if (!destaddress.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address");
for (i=0; i<33; i++)
fprintf(stderr,"%02x",pubkey37[i]);
fprintf(stderr," ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) puposhis.%llu seed.%llx\n",height,(char *)params[0].get_str().c_str(),(char *)base.c_str(),(long long)fiatoshis,destaddr,(long long)puposhis,(long long)seed);
EnsureWalletIsUnlocked();
CWalletTx wtx;
uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = puposhis / 1000;
if ( fee < 10000 )
fee = 10000;
dragon_rwnum(1,&pubkey37[33],sizeof(height),&height);
opretlen = hush_opreturnscript(opretbuf,'D',pubkey37,37);
SendMoney(address.Get(),fee,fSubtractFeeFromAmount,wtx,opretbuf,opretlen,puposhis);
return wtx.GetHash().GetHex();
}
UniValue paxwithdraw(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
CWalletTx wtx; std::string dest; int32_t hushheight; uint64_t seed,puposhis = 0; char destaddr[64]; uint8_t i,pubkey37[37]; bool fSubtractFeeFromAmount = false;
if ( SMART_CHAIN_SYMBOL[0] == 0 )
return(0);
if (!EnsureWalletIsAvailable(fHelp))
return 0;
throw runtime_error("paxwithdraw deprecated");
if (fHelp || params.size() != 2)
throw runtime_error("paxwithdraw address fiatamount");
if ( hush_isrealtime(&hushheight) == 0 )
return(0);
LOCK2(cs_main, pwalletMain->cs_wallet);
CBitcoinAddress address(params[0].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN;
puposhis = PAX_fiatdest(&seed,1,destaddr,pubkey37,(char *)params[0].get_str().c_str(),hushheight,SMART_CHAIN_SYMBOL,fiatoshis);
dest.append(destaddr);
CBitcoinAddress destaddress(CRYPTO555_HUSHADDR);
if (!destaddress.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address");
for (i=0; i<33; i++)
printf("%02x",pubkey37[i]);
printf(" hushheight.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) puposhis.%llu seed.%llx\n",hushheight,(char *)params[0].get_str().c_str(),SMART_CHAIN_SYMBOL,(long long)fiatoshis,destaddr,(long long)puposhis,(long long)seed);
EnsureWalletIsUnlocked();
uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = fiatoshis / 1000;
if ( fee < 10000 )
fee = 10000;
dragon_rwnum(1,&pubkey37[33],sizeof(hushheight),&hushheight);
opretlen = hush_opreturnscript(opretbuf,'W',pubkey37,37);
SendMoney(destaddress.Get(),fee,fSubtractFeeFromAmount,wtx,opretbuf,opretlen,fiatoshis);
return wtx.GetHash().GetHex();
}
UniValue listaddressgroupings(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp)
throw runtime_error(
"listaddressgroupings\n"
"\nLists groups of addresses which have had their common ownership\n"
"made public by common use as inputs or as the resulting change\n"
"in past transactions\n"
"\nResult:\n"
"[\n"
" [\n"
" [\n"
" \"" + strprintf("%s",hush_chainname()) + " address\", (string) The " + strprintf("%s",hush_chainname()) + " address\n"
" amount, (numeric) The amount in " + strprintf("%s",hush_chainname()) + "\n"
" \"account\" (string, optional) The account (DEPRECATED)\n"
" ]\n"
" ,...\n"
" ]\n"
" ,...\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("listaddressgroupings", "")
+ HelpExampleRpc("listaddressgroupings", "")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
UniValue jsonGroupings(UniValue::VARR);
std::map<CTxDestination, CAmount> balances = pwalletMain->GetAddressBalances();
for (const std::set<CTxDestination>& grouping : pwalletMain->GetAddressGroupings()) {
UniValue jsonGrouping(UniValue::VARR);
for (const CTxDestination& address : grouping)
{
UniValue addressInfo(UniValue::VARR);
addressInfo.push_back(EncodeDestination(address));
addressInfo.push_back(ValueFromAmount(balances[address]));
{
if (pwalletMain->mapAddressBook.find(address) != pwalletMain->mapAddressBook.end()) {
addressInfo.push_back(pwalletMain->mapAddressBook.find(address)->second.name);
}
}
jsonGrouping.push_back(addressInfo);
}
jsonGroupings.push_back(jsonGrouping);
}
return jsonGroupings;
}
UniValue signmessage(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() != 2)
throw runtime_error(
"signmessage \"t-addr\" \"message\"\n"
"\nSign a message with the private key of a t-addr"
+ HelpRequiringPassphrase() + "\n"
"\nArguments:\n"
"1. \"t-addr\" (string, required) The transparent address to use for the private key.\n"
"2. \"message\" (string, required) The message to create a signature of.\n"
"\nResult:\n"
"\"signature\" (string) The signature of the message encoded in base 64\n"
"\nExamples:\n"
"\nUnlock the wallet for 30 seconds\n"
+ HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
"\nCreate the signature\n"
+ HelpExampleCli("signmessage", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" \"my message\"") +
"\nVerify the signature\n"
+ HelpExampleCli("verifymessage", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" \"signature\" \"my message\"") +
"\nAs json rpc\n"
+ HelpExampleRpc("signmessage", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", \"my message\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
EnsureWalletIsUnlocked();
string strAddress = params[0].get_str();
string strMessage = params[1].get_str();
CTxDestination dest = DecodeDestination(strAddress);
if (!IsValidDestination(dest)) {
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
}
const CKeyID *keyID = boost::get<CKeyID>(&dest);
if (!keyID) {
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
}
CKey key;
if (!pwalletMain->GetKey(*keyID, key)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available");
}
CHashWriter ss(SER_GETHASH, 0);
ss << strMessageMagic;
ss << strMessage;
vector<unsigned char> vchSig;
if (!key.SignCompact(ss.GetHash(), vchSig))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
return EncodeBase64(&vchSig[0], vchSig.size());
}
UniValue getreceivedbyaddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
"getreceivedbyaddress \"" + strprintf("%s",hush_chainname()) + "_address\" ( minconf )\n"
"\nReturns the total amount received by the given " + strprintf("%s",hush_chainname()) + " address in transactions with at least minconf confirmations.\n"
"\nArguments:\n"
"1. \"" + strprintf("%s",hush_chainname()) + "_address\" (string, required) The " + strprintf("%s",hush_chainname()) + " address for transactions.\n"
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
"\nResult:\n"
"amount (numeric) The total amount in " + strprintf("%s",hush_chainname()) + " received at this address.\n"
"\nExamples:\n"
"\nThe amount from transactions with at least 1 confirmation\n"
+ HelpExampleCli("getreceivedbyaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\"") +
"\nThe amount including unconfirmed transactions, zero confirmations\n"
+ HelpExampleCli("getreceivedbyaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0") +
"\nThe amount with at least 6 confirmations, very safe\n"
+ HelpExampleCli("getreceivedbyaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 6") +
"\nAs a json rpc call\n"
+ HelpExampleRpc("getreceivedbyaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 6")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
// Bitcoin address
CTxDestination dest = DecodeDestination(params[0].get_str());
if (!IsValidDestination(dest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Hush address!");
}
CScript scriptPubKey = GetScriptForDestination(dest);
if (!IsMine(*pwalletMain, scriptPubKey)) {
return ValueFromAmount(0);
}
// Minimum confirmations
int nMinDepth = 1;
if (params.size() > 1)
nMinDepth = params[1].get_int();
// Tally