Skip to content

Commit

Permalink
add more descriptive errors
Browse files Browse the repository at this point in the history
  • Loading branch information
meeragjoshi committed Sep 27, 2023
1 parent 5f47827 commit 97a502e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions chia/rpc/full_node_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,13 +974,18 @@ async def get_singleton_by_launcher_id(self, request: Dict[str, Any]) -> Endpoin
launcher_coin: Optional[CoinRecord] = await self.service.blockchain.coin_store.get_coin_record(launcher_id)

if (launcher_coin is None):
return {"success": False, "error": f"Launcher coin not found for ID {launcher_id.hex()}"}
raise ValueError(f"Launcher coin not found for ID {launcher_id.hex()}")

launcher_spend = await self.get_coin_spend_for_coin_record(launcher_coin)

launcher_additions = compute_additions(launcher_spend)

eve_addition = list(filter(lambda coin: coin.amount == 1,launcher_additions))[0]
filtered_additions: List[Coin] = list(filter(lambda coin: coin.amount % 2 == 1,launcher_additions))

if len(filtered_additions) != 1:
raise ValueError(f"Invalid singleton no single odd child coin.")

eve_addition = filtered_additions[0]

singleton_coin_record: Optional[CoinRecord] = await self.service.blockchain.coin_store.get_coin_record(eve_addition.name())

Expand All @@ -989,12 +994,17 @@ async def get_singleton_by_launcher_id(self, request: Dict[str, Any]) -> Endpoin

additions = compute_additions(singleton_parent_spend)

singleton_coin: Coin = list(filter(lambda coin: coin.amount % 2 == 1,additions))[0]
filtered_additions: List[Coin] = list(filter(lambda coin: coin.amount % 2 == 1,additions))

if len(filtered_additions) != 1:
raise ValueError(f"Invalid singleton no single odd child coin.")

singleton_coin: Coin = filtered_additions[0]

singleton_coin_record = await self.service.blockchain.coin_store.get_coin_record(singleton_coin.name())

return {
"singleton_coin": coin_record_dict_backwards_compat(singleton_coin_record.to_json_dict()),
"singleton_coin_record": coin_record_dict_backwards_compat(singleton_coin_record.to_json_dict()),
"singleton_parent_spend": singleton_parent_spend.to_json_dict()
}

Expand Down

0 comments on commit 97a502e

Please sign in to comment.