diff --git a/bip380/miniscript/property.py b/bip380/miniscript/property.py index 7d49265..2f30b05 100644 --- a/bip380/miniscript/property.py +++ b/bip380/miniscript/property.py @@ -2,9 +2,11 @@ # Copyright (c) 2021 Antoine Poinsot # Distributed under the MIT software license, see the accompanying # file LICENSE or http://www.opensource.org/licenses/mit-license.php. +import inspect from .errors import MiniscriptPropertyError + # TODO: implement __eq__ class Property: """Miniscript expression property""" @@ -59,21 +61,26 @@ def check_valid(self): num_types += 1 # Check for conflicts in type & properties. - if not ( - (not self.z or not self.o) - and (not self.n or not self.z) - and (not self.V or not self.d) - and (not self.K or self.u) - and (not self.V or not self.u) - and (not self.e or not self.f) - and (not self.e or self.d) - and (not self.V or not self.e) - and (not self.d or not self.f) - and (not self.V or self.f) - and (not self.K or self.s) - and (not self.z or self.m) - ): - raise MiniscriptPropertyError("Conflicting types and properties") + + checks = [ + lambda: (not self.z or not self.o), + lambda: (not self.n or not self.z), + lambda: (not self.V or not self.d), + lambda: (not self.K or self.u), + lambda: (not self.V or not self.u), + lambda: (not self.e or not self.f), + lambda: (not self.e or self.d), + lambda: (not self.V or not self.e), + lambda: (not self.d or not self.f), + lambda: (not self.V or self.f), + lambda: (not self.K or self.s), + lambda: (not self.z or self.m), + ] + conflicts = [fn for fn in checks if not fn()] + if conflicts: + formatted_conflicts = " ".join([inspect.getsource(fn).strip().replace("self.", "").replace("lambda: ", "") + for fn in conflicts])[:-1] + raise MiniscriptPropertyError(f"Conflicting types and properties: {formatted_conflicts}") def type(self): return "".join(filter(lambda x: x in self.types, str(self)))