Skip to content

Commit

Permalink
Merge bitcoin#558: Create burn argument for createrawtransaction
Browse files Browse the repository at this point in the history
39357ca Create burn argument for createrawtransaction (Gregory Sanders)

Pull request description:

  Allows a no-data burn of any given asset using the raw interface to support multi-sig burn when `destroyamount` will not suffice.

  Resolves ElementsProject/elements#557

Tree-SHA512: 77309701c97861b30e141138b34efab3be6667993e0aa725d61500fa6943af9ce6114efcfd14fb6f8bade92d98bfcf8a5c7163a382a7358e3f160b36d0d944c8
  • Loading branch information
stevenroose committed Apr 3, 2019
2 parents f79c2fe + 39357ca commit 07cf0b2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,11 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
// ELEMENTS: explicit fee outputs
CAmount nAmount = AmountFromValue(outputs[name_]);
fee_out = CTxOut(asset, nAmount, CScript());
} else if (name_ == "burn") {
CScript datascript = CScript() << OP_RETURN;
CAmount nAmount = AmountFromValue(outputs[name_]);
CTxOut out(asset, nAmount, datascript);
rawTx.vout.push_back(out);
} else {
CTxDestination destination = DecodeDestination(name_);
if (!IsValidDestination(destination)) {
Expand Down Expand Up @@ -522,6 +527,7 @@ static UniValue createrawtransaction(const JSONRPCRequest& request)
" {\n"
" \"data\": \"hex\" , (obj, optional) A key-value pair. The key must be \"data\", the value is hex encoded data\n"
" \"vdata\": [\"hex\"] (string, optional) The key is \"vdata\", the value is an array of hex encoded data\n"
" \"burn\": x.xxx, (obj, optional) A key-value pair. The key must be \"burn\", the value is the amount that will be burned.\n"
" },\n"
" {\n"
" \"fee\": x.xxx (numeric or string, optional) The key is \"fee\", the value the fee output you want to add.\n"
Expand Down
29 changes: 29 additions & 0 deletions test/functional/feature_confidential_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,35 @@ def run_test(self):
assert("value" in outputs[0] and "value" in outputs[1] and "value" in outputs[2])
assert_equal(outputs[2]["scriptPubKey"]["type"], 'nulldata')

# Test burn argument in createrawtransaction
raw_burn1 = self.nodes[0].createrawtransaction([], {self.nodes[0].getnewaddress():1, "burn":2})
decode_burn1 = self.nodes[0].decoderawtransaction(raw_burn1)
assert_equal(len(decode_burn1["vout"]), 2)
found_pay = False
found_burn = False
for output in decode_burn1["vout"]:
if output["scriptPubKey"]["asm"] == "OP_RETURN":
found_burn = True
if output["asset"] != self.nodes[0].dumpassetlabels()["bitcoin"]:
raise Exception("Burn should have been bitcoin(policyAsset)")
if output["scriptPubKey"]["type"] == "scripthash":
found_pay = True
assert(found_pay and found_burn)

raw_burn2 = self.nodes[0].createrawtransaction([], {self.nodes[0].getnewaddress():1, "burn":2}, 101, False, {"burn":"deadbeef"*8})
decode_burn2 = self.nodes[0].decoderawtransaction(raw_burn2)
assert_equal(len(decode_burn2["vout"]), 2)
found_pay = False
found_burn = False
for output in decode_burn2["vout"]:
if output["scriptPubKey"]["asm"] == "OP_RETURN":
found_burn = True
if output["asset"] != "deadbeef"*8:
raise Exception("Burn should have been deadbeef")
if output["scriptPubKey"]["type"] == "scripthash":
found_pay = True
assert(found_pay and found_burn)

# TODO: signrawtransactionwith{wallet, key} with confidential segwit input given as previous transaction arg

if __name__ == '__main__':
Expand Down

0 comments on commit 07cf0b2

Please sign in to comment.