Skip to content

Commit

Permalink
Create burn argument for createrawtransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Apr 2, 2019
1 parent a904f02 commit c0ca764
Show file tree
Hide file tree
Showing 2 changed files with 37 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
31 changes: 31 additions & 0 deletions test/functional/feature_confidential_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,37 @@ 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
import pdb
pdb.set_trace()
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 c0ca764

Please sign in to comment.