Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoin-tx.cpp
Show First 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | |||||
static int AppInitRawTx(int argc, char *argv[]) { | static int AppInitRawTx(int argc, char *argv[]) { | ||||
// | // | ||||
// Parameters | // Parameters | ||||
// | // | ||||
SetupBitcoinTxArgs(); | SetupBitcoinTxArgs(); | ||||
std::string error; | std::string error; | ||||
if (!gArgs.ParseParameters(argc, argv, error)) { | if (!gArgs.ParseParameters(argc, argv, error)) { | ||||
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", | tfm::format(std::cerr, "Error parsing command line arguments: %s\n", | ||||
error.c_str()); | error); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
// Check for -chain, -testnet or -regtest parameter (Params() calls are only | // Check for -chain, -testnet or -regtest parameter (Params() calls are only | ||||
// valid after this clause) | // valid after this clause) | ||||
try { | try { | ||||
SelectParams(gArgs.GetChainName()); | SelectParams(gArgs.GetChainName()); | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
Show All 9 Lines | if (argc < 2 || HelpRequested(gArgs)) { | ||||
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"; | ||||
strUsage += gArgs.GetHelpMessage(); | strUsage += gArgs.GetHelpMessage(); | ||||
tfm::format(std::cout, "%s", strUsage.c_str()); | |||||
tfm::format(std::cout, "%s", strUsage); | |||||
if (argc < 2) { | if (argc < 2) { | ||||
tfm::format(std::cerr, "Error: too few parameters\n"); | tfm::format(std::cerr, "Error: too few parameters\n"); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
return EXIT_SUCCESS; | return EXIT_SUCCESS; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 610 Lines • ▼ Show 20 Lines | static void MutateTx(CMutableTransaction &tx, const std::string &command, | ||||
} | } | ||||
} | } | ||||
static void OutputTxJSON(const CTransaction &tx) { | static void OutputTxJSON(const CTransaction &tx) { | ||||
UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
TxToUniv(tx, uint256(), entry); | TxToUniv(tx, uint256(), entry); | ||||
std::string jsonOutput = entry.write(4); | std::string jsonOutput = entry.write(4); | ||||
tfm::format(std::cout, "%s\n", jsonOutput.c_str()); | tfm::format(std::cout, "%s\n", jsonOutput); | ||||
} | } | ||||
static void OutputTxHash(const CTransaction &tx) { | static void OutputTxHash(const CTransaction &tx) { | ||||
// the hex-encoded transaction id. | // the hex-encoded transaction id. | ||||
std::string strHexHash = tx.GetId().GetHex(); | std::string strHexHash = tx.GetId().GetHex(); | ||||
tfm::format(std::cout, "%s\n", strHexHash.c_str()); | tfm::format(std::cout, "%s\n", strHexHash); | ||||
} | } | ||||
static void OutputTxHex(const CTransaction &tx) { | static void OutputTxHex(const CTransaction &tx) { | ||||
std::string strHex = EncodeHexTx(tx); | std::string strHex = EncodeHexTx(tx); | ||||
tfm::format(std::cout, "%s\n", strHex.c_str()); | tfm::format(std::cout, "%s\n", strHex); | ||||
} | } | ||||
static void OutputTx(const CTransaction &tx) { | static void OutputTx(const CTransaction &tx) { | ||||
if (gArgs.GetBoolArg("-json", false)) { | if (gArgs.GetBoolArg("-json", false)) { | ||||
OutputTxJSON(tx); | OutputTxJSON(tx); | ||||
} else if (gArgs.GetBoolArg("-txid", false)) { | } else if (gArgs.GetBoolArg("-txid", false)) { | ||||
OutputTxHash(tx); | OutputTxHash(tx); | ||||
} else { | } else { | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | try { | ||||
strPrint = std::string("error: ") + e.what(); | strPrint = std::string("error: ") + e.what(); | ||||
nRet = EXIT_FAILURE; | nRet = EXIT_FAILURE; | ||||
} catch (...) { | } catch (...) { | ||||
PrintExceptionContinue(nullptr, "CommandLineRawTx()"); | PrintExceptionContinue(nullptr, "CommandLineRawTx()"); | ||||
throw; | throw; | ||||
} | } | ||||
if (strPrint != "") { | if (strPrint != "") { | ||||
tfm::format(nRet == 0 ? std::cout : std::cerr, "%s\n", | tfm::format(nRet == 0 ? std::cout : std::cerr, "%s\n", strPrint); | ||||
strPrint.c_str()); | |||||
} | } | ||||
return nRet; | return nRet; | ||||
} | } | ||||
int main(int argc, char *argv[]) { | int main(int argc, char *argv[]) { | ||||
SetupEnvironment(); | SetupEnvironment(); | ||||
Show All 24 Lines |