Skip to content
Snippets Groups Projects
Commit 4bbc4170 authored by inso's avatar inso
Browse files

Ajout d'un compte et listing des wallets

parent d6e57e62
No related branches found
No related tags found
No related merge requests found
Showing
with 240 additions and 71 deletions
......@@ -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
UI_FILES = mainwindow.ui addAccountDialog.ui addCommunityDialog.ui communityTabWidget.ui
#Qt resource files to compile
RESOURCES =
......@@ -33,4 +33,4 @@ $(COMPILED_DIR)/%_rc.py : $(RESOURCE_DIR)/%.qrc
$(PYRCC) $< -o $@
clean :
$(RM) $(COMPILED_UI) $(COMPILED_RESOURCES) $(COMPILED_UI:.py=.pyc) $(COMPILED_RESOURCES:.py=.pyc)
\ No newline at end of file
$(RM) $(COMPILED_UI) $(COMPILED_RESOURCES) $(COMPILED_UI:.py=.pyc) $(COMPILED_RESOURCES:.py=.pyc)
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CommunityTabWidget</class>
<widget class="QWidget" name="CommunityTabWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>communityTabWidget</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Members</string>
</property>
</widget>
</item>
<item>
<widget class="QListView" name="communityMembers_2"/>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Last issuance</string>
</property>
</widget>
</item>
<item>
<widget class="QListView" name="listView"/>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -32,12 +32,12 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<widget class="QTabWidget" name="accountTabs">
<property name="enabled">
<bool>false</bool>
</property>
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="walletsTab">
<attribute name="title">
......@@ -87,56 +87,16 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="communitiesTab">
<widget class="QWidget" name="communitiesWidget">
<attribute name="title">
<string>Communities</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QTabWidget" name="tabWidget_2">
<widget class="QTabWidget" name="communitiesTab">
<property name="currentIndex">
<number>1</number>
<number>-1</number>
</property>
<widget class="QWidget" name="ucoinTab">
<attribute name="title">
<string>Ucoin</string>
</attribute>
</widget>
<widget class="QWidget" name="freecoinTab">
<attribute name="title">
<string>FreeCoin</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Members</string>
</property>
</widget>
</item>
<item>
<widget class="QListView" name="communityMembers"/>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Last issuance</string>
</property>
</widget>
</item>
<item>
<widget class="QListView" name="communityIssuance"/>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
......
......@@ -13,7 +13,7 @@ class Core(object):
'''
Constructor
'''
self.account = []
self.accounts = []
self.currentAccount = None
config.parseArguments(argv)
AppData().load(self)
......
......@@ -5,6 +5,7 @@ Created on 7 févr. 2014
'''
import json
from cutecoin.core import config
import os
class AppData(object):
'''
......@@ -18,10 +19,10 @@ class AppData(object):
'''
def load(self, core):
json_data=open(config.data['home'])
data = json.load(json_data)
json_data.close()
data['accounts']
if (os.path.exists(config.data['home'])):
json_data=open(config.data['home'], 'w+')
data = json.load(json_data)
json_data.close()
def save(self, core):
......
......@@ -43,7 +43,7 @@ class AddAccountDialog(QDialog, Ui_AddAccountDialog):
self.account = Account(self.pgpkeyList.currentText(), "", Communities())
def openAddCommunityDialog(self):
self.dialog.setCommunities(self.account.communities)
self.dialog.setAccount(self.account)
self.dialog.exec_()
def actionAddCommunity(self):
......
......@@ -23,8 +23,8 @@ class AddCommunityDialog(QDialog, Ui_AddCommunityDialog):
self.accountDialog = accountDialog
self.buttonBox.accepted.connect(self.accountDialog.actionAddCommunity)
def setCommunities(self, communities):
self.communities = communities
def setAccount(self, account):
self.account = account
def addCommunity(self):
'''
......@@ -32,7 +32,8 @@ class AddCommunityDialog(QDialog, Ui_AddCommunityDialog):
'''
server = self.serverEdit.text()
port = self.portBox.value()
community = self.communities.addCommunity(MainNode(server, port))
community = self.account.communities.addCommunity(MainNode(server, port))
self.account.wallets.addWallet(community.currency)
self.communityView.setModel( CommunityTreeModel(community) )
......@@ -6,6 +6,8 @@ Created on 1 févr. 2014
from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow
from PyQt5.QtWidgets import QMainWindow
from cutecoin.gui.addAccountDialog import AddAccountDialog
from cutecoin.models.account.wallets.listModel import WalletsListModel
from cutecoin.models.wallet.listModel import WalletListModel
class MainWindow(QMainWindow, Ui_MainWindow):
'''
......@@ -23,12 +25,14 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.core = core
def openAddAccountDialog(self):
self.dialog = AddAccountDialog()
self.dialog = AddAccountDialog(self)
self.dialog.setData()
self.dialog.exec_()
def actionAddAccount(self):
self.dialog.account.name = self.dialog.accountName.text()
self.core.addAccount(self.dialog.account)
self.refreshMainWindow()
'''
Refresh main window
......@@ -36,6 +40,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
in the window have to be refreshed
'''
def refreshMainWindow(self):
if self.core.currentAccount != None:
#TODO: rafraichissement de la fenetre
pass
if self.core.currentAccount == None:
self.accountTabs.setEnabled(False)
else:
self.accountTabs.setEnabled(True)
self.accountNameLabel = self.core.currentAccount.name
self.walletsList.setModel(WalletsListModel(self.core.currentAccount))
self.walletContent.setModel(WalletListModel(self.core.currentAccount.wallets.walletsList[0]))
......@@ -5,6 +5,8 @@ Created on 1 févr. 2014
'''
import ucoinpy as ucoin
import gnupg
from cutecoin.models.account.wallets import Wallets
class Account(object):
'''
......@@ -18,16 +20,25 @@ class Account(object):
self.pgpKey = pgpKey
self.name = name
self.communities = communities
self.transactionNodes = []
self.trustableNodes = []
self.wallets = []
self.wallets = Wallets()
for community in self.communities.communitiesList:
wallet = self.wallets.addWallet(community.currency)
#TODO: Gerer le cas ou plusieurs noeuds sont presents dans la liste et le 0 ne repond pas
wallet.refreshCoins(community.knownNodes[0], self.keyFingerprint())
self.receivedTransactions = []
self.sentTransactions = []
def addTransactionNode(self, node):
self.transactionNodes.append(node)
def addWallet(name, currency):
self.wallets.addWallet(name, currency)
def keyFingerprint():
gpg = gnupg.GPG()
availableKeys = gpg.list_keys(True)
for k in availableKeys:
if k['key_id'] == self.pgpKey:
return k['fingerprint']
return ""
def addTrustableNode(self, node):
self.trustableNodes.append(node)
......@@ -18,9 +18,11 @@ class Communities(object):
def getCommunity(self, currency):
for com in self.communitiesList:
#TODO: Compare communities by amendment hash instead of currency
if com.currency == currency:
return com
#TODO: Check membership
def addCommunity(self, mainNode):
ucoin.settings['server'] = mainNode.server
ucoin.settings['port'] = mainNode.port
......@@ -31,4 +33,9 @@ class Communities(object):
community = Community(mainNode, currency)
self.communitiesList.append(community)
return community
\ No newline at end of file
return community
#TODO: Jsonify this model
def saveJson(self):
pass
......@@ -4,6 +4,8 @@ Created on 7 févr. 2014
@author: inso
'''
from cutecoin.models.wallet import Wallet
class Wallets(object):
'''
classdocs
......@@ -12,4 +14,17 @@ class Wallets(object):
'''
Constructor
'''
self.walletsList = []
def addWallet(self, currency):
wallet = Wallet(currency)
if wallet not in self.walletsList:
self.walletsList.append(wallet)
else:
return self.walletsList.get(wallet)
def getWallet(self, wallet):
for w in self.walletsLists:
if w == wallet:
return w
return None
'''
Created on 8 févr. 2014
@author: inso
'''
from PyQt5.QtCore import QAbstractListModel, Qt
class WalletsListModel(QAbstractListModel):
'''
A Qt abstract item model to display communities in a tree
'''
def __init__(self, account, parent=None):
'''
Constructor
'''
super(WalletsListModel, self).__init__(parent)
self.wallets = account.wallets
def rowCount(self ,parent):
return len(self.wallets.walletsList)
def data(self,index,role):
if role == Qt.DisplayRole:
row=index.row()
value = self.wallets.walletsList[row].getText()
return value
def flags(self,index):
return Qt.ItemIsSelectable | Qt.ItemIsEnabled
......@@ -4,14 +4,35 @@ Created on 2 févr. 2014
@author: inso
'''
import re
import math
class Coin(object):
'''
classdocs
'''
def __init__(self, number):
def __init__(self, ownerFingerprint, coin_id):
'''
Constructor
'''
self.number = number
# Regex to parse the coin id
regex = "/^([A-Z\d]{40})-(\d+)-(\d)-(\d+)-((A|F|D)-\d+))$/"
m = re.search(regex, coin_id)
self.issuer = m.group(0)
self.number = int(m.group(1))
self.base = int(m.group(2))
self.power = int(m.group(3))
self.origin = m.group(4)
self.ownerFingerprint = ownerFingerprint
def value(self):
return math.pow(self.base, self.power)
def getId(self):
return self.issuer + "-" \
+ str(self.number) + "-" \
+ str(self.base) + "-" \
+ str(self.power) + "-" \
+ self.origin
\ No newline at end of file
......@@ -35,3 +35,7 @@ class Community(object):
return self.knownNodes
#TODO: Jsonify this model
def saveJson(self):
pass
......@@ -24,6 +24,7 @@ class Node(object):
def getText(self):
return self.server + ":" + str(self.port)
class MainNode(Node):
def downstreamPeers(self):
......@@ -36,3 +37,7 @@ class MainNode(Node):
peers.append(node)
return peers
#TODO: Jsonify this model
def saveJson(self):
pass
......@@ -4,6 +4,10 @@ Created on 1 févr. 2014
@author: inso
'''
import ucoinpy as ucoin
import gnupg
from cutecoin.models.coin import Coin
class Wallet(object):
'''
classdocs
......@@ -14,6 +18,29 @@ class Wallet(object):
'''
Constructor
'''
self.initialValue = 0
self.coins = []
self.currency = currency
def __eq__(self, other):
return ( self.currency == other.currency )
def value(self):
value = 0
for coin in self.coins:
value += coin.value()
return value
def refreshCoins(self, mainNode, pgpFingerprint):
ucoin.settings['server'] = mainNode
ucoin.settings['port'] = mainNode
dataList = ucoin.hdc.coins.List(pgpFingerprint).get()
for issaunces in dataList['coins']:
issuer = issaunces['issuer']
for coinsIds in issaunces['ids']:
shortened_id = coinsIds
coin = Coin(pgpFingerprint, issuer+"-"+shortened_id)
self.coins.append(coin)
def getText(self):
return str(self.value()) + " " + self.currency
'''
Created on 8 févr. 2014
@author: inso
'''
from PyQt5.QtCore import QAbstractListModel, Qt
class WalletListModel(QAbstractListModel):
'''
A Qt abstract item model to display communities in a tree
'''
def __init__(self, wallet, parent=None):
'''
Constructor
'''
super(WalletListModel, self).__init__(parent)
self.coins = wallet.coins
def rowCount(self ,parent):
return len(self.coins)
def data(self,index,role):
if role == Qt.DisplayRole:
row=index.row()
value = str(self.coins[row].value())
return value
def flags(self,index):
return Qt.ItemIsSelectable | Qt.ItemIsEnabled
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment