diff options
author | s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b> | 2010-02-12 20:38:44 +0000 |
---|---|---|
committer | s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b> | 2010-02-12 20:38:44 +0000 |
commit | 22f721dbf23cf5ce9e3ded9bcfb65a3894cc0f8c (patch) | |
tree | 61624e0903150505dc09977ae9ff1bc9ab40ee2b /bignum.h | |
parent | 73278c0a16cf0d68fb9011203a2112c3499df195 (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
Diffstat (limited to 'bignum.h')
-rw-r--r-- | bignum.h | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -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);
|