-
Notifications
You must be signed in to change notification settings - Fork 262
Expand file tree
/
Copy pathrpcmisc.cpp
More file actions
1131 lines (1025 loc) · 39.1 KB
/
rpcmisc.cpp
File metadata and controls
1131 lines (1025 loc) · 39.1 KB
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) 2014-2016 The Bitcoin Core developers
// Original code was distributed under the MIT software license.
// Copyright (c) 2014-2017 Coin Sciences Ltd
// MultiChain code distributed under the GPLv3 license, see COPYING file.
#include "structs/base58.h"
#include "version/clientversion.h"
#include "core/init.h"
#include "core/main.h"
#include "net/net.h"
#include "net/netbase.h"
#include "rpc/rpcserver.h"
#include "utils/timedata.h"
#include "utils/util.h"
#ifdef ENABLE_WALLET
#include "wallet/wallet.h"
#include "wallet/walletdb.h"
#endif
#include <stdint.h>
/* MCHN START */
#include "multichain/multichain.h"
#include "wallet/wallettxs.h"
std::string BurnAddress(const std::vector<unsigned char>& vchVersion);
std::string SetBannedTxs(std::string txlist);
std::string SetLockedBlock(std::string hash);
/* MCHN END */
#include <boost/assign/list_of.hpp>
#include "json/json_spirit_utils.h"
#include "json/json_spirit_value.h"
using namespace boost;
using namespace boost::assign;
using namespace json_spirit;
using namespace std;
bool CBitcoinAddressFromTxEntity(CBitcoinAddress &address,mc_TxEntity *lpEntity);
Object AddressEntry(CBitcoinAddress& address,uint32_t verbose);
int paramtoint(Value param,bool check_for_min,int min_value,string error_message);
/**
* @note Do not add or change anything in the information returned by this
* method. `getinfo` exists for backwards-compatibility only. It combines
* information from wildly different sources in the program, which is a mess,
* and is thus planned to be deprecated eventually.
*
* Based on the source of the information, new information should be added to:
* - `getblockchaininfo`,
* - `getnetworkinfo` or
* - `getwalletinfo`
*
* Or alternatively, create a specific query method for the information.
**/
Value getinfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error("Help message not found\n");
proxyType proxy;
GetProxy(NET_IPV4, proxy);
Object obj;
/* MCHN START */
// obj.push_back(Pair("version", CLIENT_VERSION));
// obj.push_back(Pair("protocolversion", PROTOCOL_VERSION));
obj.push_back(Pair("version", mc_BuildDescription(mc_gState->GetNumericVersion())));
obj.push_back(Pair("nodeversion", mc_gState->GetNumericVersion()));
obj.push_back(Pair("protocolversion", mc_gState->m_NetworkParams->ProtocolVersion()));
obj.push_back(Pair("chainname", string(mc_gState->m_NetworkParams->Name())));
obj.push_back(Pair("description", string((char*)mc_gState->m_NetworkParams->GetParam("chaindescription",NULL))));
obj.push_back(Pair("protocol", string((char*)mc_gState->m_NetworkParams->GetParam("chainprotocol",NULL))));
obj.push_back(Pair("port", GetListenPort()));
obj.push_back(Pair("setupblocks", mc_gState->m_NetworkParams->GetInt64Param("setupfirstblocks")));
obj.push_back(Pair("nodeaddress", MultichainServerAddress() + strprintf(":%d",GetListenPort())));
obj.push_back(Pair("burnaddress", BurnAddress(Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS))));
obj.push_back(Pair("incomingpaused", (mc_gState->m_NodePausedState & MC_NPS_INCOMING) ? true : false));
obj.push_back(Pair("miningpaused", (mc_gState->m_NodePausedState & MC_NPS_MINING) ? true : false));
/* MCHN END */
#ifdef ENABLE_WALLET
if (pwalletMain) {
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
obj.push_back(Pair("walletdbversion", mc_gState->GetWalletDBVersion()));
}
#endif
/* MCHN START */
obj.push_back(Pair("reindex", fReindex));
/* MCHN END */
obj.push_back(Pair("blocks", (int)chainActive.Height()));
obj.push_back(Pair("timeoffset", GetTimeOffset()));
obj.push_back(Pair("connections", (int)vNodes.size()));
obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.ToStringIPPort() : string())));
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC()));
#ifdef ENABLE_WALLET
if (pwalletMain) {
obj.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime()));
obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize()));
}
if (pwalletMain && pwalletMain->IsCrypted())
obj.push_back(Pair("unlocked_until", nWalletUnlockTime));
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
#endif
/* MCHN START */
::minRelayTxFee = CFeeRate(MIN_RELAY_TX_FEE);
/* MCHN END */
obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
return obj;
}
#ifdef ENABLE_WALLET
class DescribeAddressVisitor : public boost::static_visitor<Object>
{
private:
isminetype mine;
public:
DescribeAddressVisitor(isminetype mineIn) : mine(mineIn) {}
Object operator()(const CNoDestination &dest) const { return Object(); }
Object operator()(const CKeyID &keyID) const {
Object obj;
CPubKey vchPubKey;
obj.push_back(Pair("isscript", false));
if (mine == ISMINE_SPENDABLE) {
pwalletMain->GetPubKey(keyID, vchPubKey);
obj.push_back(Pair("pubkey", HexStr(vchPubKey)));
obj.push_back(Pair("iscompressed", vchPubKey.IsCompressed()));
}
return obj;
}
Object operator()(const CScriptID &scriptID) const {
Object obj;
obj.push_back(Pair("isscript", true));
if (mine != ISMINE_NO) {
CScript subscript;
pwalletMain->GetCScript(scriptID, subscript);
std::vector<CTxDestination> addresses;
txnouttype whichType;
int nRequired;
ExtractDestinations(subscript, whichType, addresses, nRequired);
obj.push_back(Pair("script", GetTxnOutputType(whichType)));
obj.push_back(Pair("hex", HexStr(subscript.begin(), subscript.end())));
Array a;
BOOST_FOREACH(const CTxDestination& addr, addresses)
a.push_back(CBitcoinAddress(addr).ToString());
obj.push_back(Pair("addresses", a));
if (whichType == TX_MULTISIG)
obj.push_back(Pair("sigsrequired", nRequired));
}
return obj;
}
};
#endif
/* MCHN START */
string getparamstring(string param)
{
string str;
str="";
if(mapMultiArgs.count(param))
{
for(int i=0;i<(int)mapMultiArgs[param].size();i++)
{
if(str.size())
{
str += ",";
}
str += mapMultiArgs[param][i];
}
}
return str;
}
Value getruntimeparams(const json_spirit::Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
throw runtime_error("Help message not found\n");
Object obj;
/*
obj.push_back(Pair("daemon",GetBoolArg("-daemon",false)));
obj.push_back(Pair("datadir",mc_gState->m_Params->DataDir(0,0)));
obj.push_back(Pair("debug",getparamstring("-debug")));
*/
obj.push_back(Pair("port",GetListenPort()));
obj.push_back(Pair("reindex",GetBoolArg("-reindex",false)));
obj.push_back(Pair("rescan",GetBoolArg("-rescan",false)));
/*
obj.push_back(Pair("rpcallowip",getparamstring("-rpcallowip")));
obj.push_back(Pair("rpcport",GetArg("-rpcport", BaseParams().RPCPort())));
*/
obj.push_back(Pair("txindex",GetBoolArg("-txindex",true)));
obj.push_back(Pair("autocombineminconf",GetArg("-autocombineminconf", 1)));
obj.push_back(Pair("autocombinemininputs",GetArg("-autocombinemininputs", 50)));
obj.push_back(Pair("autocombinemaxinputs",GetArg("-autocombinemaxinputs", 100)));
obj.push_back(Pair("autocombinedelay",GetArg("-autocombinedelay", 1)));
obj.push_back(Pair("autocombinesuspend",GetArg("-autocombinesuspend", 15)));
obj.push_back(Pair("autosubscribe",GetArg("-autosubscribe","")));
CKeyID keyID;
CPubKey pkey;
if(!pwalletMain->GetKeyFromAddressBook(pkey,MC_PTP_CONNECT))
{
LogPrintf("mchn: Cannot find address having connect permission, trying default key\n");
pkey=pwalletMain->vchDefaultKey;
}
keyID=pkey.GetID();
obj.push_back(Pair("handshakelocal",GetArg("-handshakelocal",CBitcoinAddress(keyID).ToString())));
obj.push_back(Pair("bantx",GetArg("-bantx","")));
obj.push_back(Pair("lockblock",GetArg("-lockblock","")));
obj.push_back(Pair("hideknownopdrops",GetBoolArg("-hideknownopdrops",false)));
obj.push_back(Pair("maxshowndata",GetArg("-maxshowndata",MAX_OP_RETURN_SHOWN)));
obj.push_back(Pair("v1apicompatible",GetBoolArg("-v1apicompatible",false)));
obj.push_back(Pair("miningrequirespeers",Params().MiningRequiresPeers()));
obj.push_back(Pair("mineemptyrounds",Params().MineEmptyRounds()));
obj.push_back(Pair("miningturnover",Params().MiningTurnover()));
obj.push_back(Pair("lockadminminerounds",Params().LockAdminMineRounds()));
obj.push_back(Pair("gen",GetBoolArg("-gen", true)));
obj.push_back(Pair("genproclimit",GetArg("-genproclimit", 1)));
/*
obj.push_back(Pair("shortoutput",GetBoolArg("-shortoutput",false)));
obj.push_back(Pair("walletdbversion", mc_gState->GetWalletDBVersion()));
*/
return obj;
}
bool paramtobool(Value param,bool strict)
{
if(!strict)
{
if(param.type() == str_type)
{
if(param.get_str() == "true")
{
return true;
}
return atoi(param.get_str().c_str()) != 0;
}
if(param.type() == int_type)
{
if(param.get_int())
{
return true;
}
else
{
return false;
}
}
}
if(param.type() != bool_type)
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter value type, should be boolean");
}
return param.get_bool();
}
bool paramtobool(Value param)
{
return paramtobool(param,true);
}
Value setruntimeparam(const json_spirit::Array& params, bool fHelp)
{
if (fHelp || params.size() != 2)
throw runtime_error("Help message not found\n");
if(mc_gState->m_NetworkParams->IsProtocolMultichain() == 0)
{
throw JSONRPCError(RPC_NOT_SUPPORTED, "This API is supported only if protocol=multichain");
}
string param_name=params[0].get_str();
bool fFound=false;
if(param_name == "miningrequirespeers")
{
mapArgs ["-" + param_name]=paramtobool(params[1],false) ? "1" : "0";
fFound=true;
}
if(param_name == "mineemptyblocks")
{
mapArgs ["-" + param_name]=paramtobool(params[1],false) ? "1" : "0";
fFound=true;
}
if(param_name == "mineblocksondemand")
{
mapArgs ["-" + param_name]=paramtobool(params[1],false) ? "1" : "0";
fFound=true;
}
if(param_name == "hideknownopdrops")
{
mapArgs ["-" + param_name]=paramtobool(params[1],false) ? "1" : "0";
fFound=true;
}
if(param_name == "mineemptyrounds")
{
if( (params[1].type() == real_type) || (params[1].type() == str_type) )
{
double dValue;
if(params[1].type() == real_type)
{
dValue=params[1].get_real();
}
else
{
dValue=atof(params[1].get_str().c_str());
}
mapArgs ["-" + param_name]= strprintf("%f", dValue);
}
else
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter value type");
}
fFound=true;
}
if(param_name == "miningturnover")
{
if( (params[1].type() == real_type) || (params[1].type() == str_type) )
{
double dValue;
if(params[1].type() == real_type)
{
dValue=params[1].get_real();
}
else
{
dValue=atof(params[1].get_str().c_str());
}
if( (dValue >= 0.) && (dValue <= 1.) )
{
mapArgs ["-" + param_name]= strprintf("%f", dValue);
}
else
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "Should be in range (0,1)");
}
}
else
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter value type");
}
fFound=true;
}
if( (param_name == "lockadminminerounds") ||
(param_name == "maxshowndata") ||
(param_name == "dropmessagestest") )
{
if( (params[1].type() == int_type) || (params[1].type() == str_type) )
{
int nValue;
if(params[1].type() == int_type)
{
nValue=params[1].get_int();
}
else
{
nValue=atoi(params[1].get_str().c_str());
}
if( nValue >= 0 )
{
mapArgs ["-" + param_name]=strprintf("%d", nValue);
}
else
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "Should be non-negative");
}
}
else
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter value type");
}
fFound=true;
}
if( (param_name == "compatibility") )
{
if( (params[1].type() == int_type) || (params[1].type() == str_type) )
{
int nValue;
if(params[1].type() == int_type)
{
nValue=params[1].get_int();
}
else
{
nValue=atoi(params[1].get_str().c_str());
}
mc_gState->m_Compatibility=(uint32_t)nValue;
}
else
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter value type");
}
fFound=true;
}
if(param_name == "bantx")
{
if(params[1].type() == str_type)
{
string error=SetBannedTxs(params[1].get_str());
if(error.size())
{
throw JSONRPCError(RPC_INVALID_PARAMETER, error);
}
else
{
mapArgs ["-" + param_name]=params[1].get_str();
}
}
else
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter value type");
}
fFound=true;
}
if(param_name == "lockblock")
{
if(params[1].type() == str_type)
{
string error=SetLockedBlock(params[1].get_str());
if(error.size())
{
throw JSONRPCError(RPC_INVALID_PARAMETER, error);
}
else
{
mapArgs ["-" + param_name]=params[1].get_str();
}
}
else
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter value type");
}
fFound=true;
}
if(param_name == "handshakelocal")
{
if(params[1].type() == str_type)
{
CBitcoinAddress address(params[1].get_str());
if (!address.IsValid())
{
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
}
else
{
mapArgs ["-" + param_name]=params[1].get_str();
}
}
else
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter value type");
}
fFound=true;
}
if(param_name == "autosubscribe")
{
if(params[1].type() == str_type)
{
string autosubscribe=params[1].get_str();
uint32_t mode=MC_WMD_NONE;
if(autosubscribe=="streams")
{
mode |= MC_WMD_AUTOSUBSCRIBE_STREAMS;
} else if (autosubscribe=="assets")
{
mode |= MC_WMD_AUTOSUBSCRIBE_ASSETS;
} else if ( (autosubscribe=="assets,streams") || (autosubscribe=="streams,assets"))
{
mode |= MC_WMD_AUTOSUBSCRIBE_STREAMS;
mode |= MC_WMD_AUTOSUBSCRIBE_ASSETS;
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Should be 'assets', 'streams' or 'assets,streams'");
}
if(pwalletTxsMain)
{
pwalletTxsMain->SetMode(mode,MC_WMD_AUTOSUBSCRIBE_STREAMS | MC_WMD_AUTOSUBSCRIBE_ASSETS);
}
mapArgs ["-" + param_name]=params[1].get_str();
}
else
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter value type");
}
fFound=true;
}
if(!fFound)
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unsupported runtime parameter: " + param_name);
}
SetMultiChainRuntimeParams();
return Value::null;
}
Value getblockchainparams(const json_spirit::Array& params, bool fHelp)
{
if (fHelp || params.size() > 2) // MCHN
throw runtime_error("Help message not found\n");
bool fDisplay = true;
if (params.size() > 0)
fDisplay = params[0].get_bool();
int nHeight=chainActive.Height();
if (params.size() > 1)
{
if(params[1].type() == bool_type)
{
if(!params[1].get_bool())
{
nHeight=0;
}
}
else
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "with-upgrades should be boolean");
/*
if(params[1].type() == int_type)
{
nHeight=params[1].get_int();
}
*/
}
}
if (nHeight < 0 || nHeight > chainActive.Height())
{
nHeight+=chainActive.Height();
if (nHeight <= 0 || nHeight > chainActive.Height())
{
throw JSONRPCError(RPC_BLOCK_NOT_FOUND, "Block height out of range");
}
}
Object obj;
int protocol_version=(int)mc_gState->m_NetworkParams->GetInt64Param("protocolversion");
if(nHeight)
{
protocol_version=mc_gState->m_NetworkParams->ProtocolVersion();
}
for(int i=0;i<mc_gState->m_NetworkParams->m_Count;i++)
{
if((mc_gState->m_NetworkParams->m_lpParams+i)->IsRelevant(protocol_version))
{
string param_name;
Value param_value;
unsigned char* ptr;
int size;
bool hidden=false;
string param_string="";;
ptr=(unsigned char*)mc_gState->m_NetworkParams->GetParam((mc_gState->m_NetworkParams->m_lpParams+i)->m_Name,&size);
if(size == 0)
{
ptr=NULL;
}
/*
else
{
if(((mc_gState->m_NetworkParams->m_lpParams+i)->m_Type & MC_PRM_DATA_TYPE_MASK) == MC_PRM_STRING)
{
if(size == 1)
{
ptr=NULL;
}
}
}
*/
if(fDisplay)
{
param_name=(mc_gState->m_NetworkParams->m_lpParams+i)->m_DisplayName;
}
else
{
param_name=(mc_gState->m_NetworkParams->m_lpParams+i)->m_Name;
}
if(ptr)
{
switch((mc_gState->m_NetworkParams->m_lpParams+i)->m_Type & MC_PRM_DATA_TYPE_MASK)
{
case MC_PRM_BINARY:
for(int c=0;c<size;c++)
{
param_string += strprintf("%02x",*((unsigned char*)ptr+c));
}
param_value=param_string;
break;
case MC_PRM_STRING:
param_value = string((char*)ptr);
break;
case MC_PRM_BOOLEAN:
if(*(char*)ptr)
{
param_value=true;
}
else
{
param_value=false;
}
break;
case MC_PRM_INT32:
if((mc_gState->m_NetworkParams->m_lpParams+i)->m_Type & MC_PRM_DECIMAL)
{
// param_value=((double)(int)mc_GetLE(ptr,4))/MC_PRM_DECIMAL_GRANULARITY;
int n=(int)mc_GetLE(ptr,4);
if(n >= 0)
{
param_value=((double)n+mc_gState->m_NetworkParams->ParamAccuracy())/MC_PRM_DECIMAL_GRANULARITY;
}
else
{
param_value=-((double)(-n)+mc_gState->m_NetworkParams->ParamAccuracy())/MC_PRM_DECIMAL_GRANULARITY;
}
}
else
{
param_value=(int)mc_GetLE(ptr,4);
}
break;
case MC_PRM_UINT32:
if((mc_gState->m_NetworkParams->m_lpParams+i)->m_Type & MC_PRM_DECIMAL)
{
param_value=((double)mc_GetLE(ptr,4)+mc_gState->m_NetworkParams->ParamAccuracy())/MC_PRM_DECIMAL_GRANULARITY;
}
else
{
param_value=mc_GetLE(ptr,4);
if((mc_gState->m_NetworkParams->m_lpParams+i)->m_Type & MC_PRM_HIDDEN)
{
if(mc_GetLE(ptr,4) == (mc_gState->m_NetworkParams->m_lpParams+i)->m_DefaultIntegerValue)
{
hidden=true;
}
}
}
break;
case MC_PRM_INT64:
param_value=mc_GetLE(ptr,8);
break;
case MC_PRM_DOUBLE:
param_value=*(double*)ptr;
break;
}
}
else
{
param_value=Value::null;
}
if(nHeight)
{
if(strcmp("protocolversion",(mc_gState->m_NetworkParams->m_lpParams+i)->m_Name) == 0)
{
param_value=mc_gState->m_NetworkParams->m_ProtocolVersion;
}
if(strcmp("maximumblocksize",(mc_gState->m_NetworkParams->m_lpParams+i)->m_Name) == 0)
{
param_value=(int)MAX_BLOCK_SIZE;
}
if(strcmp("targetblocktime",(mc_gState->m_NetworkParams->m_lpParams+i)->m_Name) == 0)
{
param_value=(int)MCP_TARGET_BLOCK_TIME;
}
if(strcmp("maxstdtxsize",(mc_gState->m_NetworkParams->m_lpParams+i)->m_Name) == 0)
{
param_value=(int)MAX_STANDARD_TX_SIZE;
}
if(strcmp("maxstdopreturnscount",(mc_gState->m_NetworkParams->m_lpParams+i)->m_Name) == 0)
{
param_value=(int)MCP_MAX_STD_OP_RETURN_COUNT;
}
if(strcmp("maxstdopreturnsize",(mc_gState->m_NetworkParams->m_lpParams+i)->m_Name) == 0)
{
param_value=(int)MAX_OP_RETURN_RELAY;
}
if(strcmp("maxstdopdropscount",(mc_gState->m_NetworkParams->m_lpParams+i)->m_Name) == 0)
{
param_value=(int)MCP_STD_OP_DROP_COUNT;
}
if(strcmp("maxstdelementsize",(mc_gState->m_NetworkParams->m_lpParams+i)->m_Name) == 0)
{
param_value=(int)MAX_SCRIPT_ELEMENT_SIZE;
}
}
if(!hidden)
{
obj.push_back(Pair(param_name,param_value));
}
}
}
return obj;
}
void SetSynchronizedFlag(CTxDestination &dest,Object &ret)
{
if(mc_gState->m_WalletMode & MC_WMD_ADDRESS_TXS)
{
mc_TxEntityStat entStat;
CKeyID *lpKeyID=boost::get<CKeyID> (&dest);
CScriptID *lpScriptID=boost::get<CScriptID> (&dest);
entStat.Zero();
if(lpKeyID)
{
memcpy(&entStat,lpKeyID,MC_TDB_ENTITY_ID_SIZE);
entStat.m_Entity.m_EntityType=MC_TET_PUBKEY_ADDRESS | MC_TET_CHAINPOS;
}
if(lpScriptID)
{
memcpy(&entStat,lpScriptID,MC_TDB_ENTITY_ID_SIZE);
entStat.m_Entity.m_EntityType=MC_TET_SCRIPT_ADDRESS | MC_TET_CHAINPOS;
}
if(pwalletTxsMain->FindEntity(&entStat))
{
if(entStat.m_Flags & MC_EFL_NOT_IN_SYNC)
{
ret.push_back(Pair("synchronized",false));
}
else
{
ret.push_back(Pair("synchronized",true));
}
}
}
}
Object AddressEntry(CBitcoinAddress& address,uint32_t verbose)
{
// 0x01 add isvalid=true
// 0x02 verbose
Object ret;
if(verbose & 0x01)
{
ret.push_back(Pair("isvalid", true));
}
CTxDestination dest = address.Get();
string currentAddress = address.ToString();
ret.push_back(Pair("address", currentAddress));
#ifdef ENABLE_WALLET
isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO;
ret.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false));
if(verbose & 0x02)
{
if (mine != ISMINE_NO) {
ret.push_back(Pair("iswatchonly", (mine & ISMINE_WATCH_ONLY) ? true: false));
Object detail = boost::apply_visitor(DescribeAddressVisitor(mine), dest);
ret.insert(ret.end(), detail.begin(), detail.end());
}
if (pwalletMain && pwalletMain->mapAddressBook.count(dest))
ret.push_back(Pair("account", pwalletMain->mapAddressBook[dest].name));
#endif
SetSynchronizedFlag(dest,ret);
}
return ret;
}
/* MCHN END */
Value validateaddress(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1) // MCHN
throw runtime_error("Help message not found\n");
string str=params[0].get_str();
CBitcoinAddress address(str);
bool isValid = address.IsValid();
Object ret;
/* MCHN START */
if(!isValid)
{
CBitcoinSecret vchSecret;
CPubKey pubkey;
isValid = vchSecret.SetString(str);
if (isValid)
{
CKey key;
key = vchSecret.GetKey();
isValid=key.IsValid();
if (isValid)
{
pubkey = key.GetPubKey();
isValid=key.VerifyPubKey(pubkey);
}
}
else
{
if (IsHex(str))
{
pubkey=CPubKey(ParseHex(str));
isValid=pubkey.IsFullyValid();
}
}
if(isValid)
{
address=CBitcoinAddress(pubkey.GetID());
}
}
if(!isValid)
{
ret.push_back(Pair("isvalid", false));
return ret;
}
return AddressEntry(address,0x03);
/*
ret.push_back(Pair("isvalid", isValid));
if (isValid)
{
CTxDestination dest = address.Get();
string currentAddress = address.ToString();
ret.push_back(Pair("address", currentAddress));
#ifdef ENABLE_WALLET
isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO;
ret.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false));
if (mine != ISMINE_NO) {
ret.push_back(Pair("iswatchonly", (mine & ISMINE_WATCH_ONLY) ? true: false));
Object detail = boost::apply_visitor(DescribeAddressVisitor(mine), dest);
ret.insert(ret.end(), detail.begin(), detail.end());
}
if (pwalletMain && pwalletMain->mapAddressBook.count(dest))
ret.push_back(Pair("account", pwalletMain->mapAddressBook[dest].name));
#endif
SetSynchronizedFlag(dest,ret);
}
*/
// return ret;
/* MCHN END */
}
/* MCHN START */
Value createkeypairs(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1) // MCHN
throw runtime_error("Help message not found\n");
int count=1;
if (params.size() > 0)
{
count=paramtoint(params[0],true,0,"Invalid count");
}
Array retArray;
bool fCompressed = true;
for(int i=0;i<count;i++)
{
CKey secret;
secret.MakeNewKey(fCompressed);
CPubKey pubkey = secret.GetPubKey();
Object entry;
entry.push_back(Pair("address", CBitcoinAddress(pubkey.GetID()).ToString()));
entry.push_back(Pair("pubkey", HexStr(pubkey)));
entry.push_back(Pair("privkey", CBitcoinSecret(secret).ToString()));
retArray.push_back(entry);
}
return retArray;
}
Value getaddresses(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1) // MCHN
throw runtime_error("Help message not found\n");
int verbose=0x00;
if (params.size() > 0)
{
if(params[0].type() == bool_type)
{
if(params[0].get_bool())
{
verbose=0x02;
}
}
else
{
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid value for 'verbose' parameter, should be boolean");
}
}
Array ret;
if((mc_gState->m_WalletMode & MC_WMD_TXS))
{
int entity_count;
mc_TxEntityStat *lpEntity;
entity_count=pwalletTxsMain->GetEntityListCount();
for(int i=0;i<entity_count;i++)
{
lpEntity=pwalletTxsMain->GetEntity(i);
CBitcoinAddress address;
if( (lpEntity->m_Entity.m_EntityType & MC_TET_ORDERMASK) == MC_TET_CHAINPOS)
{
if(CBitcoinAddressFromTxEntity(address,&(lpEntity->m_Entity)))
{
if(verbose)
{
ret.push_back(AddressEntry(address,verbose));
}
else
{
ret.push_back(address.ToString());
}
}
}
}
}
else
{
// Find all addresses that have the given account
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook)
{
const CBitcoinAddress& address = item.first;
if(verbose)
{
Object addr;
CTxDestination dest = address.Get();
string currentAddress = address.ToString();
addr.push_back(Pair("address", currentAddress));
isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO;
addr.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false));
if (mine != ISMINE_NO) {
addr.push_back(Pair("iswatchonly", (mine & ISMINE_WATCH_ONLY) ? true: false));
Object detail = boost::apply_visitor(DescribeAddressVisitor(mine), dest);
addr.insert(addr.end(), detail.begin(), detail.end());
}
if (pwalletMain && pwalletMain->mapAddressBook.count(dest))
addr.push_back(Pair("account", pwalletMain->mapAddressBook[dest].name));
SetSynchronizedFlag(dest,addr);
ret.push_back(addr);
}
else
{
ret.push_back(address.ToString());
}
}
}
return ret;
}
/* MCHN END */
/**
* Used by addmultisigaddress / createmultisig:
*/
CScript _createmultisig_redeemScript(const Array& params)
{
int nRequired = params[0].get_int();
const Array& keys = params[1].get_array();
// Gather public keys
if (nRequired < 1)
throw runtime_error("a multisignature address must require at least one key to redeem");
if ((int)keys.size() < nRequired)
throw runtime_error(
strprintf("not enough keys supplied "
"(got %u keys, but need at least %d to redeem)", keys.size(), nRequired));
if (keys.size() > 16)
throw runtime_error("Number of addresses involved in the multisignature address creation > 16\nReduce the number");
std::vector<CPubKey> pubkeys;