From b2617b0cf4fd7c8099b05deaf854956f30a3b261 Mon Sep 17 00:00:00 2001 From: Sebastjan Date: Thu, 12 May 2022 14:33:36 +0200 Subject: [PATCH] fix for missing minted coins --- chia/wallet/nft_wallet/nft_wallet.py | 29 +++------------------- tests/wallet/nft_wallet/test_nft_wallet.py | 15 ++++++++--- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/chia/wallet/nft_wallet/nft_wallet.py b/chia/wallet/nft_wallet/nft_wallet.py index b34101299927..7c74e7e301d9 100644 --- a/chia/wallet/nft_wallet/nft_wallet.py +++ b/chia/wallet/nft_wallet/nft_wallet.py @@ -389,7 +389,7 @@ async def generate_new_nft( if not target_puzzle_hash: target_puzzle_hash = inner_puzzle.get_tree_hash() - condition_list = [make_create_coin_condition(target_puzzle_hash, amount, [])] + condition_list = [make_create_coin_condition(target_puzzle_hash, amount, [target_puzzle_hash])] innersol = solution_for_conditions(condition_list) # EVE SPEND BELOW fullsol = Program.to( @@ -409,6 +409,7 @@ async def generate_new_nft( eve_spend_bundle = SpendBundle(list_of_coinspends, AugSchemeMPL.aggregate([])) eve_spend_bundle = await self.sign(eve_spend_bundle) full_spend = SpendBundle.aggregate([tx_record.spend_bundle, eve_spend_bundle, launcher_sb]) + nft_record = TransactionRecord( confirmed_at_height=uint32(0), created_at_time=uint64(int(time.time())), @@ -425,35 +426,11 @@ async def generate_new_nft( trade_id=None, type=uint32(TransactionType.OUTGOING_TX.value), name=bytes32(token_bytes()), - memos=[], + memos=list(compute_memos(full_spend).items()), ) await self.standard_wallet.push_transaction(nft_record) return nft_record.spend_bundle - async def generate_eve_spend(self, coin: Coin, full_puzzle: Program, innerpuz: Program, origin_coin: Coin): - # innerpuz solution is (mode p2_solution) - p2_solution = self.standard_wallet.make_solution( - primaries=[ - { - "puzzlehash": innerpuz.get_tree_hash(), - "amount": uint64(coin.amount), - "memos": [innerpuz.get_tree_hash()], - } - ] - ) - innersol = Program.to([1, p2_solution]) - # full solution is (lineage_proof my_amount inner_solution) - fullsol = Program.to( - [ - [origin_coin.parent_coin_info, origin_coin.amount], - coin.amount, - innersol, - ] - ) - list_of_coinspends = [CoinSpend(coin, full_puzzle, fullsol)] - unsigned_spend_bundle = SpendBundle(list_of_coinspends, G2Element()) - return await self.sign(unsigned_spend_bundle) - async def sign(self, spend_bundle: SpendBundle) -> SpendBundle: sigs: List[G2Element] = [] for spend in spend_bundle.coin_spends: diff --git a/tests/wallet/nft_wallet/test_nft_wallet.py b/tests/wallet/nft_wallet/test_nft_wallet.py index 3a613e74dfa1..06a38c407e05 100644 --- a/tests/wallet/nft_wallet/test_nft_wallet.py +++ b/tests/wallet/nft_wallet/test_nft_wallet.py @@ -8,12 +8,14 @@ from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward from chia.full_node.mempool_manager import MempoolManager from chia.rpc.wallet_rpc_api import WalletRpcApi +from chia.simulator.full_node_simulator import FullNodeSimulator from chia.simulator.simulator_protocol import FarmNewBlockProtocol from chia.types.blockchain_format.program import Program from chia.types.blockchain_format.sized_bytes import bytes32 from chia.types.peer_info import PeerInfo from chia.util.ints import uint16, uint32 from chia.wallet.nft_wallet.nft_wallet import NFTWallet +from chia.wallet.util.compute_memos import compute_memos from chia.wallet.util.wallet_types import WalletType from tests.time_out_assert import time_out_assert, time_out_assert_not_none @@ -95,11 +97,9 @@ async def test_nft_wallet_creation_automatically(two_wallet_nodes: Any, trusted: assert len(coins) == 1, "nft not generated" sb = await nft_wallet_0.transfer_nft(coins[0], ph1) - assert sb is not None await asyncio.sleep(3) await time_out_assert_not_none(5, full_node_api.full_node.mempool_manager.get_spendbundle, sb.name()) - await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph1)) await asyncio.sleep(5) @@ -122,7 +122,7 @@ async def test_nft_wallet_creation_automatically(two_wallet_nodes: Any, trusted: async def test_nft_wallet_creation_and_transfer(two_wallet_nodes: Any, trusted: Any) -> None: num_blocks = 5 full_nodes, wallets = two_wallet_nodes - full_node_api = full_nodes[0] + full_node_api: FullNodeSimulator = full_nodes[0] full_node_server = full_node_api.server wallet_node_0, server_0 = wallets[0] wallet_node_1, server_1 = wallets[1] @@ -174,6 +174,8 @@ async def test_nft_wallet_creation_and_transfer(two_wallet_nodes: Any, trusted: sb = await nft_wallet_0.generate_new_nft(metadata) assert sb + # ensure hints are generated + assert compute_memos(sb) await time_out_assert_not_none(5, full_node_api.full_node.mempool_manager.get_spendbundle, sb.name()) for i in range(1, num_blocks): @@ -192,6 +194,8 @@ async def test_nft_wallet_creation_and_transfer(two_wallet_nodes: Any, trusted: sb = await nft_wallet_0.generate_new_nft(metadata) assert sb + # ensure hints are generated + assert compute_memos(sb) await time_out_assert_not_none(5, full_node_api.full_node.mempool_manager.get_spendbundle, sb.name()) for i in range(1, num_blocks): @@ -207,6 +211,9 @@ async def test_nft_wallet_creation_and_transfer(two_wallet_nodes: Any, trusted: sb = await nft_wallet_0.transfer_nft(coins[1], ph1) assert sb is not None + # ensure hints are generated + assert compute_memos(sb) + await asyncio.sleep(3) await time_out_assert_not_none(5, full_node_api.full_node.mempool_manager.get_spendbundle, sb.name()) @@ -223,6 +230,8 @@ async def test_nft_wallet_creation_and_transfer(two_wallet_nodes: Any, trusted: nsb = await nft_wallet_1.transfer_nft(coins[0], ph) assert nsb is not None + # ensure hints are generated + assert compute_memos(nsb) await asyncio.sleep(5) for i in range(1, num_blocks):