aboutsummaryrefslogtreecommitdiff
path: root/bignum.h
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-02-12 20:38:44 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-02-12 20:38:44 +0000
commit98500d70a8cf25af4bab80526fd128ccdc36ceeb (patch)
tree61624e0903150505dc09977ae9ff1bc9ab40ee2b /bignum.h
parentfa9dbd6b62ab161c29c9b8cf97b9c8da8ef4346e (diff)
command line and JSON-RPC first draft, requires Boost 1.35 or higher for boost::asio,
added SetBitcoinAddress and GetBitcoinAddress methods on CScript, critsect interlocks around mapAddressBook, added some random delays in tx broadcast to improve privacy, now compiles with MSVC 8.0 git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@60 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'bignum.h')
-rw-r--r--bignum.h33
1 files changed, 32 insertions, 1 deletions
diff --git a/bignum.h b/bignum.h
index 8aa4e9c4ff..e1ab165b2c 100644
--- a/bignum.h
+++ b/bignum.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 Satoshi Nakamoto
+// Copyright (c) 2009-2010 Satoshi Nakamoto
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
@@ -309,6 +309,37 @@ public:
*this = 0 - *this;
}
+ std::string ToString(int nBase=10) const
+ {
+ CAutoBN_CTX pctx;
+ CBigNum bnBase = nBase;
+ CBigNum bn0 = 0;
+ string str;
+ CBigNum bn = *this;
+ BN_set_negative(&bn, false);
+ CBigNum dv;
+ CBigNum rem;
+ if (BN_cmp(&bn, &bn0) == 0)
+ return "0";
+ while (BN_cmp(&bn, &bn0) > 0)
+ {
+ if (!BN_div(&dv, &rem, &bn, &bnBase, pctx))
+ throw bignum_error("CBigNum::ToString() : BN_div failed");
+ bn = dv;
+ unsigned int c = rem.getulong();
+ str += "0123456789abcdef"[c];
+ }
+ if (BN_is_negative(this))
+ str += "-";
+ reverse(str.begin(), str.end());
+ return str;
+ }
+
+ std::string GetHex() const
+ {
+ return ToString(16);
+ }
+
unsigned int GetSerializeSize(int nType=0, int nVersion=VERSION) const
{
return ::GetSerializeSize(getvch(), nType, nVersion);