Permalink
Browse files

First commit

  • Loading branch information...
non-github-bitcoin committed Aug 30, 2009
0 parents commit 4405b78d6059e536c36974088a8ed4d9f0f29898
Showing with 32,239 additions and 0 deletions.
  1. +201 −0 base58.h
  2. +498 −0 bignum.h
  3. +614 −0 db.cpp
  4. +420 −0 db.h
  5. +71 −0 headers.h
  6. +314 −0 irc.cpp
  7. +10 −0 irc.h
  8. +156 −0 key.h
  9. BIN libeay32.dll
  10. +19 −0 license.txt
  11. +2,692 −0 main.cpp
  12. +1,329 −0 main.h
  13. +83 −0 makefile
  14. +77 −0 makefile.vc
  15. +264 −0 market.cpp
  16. +182 −0 market.h
  17. BIN mingwm10.dll
  18. +1,100 −0 net.cpp
  19. +856 −0 net.h
  20. BIN rc/addressbook16.bmp
  21. BIN rc/addressbook16mask.bmp
  22. BIN rc/addressbook20.bmp
  23. BIN rc/addressbook20mask.bmp
  24. BIN rc/bitcoin.ico
  25. BIN rc/check.ico
  26. BIN rc/send16.bmp
  27. BIN rc/send16mask.bmp
  28. BIN rc/send16masknoshadow.bmp
  29. BIN rc/send20.bmp
  30. BIN rc/send20mask.bmp
  31. +76 −0 readme.txt
  32. +1,127 −0 script.cpp
  33. +597 −0 script.h
  34. +1,158 −0 serialize.h
  35. +554 −0 sha.cpp
  36. +177 −0 sha.h
  37. +3,290 −0 ui.cpp
  38. +420 −0 ui.h
  39. +14 −0 ui.rc
  40. +1,825 −0 uibase.cpp
  41. +723 −0 uibase.h
  42. +750 −0 uint256.h
  43. +11,860 −0 uiproject.fbp
  44. +383 −0 util.cpp
  45. +399 −0 util.h
201 base58.h
@@ -0,0 +1,201 @@
// Copyright (c) 2009 Satoshi Nakamoto
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
//
// Why base-58 instead of standard base-64 encoding?
// - Don't want 0OIl characters that look the same in some fonts and
// could be used to create visually identical looking account numbers.
// - A string with non-alphanumeric characters is not as easily accepted as an account number.
// - E-mail usually won't line-break if there's no punctuation to break at.
// - Doubleclicking selects the whole number as one word if it's all alphanumeric.
//
static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
inline string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend)
{
CAutoBN_CTX pctx;
CBigNum bn58 = 58;
CBigNum bn0 = 0;
// Convert big endian data to little endian
// Extra zero at the end make sure bignum will interpret as a positive number
vector<unsigned char> vchTmp(pend-pbegin+1, 0);
reverse_copy(pbegin, pend, vchTmp.begin());
// Convert little endian data to bignum
CBigNum bn;
bn.setvch(vchTmp);
// Convert bignum to string
string str;
str.reserve((pend - pbegin) * 138 / 100 + 1);
CBigNum dv;
CBigNum rem;
while (bn > bn0)
{
if (!BN_div(&dv, &rem, &bn, &bn58, pctx))
throw bignum_error("EncodeBase58 : BN_div failed");
bn = dv;
unsigned int c = rem.getulong();
str += pszBase58[c];
}
// Leading zeroes encoded as base58 zeros
for (const unsigned char* p = pbegin; p < pend && *p == 0; p++)
str += pszBase58[0];
// Convert little endian string to big endian
reverse(str.begin(), str.end());
return str;
}
inline string EncodeBase58(const vector<unsigned char>& vch)
{
return EncodeBase58(&vch[0], &vch[0] + vch.size());
}
inline bool DecodeBase58(const char* psz, vector<unsigned char>& vchRet)
{
CAutoBN_CTX pctx;
vchRet.clear();
CBigNum bn58 = 58;
CBigNum bn = 0;
CBigNum bnChar;
while (isspace(*psz))
psz++;
// Convert big endian string to bignum
for (const char* p = psz; *p; p++)
{
const char* p1 = strchr(pszBase58, *p);
if (p1 == NULL)
{
while (isspace(*p))
p++;
if (*p != '\0')
return false;
break;
}
bnChar.setulong(p1 - pszBase58);
if (!BN_mul(&bn, &bn, &bn58, pctx))
throw bignum_error("DecodeBase58 : BN_mul failed");
bn += bnChar;
}
// Get bignum as little endian data
vector<unsigned char> vchTmp = bn.getvch();
// Trim off sign byte if present
if (vchTmp.size() >= 2 && vchTmp.end()[-1] == 0 && vchTmp.end()[-2] >= 0x80)
vchTmp.erase(vchTmp.end()-1);
// Restore leading zeros
int nLeadingZeros = 0;
for (const char* p = psz; *p == pszBase58[0]; p++)
nLeadingZeros++;
vchRet.assign(nLeadingZeros + vchTmp.size(), 0);
// Convert little endian data to big endian
reverse_copy(vchTmp.begin(), vchTmp.end(), vchRet.end() - vchTmp.size());
return true;
}
inline bool DecodeBase58(const string& str, vector<unsigned char>& vchRet)
{
return DecodeBase58(str.c_str(), vchRet);
}
inline string EncodeBase58Check(const vector<unsigned char>& vchIn)
{
// add 4-byte hash check to the end
vector<unsigned char> vch(vchIn);
uint256 hash = Hash(vch.begin(), vch.end());
vch.insert(vch.end(), (unsigned char*)&hash, (unsigned char*)&hash + 4);
return EncodeBase58(vch);
}
inline bool DecodeBase58Check(const char* psz, vector<unsigned char>& vchRet)
{
if (!DecodeBase58(psz, vchRet))
return false;
if (vchRet.size() < 4)
{
vchRet.clear();
return false;
}
uint256 hash = Hash(vchRet.begin(), vchRet.end()-4);
if (memcmp(&hash, &vchRet.end()[-4], 4) != 0)
{
vchRet.clear();
return false;
}
vchRet.resize(vchRet.size()-4);
return true;
}
inline bool DecodeBase58Check(const string& str, vector<unsigned char>& vchRet)
{
return DecodeBase58Check(str.c_str(), vchRet);
}
static const unsigned char ADDRESSVERSION = 0;
inline string Hash160ToAddress(uint160 hash160)
{
// add 1-byte version number to the front
vector<unsigned char> vch(1, ADDRESSVERSION);
vch.insert(vch.end(), UBEGIN(hash160), UEND(hash160));
return EncodeBase58Check(vch);
}
inline bool AddressToHash160(const char* psz, uint160& hash160Ret)
{
vector<unsigned char> vch;
if (!DecodeBase58Check(psz, vch))
return false;
if (vch.empty())
return false;
unsigned char nVersion = vch[0];
if (vch.size() != sizeof(hash160Ret) + 1)
return false;
memcpy(&hash160Ret, &vch[1], sizeof(hash160Ret));
return (nVersion <= ADDRESSVERSION);
}
inline bool AddressToHash160(const string& str, uint160& hash160Ret)
{
return AddressToHash160(str.c_str(), hash160Ret);
}
inline bool IsValidBitcoinAddress(const char* psz)
{
uint160 hash160;
return AddressToHash160(psz, hash160);
}
inline bool IsValidBitcoinAddress(const string& str)
{
return IsValidBitcoinAddress(str.c_str());
}
inline string PubKeyToAddress(const vector<unsigned char>& vchPubKey)
{
return Hash160ToAddress(Hash160(vchPubKey));
}
Oops, something went wrong.

14 comments on commit 4405b78

@laanwj

This comment has been minimized.

Member

laanwj replied Aug 31, 2014

These initial commits were converted from svn on sourceforge. Earlier changes were never in either svn or git. Not sure if Satoshi used any kind of source control before this.

@joncursi

This comment has been minimized.

joncursi replied Feb 3, 2016

Thanks for the info @laanwj.

Hello to those curious enough about bitcoin to arrive here! 👍

@pablophg

This comment has been minimized.

pablophg replied Feb 6, 2016

@joncursi reporting in 👍 :)

@wangchun

This comment has been minimized.

wangchun replied Feb 6, 2016

关爱健康,拒绝挖坟。

@petertodd

This comment has been minimized.

Contributor

petertodd replied Feb 10, 2016

@wangchun Lol, I'm really curious what you said there, as google translate gave me something that didn't make any sense to me; I assume it's some kind of Chinese idiom. :)

@wangchun

This comment has been minimized.

wangchun replied Feb 15, 2016

@petertodd I said gravedigging (replying to an ancient post) should be avoided.

@petertodd

This comment has been minimized.

Contributor

petertodd replied Feb 15, 2016

@wangchun Ah, thanks! Cool that the idiom does translate over.

@peromax

This comment has been minimized.

peromax replied Jun 25, 2016

Такая большая вещь и так мало комментариев. 🙄

@nobsu

This comment has been minimized.

nobsu replied Jun 15, 2017

膜拜

@vrsomu59

This comment has been minimized.

vrsomu59 replied Jun 29, 2017

cool .. 👍

@sellis

This comment has been minimized.

sellis replied Jul 28, 2017

Pretty good start. I approve the changes.

@jewei

This comment has been minimized.

jewei replied Aug 9, 2017

This is an art already!

@llazzaro

This comment has been minimized.

llazzaro replied Aug 17, 2017

reporting in 👍

@ediston

This comment has been minimized.

ediston replied Aug 26, 2017

nice

Please sign in to comment.