From c4a71837012bac330433641bc0ea11b4014ecc54 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 13 Oct 2021 22:35:44 +0200 Subject: [PATCH] - Fix typos - Added .gitignore on root level - Remove .idea folder - should not checked in :-) - Removed unused spaces in Java code and formatted for better readability --- .gitignore | 8 ++ README.md | 2 +- XDC3Java/.idea/gradle.xml | 16 ---- XDC3Java/.idea/misc.xml | 9 -- XDC3Java/.idea/modules.xml | 8 -- XDC3Java/.idea/modules/Xinfin.iml | 18 ---- XDC3Java/.idea/vcs.xml | 6 -- XDC3Java/.idea/workspace.xml | 89 ------------------- .../main/java/com/XDCJava/AppConstants.java | 6 +- .../main/java/com/XDCJava/XDC20Client.java | 47 +--------- .../main/java/com/XDCJava/XDC721Client.java | 25 ------ 11 files changed, 12 insertions(+), 222 deletions(-) create mode 100644 .gitignore delete mode 100644 XDC3Java/.idea/gradle.xml delete mode 100644 XDC3Java/.idea/misc.xml delete mode 100644 XDC3Java/.idea/modules.xml delete mode 100644 XDC3Java/.idea/modules/Xinfin.iml delete mode 100644 XDC3Java/.idea/vcs.xml delete mode 100644 XDC3Java/.idea/workspace.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6811bed --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +**/.idea +**/target +**/*.iml +**/.DS_Store +**/.project +/build +*.jar +!gradle/wrapper/gradle-wrapper.jar diff --git a/README.md b/README.md index 1ec80ac..09eda24 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ go to file menu — project structure — modules — click ‘+’ — select i you can see the folder in your android project -Now we have to add Module Dependency in the application project builg.gradle file +Now we have to add Module Dependency in the application project build.gradle file put “implementation project(":XDC3Java")“ in dependencies diff --git a/XDC3Java/.idea/gradle.xml b/XDC3Java/.idea/gradle.xml deleted file mode 100644 index 67abd65..0000000 --- a/XDC3Java/.idea/gradle.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/XDC3Java/.idea/misc.xml b/XDC3Java/.idea/misc.xml deleted file mode 100644 index f845854..0000000 --- a/XDC3Java/.idea/misc.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/XDC3Java/.idea/modules.xml b/XDC3Java/.idea/modules.xml deleted file mode 100644 index 80f3a0e..0000000 --- a/XDC3Java/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/XDC3Java/.idea/modules/Xinfin.iml b/XDC3Java/.idea/modules/Xinfin.iml deleted file mode 100644 index 5b2d407..0000000 --- a/XDC3Java/.idea/modules/Xinfin.iml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/XDC3Java/.idea/vcs.xml b/XDC3Java/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/XDC3Java/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/XDC3Java/.idea/workspace.xml b/XDC3Java/.idea/workspace.xml deleted file mode 100644 index 79568e4..0000000 --- a/XDC3Java/.idea/workspace.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1627394591490 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/XDC3Java/src/main/java/com/XDCJava/AppConstants.java b/XDC3Java/src/main/java/com/XDCJava/AppConstants.java index 2e088e1..5154244 100644 --- a/XDC3Java/src/main/java/com/XDCJava/AppConstants.java +++ b/XDC3Java/src/main/java/com/XDCJava/AppConstants.java @@ -1,12 +1,8 @@ package com.XDCJava; - public class AppConstants { - public static final String BASE_URL = "https://rpc.apothem.network/"; - public static final String hex_to_dec = "1000000000000000000"; - - // public static final String BASE_URL = "https://ropsten.infura.io/v3/b2f4b3f635d8425c96854c3d28ba6bb0"; + public static final String hex_to_dec = "1000000000000000000"; } diff --git a/XDC3Java/src/main/java/com/XDCJava/XDC20Client.java b/XDC3Java/src/main/java/com/XDCJava/XDC20Client.java index 265bad4..496e2f7 100644 --- a/XDC3Java/src/main/java/com/XDCJava/XDC20Client.java +++ b/XDC3Java/src/main/java/com/XDCJava/XDC20Client.java @@ -65,8 +65,7 @@ public Boolean isWeb3jConnected() { //Show Error return false; } - } catch ( - Exception e) { + } catch (Exception e) { //Show Error return false; } @@ -99,24 +98,16 @@ public void generateWallet(File walletDirectory, String Password, CreateAccountC walletData.setPublickeyKey(publickeyKey); walletData.setSeedPhrase(seedPhrase); - createAccountCallback.success(walletData); - - - - - /*String seedPhrase = walletName.getMnemonic(); + + Credentials restoreCredentials = WalletUtils.loadBip39Credentials("1234567890", + seedPhrase); + ECKeyPair restoredPrivateKey = restoreCredentials.getEcKeyPair(); + String restoredAccountAddress = restoreCredentials.getAddress();*/ - } catch (IOException | CipherException e) { - + } catch (IOException | CipherException e) e.printStackTrace(); createAccountCallback.failure(e.getMessage()); - } catch (Exception e) { e.printStackTrace(); } @@ -126,21 +117,16 @@ public void generateWallet(File walletDirectory, String Password, CreateAccountC public void importWallet(String seedPhrase, String Password, CreateAccountCallback createAccountCallback) { try { - - Credentials restoreCredentials = WalletUtils.loadBip39Credentials(Password, seedPhrase); ECKeyPair restoredPrivateKey = restoreCredentials.getEcKeyPair(); String restoredAccountAddress = restoreCredentials.getAddress(); - - WalletData walletData = new WalletData(); restoredAccountAddress = restoredAccountAddress.replace("0x", "xdc"); walletData.setAccountAddress(restoredAccountAddress); walletData.setPrivateKey(restoredPrivateKey.getPrivateKey().toString(16)); walletData.setPublickeyKey(restoredPrivateKey.getPublicKey().toString(16)); walletData.setSeedPhrase(seedPhrase); - createAccountCallback.success(walletData); } catch (Exception e) { e.printStackTrace(); @@ -166,19 +152,15 @@ public String getContractAddress(String Privatekey) { } } catch (Exception e) { return e.getMessage(); - } - } else { return "Please check your Connection"; } - } public void getTokenoinfo(String token_address, TokenDetailCallback tokenDetailCallback) { - if (isWeb3jConnected()) { ClientTransactionManager transactionManager = new ClientTransactionManager(web3, token_address); @@ -192,12 +174,9 @@ public void getTokenoinfo(String token_address, TokenDetailCallback tokenDetailC } } else { - //Show Error tokenDetailCallback.failure("Connection has been failed"); } - - } @@ -222,13 +201,9 @@ public String getAllowance(String token_address, String owner_address, String sp e.printStackTrace(); return e.getMessage(); } - - } else { return "check your connection"; } - - } /** @@ -245,9 +220,6 @@ public String getBalance(String token_address, String owner_address) { owner_address); XRC20 javaToken = com.XDCJava.contracts.src.main.java.XRC20.load(token_address, web3, transactionManager, new DefaultGasProvider()); - - - try { BigInteger balance = javaToken.balanceOf(owner_address).send(); balance = converHexToDecimal(balance); @@ -256,13 +228,9 @@ public String getBalance(String token_address, String owner_address) { e.printStackTrace(); return e.getMessage(); } - - } else { return "check your connection"; } - - } @@ -277,19 +245,14 @@ public String getXdcBalance( String owner_address) { try { EthGetBalance balance = web3.ethGetBalance(owner_address,DefaultBlockParameterName.LATEST).send(); - return String.valueOf(converHexToDecimal(balance.getBalance())); } catch (IOException e) { e.printStackTrace(); return String.valueOf(e.getMessage()); } - - } else { return "check your connection"; } - - } public void getinfo(XRC20 javaToken, String token_address, TokenDetailCallback tokenDetailCallback) { @@ -457,12 +420,8 @@ public String approveXRC20Token(String token_address, String private_key, String return "Failed"; } } else { - return "Failed"; - } - - } @@ -734,6 +693,4 @@ public BigInteger converHexToDecimal (BigInteger hexValue) return hexValue.divide(hexvalue); } - - } diff --git a/XDC3Java/src/main/java/com/XDCJava/XDC721Client.java b/XDC3Java/src/main/java/com/XDCJava/XDC721Client.java index 75902da..ed09847 100644 --- a/XDC3Java/src/main/java/com/XDCJava/XDC721Client.java +++ b/XDC3Java/src/main/java/com/XDCJava/XDC721Client.java @@ -75,7 +75,6 @@ public static Boolean isWeb3jConnected() { public void getTokenoinfo(String tokenAddress, Token721DetailCallback tokenDetailCallback) { - if (isWeb3jConnected()) { ClientTransactionManager transactionManager = new ClientTransactionManager(web3, tokenAddress); @@ -87,9 +86,7 @@ public void getTokenoinfo(String tokenAddress, Token721DetailCallback tokenDetai exception.printStackTrace(); tokenDetailCallback.failure(exception.getMessage()); } - } else { - //Show Error tokenDetailCallback.failure("Connection has been failed"); } @@ -99,8 +96,6 @@ public void getTokenoinfo(String tokenAddress, Token721DetailCallback tokenDetai @SuppressWarnings("NewApi") public void deploy_contract(String privatekey, Token721DetailCallback tokenDetailCallback) { - - if (isWeb3jConnected()) { Credentials credentials = Credentials.create(privatekey); try { @@ -138,7 +133,6 @@ public void deploy_contract(String privatekey, Token721DetailCallback tokenDetai e.printStackTrace(); } - if (hash != null) { EthGetTransactionReceipt transactionReceipt = @@ -151,21 +145,14 @@ public void deploy_contract(String privatekey, Token721DetailCallback tokenDetai // try again tokenDetailCallback.failure("failed"); } - - } else { tokenDetailCallback.failure("failed"); } - - } catch (Exception e) { e.printStackTrace(); tokenDetailCallback.failure(e.getMessage()); } - - } else { - //Show Error tokenDetailCallback.failure("Connection has been failed"); } @@ -237,8 +224,6 @@ public String getBalance(String tokenAddress, String ownerAddress) { try { XRC721 javaToken1 = XRC721.load(tokenAddress, web3, transactionManager, new DefaultGasProvider()); BigInteger balance = javaToken1.balanceOf(ownerAddress).send(); - - return String.valueOf(balance); } catch (Exception exception) { exception.printStackTrace(); @@ -250,8 +235,6 @@ public String getBalance(String tokenAddress, String ownerAddress) { //Show Error return "Connection has been failed"; } - - } @@ -260,8 +243,6 @@ public String getBalance(String tokenAddress, String ownerAddress) { /// @return A count of valid NFTs tracked by this contract, where each one of /// them has an assigned and queryable owner not equal to the zero address public String gettotalSupply(String tokenAddress) { - - if (isWeb3jConnected()) { ClientTransactionManager transactionManager = new ClientTransactionManager(web3, tokenAddress); @@ -324,8 +305,6 @@ public static String tokenOfOwnerByIndex(String tokenAddress, String ownerAddres try { XRC721Enumerable javaToken1 = XRC721Enumerable.load(tokenAddress, web3, transactionManager, new DefaultGasProvider()); BigInteger token = javaToken1.tokenOfOwnerByIndex(ownerAddress, new BigInteger(index)).send(); - - return String.valueOf(token); } catch (Exception exception) { exception.printStackTrace(); @@ -494,8 +473,6 @@ public String getApproved(String tokenAddress, String tokenId) { /// @param tokenAddress NFT address /// @return True if `_operator` is an approved operator for `_owner`, false otherwise public boolean isApprovedForAll(String tokenAddress, String ownerAddress, String OperatorAddress) { - - if (isWeb3jConnected()) { ClientTransactionManager transactionManager = new ClientTransactionManager(web3, tokenAddress); @@ -511,7 +488,6 @@ public boolean isApprovedForAll(String tokenAddress, String ownerAddress, String } } else { - //Show Error return false; } @@ -695,5 +671,4 @@ public String transferfrom(String tokenAddress, String privatekey, String receiv return "Failed"; } } - }