From 06b02f76d6da1530abf3f4825667915c8ffb1bb4 Mon Sep 17 00:00:00 2001 From: henry Date: Sun, 1 Oct 2017 21:39:51 -0400 Subject: [PATCH 1/2] Graphene api find name avaible --- .../apigenerator/GrapheneApiGenerator.java | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) 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 573fb02..438d382 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java @@ -6,6 +6,7 @@ import com.neovisionaries.ws.client.WebSocketFactory; import cy.agorise.graphenej.Address; import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.api.GetAccountByName; import cy.agorise.graphenej.api.GetAccounts; import cy.agorise.graphenej.api.GetKeyReferences; import cy.agorise.graphenej.api.GetRelativeAccountHistory; @@ -170,7 +171,40 @@ public class GrapheneApiGenerator { * @param accountName The account Name to find * @param request The Api request object, to answer this petition */ - public static void isAccountNameAvaible(String accountName, ApiRequest request){ - //TODO implement + public static void isAccountNameAvaible(String accountName, final ApiRequest request){ + WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(connectionTimeout); + try { + final WebSocket webSocket = factory.createSocket(url); + webSocket.addListener(new GetAccountByName(accountName, new WitnessResponseListener() { + @Override + public void onSuccess(WitnessResponse response) { + AccountProperties accountProperties = ((WitnessResponse) response).result; + if(accountProperties != null){ + request.getListener().success(true,request.getId()); + }else{ + request.getListener().success(false,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()); + } } } From a94af316cc48feb31dd65b4c35cd47ad804f5d70 Mon Sep 17 00:00:00 2001 From: henry Date: Sun, 1 Oct 2017 21:42:21 -0400 Subject: [PATCH 2/2] Graphene api find name avaible --- .../crystalwallet/apigenerator/GrapheneApiGenerator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 438d382..143faf1 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java @@ -166,12 +166,12 @@ public class GrapheneApiGenerator { } /** - * Gets if an Account Name is avaible to be used for a new account + * Retrieves the account id by the name of the account * * @param accountName The account Name to find * @param request The Api request object, to answer this petition */ - public static void isAccountNameAvaible(String accountName, final ApiRequest request){ + public static void getAccountIdByName(String accountName, final ApiRequest request){ WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(connectionTimeout); try { final WebSocket webSocket = factory.createSocket(url); @@ -180,9 +180,9 @@ public class GrapheneApiGenerator { public void onSuccess(WitnessResponse response) { AccountProperties accountProperties = ((WitnessResponse) response).result; if(accountProperties != null){ - request.getListener().success(true,request.getId()); + request.getListener().success(null,request.getId()); }else{ - request.getListener().success(false,request.getId()); + request.getListener().success(accountProperties.id,request.getId()); } }