Merge pull request #5207

8487790 bitcoin-tx: Add the "-txid" option. Also add the hex-encoded transaction to the JSON output as the "hex" property. (mruddy)
This commit is contained in:
Wladimir J. van der Laan 2014-12-05 11:23:20 +01:00
commit 7d42644dda
No known key found for this signature in database
GPG key ID: 74810B012346C9A6
2 changed files with 12 additions and 0 deletions

View file

@ -57,6 +57,7 @@ static bool AppInitRawTx(int argc, char* argv[])
strUsage += " -? " + _("This help message") + "\n"; strUsage += " -? " + _("This help message") + "\n";
strUsage += " -create " + _("Create new, empty TX.") + "\n"; strUsage += " -create " + _("Create new, empty TX.") + "\n";
strUsage += " -json " + _("Select JSON output") + "\n"; strUsage += " -json " + _("Select JSON output") + "\n";
strUsage += " -txid " + _("Output only the hex-encoded transaction id of the resultant transaction.") + "\n";
strUsage += " -regtest " + _("Enter regression test mode, which uses a special chain in which blocks can be solved instantly.") + "\n"; strUsage += " -regtest " + _("Enter regression test mode, which uses a special chain in which blocks can be solved instantly.") + "\n";
strUsage += " -testnet " + _("Use the test network") + "\n"; strUsage += " -testnet " + _("Use the test network") + "\n";
strUsage += "\n"; strUsage += "\n";
@ -488,6 +489,13 @@ static void OutputTxJSON(const CTransaction& tx)
fprintf(stdout, "%s\n", jsonOutput.c_str()); fprintf(stdout, "%s\n", jsonOutput.c_str());
} }
static void OutputTxHash(const CTransaction& tx)
{
string strHexHash = tx.GetHash().GetHex(); // the hex-encoded transaction hash (aka the transaction id)
fprintf(stdout, "%s\n", strHexHash.c_str());
}
static void OutputTxHex(const CTransaction& tx) static void OutputTxHex(const CTransaction& tx)
{ {
string strHex = EncodeHexTx(tx); string strHex = EncodeHexTx(tx);
@ -499,6 +507,8 @@ static void OutputTx(const CTransaction& tx)
{ {
if (GetBoolArg("-json", false)) if (GetBoolArg("-json", false))
OutputTxJSON(tx); OutputTxJSON(tx);
else if (GetBoolArg("-txid", false))
OutputTxHash(tx);
else else
OutputTxHex(tx); OutputTxHex(tx);
} }

View file

@ -129,4 +129,6 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
if (hashBlock != 0) if (hashBlock != 0)
entry.pushKV("blockhash", hashBlock.GetHex()); entry.pushKV("blockhash", hashBlock.GetHex());
entry.pushKV("hex", EncodeHexTx(tx)); // the hex-encoded transaction. used the name "hex" to be consistent with the verbose output of "getrawtransaction".
} }