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 @@
</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>
......@@ -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)
......
......@@ -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,
......
......@@ -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
......@@ -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))
......
......@@ -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):
......
......@@ -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
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