diff --git a/app/src/main/java/cy/agorise/graphenej/AuthorityType.java b/app/src/main/java/cy/agorise/graphenej/AuthorityType.java
new file mode 100644
index 0000000..2fb52b8
--- /dev/null
+++ b/app/src/main/java/cy/agorise/graphenej/AuthorityType.java
@@ -0,0 +1,13 @@
+package cy.agorise.graphenej;
+
+/**
+ * Enum-type used to specify the different roles of an authority.
+ *
+ * @see Authority
+ */
+
+public enum AuthorityType {
+ OWNER,
+ ACTIVE,
+ MEMO
+}
diff --git a/app/src/main/java/cy/agorise/graphenej/api/GetRelativeAccountHistory.java b/app/src/main/java/cy/agorise/graphenej/api/GetRelativeAccountHistory.java
index e3d837e..935618f 100644
--- a/app/src/main/java/cy/agorise/graphenej/api/GetRelativeAccountHistory.java
+++ b/app/src/main/java/cy/agorise/graphenej/api/GetRelativeAccountHistory.java
@@ -20,6 +20,7 @@ import cy.agorise.graphenej.models.ApiCall;
import cy.agorise.graphenej.models.BaseResponse;
import cy.agorise.graphenej.models.HistoricalTransfer;
import cy.agorise.graphenej.models.WitnessResponse;
+import cy.agorise.graphenej.objects.Memo;
import cy.agorise.graphenej.operations.TransferOperation;
/**
@@ -161,6 +162,7 @@ public class GetRelativeAccountHistory extends BaseGrapheneHandler {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(TransferOperation.class, new TransferOperation.TransferDeserializer());
gsonBuilder.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer());
+ gsonBuilder.registerTypeAdapter(Memo.class, new Memo.MemoDeserializer());
WitnessResponse> transfersResponse = gsonBuilder.create().fromJson(response, RelativeAccountHistoryResponse);
mListener.onSuccess(transfersResponse);
}
diff --git a/app/src/main/java/cy/agorise/graphenej/api/SubscriptionMessagesHub.java b/app/src/main/java/cy/agorise/graphenej/api/SubscriptionMessagesHub.java
index 5373bb6..f1bd5f5 100644
--- a/app/src/main/java/cy/agorise/graphenej/api/SubscriptionMessagesHub.java
+++ b/app/src/main/java/cy/agorise/graphenej/api/SubscriptionMessagesHub.java
@@ -26,6 +26,7 @@ import cy.agorise.graphenej.models.ApiCall;
import cy.agorise.graphenej.models.DynamicGlobalProperties;
import cy.agorise.graphenej.models.SubscriptionResponse;
import cy.agorise.graphenej.models.WitnessResponse;
+import cy.agorise.graphenej.objects.Memo;
import cy.agorise.graphenej.operations.LimitOrderCreateOperation;
import cy.agorise.graphenej.operations.TransferOperation;
@@ -91,6 +92,7 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs
builder.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer());
builder.registerTypeAdapter(UserAccount.class, new UserAccount.UserAccountSimpleDeserializer());
builder.registerTypeAdapter(DynamicGlobalProperties.class, new DynamicGlobalProperties.DynamicGlobalPropertiesDeserializer());
+ builder.registerTypeAdapter(Memo.class, new Memo.MemoDeserializer());
this.gson = builder.create();
}
diff --git a/app/src/main/java/cy/agorise/graphenej/objects/Memo.java b/app/src/main/java/cy/agorise/graphenej/objects/Memo.java
index 1ba540c..669c5e4 100644
--- a/app/src/main/java/cy/agorise/graphenej/objects/Memo.java
+++ b/app/src/main/java/cy/agorise/graphenej/objects/Memo.java
@@ -1,17 +1,25 @@
package cy.agorise.graphenej.objects;
import com.google.common.primitives.Bytes;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+
import cy.agorise.graphenej.Address;
import cy.agorise.graphenej.PublicKey;
import cy.agorise.graphenej.Util;
import cy.agorise.graphenej.errors.ChecksumException;
+import cy.agorise.graphenej.errors.MalformedAddressException;
import cy.agorise.graphenej.interfaces.ByteSerializable;
import cy.agorise.graphenej.interfaces.JsonSerializable;
+import cy.agorise.graphenej.operations.TransferOperation;
+
import org.bitcoinj.core.ECKey;
import org.spongycastle.math.ec.ECPoint;
+import java.lang.reflect.Type;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
@@ -269,4 +277,30 @@ public class Memo implements ByteSerializable, JsonSerializable {
}
return memoObject;
}
+
+ /**
+ * Class used to deserialize a memo
+ */
+ public static class MemoDeserializer implements JsonDeserializer {
+
+ @Override
+ public Memo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
+ JsonObject jsonObject = json.getAsJsonObject();
+ String fromAddress = jsonObject.get(KEY_FROM).getAsString();
+ String toAddress = jsonObject.get(KEY_TO).getAsString();
+ long nonce = jsonObject.get(KEY_NONCE).getAsLong();
+ String msg = jsonObject.get(KEY_MESSAGE).getAsString();
+
+ Memo memo = null;
+ try{
+ Address from = new Address(fromAddress);
+ Address to = new Address(toAddress);
+ byte[] message = Util.hexToBytes(msg);
+ memo = new Memo(from, to, nonce, message);
+ }catch(MalformedAddressException e){
+ System.out.println("MalformedAddressException. Msg: "+e.getMessage());
+ }
+ return memo;
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/cy/agorise/graphenej/operations/TransferOperation.java b/app/src/main/java/cy/agorise/graphenej/operations/TransferOperation.java
index 33698d9..0988640 100644
--- a/app/src/main/java/cy/agorise/graphenej/operations/TransferOperation.java
+++ b/app/src/main/java/cy/agorise/graphenej/operations/TransferOperation.java
@@ -1,7 +1,6 @@
package cy.agorise.graphenej.operations;
import com.google.common.primitives.Bytes;
-import com.google.common.primitives.UnsignedLong;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
@@ -14,13 +13,10 @@ import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
-import cy.agorise.graphenej.Address;
import cy.agorise.graphenej.AssetAmount;
import cy.agorise.graphenej.BaseOperation;
import cy.agorise.graphenej.OperationType;
import cy.agorise.graphenej.UserAccount;
-import cy.agorise.graphenej.Util;
-import cy.agorise.graphenej.errors.MalformedAddressException;
import cy.agorise.graphenej.objects.Memo;
/**
@@ -171,7 +167,6 @@ public class TransferOperation extends BaseOperation {
@Override
public TransferOperation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
- System.out.println("Deserialized bitch start. Msg: "+ json.getAsString());
if(json.isJsonArray()){
// This block is used just to check if we are in the first step of the deserialization
// when we are dealing with an array.
@@ -197,20 +192,10 @@ public class TransferOperation extends BaseOperation {
UserAccount to = new UserAccount(jsonObject.get(KEY_TO).getAsString());
TransferOperation transfer = new TransferOperation(from, to, amount, fee);
- // Deserializing Memo if it exists
- System.out.println("Deserialized bitch. Msg: "+ jsonObject.getAsString());
- if(jsonObject.get(KEY_MEMO) != null){
- JsonObject memoObj = jsonObject.get(KEY_MEMO).getAsJsonObject();
- try{
- Address memoFrom = new Address(memoObj.get(Memo.KEY_FROM).getAsString());
- Address memoTo = new Address(memoObj.get(KEY_TO).getAsString());
- long nonce = UnsignedLong.valueOf(memoObj.get(Memo.KEY_NONCE).getAsString()).longValue();
- byte[] message = Util.hexToBytes(memoObj.get(Memo.KEY_MESSAGE).getAsString());
- Memo memo = new Memo(memoFrom, memoTo, nonce, message);
- transfer.setMemo(memo);
- }catch(MalformedAddressException e){
- System.out.println("MalformedAddressException. Msg: "+e.getMessage());
- }
+ // If the transfer had a memo, deserialize it
+ if(jsonObject.has(KEY_MEMO)){
+ Memo memo = context.deserialize(jsonObject.get(KEY_MEMO), Memo.class);
+ transfer.setMemo(memo);
}
return transfer;