Repository: Chia-Network/chia-blockchain
Pull request: Detect hints correctly in the TX
Fixes: https://github.com/Chia-Network/chia-blockchain/issues/10537

Problem statement:
[Bug] missing CAT tokens 
### What happened?

CAT tokens that are on the Verified list (Eg. CH21) that have a balance are not showing up automatically after importing from mnemonics. As reported by @cmmarslender 

### Version

1.2.12 dev389

### What platform are you using?

Linux

### What ui mode are you using?

CLI

### Relevant log output

_No response_

Hints from issue discussion:

Commit message: Detect hints correctly in the TX

Patch to review:
diff --git a/chia/wallet/util/compute_hints.py b/chia/wallet/util/compute_hints.py
index b6d924bbdcbf..d6e137f7c0a0 100644
--- a/chia/wallet/util/compute_hints.py
+++ b/chia/wallet/util/compute_hints.py
@@ -1,34 +1,22 @@
 from typing import List
 
-from blspy import G2Element
-
+from chia.types.blockchain_format.sized_bytes import bytes32
 from chia.types.condition_opcodes import ConditionOpcode
 from chia.types.blockchain_format.program import INFINITE_COST
 from chia.types.coin_spend import CoinSpend
-from chia.full_node.mempool_check_conditions import get_name_puzzle_conditions
-from chia.consensus.default_constants import DEFAULT_CONSTANTS
-from chia.types.spend_bundle import SpendBundle
-from chia.full_node.bundle_tools import simple_solution_generator
-
-
-def compute_coin_hints(cs: CoinSpend) -> List[bytes]:
 
-    bundle = SpendBundle([cs], G2Element())
-    generator = simple_solution_generator(bundle)
 
-    npc_result = get_name_puzzle_conditions(
-        generator,
-        INFINITE_COST,
-        cost_per_byte=DEFAULT_CONSTANTS.COST_PER_BYTE,
-        mempool_mode=False,
-        height=DEFAULT_CONSTANTS.SOFT_FORK_HEIGHT,
-    )
-    h_list = []
-    for npc in npc_result.npc_list:
-        for opcode, conditions in npc.conditions:
-            if opcode == ConditionOpcode.CREATE_COIN:
-                for condition in conditions:
-                    if len(condition.vars) > 2 and condition.vars[2] != b"":
-                        h_list.append(condition.vars[2])
+def compute_coin_hints(cs: CoinSpend) -> List[bytes32]:
+    _, result_program = cs.puzzle_reveal.run_with_cost(INFINITE_COST, cs.solution)
 
+    h_list: List[bytes32] = []
+    for condition_data in result_program.as_python():
+        condition = condition_data[0]
+        args = condition_data[1:]
+        if condition == ConditionOpcode.CREATE_COIN and len(args) > 2:
+            if isinstance(args[2], bytes):
+                h_list.append(bytes32(args[2]))
+            elif isinstance(args[2], list):
+                if isinstance(args[2][0], bytes):
+                    h_list.append(bytes32(args[2][0]))
     return h_list


Code review comments:
diff_hunk: @@ -1,34 +1,22 @@
 from typing import List
 
-from blspy import G2Element
-
+from chia.types.blockchain_format.sized_bytes import bytes32
 from chia.types.condition_opcodes import ConditionOpcode
 from chia.types.blockchain_format.program import INFINITE_COST
 from chia.types.coin_spend import CoinSpend
-from chia.full_node.mempool_check_conditions import get_name_puzzle_conditions
-from chia.consensus.default_constants import DEFAULT_CONSTANTS
-from chia.types.spend_bundle import SpendBundle
-from chia.full_node.bundle_tools import simple_solution_generator
-
-
-def compute_coin_hints(cs: CoinSpend) -> List[bytes]:
 
-    bundle = SpendBundle([cs], G2Element())
-    generator = simple_solution_generator(bundle)
 
-    npc_result = get_name_puzzle_conditions(
-        generator,
-        INFINITE_COST,
-        cost_per_byte=DEFAULT_CONSTANTS.COST_PER_BYTE,
-        mempool_mode=False,
-        height=DEFAULT_CONSTANTS.SOFT_FORK_HEIGHT,
-    )
-    h_list = []
-    for npc in npc_result.npc_list:
-        for opcode, conditions in npc.conditions:
-            if opcode == ConditionOpcode.CREATE_COIN:
-                for condition in conditions:
-                    if len(condition.vars) > 2 and condition.vars[2] != b"":
-                        h_list.append(condition.vars[2])
+def compute_coin_hints(cs: CoinSpend) -> List[bytes32]:
+    _, result_program = cs.puzzle_reveal.run_with_cost(INFINITE_COST, cs.solution)
 
+    h_list: List[bytes32] = []
+    for condition_data in result_program.as_python():
+        condition = condition_data[0]
+        args = condition_data[1:]
+        if condition == ConditionOpcode.CREATE_COIN and len(args) > 2:
+            if isinstance(args[2], bytes):
+                h_list.append(bytes32(args[2]))
path: chia/wallet/util/compute_hints.py
text: @user2:
I don't think this is a valid definition of a hint.  I think it has to be the first item in a list, it cannot be an atom.  @user1 should double check me.

@author:
I had this as a fallback since sometimes the first item is returned flattened, while sometimes it's returned as a list, from rust CLVM

@author:
The behaviour is different between `run_chia_program` and `run_generator2`, maybe names should be changed to be more descriptive?

@author:
OK fixed in latest commit