Allow DID's create_innerpuz to take p2_puzzle or hash, and document the use cases (#17116)

Allow DID's create_innerpuz to take p2_puzzle or hash, and document the use cases.
This commit is contained in:
Amine Khaldi 2023-12-21 03:50:20 +01:00 committed by GitHub
parent 67039ca648
commit 38516f7611
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -1516,7 +1516,7 @@ class DIDWallet:
return (
create_singleton_puzzle(
did_wallet_puzzles.create_innerpuz(
hint, # type: ignore[arg-type]
hint,
self.did_info.backup_ids,
uint64(self.did_info.num_of_backup_ids_needed),
self.did_info.origin_coin.name(),

View File

@ -1,6 +1,6 @@
from __future__ import annotations
from typing import Dict, Iterator, List, Optional, Tuple
from typing import Dict, Iterator, List, Optional, Tuple, Union
from chia_rs import G1Element
@ -29,28 +29,32 @@ INTERMEDIATE_LAUNCHER_MOD = load_clvm_maybe_recompile(
def create_innerpuz(
p2_puzzle: Program,
p2_puzzle_or_hash: Union[Program, bytes32],
recovery_list: List[bytes32],
num_of_backup_ids_needed: uint64,
launcher_id: bytes32,
metadata: Program = Program.to([]),
recovery_list_hash: bytes32 = None,
recovery_list_hash: Optional[bytes32] = None,
) -> Program:
"""
Create DID inner puzzle
:param p2_puzzle: Standard P2 puzzle
:param p2_puzzle_or_hash: Standard P2 puzzle or hash
:param recovery_list: A list of DIDs used for the recovery
:param num_of_backup_ids_needed: Need how many DIDs for the recovery
:param launcher_id: ID of the launch coin
:param metadata: DID customized metadata
:param recovery_list_hash: Recovery list hash
:return: DID inner puzzle
Note: Receiving a standard P2 puzzle hash wouldn't calculate a valid puzzle, but
that can be useful if calling `.get_tree_hash_precalc()` on it.
"""
backup_ids_hash = Program(Program.to(recovery_list)).get_tree_hash()
if recovery_list_hash is not None:
backup_ids_hash = recovery_list_hash
singleton_struct = Program.to((SINGLETON_TOP_LAYER_MOD_HASH, (launcher_id, SINGLETON_LAUNCHER_PUZZLE_HASH)))
return DID_INNERPUZ_MOD.curry(p2_puzzle, backup_ids_hash, num_of_backup_ids_needed, singleton_struct, metadata)
return DID_INNERPUZ_MOD.curry(
p2_puzzle_or_hash, backup_ids_hash, num_of_backup_ids_needed, singleton_struct, metadata
)
def get_inner_puzhash_by_p2(