2222config_loader = None
2323
2424digits58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
25+ digits58_ripple = 'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz'
2526digits32 = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'
2627
2728
@@ -56,7 +57,6 @@ def decode_base58(bc, length):
5657 n = n * 58 + digits58 .index (char )
5758 return n .to_bytes (length , 'big' )
5859
59-
6060# http://rosettacode.org/wiki/Bitcoin/address_validation#Python
6161def check_base58_address (bc ):
6262 try :
@@ -65,6 +65,19 @@ def check_base58_address(bc):
6565 except Exception :
6666 return False
6767
68+ def decode_base58_ripple (bc , length ):
69+ n = 0
70+ for char in bc :
71+ n = n * 58 + digits58_ripple .index (char )
72+ return n .to_bytes (length , 'big' )
73+
74+ def check_base58_ripple_address (bc ):
75+ try :
76+ bcbytes = decode_base58_ripple (bc , 25 )
77+ return bcbytes [- 4 :] == sha256 (sha256 (bcbytes [:- 4 ]).digest ()).digest ()[:4 ]
78+ except Exception :
79+ return False
80+
6881
6982class CryptoCurrency (AbstractSubtypeObject ):
7083 """
@@ -92,6 +105,8 @@ def is_valid_address(self):
92105 return check_base58_address (self .id )
93106 elif self .subtype == 'dash' or self .subtype == 'litecoin' or self .subtype == 'tron' :
94107 return check_base58_address (self .id )
108+ elif self .subtype == 'ripple' :
109+ return check_base58_ripple_address (self .id )
95110 else :
96111 return True
97112
@@ -110,6 +125,8 @@ def get_currency_symbol(self):
110125 return 'ZEC'
111126 elif self .subtype == 'dash' :
112127 return 'DASH'
128+ elif self .subtype == 'ripple' :
129+ return 'XRP'
113130 elif self .subtype == 'tron' :
114131 return 'TRX'
115132 return None
@@ -197,7 +214,7 @@ def sanitize_id_to_search(self, subtypes, name_to_search):
197214
198215def get_all_subtypes ():
199216 # return ail_core.get_object_all_subtypes(self.type)
200- return ['bitcoin' , 'bitcoin-cash' , 'dash' , 'ethereum' , 'litecoin' , 'monero' , 'tron' , 'zcash' ]
217+ return ['bitcoin' , 'bitcoin-cash' , 'dash' , 'ethereum' , 'litecoin' , 'monero' , 'ripple' , ' tron' , 'zcash' ]
201218
202219
203220# def build_crypto_regex(subtype, search_id):
@@ -229,6 +246,8 @@ def get_subtype_by_symbol(symbol):
229246 return 'zcash'
230247 elif symbol == 'DASH' :
231248 return 'dash'
249+ elif symbol == 'XRP' :
250+ return 'ripple'
232251 elif symbol == 'TRX' :
233252 return 'tron'
234253 return None
0 commit comments