From fbba0aa766469f08b290cc2195a7973fa6e541c0 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Fri, 31 Mar 2017 11:01:10 -0400 Subject: [PATCH] createrawtransaction now only supports manual fee construction --- qa/rpc-tests/confidential_transactions.py | 11 ++++----- src/rpc/rawtransaction.cpp | 29 +++++++---------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/qa/rpc-tests/confidential_transactions.py b/qa/rpc-tests/confidential_transactions.py index 2269d26853..653bfb54f5 100755 --- a/qa/rpc-tests/confidential_transactions.py +++ b/qa/rpc-tests/confidential_transactions.py @@ -87,12 +87,12 @@ class CTTest (BitcoinTestFramework): unspent = self.nodes[0].listunspent(1, 9999999, [], "bitcoin") unspent = [i for i in unspent if i['amount'] > value23] assert_equal(len(unspent), 1) - fee = Decimal(0.0001) + fee = Decimal('0.0001') tx = self.nodes[0].createrawtransaction([{"txid": unspent[0]["txid"], "vout": unspent[0]["vout"], "nValue": unspent[0]["amount"]}], {unconfidential_address: value2, address: value3, - change_address: unspent[0]["amount"] - value2 - value3 - fee}) + change_address: unspent[0]["amount"] - value2 - value3 - fee, "fee":fee}) tx = self.nodes[0].blindrawtransaction(tx) tx_signed = self.nodes[0].signrawtransaction(tx) raw_tx_id = self.nodes[0].sendrawtransaction(tx_signed['hex']) @@ -143,7 +143,7 @@ class CTTest (BitcoinTestFramework): tx = self.nodes[0].createrawtransaction([{"txid": unspent[0]["txid"], "vout": unspent[0]["vout"], "nValue": unspent[0]["amount"]}], - {unconfidential_address: unspent[0]["amount"] - fee}); + {unconfidential_address: unspent[0]["amount"] - fee, "fee":fee}); # Test that blindrawtransaction returns an exception try: @@ -160,7 +160,7 @@ class CTTest (BitcoinTestFramework): "vout": unspent[0]["vout"], "nValue": unspent[0]["amount"]}], {unconfidential_address: value4, - change_address: unspent[0]["amount"] - value4 - fee}); + change_address: unspent[0]["amount"] - value4 - fee, "fee":fee}); tx = self.nodes[0].blindrawtransaction(tx) tx_signed = self.nodes[0].signrawtransaction(tx) @@ -249,8 +249,7 @@ class CTTest (BitcoinTestFramework): rawaddrs = [] for i in range(2): rawaddrs.append(self.nodes[1].getnewaddress()) - - raw_assets = self.nodes[2].createrawtransaction([{"txid":b_utxos[0]['txid'], "vout":b_utxos[0]['vout'], "nValue":b_utxos[0]['amount']}, {"txid":b_utxos[1]['txid'], "vout":b_utxos[1]['vout'], "nValue":b_utxos[1]['amount'], "asset":b_utxos[1]['asset']}, {"txid":t_utxos[0]['txid'], "vout":t_utxos[0]['vout'], "nValue":t_utxos[0]['amount'], "asset":t_utxos[0]['asset']}], {rawaddrs[1]:Decimal(t_utxos[0]['amount']), rawaddrs[0]:Decimal(b_utxos[0]['amount']+b_utxos[1]['amount']-Decimal("0.01"))}, 0, {rawaddrs[0]:b_utxos[0]['asset'], rawaddrs[1]:t_utxos[0]['asset']}) + raw_assets = self.nodes[2].createrawtransaction([{"txid":b_utxos[0]['txid'], "vout":b_utxos[0]['vout'], "nValue":b_utxos[0]['amount']}, {"txid":b_utxos[1]['txid'], "vout":b_utxos[1]['vout'], "nValue":b_utxos[1]['amount'], "asset":b_utxos[1]['asset']}, {"txid":t_utxos[0]['txid'], "vout":t_utxos[0]['vout'], "nValue":t_utxos[0]['amount'], "asset":t_utxos[0]['asset']}], {rawaddrs[1]:Decimal(t_utxos[0]['amount']), rawaddrs[0]:Decimal(b_utxos[0]['amount']+b_utxos[1]['amount']-Decimal("0.01")), "fee":Decimal("0.01")}, 0, {rawaddrs[0]:b_utxos[0]['asset'], rawaddrs[1]:t_utxos[0]['asset'], "fee":b_utxos[0]['asset']}) # Sign unblinded, then blinded signed_assets = self.nodes[2].signrawtransaction(raw_assets) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 25ed0b48b6..bcb6d5517a 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -457,12 +457,14 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) " {\n" " \"address\": x.xxx (numeric or string, required) The key is the address, the numeric value (can be string) is the given amount of the specified asset type\n" " \"data\": \"hex\", (string, required) The key is \"data\", the value is hex encoded data\n" + " \"fee\": x.xxx (numeric or string, required) The key is \"fee\", the value the fee output you want to add.\n" " ...\n" " }\n" "3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n" "4. \"output_assets\" (strings, optional, default=bitcoin) A json object of assets to addresses\n" " {\n" " \"address\": \"hex\" \n" + " \"fee\": \"hex\" \n" " ...\n" " }\n" "\nResult:\n" @@ -498,7 +500,6 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) assets = params[3].get_obj(); } - CAsset bitcoinid(BITCOINID); CAmountMap inputValue; for (unsigned int idx = 0; idx < inputs.size(); idx++) { @@ -527,7 +528,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence); - CAsset asset(bitcoinid); + CAsset asset(policyAsset); const UniValue& asset_val = find_value(o, "asset"); if (asset_val.isStr()) { asset = CAsset(ParseHashO(o, "asset")); @@ -543,13 +544,11 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) rawTx.vin.push_back(in); } - CAmountMap outputValue; - set setAddress; vector addrList = sendTo.getKeys(); BOOST_FOREACH(const string& name_, addrList) { - // Defaults to bitcoin - CAsset asset(bitcoinid); + // Defaults to policyAsset + CAsset asset(policyAsset); if (!assets.isNull()) { if (find_value(assets, name_).isNull()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Given output_asset address is not a valid given output address: ")+name_); @@ -561,6 +560,10 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) CTxOut out(asset, 0, CScript() << OP_RETURN << data); rawTx.vout.push_back(out); + } else if (name_ == "fee") { + CAmount nAmount = AmountFromValue(sendTo[name_]); + CTxOut out(asset, nAmount, CScript()); + rawTx.vout.push_back(out); } else { CBitcoinAddress address(name_); if (!address.IsValid()) @@ -573,8 +576,6 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) CScript scriptPubKey = GetScriptForDestination(address.Get()); CAmount nAmount = AmountFromValue(sendTo[name_]); - outputValue[asset] += nAmount; - CTxOut out(asset, nAmount, scriptPubKey); if (address.IsBlinded()) { CPubKey confidentiality_pubkey = address.GetBlindingKey(); @@ -586,18 +587,6 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) } } - // Now add fee outputs - CAmountMap fees = inputValue - outputValue; - for(std::map::const_iterator it = fees.begin(); it != fees.end(); it++) { - if (it->second < 0) { - throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid transaction: Value out exceeds value in for some asset type.")); - } - else if (it->second > 0) { - CTxOut out(it->first, it->second, CScript()); - rawTx.vout.push_back(out); - } - } - return EncodeHexTx(rawTx); }