diff --git a/graphenej/src/main/java/cy/agorise/graphenej/objects/Memo.java b/graphenej/src/main/java/cy/agorise/graphenej/objects/Memo.java index 8a12ada..27e1b3a 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/objects/Memo.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/objects/Memo.java @@ -294,13 +294,12 @@ public class Memo implements ByteSerializable, JsonSerializable { JsonObject jsonObject = json.getAsJsonObject(); String fromAddress = jsonObject.get(KEY_FROM).getAsString(); String toAddress = jsonObject.get(KEY_TO).getAsString(); - BigInteger nonce; - System.out.println("Trying to deserialize memo with nonce: <"+jsonObject.get(KEY_NONCE).getAsString()+">"); - try{ - nonce = new BigInteger(jsonObject.get(KEY_NONCE).getAsString(), 10); - }catch(NumberFormatException e){ - nonce = new BigInteger(jsonObject.get(KEY_NONCE).getAsString(), 16); - } + + // Apparently the nonce is always coming from the full node as a string containing a + // decimal number. This is at odds with the result of the #toJsonObject method + // which encodes this data in hexadecimal. + BigInteger nonce = new BigInteger(jsonObject.get(KEY_NONCE).getAsString(), 10); + String msg = jsonObject.get(KEY_MESSAGE).getAsString(); Memo memo = null; try{ diff --git a/graphenej/src/test/java/cy/agorise/graphenej/objects/MemoTest.java b/graphenej/src/test/java/cy/agorise/graphenej/objects/MemoTest.java index c22172f..190ce96 100644 --- a/graphenej/src/test/java/cy/agorise/graphenej/objects/MemoTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/objects/MemoTest.java @@ -132,7 +132,7 @@ public class MemoTest { JsonObject expected = new JsonObject(); expected.addProperty("from", new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, TestAccounts.Bilthon16.WIF).getKey().getPrivKeyBytes()).getPubKey())).toString()); expected.addProperty("to", new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, TestAccounts.Bilthon7.WIF).getKey().getPrivKeyBytes()).getPubKey())).toString()); - expected.addProperty("nonce", String.format("%d", shortEncryptedMessageNonce)); + expected.addProperty("nonce", String.format("%x", shortEncryptedMessageNonce)); expected.addProperty("message", "93c398e05f2a36a535f82880032a062d"); assertEquals("Memo instance should generate a valid JsonObject",expected, jsonObject); }