mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-22 11:24:19 +01:00
Refactor conditions and fix HTLC multisig (#643)
* refactor conditions and fix htlc multisig * restore db/write.py * safer check for P2PK secrets for SIG_ALL * comment cleanup
This commit is contained in:
@@ -95,21 +95,7 @@ class ProofState(LedgerEvent):
|
||||
|
||||
class HTLCWitness(BaseModel):
|
||||
preimage: Optional[str] = None
|
||||
signature: Optional[str] = None
|
||||
|
||||
@classmethod
|
||||
def from_witness(cls, witness: str):
|
||||
return cls(**json.loads(witness))
|
||||
|
||||
|
||||
class P2SHWitness(BaseModel):
|
||||
"""
|
||||
Unlocks P2SH spending condition of a Proof
|
||||
"""
|
||||
|
||||
script: str
|
||||
signature: str
|
||||
address: Union[str, None] = None
|
||||
signatures: Optional[List[str]] = None
|
||||
|
||||
@classmethod
|
||||
def from_witness(cls, witness: str):
|
||||
@@ -206,10 +192,15 @@ class Proof(BaseModel):
|
||||
return P2PKWitness.from_witness(self.witness).signatures
|
||||
|
||||
@property
|
||||
def htlcpreimage(self) -> Union[str, None]:
|
||||
def htlcpreimage(self) -> str | None:
|
||||
assert self.witness, "Witness is missing for htlc preimage"
|
||||
return HTLCWitness.from_witness(self.witness).preimage
|
||||
|
||||
@property
|
||||
def htlcsigs(self) -> List[str] | None:
|
||||
assert self.witness, "Witness is missing for htlc signatures"
|
||||
return HTLCWitness.from_witness(self.witness).signatures
|
||||
|
||||
|
||||
class Proofs(BaseModel):
|
||||
# NOTE: not used in Pydantic validation
|
||||
@@ -647,6 +638,7 @@ class WalletKeyset:
|
||||
int(amount): PublicKey(bytes.fromhex(hex_key), raw=True)
|
||||
for amount, hex_key in dict(json.loads(serialized)).items()
|
||||
}
|
||||
|
||||
return cls(
|
||||
id=row["id"],
|
||||
unit=row["unit"],
|
||||
|
||||
Reference in New Issue
Block a user