mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-11-28 11:38:38 +03:00
Annotate did_wallet_puzzles.py (#17153)
Annotate did_wallet_puzzles.py.
This commit is contained in:
parent
eb17963b31
commit
f113aa4359
@ -1,6 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Dict, Iterator, List, Optional, Tuple, Union
|
from typing import Dict, Iterator, List, Optional, Tuple, Union, cast
|
||||||
|
|
||||||
from chia_rs import G1Element
|
from chia_rs import G1Element
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ def create_innerpuz(
|
|||||||
Note: Receiving a standard P2 puzzle hash wouldn't calculate a valid puzzle, but
|
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.
|
that can be useful if calling `.get_tree_hash_precalc()` on it.
|
||||||
"""
|
"""
|
||||||
backup_ids_hash = Program(Program.to(recovery_list)).get_tree_hash()
|
backup_ids_hash = Program.to(recovery_list).get_tree_hash()
|
||||||
if recovery_list_hash is not None:
|
if recovery_list_hash is not None:
|
||||||
backup_ids_hash = recovery_list_hash
|
backup_ids_hash = recovery_list_hash
|
||||||
singleton_struct = Program.to((SINGLETON_TOP_LAYER_MOD_HASH, (launcher_id, SINGLETON_LAUNCHER_PUZZLE_HASH)))
|
singleton_struct = Program.to((SINGLETON_TOP_LAYER_MOD_HASH, (launcher_id, SINGLETON_LAUNCHER_PUZZLE_HASH)))
|
||||||
@ -123,7 +123,7 @@ def create_recovery_message_puzzle(recovering_coin_id: bytes32, newpuz: bytes32,
|
|||||||
:param pubkey: New wallet pubkey
|
:param pubkey: New wallet pubkey
|
||||||
:return: Message puzzle
|
:return: Message puzzle
|
||||||
"""
|
"""
|
||||||
return Program.to(
|
puzzle = Program.to(
|
||||||
(
|
(
|
||||||
1,
|
1,
|
||||||
[
|
[
|
||||||
@ -132,6 +132,8 @@ def create_recovery_message_puzzle(recovering_coin_id: bytes32, newpuz: bytes32,
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
# TODO: Remove cast when we have proper hinting for this
|
||||||
|
return cast(Program, puzzle)
|
||||||
|
|
||||||
|
|
||||||
def create_spend_for_message(
|
def create_spend_for_message(
|
||||||
@ -153,7 +155,7 @@ def create_spend_for_message(
|
|||||||
|
|
||||||
def match_did_puzzle(mod: Program, curried_args: Program) -> Optional[Iterator[Program]]:
|
def match_did_puzzle(mod: Program, curried_args: Program) -> Optional[Iterator[Program]]:
|
||||||
"""
|
"""
|
||||||
Given a puzzle test if it's a DID, if it is, return the curried arguments
|
Given a puzzle test if it's a DID, if it is, return the curried arguments
|
||||||
:param puzzle: Puzzle
|
:param puzzle: Puzzle
|
||||||
:return: Curried parameters
|
:return: Curried parameters
|
||||||
"""
|
"""
|
||||||
@ -161,7 +163,8 @@ def match_did_puzzle(mod: Program, curried_args: Program) -> Optional[Iterator[P
|
|||||||
if mod == SINGLETON_TOP_LAYER_MOD:
|
if mod == SINGLETON_TOP_LAYER_MOD:
|
||||||
mod, curried_args = curried_args.rest().first().uncurry()
|
mod, curried_args = curried_args.rest().first().uncurry()
|
||||||
if mod == DID_INNERPUZ_MOD:
|
if mod == DID_INNERPUZ_MOD:
|
||||||
return curried_args.as_iter()
|
# TODO: Remove cast when we have clvm type hinting for this
|
||||||
|
return cast(Iterator[Program], curried_args.as_iter())
|
||||||
except Exception:
|
except Exception:
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
@ -178,11 +181,11 @@ def check_is_did_puzzle(puzzle: Program) -> bool:
|
|||||||
r = puzzle.uncurry()
|
r = puzzle.uncurry()
|
||||||
if r is None:
|
if r is None:
|
||||||
return False
|
return False
|
||||||
inner_f, args = r
|
inner_f, _ = r
|
||||||
return is_singleton(inner_f)
|
return is_singleton(inner_f)
|
||||||
|
|
||||||
|
|
||||||
def metadata_to_program(metadata: Dict) -> Program:
|
def metadata_to_program(metadata: Dict[str, str]) -> Program:
|
||||||
"""
|
"""
|
||||||
Convert the metadata dict to a Chialisp program
|
Convert the metadata dict to a Chialisp program
|
||||||
:param metadata: User defined metadata
|
:param metadata: User defined metadata
|
||||||
@ -191,10 +194,11 @@ def metadata_to_program(metadata: Dict) -> Program:
|
|||||||
kv_list = []
|
kv_list = []
|
||||||
for key, value in metadata.items():
|
for key, value in metadata.items():
|
||||||
kv_list.append((key, value))
|
kv_list.append((key, value))
|
||||||
return Program.to(kv_list)
|
# TODO: Remove cast when we have proper hinting for this
|
||||||
|
return cast(Program, Program.to(kv_list))
|
||||||
|
|
||||||
|
|
||||||
def did_program_to_metadata(program: Program) -> Dict:
|
def did_program_to_metadata(program: Program) -> Dict[str, str]:
|
||||||
"""
|
"""
|
||||||
Convert a program to a metadata dict
|
Convert a program to a metadata dict
|
||||||
:param program: Chialisp program contains the metadata
|
:param program: Chialisp program contains the metadata
|
||||||
|
@ -22,7 +22,6 @@ chia.types.blockchain_format.program
|
|||||||
chia.wallet.block_record
|
chia.wallet.block_record
|
||||||
chia.wallet.chialisp
|
chia.wallet.chialisp
|
||||||
chia.wallet.did_wallet.did_wallet
|
chia.wallet.did_wallet.did_wallet
|
||||||
chia.wallet.did_wallet.did_wallet_puzzles
|
|
||||||
chia.wallet.key_val_store
|
chia.wallet.key_val_store
|
||||||
chia.wallet.lineage_proof
|
chia.wallet.lineage_proof
|
||||||
chia.wallet.nft_wallet.nft_puzzles
|
chia.wallet.nft_wallet.nft_puzzles
|
||||||
|
Loading…
Reference in New Issue
Block a user