Get account name WS
This commit is contained in:
parent
888ae56dc6
commit
04d883f1e2
3 changed files with 52 additions and 27 deletions
|
@ -69,6 +69,10 @@ public class Test {
|
||||||
} else if (list.get(0).getClass() == ArrayList.class) {
|
} else if (list.get(0).getClass() == ArrayList.class) {
|
||||||
List sl = (List) list.get(0);
|
List sl = (List) list.get(0);
|
||||||
if (sl.size() > 0) {
|
if (sl.size() > 0) {
|
||||||
|
if (response.result.getClass() == AccountProperties.class) {
|
||||||
|
AccountProperties accountProperties = (AccountProperties) response.result;
|
||||||
|
System.out.println("Got account properties " + accountProperties);
|
||||||
|
} else {
|
||||||
String accountId = (String) sl.get(0);
|
String accountId = (String) sl.get(0);
|
||||||
System.out.println("account id : " + accountId);
|
System.out.println("account id : " + accountId);
|
||||||
try {
|
try {
|
||||||
|
@ -93,6 +97,7 @@ public class Test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Got empty list!");
|
System.out.println("Got empty list!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,17 @@ public class GetAccountNameById extends WebSocketAdapter {
|
||||||
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
||||||
ArrayList<Serializable> accountParams = new ArrayList();
|
ArrayList<Serializable> accountParams = new ArrayList();
|
||||||
ArrayList<Serializable> paramAddress = new ArrayList();
|
ArrayList<Serializable> paramAddress = new ArrayList();
|
||||||
paramAddress.add(accountID);
|
paramAddress.add(new JsonSerializable() {
|
||||||
|
@Override
|
||||||
|
public String toJsonString() {
|
||||||
|
return accountID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement toJsonObject() {
|
||||||
|
return new JsonParser().parse(accountID);
|
||||||
|
}
|
||||||
|
});
|
||||||
accountParams.add(paramAddress);
|
accountParams.add(paramAddress);
|
||||||
ApiCall getAccountByAddress = new ApiCall(0, RPC.CALL_GET_ACCOUNTS, accountParams, RPC.VERSION, 1);
|
ApiCall getAccountByAddress = new ApiCall(0, RPC.CALL_GET_ACCOUNTS, accountParams, RPC.VERSION, 1);
|
||||||
websocket.sendText(getAccountByAddress.toJsonString());
|
websocket.sendText(getAccountByAddress.toJsonString());
|
||||||
|
|
|
@ -40,7 +40,17 @@ public class GetAccountsByAddress extends WebSocketAdapter {
|
||||||
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
|
||||||
ArrayList<Serializable> accountParams = new ArrayList();
|
ArrayList<Serializable> accountParams = new ArrayList();
|
||||||
ArrayList<Serializable> paramAddress = new ArrayList();
|
ArrayList<Serializable> paramAddress = new ArrayList();
|
||||||
paramAddress.add(address.toString());
|
paramAddress.add(new JsonSerializable() {
|
||||||
|
@Override
|
||||||
|
public String toJsonString() {
|
||||||
|
return address.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement toJsonObject() {
|
||||||
|
return new JsonParser().parse(address.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
accountParams.add(paramAddress);
|
accountParams.add(paramAddress);
|
||||||
ApiCall getAccountByAddress = new ApiCall(0, RPC.CALL_GET_KEY_REFERENCES, accountParams, RPC.VERSION, 1);
|
ApiCall getAccountByAddress = new ApiCall(0, RPC.CALL_GET_KEY_REFERENCES, accountParams, RPC.VERSION, 1);
|
||||||
websocket.sendText(getAccountByAddress.toJsonString());
|
websocket.sendText(getAccountByAddress.toJsonString());
|
||||||
|
@ -52,8 +62,8 @@ public class GetAccountsByAddress extends WebSocketAdapter {
|
||||||
String response = frame.getPayloadText();
|
String response = frame.getPayloadText();
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
|
|
||||||
Type GetAccountByAddressResponse = new TypeToken<WitnessResponse<List<String>>>(){}.getType();
|
Type GetAccountByAddressResponse = new TypeToken<WitnessResponse<List<List<String>>>>(){}.getType();
|
||||||
WitnessResponse<WitnessResponse<List<String>>> witnessResponse = gson.fromJson(response, GetAccountByAddressResponse);
|
WitnessResponse<WitnessResponse<List<List<String>>>> witnessResponse = gson.fromJson(response, GetAccountByAddressResponse);
|
||||||
|
|
||||||
if (witnessResponse.error != null) {
|
if (witnessResponse.error != null) {
|
||||||
this.mListener.onError(witnessResponse.error);
|
this.mListener.onError(witnessResponse.error);
|
||||||
|
|
Loading…
Reference in a new issue