Fixing bug with graphenej that affected all transfers with UIA with id above 1.3.127

This commit is contained in:
Nelson R. Perez 2016-12-19 00:43:11 -05:00
parent 057b89a78b
commit 143612af88

View file

@ -1,10 +1,15 @@
package de.bitsharesmunich.graphenej; package de.bitsharesmunich.graphenej;
import com.google.common.primitives.Bytes;
import com.google.common.primitives.UnsignedLong; import com.google.common.primitives.UnsignedLong;
import com.google.gson.*; import com.google.gson.*;
import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; import de.bitsharesmunich.graphenej.interfaces.ByteSerializable;
import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; import de.bitsharesmunich.graphenej.interfaces.JsonSerializable;
import java.io.ByteArrayOutputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
/** /**
@ -34,16 +39,22 @@ public class AssetAmount implements ByteSerializable, JsonSerializable {
} }
public Asset getAsset(){ return this.asset; } public Asset getAsset(){ return this.asset; }
@Override @Override
public byte[] toBytes() { public byte[] toBytes() {
byte[] serialized = new byte[8 + 1]; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] amountBytes = this.amount.bigIntegerValue().toByteArray(); DataOutput out = new DataOutputStream(byteArrayOutputStream);
serialized[serialized.length - 1] = (byte) asset.instance; try {
Varint.writeUnsignedVarLong(asset.instance, out);
} catch (IOException e) {
e.printStackTrace();
}
// Getting asset id
byte[] assetId = byteArrayOutputStream.toByteArray();
byte[] value = Util.revertLong(this.amount.longValue());
for(int i = 0; i < amountBytes.length; i++) // Concatenating and returning value + asset id
serialized[i] = amountBytes[amountBytes.length - 1 - i]; return Bytes.concat(value, assetId);
return serialized;
} }
@Override @Override