From 98500d70a8cf25af4bab80526fd128ccdc36ceeb Mon Sep 17 00:00:00 2001 From: s_nakamoto Date: Fri, 12 Feb 2010 20:38:44 +0000 Subject: 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 --- bignum.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'bignum.h') 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); -- cgit v1.2.3