lookup accountName
This commit is contained in:
parent
e235e096c9
commit
d53f79106e
5 changed files with 121 additions and 30 deletions
|
@ -38,7 +38,7 @@ public abstract class FileBin {
|
|||
public static String getBrainkeyFromByte(byte[] input, String password) {
|
||||
try {
|
||||
byte[] publicKey = new byte[33];
|
||||
byte[] rawDataEncripted = new byte[input.length-33];
|
||||
byte[] rawDataEncripted = new byte[input.length - 33];
|
||||
|
||||
System.arraycopy(input, 0, publicKey, 0, publicKey.length);
|
||||
System.arraycopy(input, 33, rawDataEncripted, 0, rawDataEncripted.length);
|
||||
|
@ -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();
|
||||
|
@ -74,8 +72,8 @@ public abstract class FileBin {
|
|||
System.arraycopy(encKey, 0, temp, 0, temp.length);
|
||||
|
||||
byte[] encBrain = new BigInteger(wallet.get("encrypted_brainkey").getAsString(), 16).toByteArray();
|
||||
while(encBrain[0] == 0){
|
||||
byte[]temp2 = new byte[encBrain.length-1];
|
||||
while (encBrain[0] == 0) {
|
||||
byte[] temp2 = new byte[encBrain.length - 1];
|
||||
System.arraycopy(encBrain, 1, temp2, 0, temp2.length);
|
||||
encBrain = temp2;
|
||||
}
|
||||
|
@ -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];
|
||||
|
@ -187,14 +184,14 @@ public abstract class FileBin {
|
|||
byte[] pre_out = new byte[cipher.getOutputSize(input.length)];
|
||||
int proc = cipher.processBytes(input, 0, input.length, pre_out, 0);
|
||||
int proc2 = cipher.doFinal(pre_out, proc);
|
||||
byte[] out = new byte[proc+proc2];
|
||||
System.arraycopy(pre_out, 0, out, 0, proc+proc2);
|
||||
byte[] out = new byte[proc + proc2];
|
||||
System.arraycopy(pre_out, 0, out, 0, proc + proc2);
|
||||
|
||||
//Unpadding
|
||||
byte countByte = (byte)((byte)out[out.length-1] % 16);
|
||||
byte countByte = (byte) ((byte) out[out.length - 1] % 16);
|
||||
int count = countByte & 0xFF;
|
||||
|
||||
if ((count > 15) || (count <= 0)){
|
||||
if ((count > 15) || (count <= 0)) {
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -210,7 +207,6 @@ public abstract class FileBin {
|
|||
return out;
|
||||
}
|
||||
} catch (NoSuchAlgorithmException | DataLengthException | IllegalStateException | InvalidCipherTextException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,8 @@ public class Main {
|
|||
// test.testRelativeAccountHistory();
|
||||
// test.testingInvoiceGeneration();
|
||||
// test.testCompression();
|
||||
test.testCreateBinFile();
|
||||
test.testImportBinFile();
|
||||
//test.testCreateBinFile();
|
||||
//test.testImportBinFile();
|
||||
test.testLookout();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue