Skip to content

Commit

Permalink
Remove get_new methods from cat wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
Quexington committed Dec 2, 2024
1 parent d3b5fde commit b4bea1e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 41 deletions.
18 changes: 9 additions & 9 deletions chia/_tests/wallet/cat_wallet/test_cat_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ async def test_cat_spend(wallet_environments: WalletTestFramework) -> None:

assert cat_wallet.cat_info.limitations_program_hash == cat_wallet_2.cat_info.limitations_program_hash

cat_2_hash = await cat_wallet_2.get_new_inner_hash()
cat_2_hash = await cat_wallet_2.standard_wallet.get_puzzle_hash(new=False)
async with cat_wallet.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
await cat_wallet.generate_signed_transaction([uint64(60)], [cat_2_hash], action_scope, fee=uint64(1))
tx_id = None
Expand Down Expand Up @@ -408,7 +408,7 @@ async def test_cat_spend(wallet_environments: WalletTestFramework) -> None:
memos = await env_2.rpc_client.get_transaction_memo(GetTransactionMemo(transaction_id=tx_id))
assert len(memos.coins_with_memos) == 2
assert memos.coins_with_memos[1].memos[0] == cat_2_hash
cat_hash = await cat_wallet.get_new_inner_hash()
cat_hash = await cat_wallet.standard_wallet.get_puzzle_hash(new=False)
async with cat_wallet_2.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
await cat_wallet_2.generate_signed_transaction([uint64(15)], [cat_hash], action_scope)

Expand Down Expand Up @@ -610,7 +610,7 @@ async def test_cat_doesnt_see_eve(wallet_environments: WalletTestFramework) -> N

assert cat_wallet.cat_info.limitations_program_hash == cat_wallet_2.cat_info.limitations_program_hash

cat_2_hash = await cat_wallet_2.get_new_inner_hash()
cat_2_hash = await cat_wallet_2.standard_wallet.get_puzzle_hash(new=False)
async with cat_wallet.wallet_state_manager.new_action_scope(
wallet_environments.tx_config, push=True
) as action_scope:
Expand Down Expand Up @@ -684,7 +684,7 @@ async def test_cat_doesnt_see_eve(wallet_environments: WalletTestFramework) -> N
]
)

cc2_ph = await cat_wallet_2.get_new_cat_puzzle_hash()
cc2_ph = await cat_wallet_2.get_cat_puzzle_hash(new=False)
async with wallet.wallet_state_manager.new_action_scope(wallet_environments.tx_config, push=True) as action_scope:
await wallet.wallet_state_manager.main_wallet.generate_signed_transaction(uint64(10), cc2_ph, action_scope)

Expand Down Expand Up @@ -817,8 +817,8 @@ async def test_cat_spend_multiple(wallet_environments: WalletTestFramework) -> N
assert cat_wallet_0.cat_info.limitations_program_hash == cat_wallet_1.cat_info.limitations_program_hash
assert cat_wallet_0.cat_info.limitations_program_hash == cat_wallet_2.cat_info.limitations_program_hash

cat_1_hash = await cat_wallet_1.get_new_inner_hash()
cat_2_hash = await cat_wallet_2.get_new_inner_hash()
cat_1_hash = await cat_wallet_1.standard_wallet.get_puzzle_hash(new=False)
cat_2_hash = await cat_wallet_2.standard_wallet.get_puzzle_hash(new=False)

async with cat_wallet_0.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
await cat_wallet_0.generate_signed_transaction([uint64(60), uint64(20)], [cat_1_hash, cat_2_hash], action_scope)
Expand Down Expand Up @@ -900,7 +900,7 @@ async def test_cat_spend_multiple(wallet_environments: WalletTestFramework) -> N
]
)

cat_hash = await cat_wallet_0.get_new_inner_hash()
cat_hash = await cat_wallet_0.standard_wallet.get_puzzle_hash(new=False)

async with cat_wallet_1.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
await cat_wallet_1.generate_signed_transaction([uint64(15)], [cat_hash], action_scope)
Expand Down Expand Up @@ -1107,7 +1107,7 @@ async def test_cat_max_amount_send(wallet_environments: WalletTestFramework) ->

assert cat_wallet.cat_info.limitations_program_hash is not None

cat_2 = await cat_wallet.get_new_inner_puzzle()
cat_2 = await cat_wallet.standard_wallet.get_puzzle(new=False)
cat_2_hash = cat_2.get_tree_hash()
amounts = []
puzzle_hashes = []
Expand Down Expand Up @@ -1382,7 +1382,7 @@ async def test_cat_hint(wallet_environments: WalletTestFramework) -> None:
cat_wallet_2 = wallet_node_2.wallet_state_manager.wallets[uint32(2)]
assert isinstance(cat_wallet_2, CATWallet)

cat_hash = await cat_wallet.get_new_inner_hash()
cat_hash = await cat_wallet.standard_wallet.get_puzzle_hash(new=False)
async with cat_wallet_2.wallet_state_manager.new_action_scope(
wallet_environments.tx_config, push=True
) as action_scope:
Expand Down
9 changes: 7 additions & 2 deletions chia/rpc/wallet_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,12 @@ async def split_coins(
raise ValueError("Cannot split coins from non-fungible wallet types")

outputs = [
Payment(await wallet.get_puzzle_hash(new=True), request.amount_per_coin)
Payment(
await wallet.get_puzzle_hash(new=True)
if isinstance(wallet, Wallet)
else await wallet.standard_wallet.get_puzzle_hash(new=True),
request.amount_per_coin,
)
for _ in range(request.number_of_coins)
]
if len(outputs) == 0:
Expand Down Expand Up @@ -1266,7 +1271,7 @@ async def combine_coins(
assert isinstance(wallet, CATWallet)
await wallet.generate_signed_transaction(
[primary_output_amount],
[await wallet.get_puzzle_hash(new=action_scope.config.tx_config.reuse_puzhash)],
[await wallet.standard_wallet.get_puzzle_hash(new=action_scope.config.tx_config.reuse_puzhash)],
action_scope,
request.fee,
coins=set(coins),
Expand Down
36 changes: 11 additions & 25 deletions chia/wallet/cat_wallet/cat_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,27 +422,6 @@ async def puzzle_solution_received(self, coin: Coin, parent_coin_data: Optional[
# We also need to make sure there's no record of the transaction
await self.wallet_state_manager.tx_store.delete_transaction_record(record.coin.name())

async def get_new_inner_hash(self) -> bytes32:
puzzle = await self.get_new_inner_puzzle()
return puzzle.get_tree_hash()

async def get_new_inner_puzzle(self) -> Program:
return await self.standard_wallet.get_new_puzzle()

async def get_new_puzzlehash(self) -> bytes32:
return await self.standard_wallet.get_new_puzzlehash()

async def get_puzzle_hash(self, new: bool) -> bytes32:
if new:
return await self.get_new_puzzlehash()
else:
record: Optional[
DerivationRecord
] = await self.wallet_state_manager.get_current_derivation_record_for_wallet(self.standard_wallet.id())
if record is None:
return await self.get_new_puzzlehash()
return record.puzzle_hash

def require_derivation_paths(self) -> bool:
return True

Expand All @@ -456,8 +435,15 @@ def puzzle_hash_for_pk(self, pubkey: G1Element) -> bytes32:
limitations_program_hash_hash = Program.to(self.cat_info.limitations_program_hash).get_tree_hash()
return curry_and_treehash(QUOTED_MOD_HASH, CAT_MOD_HASH_HASH, limitations_program_hash_hash, inner_puzzle_hash)

async def get_new_cat_puzzle_hash(self) -> bytes32:
return (await self.wallet_state_manager.get_unused_derivation_record(self.id())).puzzle_hash
async def get_cat_puzzle_hash(self, new: bool) -> bytes32:
if new:
return (await self.wallet_state_manager.get_unused_derivation_record(self.id())).puzzle_hash
else:
derivation_record = await self.wallet_state_manager.get_current_derivation_record_for_wallet(self.id())
if derivation_record is None:
return (await self.wallet_state_manager.get_unused_derivation_record(self.id())).puzzle_hash

return derivation_record.puzzle_hash

async def get_spendable_balance(self, records: Optional[set[WalletCoinRecord]] = None) -> uint128:
coins = await self.get_cat_spendable_coins(records)
Expand Down Expand Up @@ -673,10 +659,10 @@ async def generate_unsigned_spendbundle(
for payment in payments:
if change_puzhash == payment.puzzle_hash and change == payment.amount:
# We cannot create two coins has same id, create a new puzhash for the change
change_puzhash = await self.get_new_inner_hash()
change_puzhash = await self.standard_wallet.get_puzzle_hash(new=True)
break
else:
change_puzhash = await self.get_new_inner_hash()
change_puzhash = await self.standard_wallet.get_puzzle_hash(new=True)
primaries.append(Payment(change_puzhash, uint64(change), [change_puzhash]))

# Loop through the coins we've selected and gather the information we need to spend them
Expand Down
11 changes: 8 additions & 3 deletions chia/wallet/trade_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,14 @@ async def _create_offer_for_ids(
wallet_id = uint32(id)
wallet = self.wallet_state_manager.wallets.get(wallet_id)
assert isinstance(wallet, (CATWallet, Wallet))
p2_ph: bytes32 = await wallet.get_puzzle_hash(
new=not action_scope.config.tx_config.reuse_puzhash
)
if isinstance(wallet, Wallet):
p2_ph: bytes32 = await wallet.get_puzzle_hash(
new=not action_scope.config.tx_config.reuse_puzhash
)
else:
p2_ph = await wallet.standard_wallet.get_puzzle_hash(
new=not action_scope.config.tx_config.reuse_puzhash
)
if wallet.type() != WalletType.STANDARD_WALLET:
if callable(getattr(wallet, "get_asset_id", None)): # ATTENTION: new wallets
assert isinstance(wallet, CATWallet)
Expand Down
4 changes: 2 additions & 2 deletions chia/wallet/vc_wallet/cr_cat_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,10 @@ async def _generate_unsigned_spendbundle(
for payment in payments:
if change_puzhash == payment.puzzle_hash and change == payment.amount:
# We cannot create two coins has same id, create a new puzhash for the change
change_puzhash = await self.get_new_inner_hash()
change_puzhash = await self.standard_wallet.get_puzzle_hash(new=True)
break
else:
change_puzhash = await self.get_new_inner_hash()
change_puzhash = await self.standard_wallet.get_puzzle_hash(new=True)
primaries.append(Payment(change_puzhash, uint64(change), [change_puzhash]))

# Find the VC Wallet
Expand Down

0 comments on commit b4bea1e

Please sign in to comment.