add p2sh and segwit options to bitcoin-tx outscript command
This commit is contained in:
parent
dce853ef76
commit
1814b089fb
1 changed files with 18 additions and 8 deletions
|
@ -79,7 +79,9 @@ static int AppInitRawTx(int argc, char* argv[])
|
||||||
strUsage += HelpMessageOpt("nversion=N", _("Set TX version to N"));
|
strUsage += HelpMessageOpt("nversion=N", _("Set TX version to N"));
|
||||||
strUsage += HelpMessageOpt("outaddr=VALUE:ADDRESS", _("Add address-based output to TX"));
|
strUsage += HelpMessageOpt("outaddr=VALUE:ADDRESS", _("Add address-based output to TX"));
|
||||||
strUsage += HelpMessageOpt("outdata=[VALUE:]DATA", _("Add data-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") + ". " +
|
strUsage += HelpMessageOpt("sign=SIGHASH-FLAGS", _("Add zero or more signatures to transaction") + ". " +
|
||||||
_("This command requires JSON registers:") +
|
_("This command requires JSON registers:") +
|
||||||
_("prevtxs=JSON object") + ", " +
|
_("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)
|
static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& strInput)
|
||||||
{
|
{
|
||||||
// separate VALUE:SCRIPT in string
|
// separate VALUE:SCRIPT(:SEGWIT)(:P2SH)
|
||||||
size_t pos = strInput.find(':');
|
std::vector<std::string> vStrInput;
|
||||||
if ((pos == std::string::npos) ||
|
boost::split(vStrInput, strInput, boost::is_any_of(":"));
|
||||||
(pos == 0))
|
if (vStrInput.size() < 2)
|
||||||
throw std::runtime_error("TX output missing separator");
|
throw srd::runtime_error("TX output missing separator");
|
||||||
|
|
||||||
// extract and validate VALUE
|
// extract and validate VALUE
|
||||||
std::string strValue = strInput.substr(0, pos);
|
std::string strValue = vStrInput[0];
|
||||||
CAmount value;
|
CAmount value;
|
||||||
if (!ParseMoney(strValue, value))
|
if (!ParseMoney(strValue, value))
|
||||||
throw std::runtime_error("invalid TX output value");
|
throw std::runtime_error("invalid TX output value");
|
||||||
|
|
||||||
// extract and validate script
|
// 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
|
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
|
// construct TxOut, append to transaction output list
|
||||||
CTxOut txout(value, scriptPubKey);
|
CTxOut txout(value, scriptPubKey);
|
||||||
tx.vout.push_back(txout);
|
tx.vout.push_back(txout);
|
||||||
|
|
Loading…
Reference in a new issue