diff --git a/src/main/java/de/bitsharesmunich/graphenej/Main.java b/src/main/java/de/bitsharesmunich/graphenej/Main.java index 4298c31..b6b998a 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/Main.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Main.java @@ -5,6 +5,10 @@ public class Main { // 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_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_7_BRAIN_KEY = System.getenv("BILTHON_7_BRAIN_KEY"); diff --git a/src/main/java/de/bitsharesmunich/graphenej/Test.java b/src/main/java/de/bitsharesmunich/graphenej/Test.java index 50c37a9..9f08c4a 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/Test.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Test.java @@ -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())); try { +// Address address = new Address("BTS5BgjNRDeawGSc1NPk91p2BYYEhJWKgsjLZGDmFgY6uwhAYLy9G"); + // Create a custom SSL context. SSLContext context = null; context = NaiveSSLContext.getInstance("TLS"); @@ -535,6 +537,9 @@ public class Test { } catch (NoSuchAlgorithmException e) { System.out.println("NoSuchAlgorithmException. Msg: " + e.getMessage()); } +// catch (MalformedAddressException e) { +// System.out.println("MalformedAddressException. Msg: "+e.getMessage()); +// } } public void testAccountNameById() { @@ -678,9 +683,9 @@ public class Test { authMap.put(address.getPublicKey(), 1); Authority authority = new Authority(1, authMap, null); 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()) - .setAccont(new UserAccount("1.2.140994")) + .setAccont(new UserAccount("1.2.139205")) .setOwner(authority) .setActive(authority) .setOptions(options) @@ -693,7 +698,7 @@ public class Test { // Set the custom SSL 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.connect(); diff --git a/src/main/java/de/bitsharesmunich/graphenej/UserAccount.java b/src/main/java/de/bitsharesmunich/graphenej/UserAccount.java index 3689de4..a06c251 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/UserAccount.java +++ b/src/main/java/de/bitsharesmunich/graphenej/UserAccount.java @@ -9,6 +9,7 @@ import java.io.DataOutput; import java.io.DataOutputStream; import java.io.IOException; import java.lang.reflect.Type; +import java.util.ArrayList; /** * Class tha represents a graphene user account. @@ -93,4 +94,18 @@ public class UserAccount extends GrapheneObject implements ByteSerializable, Jso 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 { + + @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); + } + } } diff --git a/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountsByAddress.java b/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountsByAddress.java index 9706fb0..86fa9ba 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountsByAddress.java +++ b/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountsByAddress.java @@ -1,12 +1,10 @@ package de.bitsharesmunich.graphenej.api; -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; +import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import de.bitsharesmunich.graphenej.Address; 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.models.ApiCall; import de.bitsharesmunich.graphenej.models.BaseResponse; @@ -37,21 +35,11 @@ public class GetAccountsByAddress extends WebSocketAdapter { @Override public void onConnected(WebSocket websocket, Map> headers) throws Exception { - ArrayList accountParams = new ArrayList(); - ArrayList paramAddress = new ArrayList(); - paramAddress.add(new JsonSerializable() { - @Override - public String toJsonString() { - 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); + ArrayList params = new ArrayList(); + ArrayList addresses = new ArrayList(); + addresses.add(address.toString()); + params.add(addresses); + ApiCall getAccountByAddress = new ApiCall(0, RPC.CALL_GET_KEY_REFERENCES, params, RPC.VERSION, 1); websocket.sendText(getAccountByAddress.toJsonString()); } @@ -59,10 +47,11 @@ public class GetAccountsByAddress extends WebSocketAdapter { public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception { System.out.println("<<< "+frame.getPayloadText()); String response = frame.getPayloadText(); - Gson gson = new Gson(); + GsonBuilder builder = new GsonBuilder(); - Type GetAccountByAddressResponse = new TypeToken>>>(){}.getType(); - WitnessResponse>> witnessResponse = gson.fromJson(response, GetAccountByAddressResponse); + Type GetAccountByAddressResponse = new TypeToken>>>(){}.getType(); + builder.registerTypeAdapter(UserAccount.class, new UserAccount.UserAccountSimpleDeserializer()); + WitnessResponse>> witnessResponse = builder.create().fromJson(response, GetAccountByAddressResponse); if (witnessResponse.error != null) { this.mListener.onError(witnessResponse.error); } else { diff --git a/src/main/java/de/bitsharesmunich/graphenej/api/GetRequiredFees.java b/src/main/java/de/bitsharesmunich/graphenej/api/GetRequiredFees.java index dfc9118..98c5909 100644 --- a/src/main/java/de/bitsharesmunich/graphenej/api/GetRequiredFees.java +++ b/src/main/java/de/bitsharesmunich/graphenej/api/GetRequiredFees.java @@ -42,7 +42,7 @@ public class GetRequiredFees extends WebSocketAdapter { ArrayList accountParams = new ArrayList<>(); accountParams.add((Serializable) this.operations); 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()); }