Fix memo deserialization
This commit is contained in:
parent
eab6990d73
commit
9b292d220e
1 changed files with 23 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue