From cbe39a38526a6c17619d02cc697b80ebfd57203b Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Tue, 29 Jul 2014 11:12:44 -0400 Subject: Add "bitcoin-tx" command line utility and supporting modules. This is a simple utility that provides command line manipulation of a hex-encoded TX. The utility takes a hex string on the command line as input, performs zero or more mutations, and outputs a hex string to standard output. This utility is also an intentional exercise of the "bitcoin library" concept. It is designed to require minimal libraries, and works entirely without need for any RPC or P2P communication. See "bitcoin-tx --help" for command and options summary. --- src/core_read.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/core_read.cpp') diff --git a/src/core_read.cpp b/src/core_read.cpp index 1ecd6db32..0f06bb695 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -4,12 +4,14 @@ #include "core.h" #include "serialize.h" #include "script.h" +#include "util.h" #include #include #include #include #include +#include "univalue/univalue.h" using namespace std; using namespace boost; @@ -100,3 +102,26 @@ bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx) return true; } +uint256 ParseHashUV(const UniValue& v, const string& strName) +{ + string strHex; + if (v.isStr()) + strHex = v.getValStr(); + if (!IsHex(strHex)) // Note: IsHex("") is false + throw runtime_error(strName+" must be hexadecimal string (not '"+strHex+"')"); + + uint256 result; + result.SetHex(strHex); + return result; +} + +vector ParseHexUV(const UniValue& v, const string& strName) +{ + string strHex; + if (v.isStr()) + strHex = v.getValStr(); + if (!IsHex(strHex)) + throw runtime_error(strName+" must be hexadecimal string (not '"+strHex+"')"); + return ParseHex(strHex); +} + -- cgit v1.2.3