diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 7435defbf..f5ebf194f 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -137,7 +137,8 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran if ( totalinputs >= totaloutputs+2*txfee ) { change = totalinputs - (totaloutputs+txfee); - mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + if ( change != 0) + mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); } if ( opret.size() > 0 ) mtx.vout.push_back(CTxOut(0,opret)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6a47e71a0..4eaec8485 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -8071,31 +8071,61 @@ void RegisterWalletRPCCommands(CRPCTable &tableRPC) UniValue opreturn_burn(const UniValue& params, bool fHelp) { - std::vector vHexStr; CScript opret; int32_t txfee = 10000; - if (fHelp || (params.size() != 2)) - throw runtime_error("amount to burn, hexstring to send\n"); + std::vector vHexStr; CScript opret; int32_t txfee = 10000;CPubKey pubkey; + if (fHelp || (params.size() < 2) || (params.size() > 4) ) + { + throw runtime_error( + "opreturn_burn burn_amount hexstring ( txfee )\n" + "\nBurn the specified amount of coins via OP_RETURN. Returns transaction raw hex that must then be broadcast via sendrawtransaction rpc\n" + "\nArguments:\n" + "1. \"burn_amount\" (numeric, required) Amount of coins to burn.\n" + "2. \"hexstring\" (string, required) Hex string to include in OP_RETURN data.\n" + "3. \"txfee\" (numeric, optional, default=0.0001) Transaction fee.\n" + "\nResult:\n" + " {\n" + " \"hex\" : \"hexstring\", (string) raw hex of transaction \n" + " \"ismine\" : \"true/false\", (bool)\n" + " \"R-address\" : \"R address\", (string) The pubkey\n" + " }\n" + "\nExamples:\n" + "\nBurn 10 coins with OP_RETURN data \"deadbeef\"\n" + + HelpExampleCli("opreturn_burn", "\"10\" \"deadbeef\"") + + HelpExampleRpc("opreturn_burn", "\"10\", \"deadbeef\"") + + "\nBurn 10 coins with OP_RETURN data \"deadbeef\" with 0.00005 txfee\n" + + HelpExampleCli("opreturn_burn", "\"10\" \"deadbeef\" \"0.00005\"") + + HelpExampleRpc("opreturn_burn", "\"10\", \"deadbeef\", 0.00005") + ); + } struct CCcontract_info *cp, C; UniValue ret(UniValue::VOBJ); - if (ensure_CCrequirements(EVAL_ORACLES) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + // this doesnt actually require EVAL_ORACLES and is just used as a dummy for CCFinalizeTx cp = CCinit(&C, EVAL_ORACLES); CAmount nAmount = AmountFromValue(params[0]); - if (nAmount <= 10000) - throw JSONRPCError(RPC_TYPE_ERROR, "must burn at least 10000 sat"); vHexStr = ParseHex(params[1].get_str()); if ( vHexStr.size() == 0 ) throw JSONRPCError(RPC_TYPE_ERROR, "hexstring is not valid."); - CPubKey myPubkey = pubkey2pk(Mypubkey()); + if ( params.size() > 2 ) + txfee = AmountFromValue(params[2]); + + if (!EnsureWalletIsAvailable(fHelp)) + throw JSONRPCError(RPC_TYPE_ERROR, "wallet is locked or unavailable."); + EnsureWalletIsUnlocked(); + CReserveKey reservekey(pwalletMain); + if (!reservekey.GetReservedKey(pubkey)) + { + throw JSONRPCError(RPC_TYPE_ERROR, "keypool error."); + } + + CPubKey myPubkey = pubkey; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - int64_t normalInputs = AddNormalinputs(mtx, myPubkey, nAmount, 60); + int64_t normalInputs = AddNormalinputs(mtx, myPubkey, nAmount+txfee, 60); if (normalInputs < nAmount) - throw runtime_error("not enough normals\n"); + throw runtime_error("insufficient funds\n"); opret << OP_RETURN << E_MARSHAL(ss << vHexStr); - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG)); mtx.vout.push_back(CTxOut(nAmount,opret)); ret.push_back(Pair("hex",FinalizeCCTx(0, cp, mtx, myPubkey, txfee, CScript()))); return(ret);