Skip to content

Commit

Permalink
calculate POD
Browse files Browse the repository at this point in the history
  • Loading branch information
icodeface committed Apr 15, 2020
1 parent de9a2a1 commit fdb54e2
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions electrum/gui/qt/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3186,11 +3186,23 @@ def delete_delegation(self, addr: str):
self.delegation_list.update()

def call_add_delegation(self, addr, staker, fee, gas_limit, gas_price, dialog):
# todo pod
pod = bfh('2068ab25fe65907b72118d08f0ce37c31d3003aa91920b77e917b814b9246c48763f863fdd481dbfcdecc811df1636e526c971312f7e5e11e82ed3e02bc161b71e')
"""
:param staker: hash160 str
"""
msg = []
if self.wallet.has_keystore_encryption():
msg.append("")
msg.append(_("Enter your password to proceed"))
password = self.password_dialog('\n'.join(msg))
if not password:
return
else:
password = None

pod = self.wallet.sign_message(addr, staker, password)
args = [staker.lower(), fee, pod]
self.sendto_smart_contract(DELEGATION_CONTRACT, DELEGATE_ABI[1], args,
gas_limit, gas_price, 0, addr, dialog, False)
gas_limit, gas_price, 0, addr, dialog, False, password)

def call_remove_delegation(self, addr, gas_limit, gas_price, dialog):
self.sendto_smart_contract(DELEGATION_CONTRACT, DELEGATE_ABI[0], [],
Expand All @@ -3205,7 +3217,7 @@ def delegation_dialog(self, dele=None, mode='add'):
d = DelegationDialog(self, dele, mode)
d.show()

def _smart_contract_broadcast(self, outputs, desc, gas_fee, sender, dialog, broadcast_done=None, preview=False):
def _smart_contract_broadcast(self, outputs, desc, gas_fee, sender, dialog, broadcast_done=None, preview=False, password=None):
coins = self.get_coins()
try:
tx = self.wallet.make_unsigned_transaction(coins=coins,
Expand Down Expand Up @@ -3244,17 +3256,18 @@ def _smart_contract_broadcast(self, outputs, desc, gas_fee, sender, dialog, broa
if fee - gas_fee > confirm_rate * tx.estimated_size() / 1000:
msg.append(_('Warning') + ': ' + _("The fee for this transaction seems unusually high."))

if self.wallet.has_keystore_encryption():
msg.append("")
msg.append(_("Enter your password to proceed"))
password = self.password_dialog('\n'.join(msg))
if not password:
return
else:
msg.append(_('Proceed?'))
password = None
if not self.question('\n'.join(msg)):
return
if not password:
if self.wallet.has_keystore_encryption():
msg.append("")
msg.append(_("Enter your password to proceed"))
password = self.password_dialog('\n'.join(msg))
if not password:
return
else:
msg.append(_('Proceed?'))
password = None
if not self.question('\n'.join(msg)):
return

def sign_done(success):
if success:
Expand Down Expand Up @@ -3321,13 +3334,13 @@ def decode_x(x):
self.logger.exception('')
dialog.show_message(f'{e} {result}')

def sendto_smart_contract(self, address, abi, args, gas_limit, gas_price, amount, sender, dialog, preview):
def sendto_smart_contract(self, address, abi, args, gas_limit, gas_price, amount, sender, dialog, preview, password=None):
try:
abi_encoded = eth_abi_encode(abi, args)
script = contract_script(gas_limit, gas_price, abi_encoded, address, opcodes.OP_CALL)
outputs = [PartialTxOutput(scriptpubkey=script, value=amount)]
tx_desc = 'contract sendto {}'.format(self.wallet.db.smart_contracts[address][0])
self._smart_contract_broadcast(outputs, tx_desc, gas_limit * gas_price, sender, dialog, None, preview)
self._smart_contract_broadcast(outputs, tx_desc, gas_limit * gas_price, sender, dialog, None, preview, password)
except (BaseException,) as e:
self.logger.exception('')
dialog.show_message(str(e))
Expand Down

0 comments on commit fdb54e2

Please sign in to comment.