Skip to content
Snippets Groups Projects
Commit 9b7affb8 authored by Vincent Texier's avatar Vincent Texier
Browse files

[enh] #798 fully functional "Send as source" feature for a CSV/CLTV locked source

parent 8444921f
No related branches found
No related tags found
1 merge request!778Release 0.51.0
...@@ -306,9 +306,13 @@ class TransferController(QObject): ...@@ -306,9 +306,13 @@ class TransferController(QObject):
else: else:
self.view.set_button_box(TransferView.ButtonBoxState.NO_RECEIVER) self.view.set_button_box(TransferView.ButtonBoxState.NO_RECEIVER)
elif self.password_input.valid(): elif self.password_input.valid():
# if source and check source successful...
self.view.set_button_box(TransferView.ButtonBoxState.OK) self.view.set_button_box(TransferView.ButtonBoxState.OK)
else: else:
self.view.set_button_box(TransferView.ButtonBoxState.WRONG_PASSWORD) self.view.set_button_box(TransferView.ButtonBoxState.WRONG_PASSWORD)
# if source and check source button still enabled...
if self.model.current_source and self.view.button_source_check.isEnabled():
self.view.set_button_box(TransferView.ButtonBoxState.SOURCE_LOCKED)
max_relative = self.model.quant_to_rel(current_base_amount / 100) max_relative = self.model.quant_to_rel(current_base_amount / 100)
self.view.spinbox_amount.setSuffix(Quantitative.base_str(current_base)) self.view.spinbox_amount.setSuffix(Quantitative.base_str(current_base))
...@@ -331,6 +335,7 @@ class TransferController(QObject): ...@@ -331,6 +335,7 @@ class TransferController(QObject):
self.refresh() self.refresh()
def check_source(self): def check_source(self):
# evaluate condition
source = self.model.current_source source = self.model.current_source
condition = pypeg2.parse(source.conditions, Condition) condition = pypeg2.parse(source.conditions, Condition)
result, _errors = self.model.app.sources_service.evaluate_condition( result, _errors = self.model.app.sources_service.evaluate_condition(
...@@ -340,10 +345,14 @@ class TransferController(QObject): ...@@ -340,10 +345,14 @@ class TransferController(QObject):
[], [],
source.identifier, source.identifier,
) )
# if success...
if result: if result:
message = QCoreApplication.translate( message = QCoreApplication.translate(
"TransferController", "Check is successful!" "TransferController", "Check is successful!"
) )
self.view.button_source_check.setDisabled(True)
self.refresh()
# if failure...
else: else:
message = QCoreApplication.translate( message = QCoreApplication.translate(
"TransferController", "<p><b>Condition</b></p>{}" "TransferController", "<p><b>Condition</b></p>{}"
......
...@@ -18,6 +18,7 @@ class TransferView(QWidget, Ui_TransferMoneyWidget): ...@@ -18,6 +18,7 @@ class TransferView(QWidget, Ui_TransferMoneyWidget):
WRONG_PASSWORD = 2 WRONG_PASSWORD = 2
NO_RECEIVER = 3 NO_RECEIVER = 3
WRONG_RECIPIENT = 4 WRONG_RECIPIENT = 4
SOURCE_LOCKED = 5
class RecipientMode(Enum): class RecipientMode(Enum):
PUBKEY = 1 PUBKEY = 1
...@@ -45,6 +46,10 @@ class TransferView(QWidget, Ui_TransferMoneyWidget): ...@@ -45,6 +46,10 @@ class TransferView(QWidget, Ui_TransferMoneyWidget):
False, False,
QT_TRANSLATE_NOOP("TransferView", "Incorrect receiver address or pubkey"), QT_TRANSLATE_NOOP("TransferView", "Incorrect receiver address or pubkey"),
), ),
ButtonBoxState.SOURCE_LOCKED: (
False,
QT_TRANSLATE_NOOP("TransferView", "Source locked"),
),
} }
def __init__( def __init__(
...@@ -60,7 +65,9 @@ class TransferView(QWidget, Ui_TransferMoneyWidget): ...@@ -60,7 +65,9 @@ class TransferView(QWidget, Ui_TransferMoneyWidget):
super().__init__(parent) super().__init__(parent)
self.setupUi(self) self.setupUi(self)
regexp = QRegExp("^([ a-zA-Z0-9-_:/;*?\[\]\(\)\\\?!^+=@&~#{}|<>%.]{0,255})$") regexp = QRegExp(
"^([ a-zA-Z0-9-_:/;*?\\[\\]\\(\\)\\\\?!^+=@&~#{}|<>%.]{0,255})$"
)
validator = QRegExpValidator(regexp) validator = QRegExpValidator(regexp)
self.edit_message.setValidator(validator) self.edit_message.setValidator(validator)
......
...@@ -534,6 +534,8 @@ class DocumentsService: ...@@ -534,6 +534,8 @@ class DocumentsService:
forged_tx += chained_tx forged_tx += chained_tx
else: else:
sources = [source] sources = [source]
computed_outputs = [(source.amount, source.base)]
overheads = []
logging.debug("Inputs: {0}".format(sources)) logging.debug("Inputs: {0}".format(sources))
...@@ -596,7 +598,6 @@ class DocumentsService: ...@@ -596,7 +598,6 @@ class DocumentsService:
): ):
""" """
Send money to a given recipient in a specified community Send money to a given recipient in a specified community
:param Source source: Source instance or None
:param int lock_mode: Index in the combo_locks combobox :param int lock_mode: Index in the combo_locks combobox
:param sakia.data.entities.Connection connection: The account salt :param sakia.data.entities.Connection connection: The account salt
:param str secret_key: The account secret_key :param str secret_key: The account secret_key
...@@ -605,6 +606,7 @@ class DocumentsService: ...@@ -605,6 +606,7 @@ class DocumentsService:
:param int amount: The amount of money to transfer :param int amount: The amount of money to transfer
:param int amount_base: The amount base of the transfer :param int amount_base: The amount base of the transfer
:param str message: The message to send with the transfer :param str message: The message to send with the transfer
:param Source source: Source instance or None
""" """
blockstamp = self._blockchain_processor.current_buid(connection.currency) blockstamp = self._blockchain_processor.current_buid(connection.currency)
key = SigningKey.from_credentials( key = SigningKey.from_credentials(
......
...@@ -74,3 +74,43 @@ async def test_transfer_chained_tx( ...@@ -74,3 +74,43 @@ async def test_transfer_chained_tx(
transfer_dialog.view.show() transfer_dialog.view.show()
await exec_test() await exec_test()
@pytest.mark.asyncio
async def test_transfer_from_source(
application_with_one_connection, fake_server_with_blockchain, bob, alice
):
def close_dialog():
if transfer_dialog.view.isVisible():
transfer_dialog.view.hide()
async def exec_test():
await asyncio.sleep(0.1)
assert not transfer_dialog.view.button_box.button(
QDialogButtonBox.Ok
).isEnabled()
assert transfer_dialog.view.spinbox_amount.value() == 1
await asyncio.sleep(0.1)
# simulate checked source condition
transfer_dialog.view.button_source_check.setDisabled(True)
QTest.keyClicks(transfer_dialog.view.password_input.edit_secret_key, bob.salt)
QTest.keyClicks(transfer_dialog.view.password_input.edit_password, bob.password)
assert transfer_dialog.view.button_box.button(QDialogButtonBox.Ok).isEnabled()
QTest.mouseClick(
transfer_dialog.view.button_box.button(QDialogButtonBox.Ok), Qt.LeftButton
)
await asyncio.sleep(0.2)
assert isinstance(fake_server_with_blockchain.forge.pool[0], Transaction)
application_with_one_connection.loop.call_later(10, close_dialog)
bob_connection = application_with_one_connection.db.connections_repo.get_one(
pubkey=bob.key.pubkey
)
source = application_with_one_connection.sources_service.get_one(
pubkey=bob.key.pubkey
)
transfer_dialog = TransferController.open_transfer_with_pubkey(
None, application_with_one_connection, bob_connection, alice.key.pubkey, source
)
await exec_test()
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