Skip to content

Commit

Permalink
Describe conflicts when raising MiniscriptPropertyError
Browse files Browse the repository at this point in the history
  • Loading branch information
stickies-v committed Apr 30, 2022
1 parent c708a6b commit 72fff33
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions bip380/miniscript/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit 72fff33

Please sign in to comment.