Improvements in the GetAccountsByAddress class and new UserAccount deserializer
This commit is contained in:
parent
c20ae23921
commit
47fa879ab0
5 changed files with 40 additions and 27 deletions
|
@ -5,6 +5,10 @@ public class Main {
|
||||||
// Brain key from Nelson's app referencing the bilthon-83 account
|
// Brain key from Nelson's app referencing the bilthon-83 account
|
||||||
public static final String BILTHON_83_BRAIN_KEY = System.getenv("BILTHON_83_BRAIN_KEY");
|
public static final String BILTHON_83_BRAIN_KEY = System.getenv("BILTHON_83_BRAIN_KEY");
|
||||||
|
|
||||||
|
public static final String BILTHON_83_ORIGINAL_BRAIN_KEY = System.getenv("BILTHON_83_ORIGINAL_BRAIN_KEY");
|
||||||
|
|
||||||
|
public static final String BILTHON_1_BRAIN_KEY = System.getenv("BILTHON_1_BRAIN_KEY");
|
||||||
|
|
||||||
public static final String BILTHON_5_BRAIN_KEY = System.getenv("BILTHON_5_BRAIN_KEY");
|
public static final String BILTHON_5_BRAIN_KEY = System.getenv("BILTHON_5_BRAIN_KEY");
|
||||||
|
|
||||||
public static final String BILTHON_7_BRAIN_KEY = System.getenv("BILTHON_7_BRAIN_KEY");
|
public static final String BILTHON_7_BRAIN_KEY = System.getenv("BILTHON_7_BRAIN_KEY");
|
||||||
|
|
|
@ -514,9 +514,11 @@ public class Test {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BrainKey brainKey = new BrainKey(Main.BILTHON_83_BRAIN_KEY, 0);
|
BrainKey brainKey = new BrainKey(Main.BILTHON_83_ORIGINAL_BRAIN_KEY, 0);
|
||||||
Address address = new Address(ECKey.fromPublicOnly(brainKey.getPrivateKey().getPubKey()));
|
Address address = new Address(ECKey.fromPublicOnly(brainKey.getPrivateKey().getPubKey()));
|
||||||
try {
|
try {
|
||||||
|
// Address address = new Address("BTS5BgjNRDeawGSc1NPk91p2BYYEhJWKgsjLZGDmFgY6uwhAYLy9G");
|
||||||
|
|
||||||
// Create a custom SSL context.
|
// Create a custom SSL context.
|
||||||
SSLContext context = null;
|
SSLContext context = null;
|
||||||
context = NaiveSSLContext.getInstance("TLS");
|
context = NaiveSSLContext.getInstance("TLS");
|
||||||
|
@ -535,6 +537,9 @@ public class Test {
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
System.out.println("NoSuchAlgorithmException. Msg: " + e.getMessage());
|
System.out.println("NoSuchAlgorithmException. Msg: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
// catch (MalformedAddressException e) {
|
||||||
|
// System.out.println("MalformedAddressException. Msg: "+e.getMessage());
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAccountNameById() {
|
public void testAccountNameById() {
|
||||||
|
@ -678,9 +683,9 @@ public class Test {
|
||||||
authMap.put(address.getPublicKey(), 1);
|
authMap.put(address.getPublicKey(), 1);
|
||||||
Authority authority = new Authority(1, authMap, null);
|
Authority authority = new Authority(1, authMap, null);
|
||||||
AccountOptions options = new AccountOptions(address.getPublicKey());
|
AccountOptions options = new AccountOptions(address.getPublicKey());
|
||||||
BrainKey brainKey = new BrainKey(Main.BILTHON_7_BRAIN_KEY, 0);
|
BrainKey brainKey = new BrainKey(Main.BILTHON_1_BRAIN_KEY, 0);
|
||||||
Transaction transaction = new AccountUpdateTransactionBuilder(brainKey.getPrivateKey())
|
Transaction transaction = new AccountUpdateTransactionBuilder(brainKey.getPrivateKey())
|
||||||
.setAccont(new UserAccount("1.2.140994"))
|
.setAccont(new UserAccount("1.2.139205"))
|
||||||
.setOwner(authority)
|
.setOwner(authority)
|
||||||
.setActive(authority)
|
.setActive(authority)
|
||||||
.setOptions(options)
|
.setOptions(options)
|
||||||
|
@ -693,7 +698,7 @@ public class Test {
|
||||||
// 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(BLOCK_PAY_DE);
|
||||||
|
|
||||||
mWebSocket.addListener(new TransactionBroadcastSequence(transaction, new Asset("1.3.0"), listener));
|
mWebSocket.addListener(new TransactionBroadcastSequence(transaction, new Asset("1.3.0"), listener));
|
||||||
mWebSocket.connect();
|
mWebSocket.connect();
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.io.DataOutput;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class tha represents a graphene user account.
|
* Class tha represents a graphene user account.
|
||||||
|
@ -93,4 +94,18 @@ public class UserAccount extends GrapheneObject implements ByteSerializable, Jso
|
||||||
return new UserAccount(id, name);
|
return new UserAccount(id, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom deserializer used to deserialize user accounts as provided by the response of the 'get_key_references' api call.
|
||||||
|
* This response contains serialized user accounts in the form [["id1","id2"]]
|
||||||
|
*/
|
||||||
|
public static class UserAccountSimpleDeserializer implements JsonDeserializer<UserAccount> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserAccount deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
String id = json.getAsString();
|
||||||
|
System.out.println("id: "+id);
|
||||||
|
return new UserAccount(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
package de.bitsharesmunich.graphenej.api;
|
package de.bitsharesmunich.graphenej.api;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import de.bitsharesmunich.graphenej.Address;
|
import de.bitsharesmunich.graphenej.Address;
|
||||||
import de.bitsharesmunich.graphenej.RPC;
|
import de.bitsharesmunich.graphenej.RPC;
|
||||||
import de.bitsharesmunich.graphenej.interfaces.JsonSerializable;
|
import de.bitsharesmunich.graphenej.UserAccount;
|
||||||
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
|
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
|
||||||
import de.bitsharesmunich.graphenej.models.ApiCall;
|
import de.bitsharesmunich.graphenej.models.ApiCall;
|
||||||
import de.bitsharesmunich.graphenej.models.BaseResponse;
|
import de.bitsharesmunich.graphenej.models.BaseResponse;
|
||||||
|
@ -37,21 +35,11 @@ public class GetAccountsByAddress extends WebSocketAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
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> params = new ArrayList();
|
||||||
ArrayList<Serializable> paramAddress = new ArrayList();
|
ArrayList<Serializable> addresses = new ArrayList();
|
||||||
paramAddress.add(new JsonSerializable() {
|
addresses.add(address.toString());
|
||||||
@Override
|
params.add(addresses);
|
||||||
public String toJsonString() {
|
ApiCall getAccountByAddress = new ApiCall(0, RPC.CALL_GET_KEY_REFERENCES, params, RPC.VERSION, 1);
|
||||||
return address.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonElement toJsonObject() {
|
|
||||||
return new JsonParser().parse(address.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
accountParams.add(paramAddress);
|
|
||||||
ApiCall getAccountByAddress = new ApiCall(0, RPC.CALL_GET_KEY_REFERENCES, accountParams, RPC.VERSION, 1);
|
|
||||||
websocket.sendText(getAccountByAddress.toJsonString());
|
websocket.sendText(getAccountByAddress.toJsonString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,10 +47,11 @@ public class GetAccountsByAddress extends WebSocketAdapter {
|
||||||
public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
|
public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
|
||||||
System.out.println("<<< "+frame.getPayloadText());
|
System.out.println("<<< "+frame.getPayloadText());
|
||||||
String response = frame.getPayloadText();
|
String response = frame.getPayloadText();
|
||||||
Gson gson = new Gson();
|
GsonBuilder builder = new GsonBuilder();
|
||||||
|
|
||||||
Type GetAccountByAddressResponse = new TypeToken<WitnessResponse<List<List<String>>>>(){}.getType();
|
Type GetAccountByAddressResponse = new TypeToken<WitnessResponse<List<List<UserAccount>>>>(){}.getType();
|
||||||
WitnessResponse<List<List<String>>> witnessResponse = gson.fromJson(response, GetAccountByAddressResponse);
|
builder.registerTypeAdapter(UserAccount.class, new UserAccount.UserAccountSimpleDeserializer());
|
||||||
|
WitnessResponse<List<List<UserAccount>>> witnessResponse = builder.create().fromJson(response, GetAccountByAddressResponse);
|
||||||
if (witnessResponse.error != null) {
|
if (witnessResponse.error != null) {
|
||||||
this.mListener.onError(witnessResponse.error);
|
this.mListener.onError(witnessResponse.error);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class GetRequiredFees extends WebSocketAdapter {
|
||||||
ArrayList<Serializable> accountParams = new ArrayList<>();
|
ArrayList<Serializable> accountParams = new ArrayList<>();
|
||||||
accountParams.add((Serializable) this.operations);
|
accountParams.add((Serializable) this.operations);
|
||||||
accountParams.add(this.asset.getObjectId());
|
accountParams.add(this.asset.getObjectId());
|
||||||
ApiCall getRequiredFees = new ApiCall(0, RPC.CALL_GET_REQUIRED_FEES, accountParams, "2.0", 1);
|
ApiCall getRequiredFees = new ApiCall(0, RPC.CALL_GET_REQUIRED_FEES, accountParams, RPC.VERSION, 1);
|
||||||
websocket.sendText(getRequiredFees.toJsonString());
|
websocket.sendText(getRequiredFees.toJsonString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue