diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..eabf805c76f445e124045a5cb504af3b177efd7f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/ucoinpy"] + path = lib/ucoinpy + url = https://github.com/ucoin-io/ucoin-python-api.git diff --git a/Makefile b/Makefile index 9988c5fc25b16e771097368980887ab7cc436988..22ff3a6855eb1366a130cb1eef6a5acbce66c4f7 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ RESOURCE_DIR = res/ui COMPILED_DIR = src/cutecoin/gen_resources #UI files to compile -UI_FILES = mainwindow.ui addAccountDialog.ui addCommunityDialog.ui communityTabWidget.ui issuanceDialog.ui transferDialog.ui addContactDialog.ui +UI_FILES = mainwindow.ui accountConfigurationDialog.ui communityConfigurationDialog.ui communityTabWidget.ui issuanceDialog.ui transferDialog.ui addContactDialog.ui communityParametersWidget.ui #Qt resource files to compile RESOURCES = diff --git a/README.md b/README.md index 55f9908d70c8ffbe1f0369821778740af07a3acd..03af4efea8f871d884bd7134e5b51e2726ebef65 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Qt Client for [Ucoin](http://www.ucoin.io) project. * Communities viewing * Coins issuance * Coins Transfer + * cx_freeze deployment ### Work in progress (dev branch) * Contacts management diff --git a/lib/ucoinpy b/lib/ucoinpy new file mode 160000 index 0000000000000000000000000000000000000000..4a17d70b2e588bbda52a414977f132853b0900f4 --- /dev/null +++ b/lib/ucoinpy @@ -0,0 +1 @@ +Subproject commit 4a17d70b2e588bbda52a414977f132853b0900f4 diff --git a/res/ui/accountConfiguration.ui b/res/ui/accountConfiguration.ui deleted file mode 100644 index d1b43c6a2f5392f290b38b1eb36067b3a22c03d6..0000000000000000000000000000000000000000 --- a/res/ui/accountConfiguration.ui +++ /dev/null @@ -1,98 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>Dialog</class> - <widget class="QDialog" name="Dialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>400</width> - <height>300</height> - </rect> - </property> - <property name="windowTitle"> - <string>Dialog</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QGroupBox" name="groupBox"> - <property name="title"> - <string>Account parameters</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Account name</string> - </property> - </widget> - </item> - <item> - <widget class="QLineEdit" name="lineEdit"/> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>PGPKey </string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </widget> - </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>Dialog</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>Dialog</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> diff --git a/res/ui/addAccountDialog.ui b/res/ui/accountConfigurationDialog.ui similarity index 67% rename from res/ui/addAccountDialog.ui rename to res/ui/accountConfigurationDialog.ui index 8cba07b0c43a4b5bf83c90614903a6e083c12533..0b1edafa95f2de909aae8e2046ed6425257ff400 100644 --- a/res/ui/addAccountDialog.ui +++ b/res/ui/accountConfigurationDialog.ui @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>AddAccountDialog</class> - <widget class="QDialog" name="AddAccountDialog"> + <class>AccountConfigurationDialog</class> + <widget class="QDialog" name="AccountConfigurationDialog"> <property name="geometry"> <rect> <x>0</x> @@ -33,7 +33,7 @@ </widget> </item> <item> - <widget class="QLineEdit" name="accountName"/> + <widget class="QLineEdit" name="edit_accountName"/> </item> </layout> </item> @@ -47,7 +47,7 @@ </widget> </item> <item> - <widget class="QComboBox" name="pgpKeysList"/> + <widget class="QComboBox" name="combo_keysList"/> </item> </layout> </item> @@ -61,19 +61,23 @@ </property> <layout class="QVBoxLayout" name="verticalLayout_3"> <item> - <widget class="QListView" name="communitiesList"/> + <widget class="QListView" name="list_communities"> + <property name="contextMenuPolicy"> + <enum>Qt::DefaultContextMenu</enum> + </property> + </widget> </item> <item> <layout class="QHBoxLayout" name="horizontalLayout_3"> <item> - <widget class="QPushButton" name="addCommunity"> + <widget class="QPushButton" name="button_addCommunity"> <property name="text"> <string>Add a community</string> </property> </widget> </item> <item> - <widget class="QPushButton" name="removeCommunity"> + <widget class="QPushButton" name="button_removeCommunity"> <property name="text"> <string>Remove selected community</string> </property> @@ -101,7 +105,7 @@ <connection> <sender>buttonBox</sender> <signal>accepted()</signal> - <receiver>AddAccountDialog</receiver> + <receiver>AccountConfigurationDialog</receiver> <slot>accept()</slot> <hints> <hint type="sourcelabel"> @@ -117,7 +121,7 @@ <connection> <sender>buttonBox</sender> <signal>rejected()</signal> - <receiver>AddAccountDialog</receiver> + <receiver>AccountConfigurationDialog</receiver> <slot>reject()</slot> <hints> <hint type="sourcelabel"> @@ -131,9 +135,9 @@ </hints> </connection> <connection> - <sender>addCommunity</sender> + <sender>button_addCommunity</sender> <signal>clicked()</signal> - <receiver>AddAccountDialog</receiver> + <receiver>AccountConfigurationDialog</receiver> <slot>openAddCommunityDialog()</slot> <hints> <hint type="sourcelabel"> @@ -146,9 +150,43 @@ </hint> </hints> </connection> + <connection> + <sender>button_removeCommunity</sender> + <signal>clicked()</signal> + <receiver>AccountConfigurationDialog</receiver> + <slot>actionRemoveCommunity()</slot> + <hints> + <hint type="sourcelabel"> + <x>290</x> + <y>237</y> + </hint> + <hint type="destinationlabel"> + <x>199</x> + <y>149</y> + </hint> + </hints> + </connection> + <connection> + <sender>list_communities</sender> + <signal>doubleClicked(QModelIndex)</signal> + <receiver>AccountConfigurationDialog</receiver> + <slot>openEditCommunityDialog(QModelIndex)</slot> + <hints> + <hint type="sourcelabel"> + <x>199</x> + <y>180</y> + </hint> + <hint type="destinationlabel"> + <x>199</x> + <y>149</y> + </hint> + </hints> + </connection> </connections> <slots> <slot>openAddCommunityDialog()</slot> <slot>keyChanged(int)</slot> + <slot>actionRemoveCommunity()</slot> + <slot>openEditCommunityDialog(QModelIndex)</slot> </slots> </ui> diff --git a/res/ui/addContactDialog.ui b/res/ui/addContactDialog.ui new file mode 100644 index 0000000000000000000000000000000000000000..73524bfafe9f52702e1b804972077c38e32e08f5 --- /dev/null +++ b/res/ui/addContactDialog.ui @@ -0,0 +1,145 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>AddContactDialog</class> + <widget class="QDialog" name="AddContactDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>228</width> + <height>134</height> + </rect> + </property> + <property name="windowTitle"> + <string>Add a contact</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Nom</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="edit_name"/> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Fingerprint</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="edit_fingerprint"/> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <property name="topMargin"> + <number>0</number> + </property> + <item> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Email</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="edit_email"/> + </item> + </layout> + </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>AddContactDialog</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>AddContactDialog</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> + <connection> + <sender>edit_fingerprint</sender> + <signal>textChanged(QString)</signal> + <receiver>AddContactDialog</receiver> + <slot>fingerprintEdited()</slot> + <hints> + <hint type="sourcelabel"> + <x>145</x> + <y>52</y> + </hint> + <hint type="destinationlabel"> + <x>113</x> + <y>66</y> + </hint> + </hints> + </connection> + <connection> + <sender>edit_name</sender> + <signal>textChanged(QString)</signal> + <receiver>AddContactDialog</receiver> + <slot>nameEdited()</slot> + <hints> + <hint type="sourcelabel"> + <x>129</x> + <y>21</y> + </hint> + <hint type="destinationlabel"> + <x>113</x> + <y>66</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <slot>nameEdited()</slot> + <slot>fingerprintEdited()</slot> + </slots> +</ui> diff --git a/res/ui/addCommunityDialog.ui b/res/ui/communityConfigurationDialog.ui similarity index 75% rename from res/ui/addCommunityDialog.ui rename to res/ui/communityConfigurationDialog.ui index 9da5921fca17c04e52ffc24039fe45c03a262fe3..2d0233754558ed1b1c11ad4232d2f86037338a4f 100644 --- a/res/ui/addCommunityDialog.ui +++ b/res/ui/communityConfigurationDialog.ui @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>AddCommunityDialog</class> - <widget class="QDialog" name="AddCommunityDialog"> + <class>CommunityConfigurationDialog</class> + <widget class="QDialog" name="CommunityConfigurationDialog"> <property name="geometry"> <rect> <x>0</x> @@ -24,7 +24,11 @@ </property> <layout class="QVBoxLayout" name="verticalLayout_3"> <item> - <widget class="QTreeView" name="communityView"/> + <widget class="QTreeView" name="communityView"> + <property name="contextMenuPolicy"> + <enum>Qt::CustomContextMenu</enum> + </property> + </widget> </item> <item> <layout class="QHBoxLayout" name="horizontalLayout_3"> @@ -80,7 +84,7 @@ <connection> <sender>buttonBox</sender> <signal>accepted()</signal> - <receiver>AddCommunityDialog</receiver> + <receiver>CommunityConfigurationDialog</receiver> <slot>accept()</slot> <hints> <hint type="sourcelabel"> @@ -96,7 +100,7 @@ <connection> <sender>buttonBox</sender> <signal>rejected()</signal> - <receiver>AddCommunityDialog</receiver> + <receiver>CommunityConfigurationDialog</receiver> <slot>reject()</slot> <hints> <hint type="sourcelabel"> @@ -112,8 +116,8 @@ <connection> <sender>addButton</sender> <signal>clicked()</signal> - <receiver>AddCommunityDialog</receiver> - <slot>addCommunity()</slot> + <receiver>CommunityConfigurationDialog</receiver> + <slot>addNode()</slot> <hints> <hint type="sourcelabel"> <x>337</x> @@ -125,8 +129,25 @@ </hint> </hints> </connection> + <connection> + <sender>communityView</sender> + <signal>customContextMenuRequested(QPoint)</signal> + <receiver>CommunityConfigurationDialog</receiver> + <slot>showContextMenu(QPoint)</slot> + <hints> + <hint type="sourcelabel"> + <x>199</x> + <y>128</y> + </hint> + <hint type="destinationlabel"> + <x>199</x> + <y>149</y> + </hint> + </hints> + </connection> </connections> <slots> - <slot>addCommunity()</slot> + <slot>addNode()</slot> + <slot>showContextMenu(QPoint)</slot> </slots> </ui> diff --git a/res/ui/communityParametersWidget.ui b/res/ui/communityParametersWidget.ui new file mode 100644 index 0000000000000000000000000000000000000000..b183684ea42516e2f080adb1a32f33523bb40e35 --- /dev/null +++ b/res/ui/communityParametersWidget.ui @@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>CommunityParametersWidget</class> + <widget class="QWidget" name="CommunityParametersWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Trusted nodes :</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QListView" name="list_Trusted"/> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="leftMargin"> + <number>6</number> + </property> + <item> + <widget class="QPushButton" name="button_addTrusted"> + <property name="text"> + <string>Add</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="button_removeTrusted"> + <property name="text"> + <string>Remove</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Favorite transaction nodes :</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QListView" name="list_Transactions"/> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <property name="leftMargin"> + <number>6</number> + </property> + <item> + <widget class="QPushButton" name="button_addTransaction"> + <property name="text"> + <string>Add</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="button_removeTransaction"> + <property name="text"> + <string>Remove</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/res/ui/mainwindow.ui b/res/ui/mainwindow.ui index 3fc73a2798bfd9c2683c859a27fec5bc20c0ae18..bec0edc3a3ea1ec7b840c695c226f7ff018c02e8 100644 --- a/res/ui/mainwindow.ui +++ b/res/ui/mainwindow.ui @@ -117,7 +117,7 @@ <height>20</height> </rect> </property> - <widget class="QMenu" name="menuTr_File"> + <widget class="QMenu" name="menu_account"> <property name="title"> <string>Account</string> </property> @@ -126,18 +126,26 @@ <string>Change account</string> </property> </widget> + <addaction name="actionConfigure_parameters"/> <addaction name="menuChange_account"/> <addaction name="actionAdd_account"/> <addaction name="separator"/> <addaction name="actionSave"/> <addaction name="actionQuit"/> </widget> - <widget class="QMenu" name="menuEdit"> + <widget class="QMenu" name="menu_contacts"> <property name="title"> <string>Contacts</string> </property> + <widget class="QMenu" name="menu_contactsList"> + <property name="title"> + <string>Contacts</string> + </property> + <addaction name="separator"/> + </widget> <addaction name="separator"/> <addaction name="actionAdd_a_contact"/> + <addaction name="menu_contactsList"/> </widget> <widget class="QMenu" name="menuActions"> <property name="title"> @@ -145,8 +153,8 @@ </property> <addaction name="actionTransfer_money"/> </widget> - <addaction name="menuTr_File"/> - <addaction name="menuEdit"/> + <addaction name="menu_account"/> + <addaction name="menu_contacts"/> <addaction name="menuActions"/> </widget> <widget class="QStatusBar" name="statusbar"/> @@ -220,6 +228,11 @@ <string>Transfer money</string> </property> </action> + <action name="actionConfigure_parameters"> + <property name="text"> + <string>Configure</string> + </property> + </action> </widget> <resources/> <connections> @@ -287,10 +300,62 @@ </hint> </hints> </connection> + <connection> + <sender>actionAdd_a_contact</sender> + <signal>triggered()</signal> + <receiver>MainWindow</receiver> + <slot>openAddContactDialog()</slot> + <hints> + <hint type="sourcelabel"> + <x>-1</x> + <y>-1</y> + </hint> + <hint type="destinationlabel"> + <x>248</x> + <y>218</y> + </hint> + </hints> + </connection> + <connection> + <sender>actionConfigure_parameters</sender> + <signal>triggered()</signal> + <receiver>MainWindow</receiver> + <slot>openConfigureAccountDialog()</slot> + <hints> + <hint type="sourcelabel"> + <x>-1</x> + <y>-1</y> + </hint> + <hint type="destinationlabel"> + <x>248</x> + <y>218</y> + </hint> + </hints> + </connection> + <connection> + <sender>walletsList</sender> + <signal>clicked(QModelIndex)</signal> + <receiver>MainWindow</receiver> + <slot>refreshWalletContent(QModelIndex)</slot> + <hints> + <hint type="sourcelabel"> + <x>137</x> + <y>240</y> + </hint> + <hint type="destinationlabel"> + <x>248</x> + <y>218</y> + </hint> + </hints> + </connection> </connections> <slots> <slot>openAddAccountDialog()</slot> <slot>save()</slot> <slot>openTransferMoneyDialog()</slot> + <slot>openAddContactDialog()</slot> + <slot>openConfigureAccountDialog()</slot> + <slot>refreshMainWindow()</slot> + <slot>refreshWalletContent(QModelIndex)</slot> </slots> </ui> diff --git a/setup.py b/setup.py new file mode 100644 index 0000000000000000000000000000000000000000..56312076422a95e9248fb8c14b5af2e72d38b1f2 --- /dev/null +++ b/setup.py @@ -0,0 +1,47 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# source d'inspiration: http://wiki.wxpython.org/cx_freeze + +import sys, os +from cx_Freeze import setup, Executable + +############################################################################# +# preparation des options +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'lib'))) +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'src'))) +print(sys.path) +includes = ["sip", "re", "json", "logging", "hashlib", "os", "urllib", "ucoinpy"] +excludes = [] +packages = ["gnupg"] + +options = {"path": sys.path, + "includes": includes, + "excludes": excludes, + "packages": packages + } + +############################################################################# +# preparation des cibles +base = None +if sys.platform == "win32": + base = "Win32GUI" + +target = Executable( + script = "src/cutecoin/__init__.py", + base = base, + compress = True, + icon = None, + ) + +############################################################################# +# creation du setup +setup( + name = "cutecoin", + version = "0.3.0", + description = "UCoin client", + author = "Inso", + options = {"build_exe": options}, + executables = [target] + ) + diff --git a/src/cutecoin/core/__init__.py b/src/cutecoin/core/__init__.py index 7aa15265c0918069ab911b6b2b116ef4c4fc0b60..e435781346c0fe46b721b78891d330217baa408a 100644 --- a/src/cutecoin/core/__init__.py +++ b/src/cutecoin/core/__init__.py @@ -35,8 +35,8 @@ class Core(object): def addAccount(self, account): for a in self.accounts: - if a.pgpKeyId == account.pgpKeyId: - raise KeyAlreadyUsed(account, account.pgpKeyId, a) + if a.keyId == account.keyId: + raise KeyAlreadyUsed(account, account.keyId, a) self.accounts.append(account) self.currentAccount = account diff --git a/src/cutecoin/gen_resources/__init__.py b/src/cutecoin/gen_resources/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..82d70b56cad15bed8a6accdacfde0024af7e40a8 --- /dev/null +++ b/src/cutecoin/gen_resources/__init__.py @@ -0,0 +1,5 @@ +''' +Created on 11 mars 2014 + +@author: inso +''' diff --git a/src/cutecoin/gui/__init__.py b/src/cutecoin/gui/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..82d70b56cad15bed8a6accdacfde0024af7e40a8 --- /dev/null +++ b/src/cutecoin/gui/__init__.py @@ -0,0 +1,5 @@ +''' +Created on 11 mars 2014 + +@author: inso +''' diff --git a/src/cutecoin/gui/addAccountDialog.py b/src/cutecoin/gui/addAccountDialog.py deleted file mode 100644 index 3dcbca64d03f275c79d557388c8069ea67c1ca40..0000000000000000000000000000000000000000 --- a/src/cutecoin/gui/addAccountDialog.py +++ /dev/null @@ -1,60 +0,0 @@ -''' -Created on 2 févr. 2014 - -@author: inso -''' -from cutecoin.gen_resources.addAccountDialog_uic import Ui_AddAccountDialog -from PyQt5.QtWidgets import QDialog -from cutecoin.gui.addCommunityDialog import AddCommunityDialog -from cutecoin.models.account import Account -from cutecoin.models.account.communities import Communities -from cutecoin.models.account.communities.listModel import CommunitiesListModel - -import gnupg - - -class AddAccountDialog(QDialog, Ui_AddAccountDialog): - ''' - classdocs - ''' - - - def __init__(self, mainWindow): - ''' - Constructor - ''' - # Set up the user interface from Designer. - super(AddAccountDialog, self).__init__() - self.setupUi(self) - self.mainWindow = mainWindow - - self.buttonBox.accepted.connect(self.mainWindow.actionAddAccount) - - self.setData() - - def setData(self): - gpg = gnupg.GPG() - self.pgpKeysList.clear() - availableKeys = gpg.list_keys(True) - for key in availableKeys: - self.pgpKeysList.addItem(key['uids'][0]) - - self.account = Account.create(availableKeys[0]['keyid'], "", Communities()) - self.pgpKeysList.setEnabled(True) - self.pgpKeysList.currentIndexChanged[int].connect(self.keyChanged) - self.communityDialog = AddCommunityDialog(self) - - def openAddCommunityDialog(self): - self.communityDialog.setAccount(self.account) - self.communityDialog.exec_() - - def actionAddCommunity(self): - self.pgpKeysList.setEnabled(False) - self.pgpKeysList.disconnect() - self.communitiesList.setModel(CommunitiesListModel(self.account)) - - def keyChanged(self, keyIndex): - gpg = gnupg.GPG() - availableKeys = gpg.list_keys(True) - self.account.pgpKeyId = availableKeys[keyIndex]['keyid'] - diff --git a/src/cutecoin/gui/addCommunityDialog.py b/src/cutecoin/gui/addCommunityDialog.py deleted file mode 100644 index c9dc14df7f3699576c9d45fb2b71b3fe2a650b54..0000000000000000000000000000000000000000 --- a/src/cutecoin/gui/addCommunityDialog.py +++ /dev/null @@ -1,44 +0,0 @@ -''' -Created on 2 févr. 2014 - -@author: inso -''' -from cutecoin.gen_resources.addCommunityDialog_uic import Ui_AddCommunityDialog -from PyQt5.QtWidgets import QDialog, QErrorMessage -from cutecoin.models.community.treeModel import CommunityTreeModel -from cutecoin.models.node import MainNode -from cutecoin.core.exceptions import NotMemberOfCommunityError - -class AddCommunityDialog(QDialog, Ui_AddCommunityDialog): - ''' - classdocs - ''' - - - def __init__(self, accountDialog): - ''' - Constructor - ''' - super(AddCommunityDialog, self).__init__() - self.setupUi(self) - self.accountDialog = accountDialog - self.buttonBox.accepted.connect(self.accountDialog.actionAddCommunity) - - def setAccount(self, account): - self.account = account - - def addCommunity(self): - ''' - Add community slot - ''' - server = self.serverEdit.text() - port = self.portBox.value() - try: - community = self.account.communities.addCommunity(MainNode(server, port), self.account.keyFingerprint()) - self.account.wallets.addWallet(community) - self.communityView.setModel( CommunityTreeModel(community) ) - except NotMemberOfCommunityError as e: - QErrorMessage(self).showMessage(e.message) - - - diff --git a/src/cutecoin/gui/addContactDialog.py b/src/cutecoin/gui/addContactDialog.py new file mode 100644 index 0000000000000000000000000000000000000000..351cd26dc000a415d691613dd593a73e2208defd --- /dev/null +++ b/src/cutecoin/gui/addContactDialog.py @@ -0,0 +1,43 @@ +''' +Created on 2 févr. 2014 + +@author: inso +''' +import re +from PyQt5.QtWidgets import QDialog, QDialogButtonBox + + +from cutecoin.models.person import Person + +from cutecoin.gen_resources.addContactDialog_uic import Ui_AddContactDialog + +class AddContactDialog(QDialog, Ui_AddContactDialog): + ''' + classdocs + ''' + def __init__(self, account, parent=None): + ''' + Constructor + ''' + super(AddContactDialog, self).__init__() + self.setupUi(self) + self.account = account + self.mainWindow = parent + self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) + + + def accept(self): + name = self.edit_name.text() + fingerprint = self.edit_fingerprint.text() + email = self.edit_email.text() + self.account.addContact(Person(name, fingerprint, email)) + self.mainWindow.menu_contactsList.addAction(name) + self.close() + + def nameEdited(self, newName): + self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( len(newName) > 0 ) + + def fingerprintEdited(self, newFingerprint): + pattern = re.compile("([A-Z]|[0-9])+") + self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( pattern.match(newFingerprint) is not None ) + diff --git a/src/cutecoin/gui/configureAccountDialog.py b/src/cutecoin/gui/configureAccountDialog.py new file mode 100644 index 0000000000000000000000000000000000000000..99a6ef87f0b90f53d818b3da6ae160167a317932 --- /dev/null +++ b/src/cutecoin/gui/configureAccountDialog.py @@ -0,0 +1,100 @@ +''' +Created on 6 mars 2014 + +@author: inso +''' +from cutecoin.gen_resources.accountConfigurationDialog_uic import Ui_AccountConfigurationDialog +from cutecoin.gui.configureCommunityDialog import ConfigureCommunityDialog +from cutecoin.models.account.communities.listModel import CommunitiesListModel +from cutecoin.core.exceptions import KeyAlreadyUsed +from PyQt5.QtWidgets import QDialog, QErrorMessage +from cutecoin.models.account import Account +from cutecoin.models.account import Communities +import gnupg + + +class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog): + ''' + classdocs + ''' + + + def __init__(self, core, account): + ''' + Constructor + ''' + # Set up the user interface from Designer. + super(ConfigureAccountDialog, self).__init__() + self.setupUi(self) + self.account = account + self.core = core + if self.account is None: + self.setWindowTitle("New account") + else: + self.setWindowTitle("Configure " + self.account.name) + self.combo_keysList.setEnabled(False) + + self.setData() + + def setData(self): + gpg = gnupg.GPG() + self.combo_keysList.clear() + availableKeys = gpg.list_keys(True) + + if self.account is None: + self.account = Account.create(availableKeys[0]['keyid'], "", Communities()) + self.combo_keysList.currentIndexChanged[int].connect(self.keyChanged) + + for index, key in enumerate(availableKeys): + self.combo_keysList.addItem(key['uids'][0]) + if (key['keyid']) == self.account.keyId: + self.combo_keysList.setCurrentIndex(index) + + + self.list_communities.setModel(CommunitiesListModel(self.account)) + self.edit_accountName.setText(self.account.name) + + def openAddCommunityDialog(self): + dialog = ConfigureCommunityDialog(None) + dialog.buttonBox.accepted.connect(self.actionAddCommunity) + dialog.setAccount(self.account) + dialog.exec_() + + def actionAddCommunity(self): + self.combo_keysList.setEnabled(False) + self.combo_keysList.disconnect() + self.list_communities.setModel(CommunitiesListModel(self.account)) + + def actionRemoveCommunity(self): + for index in self.list_communities.selectedIndexes(): + community = self.account.communities.communitiesList[ index.row() ] + self.account.wallets.removeAllWalletsOf(community) + self.account.communities.communitiesList.pop(index.row()) + + self.list_communities.setModel( CommunitiesListModel(self.account )) + + def actionEditCommunity(self): + self.list_communities.setModel(CommunitiesListModel(self.account)) + + def openEditCommunityDialog(self, index): + community = self.account.communities.communitiesList[index.row()] + dialog = ConfigureCommunityDialog(community) + dialog.buttonBox.accepted.connect(self.actionEditCommunity) + dialog.setAccount(self.account) + dialog.exec_() + + def keyChanged(self, keyIndex): + gpg = gnupg.GPG() + availableKeys = gpg.list_keys(True) + self.account.keyId = availableKeys[keyIndex]['keyid'] + + def accept(self): + if self.account not in self.core.accounts: + self.account.name = self.edit_accountName.text() + try: + self.core.addAccount(self.account) + except KeyAlreadyUsed as e: + QErrorMessage(self).showMessage(e.message) + self.close() + + diff --git a/src/cutecoin/gui/configureCommunityDialog.py b/src/cutecoin/gui/configureCommunityDialog.py new file mode 100644 index 0000000000000000000000000000000000000000..b3c91865ae1b5a5fe265912d6b8437c93d23fb39 --- /dev/null +++ b/src/cutecoin/gui/configureCommunityDialog.py @@ -0,0 +1,74 @@ +''' +Created on 8 mars 2014 + +@author: inso +''' +from cutecoin.gen_resources.communityConfigurationDialog_uic import Ui_CommunityConfigurationDialog +from PyQt5.QtWidgets import QDialog, QErrorMessage, QMenu +from cutecoin.models.community.treeModel import CommunityTreeModel +from cutecoin.models.node import TrustedNode +from cutecoin.core.exceptions import NotMemberOfCommunityError + +class ConfigureCommunityDialog(QDialog, Ui_CommunityConfigurationDialog): + ''' + classdocs + ''' + + + def __init__(self, community): + ''' + Constructor + ''' + super(ConfigureCommunityDialog, self).__init__() + self.setupUi(self) + self.community = community + if self.community is None: + self.setWindowTitle("Add a community") + else: + self.setWindowTitle("Configure community " + self.community.currency) + self.setData() + + def setData(self): + if self.community is not None: + self.communityView.setModel( CommunityTreeModel(self.community)) + + def setAccount(self, account): + self.account = account + + def addNode(self): + ''' + Add node slot + ''' + server = self.serverEdit.text() + port = self.portBox.value() + if self.community == None: + try: + self.community = self.account.communities.addCommunity(TrustedNode(server, port), self.account.keyFingerprint()) + self.account.wallets.addWallet(self.community) + self.communityView.setModel( CommunityTreeModel(self.community) ) + except NotMemberOfCommunityError as e: + QErrorMessage(self).showMessage(e.message) + else: + self.community.addTrustedNode( TrustedNode(server, port )) + self.communityView.setModel( CommunityTreeModel(self.community )) + + def showContextMenu(self, point): + menu = QMenu() + action = menu.addAction("Delete", self.removeNode) + if self.community is not None: + if len(self.community.trustedNodes) == 1: + action.setEnabled(False) + menu.exec_(self.communityView.mapToGlobal(point)) + + def removeNode(self): + for index in self.communityView.selectedIndexes(): + self.community.trustedNodes.pop(index.row()) + + self.communityView.setModel( CommunityTreeModel(self.community )) + + def accept(self): + self.close() + + + + diff --git a/src/cutecoin/gui/mainWindow.py b/src/cutecoin/gui/mainWindow.py index 1388d900996f0246d5df979c3046a23004ce7d3e..bfcb26e91ff83acf1454923de2ee128e3d7c00b2 100644 --- a/src/cutecoin/gui/mainWindow.py +++ b/src/cutecoin/gui/mainWindow.py @@ -4,16 +4,16 @@ Created on 1 févr. 2014 @author: inso ''' from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow -from PyQt5.QtWidgets import QMainWindow, QAction, QErrorMessage +from PyQt5.QtWidgets import QMainWindow, QAction, QErrorMessage, QDialogButtonBox from PyQt5.QtCore import QSignalMapper -from cutecoin.gui.addAccountDialog import AddAccountDialog +from cutecoin.gui.configureAccountDialog import ConfigureAccountDialog from cutecoin.gui.transferMoneyDialog import TransferMoneyDialog from cutecoin.gui.communityTabWidget import CommunityTabWidget +from cutecoin.gui.addContactDialog import AddContactDialog from cutecoin.models.account.wallets.listModel import WalletsListModel from cutecoin.models.wallet.listModel import WalletListModel from cutecoin.models.transaction.sentListModel import SentListModel from cutecoin.models.transaction.receivedListModel import ReceivedListModel -from cutecoin.core.exceptions import KeyAlreadyUsed import logging @@ -34,18 +34,10 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.refreshMainWindow() def openAddAccountDialog(self): - self.addAccountDialog = AddAccountDialog(self) - self.addAccountDialog.setData() - self.addAccountDialog.exec_() + dialog = ConfigureAccountDialog(self.core, None) + dialog.buttonBox.button(QDialogButtonBox.Ok).clicked.connect(self.refreshMainWindow) + dialog.exec_() - def actionAddAccount(self): - self.addAccountDialog.account.name = self.addAccountDialog.accountName.text() - try: - self.core.addAccount(self.addAccountDialog.account) - except KeyAlreadyUsed as e: - QErrorMessage(self).showMessage(e.message) - - self.refreshMainWindow() def save(self): self.core.save() @@ -55,10 +47,16 @@ class MainWindow(QMainWindow, Ui_MainWindow): logging.info('Changing account to ' + self.core.currentAccount.name) self.refreshMainWindow() - def openTransferMoneyDialog(self): - transferMoneyDialog = TransferMoneyDialog(self.core.currentAccount) - transferMoneyDialog.exec_() + TransferMoneyDialog(self.core.currentAccount).exec_() + + def openAddContactDialog(self): + AddContactDialog(self.core.currentAccount, self).exec_() + + def openConfigureAccountDialog(self): + dialog = ConfigureAccountDialog(self.core, self.core.currentAccount) + dialog.buttonBox.button(QDialogButtonBox.Ok).clicked.connect(self.refreshMainWindow) + dialog.exec_() ''' Refresh main window @@ -82,11 +80,24 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.accountTabs.setEnabled(True) self.accountNameLabel.setText("Current account : " + self.core.currentAccount.name) self.walletsList.setModel(WalletsListModel(self.core.currentAccount)) - self.walletContent.setModel(WalletListModel(self.core.currentAccount.wallets.walletsList[0])) + self.communitiesTab.clear() for community in self.core.currentAccount.communities.communitiesList: communityTab = CommunityTabWidget(self.core.currentAccount, community) self.communitiesTab.addTab(communityTab, community.name()) + + self.menu_contactsList.clear() + for contact in self.core.currentAccount.contacts: + self.menu_contactsList.addAction(contact.name) + self.transactionsSent.setModel(SentListModel(self.core.currentAccount)) self.transactionsReceived.setModel(ReceivedListModel(self.core.currentAccount)) + + def refreshWalletContent(self, index): + if index.isValid(): + currentWallet = self.core.currentAccount.wallets.walletsList[index.row()] + self.walletContent.setModel(WalletListModel(currentWallet)) + else: + self.walletContent.setModel(WalletListModel([])) + diff --git a/src/cutecoin/gui/transferMoneyDialog.py b/src/cutecoin/gui/transferMoneyDialog.py index 4e66769462650d2fff2ecebfe8ae47945d019bcf..3ad80f976dcae2d9627daf6cba5b4cc0e565ce2a 100644 --- a/src/cutecoin/gui/transferMoneyDialog.py +++ b/src/cutecoin/gui/transferMoneyDialog.py @@ -6,7 +6,7 @@ Created on 2 févr. 2014 import logging from math import pow -from PyQt5.QtWidgets import QDialog,QFrame, QSlider, QLabel, QDialogButtonBox +from PyQt5.QtWidgets import QDialog,QFrame, QSlider, QLabel, QDialogButtonBox, QErrorMessage from PyQt5.QtCore import Qt, QSignalMapper @@ -31,6 +31,9 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): for wallet in sender.wallets.walletsList: self.comboBox_wallets.addItem(wallet.getText()) + for contact in sender.contacts: + self.comboBox_contact.addItem(contact.name) + self.refreshTransaction(sender.wallets.walletsList[0]) @@ -68,8 +71,7 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): if self.radio_keyFingerprint.isChecked(): recipient = Person("", self.edit_keyFingerprint.text(), "") else: - #TODO: Manage contacts - recipient = Person("", self.edit_keyFingerprint.text(), "") + recipient = self.sender.contacts[self.comboBox_contact.currentIndex()] if self.radio_nodeAddress.isChecked(): node = Node(self.edit_nodeAddress.text(), int(self.edit_port.text())) @@ -79,7 +81,10 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): message = self.edit_message.text() #TODO: Transfer money, and validate the window if no error happened - print(self.sender.transferCoins(node, recipient, sentCoins, message)) + if self.sender.transferCoins(node, recipient, sentCoins, message): + self.close() + else: + QErrorMessage(self).showMessage("Cannot transfer coins.") def changeDisplayedWallet(self, index): wallet = self.sender.wallets.walletsList[index] diff --git a/src/cutecoin/models/account/__init__.py b/src/cutecoin/models/account/__init__.py index e780da647ebb9b466a31f49c860d7a69707afacc..ea975aa9ba2591fe27c1dee0934db71de9dafd86 100644 --- a/src/cutecoin/models/account/__init__.py +++ b/src/cutecoin/models/account/__init__.py @@ -12,29 +12,31 @@ from cutecoin.models.account.wallets import Wallets from cutecoin.models.account.communities import Communities from cutecoin.models.community import Community from cutecoin.models.transaction import factory +from cutecoin.models.person import Person class Account(object): ''' - An account is specific to a pgpKey. - Each account has only one pgpKey, and a key can + An account is specific to a key. + Each account has only one key, and a key can be locally referenced by only one account. ''' - def __init__(self, pgpKeyId, name, communities, wallets): + def __init__(self, keyId, name, communities, wallets, contacts): ''' Constructor ''' - self.pgpKeyId = pgpKeyId + self.keyId = keyId self.name = name self.communities = communities self.wallets = wallets + self.contacts = contacts @classmethod - def create(cls, pgpKeyId, name, communities): + def create(cls, keyId, name, communities): ''' Constructor ''' wallets = Wallets() - account = cls(pgpKeyId, name, communities, wallets) + account = cls(keyId, name, communities, wallets, []) for community in account.communities.communitiesList: wallet = account.wallets.addWallet(community.currency) wallet.refreshCoins(community, account.keyFingerprint()) @@ -42,27 +44,41 @@ class Account(object): @classmethod def load(cls, jsonData): - pgpKeyId = jsonData['pgpKeyId'] + keyId = jsonData['keyId'] name = jsonData['name'] communities = Communities() wallets = Wallets() - account = cls(pgpKeyId, name, communities, wallets) + contacts = [] + + for contactData in jsonData['contacts']: + contacts.append(Person.fromJson(contactData)) + + account = cls(keyId, name, communities, wallets, contacts) for communityData in jsonData['communities']: account.communities.communitiesList.append(Community.load(communityData, account)) return account - def addWallet(name, currency): + def __eq__(self, other): + if other is not None: + return other.keyId == self.keyId + else: + return False + + def addWallet(self, name, currency): self.wallets.addWallet(name, currency) + def addContact(self, person): + self.contacts.append(person) + def keyFingerprint(self): gpg = gnupg.GPG() availableKeys = gpg.list_keys() - logging.debug(self.pgpKeyId) + logging.debug(self.keyId) for k in availableKeys: logging.debug(k) - if k['keyid'] == self.pgpKeyId: + if k['keyid'] == self.keyId: return k['fingerprint'] return "" @@ -113,10 +129,17 @@ class Account(object): transfer = ucoin.wrappers.transactions.RawTransfer(self.keyFingerprint(), recipient.fingerprint, coins, message, keyid=self.pgpKeyId, server=node.server, port=node.port) return transfer() + def jsonifyContacts(self): + data = [] + for p in self.contacts: + data.append(p.jsonify()) + return data + def jsonify(self): data = {'name' : self.name, - 'pgpKeyId' : self.pgpKeyId, - 'communities' : self.communities.jsonify(self.wallets)} + 'keyId' : self.keyId, + 'communities' : self.communities.jsonify(self.wallets), + 'contacts' : self.jsonifyContacts()} return data diff --git a/src/cutecoin/models/account/communities/__init__.py b/src/cutecoin/models/account/communities/__init__.py index 0e04bb60ca47c43f1526fbd512d570bb78d350ff..180d560480b0c9d285a7fe737f151ed8a06bac1f 100644 --- a/src/cutecoin/models/account/communities/__init__.py +++ b/src/cutecoin/models/account/communities/__init__.py @@ -20,8 +20,8 @@ class Communities(object): def addCommunity(self, mainNode, keyFingerprint): ''' - Add a community with a mainNode and the pgpFingerprint of the account - Check if the pgpFingerprint is present in the community members list + Add a community with a mainNode and the fingerprint of the account + Check if the fingerprint is present in the community members list If its not, the account isnt added and an error is raised. ''' community = Community.create(mainNode) diff --git a/src/cutecoin/models/account/wallets/__init__.py b/src/cutecoin/models/account/wallets/__init__.py index 05f7c806f190cde3cc3d8b71e814badca9f4117c..c6b5dfd1734f24d60f11dc61034870708a9209b8 100644 --- a/src/cutecoin/models/account/wallets/__init__.py +++ b/src/cutecoin/models/account/wallets/__init__.py @@ -37,6 +37,12 @@ class Wallets(object): return w return None + def removeAllWalletsOf(self, community): + for wallet in self.walletsList: + if wallet.community == community: + self.walletsList.remove(wallet) + + def jsonify(self, community): ''' Return the list of wallets in a key:value form. diff --git a/src/cutecoin/models/community/__init__.py b/src/cutecoin/models/community/__init__.py index adab6a1a29c310cd6eabd4bedc1ebd723badff8f..ebc0570c2635696e0e7e0bd9fa4c28c236b0f51f 100644 --- a/src/cutecoin/models/community/__init__.py +++ b/src/cutecoin/models/community/__init__.py @@ -9,20 +9,20 @@ import hashlib import json import logging -from cutecoin.models.node import MainNode +from cutecoin.models.node import TrustedNode from cutecoin.models.wallet import Wallet class Community(object): ''' classdocs ''' - def __init__(self, knownNodes): + def __init__(self, trustedNodes): ''' A community is a group of nodes using the same currency. They are all using the same amendment and are syncing their datas. An account is a member of a community if he is a member of the current amendment. ''' - self.knownNodes = knownNodes + self.trustedNodes = trustedNodes currentAmendment = self.ucoinRequest(ucoin.hdc.amendments.Current()) self.currency = currentAmendment['currency'] @@ -37,7 +37,7 @@ class Community(object): def load(cls, jsonData, account): knownNodes = [] for nodeData in jsonData['nodes']: - knownNodes.append(MainNode(nodeData['server'], nodeData['port'])) + knownNodes.append(TrustedNode(nodeData['server'], nodeData['port'])) community = cls(knownNodes) @@ -59,7 +59,7 @@ class Community(object): return members def ucoinRequest(self, request, get_args={}): - for node in self.knownNodes: + for node in self.trustedNodes: logging.debug("Trying to connect to : " + node.getText()) request = node.use(request) return request.get(**get_args) @@ -103,7 +103,7 @@ class Community(object): def jsonifyNodesList(self): data = [] - for node in self.knownNodes: + for node in self.trustedNodes: data.append(node.jsonify()) return data diff --git a/src/cutecoin/models/community/membersListModel.py b/src/cutecoin/models/community/membersListModel.py index b017ba32c9806c9f0bb8545a3fec598835f319ea..1dcf0f13151f07cd87eefe49c8d5ec4043ad9e73 100644 --- a/src/cutecoin/models/community/membersListModel.py +++ b/src/cutecoin/models/community/membersListModel.py @@ -25,7 +25,6 @@ class MembersListModel(QAbstractListModel): return len(self.members) def data(self,index,role): - if role == Qt.DisplayRole: row=index.row() value = self.members[row].name diff --git a/src/cutecoin/models/community/treeModel.py b/src/cutecoin/models/community/treeModel.py index 2180564f5f657fc441606f56fd34251457c0b01e..c916dadd0d22568ad1073fb3717a1fb2e34b5c0d 100644 --- a/src/cutecoin/models/community/treeModel.py +++ b/src/cutecoin/models/community/treeModel.py @@ -89,7 +89,7 @@ class CommunityTreeModel(QAbstractItemModel): def refreshTreeNodes(self): logging.debug("root : " + self.rootItem.data(0)) - for mainNode in self.community.knownNodes: + for mainNode in self.community.trustedNodes: mainNodeItem = MainNodeItem(mainNode, self.rootItem) logging.debug("mainNode : " + mainNode.getText() + " / " + mainNodeItem.data(0)) self.rootItem.appendChild(mainNodeItem) diff --git a/src/cutecoin/models/node/__init__.py b/src/cutecoin/models/node/__init__.py index 41337c1be885cf1d700e0367b6be67b39e7696e9..ccf7e8e11eb970331d2620c5da7e0d6039f29f3c 100644 --- a/src/cutecoin/models/node/__init__.py +++ b/src/cutecoin/models/node/__init__.py @@ -24,9 +24,9 @@ class Node(object): return self.server + ":" + str(self.port) -class MainNode(Node): +class TrustedNode(Node): ''' - MainNode is a node the community is reading to get informations. + TrustedNode is a node the community is reading to get informations. The account sends data one of the community main nodes. ''' def downstreamPeers(self): diff --git a/src/cutecoin/models/person/__init__.py b/src/cutecoin/models/person/__init__.py index dc913e7ad62e1459aea8b4168dbd17295f92feeb..30e913129d9e1f579c621e5c46a52cbf8bab65bc 100644 --- a/src/cutecoin/models/person/__init__.py +++ b/src/cutecoin/models/person/__init__.py @@ -24,12 +24,12 @@ class Person(object): @classmethod - def lookup(cls, pgpFingerprint, community): + def lookup(cls, fingerprint, community): ''' - Create a person from the pgpFingerprint found in a community + Create a person from the fngerprint found in a community ''' keys = community.ucoinRequest(ucoin.pks.Lookup(), - get_args={'search':"0x"+pgpFingerprint, 'op':'index'})['keys'] + get_args={'search':"0x"+fingerprint, 'op':'index'})['keys'] if len(keys) > 0: json = keys[0]['key'] name = json['name'] @@ -37,7 +37,7 @@ class Person(object): email = json['email'] return cls(name, fingerprint, email) else: - raise PersonNotFoundError(pgpFingerprint, "pgpFingerprint", community) + raise PersonNotFoundError(fingerprint, "fingerprint", community) return None @classmethod @@ -46,7 +46,13 @@ class Person(object): Create a person from json data ''' name = jsonPerson['name'] - pgpFingerprint = jsonPerson['fingerprint'] + fingerprint = jsonPerson['fingerprint'] email = jsonPerson['email'] - return cls(name, pgpFingerprint, email) + return cls(name, fingerprint, email) + + def jsonify(self): + data = {'name' : self.name, + 'fingerprint' : self.fingerprint, + 'email' : self.email} + return data diff --git a/src/cutecoin/models/wallet/__init__.py b/src/cutecoin/models/wallet/__init__.py index 65386c5187ba7f1d7c10850066017407f4fc71fa..1858a91912cbeaf2b4ea4354e81abb3a0a6a57c3 100644 --- a/src/cutecoin/models/wallet/__init__.py +++ b/src/cutecoin/models/wallet/__init__.py @@ -46,8 +46,9 @@ class Wallet(object): value += coin.value() return value - def refreshCoins(self, pgpFingerprint): - dataList = self.community.ucoinRequest(ucoin.hdc.coins.List({'pgp_fingerprint':pgpFingerprint})) + #TODO: Refresh coins when changing current account + def refreshCoins(self, fingerprint): + dataList = self.community.ucoinRequest(ucoin.hdc.coins.List({'pgp_fingerprint':fingerprint})) for issaunces in dataList['coins']: issuer = issaunces['issuer'] for coinsIds in issaunces['ids']: