debris
10 years ago
83 changed files with 1462 additions and 1368 deletions
@ -0,0 +1,108 @@ |
|||||
|
/*
|
||||
|
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 NameRegNamer.h
|
||||
|
* @author Gav Wood <i@gavwood.com> |
||||
|
* @date 2015 |
||||
|
*/ |
||||
|
|
||||
|
#include "NameRegNamer.h" |
||||
|
#include <QSettings> |
||||
|
#include <libdevcore/Log.h> |
||||
|
#include <libethereum/Client.h> |
||||
|
using namespace std; |
||||
|
using namespace dev; |
||||
|
using namespace az; |
||||
|
using namespace eth; |
||||
|
|
||||
|
DEV_AZ_NOTE_PLUGIN(NameRegNamer); |
||||
|
|
||||
|
NameRegNamer::NameRegNamer(MainFace* _m): |
||||
|
AccountNamerPlugin(_m, "NameRegNamer") |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
NameRegNamer::~NameRegNamer() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
string NameRegNamer::toName(Address const& _a) const |
||||
|
{ |
||||
|
for (auto const& r: m_registrars) |
||||
|
{ |
||||
|
string n = abiOut<string>(main()->ethereum()->call(Address(1), 0, r, abiIn("name(address)", _a), 1000000, DefaultGasPrice, PendingBlock, FudgeFactor::Lenient).output); |
||||
|
if (!n.empty()) |
||||
|
return n; |
||||
|
} |
||||
|
return string(); |
||||
|
} |
||||
|
|
||||
|
Address NameRegNamer::toAddress(std::string const& _n) const |
||||
|
{ |
||||
|
for (auto const& r: m_registrars) |
||||
|
if (Address a = abiOut<Address>(main()->ethereum()->call(r, abiIn("addr(string)", _n)).output)) |
||||
|
return a; |
||||
|
return Address(); |
||||
|
} |
||||
|
|
||||
|
Addresses NameRegNamer::knownAddresses() const |
||||
|
{ |
||||
|
return m_knownCache; |
||||
|
} |
||||
|
|
||||
|
void NameRegNamer::killRegistrar(Address const& _r) |
||||
|
{ |
||||
|
if (m_filters.count(_r)) |
||||
|
{ |
||||
|
main()->uninstallWatch(m_filters.at(_r)); |
||||
|
m_filters.erase(_r); |
||||
|
} |
||||
|
for (auto i = m_registrars.begin(); i != m_registrars.end();) |
||||
|
if (*i == _r) |
||||
|
i = m_registrars.erase(i); |
||||
|
else |
||||
|
++i; |
||||
|
} |
||||
|
|
||||
|
void NameRegNamer::updateCache() |
||||
|
{ |
||||
|
// m_forwardCache.clear();
|
||||
|
// m_reverseCache.clear();
|
||||
|
m_knownCache.clear(); |
||||
|
#if ETH_FATDB || !ETH_TRUE |
||||
|
for (auto const& r: m_registrars) |
||||
|
for (u256 const& a: keysOf(ethereum()->storageAt(r))) |
||||
|
if (a < u256(1) << 160) |
||||
|
m_knownCache.push_back(Address((u160)a - 1)); |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
void NameRegNamer::readSettings(QSettings const& _s) |
||||
|
{ |
||||
|
(void)_s; |
||||
|
while (!m_registrars.empty()) |
||||
|
killRegistrar(m_registrars.back()); |
||||
|
|
||||
|
Address a("047cdba9627a8686bb24b3a65d87dab7efa53d31"); |
||||
|
m_registrars.push_back(a); |
||||
|
m_filters[a] = main()->installWatch(LogFilter().address(a), [=](LocalisedLogEntries const&){ updateCache(); }); |
||||
|
|
||||
|
noteKnownChanged(); |
||||
|
} |
||||
|
|
||||
|
void NameRegNamer::writeSettings(QSettings&) |
||||
|
{ |
||||
|
} |
@ -0,0 +1,59 @@ |
|||||
|
/*
|
||||
|
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 NameRegNamer.h
|
||||
|
* @author Gav Wood <i@gavwood.com> |
||||
|
* @date 2015 |
||||
|
*/ |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include "MainFace.h" |
||||
|
|
||||
|
namespace dev |
||||
|
{ |
||||
|
namespace az |
||||
|
{ |
||||
|
|
||||
|
class NameRegNamer: public QObject, public AccountNamerPlugin |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
|
||||
|
public: |
||||
|
NameRegNamer(MainFace* _m); |
||||
|
~NameRegNamer(); |
||||
|
|
||||
|
private: |
||||
|
void readSettings(QSettings const&) override; |
||||
|
void writeSettings(QSettings&) override; |
||||
|
|
||||
|
std::string toName(Address const&) const override; |
||||
|
Address toAddress(std::string const&) const override; |
||||
|
Addresses knownAddresses() const override; |
||||
|
|
||||
|
void updateCache(); |
||||
|
void killRegistrar(Address const& _r); |
||||
|
|
||||
|
Addresses m_registrars; |
||||
|
std::unordered_map<Address, unsigned> m_filters; |
||||
|
|
||||
|
mutable Addresses m_knownCache; |
||||
|
// mutable std::unordered_map<Address, std::string> m_forwardCache;
|
||||
|
// mutable std::unordered_map<std::string, Address> m_reverseCache;
|
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,178 @@ |
|||||
|
/*
|
||||
|
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 Whisper.cpp
|
||||
|
* @author Gav Wood <i@gavwood.com> |
||||
|
* @date 2015 |
||||
|
*/ |
||||
|
|
||||
|
#include "Whisper.h" |
||||
|
#include <QSettings> |
||||
|
#include <libethereum/Client.h> |
||||
|
#include <libethereum/Utility.h> |
||||
|
#include <libwhisper/WhisperHost.h> |
||||
|
#include <libweb3jsonrpc/WebThreeStubServerBase.h> |
||||
|
#include "OurWebThreeStubServer.h" |
||||
|
#include "ui_Whisper.h" |
||||
|
using namespace std; |
||||
|
using namespace dev; |
||||
|
using namespace az; |
||||
|
using namespace eth; |
||||
|
|
||||
|
DEV_AZ_NOTE_PLUGIN(Whisper); |
||||
|
|
||||
|
static Public stringToPublic(QString const& _a) |
||||
|
{ |
||||
|
string sn = _a.toStdString(); |
||||
|
if (_a.size() == sizeof(Public) * 2) |
||||
|
return Public(fromHex(_a.toStdString())); |
||||
|
else if (_a.size() == sizeof(Public) * 2 + 2 && _a.startsWith("0x")) |
||||
|
return Public(fromHex(_a.mid(2).toStdString())); |
||||
|
else |
||||
|
return Public(); |
||||
|
} |
||||
|
|
||||
|
static shh::Topics topicFromText(QString _s) |
||||
|
{ |
||||
|
shh::BuildTopic ret; |
||||
|
while (_s.size()) |
||||
|
{ |
||||
|
QRegExp r("(@|\\$)?\"([^\"]*)\"(\\s.*)?"); |
||||
|
QRegExp d("(@|\\$)?([0-9]+)(\\s*(ether)|(finney)|(szabo))?(\\s.*)?"); |
||||
|
QRegExp h("(@|\\$)?(0x)?(([a-fA-F0-9])+)(\\s.*)?"); |
||||
|
bytes part; |
||||
|
if (r.exactMatch(_s)) |
||||
|
{ |
||||
|
for (auto i: r.cap(2)) |
||||
|
part.push_back((byte)i.toLatin1()); |
||||
|
if (r.cap(1) != "$") |
||||
|
for (int i = r.cap(2).size(); i < 32; ++i) |
||||
|
part.push_back(0); |
||||
|
else |
||||
|
part.push_back(0); |
||||
|
_s = r.cap(3); |
||||
|
} |
||||
|
else if (d.exactMatch(_s)) |
||||
|
{ |
||||
|
u256 v(d.cap(2).toStdString()); |
||||
|
if (d.cap(6) == "szabo") |
||||
|
v *= szabo; |
||||
|
else if (d.cap(5) == "finney") |
||||
|
v *= finney; |
||||
|
else if (d.cap(4) == "ether") |
||||
|
v *= ether; |
||||
|
bytes bs = dev::toCompactBigEndian(v); |
||||
|
if (d.cap(1) != "$") |
||||
|
for (auto i = bs.size(); i < 32; ++i) |
||||
|
part.push_back(0); |
||||
|
for (auto b: bs) |
||||
|
part.push_back(b); |
||||
|
_s = d.cap(7); |
||||
|
} |
||||
|
else if (h.exactMatch(_s)) |
||||
|
{ |
||||
|
bytes bs = fromHex((((h.cap(3).size() & 1) ? "0" : "") + h.cap(3)).toStdString()); |
||||
|
if (h.cap(1) != "$") |
||||
|
for (auto i = bs.size(); i < 32; ++i) |
||||
|
part.push_back(0); |
||||
|
for (auto b: bs) |
||||
|
part.push_back(b); |
||||
|
_s = h.cap(5); |
||||
|
} |
||||
|
else |
||||
|
_s = _s.mid(1); |
||||
|
ret.shift(part); |
||||
|
} |
||||
|
return ret; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
Whisper::Whisper(MainFace* _m): |
||||
|
Plugin(_m, "Whisper"), |
||||
|
m_ui(new Ui::Whisper) |
||||
|
{ |
||||
|
dock(Qt::RightDockWidgetArea, "Whisper")->setWidget(new QWidget); |
||||
|
m_ui->setupUi(dock()->widget()); |
||||
|
connect(addMenuItem("New Whisper identity.", "menuNetwork", true), &QAction::triggered, this, &Whisper::on_newIdentity_triggered); |
||||
|
connect(_m->web3Server(), &OurWebThreeStubServer::onNewId, this, &Whisper::addNewId); |
||||
|
} |
||||
|
|
||||
|
void Whisper::readSettings(QSettings const& _s) |
||||
|
{ |
||||
|
m_myIdentities.clear(); |
||||
|
QByteArray b = _s.value("identities").toByteArray(); |
||||
|
if (!b.isEmpty()) |
||||
|
{ |
||||
|
Secret k; |
||||
|
for (unsigned i = 0; i < b.size() / sizeof(Secret); ++i) |
||||
|
{ |
||||
|
memcpy(k.writable().data(), b.data() + i * sizeof(Secret), sizeof(Secret)); |
||||
|
if (!count(m_myIdentities.begin(), m_myIdentities.end(), KeyPair(k))) |
||||
|
m_myIdentities.append(KeyPair(k)); |
||||
|
} |
||||
|
} |
||||
|
main()->web3Server()->setIdentities(keysAsVector(m_myIdentities)); |
||||
|
refreshWhisper(); |
||||
|
} |
||||
|
|
||||
|
void Whisper::writeSettings(QSettings& _s) |
||||
|
{ |
||||
|
QByteArray b; |
||||
|
b.resize(sizeof(Secret) * m_myIdentities.size()); |
||||
|
auto p = b.data(); |
||||
|
for (auto i: m_myIdentities) |
||||
|
{ |
||||
|
memcpy(p, &(i.secret()), sizeof(Secret)); |
||||
|
p += sizeof(Secret); |
||||
|
} |
||||
|
_s.setValue("identities", b); |
||||
|
} |
||||
|
|
||||
|
void Whisper::addNewId(QString _ids) |
||||
|
{ |
||||
|
KeyPair kp(jsToSecret(_ids.toStdString())); |
||||
|
m_myIdentities.push_back(kp); |
||||
|
main()->web3Server()->setIdentities(keysAsVector(m_myIdentities)); |
||||
|
refreshWhisper(); |
||||
|
} |
||||
|
|
||||
|
void Whisper::refreshWhisper() |
||||
|
{ |
||||
|
m_ui->shhFrom->clear(); |
||||
|
for (auto i: main()->web3Server()->ids()) |
||||
|
m_ui->shhFrom->addItem(QString::fromStdString(toHex(i.first.ref()))); |
||||
|
} |
||||
|
|
||||
|
void Whisper::on_newIdentity_triggered() |
||||
|
{ |
||||
|
KeyPair kp = KeyPair::create(); |
||||
|
m_myIdentities.append(kp); |
||||
|
main()->web3Server()->setIdentities(keysAsVector(m_myIdentities)); |
||||
|
refreshWhisper(); |
||||
|
} |
||||
|
|
||||
|
void Whisper::on_post_clicked() |
||||
|
{ |
||||
|
return; |
||||
|
shh::Message m; |
||||
|
m.setTo(stringToPublic(m_ui->shhTo->currentText())); |
||||
|
m.setPayload(parseData(m_ui->shhData->toPlainText().toStdString())); |
||||
|
Public f = stringToPublic(m_ui->shhFrom->currentText()); |
||||
|
Secret from; |
||||
|
if (main()->web3Server()->ids().count(f)) |
||||
|
from = main()->web3Server()->ids().at(f); |
||||
|
whisper()->inject(m.seal(from, topicFromText(m_ui->shhTopic->toPlainText()), m_ui->shhTtl->value(), m_ui->shhWork->value())); |
||||
|
} |
@ -0,0 +1,60 @@ |
|||||
|
/*
|
||||
|
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 Whisper.h
|
||||
|
* @author Gav Wood <i@gavwood.com> |
||||
|
* @date 2015 |
||||
|
*/ |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <QMutex> |
||||
|
#include <QString> |
||||
|
#include <QPair> |
||||
|
#include <QList> |
||||
|
#include "MainFace.h" |
||||
|
|
||||
|
namespace Ui |
||||
|
{ |
||||
|
class Whisper; |
||||
|
} |
||||
|
|
||||
|
namespace dev |
||||
|
{ |
||||
|
namespace az |
||||
|
{ |
||||
|
|
||||
|
class Whisper: public QObject, public Plugin |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
|
||||
|
public: |
||||
|
Whisper(MainFace* _m); |
||||
|
|
||||
|
private: |
||||
|
void readSettings(QSettings const&) override; |
||||
|
void writeSettings(QSettings&) override; |
||||
|
void refreshWhisper(); |
||||
|
void addNewId(QString _ids); |
||||
|
void on_newIdentity_triggered(); |
||||
|
void on_post_clicked(); |
||||
|
|
||||
|
Ui::Whisper* m_ui; |
||||
|
QList<KeyPair> m_myIdentities; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,176 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<ui version="4.0"> |
||||
|
<class>Whisper</class> |
||||
|
<widget class="QWidget" name="WhisperWidget"> |
||||
|
<layout class="QGridLayout" name="gridLayout_4"> |
||||
|
<item row="4" column="0" rowspan="2"> |
||||
|
<widget class="QLabel" name="label_8"> |
||||
|
<property name="sizePolicy"> |
||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Maximum"> |
||||
|
<horstretch>0</horstretch> |
||||
|
<verstretch>0</verstretch> |
||||
|
</sizepolicy> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>Data</string> |
||||
|
</property> |
||||
|
<property name="alignment"> |
||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item row="2" column="2" colspan="2"> |
||||
|
<widget class="QLabel" name="label5_6"> |
||||
|
<property name="sizePolicy"> |
||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> |
||||
|
<horstretch>0</horstretch> |
||||
|
<verstretch>0</verstretch> |
||||
|
</sizepolicy> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>Work to Prove</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item row="5" column="1" colspan="4"> |
||||
|
<widget class="QPlainTextEdit" name="shhData"> |
||||
|
<property name="sizePolicy"> |
||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> |
||||
|
<horstretch>0</horstretch> |
||||
|
<verstretch>0</verstretch> |
||||
|
</sizepolicy> |
||||
|
</property> |
||||
|
<property name="frameShape"> |
||||
|
<enum>QFrame::NoFrame</enum> |
||||
|
</property> |
||||
|
<property name="lineWidth"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item row="3" column="1" colspan="4"> |
||||
|
<widget class="QPlainTextEdit" name="shhTopic"> |
||||
|
<property name="sizePolicy"> |
||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> |
||||
|
<horstretch>0</horstretch> |
||||
|
<verstretch>0</verstretch> |
||||
|
</sizepolicy> |
||||
|
</property> |
||||
|
<property name="frameShape"> |
||||
|
<enum>QFrame::NoFrame</enum> |
||||
|
</property> |
||||
|
<property name="lineWidth"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item row="1" column="1" colspan="4"> |
||||
|
<widget class="QComboBox" name="shhFrom"> |
||||
|
<property name="editable"> |
||||
|
<bool>false</bool> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item row="3" column="0"> |
||||
|
<widget class="QLabel" name="label_9"> |
||||
|
<property name="sizePolicy"> |
||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Maximum"> |
||||
|
<horstretch>0</horstretch> |
||||
|
<verstretch>0</verstretch> |
||||
|
</sizepolicy> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>Topic</string> |
||||
|
</property> |
||||
|
<property name="alignment"> |
||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item row="0" column="0"> |
||||
|
<widget class="QLabel" name="label5_3"> |
||||
|
<property name="sizePolicy"> |
||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> |
||||
|
<horstretch>0</horstretch> |
||||
|
<verstretch>0</verstretch> |
||||
|
</sizepolicy> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>To</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item row="0" column="1" colspan="4"> |
||||
|
<widget class="QComboBox" name="shhTo"> |
||||
|
<property name="editable"> |
||||
|
<bool>true</bool> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item row="2" column="1"> |
||||
|
<widget class="QSpinBox" name="shhTtl"> |
||||
|
<property name="suffix"> |
||||
|
<string> seconds</string> |
||||
|
</property> |
||||
|
<property name="minimum"> |
||||
|
<number>5</number> |
||||
|
</property> |
||||
|
<property name="maximum"> |
||||
|
<number>259200</number> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item row="2" column="0"> |
||||
|
<widget class="QLabel" name="label5_5"> |
||||
|
<property name="sizePolicy"> |
||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> |
||||
|
<horstretch>0</horstretch> |
||||
|
<verstretch>0</verstretch> |
||||
|
</sizepolicy> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>TTL</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item row="1" column="0"> |
||||
|
<widget class="QLabel" name="label5_4"> |
||||
|
<property name="sizePolicy"> |
||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> |
||||
|
<horstretch>0</horstretch> |
||||
|
<verstretch>0</verstretch> |
||||
|
</sizepolicy> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>From</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item row="2" column="4"> |
||||
|
<widget class="QSpinBox" name="shhWork"> |
||||
|
<property name="suffix"> |
||||
|
<string> ms</string> |
||||
|
</property> |
||||
|
<property name="minimum"> |
||||
|
<number>1</number> |
||||
|
</property> |
||||
|
<property name="maximum"> |
||||
|
<number>1000</number> |
||||
|
</property> |
||||
|
<property name="value"> |
||||
|
<number>50</number> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
<item row="6" column="4"> |
||||
|
<widget class="QPushButton" name="post"> |
||||
|
<property name="text"> |
||||
|
<string>Post</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
</layout> |
||||
|
</widget> |
||||
|
<resources/> |
||||
|
<connections/> |
||||
|
</ui> |
@ -0,0 +1,78 @@ |
|||||
|
/*
|
||||
|
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 WhisperPeers.cpp
|
||||
|
* @author Gav Wood <i@gavwood.com> |
||||
|
* @date 2015 |
||||
|
*/ |
||||
|
|
||||
|
#include "WhisperPeers.h" |
||||
|
#include <QSettings> |
||||
|
#include <libethereum/Client.h> |
||||
|
#include <libwhisper/WhisperHost.h> |
||||
|
#include <libweb3jsonrpc/WebThreeStubServerBase.h> |
||||
|
#include "OurWebThreeStubServer.h" |
||||
|
#include "ui_WhisperPeers.h" |
||||
|
using namespace std; |
||||
|
using namespace dev; |
||||
|
using namespace az; |
||||
|
using namespace eth; |
||||
|
|
||||
|
DEV_AZ_NOTE_PLUGIN(WhisperPeers); |
||||
|
|
||||
|
WhisperPeers::WhisperPeers(MainFace* _m): |
||||
|
Plugin(_m, "WhisperPeers"), |
||||
|
m_ui(new Ui::WhisperPeers) |
||||
|
{ |
||||
|
dock(Qt::RightDockWidgetArea, "Active Whispers")->setWidget(new QWidget); |
||||
|
m_ui->setupUi(dock()->widget()); |
||||
|
startTimer(1000); |
||||
|
} |
||||
|
|
||||
|
void WhisperPeers::timerEvent(QTimerEvent*) |
||||
|
{ |
||||
|
refreshWhispers(); |
||||
|
} |
||||
|
|
||||
|
void WhisperPeers::refreshWhispers() |
||||
|
{ |
||||
|
return; |
||||
|
m_ui->whispers->clear(); |
||||
|
for (auto const& w: whisper()->all()) |
||||
|
{ |
||||
|
shh::Envelope const& e = w.second; |
||||
|
shh::Message m; |
||||
|
for (pair<Public, Secret> const& i: main()->web3Server()->ids()) |
||||
|
if (!!(m = e.open(shh::Topics(), i.second))) |
||||
|
break; |
||||
|
if (!m) |
||||
|
m = e.open(shh::Topics()); |
||||
|
|
||||
|
QString msg; |
||||
|
if (m.from()) |
||||
|
// Good message.
|
||||
|
msg = QString("{%1 -> %2} %3").arg(m.from() ? m.from().abridged().c_str() : "???").arg(m.to() ? m.to().abridged().c_str() : "*").arg(toHex(m.payload()).c_str()); |
||||
|
else if (m) |
||||
|
// Maybe message.
|
||||
|
msg = QString("{%1 -> %2} %3 (?)").arg(m.from() ? m.from().abridged().c_str() : "???").arg(m.to() ? m.to().abridged().c_str() : "*").arg(toHex(m.payload()).c_str()); |
||||
|
|
||||
|
time_t ex = e.expiry(); |
||||
|
QString t(ctime(&ex)); |
||||
|
t.chop(1); |
||||
|
QString item = QString("[%1 - %2s] *%3 %5 %4").arg(t).arg(e.ttl()).arg(e.workProved()).arg(toString(e.topic()).c_str()).arg(msg); |
||||
|
m_ui->whispers->addItem(item); |
||||
|
} |
||||
|
} |
@ -0,0 +1,55 @@ |
|||||
|
/*
|
||||
|
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 WhisperPeers.h
|
||||
|
* @author Gav Wood <i@gavwood.com> |
||||
|
* @date 2015 |
||||
|
*/ |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <QMutex> |
||||
|
#include <QString> |
||||
|
#include <QPair> |
||||
|
#include <QList> |
||||
|
#include "MainFace.h" |
||||
|
|
||||
|
namespace Ui |
||||
|
{ |
||||
|
class WhisperPeers; |
||||
|
} |
||||
|
|
||||
|
namespace dev |
||||
|
{ |
||||
|
namespace az |
||||
|
{ |
||||
|
|
||||
|
class WhisperPeers: public QObject, public Plugin |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
|
||||
|
public: |
||||
|
WhisperPeers(MainFace* _m); |
||||
|
|
||||
|
private: |
||||
|
void timerEvent(QTimerEvent*) override; |
||||
|
void refreshWhispers(); |
||||
|
|
||||
|
Ui::WhisperPeers* m_ui; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<ui version="4.0"> |
||||
|
<class>WhisperPeers</class> |
||||
|
<widget class="QWidget" name="whisperPeersWidget"> |
||||
|
<layout class="QHBoxLayout" name="whisperPeersLayout"> |
||||
|
<property name="spacing"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
<property name="leftMargin"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
<property name="topMargin"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
<property name="rightMargin"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
<property name="bottomMargin"> |
||||
|
<number>0</number> |
||||
|
</property> |
||||
|
<item> |
||||
|
<widget class="QListWidget" name="whispers"> |
||||
|
<property name="frameShape"> |
||||
|
<enum>QFrame::NoFrame</enum> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</item> |
||||
|
</layout> |
||||
|
</widget> |
||||
|
<resources/> |
||||
|
<connections/> |
||||
|
</ui> |
Loading…
Reference in new issue