19
19
#include < univalue.h>
20
20
21
21
extern void SendBDAPTransaction (const CScript& bdapDataScript, const CScript& bdapOPScript, CWalletTx& wtxNew, const CAmount& nRegFee, const CAmount& nDepositFee, const bool fUseInstantSend );
22
+ extern void SendColorTransaction (const CScript& scriptColorCoins, CWalletTx& wtxNew, const CAmount& nColorAmount, const CCoinControl* coinControl, const bool fUseInstantSend , const bool fUsePrivateSend );
22
23
23
24
static constexpr bool fPrintDebug = true ;
24
25
@@ -925,6 +926,55 @@ UniValue mybdapaccounts(const JSONRPCRequest& request)
925
926
return result;
926
927
}
927
928
929
+ UniValue colorcoin (const JSONRPCRequest& request)
930
+ {
931
+ if (request.fHelp || request.params .size () < 2 || request.params .size () > 3 )
932
+ throw std::runtime_error (
933
+ " colorcoin \" dynamicaddress\" \" amount\" \" utxo list\"\n "
934
+ " \n Convert your DYN to BDAP colored credits\n "
935
+ + HelpRequiringPassphrase () +
936
+ " \n Arguments:\n "
937
+ " 1. \" dynamicaddress\" (string) The destination wallet address\n "
938
+ " 2. \" amount\" (int) The amount in " + CURRENCY_UNIT + " to color. eg 0.1\n "
939
+ " 3. \" utxo list\" (string, optional) UTXO txids list seperated by commas\n "
940
+ " \n Result:\n "
941
+ " \" tx id\" (string) The transaction id for the coin coloring\n "
942
+ " \n Examples:\n "
943
+ + HelpExampleCli (" colorcoin" , " \" DKkDJn9bjoXJiiPysSVEeUc3ve6SaWLzVv\" 100.98 \" utxo1,utxo2\" " ) +
944
+ " \n As a JSON-RPC call\n "
945
+ + HelpExampleRpc (" colorcoin" , " \" DKkDJn9bjoXJiiPysSVEeUc3ve6SaWLzVv\" 100.98 \" utxo1,utxo2\" " ));
946
+
947
+ EnsureWalletIsUnlocked ();
948
+
949
+ if (!pwalletMain)
950
+ throw JSONRPCError (RPC_WALLET_ERROR, strprintf (" Error accessing wallet." ));
951
+
952
+ CTxDestination dest = DecodeDestination (request.params [0 ].get_str ());
953
+ if (!IsValidDestination (dest))
954
+ throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Invalid address" );
955
+
956
+ CAmount nColorAmount = AmountFromValue (request.params [1 ]);
957
+ if (nColorAmount <= 0 )
958
+ throw JSONRPCError (RPC_TYPE_ERROR, " Invalid amount for coloring" );
959
+
960
+ std::vector<unsigned char > vchMoveSource = vchFromString (std::string (" DYN" ));
961
+ std::vector<unsigned char > vchMoveDestination = vchFromString (std::string (" BDAP" ));
962
+
963
+ // Create BDAP move asset operation script
964
+ CScript scriptColorCoins;
965
+ scriptColorCoins << CScript::EncodeOP_N (OP_BDAP_MODIFY_RDN) << CScript::EncodeOP_N (OP_BDAP_ASSET)
966
+ << vchMoveSource << vchMoveDestination << OP_2DROP << OP_2DROP;
967
+
968
+ CScript scriptDestination;
969
+ scriptDestination = GetScriptForDestination (dest);
970
+ scriptColorCoins += scriptDestination;
971
+
972
+ CWalletTx wtx;
973
+ SendColorTransaction (scriptColorCoins, wtx, nColorAmount, NULL , false , false );
974
+
975
+ return wtx.GetHash ().GetHex ();
976
+ }
977
+
928
978
static const CRPCCommand commands[] =
929
979
{ // category name actor (function) okSafe argNames
930
980
// --------------------- ------------------------ ----------------------- ------ --------------------
@@ -941,6 +991,7 @@ static const CRPCCommand commands[] =
941
991
{ " bdap" , " addgroup" , &addgroup, true , {" account id" , " common name" , " registration days" } },
942
992
{ " bdap" , " getgroupinfo" , &getgroupinfo, true , {" account id" } },
943
993
{ " bdap" , " mybdapaccounts" , &mybdapaccounts, true , {} },
994
+ { " bdap" , " colorcoin" , &colorcoin, true , {" dynamicaddress" , " amount" , " utxo list" } },
944
995
#endif // ENABLE_WALLET
945
996
{ " bdap" , " makekeypair" , &makekeypair, true , {" prefix" } },
946
997
};
0 commit comments