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

fix for missing minted coins #11500

Merged
merged 1 commit into from
May 12, 2022
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
29 changes: 3 additions & 26 deletions chia/wallet/nft_wallet/nft_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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())),
Expand All @@ -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:
Expand Down
15 changes: 12 additions & 3 deletions tests/wallet/nft_wallet/test_nft_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand All @@ -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]
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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())

Expand All @@ -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):
Expand Down