@Test public void toBytes() throws Exception { LimitOrderCreateOperation operation = new LimitOrderCreateOperation(seller, amountToSell, minToReceive, expiration, true); operation.setFee(new AssetAmount(UnsignedLong.valueOf(2), CORE_ASSET)); byte[] serialized = operation.toBytes(); Assert.assertArrayEquals("Correct serialization", serialized, Util.hexToBytes("020000000000000000cbe10840787d01000000000001000000000000007984c4bd580100")); Assert.assertThat("Incorrect serialization", serialized, IsNot.not(IsEqual.equalTo(Util.hexToBytes("020000000000000000cbe10840787d01000000000001000000000000007984c4bd580000")))); operation = new LimitOrderCreateOperation(seller, amountToSell, minToReceive, expiration, false); operation.setFee(new AssetAmount(UnsignedLong.valueOf(2), CORE_ASSET)); serialized = operation.toBytes(); Assert.assertArrayEquals("Correct serialization", serialized, Util.hexToBytes("020000000000000000cbe10840787d01000000000001000000000000007984c4bd580000")); Assert.assertThat("Incorrect serialization", serialized, IsNot.not(IsEqual.equalTo(Util.hexToBytes("020000000000000000cbe10840787d01000000000001000000000000007984c4bd580100")))); }
@Override public byte[] toBytes() { byte[] feeBytes = this.fee.toBytes(); byte[] sellerBytes = this.seller.toBytes(); byte[] amountBytes = this.amountToSell.toBytes(); byte[] minAmountBytes = this.minToReceive.toBytes(); ByteBuffer buffer = ByteBuffer.allocate(EXPIRATION_BYTE_LENGTH); buffer.putInt(this.expiration); byte[] expirationBytes = Util.revertBytes(buffer.array()); byte[] fillOrKill = this.fillOrKill ? new byte[]{ 0x1 } : new byte[]{ 0x0 }; byte[] extensions = this.extensions.toBytes(); return Bytes.concat(feeBytes, sellerBytes, amountBytes, minAmountBytes, expirationBytes, fillOrKill, extensions); }
LimitOrderCreateOperation extends BaseOperation { @Override public byte[] toBytes() { byte[] feeBytes = this.fee.toBytes(); byte[] sellerBytes = this.seller.toBytes(); byte[] amountBytes = this.amountToSell.toBytes(); byte[] minAmountBytes = this.minToReceive.toBytes(); ByteBuffer buffer = ByteBuffer.allocate(EXPIRATION_BYTE_LENGTH); buffer.putInt(this.expiration); byte[] expirationBytes = Util.revertBytes(buffer.array()); byte[] fillOrKill = this.fillOrKill ? new byte[]{ 0x1 } : new byte[]{ 0x0 }; byte[] extensions = this.extensions.toBytes(); return Bytes.concat(feeBytes, sellerBytes, amountBytes, minAmountBytes, expirationBytes, fillOrKill, extensions); } }
LimitOrderCreateOperation extends BaseOperation { @Override public byte[] toBytes() { byte[] feeBytes = this.fee.toBytes(); byte[] sellerBytes = this.seller.toBytes(); byte[] amountBytes = this.amountToSell.toBytes(); byte[] minAmountBytes = this.minToReceive.toBytes(); ByteBuffer buffer = ByteBuffer.allocate(EXPIRATION_BYTE_LENGTH); buffer.putInt(this.expiration); byte[] expirationBytes = Util.revertBytes(buffer.array()); byte[] fillOrKill = this.fillOrKill ? new byte[]{ 0x1 } : new byte[]{ 0x0 }; byte[] extensions = this.extensions.toBytes(); return Bytes.concat(feeBytes, sellerBytes, amountBytes, minAmountBytes, expirationBytes, fillOrKill, extensions); } LimitOrderCreateOperation(UserAccount seller, AssetAmount toSell, AssetAmount minToReceive, int expiration, boolean fillOrKill); }
LimitOrderCreateOperation extends BaseOperation { @Override public byte[] toBytes() { byte[] feeBytes = this.fee.toBytes(); byte[] sellerBytes = this.seller.toBytes(); byte[] amountBytes = this.amountToSell.toBytes(); byte[] minAmountBytes = this.minToReceive.toBytes(); ByteBuffer buffer = ByteBuffer.allocate(EXPIRATION_BYTE_LENGTH); buffer.putInt(this.expiration); byte[] expirationBytes = Util.revertBytes(buffer.array()); byte[] fillOrKill = this.fillOrKill ? new byte[]{ 0x1 } : new byte[]{ 0x0 }; byte[] extensions = this.extensions.toBytes(); return Bytes.concat(feeBytes, sellerBytes, amountBytes, minAmountBytes, expirationBytes, fillOrKill, extensions); } LimitOrderCreateOperation(UserAccount seller, AssetAmount toSell, AssetAmount minToReceive, int expiration, boolean fillOrKill); @Override String toJsonString(); @Override JsonElement toJsonObject(); @Override void setFee(AssetAmount assetAmount); AssetAmount getFee(); UserAccount getSeller(); void setSeller(UserAccount seller); AssetAmount getAmountToSell(); void setAmountToSell(AssetAmount amountToSell); AssetAmount getMinToReceive(); void setMinToReceive(AssetAmount minToReceive); int getExpiration(); void setExpiration(int expiration); boolean isFillOrKill(); void setFillOrKill(boolean fillOrKill); @Override byte[] toBytes(); }
LimitOrderCreateOperation extends BaseOperation { @Override public byte[] toBytes() { byte[] feeBytes = this.fee.toBytes(); byte[] sellerBytes = this.seller.toBytes(); byte[] amountBytes = this.amountToSell.toBytes(); byte[] minAmountBytes = this.minToReceive.toBytes(); ByteBuffer buffer = ByteBuffer.allocate(EXPIRATION_BYTE_LENGTH); buffer.putInt(this.expiration); byte[] expirationBytes = Util.revertBytes(buffer.array()); byte[] fillOrKill = this.fillOrKill ? new byte[]{ 0x1 } : new byte[]{ 0x0 }; byte[] extensions = this.extensions.toBytes(); return Bytes.concat(feeBytes, sellerBytes, amountBytes, minAmountBytes, expirationBytes, fillOrKill, extensions); } LimitOrderCreateOperation(UserAccount seller, AssetAmount toSell, AssetAmount minToReceive, int expiration, boolean fillOrKill); @Override String toJsonString(); @Override JsonElement toJsonObject(); @Override void setFee(AssetAmount assetAmount); AssetAmount getFee(); UserAccount getSeller(); void setSeller(UserAccount seller); AssetAmount getAmountToSell(); void setAmountToSell(AssetAmount amountToSell); AssetAmount getMinToReceive(); void setMinToReceive(AssetAmount minToReceive); int getExpiration(); void setExpiration(int expiration); boolean isFillOrKill(); void setFillOrKill(boolean fillOrKill); @Override byte[] toBytes(); static final String KEY_SELLER; static final String KEY_AMOUNT_TO_SELL; static final String KEY_MIN_TO_RECEIVE; static final String KEY_EXPIRATION; static final String KEY_FILL_OR_KILL; }