Merge branch 'master' of https://github.com/bitcoin/bitcoin
This commit is contained in:
commit
0a76546ae9
16 changed files with 118 additions and 15 deletions
|
@ -610,7 +610,7 @@ bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account)
|
||||||
|
|
||||||
bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
|
bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
|
||||||
{
|
{
|
||||||
return Write(make_tuple(string("acentry"), acentry.strAccount, ++nAccountingEntryNumber), acentry);
|
return Write(boost::make_tuple(string("acentry"), acentry.strAccount, ++nAccountingEntryNumber), acentry);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64 CWalletDB::GetAccountCreditDebit(const string& strAccount)
|
int64 CWalletDB::GetAccountCreditDebit(const string& strAccount)
|
||||||
|
@ -638,7 +638,7 @@ void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountin
|
||||||
// Read next record
|
// Read next record
|
||||||
CDataStream ssKey;
|
CDataStream ssKey;
|
||||||
if (fFlags == DB_SET_RANGE)
|
if (fFlags == DB_SET_RANGE)
|
||||||
ssKey << make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64(0));
|
ssKey << boost::make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64(0));
|
||||||
CDataStream ssValue;
|
CDataStream ssValue;
|
||||||
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
|
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
|
||||||
fFlags = DB_NEXT;
|
fFlags = DB_NEXT;
|
||||||
|
|
|
@ -4,10 +4,17 @@
|
||||||
#ifndef BITCOIN_KEY_H
|
#ifndef BITCOIN_KEY_H
|
||||||
#define BITCOIN_KEY_H
|
#define BITCOIN_KEY_H
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <openssl/ec.h>
|
#include <openssl/ec.h>
|
||||||
#include <openssl/ecdsa.h>
|
#include <openssl/ecdsa.h>
|
||||||
#include <openssl/obj_mac.h>
|
#include <openssl/obj_mac.h>
|
||||||
|
|
||||||
|
#include "serialize.h"
|
||||||
|
#include "uint256.h"
|
||||||
|
#include "base58.h"
|
||||||
|
|
||||||
// secp160k1
|
// secp160k1
|
||||||
// const unsigned int PRIVATE_KEY_SIZE = 192;
|
// const unsigned int PRIVATE_KEY_SIZE = 192;
|
||||||
// const unsigned int PUBLIC_KEY_SIZE = 41;
|
// const unsigned int PUBLIC_KEY_SIZE = 41;
|
||||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -314,6 +314,15 @@ bool CTransaction::CheckTransaction() const
|
||||||
return error("CTransaction::CheckTransaction() : txout total out of range");
|
return error("CTransaction::CheckTransaction() : txout total out of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for duplicate inputs
|
||||||
|
set<COutPoint> vInOutPoints;
|
||||||
|
BOOST_FOREACH(const CTxIn& txin, vin)
|
||||||
|
{
|
||||||
|
if (vInOutPoints.count(txin.prevout))
|
||||||
|
return false;
|
||||||
|
vInOutPoints.insert(txin.prevout);
|
||||||
|
}
|
||||||
|
|
||||||
if (IsCoinBase())
|
if (IsCoinBase())
|
||||||
{
|
{
|
||||||
if (vin[0].scriptSig.size() < 2 || vin[0].scriptSig.size() > 100)
|
if (vin[0].scriptSig.size() < 2 || vin[0].scriptSig.size() > 100)
|
||||||
|
@ -1766,7 +1775,7 @@ bool static AlreadyHave(CTxDB& txdb, const CInv& inv)
|
||||||
// The message start string is designed to be unlikely to occur in normal data.
|
// The message start string is designed to be unlikely to occur in normal data.
|
||||||
// The characters are rarely used upper ascii, not valid as UTF-8, and produce
|
// The characters are rarely used upper ascii, not valid as UTF-8, and produce
|
||||||
// a large 4-byte int at any alignment.
|
// a large 4-byte int at any alignment.
|
||||||
char pchMessageStart[4] = { 0xf9, 0xbe, 0xb4, 0xd9 };
|
unsigned char pchMessageStart[4] = { 0xf9, 0xbe, 0xb4, 0xd9 };
|
||||||
|
|
||||||
|
|
||||||
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||||
|
|
|
@ -90,7 +90,7 @@ bitcoind.exe: $(OBJS:obj/%=obj/nogui/%) obj/ui_res.o
|
||||||
obj/test/%.o: obj/test/%.cpp $(HEADERS)
|
obj/test/%.o: obj/test/%.cpp $(HEADERS)
|
||||||
i586-mingw32msvc-g++ -c $(CFLAGS) -o $@ $<
|
i586-mingw32msvc-g++ -c $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
test_bitcoin.exe: obj/test/test_bitcoin.o
|
test_bitcoin.exe: obj/test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
|
||||||
i586-mingw32msvc-g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) -lboost_unit_test_framework-mt-s
|
i586-mingw32msvc-g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) -lboost_unit_test_framework-mt-s
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ bitcoind.exe: $(OBJS:obj/%=obj/nogui/%) obj/ui_res.o
|
||||||
obj/test/%.o: obj/test/%.cpp $(HEADERS)
|
obj/test/%.o: obj/test/%.cpp $(HEADERS)
|
||||||
g++ -c $(CFLAGS) -o $@ $<
|
g++ -c $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
test_bitcoin: obj/test/test_bitcoin.o
|
test_bitcoin.exe: obj/test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
|
||||||
g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
|
g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
|
@ -79,7 +79,7 @@ bitcoind: $(OBJS:obj/%=obj/nogui/%)
|
||||||
obj/test/%.o: test/%.cpp $(HEADERS)
|
obj/test/%.o: test/%.cpp $(HEADERS)
|
||||||
$(CXX) -c $(CFLAGS) -o $@ $<
|
$(CXX) -c $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
test_bitcoin: obj/test/test_bitcoin.o
|
test_bitcoin: obj/test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
|
||||||
$(CXX) $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) -lboost_unit_test_framework
|
$(CXX) $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) -lboost_unit_test_framework
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
|
@ -78,10 +78,10 @@ bitcoind: $(OBJS:obj/%=obj/nogui/%)
|
||||||
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)
|
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)
|
||||||
|
|
||||||
obj/test/%.o: test/%.cpp $(HEADERS)
|
obj/test/%.o: test/%.cpp $(HEADERS)
|
||||||
$(CXX) -c $(CFLAGS) -o $@ $<
|
$(CXX) -c $(CXXFLAGS) -o $@ $<
|
||||||
|
|
||||||
test_bitcoin: obj/test/test_bitcoin.o
|
test_bitcoin: obj/test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
|
||||||
$(CXX) $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) -lboost_unit_test_framework
|
$(CXX) $(CXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-Bstatic -lboost_unit_test_framework $(LIBS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -f bitcoin bitcoind test_bitcoin
|
-rm -f bitcoin bitcoind test_bitcoin
|
||||||
|
|
|
@ -98,7 +98,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout
|
||||||
SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if (hSocket == INVALID_SOCKET)
|
if (hSocket == INVALID_SOCKET)
|
||||||
return false;
|
return false;
|
||||||
#ifdef BSD
|
#ifdef SO_NOSIGPIPE
|
||||||
int set = 1;
|
int set = 1;
|
||||||
setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));
|
setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));
|
||||||
#endif
|
#endif
|
||||||
|
@ -1143,6 +1143,11 @@ void MapPort(bool fMapPort)
|
||||||
printf("Error: ThreadMapPort(ThreadMapPort) failed\n");
|
printf("Error: ThreadMapPort(ThreadMapPort) failed\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
void MapPort(bool /* unused fMapPort */)
|
||||||
|
{
|
||||||
|
// Intentionally left blank.
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -1579,7 +1584,7 @@ bool BindListenPort(string& strError)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BSD
|
#ifdef SO_NOSIGPIPE
|
||||||
// Different way of disabling SIGPIPE on BSD
|
// Different way of disabling SIGPIPE on BSD
|
||||||
setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int));
|
setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int));
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -67,7 +67,7 @@ bool StopNode();
|
||||||
// (4) size
|
// (4) size
|
||||||
// (4) checksum
|
// (4) checksum
|
||||||
|
|
||||||
extern char pchMessageStart[4];
|
extern unsigned char pchMessageStart[4];
|
||||||
|
|
||||||
class CMessageHeader
|
class CMessageHeader
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
class CTransaction;
|
class CTransaction;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -689,6 +691,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, int nHashType);
|
||||||
|
|
||||||
bool IsStandard(const CScript& scriptPubKey);
|
bool IsStandard(const CScript& scriptPubKey);
|
||||||
bool IsMine(const CKeyStore& keystore, const CScript& scriptPubKey);
|
bool IsMine(const CKeyStore& keystore, const CScript& scriptPubKey);
|
||||||
|
|
|
@ -35,6 +35,7 @@ typedef unsigned long long uint64;
|
||||||
// Note that VirtualLock does not provide this as a guarantee on Windows,
|
// Note that VirtualLock does not provide this as a guarantee on Windows,
|
||||||
// but, in practice, memory that has been VirtualLock'd almost never gets written to
|
// but, in practice, memory that has been VirtualLock'd almost never gets written to
|
||||||
// the pagefile except in rare circumstances where memory is extremely low.
|
// the pagefile except in rare circumstances where memory is extremely low.
|
||||||
|
#include <windows.h>
|
||||||
#define mlock(p, n) VirtualLock((p), (n));
|
#define mlock(p, n) VirtualLock((p), (n));
|
||||||
#define munlock(p, n) VirtualUnlock((p), (n));
|
#define munlock(p, n) VirtualUnlock((p), (n));
|
||||||
#else
|
#else
|
||||||
|
|
37
src/test/script_tests.cpp
Normal file
37
src/test/script_tests.cpp
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#include <vector>
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
|
#include "../main.h"
|
||||||
|
#include "../wallet.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE(script_tests)
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(script_PushData)
|
||||||
|
{
|
||||||
|
// Check that PUSHDATA1, PUSHDATA2, and PUSHDATA4 create the same value on
|
||||||
|
// the stack as the 1-75 opcodes do.
|
||||||
|
static const unsigned char direct[] = { 1, 0x5a };
|
||||||
|
static const unsigned char pushdata1[] = { OP_PUSHDATA1, 1, 0x5a };
|
||||||
|
static const unsigned char pushdata2[] = { OP_PUSHDATA2, 1, 0, 0x5a };
|
||||||
|
static const unsigned char pushdata4[] = { OP_PUSHDATA4, 1, 0, 0, 0, 0x5a };
|
||||||
|
|
||||||
|
vector<vector<unsigned char> > directStack;
|
||||||
|
BOOST_CHECK(EvalScript(directStack, CScript(&direct[0], &direct[sizeof(direct)]), CTransaction(), 0, 0));
|
||||||
|
|
||||||
|
vector<vector<unsigned char> > pushdata1Stack;
|
||||||
|
BOOST_CHECK(EvalScript(pushdata1Stack, CScript(&pushdata1[0], &pushdata1[sizeof(pushdata1)]), CTransaction(), 0, 0));
|
||||||
|
BOOST_CHECK(pushdata1Stack == directStack);
|
||||||
|
|
||||||
|
vector<vector<unsigned char> > pushdata2Stack;
|
||||||
|
BOOST_CHECK(EvalScript(pushdata2Stack, CScript(&pushdata2[0], &pushdata2[sizeof(pushdata2)]), CTransaction(), 0, 0));
|
||||||
|
BOOST_CHECK(pushdata2Stack == directStack);
|
||||||
|
|
||||||
|
vector<vector<unsigned char> > pushdata4Stack;
|
||||||
|
BOOST_CHECK(EvalScript(pushdata4Stack, CScript(&pushdata4[0], &pushdata4[sizeof(pushdata4)]), CTransaction(), 0, 0));
|
||||||
|
BOOST_CHECK(pushdata4Stack == directStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
|
@ -1,6 +1,18 @@
|
||||||
#define BOOST_TEST_MODULE uint160
|
#define BOOST_TEST_MODULE Bitcoin Test Suite
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
#include "../main.h"
|
||||||
|
#include "../wallet.h"
|
||||||
|
|
||||||
#include "uint160_tests.cpp"
|
#include "uint160_tests.cpp"
|
||||||
#include "uint256_tests.cpp"
|
#include "uint256_tests.cpp"
|
||||||
|
#include "script_tests.cpp"
|
||||||
|
#include "transaction_tests.cpp"
|
||||||
|
|
||||||
|
|
||||||
|
CWallet* pwalletMain;
|
||||||
|
|
||||||
|
void Shutdown(void* parg)
|
||||||
|
{
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
25
src/test/transaction_tests.cpp
Normal file
25
src/test/transaction_tests.cpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
#include "../main.h"
|
||||||
|
#include "../wallet.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE(transaction_tests)
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(basic_transaction_tests)
|
||||||
|
{
|
||||||
|
// Random real transaction (e2769b09e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436)
|
||||||
|
unsigned char ch[] = {0x01, 0x00, 0x00, 0x00, 0x01, 0x6b, 0xff, 0x7f, 0xcd, 0x4f, 0x85, 0x65, 0xef, 0x40, 0x6d, 0xd5, 0xd6, 0x3d, 0x4f, 0xf9, 0x4f, 0x31, 0x8f, 0xe8, 0x20, 0x27, 0xfd, 0x4d, 0xc4, 0x51, 0xb0, 0x44, 0x74, 0x01, 0x9f, 0x74, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x49, 0x30, 0x46, 0x02, 0x21, 0x00, 0xda, 0x0d, 0xc6, 0xae, 0xce, 0xfe, 0x1e, 0x06, 0xef, 0xdf, 0x05, 0x77, 0x37, 0x57, 0xde, 0xb1, 0x68, 0x82, 0x09, 0x30, 0xe3, 0xb0, 0xd0, 0x3f, 0x46, 0xf5, 0xfc, 0xf1, 0x50, 0xbf, 0x99, 0x0c, 0x02, 0x21, 0x00, 0xd2, 0x5b, 0x5c, 0x87, 0x04, 0x00, 0x76, 0xe4, 0xf2, 0x53, 0xf8, 0x26, 0x2e, 0x76, 0x3e, 0x2d, 0xd5, 0x1e, 0x7f, 0xf0, 0xbe, 0x15, 0x77, 0x27, 0xc4, 0xbc, 0x42, 0x80, 0x7f, 0x17, 0xbd, 0x39, 0x01, 0x41, 0x04, 0xe6, 0xc2, 0x6e, 0xf6, 0x7d, 0xc6, 0x10, 0xd2, 0xcd, 0x19, 0x24, 0x84, 0x78, 0x9a, 0x6c, 0xf9, 0xae, 0xa9, 0x93, 0x0b, 0x94, 0x4b, 0x7e, 0x2d, 0xb5, 0x34, 0x2b, 0x9d, 0x9e, 0x5b, 0x9f, 0xf7, 0x9a, 0xff, 0x9a, 0x2e, 0xe1, 0x97, 0x8d, 0xd7, 0xfd, 0x01, 0xdf, 0xc5, 0x22, 0xee, 0x02, 0x28, 0x3d, 0x3b, 0x06, 0xa9, 0xd0, 0x3a, 0xcf, 0x80, 0x96, 0x96, 0x8d, 0x7d, 0xbb, 0x0f, 0x91, 0x78, 0xff, 0xff, 0xff, 0xff, 0x02, 0x8b, 0xa7, 0x94, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xba, 0xde, 0xec, 0xfd, 0xef, 0x05, 0x07, 0x24, 0x7f, 0xc8, 0xf7, 0x42, 0x41, 0xd7, 0x3b, 0xc0, 0x39, 0x97, 0x2d, 0x7b, 0x88, 0xac, 0x40, 0x94, 0xa8, 0x02, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xc1, 0x09, 0x32, 0x48, 0x3f, 0xec, 0x93, 0xed, 0x51, 0xf5, 0xfe, 0x95, 0xe7, 0x25, 0x59, 0xf2, 0xcc, 0x70, 0x43, 0xf9, 0x88, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||||
|
vector<unsigned char> vch(ch, ch + sizeof(ch) -1);
|
||||||
|
CDataStream stream(vch);
|
||||||
|
CTransaction tx;
|
||||||
|
stream >> tx;
|
||||||
|
BOOST_CHECK_MESSAGE(tx.CheckTransaction(), "Simple deserialized transaction should be valid.");
|
||||||
|
|
||||||
|
// Check that duplicate txins fail
|
||||||
|
tx.vin.push_back(tx.vin[0]);
|
||||||
|
BOOST_CHECK_MESSAGE(!tx.CheckTransaction(), "Transaction with duplicate txins should be invalid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
|
@ -1,8 +1,10 @@
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include "../uint256.h"
|
#include "../uint256.h"
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE(uint160_tests)
|
BOOST_AUTO_TEST_SUITE(uint160_tests)
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(equality)
|
BOOST_AUTO_TEST_CASE(uint160_equality)
|
||||||
{
|
{
|
||||||
uint160 num1 = 10;
|
uint160 num1 = 10;
|
||||||
uint160 num2 = 11;
|
uint160 num2 = 11;
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include "../uint256.h"
|
#include "../uint256.h"
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE(uint256_tests)
|
BOOST_AUTO_TEST_SUITE(uint256_tests)
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(equality)
|
BOOST_AUTO_TEST_CASE(uint256_equality)
|
||||||
{
|
{
|
||||||
uint256 num1 = 10;
|
uint256 num1 = 10;
|
||||||
uint256 num2 = 11;
|
uint256 num2 = 11;
|
||||||
|
|
Loading…
Reference in a new issue