Skip to content

Commit 7d42644

Browse files
committed
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)
2 parents c78a180 + 8487790 commit 7d42644

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/bitcoin-tx.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static bool AppInitRawTx(int argc, char* argv[])
5757
strUsage += " -? " + _("This help message") + "\n";
5858
strUsage += " -create " + _("Create new, empty TX.") + "\n";
5959
strUsage += " -json " + _("Select JSON output") + "\n";
60+
strUsage += " -txid " + _("Output only the hex-encoded transaction id of the resultant transaction.") + "\n";
6061
strUsage += " -regtest " + _("Enter regression test mode, which uses a special chain in which blocks can be solved instantly.") + "\n";
6162
strUsage += " -testnet " + _("Use the test network") + "\n";
6263
strUsage += "\n";
@@ -488,6 +489,13 @@ static void OutputTxJSON(const CTransaction& tx)
488489
fprintf(stdout, "%s\n", jsonOutput.c_str());
489490
}
490491

492+
static void OutputTxHash(const CTransaction& tx)
493+
{
494+
string strHexHash = tx.GetHash().GetHex(); // the hex-encoded transaction hash (aka the transaction id)
495+
496+
fprintf(stdout, "%s\n", strHexHash.c_str());
497+
}
498+
491499
static void OutputTxHex(const CTransaction& tx)
492500
{
493501
string strHex = EncodeHexTx(tx);
@@ -499,6 +507,8 @@ static void OutputTx(const CTransaction& tx)
499507
{
500508
if (GetBoolArg("-json", false))
501509
OutputTxJSON(tx);
510+
else if (GetBoolArg("-txid", false))
511+
OutputTxHash(tx);
502512
else
503513
OutputTxHex(tx);
504514
}

src/core_write.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,6 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
129129

130130
if (hashBlock != 0)
131131
entry.pushKV("blockhash", hashBlock.GetHex());
132+
133+
entry.pushKV("hex", EncodeHexTx(tx)); // the hex-encoded transaction. used the name "hex" to be consistent with the verbose output of "getrawtransaction".
132134
}

0 commit comments

Comments
 (0)