summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmir Taaki <genjix@riseup.net>2014-05-08 17:43:28 (GMT)
committer Amir Taaki <genjix@riseup.net>2014-05-08 17:43:28 (GMT)
commitb8a044e79d71289a7a64e33d17d3be3a3fde15ed (patch)
tree1644ed504e3742f94de52b54d055a7277a6244d7
parentfa0d63b155c95656a969e6e469016b553fe84b78 (diff)
tidied up code ever so slightly.
-rw-r--r--src/ec-multiply.cpp15
-rw-r--r--src/ec-tweak-add.cpp15
-rw-r--r--src/ec_util.hpp27
-rwxr-xr-xsrc/sx.py4
4 files changed, 30 insertions, 31 deletions
diff --git a/src/ec-multiply.cpp b/src/ec-multiply.cpp
index 0ce63da..8827b95 100644
--- a/src/ec-multiply.cpp
+++ b/src/ec-multiply.cpp
@@ -7,21 +7,10 @@ int main(int argc, char** argv)
std::cerr << "Usage: sx ec-multiply INTEGER POINT" << std::endl;
return -1;
}
- ec_secret int_part = null_hash;
+ ec_secret int_part;
ec_point point_part;
- for (size_t i = 1; i < argc; ++i)
- {
- const auto arg = argv[i];
- if (set_ec_secret(int_part, arg))
- continue;
- if (set_ec_point(point_part, arg))
- continue;
- }
- if (int_part == null_hash || point_part.empty())
- {
- std::cerr << "sx: Unable to read input values." << std::endl;
+ if (!ec_math_parse_args(argc, argv, int_part, point_part))
return -1;
- }
bool success = (point_part *= int_part);
if (!success)
{
diff --git a/src/ec-tweak-add.cpp b/src/ec-tweak-add.cpp
index 7d7b658..bb22785 100644
--- a/src/ec-tweak-add.cpp
+++ b/src/ec-tweak-add.cpp
@@ -7,21 +7,10 @@ int main(int argc, char** argv)
std::cerr << "Usage: sx ec-multiply INTEGER POINT" << std::endl;
return -1;
}
- ec_secret int_part = null_hash;
+ ec_secret int_part;
ec_point point_part;
- for (size_t i = 1; i < argc; ++i)
- {
- const auto arg = argv[i];
- if (set_ec_secret(int_part, arg))
- continue;
- if (set_ec_point(point_part, arg))
- continue;
- }
- if (int_part == null_hash || point_part.empty())
- {
- std::cerr << "sx: Unable to read input values." << std::endl;
+ if (!ec_math_parse_args(argc, argv, int_part, point_part))
return -1;
- }
bool success = (point_part += int_part);
if (!success)
{
diff --git a/src/ec_util.hpp b/src/ec_util.hpp
index 7a6bc67..fe2fcbe 100644
--- a/src/ec_util.hpp
+++ b/src/ec_util.hpp
@@ -3,12 +3,14 @@ using namespace bc;
bool set_ec_secret(ec_secret& secret, const std::string& arg)
{
- secret = decode_hex_digest<ec_secret>(arg);
- return secret != null_hash;
+ ec_secret result = decode_hex_digest<ec_secret>(arg);
+ if (result == null_hash)
+ return false;
+ secret = result;
+ return true;
}
bool set_ec_point(ec_point& point, const std::string& arg)
{
- //if (arg == "G")
ec_point result = decode_hex(arg);
if (result.size() != ec_compressed_size)
return false;
@@ -18,3 +20,22 @@ bool set_ec_point(ec_point& point, const std::string& arg)
return true;
}
+bool ec_math_parse_args(
+ int argc, char** argv, ec_secret& secret, ec_point& point)
+{
+ for (size_t i = 1; i < argc; ++i)
+ {
+ const auto arg = argv[i];
+ if (set_ec_secret(secret, arg))
+ continue;
+ if (set_ec_point(point, arg))
+ continue;
+ }
+ if (secret == null_hash || point.empty())
+ {
+ std::cerr << "sx: Unable to read input values." << std::endl;
+ return false;
+ }
+ return true;
+}
+
diff --git a/src/sx.py b/src/sx.py
index 4a70376..af52c19 100755
--- a/src/sx.py
+++ b/src/sx.py
@@ -512,7 +512,7 @@ The VALUE field is in Satoshis.\
),
"wif-to-secret": (
-"STEALTH",
+"LOOSE KEYS AND ADDRESSES",
"Convert a Wallet. Import. Format to secret exponent value.",
"""\
@@ -522,7 +522,7 @@ Usage: echo WIF | sx wif-to-secret
),
"secret-to-wif": (
-"STEALTH",
+"LOOSE KEYS AND ADDRESSES",
"Convert a secret exponent value to Wallet. Import. Format.",
"""\