@Test public void testToBytes() throws Exception { CustomOperation customOperation1 = new CustomOperation(fee, payer, operationId, requiredAuths, shortData); byte[] serialized1 = customOperation1.toBytes(); assertArrayEquals(EXPECTED_SERIALIZED_BYTES_1, serialized1); CustomOperation customOperation2 = new CustomOperation(fee, payer, operationId, requiredAuths, longData); byte[] serialized2 = customOperation2.toBytes(); assertArrayEquals(EXPECTED_SERIALIZED_BYTES_2, serialized2); }
@Override public byte[] toBytes() { byte[] feeBytes = fee.toBytes(); byte[] payerBytes = payer.toBytes(); List<Byte> requiredAuthsSerialized = new LinkedList<>(); if (this.requiredAuths != null) { for (UserAccount userAccount : this.requiredAuths) { requiredAuthsSerialized.addAll(Bytes.asList(userAccount.toBytes())); } } byte[] requiredAuthsBytes = Bytes.toArray(requiredAuthsSerialized); byte[] requiredAuthsLength = {(byte)this.requiredAuths.size()}; byte[] operationIdBytes = Util.revertShort((short)operationId); byte[] dataLength = Util.serializeLongToBytes(data.length()); byte[] dataBytes = Util.hexlify(data); return Bytes.concat(feeBytes, payerBytes, requiredAuthsLength, requiredAuthsBytes, operationIdBytes, dataLength, dataBytes); }
CustomOperation extends BaseOperation { @Override public byte[] toBytes() { byte[] feeBytes = fee.toBytes(); byte[] payerBytes = payer.toBytes(); List<Byte> requiredAuthsSerialized = new LinkedList<>(); if (this.requiredAuths != null) { for (UserAccount userAccount : this.requiredAuths) { requiredAuthsSerialized.addAll(Bytes.asList(userAccount.toBytes())); } } byte[] requiredAuthsBytes = Bytes.toArray(requiredAuthsSerialized); byte[] requiredAuthsLength = {(byte)this.requiredAuths.size()}; byte[] operationIdBytes = Util.revertShort((short)operationId); byte[] dataLength = Util.serializeLongToBytes(data.length()); byte[] dataBytes = Util.hexlify(data); return Bytes.concat(feeBytes, payerBytes, requiredAuthsLength, requiredAuthsBytes, operationIdBytes, dataLength, dataBytes); } }
CustomOperation extends BaseOperation { @Override public byte[] toBytes() { byte[] feeBytes = fee.toBytes(); byte[] payerBytes = payer.toBytes(); List<Byte> requiredAuthsSerialized = new LinkedList<>(); if (this.requiredAuths != null) { for (UserAccount userAccount : this.requiredAuths) { requiredAuthsSerialized.addAll(Bytes.asList(userAccount.toBytes())); } } byte[] requiredAuthsBytes = Bytes.toArray(requiredAuthsSerialized); byte[] requiredAuthsLength = {(byte)this.requiredAuths.size()}; byte[] operationIdBytes = Util.revertShort((short)operationId); byte[] dataLength = Util.serializeLongToBytes(data.length()); byte[] dataBytes = Util.hexlify(data); return Bytes.concat(feeBytes, payerBytes, requiredAuthsLength, requiredAuthsBytes, operationIdBytes, dataLength, dataBytes); } CustomOperation(AssetAmount fee, UserAccount payer, int operationId, List<UserAccount> requiredAuths, String data); }
CustomOperation extends BaseOperation { @Override public byte[] toBytes() { byte[] feeBytes = fee.toBytes(); byte[] payerBytes = payer.toBytes(); List<Byte> requiredAuthsSerialized = new LinkedList<>(); if (this.requiredAuths != null) { for (UserAccount userAccount : this.requiredAuths) { requiredAuthsSerialized.addAll(Bytes.asList(userAccount.toBytes())); } } byte[] requiredAuthsBytes = Bytes.toArray(requiredAuthsSerialized); byte[] requiredAuthsLength = {(byte)this.requiredAuths.size()}; byte[] operationIdBytes = Util.revertShort((short)operationId); byte[] dataLength = Util.serializeLongToBytes(data.length()); byte[] dataBytes = Util.hexlify(data); return Bytes.concat(feeBytes, payerBytes, requiredAuthsLength, requiredAuthsBytes, operationIdBytes, dataLength, dataBytes); } CustomOperation(AssetAmount fee, UserAccount payer, int operationId, List<UserAccount> requiredAuths, String data); AssetAmount getFee(); @Override void setFee(AssetAmount fee); UserAccount getPayer(); void setPayer(UserAccount payer); List<UserAccount> getRequiredAuths(); void setRequiredAuths(List<UserAccount> requiredAuths); int getOperationId(); void setOperationId(int operationId); String getData(); void setData(String data); @Override byte[] toBytes(); @Override String toJsonString(); @Override JsonElement toJsonObject(); }
CustomOperation extends BaseOperation { @Override public byte[] toBytes() { byte[] feeBytes = fee.toBytes(); byte[] payerBytes = payer.toBytes(); List<Byte> requiredAuthsSerialized = new LinkedList<>(); if (this.requiredAuths != null) { for (UserAccount userAccount : this.requiredAuths) { requiredAuthsSerialized.addAll(Bytes.asList(userAccount.toBytes())); } } byte[] requiredAuthsBytes = Bytes.toArray(requiredAuthsSerialized); byte[] requiredAuthsLength = {(byte)this.requiredAuths.size()}; byte[] operationIdBytes = Util.revertShort((short)operationId); byte[] dataLength = Util.serializeLongToBytes(data.length()); byte[] dataBytes = Util.hexlify(data); return Bytes.concat(feeBytes, payerBytes, requiredAuthsLength, requiredAuthsBytes, operationIdBytes, dataLength, dataBytes); } CustomOperation(AssetAmount fee, UserAccount payer, int operationId, List<UserAccount> requiredAuths, String data); AssetAmount getFee(); @Override void setFee(AssetAmount fee); UserAccount getPayer(); void setPayer(UserAccount payer); List<UserAccount> getRequiredAuths(); void setRequiredAuths(List<UserAccount> requiredAuths); int getOperationId(); void setOperationId(int operationId); String getData(); void setData(String data); @Override byte[] toBytes(); @Override String toJsonString(); @Override JsonElement toJsonObject();  }