diff --git a/src/main/java/com/casper/sdk/model/clvalue/AbstractCLValue.java b/src/main/java/com/casper/sdk/model/clvalue/AbstractCLValue.java index e2b62bf18..e032ab679 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/AbstractCLValue.java +++ b/src/main/java/com/casper/sdk/model/clvalue/AbstractCLValue.java @@ -49,17 +49,17 @@ public T getValue() { return this.value; } - public void setValue(T value) throws ValueSerializationException { + public void setValue(final T value) throws ValueSerializationException { this.value = value; this.serialize(new SerializerBuffer()); } - public static AbstractCLValue createInstanceFromBytes(DeserializerBuffer deser) throws ValueDeserializationException { - int length = deser.readI32(); - byte[] bytes = deser.readByteArray(length); - byte clType = deser.readU8(); + public static AbstractCLValue createInstanceFromBytes(final DeserializerBuffer deser) throws ValueDeserializationException { + final int length = deser.readI32(); + final byte[] bytes = deser.readByteArray(length); + final byte clType = deser.readU8(); try { - AbstractCLValue clValue = CLTypeData.getTypeBySerializationTag(clType).getClazz().getDeclaredConstructor().newInstance(); + final AbstractCLValue clValue = CLTypeData.getTypeBySerializationTag(clType).getClazz().getDeclaredConstructor().newInstance(); clValue.deserializeCustom(new DeserializerBuffer(Hex.encode(bytes))); return clValue; } catch (Exception e) { @@ -71,7 +71,7 @@ public void setValue(T value) throws ValueSerializationException { @JsonGetter(value = "bytes") @ExcludeFromJacocoGeneratedReport protected String getJsonBytes() { - SerializerBuffer ser = new SerializerBuffer(); + final SerializerBuffer ser = new SerializerBuffer(); this.serialize(ser, Target.JSON); this.bytes = ByteUtils.encodeHexString(ser.toByteArray()); @@ -82,10 +82,10 @@ protected String getJsonBytes() { @SneakyThrows({ValueDeserializationException.class}) @JsonSetter(value = "bytes") @ExcludeFromJacocoGeneratedReport - protected void setJsonBytes(String bytes) { + protected void setJsonBytes(final String bytes) { this.bytes = bytes; - DeserializerBuffer deser = new DeserializerBuffer(this.bytes); + final DeserializerBuffer deser = new DeserializerBuffer(this.bytes); this.deserialize(deser); } @@ -96,15 +96,15 @@ protected void setJsonBytes(String bytes) { public abstract void setClType(P value); - protected void serializePrefixWithLength(SerializerBuffer ser) throws ValueSerializationException { - SerializerBuffer localSer = new SerializerBuffer(); + protected void serializePrefixWithLength(final SerializerBuffer ser) throws ValueSerializationException { + final SerializerBuffer localSer = new SerializerBuffer(); serialize(localSer); - int size = localSer.toByteArray().length; + final int size = localSer.toByteArray().length; ser.writeI32(size); } @Override - public AbstractCLValue deserialize(DeserializerBuffer deser, Target target) throws ValueDeserializationException { + public AbstractCLValue deserialize(final DeserializerBuffer deser, final Target target) throws ValueDeserializationException { if (target.equals(Target.BYTE)) { return AbstractCLValue.createInstanceFromBytes(deser); } else { @@ -114,7 +114,7 @@ protected void serializePrefixWithLength(SerializerBuffer ser) throws ValueSeria } @Override - public void serialize(SerializerBuffer ser, Target target) throws ValueSerializationException, NoSuchTypeException { + public void serialize(final SerializerBuffer ser, final Target target) throws ValueSerializationException, NoSuchTypeException { if (this.getValue() == null) return; if (target.equals(Target.BYTE)) { @@ -128,13 +128,12 @@ public void serialize(SerializerBuffer ser, Target target) throws ValueSerializa } } - protected abstract void serializeValue(final SerializerBuffer ser) throws ValueSerializationException; - public abstract void deserializeCustom(DeserializerBuffer deserializerBuffer) throws Exception; + public abstract void deserializeCustom(final DeserializerBuffer deserializerBuffer) throws Exception; @Override - public void deserialize(DeserializerBuffer deserializerBuffer) throws ValueDeserializationException { + public void deserialize(final DeserializerBuffer deserializerBuffer) throws ValueDeserializationException { try { this.deserializeCustom(deserializerBuffer); } catch (Exception e) { @@ -142,8 +141,8 @@ public void deserialize(DeserializerBuffer deserializerBuffer) throws ValueDeser } } - protected void encodeType(SerializerBuffer ser) throws NoSuchTypeException { - byte typeTag = (getClType().getClTypeData().getSerializationTag()); + protected void encodeType(final SerializerBuffer ser) throws NoSuchTypeException { + final byte typeTag = (getClType().getClTypeData().getSerializationTag()); ser.writeU8(typeTag); } } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueAny.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueAny.java index b52758bd4..aa2cc9919 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueAny.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueAny.java @@ -1,9 +1,7 @@ package com.casper.sdk.model.clvalue; import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; -import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypeAny; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -49,14 +47,13 @@ public CLValueAny(final byte[] value) throws ValueSerializationException { } @Override - protected void serializeValue(SerializerBuffer ser) throws ValueSerializationException { + protected void serializeValue(final SerializerBuffer ser) throws ValueSerializationException { ser.writeByteArray(this.getValue()); this.setBytes(Hex.toHexString(this.getValue())); } @Override - public void deserializeCustom(final DeserializerBuffer deser) - throws Exception { + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { this.setValue(deser.readByteArray(deser.getBuffer().remaining())); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueBool.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueBool.java index 8ed607e0e..b9a958f17 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueBool.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueBool.java @@ -1,9 +1,7 @@ package com.casper.sdk.model.clvalue; import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; -import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypeBool; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -14,7 +12,6 @@ import lombok.NoArgsConstructor; import lombok.Setter; import org.bouncycastle.util.encoders.Hex; -import org.jetbrains.annotations.NotNull; /** * Casper Bool CLValue implementation @@ -33,7 +30,7 @@ public class CLValueBool extends AbstractCLValue { @JsonSetter("cl_type") @ExcludeFromJacocoGeneratedReport - protected void setJsonClType(CLTypeBool clType) { + protected void setJsonClType(final CLTypeBool clType) { this.clType = clType; } @@ -43,18 +40,18 @@ protected String getJsonClType() { return this.getClType().getTypeName(); } - public CLValueBool(Boolean value) throws ValueSerializationException { + public CLValueBool(final Boolean value) throws ValueSerializationException { this.setValue(value); } @Override - protected void serializeValue(SerializerBuffer ser) throws ValueSerializationException { + protected void serializeValue(final SerializerBuffer ser) throws ValueSerializationException { ser.writeBool(this.getValue()); this.setBytes(Hex.toHexString(ser.toByteArray())); } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { this.setValue(deser.readBool()); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueByteArray.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueByteArray.java index 2575722d0..1d960d98e 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueByteArray.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueByteArray.java @@ -3,7 +3,6 @@ import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypeByteArray; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonProperty; import dev.oak3.sbs4j.DeserializerBuffer; import dev.oak3.sbs4j.SerializerBuffer; @@ -32,25 +31,25 @@ public class CLValueByteArray extends AbstractCLValue { @JsonProperty("cl_type") private CLTypeByteArray clType = new CLTypeByteArray(); - public CLValueByteArray(byte[] value) throws ValueSerializationException { + public CLValueByteArray(final byte[] value) throws ValueSerializationException { this.setValue(value); this.clType.setLength(value.length); } @Override - protected void serializeValue(SerializerBuffer ser) throws ValueSerializationException { + protected void serializeValue(final SerializerBuffer ser) throws ValueSerializationException { ser.writeByteArray(this.getValue()); - this.setBytes(Hex.toHexString(ser.toByteArray())); + this.setBytes(Hex.toHexString(getValue())); } @Override - protected void encodeType(SerializerBuffer ser) throws NoSuchTypeException { + protected void encodeType(final SerializerBuffer ser) throws NoSuchTypeException { super.encodeType(ser); ser.writeI32(this.getClType().getLength()); } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { this.setValue(deser.readByteArray(this.getClType().getLength())); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueI32.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueI32.java index ee582d2d1..a76fe520d 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueI32.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueI32.java @@ -38,13 +38,13 @@ protected String getJsonClType() { return this.getClType().getTypeName(); } - public CLValueI32(Integer value) throws ValueSerializationException { + public CLValueI32(final Integer value) throws ValueSerializationException { this.setValue(value); } @Override - protected void serializeValue(SerializerBuffer ser) throws ValueSerializationException { - final SerializerBuffer serVal = new SerializerBuffer(); + protected void serializeValue(final SerializerBuffer ser) throws ValueSerializationException { + final SerializerBuffer serVal = new SerializerBuffer(); serVal.writeI32(this.getValue()); final byte[] bytes = serVal.toByteArray(); ser.writeByteArray(bytes); @@ -52,7 +52,7 @@ protected void serializeValue(SerializerBuffer ser) throws ValueSerializationExc } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { this.setValue(deser.readI32()); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueI64.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueI64.java index 1175da463..033ebf2e5 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueI64.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueI64.java @@ -1,9 +1,7 @@ package com.casper.sdk.model.clvalue; import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; -import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypeI64; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -32,7 +30,7 @@ public class CLValueI64 extends AbstractCLValue { @JsonSetter("cl_type") @ExcludeFromJacocoGeneratedReport - protected void setJsonClType(CLTypeI64 clType) { + protected void setJsonClType(final CLTypeI64 clType) { this.clType = clType; } @@ -42,20 +40,21 @@ protected String getJsonClType() { return this.getClType().getTypeName(); } - public CLValueI64(Long value) throws ValueSerializationException { + public CLValueI64(final Long value) throws ValueSerializationException { this.setValue(value); } @Override - protected void serializeValue(SerializerBuffer ser) throws ValueSerializationException { - ser.writeI64(this.getValue()); + protected void serializeValue(final SerializerBuffer ser) throws ValueSerializationException { final SerializerBuffer serVal = new SerializerBuffer(); serVal.writeI64(this.getValue()); - this.setBytes(Hex.toHexString(serVal.toByteArray())); + final byte[] bytes = serVal.toByteArray(); + ser.writeByteArray(bytes); + this.setBytes(Hex.toHexString(bytes)); } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { this.setValue(deser.readI64()); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueKey.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueKey.java index 58034cb7b..1ec98b796 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueKey.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueKey.java @@ -1,9 +1,7 @@ package com.casper.sdk.model.clvalue; import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; -import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypeKey; -import com.casper.sdk.model.clvalue.serde.Target; import com.casper.sdk.model.key.Key; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonSetter; @@ -15,7 +13,6 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.bouncycastle.util.encoders.Hex; /** * Casper Key CLValue implementation @@ -34,7 +31,7 @@ public class CLValueKey extends AbstractCLValue { @JsonSetter("cl_type") @ExcludeFromJacocoGeneratedReport - protected void setJsonClType(CLTypeKey clType) { + protected void setJsonClType(final CLTypeKey clType) { this.clType = clType; } @@ -44,7 +41,7 @@ protected String getJsonClType() { return this.getClType().getTypeName(); } - public CLValueKey(Key value) throws ValueSerializationException { + public CLValueKey(final Key value) throws ValueSerializationException { this.setValue(value); } @@ -56,7 +53,7 @@ protected void serializeValue(final SerializerBuffer ser) throws ValueSerializat } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { this.setValue(Key.fromTaggedHexString(ByteUtils.encodeHexString(deser.readByteArray(33)))); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueList.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueList.java index cc4aebc9e..d83421457 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueList.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueList.java @@ -5,7 +5,6 @@ import com.casper.sdk.model.clvalue.cltype.CLTypeData; import com.casper.sdk.model.clvalue.cltype.CLTypeList; import com.casper.sdk.model.clvalue.cltype.CLTypeMap; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -38,12 +37,12 @@ public class CLValueList extends AbstractCLValueWithChildren> value) throws ValueSerializationException { + public CLValueList(final List> value) throws ValueSerializationException { setChildTypes(value); this.setValue(value); } @@ -51,21 +50,25 @@ public CLValueList(List> value) throws ValueSeri @Override protected void serializeValue(final SerializerBuffer ser) throws ValueSerializationException { + final SerializerBuffer serVal = new SerializerBuffer(); + setChildTypes(this.getValue()); // List length is written first - CLValueI32 length = new CLValueI32(getValue().size()); - length.serialize(ser); + final CLValueI32 length = new CLValueI32(getValue().size()); + length.serialize(serVal); for (AbstractCLValue child : getValue()) { - child.serialize(ser); + child.serialize(serVal); } - this.setBytes(Hex.toHexString(ser.toByteArray())); + final byte[] bytes = serVal.toByteArray(); + ser.writeByteArray(bytes); + this.setBytes(Hex.toHexString(bytes)); } @Override - protected void encodeType(SerializerBuffer ser) throws NoSuchTypeException { + protected void encodeType(final SerializerBuffer ser) throws NoSuchTypeException { super.encodeType(ser); byte val = (getClType().getListType().getClTypeData().getSerializationTag()); @@ -73,16 +76,16 @@ protected void encodeType(SerializerBuffer ser) throws NoSuchTypeException { } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { - CLTypeData childrenType = getClType().getListType().getClTypeData(); + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { + final CLTypeData childrenType = getClType().getListType().getClTypeData(); // List length is sent first - CLValueI32 length = new CLValueI32(); + final CLValueI32 length = new CLValueI32(); length.deserializeCustom(deser); - List> list = new ArrayList<>(); + final List> list = new ArrayList<>(); for (int i = 0; i < length.getValue(); i++) { - AbstractCLValue child = CLTypeData.createCLValueFromCLTypeData(childrenType); + final AbstractCLValue child = CLTypeData.createCLValueFromCLTypeData(childrenType); if (child.getClType() instanceof CLTypeMap) { ((CLTypeMap) child.getClType()) .setKeyValueTypes(((CLTypeMap) clType.getListType()).getKeyValueTypes()); @@ -98,7 +101,7 @@ public void deserializeCustom(DeserializerBuffer deser) throws Exception { } @Override - protected void setChildTypes(List> value) { + protected void setChildTypes(final List> value) { if (!value.isEmpty()) { clType.setListType(value.get(0).getClType()); } else { diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueMap.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueMap.java index fd8da6e00..1b670fc5c 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueMap.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueMap.java @@ -44,48 +44,54 @@ public void setClType(CLTypeMap clType) { childTypesSet(); } - public CLValueMap(Map, ? extends AbstractCLValue> value) throws ValueSerializationException { + public CLValueMap(final Map, ? extends AbstractCLValue> value) throws ValueSerializationException { setChildTypes(value); this.setValue(value); } @Override - protected void serializeValue(SerializerBuffer ser) throws ValueSerializationException { + protected void serializeValue(final SerializerBuffer ser) throws ValueSerializationException { + + final SerializerBuffer serVal = new SerializerBuffer(); + setChildTypes(this.getValue()); - CLValueI32 mapLength = new CLValueI32(getValue().size()); - mapLength.serialize(ser); + final CLValueI32 mapLength = new CLValueI32(getValue().size()); + mapLength.serialize(serVal); for (Entry, ? extends AbstractCLValue> entry : getValue().entrySet()) { - entry.getKey().serialize(ser); - entry.getValue().serialize(ser); + entry.getKey().serialize(serVal); + entry.getValue().serialize(serVal); } - this.setBytes(Hex.toHexString(ser.toByteArray())); + + final byte[] bytes = serVal.toByteArray(); + ser.writeByteArray(bytes); + this.setBytes(Hex.toHexString(bytes)); } @Override - protected void encodeType(SerializerBuffer ser) throws NoSuchTypeException { + protected void encodeType(final SerializerBuffer ser) throws NoSuchTypeException { super.encodeType(ser); - byte keyTypeTag = (getClType().getKeyValueTypes().getKeyType().getClTypeData().getSerializationTag()); + final byte keyTypeTag = (getClType().getKeyValueTypes().getKeyType().getClTypeData().getSerializationTag()); ser.writeU8(keyTypeTag); - byte valueTypeTag = (getClType().getKeyValueTypes().getValueType().getClTypeData().getSerializationTag()); + final byte valueTypeTag = (getClType().getKeyValueTypes().getValueType().getClTypeData().getSerializationTag()); ser.writeU8(valueTypeTag); } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { - CLTypeData keyType = clType.getKeyValueTypes().getKeyType().getClTypeData(); - CLTypeData valType = clType.getKeyValueTypes().getValueType().getClTypeData(); + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { + final CLTypeData keyType = clType.getKeyValueTypes().getKeyType().getClTypeData(); + final CLTypeData valType = clType.getKeyValueTypes().getValueType().getClTypeData(); - Map, AbstractCLValue> map = new LinkedHashMap<>(); - CLValueI32 mapLength = new CLValueI32(0); + final Map, AbstractCLValue> map = new LinkedHashMap<>(); + final CLValueI32 mapLength = new CLValueI32(0); mapLength.deserializeCustom(deser); for (int i = 0; i < mapLength.getValue(); i++) { - AbstractCLValue key = CLTypeData.createCLValueFromCLTypeData(keyType); + final AbstractCLValue key = CLTypeData.createCLValueFromCLTypeData(keyType); if (key.getClType() instanceof AbstractCLTypeWithChildren) { ((AbstractCLTypeWithChildren) key.getClType()) .setChildTypes( @@ -93,7 +99,7 @@ public void deserializeCustom(DeserializerBuffer deser) throws Exception { } key.deserializeCustom(deser); - AbstractCLValue val = CLTypeData.createCLValueFromCLTypeData(valType); + final AbstractCLValue val = CLTypeData.createCLValueFromCLTypeData(valType); if (val.getClType() instanceof CLTypeMap) { ((CLTypeMap) val.getClType()) @@ -113,9 +119,9 @@ public void deserializeCustom(DeserializerBuffer deser) throws Exception { @Override @JsonIgnore - protected void setChildTypes(Map, ? extends AbstractCLValue> value) { + protected void setChildTypes(final Map, ? extends AbstractCLValue> value) { if (value != null && value.entrySet().iterator().hasNext()) { - Entry, ? extends AbstractCLValue> entry = value.entrySet().iterator().next(); + final Entry, ? extends AbstractCLValue> entry = value.entrySet().iterator().next(); clType.setKeyValueTypes(new CLTypeMap.CLTypeMapEntryType(entry.getKey().getClType(), entry.getValue().getClType())); } else { clType.setChildTypes(new ArrayList<>()); diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueOption.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueOption.java index f13554d58..8d22607dc 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueOption.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueOption.java @@ -36,31 +36,23 @@ public class CLValueOption extends AbstractCLValueWithChildren> value) throws ValueSerializationException { + public CLValueOption(final Optional> value) throws ValueSerializationException { setChildTypes(value); this.setValue(value); } @Override - public void serialize(SerializerBuffer ser, Target target) throws ValueSerializationException, NoSuchTypeException { - if (!this.getValue().isPresent()) return; + public void serialize(final SerializerBuffer ser, final Target target) throws ValueSerializationException, NoSuchTypeException { - if (target.equals(Target.BYTE)) { - super.serializePrefixWithLength(ser); - } - - Optional> child = getValue(); - - this.serializeValue(ser); + super.serialize(ser, target); - // FIXME TIDY THIS UP if (target.equals(Target.BYTE)) { - this.encodeType(ser); + Optional> child = getValue(); if (child.isPresent()) { child.get().encodeType(ser); } @@ -68,34 +60,35 @@ public void serialize(SerializerBuffer ser, Target target) throws ValueSerializa } @Override - protected void serializeValue(SerializerBuffer ser) throws ValueSerializationException { - Optional> value = getValue(); + protected void serializeValue(final SerializerBuffer ser) throws ValueSerializationException { - CLValueBool isPresent = new CLValueBool(value.isPresent() && value.get().getValue() != null); - isPresent.serialize(ser); + final SerializerBuffer serVal = new SerializerBuffer(); + final Optional> value = getValue(); - // FIXME Duplication of getValue() - Optional> child = getValue(); + final CLValueBool isPresent = new CLValueBool(value.isPresent() && value.get().getValue() != null); + isPresent.serialize(serVal); - if (child.isPresent() && child.get().getClType() instanceof AbstractCLTypeWithChildren) { - ((AbstractCLTypeWithChildren) child.get().getClType()) + if (value.isPresent() && value.get().getClType() instanceof AbstractCLTypeWithChildren) { + ((AbstractCLTypeWithChildren) value.get().getClType()) .setChildTypes(((AbstractCLTypeWithChildren) clType.getOptionType()).getChildTypes()); } - if (child.isPresent() && isPresent.getValue().equals(Boolean.TRUE)) { - child.get().serialize(ser); + if (value.isPresent() && isPresent.getValue().equals(Boolean.TRUE)) { + value.get().serialize(serVal); } - this.setBytes(Hex.toHexString(ser.toByteArray())); + final byte[] bytes = serVal.toByteArray(); + ser.writeByteArray(bytes); + this.setBytes(Hex.toHexString(bytes)); } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { - CLValueBool isPresent = new CLValueBool(); + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { + final CLValueBool isPresent = new CLValueBool(); isPresent.deserializeCustom(deser); - CLTypeData childTypeData = clType.getOptionType().getClTypeData(); + final CLTypeData childTypeData = clType.getOptionType().getClTypeData(); - AbstractCLValue child = CLTypeData.createCLValueFromCLTypeData(childTypeData); + final AbstractCLValue child = CLTypeData.createCLValueFromCLTypeData(childTypeData); if (child.getClType() instanceof CLTypeList) { ((CLTypeList) child.getClType()) @@ -113,7 +106,7 @@ public void deserializeCustom(DeserializerBuffer deser) throws Exception { } @Override - protected void setChildTypes(Optional> value) { + protected void setChildTypes(final Optional> value) { if (value.isPresent()) { clType.setOptionType(value.get().getClType()); } else { diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValuePublicKey.java b/src/main/java/com/casper/sdk/model/clvalue/CLValuePublicKey.java index 3d537a0a5..6741669c8 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValuePublicKey.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValuePublicKey.java @@ -1,9 +1,7 @@ package com.casper.sdk.model.clvalue; import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; -import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypePublicKey; -import com.casper.sdk.model.clvalue.serde.Target; import com.casper.sdk.model.key.PublicKey; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonSetter; @@ -33,7 +31,7 @@ public class CLValuePublicKey extends AbstractCLValue ok, AbstractCLValue err) throws ValueSerializationException { + public CLValueResult(final AbstractCLValue ok, final AbstractCLValue err) throws ValueSerializationException { setChildTypes(ok, err); this.setValue(new Result(ok, err)); } @@ -56,29 +54,31 @@ public CLValueResult(AbstractCLValue ok, AbstractCLValue err) throws protected void serializeValue(final SerializerBuffer ser) throws ValueSerializationException { setChildTypes(this.getValue().getOk(), this.getValue().getErr()); - SerializerBuffer serValue = new SerializerBuffer(); + SerializerBuffer serVal = new SerializerBuffer(); CLValueBool clValueTrue = new CLValueBool(true); - clValueTrue.serialize(ser); + clValueTrue.serialize(serVal); - getValue().getOk().serialize(ser); + getValue().getOk().serialize(serVal); CLValueBool clValueFalse = new CLValueBool(false); - clValueFalse.serialize(ser); + clValueFalse.serialize(serVal); - getValue().getErr().serialize(ser); + getValue().getErr().serialize(serVal); - // FIXME This cannot use ser when is nested - this.setBytes(Hex.toHexString(ser.toByteArray())); + final byte[] bytes = serVal.toByteArray(); + ser.writeByteArray(bytes); + + this.setBytes(Hex.toHexString(bytes)); } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { - Result result = new Result(); + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { + final Result result = new Result(); CLValueBool bool = new CLValueBool(); bool.setValue(deser.readBool()); - CLTypeData typeOk = clType.getOkErrTypes().getOkClType().getClTypeData(); - AbstractCLValue clValueOk = CLTypeData.createCLValueFromCLTypeData(typeOk); + final CLTypeData typeOk = clType.getOkErrTypes().getOkClType().getClTypeData(); + final AbstractCLValue clValueOk = CLTypeData.createCLValueFromCLTypeData(typeOk); if (clValueOk.getClType() instanceof AbstractCLTypeWithChildren) { ((AbstractCLTypeWithChildren) clValueOk.getClType()).getChildTypes() .addAll(((AbstractCLTypeWithChildren) clType.getOkErrTypes().getOkClType()).getChildTypes()); @@ -88,8 +88,8 @@ public void deserializeCustom(DeserializerBuffer deser) throws Exception { bool = new CLValueBool(); bool.deserializeCustom(deser); - CLTypeData typeErr = clType.getOkErrTypes().getErrClType().getClTypeData(); - AbstractCLValue clValueErr = CLTypeData.createCLValueFromCLTypeData(typeErr); + final CLTypeData typeErr = clType.getOkErrTypes().getErrClType().getClTypeData(); + final AbstractCLValue clValueErr = CLTypeData.createCLValueFromCLTypeData(typeErr); if (clValueErr.getClType() instanceof AbstractCLTypeWithChildren) { ((AbstractCLTypeWithChildren) clValueErr.getClType()).getChildTypes() .addAll(((AbstractCLTypeWithChildren) clType.getOkErrTypes().getErrClType()).getChildTypes()); @@ -100,7 +100,7 @@ public void deserializeCustom(DeserializerBuffer deser) throws Exception { setValue(result); } - protected void setChildTypes(AbstractCLValue ok, AbstractCLValue err) { + protected void setChildTypes(final AbstractCLValue ok, AbstractCLValue err) { clType.setOkErrTypes( new CLTypeResult.CLTypeResultOkErrTypes(ok.getClType(), err.getClType())); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueString.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueString.java index 3f4218e02..d042b4921 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueString.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueString.java @@ -1,9 +1,7 @@ package com.casper.sdk.model.clvalue; import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; -import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypeString; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -32,7 +30,7 @@ public class CLValueString extends AbstractCLValue { @JsonSetter("cl_type") @ExcludeFromJacocoGeneratedReport - protected void setJsonClType(CLTypeString clType) { + protected void setJsonClType(final CLTypeString clType) { this.clType = clType; } @@ -42,21 +40,21 @@ protected String getJsonClType() { return this.getClType().getTypeName(); } - public CLValueString(String value) throws ValueSerializationException { + public CLValueString(final String value) throws ValueSerializationException { this.setValue(value); } @Override - protected void serializeValue(SerializerBuffer ser) throws ValueSerializationException { + protected void serializeValue(final SerializerBuffer ser) throws ValueSerializationException { final SerializerBuffer serVal = new SerializerBuffer(); serVal.writeString(this.getValue()); - byte[] bytes = serVal.toByteArray(); - ser.writeByteArray(bytes); - this.setBytes(Hex.toHexString(bytes)); + final byte[] bytes = serVal.toByteArray(); + ser.writeByteArray(bytes); + this.setBytes(Hex.toHexString(bytes)); } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { this.setValue(deser.readString()); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueTuple1.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueTuple1.java index 82bdc98ba..7fa5edc87 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueTuple1.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueTuple1.java @@ -4,7 +4,6 @@ import com.casper.sdk.model.clvalue.cltype.AbstractCLTypeWithChildren; import com.casper.sdk.model.clvalue.cltype.CLTypeData; import com.casper.sdk.model.clvalue.cltype.CLTypeTuple1; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -18,7 +17,7 @@ import org.javatuples.Unit; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; /** * Casper Tuple1 CLValue implementation @@ -37,26 +36,28 @@ public class CLValueTuple1 extends AbstractCLValueWithChildren> value) throws ValueSerializationException { + public CLValueTuple1(final Unit> value) throws ValueSerializationException { setChildTypes(value); this.setValue(value); } @Override - protected void serializeValue(SerializerBuffer ser) throws ValueSerializationException { + protected void serializeValue(final SerializerBuffer ser) throws ValueSerializationException { + final SerializerBuffer serVal = new SerializerBuffer(); setChildTypes(this.getValue()); - getValue().getValue0().serialize(ser); - // FIXME don't use ser as it can contain parent data - this.setBytes(Hex.toHexString(ser.toByteArray())); + getValue().getValue0().serialize(serVal); + final byte[] bytes = serVal.toByteArray(); + ser.writeByteArray(bytes); + this.setBytes(Hex.toHexString(bytes)); } @Override - protected void encodeType(SerializerBuffer ser) throws NoSuchTypeException { + protected void encodeType(final SerializerBuffer ser) throws NoSuchTypeException { super.encodeType(ser); byte element0TypeTag = getClType().getChildClTypeData(0).getSerializationTag(); @@ -64,7 +65,7 @@ protected void encodeType(SerializerBuffer ser) throws NoSuchTypeException { } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { CLTypeData childTypeData1 = clType.getChildClTypeData(0); AbstractCLValue child1 = CLTypeData.createCLValueFromCLTypeData(childTypeData1); @@ -78,9 +79,9 @@ public void deserializeCustom(DeserializerBuffer deser) throws Exception { } @Override - protected void setChildTypes(Unit> value) { + protected void setChildTypes(final Unit> value) { if (value.getValue0() != null) { - clType.setChildTypes(Arrays.asList(value.getValue0().getClType())); + clType.setChildTypes(Collections.singletonList(value.getValue0().getClType())); } else { clType.setChildTypes(new ArrayList<>()); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueTuple2.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueTuple2.java index 6596b729a..0bd635f84 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueTuple2.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueTuple2.java @@ -4,7 +4,6 @@ import com.casper.sdk.model.clvalue.cltype.AbstractCLTypeWithChildren; import com.casper.sdk.model.clvalue.cltype.CLTypeData; import com.casper.sdk.model.clvalue.cltype.CLTypeTuple2; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -50,35 +49,39 @@ public CLValueTuple2(Pair, ? extends AbstractCLV @Override protected void serializeValue(final SerializerBuffer ser) throws ValueSerializationException { + final SerializerBuffer serVal = new SerializerBuffer(); setChildTypes(this.getValue()); - getValue().getValue0().serialize(ser); - getValue().getValue1().serialize(ser); - this.setBytes(Hex.toHexString(ser.toByteArray())); + getValue().getValue0().serialize(serVal); + getValue().getValue1().serialize(serVal); + final byte[] bytes = serVal.toByteArray(); + ser.writeByteArray(bytes); + this.setBytes(Hex.toHexString(bytes)); + } @Override - protected void encodeType(SerializerBuffer ser) throws NoSuchTypeException { + protected void encodeType(final SerializerBuffer ser) throws NoSuchTypeException { super.encodeType(ser); - byte element0TypeTag = getClType().getChildClTypeData(0).getSerializationTag(); + final byte element0TypeTag = getClType().getChildClTypeData(0).getSerializationTag(); ser.writeU8(element0TypeTag); - byte element1TypeTag = getClType().getChildClTypeData(1).getSerializationTag(); + final byte element1TypeTag = getClType().getChildClTypeData(1).getSerializationTag(); ser.writeU8(element1TypeTag); } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { - CLTypeData childTypeData1 = clType.getChildClTypeData(0); - CLTypeData childTypeData2 = clType.getChildClTypeData(1); + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { + final CLTypeData childTypeData1 = clType.getChildClTypeData(0); + final CLTypeData childTypeData2 = clType.getChildClTypeData(1); - AbstractCLValue child1 = CLTypeData.createCLValueFromCLTypeData(childTypeData1); + final AbstractCLValue child1 = CLTypeData.createCLValueFromCLTypeData(childTypeData1); if (child1.getClType() instanceof AbstractCLTypeWithChildren) { ((AbstractCLTypeWithChildren) child1.getClType()) .setChildTypes(((AbstractCLTypeWithChildren) clType.getChildTypes().get(0)).getChildTypes()); } child1.deserializeCustom(deser); - AbstractCLValue child2 = CLTypeData.createCLValueFromCLTypeData(childTypeData2); + final AbstractCLValue child2 = CLTypeData.createCLValueFromCLTypeData(childTypeData2); if (child2.getClType() instanceof AbstractCLTypeWithChildren) { ((AbstractCLTypeWithChildren) child2.getClType()) .setChildTypes(((AbstractCLTypeWithChildren) clType.getChildTypes().get(1)).getChildTypes()); @@ -89,7 +92,7 @@ public void deserializeCustom(DeserializerBuffer deser) throws Exception { } @Override - protected void setChildTypes(Pair, ? extends AbstractCLValue> value) { + protected void setChildTypes(final Pair, ? extends AbstractCLValue> value) { if (value.getValue0() != null && value.getValue1() != null) { clType.setChildTypes(Arrays.asList(value.getValue0().getClType(), value.getValue1().getClType())); } else { diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueTuple3.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueTuple3.java index 87f972c04..b48557b20 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueTuple3.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueTuple3.java @@ -4,7 +4,6 @@ import com.casper.sdk.model.clvalue.cltype.AbstractCLTypeWithChildren; import com.casper.sdk.model.clvalue.cltype.CLTypeData; import com.casper.sdk.model.clvalue.cltype.CLTypeTuple3; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -50,12 +49,14 @@ public CLValueTuple3(Triplet, ? extends Abstract @Override protected void serializeValue(SerializerBuffer ser) throws ValueSerializationException { + SerializerBuffer serVal = new SerializerBuffer(); setChildTypes(this.getValue()); - getValue().getValue0().serialize(ser); - getValue().getValue1().serialize(ser); - getValue().getValue2().serialize(ser); - // FIXME Don't use ser as it can contain parent data - this.setBytes(Hex.toHexString(ser.toByteArray())); + getValue().getValue0().serialize(serVal); + getValue().getValue1().serialize(serVal); + getValue().getValue2().serialize(serVal); + byte[] bytes = serVal.toByteArray(); + ser.writeByteArray(bytes); + this.setBytes(Hex.toHexString(bytes)); } @Override diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueU128.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueU128.java index 31f075d4f..2b35a5cfb 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueU128.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueU128.java @@ -1,9 +1,7 @@ package com.casper.sdk.model.clvalue; import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; -import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypeU128; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -34,7 +32,7 @@ public class CLValueU128 extends AbstractCLValue { @JsonSetter("cl_type") @ExcludeFromJacocoGeneratedReport - protected void setJsonClType(CLTypeU128 clType) { + protected void setJsonClType(final CLTypeU128 clType) { this.clType = clType; } @@ -44,7 +42,7 @@ protected String getJsonClType() { return this.getClType().getTypeName(); } - public CLValueU128(BigInteger value) throws ValueSerializationException { + public CLValueU128(final BigInteger value) throws ValueSerializationException { this.setValue(value); } @@ -58,7 +56,7 @@ protected void serializeValue(final SerializerBuffer ser) throws ValueSerializat } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { this.setValue(deser.readU128()); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueU256.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueU256.java index b6a12309d..e54fce9b0 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueU256.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueU256.java @@ -1,9 +1,7 @@ package com.casper.sdk.model.clvalue; import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; -import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypeU256; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -34,7 +32,7 @@ public class CLValueU256 extends AbstractCLValue { @JsonSetter("cl_type") @ExcludeFromJacocoGeneratedReport - protected void setJsonClType(CLTypeU256 clType) { + protected void setJsonClType(final CLTypeU256 clType) { this.clType = clType; } @@ -44,7 +42,7 @@ protected String getJsonClType() { return this.getClType().getTypeName(); } - public CLValueU256(BigInteger value) throws ValueSerializationException { + public CLValueU256(final BigInteger value) throws ValueSerializationException { this.setValue(value); } @@ -58,7 +56,7 @@ protected void serializeValue(final SerializerBuffer ser) throws ValueSerializat } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { this.setValue(deser.readU256()); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueU32.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueU32.java index 557adb5c0..e284228e8 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueU32.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueU32.java @@ -1,9 +1,7 @@ package com.casper.sdk.model.clvalue; import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; -import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypeU32; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -32,7 +30,7 @@ public class CLValueU32 extends AbstractCLValue { @JsonSetter("cl_type") @ExcludeFromJacocoGeneratedReport - protected void setJsonClType(CLTypeU32 clType) { + protected void setJsonClType(final CLTypeU32 clType) { this.clType = clType; } @@ -42,7 +40,7 @@ protected String getJsonClType() { return this.getClType().getTypeName(); } - public CLValueU32(Long value) throws ValueSerializationException { + public CLValueU32(final Long value) throws ValueSerializationException { this.setValue(value); } @@ -56,7 +54,7 @@ protected void serializeValue(final SerializerBuffer ser) throws ValueSerializat } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { this.setValue(deser.readU32()); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueU512.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueU512.java index e2755be1b..836255d35 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueU512.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueU512.java @@ -1,9 +1,7 @@ package com.casper.sdk.model.clvalue; import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; -import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypeU512; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -32,7 +30,7 @@ public class CLValueU512 extends AbstractCLValue { @JsonSetter("cl_type") @ExcludeFromJacocoGeneratedReport - protected void setJsonClType(CLTypeU512 clType) { + protected void setJsonClType(final CLTypeU512 clType) { this.clType = clType; } @@ -42,7 +40,7 @@ protected String getJsonClType() { return this.getClType().getTypeName(); } - public CLValueU512(BigInteger value) throws ValueSerializationException { + public CLValueU512(final BigInteger value) throws ValueSerializationException { this.setValue(value); } @@ -56,7 +54,7 @@ protected void serializeValue(final SerializerBuffer ser) throws ValueSerializat } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { this.setValue(deser.readU512()); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueU64.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueU64.java index d27516bd8..9bd45284a 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueU64.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueU64.java @@ -1,9 +1,7 @@ package com.casper.sdk.model.clvalue; import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; -import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypeU64; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -32,7 +30,7 @@ public class CLValueU64 extends AbstractCLValue { @JsonSetter("cl_type") @ExcludeFromJacocoGeneratedReport - protected void setJsonClType(CLTypeU64 clType) { + protected void setJsonClType(final CLTypeU64 clType) { this.clType = clType; } @@ -42,7 +40,7 @@ protected String getJsonClType() { return this.getClType().getTypeName(); } - public CLValueU64(BigInteger value) throws ValueSerializationException { + public CLValueU64(final BigInteger value) throws ValueSerializationException { this.setValue(value); } @@ -56,7 +54,7 @@ protected void serializeValue(final SerializerBuffer ser) throws ValueSerializat } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { this.setValue(deser.readU64()); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueU8.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueU8.java index b11aa8ca3..9c136d7e3 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueU8.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueU8.java @@ -1,9 +1,7 @@ package com.casper.sdk.model.clvalue; import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; -import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypeU8; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -32,7 +30,7 @@ public class CLValueU8 extends AbstractCLValue { @JsonSetter("cl_type") @ExcludeFromJacocoGeneratedReport - protected void setJsonClType(CLTypeU8 clType) { + protected void setJsonClType(final CLTypeU8 clType) { this.clType = clType; } @@ -42,21 +40,21 @@ protected String getJsonClType() { return this.getClType().getTypeName(); } - public CLValueU8(Byte value) throws ValueSerializationException { + public CLValueU8(final Byte value) throws ValueSerializationException { this.setValue(value); } @Override - protected void serializeValue(SerializerBuffer ser) throws ValueSerializationException { + protected void serializeValue(final SerializerBuffer ser) throws ValueSerializationException { final SerializerBuffer serVal = new SerializerBuffer(); serVal.writeU8(this.getValue()); - byte[] bytes = serVal.toByteArray(); + final byte[] bytes = serVal.toByteArray(); ser.writeByteArray(bytes); this.setBytes(Hex.toHexString(bytes)); } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { this.setValue(deser.readU8()); } diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueURef.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueURef.java index 4842d25e3..be0915415 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueURef.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueURef.java @@ -1,9 +1,7 @@ package com.casper.sdk.model.clvalue; import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; -import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypeURef; -import com.casper.sdk.model.clvalue.serde.Target; import com.casper.sdk.model.uref.URef; import com.casper.sdk.model.uref.URefAccessRight; import com.fasterxml.jackson.annotation.JsonGetter; @@ -37,7 +35,7 @@ public class CLValueURef extends AbstractCLValue { private CLTypeURef clType = new CLTypeURef(); - public CLValueURef(URef value) throws ValueSerializationException { + public CLValueURef(final URef value) throws ValueSerializationException { this.setValue(value); } @@ -49,29 +47,30 @@ protected String getJsonClType() { @JsonSetter("cl_type") @ExcludeFromJacocoGeneratedReport - protected void setJsonClType(CLTypeURef clType) { + protected void setJsonClType(final CLTypeURef clType) { this.clType = clType; } - @Override - protected void serializeValue(SerializerBuffer ser) throws ValueSerializationException { - URef uref = this.getValue(); - byte[] urefByte = new byte[uref.getAddress().length + 1]; + protected void serializeValue(final SerializerBuffer ser) throws ValueSerializationException { + final SerializerBuffer serVal = new SerializerBuffer(); + final URef uref = this.getValue(); + final byte[] urefByte = new byte[uref.getAddress().length + 1]; System.arraycopy(uref.getAddress(), 0, urefByte, 0, uref.getAddress().length); urefByte[32] = uref.getAccessRight().serializationTag; - ser.writeByteArray(urefByte); - // FIXME use a value SerializerBuffer to get the bytes - this.setBytes(Hex.toHexString(ser.toByteArray())); + serVal.writeByteArray(urefByte); + final byte[] bytes = serVal.toByteArray(); + ser.writeByteArray(bytes); + this.setBytes(Hex.toHexString(bytes)); } @Override - public void deserializeCustom(DeserializerBuffer deser) throws Exception { - URef uref = new URef(); - CLValueByteArray clValueByteArray = new CLValueByteArray(new byte[32]); + public void deserializeCustom(final DeserializerBuffer deser) throws Exception { + final URef uref = new URef(); + final CLValueByteArray clValueByteArray = new CLValueByteArray(new byte[32]); clValueByteArray.deserializeCustom(deser); uref.setAddress(clValueByteArray.getValue()); - CLValueU8 serializationTag = new CLValueU8((byte) 0); + final CLValueU8 serializationTag = new CLValueU8((byte) 0); serializationTag.deserializeCustom(deser); uref.setAccessRight(URefAccessRight.getTypeBySerializationTag(serializationTag.getValue())); setValue(uref); diff --git a/src/main/java/com/casper/sdk/model/clvalue/CLValueUnit.java b/src/main/java/com/casper/sdk/model/clvalue/CLValueUnit.java index a35cc1a6c..13e3bc769 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/CLValueUnit.java +++ b/src/main/java/com/casper/sdk/model/clvalue/CLValueUnit.java @@ -1,9 +1,7 @@ package com.casper.sdk.model.clvalue; import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport; -import com.casper.sdk.exception.NoSuchTypeException; import com.casper.sdk.model.clvalue.cltype.CLTypeUnit; -import com.casper.sdk.model.clvalue.serde.Target; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonSetter; import dev.oak3.sbs4j.DeserializerBuffer; @@ -12,7 +10,6 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; -import org.bouncycastle.util.encoders.Hex; /** * Casper Unit CLValue implementation @@ -52,8 +49,6 @@ public CLValueUnit() throws ValueSerializationException { @Override protected void serializeValue(SerializerBuffer ser) throws ValueSerializationException { setBytes(UNITY_EMPTY_VALUE); - // FIXME use new SerializerBuffer() - this.setBytes(Hex.toHexString(ser.toByteArray())); } @Override diff --git a/src/main/java/com/casper/sdk/model/event/deployprocessed/DeployProcessed.java b/src/main/java/com/casper/sdk/model/event/deployprocessed/DeployProcessed.java index 048de74d9..7c34b5e14 100644 --- a/src/main/java/com/casper/sdk/model/event/deployprocessed/DeployProcessed.java +++ b/src/main/java/com/casper/sdk/model/event/deployprocessed/DeployProcessed.java @@ -33,7 +33,7 @@ public class DeployProcessed implements EventData { private Digest account; @JsonProperty("timestamp") - private String timestamp; // TODO convert to data + private String timestamp; // TODO convert to date @JsonProperty("ttl") private String ttl; diff --git a/src/main/java/com/casper/sdk/model/event/fault/Fault.java b/src/main/java/com/casper/sdk/model/event/fault/Fault.java index 2e2f6ff49..968b97616 100644 --- a/src/main/java/com/casper/sdk/model/event/fault/Fault.java +++ b/src/main/java/com/casper/sdk/model/event/fault/Fault.java @@ -26,5 +26,5 @@ public class Fault implements EventData { /** A timestamp type, representing a concrete moment in time of the fault. */ @JsonProperty("timestamp") - private String timestamp; // TODO convert to data + private String timestamp; // TODO convert to date } diff --git a/src/test/java/com/casper/sdk/model/clvalue/CLValueTests.java b/src/test/java/com/casper/sdk/model/clvalue/CLValueTests.java index e2cb8eb5a..829a4ef8c 100644 --- a/src/test/java/com/casper/sdk/model/clvalue/CLValueTests.java +++ b/src/test/java/com/casper/sdk/model/clvalue/CLValueTests.java @@ -45,12 +45,12 @@ void getTypeBySerializationTag_should_return_correct_CLTypeData() throws NoSuchT @Test void createCLTypeFromCLTypeData_should_return_correct_CLType() throws DynamicInstanceException { - assertTrue(CLTypeData.createCLTypeFromCLTypeData(CLTypeData.ANY) instanceof CLTypeAny); + assertInstanceOf(CLTypeAny.class, CLTypeData.createCLTypeFromCLTypeData(CLTypeData.ANY)); } @Test void createCLValueFromCLTypeName_should_return_correct_CLValue() throws DynamicInstanceException, NoSuchTypeException { - assertTrue(CLTypeData.createCLValueFromCLTypeName(CLTypeData.ANY.getClTypeName()) instanceof CLValueAny); + assertInstanceOf(CLValueAny.class, CLTypeData.createCLValueFromCLTypeName(CLTypeData.ANY.getClTypeName())); } @Test