Skip to content

Commit

Permalink
Add support for and miniscript fragments in local embit clone
Browse files Browse the repository at this point in the history
  • Loading branch information
bigspider committed Feb 13, 2024
1 parent f56c4df commit 773512e
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions bitcoin_client/ledger_bitcoin/embit/descriptor/miniscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,23 @@ def type(self):

@classmethod
def read_from(cls, s, taproot=False):
op, char = read_until(s, b"(")
op, char = read_until(s, b"(,)")
op = op.decode()
wrappers = ""
if ":" in op:
wrappers, op = op.split(":")
if char != b"(":
raise MiniscriptError("Missing operator")
if op not in OPERATOR_NAMES:
raise MiniscriptError("Unknown operator '%s'" % op)
# number of arguments, classes of args, compile fn, type, validity checker
MiniscriptCls = OPERATORS[OPERATOR_NAMES.index(op)]
args = MiniscriptCls.read_arguments(s, taproot=taproot)
if MiniscriptCls.NARGS != 0 and char != b"(":
raise MiniscriptError("Missing operator")

if MiniscriptCls.NARGS is None or MiniscriptCls.NARGS > 0:
args = MiniscriptCls.read_arguments(s, taproot=taproot)
else:
s.seek(-1, 1)
args = []
miniscript = MiniscriptCls(*args, taproot=taproot)
for w in reversed(wrappers):
if w not in WRAPPER_NAMES:
Expand Down Expand Up @@ -132,6 +137,36 @@ def carg(self):
return self.arg.compile()


class NumberZero(Miniscript):
# 0

NARGS = 0
NAME = "0"
TYPE = "B"
PROPS = "zud"

def inner_compile(self):
return b"\x00"

def __len__(self):
return 1


class NumberOne(Miniscript):
# 1

NARGS = 0
NAME = "1"
TYPE = "B"
PROPS = "zu"

def inner_compile(self):
return b"\x51"

def __len__(self):
return 1


class PkK(OneArg):
# <key>
NAME = "pk_k"
Expand Down Expand Up @@ -739,6 +774,8 @@ def __len__(self):


OPERATORS = [
NumberZero,
NumberOne,
PkK,
PkH,
Older,
Expand Down

0 comments on commit 773512e

Please sign in to comment.