aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormruddy <mruddy@users.noreply.github.com>2014-11-04 13:01:41 -0500
committermruddy <mruddy@users.noreply.github.com>2014-11-04 21:43:03 -0500
commit84877904c0f4c4d403e2c768f437c81226c1e137 (patch)
treee6451fb03475f8df5c6e37b462e83cc920ade111 /src
parentdf504e924a57fac331babef31420e257d332aa64 (diff)
bitcoin-tx: Add the "-txid" option. Also add the hex-encoded transaction to the JSON output as the "hex" property.
Diffstat (limited to 'src')
-rw-r--r--src/bitcoin-tx.cpp10
-rw-r--r--src/core_write.cpp2
2 files changed, 12 insertions, 0 deletions
diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp
index c0d21ed36f..b35b8ba53a 100644
--- a/src/bitcoin-tx.cpp
+++ b/src/bitcoin-tx.cpp
@@ -57,6 +57,7 @@ static bool AppInitRawTx(int argc, char* argv[])
strUsage += " -? " + _("This help message") + "\n";
strUsage += " -create " + _("Create new, empty TX.") + "\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 += " -testnet " + _("Use the test network") + "\n";
strUsage += "\n";
@@ -488,6 +489,13 @@ static void OutputTxJSON(const CTransaction& tx)
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)
{
string strHex = EncodeHexTx(tx);
@@ -499,6 +507,8 @@ static void OutputTx(const CTransaction& tx)
{
if (GetBoolArg("-json", false))
OutputTxJSON(tx);
+ else if (GetBoolArg("-txid", false))
+ OutputTxHash(tx);
else
OutputTxHex(tx);
}
diff --git a/src/core_write.cpp b/src/core_write.cpp
index a3ae8eec07..1d92cf87b5 100644
--- a/src/core_write.cpp
+++ b/src/core_write.cpp
@@ -129,4 +129,6 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
if (hashBlock != 0)
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".
}