From 701aeb8b38061b9f6acee4dc6f81bd8bae6485e8 Mon Sep 17 00:00:00 2001 From: henry Date: Wed, 27 Sep 2017 23:04:16 -0400 Subject: [PATCH 1/3] Created ApiRequest Complete the apiGenerator for import account --- .../apigenerator/ApiRequest.java | 33 ++++ .../apigenerator/ApiRequestListener.java | 12 ++ .../apigenerator/GrapheneApiGenerator.java | 154 +++++++++++++++--- 3 files changed, 180 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequest.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequestListener.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequest.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequest.java new file mode 100644 index 0000000..1843f70 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequest.java @@ -0,0 +1,33 @@ +package cy.agorise.crystalwallet.apigenerator; + +/** + * Created by henry on 27/9/2017. + */ + +public class ApiRequest { + + int id; + + ApiRequestListener listener; + + public ApiRequest(int id, ApiRequestListener listener) { + this.id = id; + this.listener = listener; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public ApiRequestListener getListener() { + return listener; + } + + public void setListener(ApiRequestListener listener) { + this.listener = listener; + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequestListener.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequestListener.java new file mode 100644 index 0000000..bd3d76e --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/ApiRequestListener.java @@ -0,0 +1,12 @@ +package cy.agorise.crystalwallet.apigenerator; + +/** + * Created by henry on 27/9/2017. + */ + +public interface ApiRequestListener { + + public void success(Object answer, int idPetition); + public void fail(int idPetition); + +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java index 74349c1..8c5499a 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java @@ -1,9 +1,24 @@ package cy.agorise.crystalwallet.apigenerator; +import com.neovisionaries.ws.client.WebSocket; +import com.neovisionaries.ws.client.WebSocketException; +import com.neovisionaries.ws.client.WebSocketFactory; + +import cy.agorise.graphenej.Address; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.api.GetAccounts; +import cy.agorise.graphenej.api.GetKeyReferences; +import cy.agorise.graphenej.api.GetRelativeAccountHistory; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.AccountProperties; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.HistoricalTransfer; +import cy.agorise.graphenej.models.WitnessResponse; + +import java.io.IOException; +import java.util.ArrayList; import java.util.List; -import cy.agorise.crystalwallet.models.GrapheneAccount; -import cy.agorise.graphenej.models.HistoricalTransfer; /** * Created by henry on 26/9/2017. @@ -11,50 +26,151 @@ import cy.agorise.graphenej.models.HistoricalTransfer; public class GrapheneApiGenerator { + //TODO network connections + private static int connectionTimeout = 5000; + private static String url = "http://128.0.69.157:8090" + /** * Retrieves the data of an account searching by it's id * * @param accountId The accountId to retrieve - * @return The Account properties retrieved from the net, or null if fails + * @param request The Api request object, to answer this petition */ - public GrapheneAccount getAccountById(String accountId){ - //TODO implement - return null; + public static void getAccountById(String accountId, final ApiRequest request){ + WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(connectionTimeout); + try { + final WebSocket webSocket = factory.createSocket(url); + webSocket.addListener(new GetAccounts(accountId, new WitnessResponseListener() { + @Override + public void onSuccess(WitnessResponse response) { + if (response.result.getClass() == ArrayList.class) { + List list = (List) response.result; + if (list.size() > 0) { + if (list.get(0).getClass() == AccountProperties.class) { + request.getListener().success(list.get(0),request.getId()); + //TODO answer a crystal model + } + } + } + request.getListener().fail(request.getId()); + } + + @Override + public void onError(BaseResponse.Error error) { + request.getListener().fail(request.getId()); + } + })); + Thread thread = new Thread(){ + public void run(){ + try { + webSocket.connect(); + } catch (WebSocketException e) { + e.printStackTrace(); + request.getListener().fail(request.getId()); + } + } + }; + thread.start(); + } catch (IOException e) { + e.printStackTrace(); + request.getListener().fail(request.getId()); + } } /** * Gets the account ID from an owner or active key * * @param address The address to retrieve - * @return The id of the account, of null + * @param request The Api request object, to answer this petition */ - public String getAccountByOwnerOrActiveAddress(String address){ - //TODO implement - return null; + public static void getAccountByOwnerOrActiveAddress(Address address, final ApiRequest request){ + //TODO change address + WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(connectionTimeout); + try { + final WebSocket webSocket = factory.createSocket(url); + webSocket.addListener(new GetKeyReferences(address, true, new WitnessResponseListener() { + @Override + public void onSuccess(WitnessResponse response) { + final List> resp = (List>) response.result; + if(resp.size() > 0){ + List accounts = resp.get(0); + if(accounts.size() > 0){ + for(UserAccount account : accounts) { + request.getListener().success(account,request.getId());}}} + request.getListener().fail(request.getId()); + } + + @Override + public void onError(BaseResponse.Error error) { + request.getListener().fail(request.getId()); + } + })); + Thread thread = new Thread(){ + public void run(){ + try { + webSocket.connect(); + } catch (WebSocketException e) { + e.printStackTrace(); + request.getListener().fail(request.getId()); + } + } + }; + thread.start(); + } catch (IOException e) { + e.printStackTrace(); + request.getListener().fail(request.getId()); + } } /** - * Return the Transaction for an Account + * Gets the Transaction for an Account * * @param accountId The account id to search * @param start The start index of the transaction list * @param stop The stop index of the transaction list * @param limit the maximun transactions to retrieve - * @return The list of trnsaction of the account, or null if the call fail + * @param request The Api request object, to answer this petition */ - public List getAccountTransaction(String accountId, int start, int stop, int limit){ - //TODO implement - return null; + public static void getAccountTransaction(String accountId, int start, int stop, int limit, final ApiRequest request){ + WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(connectionTimeout); + try { + final WebSocket webSocket = factory.createSocket(url); + webSocket.addListener(new GetRelativeAccountHistory(new UserAccount(accountId), stop, limit, start, new WitnessResponseListener() { + @Override + public void onSuccess(WitnessResponse response) { + WitnessResponse> resp = response; + request.getListener().success(resp,request.getId()); + } + + @Override + public void onError(BaseResponse.Error error) { + request.getListener().fail(request.getId()); + } + })); + Thread thread = new Thread(){ + public void run(){ + try { + webSocket.connect(); + } catch (WebSocketException e) { + e.printStackTrace(); + request.getListener().fail(request.getId()); + } + } + }; + thread.start(); + } catch (IOException e) { + e.printStackTrace(); + request.getListener().fail(request.getId()); + } } /** - * Returns if an Account Name is avaible to be used for a new account + * Gets if an Account Name is avaible to be used for a new account * * @param accountName The account Name to find - * @return If the account name isn't used in any bitshares account + * @param request The Api request object, to answer this petition */ - public boolean isAccountNameAvaible(String accountName){ + public static void isAccountNameAvaible(String accountName, ApiRequest request){ //TODO implement - return false; } } From 7d77348a504575f06fb522aae94e90ffb36c8aec Mon Sep 17 00:00:00 2001 From: Nelson Perez Date: Fri, 29 Sep 2017 10:29:01 -0500 Subject: [PATCH 2/3] Adjusting Bitshares precision value At least this one I know is not 8, but 5. Check it out here: https://cryptofresh.com/a/BTS. You might want to double check the precision value for all the others. Although since they are all forks of the bitcoin codebase in the end they might really be 8. --- .../main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java b/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java index 1c385b7..0dc377c 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java +++ b/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java @@ -12,7 +12,7 @@ public enum CryptoCoin implements Serializable { LITECOIN(CryptoNet.LITECOIN,"LTC",8), DASH(CryptoNet.DASH,"DASH",8), DOGECOIN(CryptoNet.DOGECOIN,"DOGE",8), - BITSHARES(CryptoNet.BITSHARES,"BTS",8); + BITSHARES(CryptoNet.BITSHARES,"BTS",5); protected CryptoNet cryptoNet; protected String label; From e74b1d21c502c0461c9b2eaa8c74804d2e84c6ce Mon Sep 17 00:00:00 2001 From: The rise of Agorism! Date: Sat, 30 Sep 2017 14:33:54 +0300 Subject: [PATCH 3/3] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..54b8475 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Agorise + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.