Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoin-tx.cpp
Show All 26 Lines | |||||
#include <univalue.h> | #include <univalue.h> | ||||
#include <cstdio> | #include <cstdio> | ||||
static bool fCreateBlank; | static bool fCreateBlank; | ||||
static std::map<std::string, UniValue> registers; | static std::map<std::string, UniValue> registers; | ||||
static const int CONTINUE_EXECUTION = -1; | static const int CONTINUE_EXECUTION = -1; | ||||
static void SetupBitcoinTxArgs() { | |||||
gArgs.AddArg("-?", _("This help message"), false, OptionsCategory::OPTIONS); | |||||
gArgs.AddArg("-create", _("Create new, empty TX."), false, | |||||
OptionsCategory::OPTIONS); | |||||
gArgs.AddArg("-json", _("Select JSON output"), false, | |||||
OptionsCategory::OPTIONS); | |||||
gArgs.AddArg("-txid", | |||||
_("Output only the hex-encoded transaction id of the " | |||||
"resultant transaction."), | |||||
false, OptionsCategory::OPTIONS); | |||||
SetupChainParamsBaseOptions(); | |||||
gArgs.AddArg("delin=N", _("Delete input N from TX"), false, | |||||
OptionsCategory::COMMANDS); | |||||
gArgs.AddArg("delout=N", _("Delete output N from TX"), false, | |||||
OptionsCategory::COMMANDS); | |||||
gArgs.AddArg("in=TXID:VOUT(:SEQUENCE_NUMBER)", _("Add input to TX"), false, | |||||
OptionsCategory::COMMANDS); | |||||
gArgs.AddArg("locktime=N", _("Set TX lock time to N"), false, | |||||
OptionsCategory::COMMANDS); | |||||
gArgs.AddArg("nversion=N", _("Set TX version to N"), false, | |||||
OptionsCategory::COMMANDS); | |||||
gArgs.AddArg("outaddr=VALUE:ADDRESS", _("Add address-based output to TX"), | |||||
false, OptionsCategory::COMMANDS); | |||||
gArgs.AddArg("outpubkey=VALUE:PUBKEY[:FLAGS]", | |||||
_("Add pay-to-pubkey output to TX") + ". " + | |||||
_("Optionally add the \"S\" flag to wrap the output in a " | |||||
"pay-to-script-hash."), | |||||
false, OptionsCategory::COMMANDS); | |||||
gArgs.AddArg("outdata=[VALUE:]DATA", _("Add data-based output to TX"), | |||||
false, OptionsCategory::COMMANDS); | |||||
gArgs.AddArg("outscript=VALUE:SCRIPT[:FLAGS]", | |||||
_("Add raw script output to TX") + ". " + | |||||
_("Optionally add the \"S\" flag to wrap the output in a " | |||||
"pay-to-script-hash."), | |||||
false, OptionsCategory::COMMANDS); | |||||
gArgs.AddArg( | |||||
"outmultisig=VALUE:REQUIRED:PUBKEYS:PUBKEY1:PUBKEY2:....[:FLAGS]", | |||||
_("Add Pay To n-of-m Multi-sig output to TX. n = REQUIRED, m = " | |||||
"PUBKEYS") + | |||||
". " + | |||||
_("Optionally add the \"S\" flag to wrap the output in a " | |||||
"pay-to-script-hash."), | |||||
false, OptionsCategory::COMMANDS); | |||||
gArgs.AddArg("sign=SIGHASH-FLAGS", | |||||
_("Add zero or more signatures to transaction") + ". " + | |||||
_("This command requires JSON registers:") + | |||||
_("prevtxs=JSON object") + ", " + | |||||
_("privatekeys=JSON object") + ". " + | |||||
_("See signrawtransaction docs for format of sighash " | |||||
"flags, JSON objects."), | |||||
false, OptionsCategory::COMMANDS); | |||||
gArgs.AddArg("load=NAME:FILENAME", | |||||
_("Load JSON file FILENAME into register NAME"), false, | |||||
OptionsCategory::REGISTER_COMMANDS); | |||||
gArgs.AddArg("set=NAME:JSON-STRING", | |||||
_("Set register NAME to given JSON-STRING"), false, | |||||
OptionsCategory::REGISTER_COMMANDS); | |||||
} | |||||
// | // | ||||
// This function returns either one of EXIT_ codes when it's expected to stop | // This function returns either one of EXIT_ codes when it's expected to stop | ||||
// the process or CONTINUE_EXECUTION when it's expected to continue further. | // the process or CONTINUE_EXECUTION when it's expected to continue further. | ||||
// | // | ||||
static int AppInitRawTx(int argc, char *argv[]) { | static int AppInitRawTx(int argc, char *argv[]) { | ||||
// | // | ||||
// Parameters | // Parameters | ||||
// | // | ||||
SetupBitcoinTxArgs(); | |||||
gArgs.ParseParameters(argc, argv); | gArgs.ParseParameters(argc, argv); | ||||
// Check for -testnet or -regtest parameter (Params() calls are only valid | // Check for -testnet or -regtest parameter (Params() calls are only valid | ||||
// after this clause) | // after this clause) | ||||
try { | try { | ||||
SelectParams(gArgs.GetChainName()); | SelectParams(gArgs.GetChainName()); | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
fprintf(stderr, "Error: %s\n", e.what()); | fprintf(stderr, "Error: %s\n", e.what()); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
fCreateBlank = gArgs.GetBoolArg("-create", false); | fCreateBlank = gArgs.GetBoolArg("-create", false); | ||||
if (argc < 2 || HelpRequested(gArgs)) { | if (argc < 2 || HelpRequested(gArgs)) { | ||||
// First part of help message is specific to this utility | // First part of help message is specific to this utility | ||||
std::string strUsage = | std::string strUsage = | ||||
PACKAGE_NAME " bitcoin-tx utility version " + FormatFullVersion() + | PACKAGE_NAME " bitcoin-tx utility version " + FormatFullVersion() + | ||||
"\n\n" + | "\n\n" + | ||||
"Usage: bitcoin-tx [options] <hex-tx> [commands] Update " | "Usage: bitcoin-tx [options] <hex-tx> [commands] Update " | ||||
"hex-encoded bitcoin transaction\n" + | "hex-encoded bitcoin transaction\n" + | ||||
"or: bitcoin-tx [options] -create [commands] Create " | "or: bitcoin-tx [options] -create [commands] Create " | ||||
"hex-encoded bitcoin transaction\n" + | "hex-encoded bitcoin transaction\n" + | ||||
"\n"; | "\n"; | ||||
fprintf(stdout, "%s", strUsage.c_str()); | strUsage += gArgs.GetHelpMessage(); | ||||
strUsage = HelpMessageGroup(_("Options:")); | |||||
strUsage += HelpMessageOpt("-?", _("This help message")); | |||||
strUsage += HelpMessageOpt("-create", _("Create new, empty TX.")); | |||||
strUsage += HelpMessageOpt("-json", _("Select JSON output")); | |||||
strUsage += | |||||
HelpMessageOpt("-txid", _("Output only the hex-encoded transaction " | |||||
"id of the resultant transaction.")); | |||||
AppendParamsHelpMessages(strUsage); | |||||
fprintf(stdout, "%s", strUsage.c_str()); | |||||
strUsage = HelpMessageGroup(_("Commands:")); | |||||
strUsage += HelpMessageOpt("delin=N", _("Delete input N from TX")); | |||||
strUsage += HelpMessageOpt("delout=N", _("Delete output N from TX")); | |||||
strUsage += HelpMessageOpt("in=TXID:VOUT(:SEQUENCE_NUMBER)", | |||||
_("Add input to TX")); | |||||
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("outpubkey=VALUE:PUBKEY[:FLAGS]", | |||||
_("Add pay-to-pubkey output to TX") + ". " + | |||||
_("Optionally add the \"S\" flag to wrap the " | |||||
"output in a pay-to-script-hash.")); | |||||
strUsage += HelpMessageOpt("outdata=[VALUE:]DATA", | |||||
_("Add data-based output to TX")); | |||||
strUsage += | |||||
HelpMessageOpt("outscript=VALUE:SCRIPT[:FLAGS]", | |||||
_("Add raw script output to TX") + ". " + | |||||
_("Optionally add the \"S\" flag to wrap the " | |||||
"output in a pay-to-script-hash.")); | |||||
strUsage += HelpMessageOpt( | |||||
"outmultisig=VALUE:REQUIRED:PUBKEYS:PUBKEY1:PUBKEY2:....[:FLAGS]", | |||||
_("Add Pay To n-of-m Multi-sig output to TX. n = REQUIRED, m = " | |||||
"PUBKEYS") + | |||||
". " + | |||||
_("Optionally add the \"S\" flag to wrap the output in a " | |||||
"pay-to-script-hash.")); | |||||
strUsage += HelpMessageOpt( | |||||
"sign=SIGHASH-FLAGS", | |||||
_("Add zero or more signatures to transaction") + ". " + | |||||
_("This command requires JSON registers:") + | |||||
_("prevtxs=JSON object") + ", " + _("privatekeys=JSON object") + | |||||
". " + | |||||
_("See signrawtransaction docs for format of sighash flags, " | |||||
"JSON objects.")); | |||||
fprintf(stdout, "%s", strUsage.c_str()); | |||||
strUsage = HelpMessageGroup(_("Register Commands:")); | |||||
strUsage += | |||||
HelpMessageOpt("load=NAME:FILENAME", | |||||
_("Load JSON file FILENAME into register NAME")); | |||||
strUsage += HelpMessageOpt("set=NAME:JSON-STRING", | |||||
_("Set register NAME to given JSON-STRING")); | |||||
fprintf(stdout, "%s", strUsage.c_str()); | fprintf(stdout, "%s", strUsage.c_str()); | ||||
if (argc < 2) { | if (argc < 2) { | ||||
fprintf(stderr, "Error: too few parameters\n"); | fprintf(stderr, "Error: too few parameters\n"); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
return EXIT_SUCCESS; | return EXIT_SUCCESS; | ||||
▲ Show 20 Lines • Show All 757 Lines • Show Last 20 Lines |