From 6f306a0b68a0cff1e68b2531df6cf7a53f81ebda Mon Sep 17 00:00:00 2001 From: kubacech Date: Wed, 3 Feb 2021 10:30:44 +0100 Subject: [PATCH 1/4] BPUB-680 removing getting non existent ETC classifier --- .../com/generalbytes/bitrafael/tools/wallet/WalletTools.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java b/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java index 13c9082..9aa5c3f 100644 --- a/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java +++ b/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java @@ -149,8 +149,6 @@ public Classification classify(String input, String cryptoCurrencyHint) { result = classificators.get(IClient.XMR).classify(input); }else if (IClient.ETH.equalsIgnoreCase(cryptoCurrencyHint)) { result = classificators.get(IClient.ETH).classify(input); - }else if (IClient.ETC.equalsIgnoreCase(cryptoCurrencyHint)) { - result = classificators.get(IClient.ETC).classify(input); }else if (IClient.BCH.equalsIgnoreCase(cryptoCurrencyHint)) { result = classificators.get(IClient.BCH).classify(input); } From 1b51d7839ec4f6fd6b065db61f3d87f408d4dcbb Mon Sep 17 00:00:00 2001 From: kubacech Date: Wed, 3 Feb 2021 14:21:37 +0100 Subject: [PATCH 2/4] BPUB-680 removing ETC from supported wallettools currencies --- .../generalbytes/bitrafael/tools/wallet/WalletTools.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java b/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java index 9aa5c3f..f4d5a57 100644 --- a/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java +++ b/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java @@ -214,13 +214,9 @@ public Classification classify(String input) { return classificators.get(IClient.BCH).classify(input); } - return result; } - - - @Override public Set supportedCryptoCurrencies() { final HashSet result = new HashSet(); @@ -229,7 +225,6 @@ public Set supportedCryptoCurrencies() { result.add(IClient.DASH); result.add(IClient.XMR); result.add(IClient.ETH); - result.add(IClient.ETC); result.add(IClient.BCH); return result; } @@ -250,5 +245,4 @@ public static int getCoinTypeByCryptoCurrency(String cryptoCurrency) { } return COIN_TYPE_BITCOIN; } - } From 60d1921f2a5164a7f09bd7272eaf2b208b73274b Mon Sep 17 00:00:00 2001 From: kubacech Date: Mon, 15 Feb 2021 13:20:58 +0100 Subject: [PATCH 3/4] BPUB-680 using ETH walletTools for ETC --- .../bitrafael/tools/wallet/WalletTools.java | 18 +++++---- .../tools/wallet/eth/WalletToolsETH.java | 40 +++++++++---------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java b/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java index f4d5a57..f738572 100644 --- a/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java +++ b/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java @@ -54,10 +54,12 @@ public WalletTools() { classificators.put(IClient.XMR, xmrwt); - WalletToolsETH wETH = new WalletToolsETH(); + WalletToolsETH wETH = new WalletToolsETH(IClient.ETH); + WalletToolsETH wETC = new WalletToolsETH(IClient.ETC); tools.put(IClient.ETH, wETH); - tools.put(IClient.ETC, wETH); + tools.put(IClient.ETC, wETC); classificators.put(IClient.ETH, wETH); + classificators.put(IClient.ETC, wETC); } private IWalletTools getDefaultWalletTools() { @@ -141,15 +143,17 @@ public Classification classify(String input, String cryptoCurrencyHint) { Classification result = new Classification(Classification.TYPE_UNKNOWN); if (IClient.BTC.equalsIgnoreCase(cryptoCurrencyHint)) { result = classificators.get(IClient.BTC).classify(input); - }else if (IClient.LTC.equalsIgnoreCase(cryptoCurrencyHint)) { + } else if (IClient.LTC.equalsIgnoreCase(cryptoCurrencyHint)) { result = classificators.get(IClient.LTC).classify(input); - }else if (IClient.DASH.equalsIgnoreCase(cryptoCurrencyHint)) { + } else if (IClient.DASH.equalsIgnoreCase(cryptoCurrencyHint)) { result = classificators.get(IClient.DASH).classify(input); - }else if (IClient.XMR.equalsIgnoreCase(cryptoCurrencyHint)) { + } else if (IClient.XMR.equalsIgnoreCase(cryptoCurrencyHint)) { result = classificators.get(IClient.XMR).classify(input); - }else if (IClient.ETH.equalsIgnoreCase(cryptoCurrencyHint)) { + } else if (IClient.ETH.equalsIgnoreCase(cryptoCurrencyHint)) { result = classificators.get(IClient.ETH).classify(input); - }else if (IClient.BCH.equalsIgnoreCase(cryptoCurrencyHint)) { + } else if (IClient.ETC.equalsIgnoreCase(cryptoCurrencyHint)) { + result = classificators.get(IClient.ETC).classify(input); + } else if (IClient.BCH.equalsIgnoreCase(cryptoCurrencyHint)) { result = classificators.get(IClient.BCH).classify(input); } diff --git a/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/eth/WalletToolsETH.java b/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/eth/WalletToolsETH.java index d1d8092..7e765e2 100644 --- a/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/eth/WalletToolsETH.java +++ b/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/eth/WalletToolsETH.java @@ -52,6 +52,15 @@ public class WalletToolsETH implements IWalletTools { public static final int XPRV = 0x0488ade4; private static final String HEX_CHARS = "0123456789abcdef"; + private String cryptoCurrency; + + public WalletToolsETH() { + this(IClient.ETH); + } + + public WalletToolsETH(String cryptoCurrency) { + this.cryptoCurrency = cryptoCurrency; + } @Override public String generateSeedMnemonicSeparatedBySpaces() { @@ -139,7 +148,7 @@ public String getWalletAddressFromAccountPUB(String accountPUB, String cryptoCur break; } - if(standard == -1) { + if (standard == -1) { throw new IllegalArgumentException("Unknown header bytes in pub: " + accountPUB); } else { if (isPub) { @@ -153,10 +162,10 @@ public String getWalletAddressFromAccountPUB(String accountPUB, String cryptoCur } if (standard == STANDARD_BIP44) { return Address.fromKey(MainNetParams.get(), walletKey, Script.ScriptType.P2PKH).toString(); - }else if (standard == STANDARD_BIP84) { + } else if (standard == STANDARD_BIP84) { return null; //TODO } - }else { + } else { return null; } } @@ -249,7 +258,6 @@ public String getAccountPUB(IMasterPrivateKey master, String cryptoCurrency, int return MasterPrivateKeyETH.serializePUB(masterKey,master.getStandard(), accountIndex, cryptoCurrency); } - @Override public String getWalletAddressFromPrivateKey(String privateKey, String cryptoCurrency) { return null; //not supported yet @@ -260,20 +268,17 @@ public ISignature sign(String privateKey, byte[] hashToSign, String cryptoCurren return null;//not supported yet } - public boolean isAddressValid(String address, String cryptoCurrency) { if (address == null) { return false; - }else{ + } else { if (!address.startsWith("0x") && !address.startsWith("XE")){ return false; } } - return isAddressValidInternal(address); } - @Override public Classification classify(String input, String cryptoCurrencyHint) { return classify(input); @@ -304,25 +309,24 @@ public Classification classify(String input) { //most likely address lets check it try { if (isAddressValidInternal(input)) { - return new Classification(Classification.TYPE_ADDRESS, IClient.ETH,input); + return new Classification(Classification.TYPE_ADDRESS, cryptoCurrency, input); } } catch (AddressFormatException e) { e.printStackTrace(); } - }else if (input.startsWith("XE")) { + } else if (input.startsWith("XE")) { try { if (isAddressValidInternal(input)) { - return new Classification(Classification.TYPE_ADDRESS,IClient.ETH,input); + return new Classification(Classification.TYPE_ADDRESS, cryptoCurrency, input); } } catch (AddressFormatException e) { e.printStackTrace(); } - }else if (input.startsWith("xpub")) { - return new Classification(Classification.TYPE_PUB,IClient.ETH,input); + } else if (input.startsWith("xpub")) { + return new Classification(Classification.TYPE_PUB, cryptoCurrency, input); } return new Classification(Classification.TYPE_UNKNOWN); - } private static boolean isAddressValidInternal(String address) { @@ -357,7 +361,6 @@ public Set supportedCryptoCurrencies() { return result; } - private static byte[] decodeAddressAsBytes(String address) { if (address == null) { return null; @@ -422,7 +425,7 @@ private static String decodeAddressFromIBAN(String iban) { String base36 = iban.substring(4); BigInteger asBn = new BigInteger(base36, 36); return encodeAddressToChecksummedAddress(padLeft(asBn.toString(16), 20)); - }else{ + } else { return null; } } @@ -471,11 +474,9 @@ private static int calculateModulus(String code) throws CheckDigitException { total %= 97L; } } - return (int)(total % 97L); } - private static String padLeft(String number, int bytes) { String result = number; while (result.length() < bytes * 2) { @@ -514,7 +515,7 @@ private static String encodeAddressToChecksummedAddress(String address) { checksumAddress += (addrChars[i] +"").toLowerCase(); } } - return "0x"+checksumAddress; + return "0x" + checksumAddress; } private static String bytesToHexString(byte[] bytes) { @@ -576,5 +577,4 @@ private String getAddress(ECKey ecKey) { System.arraycopy(result,result.length - address.length, address,0, address.length); return bytesToHexString(address); } - } From 5f82a1ccc2b485ed908c5dcb699ae2b5591ff5cd Mon Sep 17 00:00:00 2001 From: kubacech Date: Thu, 18 Feb 2021 12:08:58 +0100 Subject: [PATCH 4/4] BPUB-680 using ETH walletTools for ETC --- .../com/generalbytes/bitrafael/tools/wallet/WalletTools.java | 1 + 1 file changed, 1 insertion(+) diff --git a/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java b/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java index f738572..ff5ab4f 100644 --- a/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java +++ b/bitrafael-client/src/main/java/com/generalbytes/bitrafael/tools/wallet/WalletTools.java @@ -229,6 +229,7 @@ public Set supportedCryptoCurrencies() { result.add(IClient.DASH); result.add(IClient.XMR); result.add(IClient.ETH); + result.add(IClient.ETC); result.add(IClient.BCH); return result; }