Memo encoding

This commit is contained in:
Henry Varona 2016-12-10 00:03:46 -04:00
parent 91c5d7d181
commit 1e4327b33f
2 changed files with 12 additions and 4 deletions

View file

@ -47,7 +47,11 @@ public class Memo implements ByteSerializable, JsonSerializable {
if ((this.from == null) || (this.to == null) || (this.nonce == null) || (this.message == null)) { if ((this.from == null) || (this.to == null) || (this.nonce == null) || (this.message == null)) {
return new byte[]{(byte) 0}; return new byte[]{(byte) 0};
} else { } else {
return Bytes.concat(this.from.toBytes(), this.to.toBytes(), this.nonce, this.message); byte[] nonceformat = new byte[nonce.length];
for (int i = 0; i < nonceformat.length; i++) {
nonceformat[i] = nonce[nonce.length - i];
}
return Bytes.concat(new byte[]{1}, this.from.toBytes(), this.to.toBytes(), nonceformat, new byte[]{(byte) this.message.length}, this.message);
} }
} }
@ -127,10 +131,10 @@ public class Memo implements ByteSerializable, JsonSerializable {
return null; return null;
} }
JsonObject memoObject = new JsonObject(); JsonObject memoObject = new JsonObject();
memoObject.addProperty(KEY_FROM, new Address(this.from.getKey()).toString()); memoObject.addProperty(KEY_FROM, this.from.getAddress());
memoObject.addProperty(KEY_MESSAGE, new BigInteger(1, this.message).toString(16)); memoObject.addProperty(KEY_TO, this.to.getAddress());
memoObject.addProperty(KEY_NONCE, new BigInteger(1, this.nonce).toString(10)); memoObject.addProperty(KEY_NONCE, new BigInteger(1, this.nonce).toString(10));
memoObject.addProperty(KEY_TO, new Address(this.to.getKey()).toString()); memoObject.addProperty(KEY_MESSAGE, new BigInteger(1, this.message).toString(16));
return memoObject; return memoObject;
} }

View file

@ -21,4 +21,8 @@ public class PublicKey implements ByteSerializable {
public byte[] toBytes() { public byte[] toBytes() {
return publicKey.getPubKey(); return publicKey.getPubKey();
} }
public String getAddress(){
return new Address(publicKey).toString();
}
} }