aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);