Browse Source
OtherAccounts address namer + interface. OurAccounts address namer. Additional internal support for extensible account naming.cl-refactor
Gav Wood
10 years ago
21 changed files with 530 additions and 78 deletions
@ -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 OtherAccounts.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include "OtherAccounts.h" |
|||
#include <QSettings> |
|||
#include <libdevcore/Log.h> |
|||
#include <libethereum/Client.h> |
|||
#include <ui_OtherAccounts.h> |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace az; |
|||
using namespace eth; |
|||
|
|||
DEV_AZ_NOTE_PLUGIN(OtherAccounts); |
|||
|
|||
OtherAccounts::OtherAccounts(MainFace* _m): |
|||
AccountNamerPlugin(_m, "OtherAccounts") |
|||
{ |
|||
connect(addMenuItem("New Brain Wallet...", "menuTools", true), SIGNAL(triggered()), SLOT(import())); |
|||
} |
|||
|
|||
void OtherAccounts::import() |
|||
{ |
|||
QDialog d; |
|||
Ui_OtherAccounts u; |
|||
u.setupUi(&d); |
|||
d.setWindowTitle("Add Named Accounts"); |
|||
if (d.exec() == QDialog::Accepted) |
|||
{ |
|||
QStringList sl = u.accounts->toPlainText().split("\n"); |
|||
for (QString const& s: sl) |
|||
{ |
|||
Address addr = toAddress(s.section("[ \\t]+", 0, 1).toStdString()); |
|||
string name = s.section("[ \\t]+", 1).toStdString(); |
|||
m_toName[addr] = name; |
|||
m_toAddress[name] = addr; |
|||
} |
|||
main()->noteSettingsChanged(); |
|||
main()->noteAddressesChanged(); |
|||
} |
|||
} |
|||
|
|||
void OtherAccounts::readSettings(QSettings const& _s) |
|||
{ |
|||
m_toName.clear(); |
|||
m_toAddress.clear(); |
|||
for (QVariant const& i: _s.value("OtherAccounts", QVariantList()).toList()) |
|||
{ |
|||
QStringList l = i.toStringList(); |
|||
if (l.size() == 2) |
|||
{ |
|||
m_toName[Address(l[0].toStdString())] = l[1].toStdString(); |
|||
m_toAddress[l[1].toStdString()] = Address(l[0].toStdString()); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void OtherAccounts::writeSettings(QSettings& _s) |
|||
{ |
|||
QVariantList r; |
|||
for (auto const& i: m_toName) |
|||
{ |
|||
QStringList l; |
|||
l += QString::fromStdString(i.first.hex()); |
|||
l += QString::fromStdString(i.second); |
|||
r += QVariant(l); |
|||
} |
|||
_s.setValue("OtherAccounts", r); |
|||
} |
@ -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 OtherAccounts.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include "MainFace.h" |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace az |
|||
{ |
|||
|
|||
class OtherAccounts: public QObject, public AccountNamerPlugin |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
OtherAccounts(MainFace* _m); |
|||
|
|||
protected: |
|||
std::string toName(Address const& _a) const override { if (m_toName.count(_a)) return m_toName.at(_a); return std::string(); } |
|||
Address toAddress(std::string const& _n) const override { if (m_toAddress.count(_n)) return m_toAddress.at(_n); return Address(); } |
|||
Addresses knownAddresses() const override { return keysOf(m_toName); } |
|||
|
|||
private slots: |
|||
void import(); |
|||
|
|||
private: |
|||
void readSettings(QSettings const&) override; |
|||
void writeSettings(QSettings&) override; |
|||
|
|||
std::unordered_map<std::string, Address> m_toAddress; |
|||
std::unordered_map<Address, std::string> m_toName; |
|||
}; |
|||
|
|||
} |
|||
} |
@ -0,0 +1,95 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<ui version="4.0"> |
|||
<class>OtherAccounts</class> |
|||
<widget class="QDialog" name="OtherAccounts"> |
|||
<property name="geometry"> |
|||
<rect> |
|||
<x>0</x> |
|||
<y>0</y> |
|||
<width>511</width> |
|||
<height>508</height> |
|||
</rect> |
|||
</property> |
|||
<property name="windowTitle"> |
|||
<string>Dialog</string> |
|||
</property> |
|||
<layout class="QVBoxLayout" name="verticalLayout"> |
|||
<item> |
|||
<widget class="QTextEdit" name="accounts"> |
|||
<property name="placeholderText"> |
|||
<string>Write the accounts you wish to name here, one address/name pair per line, the name following the address split only be a single space character.</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item> |
|||
<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="cancel"> |
|||
<property name="text"> |
|||
<string>Cancel</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item> |
|||
<widget class="QPushButton" name="create"> |
|||
<property name="text"> |
|||
<string>&Import</string> |
|||
</property> |
|||
<property name="default"> |
|||
<bool>true</bool> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
</layout> |
|||
</item> |
|||
</layout> |
|||
</widget> |
|||
<resources/> |
|||
<connections> |
|||
<connection> |
|||
<sender>create</sender> |
|||
<signal>clicked()</signal> |
|||
<receiver>OtherAccounts</receiver> |
|||
<slot>accept()</slot> |
|||
<hints> |
|||
<hint type="sourcelabel"> |
|||
<x>462</x> |
|||
<y>484</y> |
|||
</hint> |
|||
<hint type="destinationlabel"> |
|||
<x>449</x> |
|||
<y>504</y> |
|||
</hint> |
|||
</hints> |
|||
</connection> |
|||
<connection> |
|||
<sender>cancel</sender> |
|||
<signal>clicked()</signal> |
|||
<receiver>OtherAccounts</receiver> |
|||
<slot>reject()</slot> |
|||
<hints> |
|||
<hint type="sourcelabel"> |
|||
<x>381</x> |
|||
<y>483</y> |
|||
</hint> |
|||
<hint type="destinationlabel"> |
|||
<x>351</x> |
|||
<y>506</y> |
|||
</hint> |
|||
</hints> |
|||
</connection> |
|||
</connections> |
|||
</ui> |
@ -0,0 +1,66 @@ |
|||
/*
|
|||
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 OurAccounts.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include "OurAccounts.h" |
|||
#include <libdevcore/Log.h> |
|||
#include <libethereum/Client.h> |
|||
#include <libethcore/KeyManager.h> |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace az; |
|||
using namespace eth; |
|||
|
|||
DEV_AZ_NOTE_PLUGIN(OurAccounts); |
|||
|
|||
OurAccounts::OurAccounts(MainFace* _m): |
|||
AccountNamerPlugin(_m, "OurAccounts") |
|||
{ |
|||
connect(main(), SIGNAL(keyManagerChanged()), SLOT(updateNames())); |
|||
updateNames(); |
|||
} |
|||
|
|||
OurAccounts::~OurAccounts() |
|||
{ |
|||
} |
|||
|
|||
std::string OurAccounts::toName(Address const& _a) const |
|||
{ |
|||
return main()->keyManager().accountName(_a); |
|||
} |
|||
|
|||
Address OurAccounts::toAddress(std::string const& _n) const |
|||
{ |
|||
if (m_names.count(_n)) |
|||
return m_names.at(_n); |
|||
return Address(); |
|||
} |
|||
|
|||
Addresses OurAccounts::knownAddresses() const |
|||
{ |
|||
return main()->keyManager().accounts(); |
|||
} |
|||
|
|||
void OurAccounts::updateNames() |
|||
{ |
|||
m_names.clear(); |
|||
for (Address const& i: main()->keyManager().accounts()) |
|||
m_names[main()->keyManager().accountName(i)] = i; |
|||
} |
@ -0,0 +1,52 @@ |
|||
/*
|
|||
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 OurAccounts.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include "MainFace.h" |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace az |
|||
{ |
|||
|
|||
class OurAccounts: public QObject, public AccountNamerPlugin |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
OurAccounts(MainFace* _m); |
|||
~OurAccounts(); |
|||
|
|||
protected: |
|||
std::string toName(Address const& _a) const override; |
|||
Address toAddress(std::string const& _n) const override; |
|||
Addresses knownAddresses() const override; |
|||
|
|||
private slots: |
|||
void updateNames(); |
|||
|
|||
private: |
|||
std::unordered_map<std::string, Address> m_names; |
|||
}; |
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue