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

Send pubkey + send membership demand

parent 7b9eadb9
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,30 @@
<item>
<widget class="QListView" name="list_community_members"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="label_quality">
<property name="text">
<string>Quality : </string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_membership">
<property name="text">
<string>Send membership demand</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
......@@ -34,8 +58,43 @@
</layout>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>button_membership</sender>
<signal>clicked()</signal>
<receiver>CommunityTabWidget</receiver>
<slot>send_membership_demand()</slot>
<hints>
<hint type="sourcelabel">
<x>289</x>
<y>277</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>149</y>
</hint>
</hints>
</connection>
<connection>
<sender>button_membership</sender>
<signal>clicked()</signal>
<receiver>CommunityTabWidget</receiver>
<slot>send_membership_leaving()</slot>
<hints>
<hint type="sourcelabel">
<x>289</x>
<y>277</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>149</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>open_issuance_dialog()</slot>
<slot>send_membership_demand()</slot>
<slot>send_membership_leaving()</slot>
</slots>
</ui>
......@@ -5,7 +5,7 @@ Created on 2 févr. 2014
'''
import logging
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QWidget, QErrorMessage
from cutecoin.models.community.membersListModel import MembersListModel
from cutecoin.gen_resources.communityTabWidget_uic import Ui_CommunityTabWidget
......@@ -26,3 +26,19 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget):
self.account = account
wallets = account.wallets.community_wallets(community.currency)
self.list_community_members.setModel(MembersListModel(community, wallets))
if self.account.quality(self.community) == "member":
self.button_membership.setText("Send leaving demand")
self.button_membership.clicked.connect(self.send_membership_leaving)
else:
self.button_membership.setText("Send membership demand")
self.button_membership.clicked.connect(self.send_membership_demand)
def send_membership_demand(self):
result = self.account.send_membership_in(self.community)
if (result):
QErrorMessage(self).showMessage(result)
def send_membership_leaving(self):
result = self.account.send_membership_out(self.community)
if (result):
QErrorMessage(self).showMessage(result)
......@@ -185,9 +185,17 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog):
menu.exec_(self.mapToGlobal(point))
def accept(self):
result = self.account.send_pubkey(self.community)
if result:
QMessageBox.critical(self, "Pubkey publishing error",
result)
#TODO: Push wht only if changed
for wallet in self.account.wallets:
wallet.push_wht(self.account.gpg)
result = wallet.push_wht(self.account.gpg)
if result:
QMessageBox.critical(self, "Wallet publishing error",
result)
self.accepted.emit()
self.close()
......@@ -113,6 +113,18 @@ class Account(object):
sent.append(t)
return sent
def send_pubkey(self, community):
wallets = self.wallets.community_wallets(community.currency)
return community.send_pubkey(self, wallets)
def send_membership_in(self, community):
wallets = self.wallets.community_wallets(community.currency)
return community.send_membership(self, wallets, "IN")
def send_membership_out(self, community):
wallets = self.wallets.community_wallets(community.currency)
return community.send_membership(self, wallets, "OUT")
def quality(self, community):
wallets = self.wallets.community_wallets(community.currency)
return community.person_quality(wallets, self.fingerprint())
......
......@@ -8,6 +8,7 @@ import ucoin
import hashlib
import json
import logging
import time
from cutecoin.models.node import Node
from cutecoin.models.account.wallets import Wallets
......@@ -72,6 +73,42 @@ class Community(object):
current_amendment = wallets.request(ucoin.hdc.amendments.Promoted())
return int(current_amendment['number'])
def send_pubkey(self, account, wallets):
ascii_key = account.gpg.export_keys(account.keyid)
ascii_key = ascii_key.replace("\n", "\r\n")
signature = account.gpg.sign(ascii_key, keyid=account.keyid, detach=True)
print(ascii_key)
print(signature)
try:
wallets.post(ucoin.pks.Add(),
{'keytext': ascii_key,
'keysign': signature})
except ValueError as e:
return str(e)
def send_membership(self, account, wallets, membership):
context_data = {'version': 1,
'currency': self.currency,
'fingerprint': account.fingerprint(),
'date': int(time.time()),
'membership': membership
}
message = """Version: %(version)d
Currency: %(currency)s
Registry: MEMBERSHIP
Issuer: %(fingerprint)s
Date: %(date)s
Membership: %(membership)s
""" % context_data
message = message.replace("\n", "\r\n")
signature = account.gpg.sign(message, keyid=account.keyid, detach=True)
try:
wallets.post(ucoin.registry.community.Members(),
{'membership': message, 'signature': signature})
except ValueError as e:
return str(e)
def person_quality(self, wallets, fingerprint):
quality = 'nothing'
voter_req = ucoin.registry.community.voters.Current(fingerprint)
......
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