Skip to content

Commit

Permalink
use UncurriedPuzzle for get_inner_puzzle()
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Aug 28, 2022
1 parent 1deaf01 commit ea8c04e
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 31 deletions.
8 changes: 4 additions & 4 deletions chia/wallet/cat_wallet/cat_outer_puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CATOuterPuzzle:
_match: Callable[[UncurriedPuzzle], Optional[PuzzleInfo]]
_construct: Callable[[PuzzleInfo, Program], Program]
_solve: Callable[[PuzzleInfo, Solver, Program, Program], Program]
_get_inner_puzzle: Callable[[PuzzleInfo, Program], Optional[Program]]
_get_inner_puzzle: Callable[[PuzzleInfo, UncurriedPuzzle], Optional[Program]]
_get_inner_solution: Callable[[PuzzleInfo, Program], Optional[Program]]

def match(self, puzzle: UncurriedPuzzle) -> Optional[PuzzleInfo]:
Expand All @@ -40,14 +40,14 @@ def match(self, puzzle: UncurriedPuzzle) -> Optional[PuzzleInfo]:
constructor_dict["also"] = next_constructor.info
return PuzzleInfo(constructor_dict)

def get_inner_puzzle(self, constructor: PuzzleInfo, puzzle_reveal: Program) -> Optional[Program]:
args = match_cat_puzzle(uncurry_puzzle(puzzle_reveal))
def get_inner_puzzle(self, constructor: PuzzleInfo, puzzle_reveal: UncurriedPuzzle) -> Optional[Program]:
args = match_cat_puzzle(puzzle_reveal)
if args is None:
raise ValueError("This driver is not for the specified puzzle reveal")
_, _, inner_puzzle = args
also = constructor.also()
if also is not None:
deep_inner_puzzle: Optional[Program] = self._get_inner_puzzle(also, inner_puzzle)
deep_inner_puzzle: Optional[Program] = self._get_inner_puzzle(also, uncurry_puzzle(inner_puzzle))
return deep_inner_puzzle
else:
return inner_puzzle
Expand Down
2 changes: 1 addition & 1 deletion chia/wallet/driver_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DriverProtocol(Protocol):
def match(self, puzzle: UncurriedPuzzle) -> Optional[PuzzleInfo]:
...

def get_inner_puzzle(self, constructor: PuzzleInfo, puzzle_reveal: Program) -> Optional[Program]:
def get_inner_puzzle(self, constructor: PuzzleInfo, puzzle_reveal: UncurriedPuzzle) -> Optional[Program]:
...

def get_inner_solution(self, constructor: PuzzleInfo, solution: Program) -> Optional[Program]:
Expand Down
8 changes: 4 additions & 4 deletions chia/wallet/nft_wallet/metadata_outer_puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MetadataOuterPuzzle:
_match: Callable[[UncurriedPuzzle], Optional[PuzzleInfo]]
_construct: Callable[[PuzzleInfo, Program], Program]
_solve: Callable[[PuzzleInfo, Solver, Program, Program], Program]
_get_inner_puzzle: Callable[[PuzzleInfo, Program], Optional[Program]]
_get_inner_puzzle: Callable[[PuzzleInfo, UncurriedPuzzle], Optional[Program]]
_get_inner_solution: Callable[[PuzzleInfo, Program], Optional[Program]]

def match(self, puzzle: UncurriedPuzzle) -> Optional[PuzzleInfo]:
Expand Down Expand Up @@ -63,13 +63,13 @@ def construct(self, constructor: PuzzleInfo, inner_puzzle: Program) -> Program:
inner_puzzle = self._construct(also, inner_puzzle)
return puzzle_for_metadata_layer(constructor["metadata"], constructor["updater_hash"], inner_puzzle)

def get_inner_puzzle(self, constructor: PuzzleInfo, puzzle_reveal: Program) -> Optional[Program]:
matched, curried_args = match_metadata_layer_puzzle(uncurry_puzzle(puzzle_reveal))
def get_inner_puzzle(self, constructor: PuzzleInfo, puzzle_reveal: UncurriedPuzzle) -> Optional[Program]:
matched, curried_args = match_metadata_layer_puzzle(puzzle_reveal)
if matched:
_, _, _, inner_puzzle = curried_args
also = constructor.also()
if also is not None:
deep_inner_puzzle: Optional[Program] = self._get_inner_puzzle(also, inner_puzzle)
deep_inner_puzzle: Optional[Program] = self._get_inner_puzzle(also, uncurry_puzzle(inner_puzzle))
return deep_inner_puzzle
else:
return inner_puzzle
Expand Down
2 changes: 1 addition & 1 deletion chia/wallet/nft_wallet/nft_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
)
from chia.wallet.trading.offer import OFFER_MOD, NotarizedPayment, Offer
from chia.wallet.transaction_record import TransactionRecord
from chia.wallet.uncurried_puzzle import uncurry_puzzle
from chia.wallet.util.compute_memos import compute_memos
from chia.wallet.util.debug_spend_bundle import disassemble
from chia.wallet.util.transaction_type import TransactionType
from chia.wallet.util.wallet_types import AmountWithPuzzlehash, WalletType
from chia.wallet.wallet import Wallet
from chia.wallet.wallet_coin_record import WalletCoinRecord
from chia.wallet.wallet_info import WalletInfo
from chia.wallet.uncurried_puzzle import uncurry_puzzle

_T_NFTWallet = TypeVar("_T_NFTWallet", bound="NFTWallet")

Expand Down
8 changes: 4 additions & 4 deletions chia/wallet/nft_wallet/ownership_outer_puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class OwnershipOuterPuzzle:
_match: Callable[[UncurriedPuzzle], Optional[PuzzleInfo]]
_construct: Callable[[PuzzleInfo, Program], Program]
_solve: Callable[[PuzzleInfo, Solver, Program, Program], Program]
_get_inner_puzzle: Callable[[PuzzleInfo, Program], Optional[Program]]
_get_inner_puzzle: Callable[[PuzzleInfo, UncurriedPuzzle], Optional[Program]]
_get_inner_solution: Callable[[PuzzleInfo, Program], Optional[Program]]

def match(self, puzzle: UncurriedPuzzle) -> Optional[PuzzleInfo]:
Expand Down Expand Up @@ -70,13 +70,13 @@ def construct(self, constructor: PuzzleInfo, inner_puzzle: Program) -> Program:
transfer_program = self._construct(transfer_program_info, inner_puzzle)
return puzzle_for_ownership_layer(constructor["owner"], transfer_program, inner_puzzle)

def get_inner_puzzle(self, constructor: PuzzleInfo, puzzle_reveal: Program) -> Optional[Program]:
matched, curried_args = match_ownership_layer_puzzle(uncurry_puzzle(puzzle_reveal))
def get_inner_puzzle(self, constructor: PuzzleInfo, puzzle_reveal: UncurriedPuzzle) -> Optional[Program]:
matched, curried_args = match_ownership_layer_puzzle(puzzle_reveal)
if matched:
_, _, _, inner_puzzle = curried_args
also = constructor.also()
if also is not None:
deep_inner_puzzle: Optional[Program] = self._get_inner_puzzle(also, inner_puzzle)
deep_inner_puzzle: Optional[Program] = self._get_inner_puzzle(also, uncurry_puzzle(inner_puzzle))
return deep_inner_puzzle
else:
return inner_puzzle
Expand Down
8 changes: 4 additions & 4 deletions chia/wallet/nft_wallet/singleton_outer_puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SingletonOuterPuzzle:
_match: Callable[[UncurriedPuzzle], Optional[PuzzleInfo]]
_construct: Callable[[PuzzleInfo, Program], Program]
_solve: Callable[[PuzzleInfo, Solver, Program, Program], Program]
_get_inner_puzzle: Callable[[PuzzleInfo, Program], Optional[Program]]
_get_inner_puzzle: Callable[[PuzzleInfo, UncurriedPuzzle], Optional[Program]]
_get_inner_solution: Callable[[PuzzleInfo, Program], Optional[Program]]

def match(self, puzzle: UncurriedPuzzle) -> Optional[PuzzleInfo]:
Expand Down Expand Up @@ -51,13 +51,13 @@ def construct(self, constructor: PuzzleInfo, inner_puzzle: Program) -> Program:
launcher_hash = constructor["launcher_ph"] if "launcher_ph" in constructor else SINGLETON_LAUNCHER_HASH
return puzzle_for_singleton(constructor["launcher_id"], inner_puzzle, launcher_hash)

def get_inner_puzzle(self, constructor: PuzzleInfo, puzzle_reveal: Program) -> Optional[Program]:
matched, curried_args = match_singleton_puzzle(uncurry_puzzle(puzzle_reveal))
def get_inner_puzzle(self, constructor: PuzzleInfo, puzzle_reveal: UncurriedPuzzle) -> Optional[Program]:
matched, curried_args = match_singleton_puzzle(puzzle_reveal)
if matched:
_, inner_puzzle = curried_args
also = constructor.also()
if also is not None:
deep_inner_puzzle: Optional[Program] = self._get_inner_puzzle(also, inner_puzzle)
deep_inner_puzzle: Optional[Program] = self._get_inner_puzzle(also, uncurry_puzzle(inner_puzzle))
return deep_inner_puzzle
else:
return inner_puzzle
Expand Down
4 changes: 2 additions & 2 deletions chia/wallet/nft_wallet/transfer_program_puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TransferProgramPuzzle:
_match: Callable[[UncurriedPuzzle], Optional[PuzzleInfo]]
_construct: Callable[[PuzzleInfo, Program], Program]
_solve: Callable[[PuzzleInfo, Solver, Program, Program], Program]
_get_inner_puzzle: Callable[[PuzzleInfo, Program], Optional[Program]]
_get_inner_puzzle: Callable[[PuzzleInfo, UncurriedPuzzle], Optional[Program]]
_get_inner_solution: Callable[[PuzzleInfo, Program], Optional[Program]]

def match(self, puzzle: UncurriedPuzzle) -> Optional[PuzzleInfo]:
Expand All @@ -67,7 +67,7 @@ def construct(self, constructor: PuzzleInfo, inner_puzzle: Program) -> Program:
constructor["launcher_id"], constructor["royalty_address"], constructor["royalty_percentage"]
)

def get_inner_puzzle(self, constructor: PuzzleInfo, puzzle_reveal: Program) -> Optional[Program]:
def get_inner_puzzle(self, constructor: PuzzleInfo, puzzle_reveal: UncurriedPuzzle) -> Optional[Program]:
return None

def get_inner_solution(self, constructor: PuzzleInfo, solution: Program) -> Optional[Program]:
Expand Down
4 changes: 2 additions & 2 deletions chia/wallet/outer_puzzles.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
A driver for a puzzle must include the following functions:
- match(self, puzzle: UncurriedPuzzle) -> Optional[PuzzleInfo]
- Given a puzzle reveal, return a PuzzleInfo object that can be used to reconstruct it later
- get_inner_puzzle(self, constructor: PuzzleInfo, puzzle_reveal: Program) -> Optional[Program]:
- get_inner_puzzle(self, constructor: PuzzleInfo, puzzle_reveal: UncurriedPuzzle) -> Optional[Program]:
- Given a PuzzleInfo object and a puzzle reveal, pull out this outer puzzle's inner puzzle
- asset_id(self, constructor: PuzzleInfo) -> Optional[bytes32]
- Given a PuzzleInfo object, generate a 32 byte ID for use in dictionaries, etc.
Expand Down Expand Up @@ -56,7 +56,7 @@ def solve_puzzle(constructor: PuzzleInfo, solver: Solver, inner_puzzle: Program,
return driver_lookup[AssetType(constructor.type())].solve(constructor, solver, inner_puzzle, inner_solution)


def get_inner_puzzle(constructor: PuzzleInfo, puzzle_reveal: Program) -> Optional[Program]:
def get_inner_puzzle(constructor: PuzzleInfo, puzzle_reveal: UncurriedPuzzle) -> Optional[Program]:
return driver_lookup[AssetType(constructor.type())].get_inner_puzzle(constructor, puzzle_reveal)


Expand Down
6 changes: 3 additions & 3 deletions chia/wallet/trading/offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
decompress_object_with_puzzles,
lowest_best_version,
)
from chia.wallet.uncurried_puzzle import uncurry_puzzle
from chia.wallet.uncurried_puzzle import UncurriedPuzzle, uncurry_puzzle

OFFER_MOD = load_clvm("settlement_payments.clvm")
ZERO_32 = bytes32([0] * 32)
Expand Down Expand Up @@ -146,11 +146,11 @@ def get_offered_coins(self) -> Dict[Optional[bytes32], List[Coin]]:
for parent_spend in self.bundle.coin_spends:
coins_for_this_spend: List[Coin] = []

parent_puzzle: Program = parent_spend.puzzle_reveal.to_program()
parent_puzzle: UncurriedPuzzle = uncurry_puzzle(parent_spend.puzzle_reveal.to_program())
parent_solution: Program = parent_spend.solution.to_program()
additions: List[Coin] = [a for a in parent_spend.additions() if a not in self.bundle.removals()]

puzzle_driver = match_puzzle(uncurry_puzzle(parent_puzzle))
puzzle_driver = match_puzzle(parent_puzzle)
if puzzle_driver is not None:
asset_id = create_asset_id(puzzle_driver)
inner_puzzle: Optional[Program] = get_inner_puzzle(puzzle_driver, parent_puzzle)
Expand Down
5 changes: 3 additions & 2 deletions tests/wallet/cat_wallet/test_cat_outer_puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def test_cat_outer_puzzle() -> None:
tail = bytes32([0] * 32)
cat_puzzle: Program = construct_cat_puzzle(CAT_MOD, tail, ACS)
double_cat_puzzle: Program = construct_cat_puzzle(CAT_MOD, tail, cat_puzzle)
cat_driver: Optional[PuzzleInfo] = match_puzzle(uncurry_puzzle(double_cat_puzzle))
uncurried_cat_puzzle = uncurry_puzzle(double_cat_puzzle)
cat_driver: Optional[PuzzleInfo] = match_puzzle(uncurried_cat_puzzle)

assert cat_driver is not None
assert cat_driver.type() == "CAT"
Expand All @@ -30,7 +31,7 @@ def test_cat_outer_puzzle() -> None:
assert inside_cat_driver.type() == "CAT"
assert inside_cat_driver["tail"] == tail
assert construct_puzzle(cat_driver, ACS) == double_cat_puzzle
assert get_inner_puzzle(cat_driver, double_cat_puzzle) == ACS
assert get_inner_puzzle(cat_driver, uncurried_cat_puzzle) == ACS

# Set up for solve
parent_coin = Coin(tail, double_cat_puzzle.get_tree_hash(), uint64(100))
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet/nft_wallet/test_nft_1_offers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from chia.wallet.puzzle_drivers import PuzzleInfo
from chia.wallet.trading.offer import Offer
from chia.wallet.trading.trade_status import TradeStatus
from chia.wallet.util.compute_memos import compute_memos
from chia.wallet.uncurried_puzzle import uncurry_puzzle
from chia.wallet.util.compute_memos import compute_memos

# from clvm_tools.binutils import disassemble
from tests.util.wallet_is_synced import wallets_are_synced
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet/nft_wallet/test_nft_offers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
from chia.wallet.puzzle_drivers import PuzzleInfo
from chia.wallet.trading.offer import Offer
from chia.wallet.trading.trade_status import TradeStatus
from chia.wallet.uncurried_puzzle import uncurry_puzzle
from tests.util.wallet_is_synced import wallets_are_synced
from tests.wallet.nft_wallet.test_nft_1_offers import mempool_not_empty
from chia.wallet.uncurried_puzzle import uncurry_puzzle


async def tx_in_pool(mempool: MempoolManager, tx_id: bytes32) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet/nft_wallet/test_nft_puzzles.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from chia.wallet.outer_puzzles import match_puzzle
from chia.wallet.puzzles.load_clvm import load_clvm
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import puzzle_for_pk, solution_for_conditions
from tests.core.make_block_generator import int_to_public_key
from chia.wallet.uncurried_puzzle import uncurry_puzzle
from tests.core.make_block_generator import int_to_public_key

SINGLETON_MOD = load_clvm("singleton_top_layer_v1_1.clvm")
LAUNCHER_PUZZLE = load_clvm("singleton_launcher.clvm")
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet/nft_wallet/test_ownership_outer_puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_ownership_outer_puzzle() -> None:
assert construct_puzzle(ownership_driver, ACS) == ownership_puzzle
assert construct_puzzle(ownership_driver_empty, ACS) == ownership_puzzle_empty
assert construct_puzzle(ownership_driver_default, ACS) == ownership_puzzle_default
assert get_inner_puzzle(ownership_driver, ownership_puzzle) == ACS
assert get_inner_puzzle(ownership_driver, uncurry_puzzle(ownership_puzzle)) == ACS

# Set up for solve
inner_solution = Program.to(
Expand Down

0 comments on commit ea8c04e

Please sign in to comment.