Greenaddress plugin works with multiple windows
This commit is contained in:
parent
8e7bcfeeb9
commit
efc95307e2
|
@ -16,19 +16,15 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import base64
|
||||||
import urllib
|
import urllib
|
||||||
import json
|
|
||||||
import sys
|
import sys
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from PyQt4.QtGui import QMessageBox, QApplication, QPushButton
|
from PyQt4.QtGui import QMessageBox, QApplication, QPushButton
|
||||||
|
|
||||||
from electrum.account import BIP32_Account
|
|
||||||
from electrum import bitcoin, util
|
|
||||||
from electrum import transaction
|
|
||||||
from electrum.plugins import BasePlugin, hook
|
from electrum.plugins import BasePlugin, hook
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.bitcoin import regenerate_key
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,50 +32,49 @@ class Plugin(BasePlugin):
|
||||||
|
|
||||||
button_label = _("Verify GA instant")
|
button_label = _("Verify GA instant")
|
||||||
|
|
||||||
@hook
|
|
||||||
def init_qt(self, gui):
|
|
||||||
self.win = gui.main_window
|
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def transaction_dialog(self, d):
|
def transaction_dialog(self, d):
|
||||||
self.wallet = d.wallet
|
d.verify_button = QPushButton(self.button_label)
|
||||||
self.verify_button = b = QPushButton(self.button_label)
|
d.verify_button.clicked.connect(lambda: self.do_verify(d))
|
||||||
b.clicked.connect(lambda: self.do_verify(d.tx))
|
d.buttons.insert(0, d.verify_button)
|
||||||
d.buttons.insert(0, b)
|
|
||||||
self.transaction_dialog_update(d)
|
self.transaction_dialog_update(d)
|
||||||
|
|
||||||
def get_my_addr(self, tx):
|
def get_my_addr(self, d):
|
||||||
"""Returns the address for given tx which can be used to request
|
"""Returns the address for given tx which can be used to request
|
||||||
instant confirmation verification from GreenAddress"""
|
instant confirmation verification from GreenAddress"""
|
||||||
|
for addr, _ in d.tx.get_outputs():
|
||||||
for addr, _ in tx.get_outputs():
|
if d.wallet.is_mine(addr):
|
||||||
if self.wallet.is_mine(addr):
|
|
||||||
return addr
|
return addr
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def transaction_dialog_update(self, d):
|
def transaction_dialog_update(self, d):
|
||||||
if d.tx.is_complete() and self.get_my_addr(d.tx):
|
if d.tx.is_complete() and self.get_my_addr(d):
|
||||||
self.verify_button.show()
|
d.verify_button.show()
|
||||||
else:
|
else:
|
||||||
self.verify_button.hide()
|
d.verify_button.hide()
|
||||||
|
|
||||||
def do_verify(self, tx):
|
def do_verify(self, d):
|
||||||
|
tx = d.tx
|
||||||
|
wallet = d.wallet
|
||||||
|
window = d.parent
|
||||||
# 1. get the password and sign the verification request
|
# 1. get the password and sign the verification request
|
||||||
password = None
|
password = None
|
||||||
if self.wallet.use_encryption:
|
if wallet.use_encryption:
|
||||||
msg = _('GreenAddress requires your signature to verify that transaction is instant.\n'
|
msg = _('GreenAddress requires your signature \n'
|
||||||
'Please enter your password to sign a verification request.')
|
'to verify that transaction is instant.\n'
|
||||||
password = self.win.password_dialog(msg)
|
'Please enter your password to sign a\n'
|
||||||
|
'verification request.')
|
||||||
|
password = window.password_dialog(msg)
|
||||||
if not password:
|
if not password:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
self.verify_button.setText(_('Verifying...'))
|
d.verify_button.setText(_('Verifying...'))
|
||||||
QApplication.processEvents() # update the button label
|
QApplication.processEvents() # update the button label
|
||||||
|
|
||||||
addr = self.get_my_addr(tx)
|
addr = self.get_my_addr(d)
|
||||||
message = "Please verify if %s is GreenAddress instant confirmed" % tx.hash()
|
message = "Please verify if %s is GreenAddress instant confirmed" % tx.hash()
|
||||||
sig = self.wallet.sign_message(addr, message, password)
|
sig = wallet.sign_message(addr, message, password)
|
||||||
sig = base64.b64encode(sig)
|
sig = base64.b64encode(sig)
|
||||||
|
|
||||||
# 2. send the request
|
# 2. send the request
|
||||||
|
@ -99,4 +94,4 @@ class Plugin(BasePlugin):
|
||||||
traceback.print_exc(file=sys.stdout)
|
traceback.print_exc(file=sys.stdout)
|
||||||
QMessageBox.information(None, _('Error'), str(e), _('OK'))
|
QMessageBox.information(None, _('Error'), str(e), _('OK'))
|
||||||
finally:
|
finally:
|
||||||
self.verify_button.setText(self.button_label)
|
d.verify_button.setText(self.button_label)
|
||||||
|
|
Loading…
Reference in New Issue