-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check address validator for evm and solana
- Loading branch information
1 parent
0987ac9
commit 028aaa8
Showing
4 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.core.exceptions import BadRequest | ||
from solders.pubkey import Pubkey | ||
|
||
from core.utils import Web3Utils | ||
|
||
from .models import Chain, NetworkTypes | ||
|
||
|
||
def address_validator(address, chain: Chain): | ||
is_address_valid = False | ||
if chain.chain_type == NetworkTypes.LIGHTNING: | ||
return | ||
elif chain.chain_type == NetworkTypes.EVM: | ||
try: | ||
Web3Utils.to_checksum_address(address) | ||
return | ||
except ValueError: | ||
is_address_valid = False | ||
elif chain.chain_type == NetworkTypes.SOLANA: | ||
try: | ||
pub_key = Pubkey.from_string(address) | ||
is_address_valid = pub_key.is_on_curve() | ||
except ValueError: | ||
is_address_valid = False | ||
|
||
if not is_address_valid: | ||
raise BadRequest(f"Address: {address} is not valid") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters