Merge branch 'master' of ssh://bitbucket.org/bilthon/fullerene
This commit is contained in:
commit
592098f1cf
3 changed files with 51 additions and 25 deletions
|
@ -58,39 +58,44 @@ public class Test {
|
||||||
} else if (response.result.getClass() == ArrayList.class) {
|
} else if (response.result.getClass() == ArrayList.class) {
|
||||||
List list = (List) response.result;
|
List list = (List) response.result;
|
||||||
if (list.size() > 0) {
|
if (list.size() > 0) {
|
||||||
if(list.get(0) instanceof AccountProperties){
|
if (list.get(0) instanceof AccountProperties) {
|
||||||
List<AccountProperties> accountPropertiesList = list;
|
List<AccountProperties> accountPropertiesList = list;
|
||||||
for(AccountProperties accountProperties : accountPropertiesList){
|
for (AccountProperties accountProperties : accountPropertiesList) {
|
||||||
System.out.println("Account id: "+accountProperties.id);
|
System.out.println("Account id: " + accountProperties.id);
|
||||||
}
|
}
|
||||||
}else if (list.get(0) instanceof AssetAmount) {
|
} else if (list.get(0) instanceof AssetAmount) {
|
||||||
AssetAmount assetAmount = (AssetAmount) list.get(0);
|
AssetAmount assetAmount = (AssetAmount) list.get(0);
|
||||||
System.out.println("Got fee");
|
System.out.println("Got fee");
|
||||||
System.out.println("amount: " + assetAmount.getAmount() + ", asset id: " + assetAmount.getAsset().getObjectId());
|
System.out.println("amount: " + assetAmount.getAmount() + ", asset id: " + assetAmount.getAsset().getObjectId());
|
||||||
} 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) {
|
||||||
String accountId = (String) sl.get(0);
|
if (response.result.getClass() == AccountProperties.class) {
|
||||||
System.out.println("account id : " + accountId);
|
AccountProperties accountProperties = (AccountProperties) response.result;
|
||||||
try {
|
System.out.println("Got account properties " + accountProperties);
|
||||||
|
} else {
|
||||||
|
String accountId = (String) sl.get(0);
|
||||||
|
System.out.println("account id : " + accountId);
|
||||||
|
try {
|
||||||
|
|
||||||
// Create a custom SSL context.
|
// Create a custom SSL context.
|
||||||
SSLContext context = null;
|
SSLContext context = null;
|
||||||
context = NaiveSSLContext.getInstance("TLS");
|
context = NaiveSSLContext.getInstance("TLS");
|
||||||
WebSocketFactory factory = new WebSocketFactory();
|
WebSocketFactory factory = new WebSocketFactory();
|
||||||
|
|
||||||
// Set the custom SSL context.
|
// Set the custom SSL context.
|
||||||
factory.setSSLContext(context);
|
factory.setSSLContext(context);
|
||||||
|
|
||||||
WebSocket mWebSocket = factory.createSocket(OPENLEDGER_WITNESS_URL);
|
WebSocket mWebSocket = factory.createSocket(OPENLEDGER_WITNESS_URL);
|
||||||
mWebSocket.addListener(new GetAccountNameById(accountId, null));
|
mWebSocket.addListener(new GetAccountNameById(accountId, null));
|
||||||
mWebSocket.connect();
|
mWebSocket.connect();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("IOException. Msg: " + e.getMessage());
|
System.out.println("IOException. Msg: " + e.getMessage());
|
||||||
} catch (WebSocketException e) {
|
} catch (WebSocketException e) {
|
||||||
System.out.println("WebSocketException. Msg: " + e.getMessage());
|
System.out.println("WebSocketException. Msg: " + e.getMessage());
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -656,7 +661,7 @@ public class Test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAccountNameById(){
|
public void testAccountNameById() {
|
||||||
try {
|
try {
|
||||||
// Create a custom SSL context.
|
// Create a custom SSL context.
|
||||||
SSLContext context = null;
|
SSLContext context = null;
|
||||||
|
|
|
@ -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());
|
||||||
|
@ -51,6 +61,7 @@ public class GetAccountsByAddress extends WebSocketAdapter {
|
||||||
System.out.println("<<< "+frame.getPayloadText());
|
System.out.println("<<< "+frame.getPayloadText());
|
||||||
String response = frame.getPayloadText();
|
String response = frame.getPayloadText();
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
|
|
||||||
Type GetAccountByAddressResponse = new TypeToken<WitnessResponse<List<List<String>>>>(){}.getType();
|
Type GetAccountByAddressResponse = new TypeToken<WitnessResponse<List<List<String>>>>(){}.getType();
|
||||||
WitnessResponse<WitnessResponse<List<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) {
|
||||||
|
|
Loading…
Reference in a new issue