Skip to content

Commit 51fbeee

Browse files
committed
feat: return none instead of raising an error
1 parent f469192 commit 51fbeee

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

hathor/nanocontracts/runner/runner.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,16 +1317,17 @@ def _get_token(self, token_uid: TokenUid) -> TokenDescription:
13171317
)
13181318

13191319
try:
1320-
return self.tx_storage.get_token_description(token_uid)
1320+
token_description = self.tx_storage.get_token_description(token_uid)
1321+
if token_description is None:
1322+
raise NCInvalidSyscall(
1323+
f'The {token_uid.hex()} token is not confirmed by any block '
1324+
f'for contract {call_record.contract_id.hex()}'
1325+
)
1326+
return token_description
13211327
except TransactionDoesNotExist:
13221328
raise NCInvalidSyscall(
13231329
f'contract {call_record.contract_id.hex()} could not find {token_uid.hex()} token'
13241330
)
1325-
except TransactionMetadataDoesNotExist:
1326-
raise NCInvalidSyscall(
1327-
f'The {token_uid.hex()} token is not confirmed by any block '
1328-
f'for contract {call_record.contract_id.hex()}'
1329-
)
13301331

13311332
def _create_token(
13321333
self,

hathor/transaction/storage/transaction_storage.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
TokenCreationTransactionDoesNotExist,
3838
TransactionDoesNotExist,
3939
TransactionIsNotABlock,
40-
TransactionMetadataDoesNotExist,
4140
TransactionNotInAllowedScopeError,
4241
)
4342
from hathor.transaction.storage.migrations import (
@@ -577,22 +576,19 @@ def get_token_creation_transaction(self, hash_bytes: bytes) -> TokenCreationTran
577576
raise TokenCreationTransactionDoesNotExist(hash_bytes)
578577
return tx
579578

580-
def get_token_description(self, token_uid: bytes) -> TokenDescription:
579+
def get_token_description(self, token_uid: bytes) -> Optional[TokenDescription]:
581580
"""Get the confirmed token description for `token_uid`.
582581
583582
:param token_uid: Unique token id to fetch.
584583
:raises TransactionDoesNotExist: If the transaction with the given hash does not exist.
585584
:raises TokenCreationTransactionDoesNotExist: If the transaction exists but is not a TokenCreationTransaction.
586-
:raises TransactionMetadataDoesNotExist: The tx that creates this token has not been confirmed by any block.
587585
:return: The TokenCreationTransaction instance.
588586
"""
589587
# Check the transaction storage for existing tokens
590588
token_creation_tx = self.get_token_creation_transaction(token_uid)
591589

592590
if token_creation_tx.get_metadata().first_block is None:
593-
raise TransactionMetadataDoesNotExist(
594-
f"The {token_uid.hex()} token is not confirmed by any block"
595-
)
591+
return None
596592

597593
return TokenDescription(
598594
token_version=token_creation_tx.token_version,

0 commit comments

Comments
 (0)