Browse Source

PoC-4 - first effort.

cl-refactor
Gav Wood 11 years ago
parent
commit
8824305b61
  1. 14
      alethzero/MainWin.cpp
  2. 3
      alethzero/MainWin.h
  3. 13
      libethereum/Client.cpp
  4. 2
      libethereum/Common.h
  5. 3
      libethereum/PeerServer.cpp
  6. 2
      libethereum/PeerServer.h
  7. 3
      libethereum/RLP.h
  8. 3
      libethereum/Transaction.cpp

14
alethzero/MainWin.cpp

@ -52,7 +52,6 @@ static void initUnits(QComboBox* _b)
{
for (auto n = (::uint)units().size(); n-- != 0; )
_b->addItem(QString::fromStdString(units()[n].second), n);
_b->setCurrentIndex(6);
}
Main::Main(QWidget *parent) :
@ -96,8 +95,11 @@ Main::Main(QWidget *parent) :
#endif
on_verbosity_sliderMoved();
initUnits(ui->valueUnits);
initUnits(ui->gasPriceUnits);
initUnits(ui->valueUnits);
ui->valueUnits->setCurrentIndex(6);
ui->gasPriceUnits->setCurrentIndex(4);
ui->gasPrice->setValue(10);
on_destination_textChanged();
statusBar()->addPermanentWidget(ui->balance);
@ -541,17 +543,11 @@ void Main::on_data_textChanged()
bool Main::isCreation() const
{
return (ui->destination->text().isEmpty() || !ui->destination->text().toInt());
return !(ui->destination->text().isEmpty() || !ui->destination->text().toInt());
}
u256 Main::fee() const
{
cnote << gasPrice();
cnote << isCreation();
cnote << ui->gas->value();
cnote << m_data.size();
cnote << m_storage.size();
return (isCreation() ? state().createGas(m_storage.size()) : state().callGas(m_data.size(), ui->gas->value())) * gasPrice();
}

3
alethzero/MainWin.h

@ -38,7 +38,10 @@ private slots:
void on_data_textChanged();
void on_idealPeers_valueChanged();
void on_value_valueChanged() { updateFee(); }
void on_gas_valueChanged() { updateFee(); }
void on_valueUnits_currentIndexChanged() { updateFee(); }
void on_gasPriceUnits_currentIndexChanged() { updateFee(); }
void on_gasPrice_valueChanged() { updateFee(); }
void on_log_doubleClicked();
void on_blocks_currentItemChanged();
void on_contracts_doubleClicked();

13
libethereum/Client.cpp

@ -92,7 +92,16 @@ void Client::startNetwork(unsigned short _listenPort, std::string const& _seedHo
{
if (m_net.get())
return;
m_net.reset(new PeerServer(m_clientVersion, m_bc, 0, _listenPort, _mode, _publicIP, _upnp));
try
{
m_net.reset(new PeerServer(m_clientVersion, m_bc, 0, _listenPort, _mode, _publicIP, _upnp));
}
catch (std::exception const&)
{
// Probably already have the port open.
m_net.reset(new PeerServer(m_clientVersion, m_bc, 0, _mode));
}
m_net->setIdealPeerCount(_peers);
if (_seedHost.size())
connect(_seedHost, _port);
@ -135,6 +144,7 @@ void Client::transact(Secret _secret, u256 _value, u256 _gasPrice, Address _dest
{
lock_guard<recursive_mutex> l(m_lock);
Transaction t;
t.isCreation = false;
t.nonce = m_postMine.transactionsFrom(toAddress(_secret));
t.receiveAddress = _dest;
t.value = _value;
@ -151,6 +161,7 @@ void Client::transact(Secret _secret, u256 _endowment, u256 _gasPrice, u256s _st
{
lock_guard<recursive_mutex> l(m_lock);
Transaction t;
t.isCreation = true;
t.nonce = m_postMine.transactionsFrom(toAddress(_secret));
t.value = _endowment;
t.gasPrice = _gasPrice;

2
libethereum/Common.h

@ -24,7 +24,7 @@
#pragma once
// define version
#define ETH_VERSION 0.3.11
#define ETH_VERSION 0.4.0
// way to many uint to size_t warnings in 32 bit build
#ifdef _M_IX86

3
libethereum/PeerServer.cpp

@ -71,10 +71,11 @@ PeerServer::PeerServer(std::string const& _clientVersion, BlockChain const& _ch,
clog(NetNote) << "Id:" << toHex(m_key.address().ref().cropped(0, 4)) << "Mode: " << (_m == NodeMode::PeerServer ? "PeerServer" : "Full");
}
PeerServer::PeerServer(std::string const& _clientVersion, unsigned int _networkId, NodeMode _m):
PeerServer::PeerServer(std::string const& _clientVersion, BlockChain const& _ch, unsigned int _networkId, NodeMode _m):
m_clientVersion(_clientVersion),
m_mode(_m),
m_listenPort(0),
m_chain(&_ch),
m_acceptor(m_ioService, bi::tcp::endpoint(bi::tcp::v4(), 0)),
m_socket(m_ioService),
m_key(KeyPair::create()),

2
libethereum/PeerServer.h

@ -43,7 +43,7 @@ public:
/// Start server, listening for connections on the given port.
PeerServer(std::string const& _clientVersion, BlockChain const& _ch, unsigned int _networkId, unsigned short _port, NodeMode _m = NodeMode::Full, std::string const& _publicAddress = std::string(), bool _upnp = true);
/// Start server, but don't listen.
PeerServer(std::string const& _clientVersion, unsigned int _networkId, NodeMode _m = NodeMode::Full);
PeerServer(std::string const& _clientVersion, BlockChain const& _ch, unsigned int _networkId, NodeMode _m = NodeMode::Full);
~PeerServer();
static unsigned protocolVersion();

3
libethereum/RLP.h

@ -283,8 +283,9 @@ public:
RLPStream& append(RLP const& _rlp, uint _itemCount = 1) { return appendRaw(_rlp.data(), _itemCount); }
/// Appends a sequence of data to the stream as a list.
template <class _T> RLPStream& append(std::vector<_T> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; }
template <class _T> RLPStream& append(std::vector<_T> const& _s) { return appendVector(_s); }
template <class _T, size_t S> RLPStream& append(std::array<_T, S> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; }
template <class _T> RLPStream& appendVector(std::vector<_T> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; }
/// Appends a list.
RLPStream& appendList(uint _items);

3
libethereum/Transaction.cpp

@ -23,6 +23,7 @@
#include "vector_ref.h"
#include "Exceptions.h"
#include "Transaction.h"
#include "Log.h"
using namespace std;
using namespace eth;
@ -129,7 +130,7 @@ void Transaction::fillStream(RLPStream& _s, bool _sig) const
if (isCreation)
_s << storage;
else
_s << receiveAddress << gas << data;
(_s << receiveAddress << gas).appendVector(data);
if (_sig)
_s << vrs.v << vrs.r << vrs.s;
}

Loading…
Cancel
Save