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

[enh] #798 use only pubkey in evaluate_condition to allow it before entering credentials

parent 22e93520
No related branches found
No related tags found
1 merge request!778Release 0.51.0
......@@ -334,7 +334,11 @@ class TransferController(QObject):
source = self.model.current_source
condition = pypeg2.parse(source.conditions, Condition)
result, _errors = self.model.app.sources_service.evaluate_condition(
self.model.app.currency, condition, [], [], source.identifier
self.model.app.currency,
condition,
[self.model.connection.pubkey],
[],
source.identifier,
)
if result:
message = QCoreApplication.translate(
......
......@@ -302,7 +302,7 @@ class DocumentsService:
:param int amount: The amount target value
:param int amount_base: The amount base target value
:param str currency: The community target of the transaction
:param str key: The key owning the sources
:param SigningKey key: The key owning the sources
:return: The list of inputs to use in the transaction document
"""
......@@ -332,7 +332,7 @@ class DocumentsService:
condition = pypeg2.parse(s.conditions, Condition)
# evaluate the condition
result, _ = self._sources_services.evaluate_condition(
currency, condition, [key], [], s.identifier
currency, condition, [key.pubkey], [], s.identifier
)
if not result:
continue
......
......@@ -279,7 +279,7 @@ class SourcesServices(QObject):
self,
currency: str,
condition: Condition,
keys: list,
pubkeys: list,
passwords: list,
identifier: str,
result: bool = False,
......@@ -291,11 +291,12 @@ class SourcesServices(QObject):
:param str currency: Name of currency
:param Condition condition: Condition instance
:param [SigningKey] keys: Keys to unlock condition
:param [str] pubkeys: Keys to unlock condition
:param [str] passwords: List of passwords
:param str identifier: Source transaction identifier
:param bool result: Evaluation result accumulator
:param [tuple] _errors: List of tuple with parameters returning false (parameter: str, message: str, param: int)
:param [tuple] _errors: List of tuple with infos on condition returning false (condition: str, message: str,
param: str|int)
:return:
"""
left = False
......@@ -304,17 +305,29 @@ class SourcesServices(QObject):
if isinstance(condition.left, Condition):
# evaluate condition
left, _errors = self.evaluate_condition(
currency, condition.left, keys, passwords, identifier, result, _errors
currency,
condition.left,
pubkeys,
passwords,
identifier,
result,
_errors,
)
# if right param is a condition...
if isinstance(condition.right, Condition):
# evaluate condition
right, _errors = self.evaluate_condition(
currency, condition.right, keys, passwords, identifier, result, _errors
currency,
condition.right,
pubkeys,
passwords,
identifier,
result,
_errors,
)
# if left param is a SIG...
if isinstance(condition.left, SIG):
if condition.left.pubkey in (key.pubkey for key in keys):
if condition.left.pubkey in pubkeys:
left = True
else:
if _errors is None:
......@@ -388,7 +401,7 @@ class SourcesServices(QObject):
# if right param is a SIG...
if isinstance(condition.right, SIG):
if condition.right.pubkey in (key.pubkey for key in keys):
if condition.right.pubkey in pubkeys:
right = True
else:
if _errors is None:
......
......@@ -127,7 +127,11 @@ def test_evaluate_condition_source_lock_mode_0(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency, condition, [bob.key], [], tx_hash
application_with_one_connection.currency,
condition,
[bob.key.pubkey],
[],
tx_hash,
)
assert result is True
assert _errors is None
......@@ -137,7 +141,11 @@ def test_evaluate_condition_source_lock_mode_0(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency, condition, [alice.key], [], tx_hash,
application_with_one_connection.currency,
condition,
[alice.key.pubkey],
[],
tx_hash,
)
assert result is False
assert _errors == [
......@@ -215,7 +223,11 @@ def test_evaluate_condition_source_lock_mode_1(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency, condition, [bob.key], [], tx_hash
application_with_one_connection.currency,
condition,
[bob.key.pubkey],
[],
tx_hash,
)
assert result is True
assert _errors == [
......@@ -232,7 +244,11 @@ def test_evaluate_condition_source_lock_mode_1(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency, condition, [alice.key], [], tx_hash,
application_with_one_connection.currency,
condition,
[alice.key.pubkey],
[],
tx_hash,
)
assert result is False
assert _errors == [
......@@ -289,7 +305,11 @@ def test_evaluate_condition_source_lock_mode_1(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency, condition, [bob.key], [], tx_hash
application_with_one_connection.currency,
condition,
[bob.key.pubkey],
[],
tx_hash,
)
assert result is True
assert _errors == [
......@@ -305,7 +325,11 @@ def test_evaluate_condition_source_lock_mode_1(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency, condition, [alice.key], [], tx_hash,
application_with_one_connection.currency,
condition,
[alice.key.pubkey],
[],
tx_hash,
)
assert result is True
assert _errors == [
......@@ -378,7 +402,11 @@ def test_evaluate_condition_source_multisig(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency, condition, [bob.key], [], tx_hash
application_with_one_connection.currency,
condition,
[bob.key.pubkey],
[],
tx_hash,
)
assert result is False
assert _errors == [
......@@ -394,7 +422,11 @@ def test_evaluate_condition_source_multisig(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency, condition, [alice.key], [], tx_hash,
application_with_one_connection.currency,
condition,
[alice.key.pubkey],
[],
tx_hash,
)
assert result is False
assert _errors == [
......@@ -412,7 +444,7 @@ def test_evaluate_condition_source_multisig(
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
condition,
[alice.key, bob.key],
[alice.key.pubkey, bob.key.pubkey],
[],
tx_hash,
)
......@@ -570,7 +602,7 @@ def test_evaluate_condition_source_atomic_swap(
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx2_condition,
[alice.key],
[alice.key.pubkey],
[password],
tx2_hash,
)
......@@ -597,7 +629,7 @@ def test_evaluate_condition_source_atomic_swap(
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx1_condition,
[bob.key],
[bob.key.pubkey],
[password],
tx1_hash,
)
......@@ -623,7 +655,7 @@ def test_evaluate_condition_source_atomic_swap(
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx1_condition,
[bob.key, alice.key],
[bob.key.pubkey, alice.key.pubkey],
[password],
tx1_hash,
)
......@@ -639,7 +671,7 @@ def test_evaluate_condition_source_atomic_swap(
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx2_condition,
[bob.key, alice.key],
[bob.key.pubkey, alice.key.pubkey],
[password],
tx2_hash,
)
......@@ -655,7 +687,7 @@ def test_evaluate_condition_source_atomic_swap(
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx2_condition,
[alice.key],
[alice.key.pubkey],
[],
tx2_hash,
)
......@@ -686,7 +718,7 @@ def test_evaluate_condition_source_atomic_swap(
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx1_condition,
[bob.key],
[bob.key.pubkey],
[],
tx1_hash,
)
......@@ -797,7 +829,7 @@ def test_evaluate_condition_source_atomic_swap(
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx1_condition,
[alice.key],
[alice.key.pubkey],
[],
tx1_hash,
)
......@@ -827,7 +859,7 @@ def test_evaluate_condition_source_atomic_swap(
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx2_condition,
[bob.key],
[bob.key.pubkey],
[],
tx2_hash,
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment