Skip to content
Snippets Groups Projects
Commit 50dc5a87 authored by inso's avatar inso
Browse files

Money issuance

parent 3d7e55f1
No related branches found
No related tags found
No related merge requests found
...@@ -83,5 +83,24 @@ ...@@ -83,5 +83,24 @@
</hint> </hint>
</hints> </hints>
</connection> </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> </connections>
<slots>
<slot>actionIssueCoins()</slot>
</slots>
</ui> </ui>
...@@ -9,6 +9,8 @@ from math import pow ...@@ -9,6 +9,8 @@ from math import pow
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QFrame, QSlider, QLabel, QDialogButtonBox from PyQt5.QtWidgets import QDialog, QVBoxLayout, QFrame, QSlider, QLabel, QDialogButtonBox
from PyQt5.QtCore import Qt, QSignalMapper from PyQt5.QtCore import Qt, QSignalMapper
from cutecoin.models.coin import Coin
from cutecoin.gen_resources.issuanceDialog_uic import Ui_IssuanceDialog from cutecoin.gen_resources.issuanceDialog_uic import Ui_IssuanceDialog
class IssuanceDialog(QDialog, Ui_IssuanceDialog): class IssuanceDialog(QDialog, Ui_IssuanceDialog):
...@@ -81,6 +83,13 @@ class IssuanceDialog(QDialog, Ui_IssuanceDialog): ...@@ -81,6 +83,13 @@ class IssuanceDialog(QDialog, Ui_IssuanceDialog):
else: else:
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(True) 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)
......
...@@ -78,7 +78,11 @@ class Account(object): ...@@ -78,7 +78,11 @@ class Account(object):
return False 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): def jsonify(self):
data = {'name' : self.name, data = {'name' : self.name,
......
...@@ -11,17 +11,24 @@ class Coin(object): ...@@ -11,17 +11,24 @@ class Coin(object):
''' '''
A coin parsing a regex to read its value A coin parsing a regex to read its value
''' '''
def __init__(self, issuer, number, base, power, origin):
self.issuer = issuer
def __init__(self, coin_id): 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 to parse the coin id
regex = "/^([A-Z\d]{40})-(\d+)-(\d)-(\d+)-((A|F|D)-\d+))$/" regex = "/^([A-Z\d]{40})-(\d+)-(\d)-(\d+)-((A|F|D)-\d+))$/"
m = re.search(regex, coin_id) m = re.search(regex, coin_id)
self.issuer = m.group(0) issuer = m.group(0)
self.number = int(m.group(1)) number = int(m.group(1))
self.base = int(m.group(2)) base = int(m.group(2))
self.power = int(m.group(3)) power = int(m.group(3))
self.origin = m.group(4) origin = m.group(4)
return cls(issuer, number, base, power, origin)
def value(self): def value(self):
return math.pow(self.base, self.power) return math.pow(self.base, self.power)
...@@ -32,5 +39,3 @@ class Coin(object): ...@@ -32,5 +39,3 @@ class Coin(object):
+ str(self.base) + "-" \ + str(self.base) + "-" \
+ str(self.power) + "-" \ + str(self.power) + "-" \
+ self.origin + self.origin
...@@ -23,7 +23,7 @@ class Transaction(object): ...@@ -23,7 +23,7 @@ class Transaction(object):
value = 0 value = 0
trxData = self.community.ucoinRequest(ucoin.hdc.transactions.View(self.sender.pgpFingerprint + "-" + self.increment)) trxData = self.community.ucoinRequest(ucoin.hdc.transactions.View(self.sender.pgpFingerprint + "-" + self.increment))
for coin in trxData['transaction']['coins']: for coin in trxData['transaction']['coins']:
value += Coin(coin[id]).value() value += Coin.fromId(coin[id]).value()
return value return value
def currency(self): def currency(self):
...@@ -56,7 +56,7 @@ class Issuance(Transaction): ...@@ -56,7 +56,7 @@ class Issuance(Transaction):
''' '''
def __init__(self): def __init__(self):
super(Issuance).__init__() super(Issuance).__init__()
def amendmentNumber(self): def amendmentNumber(self):
self.community.ucoinRequest(ucoin.hdc.transactions.View(self.sender.pgpFingerprint + "-" + self.increment)) self.community.ucoinRequest(ucoin.hdc.transactions.View(self.sender.pgpFingerprint + "-" + self.increment))
......
...@@ -39,7 +39,7 @@ class Wallet(object): ...@@ -39,7 +39,7 @@ class Wallet(object):
issuer = issaunces['issuer'] issuer = issaunces['issuer']
for coinsIds in issaunces['ids']: for coinsIds in issaunces['ids']:
shortened_id = coinsIds shortened_id = coinsIds
coin = Coin(pgpFingerprint, issuer+"-"+shortened_id) coin = Coin.fromId(pgpFingerprint, issuer+"-"+shortened_id)
self.coins.append(coin) self.coins.append(coin)
def getText(self): def getText(self):
......
...@@ -15,7 +15,7 @@ def createWallet(community): ...@@ -15,7 +15,7 @@ def createWallet(community):
def loadWallet(jsonData, community): def loadWallet(jsonData, community):
wallet = Wallet() wallet = Wallet()
for coinData in jsonData['coins']: for coinData in jsonData['coins']:
wallet.coins.append(Coin(coinData['coin'])) wallet.coins.append(Coin.fromId(coinData['coin']))
wallet.community = community wallet.community = community
return wallet return wallet
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