Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHIA-773] Swap out Payment for CreateCoin #19144

Merged
merged 4 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions chia/_tests/core/mempool/test_mempool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
from chia.types.spend_bundle_conditions import SpendBundleConditions, SpendConditions
from chia.util.errors import Err, ValidationError
from chia.util.ints import uint8, uint32, uint64
from chia.wallet.conditions import AssertCoinAnnouncement
from chia.wallet.payment import Payment
from chia.wallet.conditions import AssertCoinAnnouncement, CreateCoin
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG
from chia.wallet.wallet import Wallet
from chia.wallet.wallet_coin_record import WalletCoinRecord
Expand Down Expand Up @@ -1653,7 +1652,7 @@ async def make_setup_and_coins(
phs = [await wallet.get_new_puzzlehash() for _ in range(3)]
for _ in range(2):
await farm_a_block(full_node_api, wallet_node, ph)
other_recipients = [Payment(puzzle_hash=p, amount=uint64(200), memos=[]) for p in phs[1:]]
other_recipients = [CreateCoin(puzzle_hash=p, amount=uint64(200)) for p in phs[1:]]
async with wallet.wallet_state_manager.new_action_scope(
DEFAULT_TX_CONFIG, push=False, sign=True
) as action_scope:
Expand Down
5 changes: 2 additions & 3 deletions chia/_tests/wallet/cat_wallet/test_cat_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1641,8 +1641,7 @@ async def test_cat_melt_balance(wallet_environments: WalletTestFramework) -> Non

from chia.simulator.simulator_protocol import GetAllCoinsProtocol
from chia.wallet.cat_wallet.cat_utils import SpendableCAT, unsigned_spend_bundle_for_spendable_cats
from chia.wallet.conditions import UnknownCondition
from chia.wallet.payment import Payment
from chia.wallet.conditions import CreateCoin, UnknownCondition

await simulator.farm_blocks_to_puzzlehash(count=1, farm_to=CAT_w_ACS_HASH, guarantee_transaction_blocks=True)
await simulator.farm_blocks_to_puzzlehash(count=1)
Expand Down Expand Up @@ -1703,7 +1702,7 @@ async def test_cat_melt_balance(wallet_environments: WalletTestFramework) -> Non
limitations_program_hash=ACS_TAIL_HASH,
inner_puzzle=await cat_wallet.inner_puzzle_for_cat_puzhash(new_coin.puzzle_hash),
inner_solution=wallet.make_solution(
primaries=[Payment(wallet_ph, uint64(tx_amount), [wallet_ph])],
primaries=[CreateCoin(wallet_ph, uint64(tx_amount), [wallet_ph])],
conditions=(
UnknownCondition(
opcode=Program.to(51),
Expand Down
28 changes: 15 additions & 13 deletions chia/_tests/wallet/cat_wallet/test_offer_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
construct_cat_puzzle,
unsigned_spend_bundle_for_spendable_cats,
)
from chia.wallet.conditions import AssertPuzzleAnnouncement, ConditionValidTimes
from chia.wallet.conditions import AssertPuzzleAnnouncement, ConditionValidTimes, CreateCoin
from chia.wallet.outer_puzzles import AssetType
from chia.wallet.payment import Payment
from chia.wallet.puzzle_drivers import PuzzleInfo
from chia.wallet.trading.offer import OFFER_MOD, Offer
from chia.wallet.wallet_spend_bundle import WalletSpendBundle
Expand Down Expand Up @@ -60,7 +59,7 @@ async def generate_coins(
tail_hash = tail.get_tree_hash()
cat_puzzle = construct_cat_puzzle(CAT_MOD, tail_hash, acs)
cat_puzzle_hash = cat_puzzle.get_tree_hash()
payments.append(Payment(cat_puzzle_hash, uint64(amount)))
payments.append(CreateCoin(cat_puzzle_hash, uint64(amount)))
cat_bundles.append(
unsigned_spend_bundle_for_spendable_cats(
CAT_MOD,
Expand All @@ -75,7 +74,7 @@ async def generate_coins(
)
)
else:
payments.append(Payment(acs_ph, uint64(amount)))
payments.append(CreateCoin(acs_ph, uint64(amount)))

# This bundle creates all of the initial coins
parent_bundle = WalletSpendBundle(
Expand Down Expand Up @@ -178,8 +177,11 @@ async def test_complex_offer(cost_logger: CostLogger) -> None:
driver_dict_as_infos = {key.hex(): value.info for key, value in driver_dict.items()}

# Create an XCH Offer for RED
chia_requested_payments: dict[Optional[bytes32], list[Payment]] = {
str_to_tail_hash("red"): [Payment(acs_ph, uint64(100), [b"memo"]), Payment(acs_ph, uint64(200), [b"memo"])]
chia_requested_payments: dict[Optional[bytes32], list[CreateCoin]] = {
str_to_tail_hash("red"): [
CreateCoin(acs_ph, uint64(100), [b"memo"]),
CreateCoin(acs_ph, uint64(200), [b"memo"]),
]
}
chia_notarized_payments = Offer.notarize_payments(chia_requested_payments, chia_coins)
chia_announcements = Offer.calculate_announcements(chia_notarized_payments, driver_dict)
Expand All @@ -190,8 +192,8 @@ async def test_complex_offer(cost_logger: CostLogger) -> None:
# Create a RED Offer for XCH
red_coins_1 = red_coins[0:1]
red_coins_2 = red_coins[1:]
red_requested_payments: dict[Optional[bytes32], list[Payment]] = {
None: [Payment(acs_ph, uint64(300), [b"red memo"]), Payment(acs_ph, uint64(350), [b"red memo"])]
red_requested_payments: dict[Optional[bytes32], list[CreateCoin]] = {
None: [CreateCoin(acs_ph, uint64(300), [b"red memo"]), CreateCoin(acs_ph, uint64(350), [b"red memo"])]
}
red_notarized_payments = Offer.notarize_payments(red_requested_payments, red_coins_1)
red_announcements = Offer.calculate_announcements(red_notarized_payments, driver_dict)
Expand All @@ -201,8 +203,8 @@ async def test_complex_offer(cost_logger: CostLogger) -> None:
red_offer = Offer(red_notarized_payments, red_secured_bundle, driver_dict)
assert not red_offer.is_valid()

red_requested_payments_2: dict[Optional[bytes32], list[Payment]] = {
None: [Payment(acs_ph, uint64(50), [b"red memo"])]
red_requested_payments_2: dict[Optional[bytes32], list[CreateCoin]] = {
None: [CreateCoin(acs_ph, uint64(50), [b"red memo"])]
}
red_notarized_payments_2 = Offer.notarize_payments(red_requested_payments_2, red_coins_2)
red_announcements_2 = Offer.calculate_announcements(red_notarized_payments_2, driver_dict)
Expand All @@ -219,9 +221,9 @@ async def test_complex_offer(cost_logger: CostLogger) -> None:
assert new_offer.is_valid()

# Create yet another offer of BLUE for XCH and RED
blue_requested_payments: dict[Optional[bytes32], list[Payment]] = {
None: [Payment(acs_ph, uint64(200), [b"blue memo"])],
str_to_tail_hash("red"): [Payment(acs_ph, uint64(50), [b"blue memo"])],
blue_requested_payments: dict[Optional[bytes32], list[CreateCoin]] = {
None: [CreateCoin(acs_ph, uint64(200), [b"blue memo"])],
str_to_tail_hash("red"): [CreateCoin(acs_ph, uint64(50), [b"blue memo"])],
}
blue_notarized_payments = Offer.notarize_payments(blue_requested_payments, blue_coins)
blue_announcements = Offer.calculate_announcements(blue_notarized_payments, driver_dict)
Expand Down
30 changes: 15 additions & 15 deletions chia/_tests/wallet/sync/test_wallet_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
from chia.types.validation_state import ValidationState
from chia.util.hash import std_hash
from chia.util.ints import uint32, uint64, uint128
from chia.wallet.conditions import CreateCoin
from chia.wallet.nft_wallet.nft_wallet import NFTWallet
from chia.wallet.payment import Payment
from chia.wallet.util.compute_memos import compute_memos
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG
from chia.wallet.util.wallet_sync_utils import PeerRequestException
Expand Down Expand Up @@ -665,11 +665,11 @@ async def test_request_additions_success(simulator_and_wallet: OldSimulatorsAndW

await full_node_api.wait_for_wallet_synced(wallet_node=wallet_node, timeout=20)

payees: list[Payment] = []
payees: list[CreateCoin] = []
for i in range(10):
payee_ph = await wallet.get_new_puzzlehash()
payees.append(Payment(payee_ph, uint64(i + 100)))
payees.append(Payment(payee_ph, uint64(i + 200)))
payees.append(CreateCoin(payee_ph, uint64(i + 100)))
payees.append(CreateCoin(payee_ph, uint64(i + 200)))

async with wallet.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
await wallet.generate_signed_transaction(uint64(0), ph, action_scope, primaries=payees)
Expand Down Expand Up @@ -880,9 +880,9 @@ async def test_dusted_wallet(
await full_node_api.wait_for_wallets_synced(wallet_nodes=[farm_wallet_node, dust_wallet_node], timeout=20)

# Part 1: create a single dust coin
payees: list[Payment] = []
payees: list[CreateCoin] = []
payee_ph = await dust_wallet.get_new_puzzlehash()
payees.append(Payment(payee_ph, uint64(dust_value)))
payees.append(CreateCoin(payee_ph, uint64(dust_value)))

# construct and send tx
async with farm_wallet.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
Expand Down Expand Up @@ -939,7 +939,7 @@ async def test_dusted_wallet(

while dust_remaining > 0:
payee_ph = await dust_wallet.get_new_puzzlehash()
payees.append(Payment(payee_ph, uint64(dust_value)))
payees.append(CreateCoin(payee_ph, uint64(dust_value)))

# After every 100 (at most) coins added, push the tx and advance the chain
# This greatly speeds up the overall process
Expand Down Expand Up @@ -1007,7 +1007,7 @@ async def test_dusted_wallet(

for _ in range(large_coins):
payee_ph = await dust_wallet.get_new_puzzlehash()
payees.append(Payment(payee_ph, uint64(xch_spam_amount)))
payees.append(CreateCoin(payee_ph, uint64(xch_spam_amount)))

# construct and send tx
async with farm_wallet.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
Expand Down Expand Up @@ -1046,7 +1046,7 @@ async def test_dusted_wallet(
payees = []

payee_ph = await dust_wallet.get_new_puzzlehash()
payees.append(Payment(payee_ph, uint64(dust_value)))
payees.append(CreateCoin(payee_ph, uint64(dust_value)))

# construct and send tx
async with farm_wallet.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
Expand Down Expand Up @@ -1090,17 +1090,17 @@ async def test_dusted_wallet(
payee_ph = await dust_wallet.get_new_puzzlehash()

# Create a large coin and add on the appropriate balance.
payees.append(Payment(payee_ph, uint64(xch_spam_amount + i)))
payees.append(CreateCoin(payee_ph, uint64(xch_spam_amount + i)))
large_coins += 1
large_coin_balance += xch_spam_amount + i

payee_ph = await dust_wallet.get_new_puzzlehash()

# Make sure we are always creating coins with a positive value.
if xch_spam_amount - dust_value - i > 0:
payees.append(Payment(payee_ph, uint64(xch_spam_amount - dust_value - i)))
payees.append(CreateCoin(payee_ph, uint64(xch_spam_amount - dust_value - i)))
else:
payees.append(Payment(payee_ph, uint64(dust_value)))
payees.append(CreateCoin(payee_ph, uint64(dust_value)))
# In cases where xch_spam_amount is sufficiently low,
# the new dust should be considered a large coina and not be filtered.
if xch_spam_amount <= dust_value:
Expand Down Expand Up @@ -1141,7 +1141,7 @@ async def test_dusted_wallet(
# Send 1 mojo from the dust wallet. The dust wallet should receive a change coin valued at "xch_spam_amount-1".

payee_ph = await farm_wallet.get_new_puzzlehash()
payees = [Payment(payee_ph, uint64(balance))]
payees = [CreateCoin(payee_ph, uint64(balance))]

# construct and send tx
async with dust_wallet.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
Expand Down Expand Up @@ -1182,7 +1182,7 @@ async def test_dusted_wallet(

while coins_remaining > 0:
payee_ph = await dust_wallet.get_new_puzzlehash()
payees.append(Payment(payee_ph, uint64(coin_value)))
payees.append(CreateCoin(payee_ph, uint64(coin_value)))

# After every 100 (at most) coins added, push the tx and advance the chain
# This greatly speeds up the overall process
Expand Down Expand Up @@ -1230,7 +1230,7 @@ async def test_dusted_wallet(

# Send a 1 mojo coin from the dust wallet to the farm wallet
payee_ph = await farm_wallet.get_new_puzzlehash()
payees = [Payment(payee_ph, uint64(1))]
payees = [CreateCoin(payee_ph, uint64(1))]

# construct and send tx
async with dust_wallet.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
Expand Down
5 changes: 2 additions & 3 deletions chia/_tests/wallet/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
from chia.util.bech32m import encode_puzzle_hash
from chia.util.errors import Err
from chia.util.ints import uint16, uint32, uint64
from chia.wallet.conditions import ConditionValidTimes
from chia.wallet.conditions import ConditionValidTimes, CreateCoin
from chia.wallet.derive_keys import master_sk_to_wallet_sk
from chia.wallet.payment import Payment
from chia.wallet.puzzles.clawback.metadata import AutoClaimSettings
from chia.wallet.transaction_record import TransactionRecord
from chia.wallet.util.query_filter import TransactionTypeFilter
Expand Down Expand Up @@ -1580,7 +1579,7 @@ async def test_wallet_create_hit_max_send_amount(self, wallet_environments: Wall
wallet = env.xch_wallet

ph = await wallet.get_puzzle_hash(False)
primaries = [Payment(ph, uint64(1000000000 + i)) for i in range(int(wallet.max_send_quantity) + 1)]
primaries = [CreateCoin(ph, uint64(1000000000 + i)) for i in range(int(wallet.max_send_quantity) + 1)]
async with wallet.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
await wallet.generate_signed_transaction(uint64(1), ph, action_scope, uint64(0), primaries=primaries)

Expand Down
6 changes: 3 additions & 3 deletions chia/_tests/wallet/vc_wallet/test_vc_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from chia.util.errors import Err
from chia.util.hash import std_hash
from chia.util.ints import uint32, uint64
from chia.wallet.conditions import CreateCoin
from chia.wallet.lineage_proof import LineageProof
from chia.wallet.payment import Payment
from chia.wallet.puzzles.singleton_top_layer_v1_1 import (
launch_conditions_and_coinsol,
puzzle_for_singleton,
Expand Down Expand Up @@ -615,15 +615,15 @@ async def test_vc_lifecycle(test_syncing: bool, cost_logger: CostLogger) -> None
AUTHORIZED_PROVIDERS: list[bytes32] = [launcher_id]
dpuz_1, launch_crcat_spend_1, cr_1 = CRCAT.launch(
cr_coin_1,
Payment(ACS_PH, uint64(cr_coin_1.amount), []),
CreateCoin(ACS_PH, uint64(cr_coin_1.amount)),
Program.to(None),
Program.to(None),
AUTHORIZED_PROVIDERS,
proofs_checker.as_program(),
)
dpuz_2, launch_crcat_spend_2, cr_2 = CRCAT.launch(
cr_coin_2,
Payment(ACS_PH, uint64(cr_coin_2.amount), []),
CreateCoin(ACS_PH, uint64(cr_coin_2.amount)),
Program.to(None),
Program.to(None),
AUTHORIZED_PROVIDERS,
Expand Down
6 changes: 3 additions & 3 deletions chia/data_layer/data_layer_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
AssertCoinAnnouncement,
AssertPuzzleAnnouncement,
Condition,
CreateCoin,
CreateCoinAnnouncement,
UnknownCondition,
parse_timelock_info,
Expand All @@ -47,7 +48,6 @@
from chia.wallet.derivation_record import DerivationRecord
from chia.wallet.lineage_proof import LineageProof
from chia.wallet.outer_puzzles import AssetType
from chia.wallet.payment import Payment
from chia.wallet.puzzle_drivers import PuzzleInfo, Solver
from chia.wallet.singleton import SINGLETON_LAUNCHER_PUZZLE, SINGLETON_LAUNCHER_PUZZLE_HASH
from chia.wallet.trading.offer import NotarizedPayment, Offer
Expand Down Expand Up @@ -518,7 +518,7 @@ async def create_update_state_spend(

# Create the solution
primaries = [
Payment(
CreateCoin(
announce_only.get_tree_hash() if announce_new_state else new_puz_hash,
singleton_record.lineage_proof.amount if new_amount is None else new_amount,
[
Expand Down Expand Up @@ -747,7 +747,7 @@ async def delete_mirror(
)
excess_fee: int = fee - mirror_coin.amount
inner_sol: Program = self.standard_wallet.make_solution(
primaries=[Payment(new_puzhash, uint64(mirror_coin.amount - fee))] if excess_fee < 0 else [],
primaries=[CreateCoin(new_puzhash, uint64(mirror_coin.amount - fee))] if excess_fee < 0 else [],
conditions=(*extra_conditions, CreateCoinAnnouncement(b"$")) if excess_fee > 0 else extra_conditions,
)
mirror_spend = CoinSpend(
Expand Down
11 changes: 6 additions & 5 deletions chia/rpc/wallet_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
AssertPuzzleAnnouncement,
Condition,
ConditionValidTimes,
CreateCoin,
CreateCoinAnnouncement,
CreatePuzzleAnnouncement,
conditions_from_json_dicts,
Expand Down Expand Up @@ -138,7 +139,6 @@
from chia.wallet.nft_wallet.uncurry_nft import UncurriedNFT
from chia.wallet.notification_store import Notification
from chia.wallet.outer_puzzles import AssetType
from chia.wallet.payment import Payment
from chia.wallet.puzzle_drivers import PuzzleInfo, Solver
from chia.wallet.puzzles import p2_delegated_conditions
from chia.wallet.puzzles.clawback.metadata import AutoClaimSettings, ClawbackMetadata
Expand Down Expand Up @@ -1341,7 +1341,7 @@ async def split_coins(
raise ValueError("Cannot split coins from non-fungible wallet types")

outputs = [
Payment(
CreateCoin(
await wallet.get_puzzle_hash(new=True)
if isinstance(wallet, Wallet)
else await wallet.standard_wallet.get_puzzle_hash(new=True),
Expand Down Expand Up @@ -4254,7 +4254,7 @@ async def create_signed_transaction(

memos_0 = [] if "memos" not in additions[0] else [mem.encode("utf-8") for mem in additions[0]["memos"]]

additional_outputs: list[Payment] = []
additional_outputs: list[CreateCoin] = []
for addition in additions[1:]:
receiver_ph = bytes32.from_hexstr(addition["puzzle_hash"])
if len(receiver_ph) != 32:
Expand All @@ -4263,7 +4263,7 @@ async def create_signed_transaction(
if amount > self.service.constants.MAX_COIN_AMOUNT:
raise ValueError(f"Coin amount cannot exceed {self.service.constants.MAX_COIN_AMOUNT}")
memos = [] if "memos" not in addition else [mem.encode("utf-8") for mem in addition["memos"]]
additional_outputs.append(Payment(receiver_ph, amount, memos))
additional_outputs.append(CreateCoin(receiver_ph, amount, memos))

fee: uint64 = uint64(request.get("fee", 0))

Expand Down Expand Up @@ -4319,7 +4319,8 @@ async def _generate_signed_transaction() -> EndpointResult:
action_scope,
fee,
coins=coins,
memos=[memos_0] + [output.memos for output in additional_outputs],
memos=[memos_0]
+ [output.memos if output.memos is not None else [] for output in additional_outputs],
extra_conditions=(
*extra_conditions,
*(
Expand Down
6 changes: 3 additions & 3 deletions chia/simulator/full_node_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from chia.util.config import lock_and_load_config, save_config
from chia.util.ints import uint8, uint32, uint64, uint128
from chia.util.timing import adjusted_timeout, backoff_times
from chia.wallet.payment import Payment
from chia.wallet.conditions import CreateCoin
from chia.wallet.transaction_record import LightTransactionRecord, TransactionRecord
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG
from chia.wallet.wallet import Wallet
Expand Down Expand Up @@ -686,13 +686,13 @@ async def create_coins_with_amounts(
if len(amounts) == 0:
return set()

outputs: list[Payment] = []
outputs: list[CreateCoin] = []
amounts_seen: set[uint64] = set()
for amount in amounts:
# We need unique puzzle hash amount combos so we'll only generate a new puzzle hash when we've already
# seen that amount sent to that puzzle hash
puzzle_hash = await wallet.get_puzzle_hash(new=amount in amounts_seen)
outputs.append(Payment(puzzle_hash, amount))
outputs.append(CreateCoin(puzzle_hash, amount))
amounts_seen.add(amount)

transaction_records: list[TransactionRecord] = []
Expand Down
Loading
Loading