13
13
#include " primitives/transaction.h"
14
14
#include " spork.h"
15
15
#include " wallet/wallet.h"
16
+ #include " utilmoneystr.h"
16
17
#include " validation.h"
17
18
#include " dynode-sync.h"
18
19
@@ -148,7 +149,7 @@ UniValue adduser(const JSONRPCRequest& request)
148
149
" 3. registration months (int, optional) Number of months to register account\n "
149
150
" \n Adds a new bdap.io public name account entry to the blockchain directory.\n "
150
151
" \n Result:\n "
151
- " {(json object )\n "
152
+ " {(json objects )\n "
152
153
" \" oid\" (string) Account OID\n "
153
154
" \" version\" (int) Recipient's BDAP full path\n "
154
155
" \" domain_component\" (string) Account domain name\n "
@@ -167,7 +168,7 @@ UniValue adduser(const JSONRPCRequest& request)
167
168
" \" height\" (int) Last transaction height for account data\n "
168
169
" \" expires_on\" (int) Account expiration epoch time\n "
169
170
" \" expired\" (boolean) Account expired\n "
170
- " }\n "
171
+ " },...n \n "
171
172
" \n Examples\n " +
172
173
HelpExampleCli (" adduser" , " Alice \" Wonderland, Alice\" " ) +
173
174
" \n As a JSON-RPC call\n " +
@@ -924,27 +925,27 @@ UniValue mybdapaccounts(const JSONRPCRequest& request)
924
925
return result;
925
926
}
926
927
927
- UniValue colorcoin (const JSONRPCRequest& request)
928
+ UniValue makecredits (const JSONRPCRequest& request)
928
929
{
929
930
if (request.fHelp || request.params .size () < 2 || request.params .size () > 3 )
930
931
throw std::runtime_error (
931
- " colorcoin \" dynamicaddress\" \" amount\" \" utxo list \"\n "
932
- " \n Convert your DYN to BDAP colored credits\n "
932
+ " makecredits \" dynamicaddress\" \" amount\"\n "
933
+ " \n Convert your Dynamic ( DYN) to BDAP colored credits\n "
933
934
+ HelpRequiringPassphrase () +
934
935
" \n Arguments:\n "
935
936
" 1. \" dynamicaddress\" (string) The destination wallet address\n "
936
937
" 2. \" amount\" (int) The amount in " + CURRENCY_UNIT + " to color. eg 0.1\n "
937
938
" \n Result:\n "
938
939
" \" tx id\" (string) The transaction id for the coin coloring\n "
939
940
" \n Examples:\n "
940
- + HelpExampleCli (" colorcoin " , " \" DKkDJn9bjoXJiiPysSVEeUc3ve6SaWLzVv\" 100.98 \" utxo1,utxo2 \" " ) +
941
+ + HelpExampleCli (" makecredits " , " \" DKkDJn9bjoXJiiPysSVEeUc3ve6SaWLzVv\" 100.98" ) +
941
942
" \n As a JSON-RPC call\n "
942
- + HelpExampleRpc (" colorcoin " , " \" DKkDJn9bjoXJiiPysSVEeUc3ve6SaWLzVv\" 100.98 \" utxo1,utxo2 \" " ));
943
+ + HelpExampleRpc (" makecredits " , " \" DKkDJn9bjoXJiiPysSVEeUc3ve6SaWLzVv\" 100.98" ));
943
944
944
945
EnsureWalletIsUnlocked ();
945
946
946
947
if (!sporkManager.IsSporkActive (SPORK_30_ACTIVATE_BDAP))
947
- throw JSONRPCError (RPC_BDAP_SPORK_INACTIVE, strprintf (" Can not use the colorcoin RPC command until the BDAP spork is active." ));
948
+ throw JSONRPCError (RPC_BDAP_SPORK_INACTIVE, strprintf (" Can not use the makecredits RPC command until the BDAP spork is active." ));
948
949
949
950
if (!pwalletMain)
950
951
throw JSONRPCError (RPC_WALLET_ERROR, strprintf (" Error accessing wallet." ));
@@ -975,6 +976,84 @@ UniValue colorcoin(const JSONRPCRequest& request)
975
976
return wtx.GetHash ().GetHex ();
976
977
}
977
978
979
+ UniValue getcredits (const JSONRPCRequest& request)
980
+ {
981
+ if (request.fHelp || request.params .size () != 0 )
982
+ throw std::runtime_error (
983
+ " getcredits\n "
984
+ " \n Get available BDAP credit balance\n "
985
+ + HelpRequiringPassphrase () +
986
+ " \n Result:\n "
987
+ " {(json objects)\n "
988
+ " \" type\" (string) The credit type.\n "
989
+ " \" operation\" (string) The operation code used in the tx output\n "
990
+ " \" address\" (string) The address holding the unspent BDAP credits\n "
991
+ " \" dynamic_amount\" (int) The unspent BDAP amount int DYN\n "
992
+ " \" credits\" (int) The unspent BDAP credits\n "
993
+ " },...n \n "
994
+ " \" total_credits\" (int) The total credits available.\n "
995
+ " \" total_deposits\" (int) The total deposits available.\n "
996
+ " \" total_dynamic\" (int) The total Dynamic available that are BDAP colored.\n "
997
+ " \n Examples:\n "
998
+ + HelpExampleCli (" getcredits" , " " ) +
999
+ " \n As a JSON-RPC call\n "
1000
+ + HelpExampleRpc (" getcredits" , " " ));
1001
+
1002
+ if (!pwalletMain)
1003
+ throw JSONRPCError (RPC_WALLET_ERROR, strprintf (" Error accessing wallet." ));
1004
+
1005
+ std::vector<std::pair<CTxOut, COutPoint>> vCredits;
1006
+ pwalletMain->AvailableBDAPCredits (vCredits);
1007
+
1008
+ CAmount nTotalAmount = 0 ;
1009
+ CAmount nTotalCredits = 0 ;
1010
+ CAmount nTotalDeposits = 0 ;
1011
+ UniValue result (UniValue::VOBJ);
1012
+ for (const std::pair<CTxOut, COutPoint>& credit : vCredits) {
1013
+ UniValue oCredit (UniValue::VOBJ);
1014
+ int opCode1 = -1 ; int opCode2 = -1 ;
1015
+ std::vector<std::vector<unsigned char >> vvch;
1016
+ credit.first .GetBDAPOpCodes (opCode1, opCode2, vvch);
1017
+ std::string strOpType = GetBDAPOpTypeString (opCode1, opCode2);
1018
+ const CDynamicAddress address = GetScriptAddress (credit.first .scriptPubKey );
1019
+ std::string strType = " unknown" ;
1020
+ if (strOpType == " bdap_new_account" || strOpType == " bdap_update_account" ) {
1021
+ strType = " account deposit" ;
1022
+ nTotalDeposits += credit.first .nValue ;
1023
+ } else if (strOpType == " bdap_new_link_request" || strOpType == " bdap_new_link_accept" ||
1024
+ strOpType == " bdap_delete_link_request" || strOpType == " bdap_delete_link_accept" ) {
1025
+ strType = " link deposit" ;
1026
+ nTotalDeposits += credit.first .nValue ;
1027
+ } else if (strOpType == " bdap_move_asset" ) {
1028
+ if (vvch.size () > 1 ) {
1029
+ std::string strMoveSource = stringFromVch (vvch[0 ]);
1030
+ std::string strMoveDestination = stringFromVch (vvch[1 ]);
1031
+ strType = strprintf (" credit (%s to %s)" , strMoveSource, strMoveDestination);
1032
+ if (strMoveSource == " DYN" && strMoveDestination == " BDAP" )
1033
+ nTotalCredits += credit.first .nValue ;
1034
+ } else {
1035
+ strType = strprintf (" credit (unknown)" );
1036
+ }
1037
+ }
1038
+ oCredit.push_back (Pair (" type" , strType));
1039
+ oCredit.push_back (Pair (" operation" , strOpType));
1040
+ oCredit.push_back (Pair (" address" , address.ToString ()));
1041
+ oCredit.push_back (Pair (" dynamic_amount" , FormatMoney (credit.first .nValue )));
1042
+ oCredit.push_back (Pair (" credits" , credit.first .nValue /BDAP_CREDIT));
1043
+ std::string strOutput = credit.second .hash .ToString () + " -" + std::to_string (credit.second .n );
1044
+ result.push_back (Pair (strOutput, oCredit));
1045
+ nTotalAmount += credit.first .nValue ;
1046
+ }
1047
+ // Add total amounts and credits
1048
+
1049
+ result.push_back (Pair (" total_credits" , nTotalCredits/BDAP_CREDIT));
1050
+ result.push_back (Pair (" total_deposits" , nTotalDeposits/BDAP_CREDIT));
1051
+ result.push_back (Pair (" total_dynamic" , FormatMoney (nTotalAmount)));
1052
+
1053
+ return result;
1054
+ }
1055
+
1056
+
978
1057
static const CRPCCommand commands[] =
979
1058
{ // category name actor (function) okSafe argNames
980
1059
// --------------------- ------------------------ ----------------------- ------ --------------------
@@ -991,7 +1070,8 @@ static const CRPCCommand commands[] =
991
1070
{ " bdap" , " addgroup" , &addgroup, true , {" account id" , " common name" , " registration days" } },
992
1071
{ " bdap" , " getgroupinfo" , &getgroupinfo, true , {" account id" } },
993
1072
{ " bdap" , " mybdapaccounts" , &mybdapaccounts, true , {} },
994
- { " bdap" , " colorcoin" , &colorcoin, true , {" dynamicaddress" , " amount" } },
1073
+ { " bdap" , " makecredits" , &makecredits, true , {" dynamicaddress" , " amount" } },
1074
+ { " bdap" , " getcredits" , &getcredits, true , {} },
995
1075
#endif // ENABLE_WALLET
996
1076
{ " bdap" , " makekeypair" , &makekeypair, true , {" prefix" } },
997
1077
};
0 commit comments