From 50dc5a8757432f776170bd811d027a8f26fcd460 Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Mon, 17 Feb 2014 00:16:13 +0100 Subject: [PATCH] Money issuance --- res/ui/issuanceDialog.ui | 19 ++++++++++++++++ src/cutecoin/gui/issuanceDialog.py | 9 ++++++++ src/cutecoin/models/account/__init__.py | 6 ++++- src/cutecoin/models/coin/__init__.py | 25 ++++++++++++--------- src/cutecoin/models/transaction/__init__.py | 4 ++-- src/cutecoin/models/wallet/__init__.py | 2 +- src/cutecoin/models/wallet/factory.py | 2 +- 7 files changed, 52 insertions(+), 15 deletions(-) diff --git a/res/ui/issuanceDialog.ui b/res/ui/issuanceDialog.ui index f139380c..527942fc 100644 --- a/res/ui/issuanceDialog.ui +++ b/res/ui/issuanceDialog.ui @@ -83,5 +83,24 @@ </hint> </hints> </connection> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>IssuanceDialog</receiver> + <slot>actionIssueCoins()</slot> + <hints> + <hint type="sourcelabel"> + <x>199</x> + <y>279</y> + </hint> + <hint type="destinationlabel"> + <x>199</x> + <y>149</y> + </hint> + </hints> + </connection> </connections> + <slots> + <slot>actionIssueCoins()</slot> + </slots> </ui> diff --git a/src/cutecoin/gui/issuanceDialog.py b/src/cutecoin/gui/issuanceDialog.py index a786e9f0..e3d05705 100644 --- a/src/cutecoin/gui/issuanceDialog.py +++ b/src/cutecoin/gui/issuanceDialog.py @@ -9,6 +9,8 @@ from math import pow from PyQt5.QtWidgets import QDialog, QVBoxLayout, QFrame, QSlider, QLabel, QDialogButtonBox from PyQt5.QtCore import Qt, QSignalMapper +from cutecoin.models.coin import Coin + from cutecoin.gen_resources.issuanceDialog_uic import Ui_IssuanceDialog class IssuanceDialog(QDialog, Ui_IssuanceDialog): @@ -81,6 +83,13 @@ class IssuanceDialog(QDialog, Ui_IssuanceDialog): else: self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(True) + def actionIssueCoins(self): + coins = [] + n = 0 + for slider in self.sliders: + coins.append(str(slider.value())+","+str(n)) + n += 1 + self.issuer.issueDividend(self.community, coins) diff --git a/src/cutecoin/models/account/__init__.py b/src/cutecoin/models/account/__init__.py index 9211f74e..3cf9917c 100644 --- a/src/cutecoin/models/account/__init__.py +++ b/src/cutecoin/models/account/__init__.py @@ -78,7 +78,11 @@ class Account(object): return False - + def issueDividend(self, community, coins): + if community in self.communities.communitiesList: + ucoin.settings['gpg'] = gnupg.GPG() + issuance = ucoin.wrappers.transactions.Issue(self.keyFingerprint(), community.amendmentNumber(), coins) + return issuance() def jsonify(self): data = {'name' : self.name, diff --git a/src/cutecoin/models/coin/__init__.py b/src/cutecoin/models/coin/__init__.py index c7945b8b..ade69e4b 100644 --- a/src/cutecoin/models/coin/__init__.py +++ b/src/cutecoin/models/coin/__init__.py @@ -11,17 +11,24 @@ class Coin(object): ''' A coin parsing a regex to read its value ''' - - - def __init__(self, coin_id): + def __init__(self, issuer, number, base, power, origin): + self.issuer = issuer + self.number = number + self.base = base + self.power = power + self.origin = origin + + @classmethod + def fromId(cls, coin_id): # 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) + issuer = m.group(0) + number = int(m.group(1)) + base = int(m.group(2)) + power = int(m.group(3)) + origin = m.group(4) + return cls(issuer, number, base, power, origin) def value(self): return math.pow(self.base, self.power) @@ -32,5 +39,3 @@ class Coin(object): + str(self.base) + "-" \ + str(self.power) + "-" \ + self.origin - - diff --git a/src/cutecoin/models/transaction/__init__.py b/src/cutecoin/models/transaction/__init__.py index cec0028b..10c30221 100644 --- a/src/cutecoin/models/transaction/__init__.py +++ b/src/cutecoin/models/transaction/__init__.py @@ -23,7 +23,7 @@ class Transaction(object): value = 0 trxData = self.community.ucoinRequest(ucoin.hdc.transactions.View(self.sender.pgpFingerprint + "-" + self.increment)) for coin in trxData['transaction']['coins']: - value += Coin(coin[id]).value() + value += Coin.fromId(coin[id]).value() return value def currency(self): @@ -56,7 +56,7 @@ class Issuance(Transaction): ''' def __init__(self): super(Issuance).__init__() - + def amendmentNumber(self): self.community.ucoinRequest(ucoin.hdc.transactions.View(self.sender.pgpFingerprint + "-" + self.increment)) diff --git a/src/cutecoin/models/wallet/__init__.py b/src/cutecoin/models/wallet/__init__.py index ad1e17fa..8e0ebd70 100644 --- a/src/cutecoin/models/wallet/__init__.py +++ b/src/cutecoin/models/wallet/__init__.py @@ -39,7 +39,7 @@ class Wallet(object): issuer = issaunces['issuer'] for coinsIds in issaunces['ids']: shortened_id = coinsIds - coin = Coin(pgpFingerprint, issuer+"-"+shortened_id) + coin = Coin.fromId(pgpFingerprint, issuer+"-"+shortened_id) self.coins.append(coin) def getText(self): diff --git a/src/cutecoin/models/wallet/factory.py b/src/cutecoin/models/wallet/factory.py index eb0316a1..fca886d1 100644 --- a/src/cutecoin/models/wallet/factory.py +++ b/src/cutecoin/models/wallet/factory.py @@ -15,7 +15,7 @@ def createWallet(community): def loadWallet(jsonData, community): wallet = Wallet() for coinData in jsonData['coins']: - wallet.coins.append(Coin(coinData['coin'])) + wallet.coins.append(Coin.fromId(coinData['coin'])) wallet.community = community return wallet -- GitLab