lookup accountName

This commit is contained in:
Henry Varona 2016-12-07 21:36:26 -04:00
parent e235e096c9
commit d53f79106e
5 changed files with 121 additions and 30 deletions

View file

@ -55,8 +55,6 @@ public abstract class FileBin {
System.arraycopy(rawData, 0, checksum, 0, 4);
byte[] compressedData = new byte[rawData.length - 4];
System.arraycopy(rawData, 4, compressedData, 0, compressedData.length);
System.out.println("Despues:"+byteToString(compressedData));
byte[] wallet_object_bytes = Util.decompress(compressedData, Util.XZ);
String wallet_string = new String(wallet_object_bytes, "UTF-8");
JsonObject wallet = new JsonParser().parse(wallet_string).getAsJsonObject();
@ -122,7 +120,6 @@ public abstract class FileBin {
accountNames.add(jsonAccountName);
wallet_object.add("linked_accounts", accountNames);
byte[] compressedData = Util.compress(wallet_object.toString().getBytes("UTF-8"), Util.XZ);
System.out.println("Antes:"+byteToString(compressedData));
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] checksum = md.digest(compressedData);
byte[] rawData = new byte[compressedData.length + 4];
@ -210,7 +207,6 @@ public abstract class FileBin {
return out;
}
} catch (NoSuchAlgorithmException | DataLengthException | IllegalStateException | InvalidCipherTextException ex) {
ex.printStackTrace();
}
return null;
}

View file

@ -59,7 +59,8 @@ public class Main {
// test.testRelativeAccountHistory();
// test.testingInvoiceGeneration();
// test.testCompression();
test.testCreateBinFile();
test.testImportBinFile();
//test.testCreateBinFile();
//test.testImportBinFile();
test.testLookout();
}
}

View file

@ -15,4 +15,5 @@ public class RPC {
public static final String CALL_GET_ACCOUNTS = "get_accounts";
public static final String CALL_GET_KEY_REFERENCES = "get_key_references";
public static final String CALL_GET_RELATIVE_ACCOUNT_HISTORY = "get_relative_account_history";
public static final String CALL_GET_ID_BY_NAME = "lookup_accounts";
}

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,72 @@
package com.luminiasoft.bitshares.ws;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.reflect.TypeToken;
import com.luminiasoft.bitshares.RPC;
import com.luminiasoft.bitshares.interfaces.WitnessResponseListener;
import com.luminiasoft.bitshares.models.ApiCall;
import com.luminiasoft.bitshares.models.BaseResponse;
import com.luminiasoft.bitshares.models.WitnessResponse;
import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketAdapter;
import com.neovisionaries.ws.client.WebSocketException;
import com.neovisionaries.ws.client.WebSocketFrame;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Created by henry on 07/12/16.
*/
public class GetAccountIdByName extends WebSocketAdapter {
private final String accountName;
private final WitnessResponseListener mListener;
public GetAccountIdByName(String accountName, WitnessResponseListener listener){
this.accountName = accountName;
this.mListener = listener;
}
@Override
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
ArrayList<Serializable> accountParams = new ArrayList<>();
accountParams.add(this.accountName);
accountParams.add(50);
ApiCall getAccountByName = new ApiCall(0, RPC.CALL_GET_ID_BY_NAME, accountParams, "2.0", 1);
websocket.sendText(getAccountByName.toJsonString());
}
@Override
public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
String response = frame.getPayloadText();
Gson gson = new Gson();
Type GetAccountByNameResponse = new TypeToken<WitnessResponse<JsonArray>>(){}.getType();
WitnessResponse<WitnessResponse<JsonArray>> witnessResponse = gson.fromJson(response, GetAccountByNameResponse);
if(witnessResponse.error != null){
this.mListener.onError(witnessResponse.error);
}else{
this.mListener.onSuccess(witnessResponse);
}
websocket.disconnect();
}
@Override
public void onError(WebSocket websocket, WebSocketException cause) throws Exception {
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
@Override
public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception {
mListener.onError(new BaseResponse.Error(cause.getMessage()));
websocket.disconnect();
}
}