From 9b292d220ed014f1754eabed04a6334bc2eab312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius?= Date: Mon, 31 Jul 2017 15:24:13 -0300 Subject: [PATCH] Fix memo deserialization --- .../operations/TransferOperation.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/TransferOperation.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/TransferOperation.java index 47d34d4..c4af581 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/TransferOperation.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/operations/TransferOperation.java @@ -1,6 +1,7 @@ package de.bitsharesmunich.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; @@ -13,10 +14,13 @@ import com.google.gson.JsonSerializer; import java.lang.reflect.Type; +import de.bitsharesmunich.graphenej.Address; import de.bitsharesmunich.graphenej.AssetAmount; import de.bitsharesmunich.graphenej.BaseOperation; import de.bitsharesmunich.graphenej.OperationType; import de.bitsharesmunich.graphenej.UserAccount; +import de.bitsharesmunich.graphenej.Util; +import de.bitsharesmunich.graphenej.errors.MalformedAddressException; import de.bitsharesmunich.graphenej.objects.Memo; /** @@ -167,6 +171,7 @@ 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. @@ -191,8 +196,25 @@ public class TransferOperation extends BaseOperation { UserAccount from = new UserAccount(jsonObject.get(KEY_FROM).getAsString()); 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()); + } + } + return transfer; } } } -} \ No newline at end of file +}