Fixing memo toJsonObject test and deserializing memo's nonce only as a decimal number
This commit is contained in:
parent
0192728bd5
commit
3d4b2719bb
2 changed files with 7 additions and 8 deletions
|
@ -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{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue