aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoin-tx.cpp
diff options
context:
space:
mode:
authorStanislas Marion <stanislas.marion@gmail.com>2016-09-30 15:29:45 -0400
committerJohn Newbery <john@johnnewbery.com>2016-12-29 15:40:40 +0000
commit1814b089fbf6eca03b1f026e2033d4a6ccc6305f (patch)
treec0dc1cbcb8f8a54b3772c60ea14e54168e42ed8b /src/bitcoin-tx.cpp
parentdce853ef76ef90c46d84294225088d595467d08c (diff)
add p2sh and segwit options to bitcoin-tx outscript command
Diffstat (limited to 'src/bitcoin-tx.cpp')
-rw-r--r--src/bitcoin-tx.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp
index d46f330453..f9bb9f77de 100644
--- a/src/bitcoin-tx.cpp
+++ b/src/bitcoin-tx.cpp
@@ -79,7 +79,9 @@ static int AppInitRawTx(int argc, char* argv[])
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("outscript=VALUE:SCRIPT(:\"SEGWIT\")(:\"P2SH\")", _("Add raw script output to TX") + ". " +
+ _("Optionally add the \"SEGWIT\" flag to produce a segwit output") + ". " +
+ _("Optionally add the \"P2SH\" flag to wrap the script in a P2SH output."));
strUsage += HelpMessageOpt("sign=SIGHASH-FLAGS", _("Add zero or more signatures to transaction") + ". " +
_("This command requires JSON registers:") +
_("prevtxs=JSON object") + ", " +
@@ -280,22 +282,30 @@ static void MutateTxAddOutData(CMutableTransaction& tx, const std::string& strIn
static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& strInput)
{
- // separate VALUE:SCRIPT in string
- size_t pos = strInput.find(':');
- if ((pos == std::string::npos) ||
- (pos == 0))
- throw std::runtime_error("TX output missing separator");
+ // separate VALUE:SCRIPT(:SEGWIT)(:P2SH)
+ std::vector<std::string> vStrInput;
+ boost::split(vStrInput, strInput, boost::is_any_of(":"));
+ if (vStrInput.size() < 2)
+ throw srd::runtime_error("TX output missing separator");
// extract and validate VALUE
- std::string strValue = strInput.substr(0, pos);
+ std::string strValue = vStrInput[0];
CAmount value;
if (!ParseMoney(strValue, value))
throw std::runtime_error("invalid TX output value");
// extract and validate script
- std::string strScript = strInput.substr(pos + 1, std::string::npos);
+ std::string strScript = vStrInput[1];
CScript scriptPubKey = ParseScript(strScript); // throws on err
+ if (std::find(vStrInput.begin(), vStrInput.end(), "SEGWIT") != vStrInput.end()) {
+ scriptPubKey = GetScriptForWitness(scriptPubKey);
+ }
+ if (std::find(vStrInput.begin(), vStrInput.end(), "P2SH") != vStrInput.end()) {
+ CBitcoinAddress addr(scriptPubKey);
+ scriptPubKey = GetScriptForDestination(addr.Get());
+ }
+
// construct TxOut, append to transaction output list
CTxOut txout(value, scriptPubKey);
tx.vout.push_back(txout);