Skip to content

Commit

Permalink
Merge pull request #30 from pvyhnal-generalbytes/BATM-864-update-bitc…
Browse files Browse the repository at this point in the history
…oinj-litecoinj-dashj

BATM-864 enable ltc1 addresses
  • Loading branch information
generalbytes authored Jun 11, 2019
2 parents 36f10d5 + 2011c53 commit 1f84217
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,24 @@ public Classification classify(String input) {
input = input.substring(0,input.indexOf("?"));
}

if ((input.startsWith("L") || input.startsWith("3") || input.startsWith("M")) && input.length() <= 34) {
if ((input.startsWith("L") || input.startsWith("3") || input.startsWith("M")) && input.length() <= 34) {
//most likely address lets check it
try {
if (isAddressValidInternal(input)) {
return new Classification(Classification.TYPE_ADDRESS,IClient.LTC,input);
return new Classification(Classification.TYPE_ADDRESS, IClient.LTC, input);
}
} catch (AddressFormatException e) {
e.printStackTrace();
}
}else if (((input.startsWith("6")) && input.length() >= 51) || ((input.startsWith("T")) && input.length() >= 51)) {
} else if (input.startsWith("ltc1")) {
try {
if (isAddressValidBech32Internal(input)) {
return new Classification(Classification.TYPE_ADDRESS, IClient.LTC, input);
}
} catch (AddressFormatException e) {
e.printStackTrace();
}
} else if (((input.startsWith("6")) && input.length() >= 51) || ((input.startsWith("T")) && input.length() >= 51)) {
//most likely private key
try {
DumpedPrivateKey dp = DumpedPrivateKey.fromBase58(MainNetParams.get(), input);
Expand Down Expand Up @@ -392,6 +400,16 @@ private static boolean isAddressValidInternal(String address) {
return true;
}

private static boolean isAddressValidBech32Internal(String address) {
try {
Bech32.decode(address);
} catch (AddressFormatException e) {
e.printStackTrace();
return false;
}
return true;
}

@Override
public Set<String> supportedCryptoCurrencies() {
final HashSet<String> result = new HashSet<String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@ public void classify() {
Assert.assertEquals("BTC", walletToolsBTC.classify("3CuvPRVeG3jWhm1dLSACKDN9PMPuY6FVXT", "BTC").getCryptoCurrency());
Assert.assertEquals("BTC", walletToolsBTC.classify("112pN943KyuQY26epMwFFvcj85EVVc2fnJ", "BTC").getCryptoCurrency());
Assert.assertEquals("BTC", walletToolsBTC.classify("bc1qlgp42vadfqkdjr0wdwvfnpqlvs5cg3xnl5zukw", "BTC").getCryptoCurrency());
Assert.assertEquals("BTC", walletToolsBTC.classify("bitcoin:3CuvPRVeG3jWhm1dLSACKDN9PMPuY6FVXT", "BTC").getCryptoCurrency());
Assert.assertEquals("BTC", walletToolsBTC.classify("bitcoin:112pN943KyuQY26epMwFFvcj85EVVc2fnJ", "BTC").getCryptoCurrency());
Assert.assertEquals("BTC", walletToolsBTC.classify("bitcoin:bc1qlgp42vadfqkdjr0wdwvfnpqlvs5cg3xnl5zukw", "BTC").getCryptoCurrency());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ public void getWalletAddress() {

@Test
public void classify() {
Assert.assertEquals("LTC", walletToolsLTC.classify("ltc1q3cv28h4f33dj7msgm85va0epdw6298rxsparl7", "LTC").getCryptoCurrency());
Assert.assertEquals("LTC", walletToolsLTC.classify("litecoin:ltc1q3cv28h4f33dj7msgm85va0epdw6298rxsparl7", "LTC").getCryptoCurrency());
Assert.assertEquals("LTC", walletToolsLTC.classify("MV5sqqgY5qG3rxBciUQgz9dSYSKiyxN2n3", "LTC").getCryptoCurrency());
Assert.assertEquals("LTC", walletToolsLTC.classify("litecoin:MV5sqqgY5qG3rxBciUQgz9dSYSKiyxN2n3", "LTC").getCryptoCurrency());
Assert.assertEquals("LTC", walletToolsLTC.classify("LZpVz2zJ9Mq4tUx2UeSiFHRqKfN54BL6yr", "LTC").getCryptoCurrency());
Assert.assertEquals("LTC", walletToolsLTC.classify("litecoin:LZpVz2zJ9Mq4tUx2UeSiFHRqKfN54BL6yr", "LTC").getCryptoCurrency());

Assert.assertNull(walletToolsLTC.classify("ltc1QQQQQQQQQ3cv28h4f33dj7msgm85va0epdw6298rxsparl7", "LTC").getCryptoCurrency());
Assert.assertNull(walletToolsLTC.classify("MV5sqqgY5qG3rxBciUXXXXXdSYSKiyxN2n3", "LTC").getCryptoCurrency());
}
}

0 comments on commit 1f84217

Please sign in to comment.