Gav Wood
11 years ago
14 changed files with 576 additions and 45 deletions
@ -0,0 +1,17 @@ |
|||||
|
#include "Main.h" |
||||
|
#include "ui_Main.h" |
||||
|
|
||||
|
Main::Main(QWidget *parent) : |
||||
|
QDialog(parent), |
||||
|
ui(new Ui::Main) |
||||
|
{ |
||||
|
setWindowFlags(Qt::Window); |
||||
|
ui->setupUi(this); |
||||
|
|
||||
|
ui->transactions->setHtml("Hello world!"); |
||||
|
} |
||||
|
|
||||
|
Main::~Main() |
||||
|
{ |
||||
|
delete ui; |
||||
|
} |
@ -0,0 +1,27 @@ |
|||||
|
#ifndef MAIN_H |
||||
|
#define MAIN_H |
||||
|
|
||||
|
#include <QDialog> |
||||
|
|
||||
|
namespace Ui { |
||||
|
class Main; |
||||
|
} |
||||
|
|
||||
|
class Main : public QDialog |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
|
||||
|
public: |
||||
|
explicit Main(QWidget *parent = 0); |
||||
|
~Main(); |
||||
|
|
||||
|
private slots: |
||||
|
void on_connect_clicked(); |
||||
|
|
||||
|
private: |
||||
|
Client c; |
||||
|
|
||||
|
Ui::Main *ui; |
||||
|
}; |
||||
|
|
||||
|
#endif // MAIN_H
|
@ -0,0 +1,149 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<ui version="4.0"> |
||||
|
<class>Main</class> |
||||
|
<widget class="QDialog" name="Main"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>0</x> |
||||
|
<y>0</y> |
||||
|
<width>787</width> |
||||
|
<height>555</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
<property name="windowTitle"> |
||||
|
<string>Main</string> |
||||
|
</property> |
||||
|
<property name="sizeGripEnabled"> |
||||
|
<bool>true</bool> |
||||
|
</property> |
||||
|
<layout class="QVBoxLayout" name="verticalLayout"> |
||||
|
<item> |
||||
|
<widget class="QFrame" name="frame"> |
||||
|
<property name="frameShape"> |
||||
|
<enum>QFrame::NoFrame</enum> |
||||
|
</property> |
||||
|
<property name="frameShadow"> |
||||
|
<enum>QFrame::Raised</enum> |
||||
|
</property> |
||||
|
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||
|
<property name="margin"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
<item> |
||||
|
<widget class="QToolButton" name="connect"> |
||||
|
<property name="text"> |
||||
|
<string>Connect</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item> |
||||
|
<widget class="QSpinBox" name="value"> |
||||
|
<property name="suffix"> |
||||
|
<string> wei</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item> |
||||
|
<widget class="QSpinBox" name="fee"> |
||||
|
<property name="suffix"> |
||||
|
<string>)</string> |
||||
|
</property> |
||||
|
<property name="prefix"> |
||||
|
<string>(fee </string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item> |
||||
|
<widget class="QLineEdit" name="destination"/> |
||||
|
</item> |
||||
|
<item> |
||||
|
<widget class="QToolButton" name="send"> |
||||
|
<property name="text"> |
||||
|
<string>Send</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item> |
||||
|
<spacer name="horizontalSpacer"> |
||||
|
<property name="orientation"> |
||||
|
<enum>Qt::Horizontal</enum> |
||||
|
</property> |
||||
|
<property name="sizeHint" stdset="0"> |
||||
|
<size> |
||||
|
<width>205</width> |
||||
|
<height>20</height> |
||||
|
</size> |
||||
|
</property> |
||||
|
</spacer> |
||||
|
</item> |
||||
|
<item> |
||||
|
<widget class="QToolButton" name="mine"> |
||||
|
<property name="text"> |
||||
|
<string>Mine</string> |
||||
|
</property> |
||||
|
<property name="checkable"> |
||||
|
<bool>true</bool> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item> |
||||
|
<widget class="QWidget" name="mineProgress" native="true"/> |
||||
|
</item> |
||||
|
</layout> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item> |
||||
|
<widget class="QSplitter" name="splitter"> |
||||
|
<property name="sizePolicy"> |
||||
|
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding"> |
||||
|
<horstretch>0</horstretch> |
||||
|
<verstretch>0</verstretch> |
||||
|
</sizepolicy> |
||||
|
</property> |
||||
|
<property name="orientation"> |
||||
|
<enum>Qt::Horizontal</enum> |
||||
|
</property> |
||||
|
<widget class="QListView" name="accounts"> |
||||
|
<property name="frameShape"> |
||||
|
<enum>QFrame::NoFrame</enum> |
||||
|
</property> |
||||
|
</widget> |
||||
|
<widget class="QTextEdit" name="transactions"> |
||||
|
<property name="readOnly"> |
||||
|
<bool>true</bool> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item> |
||||
|
<widget class="QWidget" name="widget_2" native="true"> |
||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2"> |
||||
|
<property name="margin"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
<item> |
||||
|
<widget class="QLabel" name="balance"> |
||||
|
<property name="text"> |
||||
|
<string>0 wei</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item> |
||||
|
<widget class="QLineEdit" name="address"/> |
||||
|
</item> |
||||
|
<item> |
||||
|
<widget class="QLabel" name="peers"> |
||||
|
<property name="text"> |
||||
|
<string>0 peers</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
</layout> |
||||
|
</widget> |
||||
|
</item> |
||||
|
</layout> |
||||
|
</widget> |
||||
|
<layoutdefault spacing="6" margin="11"/> |
||||
|
<resources/> |
||||
|
<connections/> |
||||
|
</ui> |
@ -0,0 +1,25 @@ |
|||||
|
#------------------------------------------------- |
||||
|
# |
||||
|
# Project created by QtCreator 2014-01-22T11:47:38 |
||||
|
# |
||||
|
#------------------------------------------------- |
||||
|
|
||||
|
QT += core gui widgets |
||||
|
|
||||
|
TARGET = alephzero |
||||
|
TEMPLATE = app |
||||
|
|
||||
|
QMAKE_LIBDIR += ../../cpp-ethereum-build/libethereum ../../secp256k1 ../../cryptopp562 |
||||
|
|
||||
|
LIBS += -lethereum -lsecp256k1 -lleveldb -lcryptopp -lgmp -lboost_system -lboost_filesystem |
||||
|
|
||||
|
SOURCES += main.cpp\ |
||||
|
Main.cpp |
||||
|
|
||||
|
HEADERS += Main.h |
||||
|
|
||||
|
FORMS += Main.ui |
||||
|
|
||||
|
INCLUDEPATH = ../../secp256k1/include ../../cryptopp562 |
||||
|
|
||||
|
|
@ -0,0 +1,11 @@ |
|||||
|
#include "Main.h" |
||||
|
#include <QApplication> |
||||
|
|
||||
|
int main(int argc, char *argv[]) |
||||
|
{ |
||||
|
QApplication a(argc, argv); |
||||
|
Main w; |
||||
|
w.show(); |
||||
|
|
||||
|
return a.exec(); |
||||
|
} |
@ -0,0 +1,121 @@ |
|||||
|
/*
|
||||
|
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 Client.cpp
|
||||
|
* @author Gav Wood <i@gavwood.com> |
||||
|
* @date 2014 |
||||
|
*/ |
||||
|
|
||||
|
#include "Common.h" |
||||
|
#include "Client.h" |
||||
|
using namespace std; |
||||
|
using namespace eth; |
||||
|
|
||||
|
Client::Client(std::string const& _dbPath): |
||||
|
m_bc(_dbPath), |
||||
|
m_stateDB(State::openDB(_dbPath)), |
||||
|
m_s(m_stateDB) |
||||
|
{ |
||||
|
Defaults::setDBPath(_dbPath); |
||||
|
|
||||
|
// Synchronise the state according to the block chain - i.e. replay all transactions in block chain, in order.
|
||||
|
// In practise this won't need to be done since the State DB will contain the keys for the tries for most recent (and many old) blocks.
|
||||
|
// TODO: currently it contains keys for *all* blocks. Make it remove old ones.
|
||||
|
s.sync(bc); |
||||
|
s.sync(tq); |
||||
|
|
||||
|
m_work = new thread([&](){ while (m_workState != Deleting) work(); m_workState = Deleted; }); |
||||
|
} |
||||
|
|
||||
|
Client::~Client() |
||||
|
{ |
||||
|
if (m_workState == Active) |
||||
|
m_workState = Deleting; |
||||
|
while (m_workState != Deleted) |
||||
|
usleep(10000); |
||||
|
} |
||||
|
|
||||
|
void Client::transact(Address _dest, u256 _amount, u256 _fee, u256s _data = u256s(), Secret _secret) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
BlockChain const& Client::blockChain() const |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
TransactionQueue const& Client::transactionQueue() const |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
unsigned Client::peerCount() const |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void Client::startNetwork(short _listenPort = 30303, std::string const& _seedHost, short _port = 30303) |
||||
|
{ |
||||
|
if (m_net) |
||||
|
return; |
||||
|
m_net = new PeerServer(m_bc, 0, _listenPort); |
||||
|
if (_seedHost.size()) |
||||
|
m_net->connect(_seedHost, _port); |
||||
|
} |
||||
|
|
||||
|
void Client::stopNetwork() |
||||
|
{ |
||||
|
delete m_net; |
||||
|
m_net = nullptr; |
||||
|
} |
||||
|
|
||||
|
void Client::startMining() |
||||
|
{ |
||||
|
m_doMine = true; |
||||
|
} |
||||
|
|
||||
|
void Client::stopMining() |
||||
|
{ |
||||
|
m_doMine = false; |
||||
|
} |
||||
|
|
||||
|
std::pair<unsigned, unsigned> Client::miningProgress() const |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void Client::work(string const& _seedHost, short _port) |
||||
|
{ |
||||
|
// Process network events.
|
||||
|
// Synchronise block chain with network.
|
||||
|
// Will broadcast any of our (new) transactions and blocks, and collect & add any of their (new) transactions and blocks.
|
||||
|
m_net->process(m_bc, m_tq); |
||||
|
|
||||
|
// Synchronise state to block chain.
|
||||
|
// This should remove any transactions on our queue that are included within our state.
|
||||
|
// It also guarantees that the state reflects the longest (valid!) chain on the block chain.
|
||||
|
// This might mean reverting to an earlier state and replaying some blocks, or, (worst-case:
|
||||
|
// if there are no checkpoints before our fork) reverting to the genesis block and replaying
|
||||
|
// all blocks.
|
||||
|
m_s.sync(m_bc); // Resynchronise state with block chain & trans
|
||||
|
m_s.sync(m_tq); |
||||
|
|
||||
|
if (m_doMine) |
||||
|
{ |
||||
|
// Mine for a while.
|
||||
|
bytes b = s.mine(100); |
||||
|
|
||||
|
if (b.size()) |
||||
|
// Import block.
|
||||
|
bc.attemptImport(b, stateDB); |
||||
|
} |
||||
|
} |
@ -0,0 +1,68 @@ |
|||||
|
/*
|
||||
|
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 Client.h
|
||||
|
* @author Gav Wood <i@gavwood.com> |
||||
|
* @date 2014 |
||||
|
*/ |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <thread> |
||||
|
#include <mutex> |
||||
|
#include "Common.h" |
||||
|
#include "BlockChain.h" |
||||
|
#include "TransactionQueue.h" |
||||
|
#include "State.h" |
||||
|
#include "PeerNetwork.h" |
||||
|
|
||||
|
namespace eth |
||||
|
{ |
||||
|
|
||||
|
class Client |
||||
|
{ |
||||
|
public: |
||||
|
Client(std::string const& _dbPath); |
||||
|
~Client(); |
||||
|
|
||||
|
void transact(Address _dest, u256 _amount, u256 _fee, u256s _data = u256s(), Secret _secret); |
||||
|
|
||||
|
BlockChain const& blockChain() const; |
||||
|
TransactionQueue const& transactionQueue() const; |
||||
|
|
||||
|
unsigned peerCount() const; |
||||
|
|
||||
|
void startNetwork(short _listenPort = 30303, std::string const& _seedHost, short _port = 30303); |
||||
|
void stopNetwork(); |
||||
|
|
||||
|
void startMining(); |
||||
|
void stopMining(); |
||||
|
std::pair<unsigned, unsigned> miningProgress() const; |
||||
|
|
||||
|
private: |
||||
|
void work(); |
||||
|
|
||||
|
BlockChain m_bc; ///< Maintains block database.
|
||||
|
TransactionQueue m_tq; ///< Maintains list of incoming transactions not yet on the block chain.
|
||||
|
Overlay m_stateDB; ///< Acts as the central point for the state database, so multiple States can share it.
|
||||
|
State m_s; ///< The present state of the client.
|
||||
|
PeerServer* m_net = nullptr; ///< Should run in background and send us events when blocks found and allow us to send blocks as required.
|
||||
|
std::thread* m_work; ///< The work thread.
|
||||
|
enum { Active = 0, Deleting, Deleted } m_workState = Active; |
||||
|
bool m_doMine = false; ///< Are we supposed to be mining?
|
||||
|
}; |
||||
|
|
||||
|
} |
Loading…
Reference in new issue