9 changed files with 233 additions and 3 deletions
@ -0,0 +1,13 @@ |
|||
cmake_policy(SET CMP0015 NEW) |
|||
|
|||
aux_source_directory(. SRC_LIST) |
|||
include_directories(../../secp256k1/include) |
|||
include_directories(../libethereum) |
|||
link_directories(../libethereum) |
|||
link_directories(../../secp256k1) |
|||
|
|||
add_executable(eth ${SRC_LIST}) |
|||
|
|||
target_link_libraries(eth secp256k1) |
|||
target_link_libraries(eth ethereum) |
|||
target_link_libraries(eth gmp) |
@ -0,0 +1,76 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
Foobar is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file main.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
* Ethereum client. |
|||
*/ |
|||
|
|||
#include "PeerNetwork.h" |
|||
#include "BlockChain.h" |
|||
#include "State.h" |
|||
using namespace std; |
|||
using namespace eth; |
|||
|
|||
int main() |
|||
{ |
|||
// Our address.
|
|||
Address us; // TODO: should be loaded from config file/set at command-line.
|
|||
|
|||
BlockChain bc; // TODO: Implement - should look for block database.
|
|||
|
|||
State s(us); |
|||
// s.restore(); // TODO: Implement - key optimisation.
|
|||
|
|||
TransactionQueue tq; // TODO: Implement.
|
|||
|
|||
// Synchronise the state according to the block chain - i.e. replay all transactions, in order. Will take a while if the state isn't restored.
|
|||
s.sync(bc, tq); |
|||
|
|||
PeerNetwork net; // TODO: Implement - should run in background and send us events when blocks found and allow us to send blocks as required.
|
|||
while (true) |
|||
{ |
|||
// Process network events.
|
|||
net.process(); |
|||
|
|||
// Synchronise block chain with network.
|
|||
net.sync(bc, tq); |
|||
|
|||
// Synchronise state to block chain.
|
|||
// This should remove any transactions on our queue that are included in the block chain.
|
|||
s.sync(bc, tq); // Resynchronise state with block chain & trans
|
|||
|
|||
if (s.mine(100)) |
|||
{ |
|||
// Mined block
|
|||
bytes b = s.blockData(); |
|||
bc.import(b); |
|||
} |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
/*
|
|||
while (net.incomingTransaction()) |
|||
{ |
|||
bytes const& tx = net.incomingTransaction(); |
|||
s.execute(tx); |
|||
net.popIncomingTransaction(); |
|||
} |
|||
|
|||
*/ |
@ -0,0 +1,14 @@ |
|||
#include "Common.h" |
|||
#include "BlockChain.h" |
|||
using namespace std; |
|||
using namespace eth; |
|||
|
|||
BlockChain::BlockChain() |
|||
{ |
|||
} |
|||
|
|||
BlockChain::~BlockChain() |
|||
{ |
|||
} |
|||
|
|||
|
@ -0,0 +1,24 @@ |
|||
#pragma once |
|||
|
|||
#include "Common.h" |
|||
|
|||
namespace eth |
|||
{ |
|||
|
|||
/**
|
|||
* @brief Models the blockchain database. |
|||
*/ |
|||
class BlockChain |
|||
{ |
|||
public: |
|||
BlockChain(); |
|||
~BlockChain(); |
|||
|
|||
void import(bytes const& _block) {} |
|||
|
|||
private: |
|||
}; |
|||
|
|||
} |
|||
|
|||
|
@ -0,0 +1,31 @@ |
|||
#include "Common.h" |
|||
#include "PeerNetwork.h" |
|||
using namespace std; |
|||
using namespace eth; |
|||
|
|||
PeerNetwork::PeerNetwork() |
|||
{ |
|||
} |
|||
|
|||
PeerNetwork::~PeerNetwork() |
|||
{ |
|||
} |
|||
|
|||
void PeerNetwork::process() |
|||
{ |
|||
} |
|||
|
|||
void PeerNetwork::sync(BlockChain& _bc, TransactionQueue const&) |
|||
{ |
|||
/* while (incomingBlock())
|
|||
{ |
|||
// import new block
|
|||
bytes const& block = net.incomingBlock(); |
|||
bc.import(block); |
|||
net.popIncomingBlock(); |
|||
|
|||
// check block chain and make longest given all available blocks.
|
|||
bc.rejig(); |
|||
}*/ |
|||
} |
|||
|
@ -0,0 +1,37 @@ |
|||
#pragma once |
|||
|
|||
#include "Common.h" |
|||
|
|||
namespace eth |
|||
{ |
|||
|
|||
class BlockChain; |
|||
class TransactionQueue; |
|||
|
|||
static const bytes NullBytes; |
|||
|
|||
class PeerNetwork |
|||
{ |
|||
public: |
|||
PeerNetwork(); |
|||
~PeerNetwork(); |
|||
|
|||
/// Conduct I/O, polling, syncing, whatever.
|
|||
/// Ideally all time-consuming I/O is done in a background thread, but you get this call every 100ms or so anyway.
|
|||
void process(); |
|||
|
|||
/// Sync with the BlockChain. It might contain one of our mined blocks, we might have new candidates from the network.
|
|||
void sync(BlockChain& _bc, TransactionQueue const&); |
|||
|
|||
/// Get an incoming transaction from the queue. @returns bytes() if nothing waiting.
|
|||
bytes const& incomingTransaction() { return NullBytes; } |
|||
|
|||
/// Remove incoming transaction from the queue. Make sure you've finished with the data from any previous incomingTransaction() calls.
|
|||
void popIncomingTransaction() {} |
|||
|
|||
private: |
|||
}; |
|||
|
|||
} |
|||
|
|||
|
Loading…
Reference in new issue