aboutsummaryrefslogtreecommitdiff
path: root/src/core_read.cpp
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@bitpay.com>2014-07-29 11:12:44 -0400
committerJeff Garzik <jgarzik@bitpay.com>2014-07-29 11:13:27 -0400
commitcbe39a38526a6c17619d02cc697b80ebfd57203b (patch)
tree41ee0470ef9b6f3c87a4bb509c5b25ddba84c3a5 /src/core_read.cpp
parent3ce7e669e3f90b3099a969ea5ffe3fa2643f4ed8 (diff)
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.
Diffstat (limited to 'src/core_read.cpp')
-rw-r--r--src/core_read.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/core_read.cpp b/src/core_read.cpp
index 1ecd6db324..0f06bb6952 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 <boost/assign/list_of.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/replace.hpp>
+#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<unsigned char> 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);
+}
+