Paweł Bylica
10 years ago
722 changed files with 63884 additions and 23688 deletions
@ -0,0 +1,187 @@ |
|||
/*
|
|||
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. |
|||
|
|||
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file ExportState.cpp
|
|||
* @author Arkadiy Paronyan <arkadiy@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include "ExportState.h" |
|||
#include <QFileDialog> |
|||
#include <QTextStream> |
|||
#include <libethereum/Client.h> |
|||
#include "MainWin.h" |
|||
#include "ui_ExportState.h" |
|||
|
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
|
|||
ExportStateDialog::ExportStateDialog(Main* _parent): |
|||
QDialog(_parent), |
|||
ui(new Ui::ExportState), |
|||
m_main(_parent) |
|||
{ |
|||
ui->setupUi(this); |
|||
connect(ui->close, &QPushButton::clicked, this, &ExportStateDialog::close); |
|||
connect(ui->accounts, &QListWidget::itemSelectionChanged, this, &ExportStateDialog::generateJSON); |
|||
connect(ui->contracts, &QListWidget::itemSelectionChanged, this, &ExportStateDialog::generateJSON); |
|||
fillBlocks(); |
|||
} |
|||
|
|||
ExportStateDialog::~ExportStateDialog() |
|||
{ |
|||
} |
|||
|
|||
dev::eth::Client* ExportStateDialog::ethereum() const |
|||
{ |
|||
return m_main->ethereum(); |
|||
} |
|||
|
|||
void ExportStateDialog::on_block_editTextChanged() |
|||
{ |
|||
QString text = ui->block->currentText(); |
|||
int i = ui->block->count(); |
|||
while (i-- >= 0) |
|||
if (ui->block->itemText(i) == text) |
|||
return; |
|||
fillBlocks(); |
|||
} |
|||
|
|||
void ExportStateDialog::on_block_currentIndexChanged(int _index) |
|||
{ |
|||
m_block = ui->block->itemData(_index).toUInt(); |
|||
fillContracts(); |
|||
} |
|||
|
|||
void ExportStateDialog::fillBlocks() |
|||
{ |
|||
BlockChain const& bc = ethereum()->blockChain(); |
|||
QStringList filters = ui->block->currentText().toLower().split(QRegExp("\\s+"), QString::SkipEmptyParts); |
|||
const unsigned numLastBlocks = 10; |
|||
if (ui->block->count() == 0) |
|||
{ |
|||
unsigned i = numLastBlocks; |
|||
for (auto h = bc.currentHash(); bc.details(h) && i; h = bc.details(h).parent, --i) |
|||
{ |
|||
auto d = bc.details(h); |
|||
ui->block->addItem(QString("#%1 %2").arg(d.number).arg(h.abridged().c_str()), d.number); |
|||
if (h == bc.genesisHash()) |
|||
break; |
|||
} |
|||
if (ui->block->currentIndex() < 0) |
|||
ui->block->setCurrentIndex(0); |
|||
m_recentBlocks = numLastBlocks - i; |
|||
} |
|||
|
|||
int i = ui->block->count(); |
|||
while (i > 0 && i >= m_recentBlocks) |
|||
ui->block->removeItem(i--); |
|||
|
|||
h256Hash blocks; |
|||
for (QString f: filters) |
|||
{ |
|||
if (f.startsWith("#")) |
|||
f = f.remove(0, 1); |
|||
if (f.size() == 64) |
|||
{ |
|||
h256 h(f.toStdString()); |
|||
if (bc.isKnown(h)) |
|||
blocks.insert(h); |
|||
for (auto const& b: bc.withBlockBloom(LogBloom().shiftBloom<3>(sha3(h)), 0, -1)) |
|||
blocks.insert(bc.numberHash(b)); |
|||
} |
|||
else if (f.toLongLong() <= bc.number()) |
|||
blocks.insert(bc.numberHash((unsigned)f.toLongLong())); |
|||
else if (f.size() == 40) |
|||
{ |
|||
Address h(f.toStdString()); |
|||
for (auto const& b: bc.withBlockBloom(LogBloom().shiftBloom<3>(sha3(h)), 0, -1)) |
|||
blocks.insert(bc.numberHash(b)); |
|||
} |
|||
} |
|||
|
|||
for (auto const& h: blocks) |
|||
{ |
|||
auto d = bc.details(h); |
|||
ui->block->addItem(QString("#%1 %2").arg(d.number).arg(h.abridged().c_str()), d.number); |
|||
} |
|||
} |
|||
|
|||
void ExportStateDialog::fillContracts() |
|||
{ |
|||
ui->accounts->clear(); |
|||
ui->contracts->clear(); |
|||
ui->accounts->setEnabled(true); |
|||
ui->contracts->setEnabled(true); |
|||
for (auto i: ethereum()->addresses(m_block)) |
|||
{ |
|||
string r = m_main->render(i); |
|||
(new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(ethereum()->balanceAt(i)).c_str()).arg(QString::fromStdString(r)).arg((unsigned)ethereum()->countAt(i)), ethereum()->codeAt(i).empty() ? ui->accounts : ui->contracts)) |
|||
->setData(Qt::UserRole, QByteArray((char const*)i.data(), Address::size)); |
|||
} |
|||
} |
|||
|
|||
void ExportStateDialog::generateJSON() |
|||
{ |
|||
std::stringstream json; |
|||
json << "{\n"; |
|||
std::string prefix; |
|||
for(QListWidgetItem* item: ui->accounts->selectedItems()) |
|||
{ |
|||
auto hba = item->data(Qt::UserRole).toByteArray(); |
|||
auto address = Address((byte const*)hba.data(), Address::ConstructFromPointer); |
|||
json << prefix << "\t\"" << toHex(address.ref()) << "\": { \"wei\": \"" << ethereum()->balanceAt(address, m_block) << "\" }"; |
|||
prefix = ",\n"; |
|||
} |
|||
for(QListWidgetItem* item: ui->contracts->selectedItems()) |
|||
{ |
|||
auto hba = item->data(Qt::UserRole).toByteArray(); |
|||
auto address = Address((byte const*)hba.data(), Address::ConstructFromPointer); |
|||
json << prefix << "\t\"" << toHex(address.ref()) << "\":\n\t{\n\t\t\"wei\": \"" << ethereum()->balanceAt(address, m_block) << "\",\n"; |
|||
json << "\t\t\"code\": \"" << toHex(ethereum()->codeAt(address, m_block)) << "\",\n"; |
|||
std::unordered_map<u256, u256> storage = ethereum()->storageAt(address, m_block); |
|||
if (!storage.empty()) |
|||
{ |
|||
json << "\t\t\"storage\":\n\t\t{\n"; |
|||
std::string storagePrefix; |
|||
for (auto s: storage) |
|||
{ |
|||
json << storagePrefix << "\t\t\t\"" << toHex(s.first) << "\": \"" << toHex(s.second) << "\""; |
|||
storagePrefix = ",\n"; |
|||
} |
|||
json << "\n\t\t}\n"; |
|||
} |
|||
json << "\t}"; |
|||
prefix = ",\n"; |
|||
} |
|||
json << "\n}"; |
|||
json.flush(); |
|||
|
|||
ui->json->setEnabled(true); |
|||
ui->json->setText(QString::fromStdString(json.str())); |
|||
ui->saveButton->setEnabled(true); |
|||
} |
|||
|
|||
void ExportStateDialog::on_saveButton_clicked() |
|||
{ |
|||
QString fn = QFileDialog::getSaveFileName(this, "Save state", QString(), "JSON Files (*.json)"); |
|||
if (!fn.endsWith(".json")) |
|||
fn = fn.append(".json"); |
|||
ofstream file(fn.toStdString()); |
|||
if (file.is_open()) |
|||
file << ui->json->toPlainText().toStdString(); |
|||
} |
@ -0,0 +1,57 @@ |
|||
/*
|
|||
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. |
|||
|
|||
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file ExportState.h
|
|||
* @author Arkadiy Paronyan <arkadiy@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <memory> |
|||
#include <QDialog> |
|||
#include <libethcore/Common.h> |
|||
|
|||
namespace Ui { class ExportState; } |
|||
namespace dev { namespace eth { class Client; } } |
|||
|
|||
class Main; |
|||
|
|||
class ExportStateDialog: public QDialog |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
explicit ExportStateDialog(Main* _parent = 0); |
|||
virtual ~ExportStateDialog(); |
|||
|
|||
private slots: |
|||
void on_block_editTextChanged(); |
|||
void on_block_currentIndexChanged(int _index); |
|||
void on_saveButton_clicked(); |
|||
|
|||
private: |
|||
dev::eth::Client* ethereum() const; |
|||
void fillBlocks(); |
|||
void fillContracts(); |
|||
void generateJSON(); |
|||
|
|||
private: |
|||
std::unique_ptr<Ui::ExportState> ui; |
|||
Main* m_main; |
|||
int m_recentBlocks = 0; |
|||
dev::eth::BlockNumber m_block = dev::eth::LatestBlock; |
|||
}; |
@ -0,0 +1,183 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<ui version="4.0"> |
|||
<class>ExportState</class> |
|||
<widget class="QDialog" name="ExportState"> |
|||
<property name="geometry"> |
|||
<rect> |
|||
<x>0</x> |
|||
<y>0</y> |
|||
<width>490</width> |
|||
<height>522</height> |
|||
</rect> |
|||
</property> |
|||
<property name="windowTitle"> |
|||
<string>Export State</string> |
|||
</property> |
|||
<property name="modal"> |
|||
<bool>true</bool> |
|||
</property> |
|||
<layout class="QGridLayout" name="gridLayout"> |
|||
<item row="0" column="0"> |
|||
<widget class="QLabel" name="label5"> |
|||
<property name="sizePolicy"> |
|||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> |
|||
<horstretch>0</horstretch> |
|||
<verstretch>0</verstretch> |
|||
</sizepolicy> |
|||
</property> |
|||
<property name="text"> |
|||
<string>&Block</string> |
|||
</property> |
|||
<property name="buddy"> |
|||
<cstring>block</cstring> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="0" column="1"> |
|||
<widget class="QComboBox" name="block"> |
|||
<property name="editable"> |
|||
<bool>true</bool> |
|||
</property> |
|||
<property name="currentText"> |
|||
<string/> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="1" column="0"> |
|||
<widget class="QLabel" name="label_7"> |
|||
<property name="text"> |
|||
<string>&Accounts</string> |
|||
</property> |
|||
<property name="buddy"> |
|||
<cstring>accounts</cstring> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="1" column="1"> |
|||
<widget class="QListWidget" name="accounts"> |
|||
<property name="enabled"> |
|||
<bool>false</bool> |
|||
</property> |
|||
<property name="sizePolicy"> |
|||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> |
|||
<horstretch>0</horstretch> |
|||
<verstretch>1</verstretch> |
|||
</sizepolicy> |
|||
</property> |
|||
<property name="selectionMode"> |
|||
<enum>QAbstractItemView::MultiSelection</enum> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="2" column="0"> |
|||
<widget class="QLabel" name="label_6"> |
|||
<property name="text"> |
|||
<string>&Contracts</string> |
|||
</property> |
|||
<property name="buddy"> |
|||
<cstring>contracts</cstring> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="2" column="1"> |
|||
<widget class="QListWidget" name="contracts"> |
|||
<property name="enabled"> |
|||
<bool>false</bool> |
|||
</property> |
|||
<property name="sizePolicy"> |
|||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> |
|||
<horstretch>0</horstretch> |
|||
<verstretch>1</verstretch> |
|||
</sizepolicy> |
|||
</property> |
|||
<property name="selectionMode"> |
|||
<enum>QAbstractItemView::MultiSelection</enum> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="3" column="0"> |
|||
<widget class="QLabel" name="label_2"> |
|||
<property name="sizePolicy"> |
|||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum"> |
|||
<horstretch>0</horstretch> |
|||
<verstretch>0</verstretch> |
|||
</sizepolicy> |
|||
</property> |
|||
<property name="text"> |
|||
<string>&JSON</string> |
|||
</property> |
|||
<property name="alignment"> |
|||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> |
|||
</property> |
|||
<property name="buddy"> |
|||
<cstring>json</cstring> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="3" column="1"> |
|||
<widget class="QTextEdit" name="json"> |
|||
<property name="enabled"> |
|||
<bool>false</bool> |
|||
</property> |
|||
<property name="sizePolicy"> |
|||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> |
|||
<horstretch>0</horstretch> |
|||
<verstretch>2</verstretch> |
|||
</sizepolicy> |
|||
</property> |
|||
<property name="readOnly"> |
|||
<bool>true</bool> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="4" column="1"> |
|||
<layout class="QHBoxLayout" name="horizontalLayout"> |
|||
<item> |
|||
<widget class="QPushButton" name="saveButton"> |
|||
<property name="enabled"> |
|||
<bool>false</bool> |
|||
</property> |
|||
<property name="sizePolicy"> |
|||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> |
|||
<horstretch>0</horstretch> |
|||
<verstretch>0</verstretch> |
|||
</sizepolicy> |
|||
</property> |
|||
<property name="text"> |
|||
<string>&Save...</string> |
|||
</property> |
|||
<property name="shortcut"> |
|||
<string>Esc</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item> |
|||
<spacer name="horizontalSpacer"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Horizontal</enum> |
|||
</property> |
|||
<property name="sizeHint" stdset="0"> |
|||
<size> |
|||
<width>40</width> |
|||
<height>20</height> |
|||
</size> |
|||
</property> |
|||
</spacer> |
|||
</item> |
|||
<item> |
|||
<widget class="QPushButton" name="close"> |
|||
<property name="text"> |
|||
<string>&Close</string> |
|||
</property> |
|||
<property name="shortcut"> |
|||
<string>Esc</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
</layout> |
|||
</item> |
|||
</layout> |
|||
</widget> |
|||
<resources/> |
|||
<connections/> |
|||
</ui> |
@ -0,0 +1,181 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<ui version="4.0"> |
|||
<class>GasPricing</class> |
|||
<widget class="QDialog" name="GasPricing"> |
|||
<property name="geometry"> |
|||
<rect> |
|||
<x>0</x> |
|||
<y>0</y> |
|||
<width>416</width> |
|||
<height>286</height> |
|||
</rect> |
|||
</property> |
|||
<property name="windowTitle"> |
|||
<string>Gas Pricing</string> |
|||
</property> |
|||
<layout class="QGridLayout" name="gridLayout"> |
|||
<item row="3" column="0" colspan="2"> |
|||
<spacer name="verticalSpacer"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Vertical</enum> |
|||
</property> |
|||
<property name="sizeHint" stdset="0"> |
|||
<size> |
|||
<width>398</width> |
|||
<height>45</height> |
|||
</size> |
|||
</property> |
|||
</spacer> |
|||
</item> |
|||
<item row="4" column="0" colspan="2"> |
|||
<widget class="QLabel" name="label5_3"> |
|||
<property name="text"> |
|||
<string>&Bid: The minimum grice of gas that is accepting into a block which we mine.</string> |
|||
</property> |
|||
<property name="alignment"> |
|||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> |
|||
</property> |
|||
<property name="wordWrap"> |
|||
<bool>true</bool> |
|||
</property> |
|||
<property name="buddy"> |
|||
<cstring>bidValue</cstring> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="1" column="0"> |
|||
<widget class="QSpinBox" name="askValue"> |
|||
<property name="suffix"> |
|||
<string/> |
|||
</property> |
|||
<property name="maximum"> |
|||
<number>430000000</number> |
|||
</property> |
|||
<property name="value"> |
|||
<number>0</number> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="10" column="0" colspan="2"> |
|||
<layout class="QHBoxLayout" name="horizontalLayout"> |
|||
<item> |
|||
<spacer name="horizontalSpacer"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Horizontal</enum> |
|||
</property> |
|||
<property name="sizeHint" stdset="0"> |
|||
<size> |
|||
<width>40</width> |
|||
<height>20</height> |
|||
</size> |
|||
</property> |
|||
</spacer> |
|||
</item> |
|||
<item> |
|||
<widget class="QPushButton" name="close"> |
|||
<property name="text"> |
|||
<string>Close</string> |
|||
</property> |
|||
<property name="default"> |
|||
<bool>true</bool> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
</layout> |
|||
</item> |
|||
<item row="0" column="0" colspan="2"> |
|||
<widget class="QLabel" name="label5_2"> |
|||
<property name="text"> |
|||
<string>&Ask: The minimum grice of gas that is accepting into a block which we mine.</string> |
|||
</property> |
|||
<property name="alignment"> |
|||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> |
|||
</property> |
|||
<property name="wordWrap"> |
|||
<bool>true</bool> |
|||
</property> |
|||
<property name="buddy"> |
|||
<cstring>askValue</cstring> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="1" column="1"> |
|||
<widget class="QComboBox" name="askUnits"/> |
|||
</item> |
|||
<item row="5" column="0"> |
|||
<widget class="QSpinBox" name="bidValue"> |
|||
<property name="suffix"> |
|||
<string/> |
|||
</property> |
|||
<property name="maximum"> |
|||
<number>430000000</number> |
|||
</property> |
|||
<property name="value"> |
|||
<number>0</number> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="5" column="1"> |
|||
<widget class="QComboBox" name="bidUnits"/> |
|||
</item> |
|||
<item row="7" column="0" colspan="2"> |
|||
<spacer name="verticalSpacer_2"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Vertical</enum> |
|||
</property> |
|||
<property name="sizeHint" stdset="0"> |
|||
<size> |
|||
<width>20</width> |
|||
<height>40</height> |
|||
</size> |
|||
</property> |
|||
</spacer> |
|||
</item> |
|||
<item row="9" column="0" colspan="2"> |
|||
<spacer name="verticalSpacer_3"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Vertical</enum> |
|||
</property> |
|||
<property name="sizeHint" stdset="0"> |
|||
<size> |
|||
<width>20</width> |
|||
<height>40</height> |
|||
</size> |
|||
</property> |
|||
</spacer> |
|||
</item> |
|||
<item row="8" column="0" colspan="2"> |
|||
<spacer name="verticalSpacer_4"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Vertical</enum> |
|||
</property> |
|||
<property name="sizeHint" stdset="0"> |
|||
<size> |
|||
<width>20</width> |
|||
<height>40</height> |
|||
</size> |
|||
</property> |
|||
</spacer> |
|||
</item> |
|||
</layout> |
|||
</widget> |
|||
<resources/> |
|||
<connections> |
|||
<connection> |
|||
<sender>close</sender> |
|||
<signal>clicked()</signal> |
|||
<receiver>GasPricing</receiver> |
|||
<slot>accept()</slot> |
|||
<hints> |
|||
<hint type="sourcelabel"> |
|||
<x>387</x> |
|||
<y>264</y> |
|||
</hint> |
|||
<hint type="destinationlabel"> |
|||
<x>240</x> |
|||
<y>262</y> |
|||
</hint> |
|||
</hints> |
|||
</connection> |
|||
</connections> |
|||
</ui> |
@ -0,0 +1,123 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<ui version="4.0"> |
|||
<class>GetPassword</class> |
|||
<widget class="QDialog" name="GetPassword"> |
|||
<property name="geometry"> |
|||
<rect> |
|||
<x>0</x> |
|||
<y>0</y> |
|||
<width>400</width> |
|||
<height>187</height> |
|||
</rect> |
|||
</property> |
|||
<property name="windowTitle"> |
|||
<string>Enter Password</string> |
|||
</property> |
|||
<layout class="QVBoxLayout" name="verticalLayout"> |
|||
<item> |
|||
<spacer name="verticalSpacer_3"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Vertical</enum> |
|||
</property> |
|||
<property name="sizeHint" stdset="0"> |
|||
<size> |
|||
<width>20</width> |
|||
<height>40</height> |
|||
</size> |
|||
</property> |
|||
</spacer> |
|||
</item> |
|||
<item> |
|||
<widget class="QLabel" name="label"> |
|||
<property name="text"> |
|||
<string/> |
|||
</property> |
|||
<property name="textFormat"> |
|||
<enum>Qt::RichText</enum> |
|||
</property> |
|||
<property name="wordWrap"> |
|||
<bool>true</bool> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item> |
|||
<spacer name="verticalSpacer_2"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Vertical</enum> |
|||
</property> |
|||
<property name="sizeHint" stdset="0"> |
|||
<size> |
|||
<width>20</width> |
|||
<height>40</height> |
|||
</size> |
|||
</property> |
|||
</spacer> |
|||
</item> |
|||
<item> |
|||
<widget class="QLineEdit" name="entry"> |
|||
<property name="echoMode"> |
|||
<enum>QLineEdit::Password</enum> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item> |
|||
<spacer name="verticalSpacer"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Vertical</enum> |
|||
</property> |
|||
<property name="sizeHint" stdset="0"> |
|||
<size> |
|||
<width>20</width> |
|||
<height>40</height> |
|||
</size> |
|||
</property> |
|||
</spacer> |
|||
</item> |
|||
<item> |
|||
<widget class="QDialogButtonBox" name="buttonBox"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Horizontal</enum> |
|||
</property> |
|||
<property name="standardButtons"> |
|||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
</layout> |
|||
</widget> |
|||
<resources/> |
|||
<connections> |
|||
<connection> |
|||
<sender>buttonBox</sender> |
|||
<signal>accepted()</signal> |
|||
<receiver>GetPassword</receiver> |
|||
<slot>accept()</slot> |
|||
<hints> |
|||
<hint type="sourcelabel"> |
|||
<x>248</x> |
|||
<y>254</y> |
|||
</hint> |
|||
<hint type="destinationlabel"> |
|||
<x>157</x> |
|||
<y>274</y> |
|||
</hint> |
|||
</hints> |
|||
</connection> |
|||
<connection> |
|||
<sender>buttonBox</sender> |
|||
<signal>rejected()</signal> |
|||
<receiver>GetPassword</receiver> |
|||
<slot>reject()</slot> |
|||
<hints> |
|||
<hint type="sourcelabel"> |
|||
<x>316</x> |
|||
<y>260</y> |
|||
</hint> |
|||
<hint type="destinationlabel"> |
|||
<x>286</x> |
|||
<y>274</y> |
|||
</hint> |
|||
</hints> |
|||
</connection> |
|||
</connections> |
|||
</ui> |
File diff suppressed because it is too large
@ -0,0 +1,13 @@ |
|||
{ |
|||
"title": "Ethereum", |
|||
"icon": "appdmg_icon.icns", |
|||
"background": "appdmg_background.png", |
|||
"icon-size": 55, |
|||
"contents": [ |
|||
{ "x": 242, "y": 240, "type": "link", "path": "/Applications" }, |
|||
{ "x": 145, "y": 125, "type": "file", "path": "${ETH_ALETHZERO_APP}" }, |
|||
{ "x": 339, "y": 125, "type": "file", "path": "${ETH_MIX_APP}" } |
|||
] |
|||
} |
|||
|
|||
|
@ -0,0 +1,322 @@ |
|||
# - Find the Windows SDK aka Platform SDK |
|||
# |
|||
# Relevant Wikipedia article: http://en.wikipedia.org/wiki/Microsoft_Windows_SDK |
|||
# |
|||
# Variables: |
|||
# WINDOWSSDK_FOUND - if any version of the windows or platform SDK was found that is usable with the current version of visual studio |
|||
# WINDOWSSDK_LATEST_DIR |
|||
# WINDOWSSDK_LATEST_NAME |
|||
# WINDOWSSDK_FOUND_PREFERENCE - if we found an entry indicating a "preferred" SDK listed for this visual studio version |
|||
# WINDOWSSDK_PREFERRED_DIR |
|||
# WINDOWSSDK_PREFERRED_NAME |
|||
# |
|||
# WINDOWSSDK_DIRS - contains no duplicates, ordered most recent first. |
|||
# WINDOWSSDK_PREFERRED_FIRST_DIRS - contains no duplicates, ordered with preferred first, followed by the rest in descending recency |
|||
# |
|||
# Functions: |
|||
# windowssdk_name_lookup(<directory> <output variable>) - Find the name corresponding with the SDK directory you pass in, or |
|||
# NOTFOUND if not recognized. Your directory must be one of WINDOWSSDK_DIRS for this to work. |
|||
# |
|||
# get_windowssdk_from_component(<file or dir> <output variable>) - Given a library or include dir, |
|||
# find the Windows SDK root dir corresponding to it, or NOTFOUND if unrecognized. |
|||
# |
|||
# get_windowssdk_library_dirs(<directory> <output variable>) - Find the architecture-appropriate |
|||
# library directories corresponding to the SDK directory you pass in (or NOTFOUND if none) |
|||
# |
|||
# get_windowssdk_include_dirs(<directory> <output variable>) - Find the |
|||
# include directories corresponding to the SDK directory you pass in (or NOTFOUND if none) |
|||
# |
|||
# Requires these CMake modules: |
|||
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) |
|||
# |
|||
# Original Author: |
|||
# 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> |
|||
# http://academic.cleardefinition.com |
|||
# Iowa State University HCI Graduate Program/VRAC |
|||
# |
|||
# Copyright Iowa State University 2012. |
|||
# Distributed under the Boost Software License, Version 1.0. |
|||
# (See accompanying file LICENSE_1_0.txt or copy at |
|||
# http://www.boost.org/LICENSE_1_0.txt) |
|||
|
|||
set(_preferred_sdk_dirs) |
|||
set(_win_sdk_dirs) |
|||
set(_win_sdk_versanddirs) |
|||
if(MSVC_VERSION GREATER 1310) # Newer than VS .NET/VS Toolkit 2003 |
|||
|
|||
# Environment variable for SDK dir |
|||
if(EXISTS "$ENV{WindowsSDKDir}" AND (NOT "$ENV{WindowsSDKDir}" STREQUAL "")) |
|||
message(STATUS "Got $ENV{WindowsSDKDir} - Windows/Platform SDK directories: ${_win_sdk_dirs}") |
|||
list(APPEND _preferred_sdk_dirs "$ENV{WindowsSDKDir}") |
|||
endif() |
|||
|
|||
if(MSVC_VERSION LESS 1600) |
|||
# Per-user current Windows SDK for VS2005/2008 |
|||
get_filename_component(_sdkdir |
|||
"[HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]" |
|||
ABSOLUTE) |
|||
if(EXISTS "${_sdkdir}") |
|||
list(APPEND _preferred_sdk_dirs "${_sdkdir}") |
|||
endif() |
|||
|
|||
# System-wide current Windows SDK for VS2005/2008 |
|||
get_filename_component(_sdkdir |
|||
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]" |
|||
ABSOLUTE) |
|||
if(EXISTS "${_sdkdir}") |
|||
list(APPEND _preferred_sdk_dirs "${_sdkdir}") |
|||
endif() |
|||
endif() |
|||
|
|||
if(MSVC_VERSION LESS 1700) |
|||
# VC 10 and older has broad target support |
|||
set(_winsdk_vistaonly) |
|||
else() |
|||
# VC 11 by default targets Vista and later only, so we can add a few more SDKs that (might?) only work on vista+ |
|||
if("${CMAKE_VS_PLATFORM_TOOLSET}" MATCHES "_xp") |
|||
# This is the XP-compatible v110 toolset |
|||
elseif("${CMAKE_VS_PLATFORM_TOOLSET}" STREQUAL "v100") |
|||
# This is the VS2010 toolset |
|||
else() |
|||
if(NOT WINDOWSSDK_FOUND AND NOT WindowsSDK_FIND_QUIETLY) |
|||
message(STATUS "FindWindowsSDK: Detected Visual Studio 2012 or newer, not using the _xp toolset variant: including SDK versions that drop XP support in search!") |
|||
endif() |
|||
# These versions have no XP (and possibly Vista pre-SP1) support |
|||
set(_winsdk_vistaonly) |
|||
if(NOT MSVC_VERSION LESS 1800) |
|||
list(APPEND _winsdk_vistaonly |
|||
# Windows Software Development Kit (SDK) for Windows 8.1 |
|||
# http://msdn.microsoft.com/en-gb/windows/desktop/bg162891 |
|||
v8.1) |
|||
endif() |
|||
list(APPEND _winsdk_vistaonly |
|||
# Included in Visual Studio 2012 |
|||
v8.0A |
|||
|
|||
# Microsoft Windows SDK for Windows 8 and .NET Framework 4.5 |
|||
# This is the first version to also include the DirectX SDK |
|||
# http://msdn.microsoft.com/en-US/windows/desktop/hh852363.aspx |
|||
v8.0 |
|||
|
|||
# Microsoft Windows SDK for Windows 7 and .NET Framework 4 |
|||
# http://www.microsoft.com/downloads/en/details.aspx?FamilyID=6b6c21d2-2006-4afa-9702-529fa782d63b |
|||
v7.1 |
|||
) |
|||
endif() |
|||
endif() |
|||
foreach(_winsdkver |
|||
${_winsdk_vistaonly} |
|||
|
|||
# Included in Visual Studio 2013 |
|||
# Includes the v120_xp toolset |
|||
v8.1A |
|||
|
|||
# Included with VS 2012 Update 1 or later |
|||
# Introduces v110_xp toolset |
|||
v7.1A |
|||
|
|||
# Included with VS 2010 |
|||
v7.0A |
|||
|
|||
# Windows SDK for Windows 7 and .NET Framework 3.5 SP1 |
|||
# Works with VC9 |
|||
#http://www.microsoft.com/en-us/download/details.aspx?id=18950 |
|||
v7.0 |
|||
|
|||
# Two versions call themselves "v6.1": |
|||
# Older: |
|||
# Windows Vista Update & .NET 3.0 SDK |
|||
# http://www.microsoft.com/en-us/download/details.aspx?id=14477 |
|||
|
|||
# Newer: |
|||
# Windows Server 2008 & .NET 3.5 SDK |
|||
# may have broken VS9SP1? they recommend v7.0 instead, or a KB... |
|||
# http://www.microsoft.com/en-us/download/details.aspx?id=24826 |
|||
v6.1 |
|||
|
|||
# Included in VS 2008 |
|||
v6.0A |
|||
|
|||
# Microsoft Windows Software Development Kit for Windows Vista and .NET Framework 3.0 Runtime Components |
|||
# http://blogs.msdn.com/b/stanley/archive/2006/11/08/microsoft-windows-software-development-kit-for-windows-vista-and-net-framework-3-0-runtime-components.aspx |
|||
v6.0) |
|||
|
|||
get_filename_component(_sdkdir |
|||
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\${_winsdkver};InstallationFolder]" |
|||
ABSOLUTE) |
|||
if(EXISTS "${_sdkdir}") |
|||
list(APPEND _win_sdk_dirs "${_sdkdir}") |
|||
list(APPEND |
|||
_win_sdk_versanddirs |
|||
"Windows SDK ${_winsdkver}" |
|||
"${_sdkdir}") |
|||
endif() |
|||
endforeach() |
|||
endif() |
|||
if(MSVC_VERSION GREATER 1200) |
|||
foreach(_platformsdkinfo |
|||
"D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1_Microsoft Platform SDK for Windows Server 2003 R2" |
|||
"8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3_Microsoft Platform SDK for Windows Server 2003 SP1") |
|||
string(SUBSTRING "${_platformsdkinfo}" 0 36 _platformsdkguid) |
|||
string(SUBSTRING "${_platformsdkinfo}" 37 -1 _platformsdkname) |
|||
foreach(HIVE HKEY_LOCAL_MACHINE HKEY_CURRENT_USER) |
|||
get_filename_component(_sdkdir |
|||
"[${HIVE}\\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\${_platformsdkguid};Install Dir]" |
|||
ABSOLUTE) |
|||
if(EXISTS "${_sdkdir}") |
|||
list(APPEND _win_sdk_dirs "${_sdkdir}") |
|||
list(APPEND _win_sdk_versanddirs "${_platformsdkname}" "${_sdkdir}") |
|||
endif() |
|||
endforeach() |
|||
endforeach() |
|||
endif() |
|||
|
|||
set(_win_sdk_versanddirs |
|||
"${_win_sdk_versanddirs}" |
|||
CACHE |
|||
INTERNAL |
|||
"mapping between windows sdk version locations and names" |
|||
FORCE) |
|||
|
|||
function(windowssdk_name_lookup _dir _outvar) |
|||
list(FIND _win_sdk_versanddirs "${_dir}" _diridx) |
|||
math(EXPR _nameidx "${_diridx} - 1") |
|||
if(${_nameidx} GREATER -1) |
|||
list(GET _win_sdk_versanddirs ${_nameidx} _sdkname) |
|||
else() |
|||
set(_sdkname "NOTFOUND") |
|||
endif() |
|||
set(${_outvar} "${_sdkname}" PARENT_SCOPE) |
|||
endfunction() |
|||
|
|||
if(_win_sdk_dirs) |
|||
# Remove duplicates |
|||
list(REMOVE_DUPLICATES _win_sdk_dirs) |
|||
list(GET _win_sdk_dirs 0 WINDOWSSDK_LATEST_DIR) |
|||
windowssdk_name_lookup("${WINDOWSSDK_LATEST_DIR}" |
|||
WINDOWSSDK_LATEST_NAME) |
|||
set(WINDOWSSDK_DIRS ${_win_sdk_dirs}) |
|||
endif() |
|||
if(_preferred_sdk_dirs) |
|||
list(GET _preferred_sdk_dirs 0 WINDOWSSDK_PREFERRED_DIR) |
|||
windowssdk_name_lookup("${WINDOWSSDK_LATEST_DIR}" |
|||
WINDOWSSDK_PREFERRED_NAME) |
|||
set(WINDOWSSDK_PREFERRED_FIRST_DIRS |
|||
${_preferred_sdk_dirs} |
|||
${_win_sdk_dirs}) |
|||
list(REMOVE_DUPLICATES WINDOWSSDK_PREFERRED_FIRST_DIRS) |
|||
set(WINDOWSSDK_FOUND_PREFERENCE ON) |
|||
|
|||
# In case a preferred dir was found that isn't found otherwise |
|||
#set(WINDOWSSDK_DIRS ${WINDOWSSDK_DIRS} ${WINDOWSSDK_PREFERRED_FIRST_DIRS}) |
|||
#list(REMOVE_DUPLICATES WINDOWSSDK_DIRS) |
|||
else() |
|||
set(WINDOWSSDK_PREFERRED_DIR "${WINDOWSSDK_LATEST_DIR}") |
|||
set(WINDOWSSDK_PREFERRED_NAME "${WINDOWSSDK_LATEST_NAME}") |
|||
set(WINDOWSSDK_PREFERRED_FIRST_DIRS ${WINDOWSSDK_DIRS}) |
|||
set(WINDOWSSDK_FOUND_PREFERENCE OFF) |
|||
endif() |
|||
|
|||
include(FindPackageHandleStandardArgs) |
|||
find_package_handle_standard_args(WindowsSDK |
|||
"No compatible version of the Windows SDK or Platform SDK found." |
|||
WINDOWSSDK_DIRS) |
|||
|
|||
if(WINDOWSSDK_FOUND) |
|||
if(NOT _winsdk_remembered_dirs STREQUAL WINDOWSSDK_DIRS) |
|||
set(_winsdk_remembered_dirs |
|||
"${WINDOWSSDK_DIRS}" |
|||
CACHE |
|||
INTERNAL |
|||
"" |
|||
FORCE) |
|||
if(NOT WindowsSDK_FIND_QUIETLY) |
|||
foreach(_sdkdir ${WINDOWSSDK_DIRS}) |
|||
windowssdk_name_lookup("${_sdkdir}" _sdkname) |
|||
message(STATUS " - Found ${_sdkname} at ${_sdkdir}") |
|||
endforeach() |
|||
endif() |
|||
endif() |
|||
|
|||
# Internal: Architecture-appropriate library directory names. |
|||
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM") |
|||
set(_winsdk_archbare /arm) # what the architecture used to be called in oldest SDKs |
|||
set(_winsdk_arch arm) # what the architecture used to be called |
|||
set(_winsdk_arch8 arm) # what the WDK for Win8+ calls this architecture |
|||
else() |
|||
if(CMAKE_SIZEOF_VOID_P MATCHES "8") |
|||
set(_winsdk_archbare /x64) # what the architecture used to be called in oldest SDKs |
|||
set(_winsdk_arch amd64) # what the architecture used to be called |
|||
set(_winsdk_arch8 x64) # what the WDK for Win8+ calls this architecture |
|||
else() |
|||
set(_winsdk_archbare ) # what the architecture used to be called in oldest SDKs |
|||
set(_winsdk_arch i386) # what the architecture used to be called |
|||
set(_winsdk_arch8 x86) # what the WDK for Win8+ calls this architecture |
|||
endif() |
|||
endif() |
|||
|
|||
function(get_windowssdk_from_component _component _var) |
|||
get_filename_component(_component "${_component}" ABSOLUTE) |
|||
file(TO_CMAKE_PATH "${_component}" _component) |
|||
foreach(_sdkdir ${WINDOWSSDK_DIRS}) |
|||
get_filename_component(_sdkdir "${_sdkdir}" ABSOLUTE) |
|||
string(LENGTH "${_sdkdir}" _sdklen) |
|||
file(RELATIVE_PATH _rel "${_sdkdir}" "${_component}") |
|||
# If we don't have any "parent directory" items... |
|||
if(NOT "${_rel}" MATCHES "[.][.]") |
|||
set(${_var} "${_sdkdir}" PARENT_SCOPE) |
|||
return() |
|||
endif() |
|||
endforeach() |
|||
# Fail. |
|||
set(${_var} "NOTFOUND" PARENT_SCOPE) |
|||
endfunction() |
|||
function(get_windowssdk_library_dirs _winsdk_dir _var) |
|||
set(_result) |
|||
foreach(_suffix |
|||
"lib${_winsdk_archbare}" # SDKs like 7.1A |
|||
"lib/w2k/${_winsdk_arch}" # Win2k min requirement |
|||
"lib/wxp/${_winsdk_arch}" # WinXP min requirement |
|||
"lib/wnet/${_winsdk_arch}" # Win Server 2003 min requirement |
|||
"lib/wlh/${_winsdk_arch}" # Win Vista ("Long Horn") min requirement |
|||
"lib/wlh/um/${_winsdk_arch8}" # Win Vista ("Long Horn") min requirement |
|||
"lib/win7/${_winsdk_arch}" # Win 7 min requirement |
|||
"lib/win7/um/${_winsdk_arch8}" # Win 7 min requirement |
|||
"lib/win8/um/${_winsdk_arch8}" # Win 8 min requirement |
|||
"lib/win8/km/${_winsdk_arch8}" # Win 8 min requirement |
|||
"lib/winv6.3/km/${_winsdk_arch8}" # Win 8.1 min requirement |
|||
"lib/winv6.3/um/${_winsdk_arch8}" # Win 8.1 min requirement |
|||
) |
|||
# Check to see if a library actually exists here. |
|||
file(GLOB _libs "${_winsdk_dir}/${_suffix}/*.lib") |
|||
if(_libs) |
|||
list(APPEND _result "${_winsdk_dir}/${_suffix}") |
|||
endif() |
|||
endforeach() |
|||
if(NOT _result) |
|||
set(_result NOTFOUND) |
|||
endif() |
|||
set(${_var} ${_result} PARENT_SCOPE) |
|||
endfunction() |
|||
function(get_windowssdk_include_dirs _winsdk_dir _var) |
|||
set(_result) |
|||
foreach(_suffix |
|||
"Include" |
|||
"Include/shared" |
|||
"Include/um" |
|||
"Include/winrt" |
|||
"Include/km" |
|||
"Include/wdf" |
|||
) |
|||
# Check to see if a header file actually exists here. |
|||
file(GLOB _headers "${_winsdk_dir}/${_suffix}/*.h") |
|||
if(_headers) |
|||
list(APPEND _result "${_winsdk_dir}/${_suffix}") |
|||
endif() |
|||
endforeach() |
|||
if(NOT _result) |
|||
set(_result NOTFOUND) |
|||
endif() |
|||
set(${_var} ${_result} PARENT_SCOPE) |
|||
endfunction() |
|||
endif() |
@ -0,0 +1,49 @@ |
|||
# Find v8 |
|||
# |
|||
# Find the v8 includes and library |
|||
# |
|||
# if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH |
|||
# |
|||
# This module defines |
|||
# V8_INCLUDE_DIRS, where to find header, etc. |
|||
# V8_LIBRARIES, the libraries needed to use v8. |
|||
# V8_FOUND, If false, do not try to use v8. |
|||
|
|||
# only look in default directories |
|||
find_path( |
|||
V8_INCLUDE_DIR |
|||
NAMES v8.h |
|||
DOC "v8 include dir" |
|||
) |
|||
|
|||
find_library( |
|||
V8_LIBRARY |
|||
NAMES v8 |
|||
DOC "v8 library" |
|||
) |
|||
|
|||
set(V8_INCLUDE_DIRS ${V8_INCLUDE_DIR}) |
|||
set(V8_LIBRARIES ${V8_LIBRARY}) |
|||
|
|||
# debug library on windows |
|||
# same naming convention as in qt (appending debug library with d) |
|||
# boost is using the same "hack" as us with "optimized" and "debug" |
|||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
|||
|
|||
find_library( |
|||
V8_LIBRARY_DEBUG |
|||
NAMES v8d |
|||
DOC "v8 debug library" |
|||
) |
|||
|
|||
set(V8_LIBRARIES optimized ${V8_LIBRARIES} debug ${V8_LIBRARY_DEBUG}) |
|||
|
|||
endif() |
|||
|
|||
# handle the QUIETLY and REQUIRED arguments and set V8_FOUND to TRUE |
|||
# if all listed variables are TRUE, hide their existence from configuration view |
|||
include(FindPackageHandleStandardArgs) |
|||
find_package_handle_standard_args(v8 DEFAULT_MSG |
|||
V8_INCLUDE_DIR V8_LIBRARY) |
|||
mark_as_advanced (V8_INCLUDE_DIR V8_LIBRARY) |
|||
|
@ -0,0 +1,17 @@ |
|||
|
|||
if (NOT APP_DMG_EXE) |
|||
message(FATAL_ERROR "Please install appdmg! https://github.com/LinusU/node-appdmg") |
|||
endif() |
|||
|
|||
string(REPLACE "/Contents/MacOS" "" ETH_MIX_APP "${ETH_MIX_APP}") |
|||
string(REPLACE "/Contents/MacOS" "" ETH_ALETHZERO_APP "${ETH_ALETHZERO_APP}") |
|||
|
|||
set(OUTFILE "${ETH_BUILD_DIR}/appdmg.json") |
|||
|
|||
configure_file(${APP_DMG_FILE} ${OUTFILE}) |
|||
|
|||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${APP_DMG_ICON}" "${ETH_BUILD_DIR}/appdmg_icon.icns") |
|||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${APP_DMG_BACKGROUND}" "${ETH_BUILD_DIR}/appdmg_background.png") |
|||
execute_process(COMMAND ${CMAKE_COMMAND} -E remove "${ETH_BUILD_DIR}/Ethereum.dmg") |
|||
execute_process(COMMAND ${APP_DMG_EXE} ${OUTFILE} "${ETH_BUILD_DIR}/Ethereum.dmg") |
|||
|
@ -0,0 +1,30 @@ |
|||
// this file is autogenerated, do not modify!!!
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <map> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
|
|||
class ${ETH_RESOURCE_NAME} |
|||
{ |
|||
public: |
|||
${ETH_RESOURCE_NAME}() |
|||
{ |
|||
${ETH_RESULT_DATA} |
|||
${ETH_RESULT_INIT} |
|||
} |
|||
|
|||
std::string loadResourceAsString(std::string _name) { return std::string(m_resources[_name], m_sizes[_name]); } |
|||
|
|||
private: |
|||
std::map <std::string, const char*> m_resources; |
|||
std::map <std::string, unsigned> m_sizes; |
|||
}; |
|||
|
|||
} |
|||
} |
|||
|
@ -0,0 +1,57 @@ |
|||
# based on: http://stackoverflow.com/questions/11813271/embed-resources-eg-shader-code-images-into-executable-library-with-cmake |
|||
# |
|||
# example: |
|||
# cmake -DETH_RES_FILE=test.cmake -P resources.cmake |
|||
# |
|||
# where test.cmake is: |
|||
# |
|||
# # BEGIN OF cmake.test |
|||
# |
|||
# set(copydlls "copydlls.cmake") |
|||
# set(conf "configure.cmake") |
|||
# |
|||
# # this three properties must be set! |
|||
# |
|||
# set(ETH_RESOURCE_NAME "EthResources") |
|||
# set(ETH_RESOURCE_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}") |
|||
# set(ETH_RESOURCES "copydlls" "conf") |
|||
# |
|||
# # END of cmake.test |
|||
# |
|||
|
|||
# should define ETH_RESOURCES |
|||
include(${ETH_RES_FILE}) |
|||
|
|||
set(ETH_RESULT_DATA "") |
|||
set(ETH_RESULT_INIT "") |
|||
|
|||
# resource is a name visible for cpp application |
|||
foreach(resource ${ETH_RESOURCES}) |
|||
|
|||
# filename is the name of file which will be used in app |
|||
set(filename ${${resource}}) |
|||
|
|||
# filedata is a file content |
|||
file(READ ${filename} filedata HEX) |
|||
|
|||
# read full name of the file |
|||
file(GLOB filename ${filename}) |
|||
|
|||
# Convert hex data for C compatibility |
|||
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata}) |
|||
|
|||
# append static variables to result variable |
|||
set(ETH_RESULT_DATA "${ETH_RESULT_DATA} static const unsigned char eth_${resource}[] = {\n // ${filename}\n ${filedata}\n};\n") |
|||
|
|||
# append init resources |
|||
set(ETH_RESULT_INIT "${ETH_RESULT_INIT} m_resources[\"${resource}\"] = (char const*)eth_${resource};\n") |
|||
set(ETH_RESULT_INIT "${ETH_RESULT_INIT} m_sizes[\"${resource}\"] = sizeof(eth_${resource});\n") |
|||
|
|||
endforeach(resource) |
|||
|
|||
set(ETH_DST_NAME "${ETH_RESOURCE_LOCATION}/${ETH_RESOURCE_NAME}") |
|||
|
|||
configure_file("${CMAKE_CURRENT_LIST_DIR}/resource.hpp.in" "${ETH_DST_NAME}.hpp.tmp") |
|||
|
|||
include("${CMAKE_CURRENT_LIST_DIR}/../EthUtils.cmake") |
|||
replace_if_different("${ETH_DST_NAME}.hpp.tmp" "${ETH_DST_NAME}.hpp") |
@ -1,36 +1,31 @@ |
|||
FROM ubuntu:14.04 |
|||
FROM ubuntu:utopic |
|||
MAINTAINER caktux |
|||
|
|||
ENV DEBIAN_FRONTEND noninteractive |
|||
|
|||
# Usual update / upgrade |
|||
RUN apt-get update |
|||
RUN apt-get upgrade -y |
|||
RUN apt-get upgrade -q -y |
|||
RUN apt-get dist-upgrade -q -y |
|||
|
|||
# Ethereum dependencies |
|||
RUN apt-get install -qy build-essential g++-4.8 git cmake libboost-all-dev libcurl4-openssl-dev wget |
|||
RUN apt-get install -qy automake unzip libgmp-dev libtool libleveldb-dev yasm libminiupnpc-dev libreadline-dev scons |
|||
RUN apt-get install -qy libjsoncpp-dev libargtable2-dev |
|||
RUN apt-get install -qy libncurses5-dev libcurl4-openssl-dev wget |
|||
RUN apt-get install -qy libjsoncpp-dev libargtable2-dev libmicrohttpd-dev |
|||
# Let our containers upgrade themselves |
|||
RUN apt-get install -q -y unattended-upgrades |
|||
|
|||
# Ethereum PPA |
|||
RUN apt-get install -qy software-properties-common |
|||
# Install Ethereum |
|||
RUN apt-get install -q -y software-properties-common |
|||
RUN add-apt-repository ppa:ethereum/ethereum |
|||
RUN add-apt-repository ppa:ethereum/ethereum-dev |
|||
RUN apt-get update |
|||
RUN apt-get install -qy libcryptopp-dev libjson-rpc-cpp-dev |
|||
RUN apt-get install -q -y eth |
|||
|
|||
# LLVM-3.5 |
|||
RUN wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key|sudo apt-key add - |
|||
RUN echo "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.5 main\ndeb-src http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.5 main" > /etc/apt/sources.list.d/llvm-trusty.list |
|||
RUN apt-get update |
|||
RUN apt-get install -qy llvm-3.5 libedit-dev |
|||
# Install supervisor |
|||
RUN apt-get install -q -y supervisor |
|||
|
|||
# Fix llvm-3.5 cmake paths |
|||
RUN mkdir -p /usr/lib/llvm-3.5/share/llvm && ln -s /usr/share/llvm-3.5/cmake /usr/lib/llvm-3.5/share/llvm/cmake |
|||
# Add supervisor configs |
|||
ADD supervisord.conf supervisord.conf |
|||
|
|||
# Build Ethereum (HEADLESS) |
|||
RUN git clone --depth=1 https://github.com/ethereum/cpp-ethereum |
|||
RUN mkdir -p cpp-ethereum/build |
|||
RUN cd cpp-ethereum/build && cmake .. -DHEADLESS=1 -DLLVM_DIR=/usr/share/llvm-3.5/cmake -DEVMJIT=1 && make -j $(cat /proc/cpuinfo | grep processor | wc -l) && make install |
|||
RUN ldconfig |
|||
EXPOSE 8080 |
|||
EXPOSE 30303 |
|||
|
|||
ENTRYPOINT ["/usr/local/bin/eth"] |
|||
CMD ["-n", "-c", "/supervisord.conf"] |
|||
ENTRYPOINT ["/usr/bin/supervisord"] |
|||
|
@ -1,17 +1,30 @@ |
|||
# Dockerfile for cpp-ethereum |
|||
Dockerfile to build a bleeding edge cpp-ethereum docker image from source |
|||
|
|||
docker build -t cppeth < Dockerfile |
|||
### Quick usage |
|||
|
|||
Run a simple peer server |
|||
docker run -d ethereum/client-cpp |
|||
|
|||
docker run -i cppeth -m off -o peer -x 256 |
|||
### Building |
|||
|
|||
GUI is compiled but not exposed. You can mount /cpp-ethereum/build to access binaries: |
|||
Dockerfile to build a cpp-ethereum docker image from source |
|||
|
|||
cid = $(docker run -i -v /cpp-ethereum/build cppeth -m off -o peer -x 256) |
|||
docker inspect $cid # <-- Find volume path in JSON output |
|||
docker build -t cpp-ethereum . |
|||
|
|||
You may also modify the Docker image to run the GUI and expose a |
|||
ssh/VNC server in order to tunnel an X11 or VNC session. |
|||
### Running |
|||
|
|||
docker run -d cpp-ethereum |
|||
|
|||
### Usage |
|||
|
|||
First enter the container: |
|||
|
|||
docker exec -it <container name> bash |
|||
|
|||
Inspect logs: |
|||
|
|||
cat /var/log/cpp-ethereum.log |
|||
cat /var/log/cpp-ethereum.err |
|||
|
|||
Restart supervisor service: |
|||
|
|||
supervisorctl restart cpp-ethereum |
|||
|
@ -0,0 +1,23 @@ |
|||
[supervisord] |
|||
nodaemon=false |
|||
|
|||
[program:eth] |
|||
priority=30 |
|||
directory=/ |
|||
command=eth --bootstrap --json-rpc |
|||
user=root |
|||
autostart=true |
|||
autorestart=true |
|||
startsecs=10 |
|||
stopsignal=QUIT |
|||
stdout_logfile=/var/log/eth.log |
|||
stderr_logfile=/var/log/eth.err |
|||
|
|||
[unix_http_server] |
|||
file=%(here)s/supervisor.sock |
|||
|
|||
[supervisorctl] |
|||
serverurl=unix://%(here)s/supervisor.sock |
|||
|
|||
[rpcinterface:supervisor] |
|||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface |
File diff suppressed because it is too large
@ -0,0 +1,33 @@ |
|||
cmake_policy(SET CMP0015 NEW) |
|||
set(CMAKE_AUTOMOC OFF) |
|||
|
|||
aux_source_directory(. SRC_LIST) |
|||
|
|||
include_directories(BEFORE ..) |
|||
include_directories(${Boost_INCLUDE_DIRS}) |
|||
include_directories(${JSON_RPC_CPP_INCLUDE_DIRS}) |
|||
|
|||
if (JSCONSOLE) |
|||
include_directories(${V8_INCLUDE_DIRS}) |
|||
endif() |
|||
|
|||
set(EXECUTABLE ethkey) |
|||
|
|||
file(GLOB HEADERS "*.h") |
|||
|
|||
add_executable(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) |
|||
|
|||
add_dependencies(${EXECUTABLE} BuildInfo.h) |
|||
|
|||
target_link_libraries(${EXECUTABLE} devcrypto) |
|||
target_link_libraries(${EXECUTABLE} ethcore) |
|||
|
|||
if (DEFINED WIN32 AND NOT DEFINED CMAKE_COMPILER_IS_MINGW) |
|||
eth_copy_dlls("${EXECUTABLE}" MHD_DLLS) |
|||
endif() |
|||
|
|||
if (APPLE) |
|||
install(TARGETS ${EXECUTABLE} DESTINATION bin) |
|||
else() |
|||
eth_install_executable(${EXECUTABLE}) |
|||
endif() |
@ -0,0 +1,468 @@ |
|||
#pragma once |
|||
|
|||
/*
|
|||
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. |
|||
|
|||
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file KeyAux.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
* CLI module for key management. |
|||
*/ |
|||
|
|||
#include <thread> |
|||
#include <chrono> |
|||
#include <fstream> |
|||
#include <iostream> |
|||
#include <boost/algorithm/string.hpp> |
|||
#include <boost/algorithm/string/trim_all.hpp> |
|||
#include <libdevcore/SHA3.h> |
|||
#include <libdevcore/FileSystem.h> |
|||
#include <libethcore/KeyManager.h> |
|||
#include <libethcore/ICAP.h> |
|||
#include "BuildInfo.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
using namespace boost::algorithm; |
|||
|
|||
#undef RETURN |
|||
|
|||
class BadArgument: public Exception {}; |
|||
|
|||
string getAccountPassword(KeyManager& keyManager, Address const& a) |
|||
{ |
|||
return getPassword("Enter password for address " + keyManager.accountDetails()[a].first + " (" + a.abridged() + "; hint:" + keyManager.accountDetails()[a].second + "): "); |
|||
} |
|||
|
|||
string createPassword(std::string const& _prompt) |
|||
{ |
|||
string ret; |
|||
while (true) |
|||
{ |
|||
ret = getPassword(_prompt); |
|||
string confirm = getPassword("Please confirm the password by entering it again: "); |
|||
if (ret == confirm) |
|||
break; |
|||
cout << "Passwords were different. Try again." << endl; |
|||
} |
|||
return ret; |
|||
// cout << "Enter a hint to help you remember this password: " << flush;
|
|||
// cin >> hint;
|
|||
// return make_pair(ret, hint);
|
|||
} |
|||
|
|||
pair<string, string> createPassword(KeyManager& _keyManager, std::string const& _prompt, std::string const& _pass = std::string(), std::string const& _hint = std::string()) |
|||
{ |
|||
string pass = _pass; |
|||
if (pass.empty()) |
|||
while (true) |
|||
{ |
|||
pass = getPassword(_prompt); |
|||
string confirm = getPassword("Please confirm the password by entering it again: "); |
|||
if (pass == confirm) |
|||
break; |
|||
cout << "Passwords were different. Try again." << endl; |
|||
} |
|||
string hint = _hint; |
|||
if (hint.empty() && !pass.empty() && !_keyManager.haveHint(pass)) |
|||
{ |
|||
cout << "Enter a hint to help you remember this password: " << flush; |
|||
getline(cin, hint); |
|||
} |
|||
return make_pair(pass, hint); |
|||
} |
|||
|
|||
class KeyCLI |
|||
{ |
|||
public: |
|||
enum class OperationMode |
|||
{ |
|||
None, |
|||
ListBare, |
|||
NewBare, |
|||
ImportBare, |
|||
ExportBare, |
|||
RecodeBare, |
|||
KillBare, |
|||
InspectBare, |
|||
CreateWallet, |
|||
List, |
|||
New, |
|||
Import, |
|||
ImportWithAddress, |
|||
Export, |
|||
Recode, |
|||
Kill |
|||
}; |
|||
|
|||
KeyCLI(OperationMode _mode = OperationMode::None): m_mode(_mode) {} |
|||
|
|||
bool interpretOption(int& i, int argc, char** argv) |
|||
{ |
|||
string arg = argv[i]; |
|||
if (arg == "--wallet-path" && i + 1 < argc) |
|||
m_walletPath = argv[++i]; |
|||
else if (arg == "--secrets-path" && i + 1 < argc) |
|||
m_secretsPath = argv[++i]; |
|||
else if ((arg == "-m" || arg == "--master") && i + 1 < argc) |
|||
m_masterPassword = argv[++i]; |
|||
else if (arg == "--unlock" && i + 1 < argc) |
|||
m_unlocks.push_back(argv[++i]); |
|||
else if (arg == "--lock" && i + 1 < argc) |
|||
m_lock = argv[++i]; |
|||
else if (arg == "--kdf" && i + 1 < argc) |
|||
m_kdf = argv[++i]; |
|||
else if (arg == "--kdf-param" && i + 2 < argc) |
|||
{ |
|||
auto n = argv[++i]; |
|||
auto v = argv[++i]; |
|||
m_kdfParams[n] = v; |
|||
} |
|||
else if (arg == "--new-bare") |
|||
m_mode = OperationMode::NewBare; |
|||
else if (arg == "--import-bare") |
|||
m_mode = OperationMode::ImportBare; |
|||
else if (arg == "--list-bare") |
|||
m_mode = OperationMode::ListBare; |
|||
else if (arg == "--export-bare") |
|||
m_mode = OperationMode::ExportBare; |
|||
else if (arg == "--inspect-bare") |
|||
m_mode = OperationMode::InspectBare; |
|||
else if (arg == "--recode-bare") |
|||
m_mode = OperationMode::RecodeBare; |
|||
else if (arg == "--kill-bare") |
|||
m_mode = OperationMode::KillBare; |
|||
else if (arg == "--create-wallet") |
|||
m_mode = OperationMode::CreateWallet; |
|||
else if (arg == "--list") |
|||
m_mode = OperationMode::List; |
|||
else if ((arg == "-n" || arg == "--new") && i + 1 < argc) |
|||
{ |
|||
m_mode = OperationMode::New; |
|||
m_name = argv[++i]; |
|||
} |
|||
else if ((arg == "-i" || arg == "--import") && i + 2 < argc) |
|||
{ |
|||
m_mode = OperationMode::Import; |
|||
m_inputs = strings(1, argv[++i]); |
|||
m_name = argv[++i]; |
|||
} |
|||
else if ((arg == "-i" || arg == "--import-with-address") && i + 3 < argc) |
|||
{ |
|||
m_mode = OperationMode::ImportWithAddress; |
|||
m_inputs = strings(1, argv[++i]); |
|||
m_address = Address(argv[++i]); |
|||
m_name = argv[++i]; |
|||
} |
|||
else if (arg == "--export") |
|||
m_mode = OperationMode::Export; |
|||
else if (arg == "--recode") |
|||
m_mode = OperationMode::Recode; |
|||
else if (arg == "--no-icap") |
|||
m_icap = false; |
|||
else if (m_mode == OperationMode::ImportBare || m_mode == OperationMode::InspectBare || m_mode == OperationMode::KillBare || m_mode == OperationMode::Recode || m_mode == OperationMode::Export || m_mode == OperationMode::RecodeBare || m_mode == OperationMode::ExportBare) |
|||
m_inputs.push_back(arg); |
|||
else |
|||
return false; |
|||
return true; |
|||
} |
|||
|
|||
KeyPair makeKey() const |
|||
{ |
|||
KeyPair k(Secret::random()); |
|||
while (m_icap && k.address()[0]) |
|||
k = KeyPair(sha3(k.secret())); |
|||
return k; |
|||
} |
|||
|
|||
void execute() |
|||
{ |
|||
if (m_mode == OperationMode::CreateWallet) |
|||
{ |
|||
KeyManager wallet(m_walletPath, m_secretsPath); |
|||
if (m_masterPassword.empty()) |
|||
m_masterPassword = createPassword("Please enter a MASTER password to protect your key store (make it strong!): "); |
|||
if (m_masterPassword.empty()) |
|||
cerr << "Aborted (empty password not allowed)." << endl; |
|||
else |
|||
wallet.create(m_masterPassword); |
|||
} |
|||
else if (m_mode < OperationMode::CreateWallet) |
|||
{ |
|||
SecretStore store(m_secretsPath); |
|||
switch (m_mode) |
|||
{ |
|||
case OperationMode::ListBare: |
|||
for (h128 const& u: std::set<h128>() + store.keys()) |
|||
cout << toUUID(u) << endl; |
|||
break; |
|||
case OperationMode::NewBare: |
|||
{ |
|||
if (m_lock.empty()) |
|||
m_lock = createPassword("Enter a password with which to secure this account: "); |
|||
auto k = makeKey(); |
|||
h128 u = store.importSecret(k.secret().asBytes(), m_lock); |
|||
cout << "Created key " << toUUID(u) << endl; |
|||
cout << " Address: " << k.address().hex() << endl; |
|||
cout << " ICAP: " << ICAP(k.address()).encoded() << endl; |
|||
break; |
|||
} |
|||
case OperationMode::ImportBare: |
|||
for (string const& i: m_inputs) |
|||
{ |
|||
h128 u; |
|||
bytes b; |
|||
b = fromHex(i); |
|||
if (b.size() != 32) |
|||
{ |
|||
std::string s = contentsString(i); |
|||
b = fromHex(s); |
|||
if (b.size() != 32) |
|||
u = store.importKey(i); |
|||
} |
|||
if (!u && b.size() == 32) |
|||
u = store.importSecret(b, lockPassword(toAddress(Secret(b)).abridged())); |
|||
if (!u) |
|||
{ |
|||
cerr << "Cannot import " << i << " not a file or secret." << endl; |
|||
continue; |
|||
} |
|||
cout << "Successfully imported " << i << " as " << toUUID(u); |
|||
} |
|||
break; |
|||
case OperationMode::InspectBare: |
|||
for (auto const& i: m_inputs) |
|||
if (!contents(i).empty()) |
|||
{ |
|||
h128 u = store.readKey(i, false); |
|||
bytes s = store.secret(u, [&](){ return getPassword("Enter password for key " + i + ": "); }); |
|||
cout << "Key " << i << ":" << endl; |
|||
cout << " UUID: " << toUUID(u) << ":" << endl; |
|||
cout << " Address: " << toAddress(Secret(s)).hex() << endl; |
|||
cout << " Secret: " << Secret(s).abridged() << endl; |
|||
} |
|||
else if (h128 u = fromUUID(i)) |
|||
{ |
|||
bytes s = store.secret(u, [&](){ return getPassword("Enter password for key " + toUUID(u) + ": "); }); |
|||
cout << "Key " << i << ":" << endl; |
|||
cout << " Address: " << toAddress(Secret(s)).hex() << endl; |
|||
cout << " Secret: " << Secret(s).abridged() << endl; |
|||
} |
|||
else |
|||
cerr << "Couldn't inspect " << i << "; not found." << endl; |
|||
break; |
|||
case OperationMode::ExportBare: break; |
|||
case OperationMode::RecodeBare: |
|||
for (auto const& i: m_inputs) |
|||
if (h128 u = fromUUID(i)) |
|||
if (store.recode(u, lockPassword(toUUID(u)), [&](){ return getPassword("Enter password for key " + toUUID(u) + ": "); }, kdf())) |
|||
cerr << "Re-encoded " << toUUID(u) << endl; |
|||
else |
|||
cerr << "Couldn't re-encode " << toUUID(u) << "; key corrupt or incorrect password supplied." << endl; |
|||
else |
|||
cerr << "Couldn't re-encode " << i << "; not found." << endl; |
|||
case OperationMode::KillBare: |
|||
for (auto const& i: m_inputs) |
|||
if (h128 u = fromUUID(i)) |
|||
store.kill(u); |
|||
else |
|||
cerr << "Couldn't kill " << i << "; not found." << endl; |
|||
break; |
|||
default: break; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
KeyManager wallet(m_walletPath, m_secretsPath); |
|||
if (wallet.exists()) |
|||
while (true) |
|||
{ |
|||
if (wallet.load(m_masterPassword)) |
|||
break; |
|||
if (!m_masterPassword.empty()) |
|||
{ |
|||
cout << "Password invalid. Try again." << endl; |
|||
m_masterPassword.clear(); |
|||
} |
|||
m_masterPassword = getPassword("Please enter your MASTER password: "); |
|||
} |
|||
else |
|||
{ |
|||
cerr << "Couldn't open wallet. Does it exist?" << endl; |
|||
exit(-1); |
|||
} |
|||
switch (m_mode) |
|||
{ |
|||
case OperationMode::New: |
|||
{ |
|||
tie(m_lock, m_lockHint) = createPassword(wallet, "Enter a password with which to secure this account (or nothing to use the master password): ", m_lock, m_lockHint); |
|||
auto k = makeKey(); |
|||
bool usesMaster = m_lock.empty(); |
|||
h128 u = usesMaster ? wallet.import(k.secret(), m_name) : wallet.import(k.secret(), m_name, m_lock, m_lockHint); |
|||
cout << "Created key " << toUUID(u) << endl; |
|||
cout << " Name: " << m_name << endl; |
|||
if (usesMaster) |
|||
cout << " Uses master password." << endl; |
|||
else |
|||
cout << " Password hint: " << m_lockHint << endl; |
|||
cout << " Address: " << k.address().hex() << endl; |
|||
cout << " ICAP: " << ICAP(k.address()).encoded() << endl; |
|||
break; |
|||
} |
|||
case OperationMode::ImportWithAddress: |
|||
{ |
|||
string const& i = m_inputs[0]; |
|||
h128 u; |
|||
bytes b; |
|||
b = fromHex(i); |
|||
if (b.size() != 32) |
|||
{ |
|||
std::string s = contentsString(i); |
|||
b = fromHex(s); |
|||
if (b.size() != 32) |
|||
u = wallet.store().importKey(i); |
|||
} |
|||
if (!u && b.size() == 32) |
|||
u = wallet.store().importSecret(b, lockPassword(toAddress(Secret(b)).abridged())); |
|||
if (!u) |
|||
{ |
|||
cerr << "Cannot import " << i << " not a file or secret." << endl; |
|||
break; |
|||
} |
|||
wallet.importExisting(u, m_name, m_address); |
|||
cout << "Successfully imported " << i << ":" << endl; |
|||
cout << " Name: " << m_name << endl; |
|||
cout << " Address: " << m_address << endl; |
|||
cout << " UUID: " << toUUID(u) << endl; |
|||
break; |
|||
} |
|||
case OperationMode::List: |
|||
{ |
|||
vector<u128> bare; |
|||
vector<u128> nonIcap; |
|||
for (auto const& u: wallet.store().keys()) |
|||
if (Address a = wallet.address(u)) |
|||
if (a[0]) |
|||
nonIcap.push_back(u); |
|||
else |
|||
{ |
|||
std::pair<std::string, std::string> info = wallet.accountDetails()[a]; |
|||
cout << toUUID(u) << " " << a.abridged(); |
|||
cout << " " << ICAP(a).encoded(); |
|||
cout << " " << info.first << endl; |
|||
} |
|||
else |
|||
bare.push_back(u); |
|||
for (auto const& u: nonIcap) |
|||
if (Address a = wallet.address(u)) |
|||
{ |
|||
std::pair<std::string, std::string> info = wallet.accountDetails()[a]; |
|||
cout << toUUID(u) << " " << a.abridged(); |
|||
cout << " (Not ICAP) "; |
|||
cout << " " << info.first << endl; |
|||
} |
|||
for (auto const& u: bare) |
|||
cout << toUUID(u) << " (Bare)" << endl; |
|||
} |
|||
default: break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
std::string lockPassword(std::string const& _accountName) |
|||
{ |
|||
return m_lock.empty() ? createPassword("Enter a password with which to secure account " + _accountName + ": ") : m_lock; |
|||
} |
|||
|
|||
static void streamHelp(ostream& _out) |
|||
{ |
|||
_out |
|||
<< "Secret-store (\"bare\") operation modes:" << endl |
|||
<< " --list-bare List all secret available in secret-store." << endl |
|||
<< " --new-bare Generate and output a key without interacting with wallet and dump the JSON." << endl |
|||
<< " --import-bare [ <file>|<secret-hex> , ... ] Import keys from given sources." << endl |
|||
<< " --recode-bare [ <uuid>|<file> , ... ] Decrypt and re-encrypt given keys." << endl |
|||
// << " --export-bare [ <uuid> , ... ] Export given keys." << endl
|
|||
<< " --kill-bare [ <uuid> , ... ] Delete given keys." << endl |
|||
<< "Secret-store configuration:" << endl |
|||
<< " --secrets-path <path> Specify Web3 secret-store path (default: " << SecretStore::defaultPath() << ")" << endl |
|||
<< endl |
|||
<< "Wallet operating modes:" << endl |
|||
<< " -l,--list List all keys available in wallet." << endl |
|||
<< " -n,--new <name> Create a new key with given name and add it in the wallet." << endl |
|||
<< " -i,--import [<uuid>|<file>|<secret-hex>] <name> Import keys from given source and place in wallet." << endl |
|||
<< " --import-with-address [<uuid>|<file>|<secret-hex>] <address> <name> Import keys from given source with given address and place in wallet." << endl |
|||
<< " -e,--export [ <address>|<uuid> , ... ] Export given keys." << endl |
|||
<< " -r,--recode [ <address>|<uuid>|<file> , ... ] Decrypt and re-encrypt given keys." << endl |
|||
<< "Wallet configuration:" << endl |
|||
<< " --create-wallet Create an Ethereum master wallet." << endl |
|||
<< " --wallet-path <path> Specify Ethereum wallet path (default: " << KeyManager::defaultPath() << ")" << endl |
|||
<< " -m, --master <password> Specify wallet (master) password." << endl |
|||
<< endl |
|||
<< "Encryption configuration:" << endl |
|||
<< " --kdf <kdfname> Specify KDF to use when encrypting (default: sc rypt)" << endl |
|||
<< " --kdf-param <name> <value> Specify a parameter for the KDF." << endl |
|||
// << " --cipher <ciphername> Specify cipher to use when encrypting (default: aes-128-ctr)" << endl
|
|||
// << " --cipher-param <name> <value> Specify a parameter for the cipher." << endl
|
|||
<< " --lock <password> Specify password for when encrypting a (the) key." << endl |
|||
<< " --hint <hint> Specify hint for the --lock password." << endl |
|||
<< endl |
|||
<< "Decryption configuration:" << endl |
|||
<< " --unlock <password> Specify password for a (the) key." << endl |
|||
<< "Key generation configuration:" << endl |
|||
<< " --no-icap Don't bother to make a direct-ICAP capable key." << endl |
|||
; |
|||
} |
|||
|
|||
static bool isTrue(std::string const& _m) |
|||
{ |
|||
return _m == "on" || _m == "yes" || _m == "true" || _m == "1"; |
|||
} |
|||
|
|||
static bool isFalse(std::string const& _m) |
|||
{ |
|||
return _m == "off" || _m == "no" || _m == "false" || _m == "0"; |
|||
} |
|||
|
|||
private: |
|||
KDF kdf() const { return m_kdf == "pbkdf2" ? KDF::PBKDF2_SHA256 : KDF::Scrypt; } |
|||
|
|||
/// Operating mode.
|
|||
OperationMode m_mode; |
|||
|
|||
/// Wallet stuff
|
|||
string m_secretsPath = SecretStore::defaultPath(); |
|||
string m_walletPath = KeyManager::defaultPath(); |
|||
|
|||
/// Wallet password stuff
|
|||
string m_masterPassword; |
|||
strings m_unlocks; |
|||
string m_lock; |
|||
string m_lockHint; |
|||
bool m_icap = true; |
|||
|
|||
/// Creating/importing
|
|||
string m_name; |
|||
Address m_address; |
|||
|
|||
/// Importing
|
|||
strings m_inputs; |
|||
|
|||
string m_kdf = "scrypt"; |
|||
map<string, string> m_kdfParams; |
|||
// string m_cipher;
|
|||
// map<string, string> m_cipherParams;
|
|||
}; |
@ -0,0 +1,84 @@ |
|||
/*
|
|||
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. |
|||
|
|||
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file main.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
* Ethereum client. |
|||
*/ |
|||
|
|||
#include <thread> |
|||
#include <chrono> |
|||
#include <fstream> |
|||
#include <iostream> |
|||
#include <libdevcore/FileSystem.h> |
|||
#include <libdevcore/Log.h> |
|||
#include <libethcore/KeyManager.h> |
|||
#include "BuildInfo.h" |
|||
#include "KeyAux.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
|
|||
void help() |
|||
{ |
|||
cout |
|||
<< "Usage ethkey [OPTIONS]" << endl |
|||
<< "Options:" << endl << endl; |
|||
KeyCLI::streamHelp(cout); |
|||
cout |
|||
<< "General Options:" << endl |
|||
<< " -v,--verbosity <0 - 9> Set the log verbosity from 0 to 9 (default: 8)." << endl |
|||
<< " -V,--version Show the version and exit." << endl |
|||
<< " -h,--help Show this help message and exit." << endl |
|||
; |
|||
exit(0); |
|||
} |
|||
|
|||
void version() |
|||
{ |
|||
cout << "ethkey version " << dev::Version << endl; |
|||
cout << "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << endl; |
|||
exit(0); |
|||
} |
|||
|
|||
int main(int argc, char** argv) |
|||
{ |
|||
KeyCLI m(KeyCLI::OperationMode::ListBare); |
|||
g_logVerbosity = 0; |
|||
|
|||
for (int i = 1; i < argc; ++i) |
|||
{ |
|||
string arg = argv[i]; |
|||
if (m.interpretOption(i, argc, argv)) {} |
|||
else if ((arg == "-v" || arg == "--verbosity") && i + 1 < argc) |
|||
g_logVerbosity = atoi(argv[++i]); |
|||
else if (arg == "-h" || arg == "--help") |
|||
help(); |
|||
else if (arg == "-V" || arg == "--version") |
|||
version(); |
|||
else |
|||
{ |
|||
cerr << "Invalid argument: " << arg << endl; |
|||
exit(-1); |
|||
} |
|||
} |
|||
|
|||
m.execute(); |
|||
|
|||
return 0; |
|||
} |
|||
|
@ -0,0 +1,43 @@ |
|||
cmake_policy(SET CMP0015 NEW) |
|||
set(CMAKE_AUTOMOC OFF) |
|||
|
|||
aux_source_directory(. SRC_LIST) |
|||
|
|||
include_directories(BEFORE ..) |
|||
include_directories(${Boost_INCLUDE_DIRS}) |
|||
if (JSONRPC) |
|||
include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS}) |
|||
include_directories(${JSON_RPC_CPP_INCLUDE_DIRS}) |
|||
endif() |
|||
|
|||
set(EXECUTABLE ethminer) |
|||
|
|||
file(GLOB HEADERS "*.h") |
|||
|
|||
add_executable(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) |
|||
|
|||
add_dependencies(${EXECUTABLE} BuildInfo.h) |
|||
|
|||
target_link_libraries(${EXECUTABLE} ${Boost_REGEX_LIBRARIES}) |
|||
|
|||
if (JSONRPC) |
|||
target_link_libraries(${EXECUTABLE} ${JSON_RPC_CPP_CLIENT_LIBRARIES}) |
|||
target_link_libraries(${EXECUTABLE} ${CURL_LIBRARIES}) |
|||
if (DEFINED WIN32 AND NOT DEFINED CMAKE_COMPILER_IS_MINGW) |
|||
eth_copy_dlls(${EXECUTABLE} CURL_DLLS) |
|||
endif() |
|||
endif() |
|||
|
|||
target_link_libraries(${EXECUTABLE} ethcore) |
|||
target_link_libraries(${EXECUTABLE} ethash) |
|||
|
|||
if (DEFINED WIN32 AND NOT DEFINED CMAKE_COMPILER_IS_MINGW) |
|||
eth_copy_dlls("${EXECUTABLE}" MHD_DLLS) |
|||
endif() |
|||
|
|||
if (APPLE) |
|||
install(TARGETS ${EXECUTABLE} DESTINATION bin) |
|||
else() |
|||
eth_install_executable(${EXECUTABLE}) |
|||
endif() |
|||
|
@ -0,0 +1,39 @@ |
|||
/**
|
|||
* This file is generated by jsonrpcstub, DO NOT CHANGE IT MANUALLY! |
|||
*/ |
|||
|
|||
#ifndef JSONRPC_CPP_STUB_FARM_H_ |
|||
#define JSONRPC_CPP_STUB_FARM_H_ |
|||
|
|||
#include <jsonrpccpp/client.h> |
|||
|
|||
class Farm : public jsonrpc::Client |
|||
{ |
|||
public: |
|||
Farm(jsonrpc::IClientConnector &conn, jsonrpc::clientVersion_t type = jsonrpc::JSONRPC_CLIENT_V2) : jsonrpc::Client(conn, type) {} |
|||
|
|||
Json::Value eth_getWork() throw (jsonrpc::JsonRpcException) |
|||
{ |
|||
Json::Value p; |
|||
p = Json::nullValue; |
|||
Json::Value result = this->CallMethod("eth_getWork",p); |
|||
if (result.isArray()) |
|||
return result; |
|||
else |
|||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); |
|||
} |
|||
bool eth_submitWork(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException) |
|||
{ |
|||
Json::Value p; |
|||
p.append(param1); |
|||
p.append(param2); |
|||
p.append(param3); |
|||
Json::Value result = this->CallMethod("eth_submitWork",p); |
|||
if (result.isBool()) |
|||
return result.asBool(); |
|||
else |
|||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); |
|||
} |
|||
}; |
|||
|
|||
#endif //JSONRPC_CPP_STUB_FARM_H_
|
@ -0,0 +1,532 @@ |
|||
#pragma once |
|||
|
|||
/*
|
|||
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. |
|||
|
|||
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file MinerAux.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
* CLI module for mining. |
|||
*/ |
|||
|
|||
#include <thread> |
|||
#include <chrono> |
|||
#include <fstream> |
|||
#include <iostream> |
|||
#include <signal.h> |
|||
|
|||
#include <boost/algorithm/string.hpp> |
|||
#include <boost/algorithm/string/trim_all.hpp> |
|||
#include <boost/optional.hpp> |
|||
|
|||
#include <libdevcore/FileSystem.h> |
|||
#include <libevmcore/Instruction.h> |
|||
#include <libdevcore/StructuredLogger.h> |
|||
#include <libethcore/Exceptions.h> |
|||
#include <libdevcore/SHA3.h> |
|||
#include <libethcore/ProofOfWork.h> |
|||
#include <libethcore/EthashAux.h> |
|||
#include <libethcore/Farm.h> |
|||
#if ETH_JSONRPC || !ETH_TRUE |
|||
#include <libweb3jsonrpc/WebThreeStubServer.h> |
|||
#include <jsonrpccpp/server/connectors/httpserver.h> |
|||
#include <jsonrpccpp/client/connectors/httpclient.h> |
|||
#endif |
|||
#include "BuildInfo.h" |
|||
#if ETH_JSONRPC || !ETH_TRUE |
|||
#include "PhoneHome.h" |
|||
#include "Farm.h" |
|||
#endif |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
using namespace boost::algorithm; |
|||
using dev::eth::Instruction; |
|||
|
|||
#undef RETURN |
|||
|
|||
bool isTrue(std::string const& _m) |
|||
{ |
|||
return _m == "on" || _m == "yes" || _m == "true" || _m == "1"; |
|||
} |
|||
|
|||
bool isFalse(std::string const& _m) |
|||
{ |
|||
return _m == "off" || _m == "no" || _m == "false" || _m == "0"; |
|||
} |
|||
|
|||
inline std::string credits() |
|||
{ |
|||
std::ostringstream out; |
|||
out |
|||
<< "Ethereum (++) " << dev::Version << endl |
|||
<< " Code by Gav Wood et al, (c) 2013, 2014, 2015." << endl; |
|||
return out.str(); |
|||
} |
|||
|
|||
class BadArgument: public Exception {}; |
|||
|
|||
class MinerCLI |
|||
{ |
|||
public: |
|||
enum class OperationMode |
|||
{ |
|||
None, |
|||
DAGInit, |
|||
Benchmark, |
|||
Farm |
|||
}; |
|||
|
|||
MinerCLI(OperationMode _mode = OperationMode::None): mode(_mode) {} |
|||
|
|||
bool interpretOption(int& i, int argc, char** argv) |
|||
{ |
|||
string arg = argv[i]; |
|||
if ((arg == "-F" || arg == "--farm") && i + 1 < argc) |
|||
{ |
|||
mode = OperationMode::Farm; |
|||
m_farmURL = argv[++i]; |
|||
} |
|||
else if (arg == "--farm-recheck" && i + 1 < argc) |
|||
try { |
|||
m_farmRecheckPeriod = stol(argv[++i]); |
|||
} |
|||
catch (...) |
|||
{ |
|||
cerr << "Bad " << arg << " option: " << argv[i] << endl; |
|||
throw BadArgument(); |
|||
} |
|||
else if (arg == "--opencl-platform" && i + 1 < argc) |
|||
try { |
|||
m_openclPlatform = stol(argv[++i]); |
|||
} |
|||
catch (...) |
|||
{ |
|||
cerr << "Bad " << arg << " option: " << argv[i] << endl; |
|||
throw BadArgument(); |
|||
} |
|||
else if (arg == "--opencl-device" && i + 1 < argc) |
|||
try { |
|||
m_openclDevice = stol(argv[++i]); |
|||
m_miningThreads = 1; |
|||
} |
|||
catch (...) |
|||
{ |
|||
cerr << "Bad " << arg << " option: " << argv[i] << endl; |
|||
throw BadArgument(); |
|||
} |
|||
else if (arg == "--list-devices") |
|||
m_shouldListDevices = true; |
|||
else if (arg == "--allow-opencl-cpu") |
|||
m_clAllowCPU = true; |
|||
else if (arg == "--cl-extragpu-mem" && i + 1 < argc) |
|||
m_extraGPUMemory = 1000000 * stol(argv[++i]); |
|||
else if (arg == "--force-single-chunk") |
|||
m_forceSingleChunk = true; |
|||
else if (arg == "--phone-home" && i + 1 < argc) |
|||
{ |
|||
string m = argv[++i]; |
|||
if (isTrue(m)) |
|||
m_phoneHome = true; |
|||
else if (isFalse(m)) |
|||
m_phoneHome = false; |
|||
else |
|||
{ |
|||
cerr << "Bad " << arg << " option: " << m << endl; |
|||
throw BadArgument(); |
|||
} |
|||
} |
|||
else if (arg == "--benchmark-warmup" && i + 1 < argc) |
|||
try { |
|||
m_benchmarkWarmup = stol(argv[++i]); |
|||
} |
|||
catch (...) |
|||
{ |
|||
cerr << "Bad " << arg << " option: " << argv[i] << endl; |
|||
throw BadArgument(); |
|||
} |
|||
else if (arg == "--benchmark-trial" && i + 1 < argc) |
|||
try { |
|||
m_benchmarkTrial = stol(argv[++i]); |
|||
} |
|||
catch (...) |
|||
{ |
|||
cerr << "Bad " << arg << " option: " << argv[i] << endl; |
|||
throw BadArgument(); |
|||
} |
|||
else if (arg == "--benchmark-trials" && i + 1 < argc) |
|||
try { |
|||
m_benchmarkTrials = stol(argv[++i]); |
|||
} |
|||
catch (...) |
|||
{ |
|||
cerr << "Bad " << arg << " option: " << argv[i] << endl; |
|||
throw BadArgument(); |
|||
} |
|||
else if (arg == "-C" || arg == "--cpu") |
|||
m_minerType = MinerType::CPU; |
|||
else if (arg == "-G" || arg == "--opencl") |
|||
m_minerType = MinerType::GPU; |
|||
else if (arg == "--current-block" && i + 1 < argc) |
|||
m_currentBlock = stol(argv[++i]); |
|||
else if (arg == "--no-precompute") |
|||
{ |
|||
m_precompute = false; |
|||
} |
|||
else if ((arg == "-D" || arg == "--create-dag") && i + 1 < argc) |
|||
{ |
|||
string m = boost::to_lower_copy(string(argv[++i])); |
|||
mode = OperationMode::DAGInit; |
|||
try |
|||
{ |
|||
m_initDAG = stol(m); |
|||
} |
|||
catch (...) |
|||
{ |
|||
cerr << "Bad " << arg << " option: " << m << endl; |
|||
throw BadArgument(); |
|||
} |
|||
} |
|||
else if ((arg == "-w" || arg == "--check-pow") && i + 4 < argc) |
|||
{ |
|||
string m; |
|||
try |
|||
{ |
|||
BlockInfo bi; |
|||
m = boost::to_lower_copy(string(argv[++i])); |
|||
h256 powHash(m); |
|||
m = boost::to_lower_copy(string(argv[++i])); |
|||
h256 seedHash; |
|||
if (m.size() == 64 || m.size() == 66) |
|||
seedHash = h256(m); |
|||
else |
|||
seedHash = EthashAux::seedHash(stol(m)); |
|||
m = boost::to_lower_copy(string(argv[++i])); |
|||
bi.difficulty = u256(m); |
|||
auto boundary = bi.boundary(); |
|||
m = boost::to_lower_copy(string(argv[++i])); |
|||
bi.nonce = h64(m); |
|||
auto r = EthashAux::eval(bi.seedHash(), powHash, bi.nonce); |
|||
bool valid = r.value < boundary; |
|||
cout << (valid ? "VALID :-)" : "INVALID :-(") << endl; |
|||
cout << r.value << (valid ? " < " : " >= ") << boundary << endl; |
|||
cout << " where " << boundary << " = 2^256 / " << bi.difficulty << endl; |
|||
cout << " and " << r.value << " = ethash(" << powHash << ", " << bi.nonce << ")" << endl; |
|||
cout << " with seed as " << seedHash << endl; |
|||
if (valid) |
|||
cout << "(mixHash = " << r.mixHash << ")" << endl; |
|||
cout << "SHA3( light(seed) ) = " << sha3(EthashAux::light(bi.seedHash())->data()) << endl; |
|||
exit(0); |
|||
} |
|||
catch (...) |
|||
{ |
|||
cerr << "Bad " << arg << " option: " << m << endl; |
|||
throw BadArgument(); |
|||
} |
|||
} |
|||
else if (arg == "-M" || arg == "--benchmark") |
|||
mode = OperationMode::Benchmark; |
|||
else if ((arg == "-t" || arg == "--mining-threads") && i + 1 < argc) |
|||
{ |
|||
try { |
|||
m_miningThreads = stol(argv[++i]); |
|||
} |
|||
catch (...) |
|||
{ |
|||
cerr << "Bad " << arg << " option: " << argv[i] << endl; |
|||
throw BadArgument(); |
|||
} |
|||
} |
|||
else |
|||
return false; |
|||
return true; |
|||
} |
|||
|
|||
void execute() |
|||
{ |
|||
if (m_shouldListDevices) |
|||
{ |
|||
ProofOfWork::GPUMiner::listDevices(); |
|||
exit(0); |
|||
} |
|||
|
|||
if (m_minerType == MinerType::CPU) |
|||
ProofOfWork::CPUMiner::setNumInstances(m_miningThreads); |
|||
else if (m_minerType == MinerType::GPU) |
|||
{ |
|||
ProofOfWork::GPUMiner::setNumInstances(m_miningThreads); |
|||
if (!ProofOfWork::GPUMiner::configureGPU( |
|||
m_openclPlatform, |
|||
m_openclDevice, |
|||
m_clAllowCPU, |
|||
m_extraGPUMemory, |
|||
m_forceSingleChunk, |
|||
m_currentBlock |
|||
)) |
|||
{ |
|||
cout << "No GPU device with sufficient memory was found. Can't GPU mine. Remove the -G argument" << endl; |
|||
exit(1); |
|||
} |
|||
} |
|||
if (mode == OperationMode::DAGInit) |
|||
doInitDAG(m_initDAG); |
|||
else if (mode == OperationMode::Benchmark) |
|||
doBenchmark(m_minerType, m_phoneHome, m_benchmarkWarmup, m_benchmarkTrial, m_benchmarkTrials); |
|||
else if (mode == OperationMode::Farm) |
|||
doFarm(m_minerType, m_farmURL, m_farmRecheckPeriod); |
|||
} |
|||
|
|||
static void streamHelp(ostream& _out) |
|||
{ |
|||
_out |
|||
#if ETH_JSONRPC || !ETH_TRUE |
|||
<< "Work farming mode:" << endl |
|||
<< " -F,--farm <url> Put into mining farm mode with the work server at URL (default: http://127.0.0.1:8545)" << endl |
|||
<< " --farm-recheck <n> Leave n ms between checks for changed work (default: 500)." << endl |
|||
<< " --no-precompute Don't precompute the next epoch's DAG." << endl |
|||
#endif |
|||
<< "Ethash verify mode:" << endl |
|||
<< " -w,--check-pow <headerHash> <seedHash> <difficulty> <nonce> Check PoW credentials for validity." << endl |
|||
<< endl |
|||
<< "Benchmarking mode:" << endl |
|||
<< " -M,--benchmark Benchmark for mining and exit; use with --cpu and --opencl." << endl |
|||
<< " --benchmark-warmup <seconds> Set the duration of warmup for the benchmark tests (default: 3)." << endl |
|||
<< " --benchmark-trial <seconds> Set the duration for each trial for the benchmark tests (default: 3)." << endl |
|||
<< " --benchmark-trials <n> Set the duration of warmup for the benchmark tests (default: 5)." << endl |
|||
#if ETH_JSONRPC || !ETH_TRUE |
|||
<< " --phone-home <on/off> When benchmarking, publish results (default: on)" << endl |
|||
#endif |
|||
<< "DAG creation mode:" << endl |
|||
<< " -D,--create-dag <number> Create the DAG in preparation for mining on given block and exit." << endl |
|||
<< "Mining configuration:" << endl |
|||
<< " -C,--cpu When mining, use the CPU." << endl |
|||
<< " -G,--opencl When mining use the GPU via OpenCL." << endl |
|||
<< " --opencl-platform <n> When mining using -G/--opencl use OpenCL platform n (default: 0)." << endl |
|||
<< " --opencl-device <n> When mining using -G/--opencl use OpenCL device n (default: 0)." << endl |
|||
<< " -t, --mining-threads <n> Limit number of CPU/GPU miners to n (default: use everything available on selected platform)" << endl |
|||
<< " --allow-opencl-cpu Allows CPU to be considered as an OpenCL device if the OpenCL platform supports it." << endl |
|||
<< " --list-devices List the detected OpenCL devices and exit." <<endl |
|||
<< " --current-block Let the miner know the current block number at configuration time. Will help determine DAG size and required GPU memory." <<endl |
|||
<< " --cl-extragpu-mem Set the memory (in MB) you believe your GPU requires for stuff other than mining. Windows rendering e.t.c.." <<endl |
|||
<< " --force-single-chunk Force DAG uploading in a single chunk against OpenCL's judgement. Use at your own risk." <<endl |
|||
; |
|||
} |
|||
|
|||
enum class MinerType |
|||
{ |
|||
CPU, |
|||
GPU |
|||
}; |
|||
|
|||
MinerType minerType() const { return m_minerType; } |
|||
|
|||
private: |
|||
void doInitDAG(unsigned _n) |
|||
{ |
|||
BlockInfo bi; |
|||
bi.number = _n; |
|||
cout << "Initializing DAG for epoch beginning #" << (bi.number / 30000 * 30000) << " (seedhash " << bi.seedHash().abridged() << "). This will take a while." << endl; |
|||
Ethash::prep(bi); |
|||
exit(0); |
|||
} |
|||
|
|||
void doBenchmark(MinerType _m, bool _phoneHome, unsigned _warmupDuration = 15, unsigned _trialDuration = 3, unsigned _trials = 5) |
|||
{ |
|||
BlockInfo genesis; |
|||
genesis.difficulty = 1 << 18; |
|||
cdebug << genesis.boundary(); |
|||
|
|||
GenericFarm<Ethash> f; |
|||
f.onSolutionFound([&](ProofOfWork::Solution) { return false; }); |
|||
|
|||
string platformInfo = _m == MinerType::CPU ? ProofOfWork::CPUMiner::platformInfo() : _m == MinerType::GPU ? ProofOfWork::GPUMiner::platformInfo() : ""; |
|||
cout << "Benchmarking on platform: " << platformInfo << endl; |
|||
|
|||
cout << "Preparing DAG..." << endl; |
|||
Ethash::prep(genesis); |
|||
|
|||
genesis.difficulty = u256(1) << 63; |
|||
genesis.noteDirty(); |
|||
f.setWork(genesis); |
|||
if (_m == MinerType::CPU) |
|||
f.startCPU(); |
|||
else if (_m == MinerType::GPU) |
|||
f.startGPU(); |
|||
|
|||
map<uint64_t, MiningProgress> results; |
|||
uint64_t mean = 0; |
|||
uint64_t innerMean = 0; |
|||
for (unsigned i = 0; i <= _trials; ++i) |
|||
{ |
|||
if (!i) |
|||
cout << "Warming up..." << endl; |
|||
else |
|||
cout << "Trial " << i << "... " << flush; |
|||
this_thread::sleep_for(chrono::seconds(i ? _trialDuration : _warmupDuration)); |
|||
|
|||
auto mp = f.miningProgress(); |
|||
f.resetMiningProgress(); |
|||
if (!i) |
|||
continue; |
|||
auto rate = mp.rate(); |
|||
|
|||
cout << rate << endl; |
|||
results[rate] = mp; |
|||
mean += rate; |
|||
} |
|||
f.stop(); |
|||
int j = -1; |
|||
for (auto const& r: results) |
|||
if (++j > 0 && j < (int)_trials - 1) |
|||
innerMean += r.second.rate(); |
|||
innerMean /= (_trials - 2); |
|||
cout << "min/mean/max: " << results.begin()->second.rate() << "/" << (mean / _trials) << "/" << results.rbegin()->second.rate() << " H/s" << endl; |
|||
cout << "inner mean: " << innerMean << " H/s" << endl; |
|||
|
|||
(void)_phoneHome; |
|||
#if ETH_JSONRPC || !ETH_TRUE |
|||
if (_phoneHome) |
|||
{ |
|||
cout << "Phoning home to find world ranking..." << endl; |
|||
jsonrpc::HttpClient client("http://gav.ethdev.com:3000"); |
|||
PhoneHome rpc(client); |
|||
try |
|||
{ |
|||
unsigned ranking = rpc.report_benchmark(platformInfo, innerMean); |
|||
cout << "Ranked: " << ranking << " of all benchmarks." << endl; |
|||
} |
|||
catch (...) |
|||
{ |
|||
cout << "Error phoning home. ET is sad." << endl; |
|||
} |
|||
} |
|||
#endif |
|||
exit(0); |
|||
} |
|||
|
|||
void doFarm(MinerType _m, string const& _remote, unsigned _recheckPeriod) |
|||
{ |
|||
(void)_m; |
|||
(void)_remote; |
|||
(void)_recheckPeriod; |
|||
#if ETH_JSONRPC || !ETH_TRUE |
|||
jsonrpc::HttpClient client(_remote); |
|||
|
|||
Farm rpc(client); |
|||
GenericFarm<Ethash> f; |
|||
if (_m == MinerType::CPU) |
|||
f.startCPU(); |
|||
else if (_m == MinerType::GPU) |
|||
f.startGPU(); |
|||
|
|||
ProofOfWork::WorkPackage current; |
|||
EthashAux::FullType dag; |
|||
while (true) |
|||
try |
|||
{ |
|||
bool completed = false; |
|||
ProofOfWork::Solution solution; |
|||
f.onSolutionFound([&](ProofOfWork::Solution sol) |
|||
{ |
|||
solution = sol; |
|||
return completed = true; |
|||
}); |
|||
for (unsigned i = 0; !completed; ++i) |
|||
{ |
|||
if (current) |
|||
cnote << "Mining on PoWhash" << current.headerHash << ": " << f.miningProgress(); |
|||
else |
|||
cnote << "Getting work package..."; |
|||
Json::Value v = rpc.eth_getWork(); |
|||
h256 hh(v[0].asString()); |
|||
h256 newSeedHash(v[1].asString()); |
|||
if (current.seedHash != newSeedHash) |
|||
cnote << "Grabbing DAG for" << newSeedHash; |
|||
if (!(dag = EthashAux::full(newSeedHash, true, [&](unsigned _pc){ cout << "\rCreating DAG. " << _pc << "% done..." << flush; return 0; }))) |
|||
BOOST_THROW_EXCEPTION(DAGCreationFailure()); |
|||
if (m_precompute) |
|||
EthashAux::computeFull(sha3(newSeedHash), true); |
|||
if (hh != current.headerHash) |
|||
{ |
|||
current.headerHash = hh; |
|||
current.seedHash = newSeedHash; |
|||
current.boundary = h256(fromHex(v[2].asString()), h256::AlignRight); |
|||
cnote << "Got work package:"; |
|||
cnote << " Header-hash:" << current.headerHash.hex(); |
|||
cnote << " Seedhash:" << current.seedHash.hex(); |
|||
cnote << " Target: " << h256(current.boundary).hex(); |
|||
f.setWork(current); |
|||
} |
|||
this_thread::sleep_for(chrono::milliseconds(_recheckPeriod)); |
|||
} |
|||
cnote << "Solution found; Submitting to" << _remote << "..."; |
|||
cnote << " Nonce:" << solution.nonce.hex(); |
|||
cnote << " Mixhash:" << solution.mixHash.hex(); |
|||
cnote << " Header-hash:" << current.headerHash.hex(); |
|||
cnote << " Seedhash:" << current.seedHash.hex(); |
|||
cnote << " Target: " << h256(current.boundary).hex(); |
|||
cnote << " Ethash: " << h256(EthashAux::eval(current.seedHash, current.headerHash, solution.nonce).value).hex(); |
|||
if (EthashAux::eval(current.seedHash, current.headerHash, solution.nonce).value < current.boundary) |
|||
{ |
|||
bool ok = rpc.eth_submitWork("0x" + toString(solution.nonce), "0x" + toString(current.headerHash), "0x" + toString(solution.mixHash)); |
|||
if (ok) |
|||
cnote << "B-) Submitted and accepted."; |
|||
else |
|||
cwarn << ":-( Not accepted."; |
|||
} |
|||
else |
|||
cwarn << "FAILURE: GPU gave incorrect result!"; |
|||
current.reset(); |
|||
} |
|||
catch (jsonrpc::JsonRpcException&) |
|||
{ |
|||
for (auto i = 3; --i; this_thread::sleep_for(chrono::seconds(1))) |
|||
cerr << "JSON-RPC problem. Probably couldn't connect. Retrying in " << i << "... \r"; |
|||
cerr << endl; |
|||
} |
|||
#endif |
|||
exit(0); |
|||
} |
|||
|
|||
/// Operating mode.
|
|||
OperationMode mode; |
|||
|
|||
/// Mining options
|
|||
MinerType m_minerType = MinerType::CPU; |
|||
unsigned m_openclPlatform = 0; |
|||
unsigned m_openclDevice = 0; |
|||
unsigned m_miningThreads = UINT_MAX; |
|||
bool m_shouldListDevices = false; |
|||
bool m_clAllowCPU = false; |
|||
bool m_forceSingleChunk = false; |
|||
boost::optional<uint64_t> m_currentBlock; |
|||
// default value is 350MB of GPU memory for other stuff (windows system rendering, e.t.c.)
|
|||
unsigned m_extraGPUMemory = 350000000; |
|||
|
|||
/// DAG initialisation param.
|
|||
unsigned m_initDAG = 0; |
|||
|
|||
/// Benchmarking params
|
|||
bool m_phoneHome = true; |
|||
unsigned m_benchmarkWarmup = 3; |
|||
unsigned m_benchmarkTrial = 3; |
|||
unsigned m_benchmarkTrials = 5; |
|||
|
|||
/// Farm params
|
|||
string m_farmURL = "http://127.0.0.1:8545"; |
|||
unsigned m_farmRecheckPeriod = 500; |
|||
bool m_precompute = true; |
|||
}; |
@ -0,0 +1,28 @@ |
|||
/**
|
|||
* This file is generated by jsonrpcstub, DO NOT CHANGE IT MANUALLY! |
|||
*/ |
|||
|
|||
#ifndef JSONRPC_CPP_STUB_PHONEHOME_H_ |
|||
#define JSONRPC_CPP_STUB_PHONEHOME_H_ |
|||
|
|||
#include <jsonrpccpp/client.h> |
|||
|
|||
class PhoneHome : public jsonrpc::Client |
|||
{ |
|||
public: |
|||
PhoneHome(jsonrpc::IClientConnector &conn, jsonrpc::clientVersion_t type = jsonrpc::JSONRPC_CLIENT_V2) : jsonrpc::Client(conn, type) {} |
|||
|
|||
int report_benchmark(const std::string& param1, int param2) throw (jsonrpc::JsonRpcException) |
|||
{ |
|||
Json::Value p; |
|||
p.append(param1); |
|||
p.append(param2); |
|||
Json::Value result = this->CallMethod("report_benchmark",p); |
|||
if (result.isInt()) |
|||
return result.asInt(); |
|||
else |
|||
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); |
|||
} |
|||
}; |
|||
|
|||
#endif //JSONRPC_CPP_STUB_PHONEHOME_H_
|
@ -0,0 +1,6 @@ |
|||
[ |
|||
{ "name": "eth_getWork", "params": [], "order": [], "returns": []}, |
|||
{ "name": "eth_submitWork", "params": ["", "", ""], "order": [], "returns": true} |
|||
{ "name": "eth_awaitNewWork", "params": [], "order": [], "returns": []}, |
|||
{ "name": "eth_progress", "params": [], "order": [], "returns": true} |
|||
] |
@ -0,0 +1,87 @@ |
|||
/*
|
|||
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. |
|||
|
|||
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file main.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
* Ethereum client. |
|||
*/ |
|||
|
|||
#include <thread> |
|||
#include <chrono> |
|||
#include <fstream> |
|||
#include <iostream> |
|||
#include <signal.h> |
|||
#include <boost/algorithm/string.hpp> |
|||
#include <boost/algorithm/string/trim_all.hpp> |
|||
#include <libdevcore/FileSystem.h> |
|||
#include "MinerAux.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
using namespace boost::algorithm; |
|||
|
|||
#undef RETURN |
|||
|
|||
void help() |
|||
{ |
|||
cout |
|||
<< "Usage ethminer [OPTIONS]" << endl |
|||
<< "Options:" << endl << endl; |
|||
MinerCLI::streamHelp(cout); |
|||
cout |
|||
<< "General Options:" << endl |
|||
<< " -v,--verbosity <0 - 9> Set the log verbosity from 0 to 9 (default: 8)." << endl |
|||
<< " -V,--version Show the version and exit." << endl |
|||
<< " -h,--help Show this help message and exit." << endl |
|||
; |
|||
exit(0); |
|||
} |
|||
|
|||
void version() |
|||
{ |
|||
cout << "ethminer version " << dev::Version << endl; |
|||
cout << "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << endl; |
|||
exit(0); |
|||
} |
|||
|
|||
int main(int argc, char** argv) |
|||
{ |
|||
MinerCLI m(MinerCLI::OperationMode::Farm); |
|||
|
|||
for (int i = 1; i < argc; ++i) |
|||
{ |
|||
string arg = argv[i]; |
|||
if (m.interpretOption(i, argc, argv)) |
|||
{} |
|||
else if ((arg == "-v" || arg == "--verbosity") && i + 1 < argc) |
|||
g_logVerbosity = atoi(argv[++i]); |
|||
else if (arg == "-h" || arg == "--help") |
|||
help(); |
|||
else if (arg == "-V" || arg == "--version") |
|||
version(); |
|||
else |
|||
{ |
|||
cerr << "Invalid argument: " << arg << endl; |
|||
exit(-1); |
|||
} |
|||
} |
|||
|
|||
m.execute(); |
|||
|
|||
return 0; |
|||
} |
|||
|
@ -0,0 +1,3 @@ |
|||
[ |
|||
{ "name": "report_benchmark", "params": [ "", 0 ], "order": [], "returns": 0 } |
|||
] |
@ -0,0 +1,19 @@ |
|||
cmake_policy(SET CMP0015 NEW) |
|||
set(CMAKE_AUTOMOC OFF) |
|||
|
|||
aux_source_directory(. SRC_LIST) |
|||
|
|||
include_directories(BEFORE ..) |
|||
include_directories(${LEVELDB_INCLUDE_DIRS}) |
|||
|
|||
set(EXECUTABLE ethvm) |
|||
|
|||
add_executable(${EXECUTABLE} ${SRC_LIST}) |
|||
|
|||
target_link_libraries(${EXECUTABLE} ethereum) |
|||
|
|||
if (APPLE) |
|||
install(TARGETS ${EXECUTABLE} DESTINATION bin) |
|||
else() |
|||
eth_install_executable(${EXECUTABLE}) |
|||
endif() |
@ -0,0 +1,200 @@ |
|||
/*
|
|||
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. |
|||
|
|||
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file main.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
* EVM Execution tool. |
|||
*/ |
|||
#include <fstream> |
|||
#include <iostream> |
|||
#include <boost/algorithm/string.hpp> |
|||
#include <libdevcore/CommonIO.h> |
|||
#include <libdevcore/RLP.h> |
|||
#include <libdevcore/SHA3.h> |
|||
#include <libethereum/State.h> |
|||
#include <libethereum/Executive.h> |
|||
#include <libevm/VM.h> |
|||
#include <libevm/VMFactory.h> |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace eth; |
|||
|
|||
void help() |
|||
{ |
|||
cout |
|||
<< "Usage ethvm <options> [trace|stats|output] (<file>|--)" << endl |
|||
<< "Transaction options:" << endl |
|||
<< " --value <n> Transaction should transfer the <n> wei (default: 0)." << endl |
|||
<< " --gas <n> Transaction should be given <n> gas (default: block gas limit)." << endl |
|||
<< " --gas-price <n> Transaction's gas price' should be <n> (default: 0)." << endl |
|||
<< " --sender <a> Transaction sender should be <a> (default: 0000...0069)." << endl |
|||
<< " --origin <a> Transaction origin should be <a> (default: 0000...0069)." << endl |
|||
#if ETH_EVMJIT || !ETH_TRUE |
|||
<< endl |
|||
<< "VM options:" << endl |
|||
<< " -J,--jit Enable LLVM VM (default: off)." << endl |
|||
<< " --smart Enable smart VM (default: off)." << endl |
|||
#endif |
|||
<< endl |
|||
<< "Options for trace:" << endl |
|||
<< " --flat Minimal whitespace in the JSON." << endl |
|||
<< " --mnemonics Show instruction mnemonics in the trace (non-standard)." << endl |
|||
<< endl |
|||
<< "General options:" << endl |
|||
<< " -V,--version Show the version and exit." << endl |
|||
<< " -h,--help Show this help message and exit." << endl; |
|||
exit(0); |
|||
} |
|||
|
|||
void version() |
|||
{ |
|||
cout << "ethvm version " << dev::Version << endl; |
|||
cout << "By Gav Wood, 2015." << endl; |
|||
cout << "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << endl; |
|||
exit(0); |
|||
} |
|||
|
|||
enum class Mode |
|||
{ |
|||
Trace, |
|||
Statistics, |
|||
OutputOnly |
|||
}; |
|||
|
|||
int main(int argc, char** argv) |
|||
{ |
|||
string incoming = "--"; |
|||
|
|||
Mode mode = Mode::Statistics; |
|||
State state; |
|||
Address sender = Address(69); |
|||
Address origin = Address(69); |
|||
u256 value = 0; |
|||
u256 gas = state.gasLimitRemaining(); |
|||
u256 gasPrice = 0; |
|||
bool styledJson = true; |
|||
StandardTrace st; |
|||
|
|||
for (int i = 1; i < argc; ++i) |
|||
{ |
|||
string arg = argv[i]; |
|||
if (arg == "-h" || arg == "--help") |
|||
help(); |
|||
else if (arg == "-V" || arg == "--version") |
|||
version(); |
|||
#if ETH_EVMJIT |
|||
else if (arg == "-J" || arg == "--jit") |
|||
VMFactory::setKind(VMKind::JIT); |
|||
else if (arg == "--smart") |
|||
VMFactory::setKind(VMKind::Smart); |
|||
#endif |
|||
else if (arg == "--mnemonics") |
|||
st.setShowMnemonics(); |
|||
else if (arg == "--flat") |
|||
styledJson = false; |
|||
else if (arg == "--value" && i + 1 < argc) |
|||
value = u256(argv[++i]); |
|||
else if (arg == "--sender" && i + 1 < argc) |
|||
sender = Address(argv[++i]); |
|||
else if (arg == "--origin" && i + 1 < argc) |
|||
origin = Address(argv[++i]); |
|||
else if (arg == "--gas" && i + 1 < argc) |
|||
gas = u256(argv[++i]); |
|||
else if (arg == "--gas-price" && i + 1 < argc) |
|||
gasPrice = u256(argv[++i]); |
|||
else if (arg == "--value" && i + 1 < argc) |
|||
value = u256(argv[++i]); |
|||
else if (arg == "--value" && i + 1 < argc) |
|||
value = u256(argv[++i]); |
|||
else if (arg == "stats") |
|||
mode = Mode::Statistics; |
|||
else if (arg == "output") |
|||
mode = Mode::OutputOnly; |
|||
else if (arg == "trace") |
|||
mode = Mode::Trace; |
|||
else |
|||
incoming = arg; |
|||
} |
|||
|
|||
bytes code; |
|||
if (incoming == "--" || incoming.empty()) |
|||
for (int i = cin.get(); i != -1; i = cin.get()) |
|||
code.push_back((char)i); |
|||
else |
|||
code = contents(incoming); |
|||
bytes data = fromHex(boost::trim_copy(asString(code))); |
|||
if (data.empty()) |
|||
data = code; |
|||
|
|||
state.addBalance(sender, value); |
|||
Executive executive(state, eth::LastHashes(), 0); |
|||
ExecutionResult res; |
|||
executive.setResultRecipient(res); |
|||
Transaction t = eth::Transaction(value, gasPrice, gas, data, 0); |
|||
t.forceSender(sender); |
|||
|
|||
unordered_map<byte, pair<unsigned, bigint>> counts; |
|||
unsigned total = 0; |
|||
bigint memTotal; |
|||
auto onOp = [&](uint64_t step, Instruction inst, bigint m, bigint gasCost, bigint gas, VM* vm, ExtVMFace const* extVM) { |
|||
if (mode == Mode::Statistics) |
|||
{ |
|||
counts[(byte)inst].first++; |
|||
counts[(byte)inst].second += gasCost; |
|||
total++; |
|||
if (m > 0) |
|||
memTotal = m; |
|||
} |
|||
else if (mode == Mode::Trace) |
|||
st(step, inst, m, gasCost, gas, vm, extVM); |
|||
}; |
|||
|
|||
executive.initialize(t); |
|||
executive.create(sender, value, gasPrice, gas, &data, origin); |
|||
boost::timer timer; |
|||
executive.go(onOp); |
|||
double execTime = timer.elapsed(); |
|||
executive.finalize(); |
|||
bytes output = std::move(res.output); |
|||
|
|||
if (mode == Mode::Statistics) |
|||
{ |
|||
cout << "Gas used: " << res.gasUsed << " (+" << t.gasRequired() << " for transaction, -" << res.gasRefunded << " refunded)" << endl; |
|||
cout << "Output: " << toHex(output) << endl; |
|||
LogEntries logs = executive.logs(); |
|||
cout << logs.size() << " logs" << (logs.empty() ? "." : ":") << endl; |
|||
for (LogEntry const& l: logs) |
|||
{ |
|||
cout << " " << l.address.hex() << ": " << toHex(t.data()) << endl; |
|||
for (h256 const& t: l.topics) |
|||
cout << " " << t.hex() << endl; |
|||
} |
|||
|
|||
cout << total << " operations in " << execTime << " seconds." << endl; |
|||
cout << "Maximum memory usage: " << memTotal * 32 << " bytes" << endl; |
|||
cout << "Expensive operations:" << endl; |
|||
for (auto const& c: {Instruction::SSTORE, Instruction::SLOAD, Instruction::CALL, Instruction::CREATE, Instruction::CALLCODE, Instruction::MSTORE8, Instruction::MSTORE, Instruction::MLOAD, Instruction::SHA3}) |
|||
if (!!counts[(byte)c].first) |
|||
cout << " " << instructionInfo(c).name << " x " << counts[(byte)c].first << " (" << counts[(byte)c].second << " gas)" << endl; |
|||
} |
|||
else if (mode == Mode::Trace) |
|||
cout << st.json(styledJson); |
|||
else if (mode == Mode::OutputOnly) |
|||
cout << toHex(output); |
|||
|
|||
return 0; |
|||
} |
@ -0,0 +1,56 @@ |
|||
#pragma once |
|||
|
|||
#include <cstdint> |
|||
#include <functional> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace evmjit |
|||
{ |
|||
|
|||
struct h256 |
|||
{ |
|||
uint64_t words[4]; |
|||
}; |
|||
|
|||
inline bool operator==(h256 _h1, h256 _h2) |
|||
{ |
|||
return _h1.words[0] == _h2.words[0] && |
|||
_h1.words[1] == _h2.words[1] && |
|||
_h1.words[2] == _h2.words[2] && |
|||
_h1.words[3] == _h2.words[3]; |
|||
} |
|||
|
|||
/// Representation of 256-bit value binary compatible with LLVM i256
|
|||
struct i256 |
|||
{ |
|||
uint64_t a = 0; |
|||
uint64_t b = 0; |
|||
uint64_t c = 0; |
|||
uint64_t d = 0; |
|||
|
|||
i256() = default; |
|||
i256(h256 _h) |
|||
{ |
|||
a = _h.words[0]; |
|||
b = _h.words[1]; |
|||
c = _h.words[2]; |
|||
d = _h.words[3]; |
|||
} |
|||
}; |
|||
|
|||
} |
|||
} |
|||
|
|||
namespace std |
|||
{ |
|||
template<> struct hash<dev::evmjit::h256> |
|||
{ |
|||
size_t operator()(dev::evmjit::h256 const& _h) const |
|||
{ |
|||
/// This implementation expects the argument to be a full 256-bit Keccak hash.
|
|||
/// It does nothing more than returning a slice of the input hash.
|
|||
return static_cast<size_t>(_h.words[0]); |
|||
}; |
|||
}; |
|||
} |
@ -0,0 +1,36 @@ |
|||
#pragma once |
|||
|
|||
#include "evmjit/DataTypes.h" |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
namespace jit |
|||
{ |
|||
class ExecutionEngine; |
|||
} |
|||
} |
|||
|
|||
namespace evmjit |
|||
{ |
|||
|
|||
class JIT |
|||
{ |
|||
public: |
|||
|
|||
/// Ask JIT if the EVM code is ready for execution.
|
|||
/// Returns `true` if the EVM code has been compiled and loaded into memory.
|
|||
/// In this case the code can be executed without overhead.
|
|||
/// \param _codeHash The Keccak hash of the EVM code.
|
|||
static bool isCodeReady(h256 _codeHash); |
|||
|
|||
private: |
|||
friend class dev::eth::jit::ExecutionEngine; |
|||
|
|||
static uint64_t getCode(h256 _codeHash); |
|||
static void mapCode(h256 _codeHash, uint64_t _funcAddr); |
|||
}; |
|||
|
|||
} |
|||
} |
@ -0,0 +1,46 @@ |
|||
#include "evmjit/JIT.h" |
|||
|
|||
#include <unordered_map> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace evmjit |
|||
{ |
|||
namespace |
|||
{ |
|||
|
|||
class JITImpl: JIT |
|||
{ |
|||
public: |
|||
std::unordered_map<h256, uint64_t> codeMap; |
|||
|
|||
static JITImpl& instance() |
|||
{ |
|||
static JITImpl s_instance; |
|||
return s_instance; |
|||
} |
|||
}; |
|||
|
|||
} // anonymous namespace
|
|||
|
|||
bool JIT::isCodeReady(h256 _codeHash) |
|||
{ |
|||
return JITImpl::instance().codeMap.count(_codeHash) != 0; |
|||
} |
|||
|
|||
uint64_t JIT::getCode(h256 _codeHash) |
|||
{ |
|||
auto& codeMap = JITImpl::instance().codeMap; |
|||
auto it = codeMap.find(_codeHash); |
|||
if (it != codeMap.end()) |
|||
return it->second; |
|||
return 0; |
|||
} |
|||
|
|||
void JIT::mapCode(h256 _codeHash, uint64_t _funcAddr) |
|||
{ |
|||
JITImpl::instance().codeMap.insert(std::make_pair(_codeHash, _funcAddr)); |
|||
} |
|||
|
|||
} |
|||
} |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 34 KiB |
@ -0,0 +1,440 @@ |
|||
/*
|
|||
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. |
|||
|
|||
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file Hash.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "Hash.h" |
|||
#include <cstdio> |
|||
#include <cstdlib> |
|||
#include <cstring> |
|||
#include "picosha2.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
|
|||
namespace dev |
|||
{ |
|||
|
|||
h256 sha256(bytesConstRef _input) |
|||
{ |
|||
h256 ret; |
|||
picosha2::hash256(_input.begin(), _input.end(), ret.data(), ret.data() + 32); |
|||
return ret; |
|||
} |
|||
|
|||
namespace rmd160 |
|||
{ |
|||
|
|||
/********************************************************************\
|
|||
* |
|||
* FILE: rmd160.h |
|||
* FILE: rmd160.c |
|||
* |
|||
* CONTENTS: Header file for a sample C-implementation of the |
|||
* RIPEMD-160 hash-function. |
|||
* TARGET: any computer with an ANSI C compiler |
|||
* |
|||
* AUTHOR: Antoon Bosselaers, ESAT-COSIC |
|||
* DATE: 1 March 1996 |
|||
* VERSION: 1.0 |
|||
* |
|||
* Copyright (c) Katholieke Universiteit Leuven |
|||
* 1996, All Rights Reserved |
|||
* |
|||
\********************************************************************/ |
|||
|
|||
// Adapted into "header-only" format by Gav Wood.
|
|||
|
|||
/* macro definitions */ |
|||
|
|||
#define RMDsize 160 |
|||
|
|||
/* collect four bytes into one word: */ |
|||
#define BYTES_TO_DWORD(strptr) \ |
|||
(((uint32_t) *((strptr)+3) << 24) | \ |
|||
((uint32_t) *((strptr)+2) << 16) | \ |
|||
((uint32_t) *((strptr)+1) << 8) | \ |
|||
((uint32_t) *(strptr))) |
|||
|
|||
/* ROL(x, n) cyclically rotates x over n bits to the left */ |
|||
/* x must be of an unsigned 32 bits type and 0 <= n < 32. */ |
|||
#define ROL(x, n) (((x) << (n)) | ((x) >> (32-(n)))) |
|||
|
|||
/* the five basic functions F(), G() and H() */ |
|||
#define F(x, y, z) ((x) ^ (y) ^ (z)) |
|||
#define G(x, y, z) (((x) & (y)) | (~(x) & (z))) |
|||
#define H(x, y, z) (((x) | ~(y)) ^ (z)) |
|||
#define I(x, y, z) (((x) & (z)) | ((y) & ~(z))) |
|||
#define J(x, y, z) ((x) ^ ((y) | ~(z))) |
|||
|
|||
/* the ten basic operations FF() through III() */ |
|||
#define FF(a, b, c, d, e, x, s) {\ |
|||
(a) += F((b), (c), (d)) + (x);\ |
|||
(a) = ROL((a), (s)) + (e);\ |
|||
(c) = ROL((c), 10);\ |
|||
} |
|||
#define GG(a, b, c, d, e, x, s) {\ |
|||
(a) += G((b), (c), (d)) + (x) + 0x5a827999UL;\ |
|||
(a) = ROL((a), (s)) + (e);\ |
|||
(c) = ROL((c), 10);\ |
|||
} |
|||
#define HH(a, b, c, d, e, x, s) {\ |
|||
(a) += H((b), (c), (d)) + (x) + 0x6ed9eba1UL;\ |
|||
(a) = ROL((a), (s)) + (e);\ |
|||
(c) = ROL((c), 10);\ |
|||
} |
|||
#define II(a, b, c, d, e, x, s) {\ |
|||
(a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcUL;\ |
|||
(a) = ROL((a), (s)) + (e);\ |
|||
(c) = ROL((c), 10);\ |
|||
} |
|||
#define JJ(a, b, c, d, e, x, s) {\ |
|||
(a) += J((b), (c), (d)) + (x) + 0xa953fd4eUL;\ |
|||
(a) = ROL((a), (s)) + (e);\ |
|||
(c) = ROL((c), 10);\ |
|||
} |
|||
#define FFF(a, b, c, d, e, x, s) {\ |
|||
(a) += F((b), (c), (d)) + (x);\ |
|||
(a) = ROL((a), (s)) + (e);\ |
|||
(c) = ROL((c), 10);\ |
|||
} |
|||
#define GGG(a, b, c, d, e, x, s) {\ |
|||
(a) += G((b), (c), (d)) + (x) + 0x7a6d76e9UL;\ |
|||
(a) = ROL((a), (s)) + (e);\ |
|||
(c) = ROL((c), 10);\ |
|||
} |
|||
#define HHH(a, b, c, d, e, x, s) {\ |
|||
(a) += H((b), (c), (d)) + (x) + 0x6d703ef3UL;\ |
|||
(a) = ROL((a), (s)) + (e);\ |
|||
(c) = ROL((c), 10);\ |
|||
} |
|||
#define III(a, b, c, d, e, x, s) {\ |
|||
(a) += I((b), (c), (d)) + (x) + 0x5c4dd124UL;\ |
|||
(a) = ROL((a), (s)) + (e);\ |
|||
(c) = ROL((c), 10);\ |
|||
} |
|||
#define JJJ(a, b, c, d, e, x, s) {\ |
|||
(a) += J((b), (c), (d)) + (x) + 0x50a28be6UL;\ |
|||
(a) = ROL((a), (s)) + (e);\ |
|||
(c) = ROL((c), 10);\ |
|||
} |
|||
|
|||
void MDinit(uint32_t *MDbuf) |
|||
{ |
|||
MDbuf[0] = 0x67452301UL; |
|||
MDbuf[1] = 0xefcdab89UL; |
|||
MDbuf[2] = 0x98badcfeUL; |
|||
MDbuf[3] = 0x10325476UL; |
|||
MDbuf[4] = 0xc3d2e1f0UL; |
|||
|
|||
return; |
|||
} |
|||
|
|||
/********************************************************************/ |
|||
|
|||
void MDcompress(uint32_t *MDbuf, uint32_t *X) |
|||
{ |
|||
uint32_t aa = MDbuf[0], bb = MDbuf[1], cc = MDbuf[2], |
|||
dd = MDbuf[3], ee = MDbuf[4]; |
|||
uint32_t aaa = MDbuf[0], bbb = MDbuf[1], ccc = MDbuf[2], |
|||
ddd = MDbuf[3], eee = MDbuf[4]; |
|||
|
|||
/* round 1 */ |
|||
FF(aa, bb, cc, dd, ee, X[ 0], 11); |
|||
FF(ee, aa, bb, cc, dd, X[ 1], 14); |
|||
FF(dd, ee, aa, bb, cc, X[ 2], 15); |
|||
FF(cc, dd, ee, aa, bb, X[ 3], 12); |
|||
FF(bb, cc, dd, ee, aa, X[ 4], 5); |
|||
FF(aa, bb, cc, dd, ee, X[ 5], 8); |
|||
FF(ee, aa, bb, cc, dd, X[ 6], 7); |
|||
FF(dd, ee, aa, bb, cc, X[ 7], 9); |
|||
FF(cc, dd, ee, aa, bb, X[ 8], 11); |
|||
FF(bb, cc, dd, ee, aa, X[ 9], 13); |
|||
FF(aa, bb, cc, dd, ee, X[10], 14); |
|||
FF(ee, aa, bb, cc, dd, X[11], 15); |
|||
FF(dd, ee, aa, bb, cc, X[12], 6); |
|||
FF(cc, dd, ee, aa, bb, X[13], 7); |
|||
FF(bb, cc, dd, ee, aa, X[14], 9); |
|||
FF(aa, bb, cc, dd, ee, X[15], 8); |
|||
|
|||
/* round 2 */ |
|||
GG(ee, aa, bb, cc, dd, X[ 7], 7); |
|||
GG(dd, ee, aa, bb, cc, X[ 4], 6); |
|||
GG(cc, dd, ee, aa, bb, X[13], 8); |
|||
GG(bb, cc, dd, ee, aa, X[ 1], 13); |
|||
GG(aa, bb, cc, dd, ee, X[10], 11); |
|||
GG(ee, aa, bb, cc, dd, X[ 6], 9); |
|||
GG(dd, ee, aa, bb, cc, X[15], 7); |
|||
GG(cc, dd, ee, aa, bb, X[ 3], 15); |
|||
GG(bb, cc, dd, ee, aa, X[12], 7); |
|||
GG(aa, bb, cc, dd, ee, X[ 0], 12); |
|||
GG(ee, aa, bb, cc, dd, X[ 9], 15); |
|||
GG(dd, ee, aa, bb, cc, X[ 5], 9); |
|||
GG(cc, dd, ee, aa, bb, X[ 2], 11); |
|||
GG(bb, cc, dd, ee, aa, X[14], 7); |
|||
GG(aa, bb, cc, dd, ee, X[11], 13); |
|||
GG(ee, aa, bb, cc, dd, X[ 8], 12); |
|||
|
|||
/* round 3 */ |
|||
HH(dd, ee, aa, bb, cc, X[ 3], 11); |
|||
HH(cc, dd, ee, aa, bb, X[10], 13); |
|||
HH(bb, cc, dd, ee, aa, X[14], 6); |
|||
HH(aa, bb, cc, dd, ee, X[ 4], 7); |
|||
HH(ee, aa, bb, cc, dd, X[ 9], 14); |
|||
HH(dd, ee, aa, bb, cc, X[15], 9); |
|||
HH(cc, dd, ee, aa, bb, X[ 8], 13); |
|||
HH(bb, cc, dd, ee, aa, X[ 1], 15); |
|||
HH(aa, bb, cc, dd, ee, X[ 2], 14); |
|||
HH(ee, aa, bb, cc, dd, X[ 7], 8); |
|||
HH(dd, ee, aa, bb, cc, X[ 0], 13); |
|||
HH(cc, dd, ee, aa, bb, X[ 6], 6); |
|||
HH(bb, cc, dd, ee, aa, X[13], 5); |
|||
HH(aa, bb, cc, dd, ee, X[11], 12); |
|||
HH(ee, aa, bb, cc, dd, X[ 5], 7); |
|||
HH(dd, ee, aa, bb, cc, X[12], 5); |
|||
|
|||
/* round 4 */ |
|||
II(cc, dd, ee, aa, bb, X[ 1], 11); |
|||
II(bb, cc, dd, ee, aa, X[ 9], 12); |
|||
II(aa, bb, cc, dd, ee, X[11], 14); |
|||
II(ee, aa, bb, cc, dd, X[10], 15); |
|||
II(dd, ee, aa, bb, cc, X[ 0], 14); |
|||
II(cc, dd, ee, aa, bb, X[ 8], 15); |
|||
II(bb, cc, dd, ee, aa, X[12], 9); |
|||
II(aa, bb, cc, dd, ee, X[ 4], 8); |
|||
II(ee, aa, bb, cc, dd, X[13], 9); |
|||
II(dd, ee, aa, bb, cc, X[ 3], 14); |
|||
II(cc, dd, ee, aa, bb, X[ 7], 5); |
|||
II(bb, cc, dd, ee, aa, X[15], 6); |
|||
II(aa, bb, cc, dd, ee, X[14], 8); |
|||
II(ee, aa, bb, cc, dd, X[ 5], 6); |
|||
II(dd, ee, aa, bb, cc, X[ 6], 5); |
|||
II(cc, dd, ee, aa, bb, X[ 2], 12); |
|||
|
|||
/* round 5 */ |
|||
JJ(bb, cc, dd, ee, aa, X[ 4], 9); |
|||
JJ(aa, bb, cc, dd, ee, X[ 0], 15); |
|||
JJ(ee, aa, bb, cc, dd, X[ 5], 5); |
|||
JJ(dd, ee, aa, bb, cc, X[ 9], 11); |
|||
JJ(cc, dd, ee, aa, bb, X[ 7], 6); |
|||
JJ(bb, cc, dd, ee, aa, X[12], 8); |
|||
JJ(aa, bb, cc, dd, ee, X[ 2], 13); |
|||
JJ(ee, aa, bb, cc, dd, X[10], 12); |
|||
JJ(dd, ee, aa, bb, cc, X[14], 5); |
|||
JJ(cc, dd, ee, aa, bb, X[ 1], 12); |
|||
JJ(bb, cc, dd, ee, aa, X[ 3], 13); |
|||
JJ(aa, bb, cc, dd, ee, X[ 8], 14); |
|||
JJ(ee, aa, bb, cc, dd, X[11], 11); |
|||
JJ(dd, ee, aa, bb, cc, X[ 6], 8); |
|||
JJ(cc, dd, ee, aa, bb, X[15], 5); |
|||
JJ(bb, cc, dd, ee, aa, X[13], 6); |
|||
|
|||
/* parallel round 1 */ |
|||
JJJ(aaa, bbb, ccc, ddd, eee, X[ 5], 8); |
|||
JJJ(eee, aaa, bbb, ccc, ddd, X[14], 9); |
|||
JJJ(ddd, eee, aaa, bbb, ccc, X[ 7], 9); |
|||
JJJ(ccc, ddd, eee, aaa, bbb, X[ 0], 11); |
|||
JJJ(bbb, ccc, ddd, eee, aaa, X[ 9], 13); |
|||
JJJ(aaa, bbb, ccc, ddd, eee, X[ 2], 15); |
|||
JJJ(eee, aaa, bbb, ccc, ddd, X[11], 15); |
|||
JJJ(ddd, eee, aaa, bbb, ccc, X[ 4], 5); |
|||
JJJ(ccc, ddd, eee, aaa, bbb, X[13], 7); |
|||
JJJ(bbb, ccc, ddd, eee, aaa, X[ 6], 7); |
|||
JJJ(aaa, bbb, ccc, ddd, eee, X[15], 8); |
|||
JJJ(eee, aaa, bbb, ccc, ddd, X[ 8], 11); |
|||
JJJ(ddd, eee, aaa, bbb, ccc, X[ 1], 14); |
|||
JJJ(ccc, ddd, eee, aaa, bbb, X[10], 14); |
|||
JJJ(bbb, ccc, ddd, eee, aaa, X[ 3], 12); |
|||
JJJ(aaa, bbb, ccc, ddd, eee, X[12], 6); |
|||
|
|||
/* parallel round 2 */ |
|||
III(eee, aaa, bbb, ccc, ddd, X[ 6], 9); |
|||
III(ddd, eee, aaa, bbb, ccc, X[11], 13); |
|||
III(ccc, ddd, eee, aaa, bbb, X[ 3], 15); |
|||
III(bbb, ccc, ddd, eee, aaa, X[ 7], 7); |
|||
III(aaa, bbb, ccc, ddd, eee, X[ 0], 12); |
|||
III(eee, aaa, bbb, ccc, ddd, X[13], 8); |
|||
III(ddd, eee, aaa, bbb, ccc, X[ 5], 9); |
|||
III(ccc, ddd, eee, aaa, bbb, X[10], 11); |
|||
III(bbb, ccc, ddd, eee, aaa, X[14], 7); |
|||
III(aaa, bbb, ccc, ddd, eee, X[15], 7); |
|||
III(eee, aaa, bbb, ccc, ddd, X[ 8], 12); |
|||
III(ddd, eee, aaa, bbb, ccc, X[12], 7); |
|||
III(ccc, ddd, eee, aaa, bbb, X[ 4], 6); |
|||
III(bbb, ccc, ddd, eee, aaa, X[ 9], 15); |
|||
III(aaa, bbb, ccc, ddd, eee, X[ 1], 13); |
|||
III(eee, aaa, bbb, ccc, ddd, X[ 2], 11); |
|||
|
|||
/* parallel round 3 */ |
|||
HHH(ddd, eee, aaa, bbb, ccc, X[15], 9); |
|||
HHH(ccc, ddd, eee, aaa, bbb, X[ 5], 7); |
|||
HHH(bbb, ccc, ddd, eee, aaa, X[ 1], 15); |
|||
HHH(aaa, bbb, ccc, ddd, eee, X[ 3], 11); |
|||
HHH(eee, aaa, bbb, ccc, ddd, X[ 7], 8); |
|||
HHH(ddd, eee, aaa, bbb, ccc, X[14], 6); |
|||
HHH(ccc, ddd, eee, aaa, bbb, X[ 6], 6); |
|||
HHH(bbb, ccc, ddd, eee, aaa, X[ 9], 14); |
|||
HHH(aaa, bbb, ccc, ddd, eee, X[11], 12); |
|||
HHH(eee, aaa, bbb, ccc, ddd, X[ 8], 13); |
|||
HHH(ddd, eee, aaa, bbb, ccc, X[12], 5); |
|||
HHH(ccc, ddd, eee, aaa, bbb, X[ 2], 14); |
|||
HHH(bbb, ccc, ddd, eee, aaa, X[10], 13); |
|||
HHH(aaa, bbb, ccc, ddd, eee, X[ 0], 13); |
|||
HHH(eee, aaa, bbb, ccc, ddd, X[ 4], 7); |
|||
HHH(ddd, eee, aaa, bbb, ccc, X[13], 5); |
|||
|
|||
/* parallel round 4 */ |
|||
GGG(ccc, ddd, eee, aaa, bbb, X[ 8], 15); |
|||
GGG(bbb, ccc, ddd, eee, aaa, X[ 6], 5); |
|||
GGG(aaa, bbb, ccc, ddd, eee, X[ 4], 8); |
|||
GGG(eee, aaa, bbb, ccc, ddd, X[ 1], 11); |
|||
GGG(ddd, eee, aaa, bbb, ccc, X[ 3], 14); |
|||
GGG(ccc, ddd, eee, aaa, bbb, X[11], 14); |
|||
GGG(bbb, ccc, ddd, eee, aaa, X[15], 6); |
|||
GGG(aaa, bbb, ccc, ddd, eee, X[ 0], 14); |
|||
GGG(eee, aaa, bbb, ccc, ddd, X[ 5], 6); |
|||
GGG(ddd, eee, aaa, bbb, ccc, X[12], 9); |
|||
GGG(ccc, ddd, eee, aaa, bbb, X[ 2], 12); |
|||
GGG(bbb, ccc, ddd, eee, aaa, X[13], 9); |
|||
GGG(aaa, bbb, ccc, ddd, eee, X[ 9], 12); |
|||
GGG(eee, aaa, bbb, ccc, ddd, X[ 7], 5); |
|||
GGG(ddd, eee, aaa, bbb, ccc, X[10], 15); |
|||
GGG(ccc, ddd, eee, aaa, bbb, X[14], 8); |
|||
|
|||
/* parallel round 5 */ |
|||
FFF(bbb, ccc, ddd, eee, aaa, X[12] , 8); |
|||
FFF(aaa, bbb, ccc, ddd, eee, X[15] , 5); |
|||
FFF(eee, aaa, bbb, ccc, ddd, X[10] , 12); |
|||
FFF(ddd, eee, aaa, bbb, ccc, X[ 4] , 9); |
|||
FFF(ccc, ddd, eee, aaa, bbb, X[ 1] , 12); |
|||
FFF(bbb, ccc, ddd, eee, aaa, X[ 5] , 5); |
|||
FFF(aaa, bbb, ccc, ddd, eee, X[ 8] , 14); |
|||
FFF(eee, aaa, bbb, ccc, ddd, X[ 7] , 6); |
|||
FFF(ddd, eee, aaa, bbb, ccc, X[ 6] , 8); |
|||
FFF(ccc, ddd, eee, aaa, bbb, X[ 2] , 13); |
|||
FFF(bbb, ccc, ddd, eee, aaa, X[13] , 6); |
|||
FFF(aaa, bbb, ccc, ddd, eee, X[14] , 5); |
|||
FFF(eee, aaa, bbb, ccc, ddd, X[ 0] , 15); |
|||
FFF(ddd, eee, aaa, bbb, ccc, X[ 3] , 13); |
|||
FFF(ccc, ddd, eee, aaa, bbb, X[ 9] , 11); |
|||
FFF(bbb, ccc, ddd, eee, aaa, X[11] , 11); |
|||
|
|||
/* combine results */ |
|||
ddd += cc + MDbuf[1]; /* final result for MDbuf[0] */ |
|||
MDbuf[1] = MDbuf[2] + dd + eee; |
|||
MDbuf[2] = MDbuf[3] + ee + aaa; |
|||
MDbuf[3] = MDbuf[4] + aa + bbb; |
|||
MDbuf[4] = MDbuf[0] + bb + ccc; |
|||
MDbuf[0] = ddd; |
|||
|
|||
return; |
|||
} |
|||
|
|||
void MDfinish(uint32_t *MDbuf, byte const *strptr, uint32_t lswlen, uint32_t mswlen) |
|||
{ |
|||
unsigned int i; /* counter */ |
|||
uint32_t X[16]; /* message words */ |
|||
|
|||
memset(X, 0, 16*sizeof(uint32_t)); |
|||
|
|||
/* put bytes from strptr into X */ |
|||
for (i=0; i<(lswlen&63); i++) { |
|||
/* byte i goes into word X[i div 4] at pos. 8*(i mod 4) */ |
|||
X[i>>2] ^= (uint32_t) *strptr++ << (8 * (i&3)); |
|||
} |
|||
|
|||
/* append the bit m_n == 1 */ |
|||
X[(lswlen>>2)&15] ^= (uint32_t)1 << (8*(lswlen&3) + 7); |
|||
|
|||
if ((lswlen & 63) > 55) { |
|||
/* length goes to next block */ |
|||
MDcompress(MDbuf, X); |
|||
memset(X, 0, 16*sizeof(uint32_t)); |
|||
} |
|||
|
|||
/* append length in bits*/ |
|||
X[14] = lswlen << 3; |
|||
X[15] = (lswlen >> 29) | (mswlen << 3); |
|||
MDcompress(MDbuf, X); |
|||
|
|||
return; |
|||
} |
|||
|
|||
#undef ROL |
|||
#undef F |
|||
#undef G |
|||
#undef H |
|||
#undef I |
|||
#undef J |
|||
#undef FF |
|||
#undef GG |
|||
#undef HH |
|||
#undef II |
|||
#undef JJ |
|||
#undef FFF |
|||
#undef GGG |
|||
#undef HHH |
|||
#undef III |
|||
#undef JJJ |
|||
|
|||
} |
|||
|
|||
/*
|
|||
* @returns RMD(_input) |
|||
*/ |
|||
h160 ripemd160(bytesConstRef _input) |
|||
{ |
|||
h160 hashcode; |
|||
uint32_t buffer[RMDsize / 32]; // contains (A, B, C, D(, E))
|
|||
uint32_t current[16]; // current 16-word chunk
|
|||
|
|||
// initialize
|
|||
rmd160::MDinit(buffer); |
|||
byte const* message = _input.data(); |
|||
uint32_t remaining = _input.size(); // # of bytes not yet processed
|
|||
|
|||
// process message in 16x 4-byte chunks
|
|||
for (; remaining >= 64; remaining -= 64) |
|||
{ |
|||
for (unsigned i = 0; i < 16; i++) |
|||
{ |
|||
current[i] = BYTES_TO_DWORD(message); |
|||
message += 4; |
|||
} |
|||
rmd160::MDcompress(buffer, current); |
|||
} |
|||
// length mod 64 bytes left
|
|||
|
|||
// finish:
|
|||
rmd160::MDfinish(buffer, message, _input.size(), 0); |
|||
|
|||
for (unsigned i = 0; i < RMDsize / 8; i += 4) |
|||
{ |
|||
hashcode[i] = buffer[i >> 2]; // implicit cast to byte
|
|||
hashcode[i + 1] = (buffer[i >> 2] >> 8); //extracts the 8 least
|
|||
hashcode[i + 2] = (buffer[i >> 2] >> 16); // significant bits.
|
|||
hashcode[i + 3] = (buffer[i >> 2] >> 24); |
|||
} |
|||
|
|||
return hashcode; |
|||
} |
|||
|
|||
#undef BYTES_TO_DWORD |
|||
#undef RMDsize |
|||
|
|||
} |
@ -0,0 +1,183 @@ |
|||
/*
|
|||
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. |
|||
|
|||
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file MemoryDB.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include <libdevcore/Common.h> |
|||
#include "MemoryDB.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
|
|||
namespace dev |
|||
{ |
|||
|
|||
const char* DBChannel::name() { return "TDB"; } |
|||
const char* DBWarn::name() { return "TDB"; } |
|||
|
|||
std::unordered_map<h256, std::string> MemoryDB::get() const |
|||
{ |
|||
#if DEV_GUARDED_DB |
|||
ReadGuard l(x_this); |
|||
#endif |
|||
std::unordered_map<h256, std::string> ret; |
|||
for (auto const& i: m_main) |
|||
if (!m_enforceRefs || i.second.second > 0) |
|||
ret.insert(make_pair(i.first, i.second.first)); |
|||
return ret; |
|||
} |
|||
|
|||
MemoryDB& MemoryDB::operator=(MemoryDB const& _c) |
|||
{ |
|||
if (this == &_c) |
|||
return *this; |
|||
#if DEV_GUARDED_DB |
|||
ReadGuard l(_c.x_this); |
|||
WriteGuard l2(x_this); |
|||
#endif |
|||
m_main = _c.m_main; |
|||
m_aux = _c.m_aux; |
|||
return *this; |
|||
} |
|||
|
|||
std::string MemoryDB::lookup(h256 const& _h) const |
|||
{ |
|||
#if DEV_GUARDED_DB |
|||
ReadGuard l(x_this); |
|||
#endif |
|||
auto it = m_main.find(_h); |
|||
if (it != m_main.end()) |
|||
{ |
|||
if (!m_enforceRefs || it->second.second > 0) |
|||
return it->second.first; |
|||
else |
|||
cwarn << "Lookup required for value with refcount == 0. This is probably a critical trie issue" << _h; |
|||
} |
|||
return std::string(); |
|||
} |
|||
|
|||
bool MemoryDB::exists(h256 const& _h) const |
|||
{ |
|||
#if DEV_GUARDED_DB |
|||
ReadGuard l(x_this); |
|||
#endif |
|||
auto it = m_main.find(_h); |
|||
if (it != m_main.end() && (!m_enforceRefs || it->second.second > 0)) |
|||
return true; |
|||
return false; |
|||
} |
|||
|
|||
void MemoryDB::insert(h256 const& _h, bytesConstRef _v) |
|||
{ |
|||
#if DEV_GUARDED_DB |
|||
WriteGuard l(x_this); |
|||
#endif |
|||
auto it = m_main.find(_h); |
|||
if (it != m_main.end()) |
|||
{ |
|||
it->second.first = _v.toString(); |
|||
it->second.second++; |
|||
} |
|||
else |
|||
m_main[_h] = make_pair(_v.toString(), 1); |
|||
#if ETH_PARANOIA |
|||
dbdebug << "INST" << _h << "=>" << m_main[_h].second; |
|||
#endif |
|||
} |
|||
|
|||
bool MemoryDB::kill(h256 const& _h) |
|||
{ |
|||
#if DEV_GUARDED_DB |
|||
ReadGuard l(x_this); |
|||
#endif |
|||
if (m_main.count(_h)) |
|||
{ |
|||
if (m_main[_h].second > 0) |
|||
{ |
|||
m_main[_h].second--; |
|||
return true; |
|||
} |
|||
#if ETH_PARANOIA |
|||
else |
|||
{ |
|||
// If we get to this point, then there was probably a node in the level DB which we need to remove and which we have previously
|
|||
// used as part of the memory-based MemoryDB. Nothing to be worried about *as long as the node exists in the DB*.
|
|||
dbdebug << "NOKILL-WAS" << _h; |
|||
} |
|||
dbdebug << "KILL" << _h << "=>" << m_main[_h].second; |
|||
} |
|||
else |
|||
{ |
|||
dbdebug << "NOKILL" << _h; |
|||
#endif |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
bytes MemoryDB::lookupAux(h256 const& _h) const |
|||
{ |
|||
#if DEV_GUARDED_DB |
|||
ReadGuard l(x_this); |
|||
#endif |
|||
auto it = m_aux.find(_h); |
|||
if (it != m_aux.end() && (!m_enforceRefs || it->second.second)) |
|||
return it->second.first; |
|||
return bytes(); |
|||
} |
|||
|
|||
void MemoryDB::removeAux(h256 const& _h) |
|||
{ |
|||
#if DEV_GUARDED_DB |
|||
WriteGuard l(x_this); |
|||
#endif |
|||
m_aux[_h].second = false; |
|||
} |
|||
|
|||
void MemoryDB::insertAux(h256 const& _h, bytesConstRef _v) |
|||
{ |
|||
#if DEV_GUARDED_DB |
|||
WriteGuard l(x_this); |
|||
#endif |
|||
m_aux[_h] = make_pair(_v.toBytes(), true); |
|||
} |
|||
|
|||
void MemoryDB::purge() |
|||
{ |
|||
#if DEV_GUARDED_DB |
|||
WriteGuard l(x_this); |
|||
#endif |
|||
for (auto it = m_main.begin(); it != m_main.end(); ) |
|||
if (it->second.second) |
|||
++it; |
|||
else |
|||
it = m_main.erase(it); |
|||
} |
|||
|
|||
h256Hash MemoryDB::keys() const |
|||
{ |
|||
#if DEV_GUARDED_DB |
|||
ReadGuard l(x_this); |
|||
#endif |
|||
h256Hash ret; |
|||
for (auto const& i: m_main) |
|||
if (i.second.second) |
|||
ret.insert(i.first); |
|||
return ret; |
|||
} |
|||
|
|||
} |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue