mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2025-01-08 10:25:24 +03:00
wallet: Drop puzzles/genesis_checkers.py
and related puzzles (#10790)
Its all duplicated code and puzzles as far as i can tell, see `chia/wallet/puzzles/tails.py`.
This commit is contained in:
parent
d892e14c64
commit
0917d0ae78
@ -120,7 +120,6 @@ extend_skip=
|
||||
chia/wallet/did_wallet/did_wallet.py
|
||||
chia/wallet/lineage_proof.py
|
||||
chia/wallet/payment.py
|
||||
chia/wallet/puzzles/genesis_checkers.py
|
||||
chia/wallet/puzzles/load_clvm.py
|
||||
chia/wallet/puzzles/prefarm/make_prefarm_ph.py
|
||||
chia/wallet/puzzles/prefarm/spend_prefarm.py
|
||||
|
@ -36,7 +36,7 @@ from chia.wallet.derivation_record import DerivationRecord
|
||||
from chia.wallet.cat_wallet.lineage_store import CATLineageStore
|
||||
from chia.wallet.lineage_proof import LineageProof
|
||||
from chia.wallet.payment import Payment
|
||||
from chia.wallet.puzzles.genesis_checkers import ALL_LIMITATIONS_PROGRAMS
|
||||
from chia.wallet.puzzles.tails import ALL_LIMITATIONS_PROGRAMS
|
||||
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import (
|
||||
DEFAULT_HIDDEN_PUZZLE_HASH,
|
||||
calculate_synthetic_secret_key,
|
||||
|
@ -1,25 +0,0 @@
|
||||
; This is a "limitations_program" for use with cat.clvm.
|
||||
(mod (
|
||||
PUBKEY
|
||||
Truths
|
||||
parent_is_cat
|
||||
lineage_proof
|
||||
delta
|
||||
inner_conditions
|
||||
(
|
||||
delegated_puzzle
|
||||
delegated_solution
|
||||
)
|
||||
)
|
||||
|
||||
(include condition_codes.clvm)
|
||||
|
||||
(defun sha256tree1 (TREE)
|
||||
(if (l TREE)
|
||||
(sha256 2 (sha256tree1 (f TREE)) (sha256tree1 (r TREE)))
|
||||
(sha256 1 TREE)))
|
||||
|
||||
(c (list AGG_SIG_UNSAFE PUBKEY (sha256tree1 delegated_puzzle))
|
||||
(a delegated_puzzle (c Truths (c parent_is_cat (c lineage_proof (c delta (c inner_conditions delegated_solution))))))
|
||||
)
|
||||
)
|
@ -1 +0,0 @@
|
||||
ff02ffff01ff04ffff04ff04ffff04ff05ffff04ffff02ff06ffff04ff02ffff04ff82027fff80808080ff80808080ffff02ff82027fffff04ff0bffff04ff17ffff04ff2fffff04ff5fffff04ff81bfff82057f80808080808080ffff04ffff01ff31ff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff06ffff04ff02ffff04ff09ff80808080ffff02ff06ffff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff018080
|
@ -1 +0,0 @@
|
||||
999c3696e167f8a79d938adc11feba3a3dcb39ccff69a426d570706e7b8ec399
|
@ -1,26 +0,0 @@
|
||||
; This is a "genesis checker" for use with cc.clvm.
|
||||
;
|
||||
; This checker allows new CATs to be created if they have a particular coin id as parent
|
||||
;
|
||||
; The genesis_id is curried in, making this lineage_check program unique and giving the CAT it's uniqueness
|
||||
(mod (
|
||||
GENESIS_ID
|
||||
Truths
|
||||
parent_is_cat
|
||||
lineage_proof
|
||||
delta
|
||||
inner_conditions
|
||||
_
|
||||
)
|
||||
|
||||
(include cat_truths.clib)
|
||||
|
||||
(if delta
|
||||
(x)
|
||||
(if (= (my_parent_cat_truth Truths) GENESIS_ID)
|
||||
()
|
||||
(x)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
@ -1 +0,0 @@
|
||||
ff02ffff03ff2fffff01ff0880ffff01ff02ffff03ffff09ff2dff0280ff80ffff01ff088080ff018080ff0180
|
@ -1 +0,0 @@
|
||||
493afb89eed93ab86741b2aa61b8f5de495d33ff9b781dfc8919e602b2afa150
|
@ -1,24 +0,0 @@
|
||||
; This is a "limitations_program" for use with cat.clvm.
|
||||
;
|
||||
; This checker allows new CATs to be created if their parent has a particular puzzle hash
|
||||
(mod (
|
||||
GENESIS_PUZZLE_HASH
|
||||
Truths
|
||||
parent_is_cat
|
||||
lineage_proof
|
||||
delta
|
||||
inner_conditions
|
||||
(parent_parent_id parent_amount)
|
||||
)
|
||||
|
||||
(include cat_truths.clib)
|
||||
|
||||
; Returns nil since we don't need to add any conditions
|
||||
(if delta
|
||||
(x)
|
||||
(if (= (sha256 parent_parent_id GENESIS_PUZZLE_HASH parent_amount) (my_parent_cat_truth Truths))
|
||||
()
|
||||
(x)
|
||||
)
|
||||
)
|
||||
)
|
@ -1 +0,0 @@
|
||||
ff02ffff03ff2fffff01ff0880ffff01ff02ffff03ffff09ffff0bff82013fff02ff8202bf80ff2d80ff80ffff01ff088080ff018080ff0180
|
@ -1 +0,0 @@
|
||||
de5a6e06d41518be97ff6365694f4f89475dda773dede267caa33da63b434e36
|
@ -1,208 +0,0 @@
|
||||
from typing import Tuple, Dict, List, Optional, Any
|
||||
|
||||
from chia.types.blockchain_format.program import Program
|
||||
from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
from chia.types.spend_bundle import SpendBundle
|
||||
from chia.util.ints import uint64
|
||||
from chia.util.byte_types import hexstr_to_bytes
|
||||
from chia.wallet.lineage_proof import LineageProof
|
||||
from chia.wallet.puzzles.load_clvm import load_clvm
|
||||
from chia.wallet.cat_wallet.cat_utils import (
|
||||
CAT_MOD,
|
||||
construct_cat_puzzle,
|
||||
unsigned_spend_bundle_for_spendable_cats,
|
||||
SpendableCAT,
|
||||
)
|
||||
from chia.wallet.cat_wallet.cat_info import CATInfo
|
||||
from chia.wallet.transaction_record import TransactionRecord
|
||||
|
||||
GENESIS_BY_ID_MOD = load_clvm("genesis-by-coin-id-with-0.clvm")
|
||||
GENESIS_BY_PUZHASH_MOD = load_clvm("genesis-by-puzzle-hash-with-0.clvm")
|
||||
EVERYTHING_WITH_SIG_MOD = load_clvm("everything_with_signature.clvm")
|
||||
DELEGATED_LIMITATIONS_MOD = load_clvm("delegated_genesis_checker.clvm")
|
||||
|
||||
|
||||
class LimitationsProgram:
|
||||
@staticmethod
|
||||
def match(uncurried_mod: Program, curried_args: Program) -> Tuple[bool, List[Program]]:
|
||||
raise NotImplementedError("Need to implement 'match' on limitations programs")
|
||||
|
||||
@staticmethod
|
||||
def construct(args: List[Program]) -> Program:
|
||||
raise NotImplementedError("Need to implement 'construct' on limitations programs")
|
||||
|
||||
@staticmethod
|
||||
def solve(args: List[Program], solution_dict: Dict) -> Program:
|
||||
raise NotImplementedError("Need to implement 'solve' on limitations programs")
|
||||
|
||||
@classmethod
|
||||
async def generate_issuance_bundle(
|
||||
cls, wallet, cat_tail_info: Dict, amount: uint64
|
||||
) -> Tuple[TransactionRecord, SpendBundle]:
|
||||
raise NotImplementedError("Need to implement 'generate_issuance_bundle' on limitations programs")
|
||||
|
||||
|
||||
class GenesisById(LimitationsProgram):
|
||||
"""
|
||||
This TAIL allows for coins to be issued only by a specific "genesis" coin ID.
|
||||
There can therefore only be one issuance. There is no minting or melting allowed.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def match(uncurried_mod: Program, curried_args: Program) -> Tuple[bool, List[Program]]:
|
||||
if uncurried_mod == GENESIS_BY_ID_MOD:
|
||||
genesis_id = curried_args.first()
|
||||
return True, [genesis_id]
|
||||
else:
|
||||
return False, []
|
||||
|
||||
@staticmethod
|
||||
def construct(args: List[Program]) -> Program:
|
||||
return GENESIS_BY_ID_MOD.curry(args[0])
|
||||
|
||||
@staticmethod
|
||||
def solve(args: List[Program], solution_dict: Dict) -> Program:
|
||||
return Program.to([])
|
||||
|
||||
@classmethod
|
||||
async def generate_issuance_bundle(cls, wallet, _: Dict, amount: uint64) -> Tuple[TransactionRecord, SpendBundle]:
|
||||
coins = await wallet.standard_wallet.select_coins(amount)
|
||||
|
||||
origin = coins.copy().pop()
|
||||
origin_id = origin.name()
|
||||
|
||||
cat_inner: Program = await wallet.get_new_inner_puzzle()
|
||||
await wallet.add_lineage(origin_id, LineageProof(), False)
|
||||
genesis_coin_checker: Program = cls.construct([Program.to(origin_id)])
|
||||
|
||||
minted_cat_puzzle_hash: bytes32 = construct_cat_puzzle(
|
||||
CAT_MOD, genesis_coin_checker.get_tree_hash(), cat_inner
|
||||
).get_tree_hash()
|
||||
|
||||
tx_record: TransactionRecord = await wallet.standard_wallet.generate_signed_transaction(
|
||||
amount, minted_cat_puzzle_hash, uint64(0), origin_id, coins
|
||||
)
|
||||
assert tx_record.spend_bundle is not None
|
||||
|
||||
inner_solution = wallet.standard_wallet.add_condition_to_solution(
|
||||
Program.to([51, 0, -113, genesis_coin_checker, []]),
|
||||
wallet.standard_wallet.make_solution(
|
||||
primaries=[{"puzzlehash": cat_inner.get_tree_hash(), "amount": amount}],
|
||||
),
|
||||
)
|
||||
eve_spend = unsigned_spend_bundle_for_spendable_cats(
|
||||
CAT_MOD,
|
||||
[
|
||||
SpendableCAT(
|
||||
list(filter(lambda a: a.amount == amount, tx_record.additions))[0],
|
||||
genesis_coin_checker.get_tree_hash(),
|
||||
cat_inner,
|
||||
inner_solution,
|
||||
limitations_program_reveal=genesis_coin_checker,
|
||||
)
|
||||
],
|
||||
)
|
||||
signed_eve_spend = await wallet.sign(eve_spend)
|
||||
|
||||
if wallet.cat_info.my_tail is None:
|
||||
await wallet.save_info(
|
||||
CATInfo(genesis_coin_checker.get_tree_hash(), genesis_coin_checker),
|
||||
False,
|
||||
)
|
||||
|
||||
return tx_record, SpendBundle.aggregate([tx_record.spend_bundle, signed_eve_spend])
|
||||
|
||||
|
||||
class GenesisByPuzhash(LimitationsProgram):
|
||||
"""
|
||||
This TAIL allows for issuance of a certain coin only by a specific puzzle hash.
|
||||
There is no minting or melting allowed.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def match(uncurried_mod: Program, curried_args: Program) -> Tuple[bool, List[Program]]:
|
||||
if uncurried_mod == GENESIS_BY_PUZHASH_MOD:
|
||||
genesis_puzhash = curried_args.first()
|
||||
return True, [genesis_puzhash]
|
||||
else:
|
||||
return False, []
|
||||
|
||||
@staticmethod
|
||||
def construct(args: List[Program]) -> Program:
|
||||
return GENESIS_BY_PUZHASH_MOD.curry(args[0])
|
||||
|
||||
@staticmethod
|
||||
def solve(args: List[Program], solution_dict: Dict) -> Program:
|
||||
pid = hexstr_to_bytes(solution_dict["parent_coin_info"])
|
||||
return Program.to([pid, solution_dict["amount"]])
|
||||
|
||||
|
||||
class EverythingWithSig(LimitationsProgram):
|
||||
"""
|
||||
This TAIL allows for issuance, minting, and melting as long as you provide a signature with the spend.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def match(uncurried_mod: Program, curried_args: Program) -> Tuple[bool, List[Program]]:
|
||||
if uncurried_mod == EVERYTHING_WITH_SIG_MOD:
|
||||
pubkey = curried_args.first()
|
||||
return True, [pubkey]
|
||||
else:
|
||||
return False, []
|
||||
|
||||
@staticmethod
|
||||
def construct(args: List[Program]) -> Program:
|
||||
return EVERYTHING_WITH_SIG_MOD.curry(args[0])
|
||||
|
||||
@staticmethod
|
||||
def solve(args: List[Program], solution_dict: Dict) -> Program:
|
||||
return Program.to([])
|
||||
|
||||
|
||||
class DelegatedLimitations(LimitationsProgram):
|
||||
"""
|
||||
This TAIL allows for another TAIL to be used, as long as a signature of that TAIL's puzzlehash is included.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def match(uncurried_mod: Program, curried_args: Program) -> Tuple[bool, List[Program]]:
|
||||
if uncurried_mod == DELEGATED_LIMITATIONS_MOD:
|
||||
pubkey = curried_args.first()
|
||||
return True, [pubkey]
|
||||
else:
|
||||
return False, []
|
||||
|
||||
@staticmethod
|
||||
def construct(args: List[Program]) -> Program:
|
||||
return DELEGATED_LIMITATIONS_MOD.curry(args[0])
|
||||
|
||||
@staticmethod
|
||||
def solve(args: List[Program], solution_dict: Dict) -> Program:
|
||||
signed_program = ALL_LIMITATIONS_PROGRAMS[solution_dict["signed_program"]["identifier"]]
|
||||
inner_program_args = [Program.fromhex(item) for item in solution_dict["signed_program"]["args"]]
|
||||
inner_solution_dict = solution_dict["program_arguments"]
|
||||
return Program.to(
|
||||
[
|
||||
signed_program.construct(inner_program_args),
|
||||
signed_program.solve(inner_program_args, inner_solution_dict),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
# This should probably be much more elegant than just a dictionary with strings as identifiers
|
||||
# Right now this is small and experimental so it can stay like this
|
||||
ALL_LIMITATIONS_PROGRAMS: Dict[str, Any] = {
|
||||
"genesis_by_id": GenesisById,
|
||||
"genesis_by_puzhash": GenesisByPuzhash,
|
||||
"everything_with_signature": EverythingWithSig,
|
||||
"delegated_limitations": DelegatedLimitations,
|
||||
}
|
||||
|
||||
|
||||
def match_limitations_program(limitations_program: Program) -> Tuple[Optional[LimitationsProgram], List[Program]]:
|
||||
uncurried_mod, curried_args = limitations_program.uncurry()
|
||||
for key, lp in ALL_LIMITATIONS_PROGRAMS.items():
|
||||
matched, args = lp.match(uncurried_mod, curried_args)
|
||||
if matched:
|
||||
return lp, args
|
||||
return None, []
|
@ -40,9 +40,6 @@ wallet_program_files = set(
|
||||
"chia/wallet/puzzles/delegated_tail.clvm",
|
||||
"chia/wallet/puzzles/settlement_payments.clvm",
|
||||
"chia/wallet/puzzles/genesis_by_coin_id.clvm",
|
||||
"chia/wallet/puzzles/genesis-by-puzzle-hash-with-0.clvm",
|
||||
"chia/wallet/puzzles/delegated_genesis_checker.clvm",
|
||||
"chia/wallet/puzzles/genesis-by-coin-id-with-0.clvm",
|
||||
]
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user