Skip to content

Commit

Permalink
Added examples:
Browse files Browse the repository at this point in the history
* btcsimple: the 24 line bitcoin server - closes bitcoin#12
* ponzicoin: An example of an alternative chain, this one is a fast forward of bitcoin to easily study long term effects. - closes bitcoin#11

Build example using ccmake - first configure ('c') then scroll down to enable examples, then configure again and then generate and exit. Default is to build without examples.
  • Loading branch information
Michael Gronager authored and Michael Gronager committed Jan 25, 2012
1 parent e8d5d85 commit 5bc9ac0
Show file tree
Hide file tree
Showing 5 changed files with 437 additions and 0 deletions.
35 changes: 35 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#######################################################
# this are setting used in SETUP_EXAMPLE macro
#######################################################
SET(TARGET_DEFAULT_PREFIX "example_")
SET(TARGET_DEFAULT_LABEL_PREFIX "Examples")

SET(TARGET_COMMON_LIBRARIES
btc
btcHTTP
btcNode
)

IF(ANDROID)
# ADD_SUBDIRECTORY(btcandroidsimple)
ELSE(ANDROID)

IF(DYNAMIC_BITCOIN)
ADD_SUBDIRECTORY(btcsimple)
ADD_SUBDIRECTORY(ponzicoin)
# ADD_SUBDIRECTORY(btcexplorer)
# ADD_SUBDIRECTORY(btconline)

IF (wxWidgets_FOUND)
# ADD_SUBDIRECTORY(bitsimpleWX)
ENDIF(wxWidgets_FOUND)


ELSE(DYNAMIC_BITCOIN)
#needed on win32 or the linker get confused by _declspec declarations
ADD_DEFINITIONS(-DBTC_LIBRARY_STATIC)

ENDIF(DYNAMIC_BITCOIN)

ENDIF(ANDROID)

5 changes: 5 additions & 0 deletions examples/btcsimple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SET(TARGET_SRC btcsimple.cpp)

SET(TARGET_ADDED_LIBRARIES btcWallet)

SETUP_EXAMPLE(btcsimple)
46 changes: 46 additions & 0 deletions examples/btcsimple/btcsimple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

#include "btcNode/Node.h"
#include "btcNode/NodeRPC.h"

#include "btcHTTP/Server.h"

#include "btcWallet/wallet.h"
#include "btcWallet/walletrpc.h"

#include <boost/thread.hpp>

using namespace std;
using namespace boost;

int main(int argc, char* argv[])
{
logfile = CDB::dataDir(bitcoin.dataDirSuffix()) + "/debug.log";

Node node; // deafult chain is bitcoin

Wallet wallet(node); // add the wallet

thread nodeThread(&Node::run, &node); // run this as a background thread

Server server;

// Register Server methods.
server.registerMethod(method_ptr(new Stop(server)));

// Register Node methods.
server.registerMethod(method_ptr(new GetBlockCount(node)));
server.registerMethod(method_ptr(new GetConnectionCount(node)));
server.registerMethod(method_ptr(new GetDifficulty(node)));
server.registerMethod(method_ptr(new GetInfo(node)));

// Register Wallet methods. - note that we don't have any auth, so anyone (on localhost) can read your balance!
server.registerMethod(method_ptr(new GetBalance(wallet)));
server.registerMethod(method_ptr(new SendToAddress(wallet)), Auth("username","password"));

server.run();

node.shutdown();
nodeThread.join();

return 0;
}
5 changes: 5 additions & 0 deletions examples/ponzicoin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SET(TARGET_SRC ponzicoin.cpp)

SET(TARGET_ADDED_LIBRARIES btcWallet btcMine)

SETUP_EXAMPLE(ponzicoin)

0 comments on commit 5bc9ac0

Please sign in to comment.