Add support for data-based outputs (OP_RETURN) to bitcoin-tx.
This commit is contained in:
parent
d7078533eb
commit
627468d2ea
@ -15,6 +15,8 @@ EXTRA_DIST += \
|
||||
test/data/tx394b54bb.hex \
|
||||
test/data/txcreate1.hex \
|
||||
test/data/txcreate2.hex \
|
||||
test/data/txcreatedata1.hex \
|
||||
test/data/txcreatedata2.hex \
|
||||
test/data/txcreatesign.hex
|
||||
|
||||
JSON_TEST_FILES = \
|
||||
|
@ -70,6 +70,7 @@ static bool AppInitRawTx(int argc, char* argv[])
|
||||
strUsage += HelpMessageOpt("locktime=N", _("Set TX lock time to N"));
|
||||
strUsage += HelpMessageOpt("nversion=N", _("Set TX version to N"));
|
||||
strUsage += HelpMessageOpt("outaddr=VALUE:ADDRESS", _("Add address-based output to TX"));
|
||||
strUsage += HelpMessageOpt("outdata=[VALUE:]DATA", _("Add data-based output to TX"));
|
||||
strUsage += HelpMessageOpt("outscript=VALUE:SCRIPT", _("Add raw script output to TX"));
|
||||
strUsage += HelpMessageOpt("sign=SIGHASH-FLAGS", _("Add zero or more signatures to transaction") + ". " +
|
||||
_("This command requires JSON registers:") +
|
||||
@ -231,6 +232,35 @@ static void MutateTxAddOutAddr(CMutableTransaction& tx, const string& strInput)
|
||||
tx.vout.push_back(txout);
|
||||
}
|
||||
|
||||
static void MutateTxAddOutData(CMutableTransaction& tx, const string& strInput)
|
||||
{
|
||||
CAmount value = 0;
|
||||
|
||||
// separate [VALUE:]DATA in string
|
||||
size_t pos = strInput.find(':');
|
||||
|
||||
if (pos==0)
|
||||
throw runtime_error("TX output value not specified");
|
||||
|
||||
if (pos != string::npos) {
|
||||
// extract and validate VALUE
|
||||
string strValue = strInput.substr(0, pos);
|
||||
if (!ParseMoney(strValue, value))
|
||||
throw runtime_error("invalid TX output value");
|
||||
}
|
||||
|
||||
// extract and validate DATA
|
||||
string strData = strInput.substr(pos + 1, string::npos);
|
||||
|
||||
if (!IsHex(strData))
|
||||
throw runtime_error("invalid TX output data");
|
||||
|
||||
std::vector<unsigned char> data = ParseHex(strData);
|
||||
|
||||
CTxOut txout(value, CScript() << OP_RETURN << data);
|
||||
tx.vout.push_back(txout);
|
||||
}
|
||||
|
||||
static void MutateTxAddOutScript(CMutableTransaction& tx, const string& strInput)
|
||||
{
|
||||
// separate VALUE:SCRIPT in string
|
||||
@ -470,6 +500,8 @@ static void MutateTx(CMutableTransaction& tx, const string& command,
|
||||
MutateTxDelOutput(tx, commandVal);
|
||||
else if (command == "outaddr")
|
||||
MutateTxAddOutAddr(tx, commandVal);
|
||||
else if (command == "outdata")
|
||||
MutateTxAddOutData(tx, commandVal);
|
||||
else if (command == "outscript")
|
||||
MutateTxAddOutScript(tx, commandVal);
|
||||
|
||||
|
@ -56,5 +56,35 @@
|
||||
"sign=ALL",
|
||||
"outaddr=0.001:193P6LtvS4nCnkDvM9uXn1gsSRqh4aDAz7"],
|
||||
"output_cmp": "txcreatesign.hex"
|
||||
},
|
||||
{ "exec": "./bitcoin-tx",
|
||||
"args":
|
||||
["-create",
|
||||
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
|
||||
"outdata=4:badhexdata"],
|
||||
"return_code": 1
|
||||
},
|
||||
{ "exec": "./bitcoin-tx",
|
||||
"args":
|
||||
["-create",
|
||||
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
|
||||
"outdata=badhexdata"],
|
||||
"return_code": 1
|
||||
},
|
||||
{ "exec": "./bitcoin-tx",
|
||||
"args":
|
||||
["-create",
|
||||
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
|
||||
"outaddr=0.18:13tuJJDR2RgArmgfv6JScSdreahzgc4T6o",
|
||||
"outdata=4:54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e"],
|
||||
"output_cmp": "txcreatedata1.hex"
|
||||
},
|
||||
{ "exec": "./bitcoin-tx",
|
||||
"args":
|
||||
["-create",
|
||||
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
|
||||
"outaddr=0.18:13tuJJDR2RgArmgfv6JScSdreahzgc4T6o",
|
||||
"outdata=54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e"],
|
||||
"output_cmp": "txcreatedata2.hex"
|
||||
}
|
||||
]
|
||||
|
1
src/test/data/txcreatedata1.hex
Normal file
1
src/test/data/txcreatedata1.hex
Normal file
@ -0,0 +1 @@
|
||||
01000000011f5c38dfcf6f1a5f5a87c416076d392c87e6d41970d5ad5e477a02d66bde97580000000000ffffffff0280a81201000000001976a9141fc11f39be1729bf973a7ab6a615ca4729d6457488ac0084d71700000000526a4c4f54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e00000000
|
1
src/test/data/txcreatedata2.hex
Normal file
1
src/test/data/txcreatedata2.hex
Normal file
@ -0,0 +1 @@
|
||||
01000000011f5c38dfcf6f1a5f5a87c416076d392c87e6d41970d5ad5e477a02d66bde97580000000000ffffffff0280a81201000000001976a9141fc11f39be1729bf973a7ab6a615ca4729d6457488ac0000000000000000526a4c4f54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e00000000
|
Loading…
Reference in New Issue
Block a user