From ce29e267424737c9afa70e1c03314c7c8565ff68 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Thu, 11 Jul 2019 01:40:37 +0200 Subject: [PATCH 1/6] remove EVAL_ORACLES dependency for opreturn_burn --- src/cc/CCtx.cpp | 3 ++- src/wallet/rpcwallet.cpp | 52 +++++++++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 12 deletions(-) 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); From 8a29940908a0063c8027550112687e140dce5bad Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Thu, 11 Jul 2019 01:43:30 +0200 Subject: [PATCH 2/6] fix opreturn_burn help --- src/wallet/rpcwallet.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4eaec8485..44d52597d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -8084,8 +8084,6 @@ UniValue opreturn_burn(const UniValue& params, bool fHelp) "\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" From 616324d032812b49f50a813ae97a817f46f611a3 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Thu, 11 Jul 2019 03:12:28 +0200 Subject: [PATCH 3/6] remove extra var --- src/wallet/rpcwallet.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 44d52597d..5071f7935 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -8071,7 +8071,7 @@ void RegisterWalletRPCCommands(CRPCTable &tableRPC) UniValue opreturn_burn(const UniValue& params, bool fHelp) { - std::vector vHexStr; CScript opret; int32_t txfee = 10000;CPubKey pubkey; + std::vector vHexStr; CScript opret; int32_t txfee = 10000;CPubKey myPubkey; if (fHelp || (params.size() < 2) || (params.size() > 4) ) { throw runtime_error( @@ -8110,12 +8110,11 @@ UniValue opreturn_burn(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_TYPE_ERROR, "wallet is locked or unavailable."); EnsureWalletIsUnlocked(); CReserveKey reservekey(pwalletMain); - if (!reservekey.GetReservedKey(pubkey)) + if (!reservekey.GetReservedKey(myPubkey)) { throw JSONRPCError(RPC_TYPE_ERROR, "keypool error."); } - CPubKey myPubkey = pubkey; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); int64_t normalInputs = AddNormalinputs(mtx, myPubkey, nAmount+txfee, 60); From db5f9c4432bbdeacd00c04087c32f0ad7e793a27 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Tue, 6 Aug 2019 07:46:27 +0000 Subject: [PATCH 4/6] remove CCFinalize change, return unsigned hex instead --- src/cc/CCtx.cpp | 1 - src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 31fc1cf51..d5697ed02 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -146,7 +146,6 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran if ( totalinputs >= totaloutputs+2*txfee ) { change = totalinputs - (totaloutputs+txfee); - if ( change != 0) mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); } if ( opret.size() > 0 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ff4549caa..d3d2d6dea 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -8352,6 +8352,6 @@ UniValue opreturn_burn(const UniValue& params, bool fHelp) opret << OP_RETURN << E_MARSHAL(ss << vHexStr); mtx.vout.push_back(CTxOut(nAmount,opret)); - ret.push_back(Pair("hex",FinalizeCCTx(0, cp, mtx, myPubkey, txfee, CScript()))); + ret.push_back(Pair("hex", EncodeHexTx(mtx))); return(ret); } From f44fb3357a585307ac0437d86dbe817c0e5c7547 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Tue, 6 Aug 2019 07:47:27 +0000 Subject: [PATCH 5/6] remove whitespace --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index d5697ed02..5799f0b18 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -146,7 +146,7 @@ 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)); + mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); } if ( opret.size() > 0 ) mtx.vout.push_back(CTxOut(0,opret)); From ae465a1d04023bdcce92c76fc4b62b6e97a5d5a3 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Tue, 6 Aug 2019 08:08:32 +0000 Subject: [PATCH 6/6] fix opreturn_burn help info --- src/wallet/rpcwallet.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d3d2d6dea..76aad06ab 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -8304,7 +8304,7 @@ UniValue opreturn_burn(const UniValue& params, bool fHelp) { 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" + "\nBurn the specified amount of coins via OP_RETURN. Returns unsigned transaction raw hex that must then be signed via signrawtransaction and 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" @@ -8322,10 +8322,8 @@ UniValue opreturn_burn(const UniValue& params, bool fHelp) + HelpExampleRpc("opreturn_burn", "\"10\", \"deadbeef\", 0.00005") ); } - struct CCcontract_info *cp, C; UniValue ret(UniValue::VOBJ); - // this doesnt actually require EVAL_ORACLES and is just used as a dummy for CCFinalizeTx - cp = CCinit(&C, EVAL_ORACLES); - + UniValue ret(UniValue::VOBJ); + CAmount nAmount = AmountFromValue(params[0]); vHexStr = ParseHex(params[1].get_str()); if ( vHexStr.size() == 0 )