Skip to content

Commit

Permalink
add error if singleton coin record isn't found
Browse files Browse the repository at this point in the history
  • Loading branch information
meeragjoshi committed Sep 27, 2023
1 parent 4fa01f4 commit 14861b6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions chia/rpc/full_node_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ async def get_coin_spend_for_coin_record(self, coin_record: CoinRecord) -> Optio

return CoinSpend(coin_record.coin, spend_info.puzzle, spend_info.solution)

async def get_singleton_addition(self, parent_spend: CoinSpend) -> CoinRecord:
async def get_singleton_addition(self, parent_spend: CoinSpend) -> Optional[CoinRecord]:
additions: List[Coin] = compute_additions(parent_spend)

filtered_additions: List[Coin] = list(filter(lambda coin: coin.amount % 2 == 1,additions))
Expand All @@ -983,13 +983,16 @@ async def get_singleton_by_launcher_id(self, request: Dict[str, Any]) -> Endpoin

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

if (singleton_coin_record is None):
if singleton_coin_record is None:
raise ValueError(f"Launcher coin not found for ID {launcher_id.hex()}")

while singleton_coin_record.spent_block_index > 0:
singleton_parent_spend = await self.get_coin_spend_for_coin_record(singleton_coin_record)

singleton_coin_record = await self.get_singleton_addition(singleton_parent_spend)

if singleton_coin_record is None:
raise ValueError("Singleton coin record not found")

return {
"coin_record": coin_record_dict_backwards_compat(singleton_coin_record.to_json_dict()),
Expand Down

0 comments on commit 14861b6

Please sign in to comment.