mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-22 19:34:18 +01:00
* refactor conditions and fix htlc multisig * restore db/write.py * safer check for P2PK secrets for SIG_ALL * comment cleanup
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
from enum import Enum
|
|
from typing import Union
|
|
|
|
from .secret import Secret, SecretKind
|
|
|
|
|
|
class SigFlags(Enum):
|
|
# require signatures only on the inputs (default signature flag)
|
|
SIG_INPUTS = "SIG_INPUTS"
|
|
# require signatures on inputs and outputs
|
|
SIG_ALL = "SIG_ALL"
|
|
|
|
|
|
class HTLCSecret(Secret):
|
|
@classmethod
|
|
def from_secret(cls, secret: Secret):
|
|
assert SecretKind(secret.kind) == SecretKind.HTLC, "Secret is not a HTLC secret"
|
|
# NOTE: exclude tags in .dict() because it doesn't deserialize it properly
|
|
# need to add it back in manually with tags=secret.tags
|
|
return cls(**secret.dict(exclude={"tags"}), tags=secret.tags)
|
|
|
|
@property
|
|
def locktime(self) -> Union[None, int]:
|
|
locktime = self.tags.get_tag("locktime")
|
|
return int(locktime) if locktime else None
|
|
|
|
@property
|
|
def sigflag(self) -> Union[None, SigFlags]:
|
|
sigflag = self.tags.get_tag("sigflag")
|
|
return SigFlags(sigflag) if sigflag else None
|
|
|
|
@property
|
|
def n_sigs(self) -> Union[None, int]:
|
|
n_sigs = self.tags.get_tag("n_sigs")
|
|
return int(n_sigs) if n_sigs else None
|