{
private CLTypeURef clType = new CLTypeURef();
- @JsonSetter("cl_type")
- @ExcludeFromJacocoGeneratedReport
- protected void setJsonClType(CLTypeURef clType) {
- this.clType = clType;
+ public CLValueURef(URef value) {
+ this.setValue(value);
}
@JsonGetter("cl_type")
@ExcludeFromJacocoGeneratedReport
- protected String getJsonClType() {
+ protected String getJsonClType() {
return this.getClType().getTypeName();
}
- public CLValueURef(URef value) {
- this.setValue(value);
+ @JsonSetter("cl_type")
+ @ExcludeFromJacocoGeneratedReport
+ protected void setJsonClType(CLTypeURef clType) {
+ this.clType = clType;
}
@Override
- public void encode(CLValueEncoder clve) throws IOException {
+ public void encode(CLValueEncoder clve, boolean encodeType) throws IOException, NoSuchTypeException, CLValueEncodeException {
URef uref = this.getValue();
byte[] urefByte = new byte[uref.getAddress().length + 1];
System.arraycopy(uref.getAddress(), 0, urefByte, 0, uref.getAddress().length);
- urefByte[32] = uref.getAccessRight().serializationTag;
+ urefByte[32] = uref.getAccessRight().serializationTag;
setBytes(StringByteHelper.convertBytesToHex(urefByte));
+ if (encodeType) {
+ this.encodeType(clve);
+ }
}
@Override
@@ -94,9 +98,7 @@ public boolean equals(final Object o) {
return false;
final Object thisClType = this.getClType();
final Object otherClType = other.getClType();
- if (thisClType == null ? otherClType != null : !thisClType.equals(otherClType))
- return false;
- return true;
+ return thisClType == null ? otherClType == null : thisClType.equals(otherClType);
}
@ExcludeFromJacocoGeneratedReport
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/CLValueUnit.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/CLValueUnit.java
index f64b50cb..f8e8b339 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/CLValueUnit.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/CLValueUnit.java
@@ -1,25 +1,26 @@
package com.syntifi.casper.sdk.model.clvalue;
-import java.io.IOException;
-
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
import com.syntifi.casper.sdk.exception.CLValueDecodeException;
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
import com.syntifi.casper.sdk.model.clvalue.cltype.CLTypeUnit;
import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueDecoder;
import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
+import java.io.IOException;
+
/**
* Casper Unit CLValue implementation
- *
+ *
* Unit is singleton value without additional semantics and serializes to an
* empty byte array.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLValue
@@ -50,8 +51,11 @@ public CLValueUnit() {
}
@Override
- public void encode(CLValueEncoder clve) throws IOException {
+ public void encode(CLValueEncoder clve, boolean encodeType) throws IOException, NoSuchTypeException, CLValueEncodeException {
setBytes(UNITY_EMPTY_VALUE);
+ if (encodeType) {
+ this.encodeType(clve);
+ }
}
@Override
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/AbstractCLType.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/AbstractCLType.java
index da05bdcd..19f4d385 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/AbstractCLType.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/AbstractCLType.java
@@ -5,13 +5,12 @@
import com.fasterxml.jackson.databind.annotation.JsonTypeResolver;
import com.syntifi.casper.sdk.exception.NoSuchTypeException;
import com.syntifi.casper.sdk.jackson.resolver.CLTypeResolver;
-
import lombok.Getter;
import lombok.Setter;
/**
* Basic class for CLType implementation
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -52,7 +51,7 @@ public abstract class AbstractCLType {
/**
* Required getter for implementations of CLType
- *
+ *
* @return the CLType name
*/
@JsonIgnore
@@ -60,7 +59,7 @@ public abstract class AbstractCLType {
/**
* @return the {@link CLTypeData} for the current CLType
- * @throws NoSuchTypeException
+ * @throws NoSuchTypeException thrown if no cl type data found
*/
@JsonIgnore
public CLTypeData getClTypeData() throws NoSuchTypeException {
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/AbstractCLTypeBasic.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/AbstractCLTypeBasic.java
index ed05f1ed..e6301893 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/AbstractCLTypeBasic.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/AbstractCLTypeBasic.java
@@ -4,14 +4,14 @@
/**
* Base class for all types which are simple mappings
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@NoArgsConstructor
public abstract class AbstractCLTypeBasic extends AbstractCLType {
- protected AbstractCLTypeBasic(String typeName) {
+ protected AbstractCLTypeBasic(String typeName) {
if (!this.getTypeName().equals(typeName)) {
throw new IllegalArgumentException(
String.format("%s is an invalid type for %s", getClass().getSimpleName(), typeName));
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/AbstractCLTypeWithChildren.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/AbstractCLTypeWithChildren.java
index 70a9699c..1848c728 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/AbstractCLTypeWithChildren.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/AbstractCLTypeWithChildren.java
@@ -1,28 +1,27 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map.Entry;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.syntifi.casper.sdk.exception.NoSuchTypeException;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map.Entry;
+
/**
* Base class for all types which have an array of child types
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Setter
@Getter
-@EqualsAndHashCode(callSuper = false, of = { "childTypes" })
+@EqualsAndHashCode(callSuper = false, of = {"childTypes"})
public abstract class AbstractCLTypeWithChildren extends AbstractCLType {
@JsonIgnore
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeAny.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeAny.java
index b973a22c..1b6c21c9 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeAny.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeAny.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#ANY}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -16,7 +15,7 @@
*/
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeAny extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.ANY;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeBool.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeBool.java
index 9bfb1642..afda8484 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeBool.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeBool.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#BOOL}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -16,7 +15,7 @@
*/
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeBool extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.BOOL;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeByteArray.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeByteArray.java
index 80c27feb..6ea0de4f 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeByteArray.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeByteArray.java
@@ -1,21 +1,20 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonProperty;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
/**
* CLType for {@link AbstractCLType#BYTE_ARRAY}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
* @since 0.0.1
*/
@Getter
-@EqualsAndHashCode(callSuper = false, of = { "typeName", "length" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName", "length"})
public class CLTypeByteArray extends AbstractCLType {
private final String typeName = AbstractCLType.BYTE_ARRAY;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeData.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeData.java
index 878e7145..aa2ecab3 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeData.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeData.java
@@ -1,212 +1,211 @@
-package com.syntifi.casper.sdk.model.clvalue.cltype;
-
-import java.lang.reflect.InvocationTargetException;
-
-import com.syntifi.casper.sdk.exception.DynamicInstanceException;
-import com.syntifi.casper.sdk.exception.NoSuchTypeException;
-import com.syntifi.casper.sdk.model.clvalue.AbstractCLValue;
-import com.syntifi.casper.sdk.model.clvalue.CLValueAny;
-import com.syntifi.casper.sdk.model.clvalue.CLValueBool;
-import com.syntifi.casper.sdk.model.clvalue.CLValueByteArray;
-import com.syntifi.casper.sdk.model.clvalue.CLValueFixedList;
-import com.syntifi.casper.sdk.model.clvalue.CLValueI32;
-import com.syntifi.casper.sdk.model.clvalue.CLValueI64;
-import com.syntifi.casper.sdk.model.clvalue.CLValueKey;
-import com.syntifi.casper.sdk.model.clvalue.CLValueList;
-import com.syntifi.casper.sdk.model.clvalue.CLValueMap;
-import com.syntifi.casper.sdk.model.clvalue.CLValueOption;
-import com.syntifi.casper.sdk.model.clvalue.CLValuePublicKey;
-import com.syntifi.casper.sdk.model.clvalue.CLValueResult;
-import com.syntifi.casper.sdk.model.clvalue.CLValueString;
-import com.syntifi.casper.sdk.model.clvalue.CLValueTuple1;
-import com.syntifi.casper.sdk.model.clvalue.CLValueTuple2;
-import com.syntifi.casper.sdk.model.clvalue.CLValueTuple3;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU128;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU256;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU32;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU512;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU64;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU8;
-import com.syntifi.casper.sdk.model.clvalue.CLValueURef;
-import com.syntifi.casper.sdk.model.clvalue.CLValueUnit;
-import com.syntifi.casper.sdk.model.storedvalue.StoredValue;
-
-import lombok.AccessLevel;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-
-/**
- * Casper CLType definitions and type mappings
- *
- * All types must be listed and mapped here.
- *
- * @author Alexandre Carvalho
- * @author Andre Bertolace
- * @see StoredValue
- * @since 0.0.1
- */
-@Getter
-@AllArgsConstructor(access = AccessLevel.PRIVATE)
-public enum CLTypeData {
- BOOL(AbstractCLType.BOOL, (byte) 0x0, CLValueBool.class, CLTypeBool.class),
- I32(AbstractCLType.I32, (byte) 0x1, CLValueI32.class, CLTypeI32.class),
- I64(AbstractCLType.I64, (byte) 0x2, CLValueI64.class, CLTypeI64.class),
- U8(AbstractCLType.U8, (byte) 0x3, CLValueU8.class, CLTypeU8.class),
- U32(AbstractCLType.U32, (byte) 0x4, CLValueU32.class, CLTypeU32.class),
- U64(AbstractCLType.U64, (byte) 0x5, CLValueU64.class, CLTypeU64.class),
- U128(AbstractCLType.U128, (byte) 0x6, CLValueU128.class, CLTypeU128.class),
- U256(AbstractCLType.U256, (byte) 0x7, CLValueU256.class, CLTypeU256.class),
- U512(AbstractCLType.U512, (byte) 0x8, CLValueU512.class, CLTypeU512.class),
- UNIT(AbstractCLType.UNIT, (byte) 0x9, CLValueUnit.class, CLTypeUnit.class),
- STRING(AbstractCLType.STRING, (byte) 0x10, CLValueString.class, CLTypeString.class),
- UREF(AbstractCLType.UREF, (byte) 0x11, CLValueURef.class, CLTypeURef.class),
- KEY(AbstractCLType.KEY, (byte) 0x12, CLValueKey.class, CLTypeKey.class),
- OPTION(AbstractCLType.OPTION, (byte) 0x13, CLValueOption.class, CLTypeOption.class),
- LIST(AbstractCLType.LIST, (byte) 0x14, CLValueList.class, CLTypeList.class),
- FIXED_LIST(AbstractCLType.FIXED_LIST, (byte) 0x15, CLValueFixedList.class, CLTypeFixedList.class),
- RESULT(AbstractCLType.RESULT, (byte) 0x16, CLValueResult.class, CLTypeResult.class),
- MAP(AbstractCLType.MAP, (byte) 0x17, CLValueMap.class, CLTypeMap.class),
- TUPLE1(AbstractCLType.TUPLE1, (byte) 0x18, CLValueTuple1.class, CLTypeTuple1.class),
- TUPLE2(AbstractCLType.TUPLE2, (byte) 0x19, CLValueTuple2.class, CLTypeTuple2.class),
- TUPLE3(AbstractCLType.TUPLE3, (byte) 0x20, CLValueTuple3.class, CLTypeTuple3.class),
- ANY(AbstractCLType.ANY, (byte) 0x21, CLValueAny.class, CLTypeAny.class),
- PUBLIC_KEY(AbstractCLType.PUBLIC_KEY, (byte) 0x22, CLValuePublicKey.class, CLTypePublicKey.class),
- BYTE_ARRAY(AbstractCLType.BYTE_ARRAY, (byte) 0x23, CLValueByteArray.class, CLTypeByteArray.class);
-
- private final String clTypeName;
- private final byte serializationTag;
- private final Class extends AbstractCLValue, ?>> clazz;
- private final Class extends AbstractCLType> clTypeClass;
-
- /**
- * Retrieve CLType by its serialization tag
- *
- * @param serializationTag the serialization tag to find
- * @return the requested {@link CLTypeData}
- * @throws NoSuchTypeException raised when the clType is not valid/found
- */
- public static CLTypeData getTypeBySerializationTag(byte serializationTag) throws NoSuchTypeException {
- for (CLTypeData clType : values()) {
- if (clType.serializationTag == serializationTag) {
- return clType;
- }
- }
- throw new NoSuchTypeException();
- }
-
- /**
- * Retrieve CLValue implementation class from CLType name
- *
- * @param name the type's name
- * @return the {@link Class} object holding the requested
- * {@link AbstractCLValue}
- * @throws NoSuchTypeException raised when the clType is not valid/found
- */
- public static Class> getClassByName(String name) throws NoSuchTypeException {
- for (CLTypeData clType : values()) {
- if (clType.clTypeName.equals(name)) {
- return clType.getClazz();
- }
- }
- throw new NoSuchTypeException();
- }
-
- /**
- * Retrieve CLType class from CLType name
- *
- * @param name the type's name
- * @return the {@link Class} object holding the requested {@link AbstractCLType}
- * @throws NoSuchTypeException raised when the clType is not valid/found
- */
- public static Class> getCLTypeClassByName(String name) throws NoSuchTypeException {
- for (CLTypeData clType : values()) {
- if (clType.clTypeName.equals(name)) {
- return clType.getClTypeClass();
- }
- }
- throw new NoSuchTypeException();
- }
-
- /**
- * Retrieve CLType from its name
- *
- * @param name the type's name
- * @return the requested {@link CLTypeData}
- * @throws NoSuchTypeException raised when the clType is not valid/found
- */
- public static CLTypeData getTypeByName(String name) throws NoSuchTypeException {
- for (CLTypeData clType : values()) {
- if (clType.clTypeName.equals(name)) {
- return clType;
- }
- }
- throw new NoSuchTypeException();
- }
-
- /**
- * Dynamically instantiate a CLValue when needed for decoding children objects
- *
- * @param clValueName the name of the {@link AbstractCLValue} to instantiate
- * @return the desired {@link AbstractCLValue} implementation
- * @throws DynamicInstanceException error while dynamically instantiating the
- * clValue
- * @throws NoSuchTypeException raised when the clType is not valid/found
- */
- public static AbstractCLValue, ?> createCLValueFromCLTypeName(String clValueName)
- throws DynamicInstanceException, NoSuchTypeException {
- return CLTypeData.createCLValueFromCLTypeData(CLTypeData.getTypeByName(clValueName));
- }
-
- /**
- * Dynamically instantiate a CLValue when needed for decoding children objects
- *
- * @param clTypeData the {@link CLTypeData} to instantiate
- * @return the desired {@link AbstractCLValue} implementation
- * @throws DynamicInstanceException error while dynamically instantiating the
- * clValue
- */
- public static AbstractCLValue, ?> createCLValueFromCLTypeData(CLTypeData clTypeData)
- throws DynamicInstanceException {
- Class> clazz = clTypeData.getClazz();
-
- try {
- return (AbstractCLValue, ?>) clazz.getConstructor().newInstance();
- } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | NoSuchMethodException | SecurityException e) {
- throw new DynamicInstanceException(String.format("Error while instantiating %s", clazz.getName()), e);
- }
- }
-
- /**
- * Dynamically instantiate a CLType when needed for decoding children objects
- *
- * @param clTypeName the name of the {@link AbstractCLType} to instantiate
- * @return the desired {@link AbstractCLType} implementation
- * @throws DynamicInstanceException error while dynamically instantiating the
- * clValue
- * @throws NoSuchTypeException raised when the clType is not valid/found
- */
- public static AbstractCLType createCLTypeFromCLTypeName(String clTypeName)
- throws DynamicInstanceException, NoSuchTypeException {
- return CLTypeData.createCLTypeFromCLTypeData(CLTypeData.getTypeByName(clTypeName));
- }
-
- /**
- * Dynamically instantiate a CLType when needed for decoding children objects
- *
- * @param clTypeData the {@link CLTypeData} to instantiate
- * @return the desired {@link AbstractCLType} implementation
- * @throws DynamicInstanceException error while dynamically instantiating the
- * clValue
- */
- public static AbstractCLType createCLTypeFromCLTypeData(CLTypeData clTypeData) throws DynamicInstanceException {
- Class> clazz = clTypeData.getClTypeClass();
-
- try {
- return (AbstractCLType) clazz.getConstructor().newInstance();
- } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | NoSuchMethodException | SecurityException e) {
- throw new DynamicInstanceException(String.format("Error while instantiating %s", clazz.getName()), e);
- }
- }
-}
+package com.syntifi.casper.sdk.model.clvalue.cltype;
+
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.AbstractCLValue;
+import com.syntifi.casper.sdk.model.clvalue.CLValueAny;
+import com.syntifi.casper.sdk.model.clvalue.CLValueBool;
+import com.syntifi.casper.sdk.model.clvalue.CLValueByteArray;
+import com.syntifi.casper.sdk.model.clvalue.CLValueFixedList;
+import com.syntifi.casper.sdk.model.clvalue.CLValueI32;
+import com.syntifi.casper.sdk.model.clvalue.CLValueI64;
+import com.syntifi.casper.sdk.model.clvalue.CLValueKey;
+import com.syntifi.casper.sdk.model.clvalue.CLValueList;
+import com.syntifi.casper.sdk.model.clvalue.CLValueMap;
+import com.syntifi.casper.sdk.model.clvalue.CLValueOption;
+import com.syntifi.casper.sdk.model.clvalue.CLValuePublicKey;
+import com.syntifi.casper.sdk.model.clvalue.CLValueResult;
+import com.syntifi.casper.sdk.model.clvalue.CLValueString;
+import com.syntifi.casper.sdk.model.clvalue.CLValueTuple1;
+import com.syntifi.casper.sdk.model.clvalue.CLValueTuple2;
+import com.syntifi.casper.sdk.model.clvalue.CLValueTuple3;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU128;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU256;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU32;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU512;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU64;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU8;
+import com.syntifi.casper.sdk.model.clvalue.CLValueURef;
+import com.syntifi.casper.sdk.model.clvalue.CLValueUnit;
+import com.syntifi.casper.sdk.model.storedvalue.StoredValue;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * Casper CLType definitions and type mappings
+ *
+ * All types must be listed and mapped here.
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @see StoredValue
+ * @since 0.0.1
+ */
+@Getter
+@AllArgsConstructor(access = AccessLevel.PRIVATE)
+public enum CLTypeData {
+ BOOL(AbstractCLType.BOOL, (byte) 0x0, CLValueBool.class, CLTypeBool.class),
+ I32(AbstractCLType.I32, (byte) 0x1, CLValueI32.class, CLTypeI32.class),
+ I64(AbstractCLType.I64, (byte) 0x2, CLValueI64.class, CLTypeI64.class),
+ U8(AbstractCLType.U8, (byte) 0x3, CLValueU8.class, CLTypeU8.class),
+ U32(AbstractCLType.U32, (byte) 0x4, CLValueU32.class, CLTypeU32.class),
+ U64(AbstractCLType.U64, (byte) 0x5, CLValueU64.class, CLTypeU64.class),
+ U128(AbstractCLType.U128, (byte) 0x6, CLValueU128.class, CLTypeU128.class),
+ U256(AbstractCLType.U256, (byte) 0x7, CLValueU256.class, CLTypeU256.class),
+ U512(AbstractCLType.U512, (byte) 0x8, CLValueU512.class, CLTypeU512.class),
+ UNIT(AbstractCLType.UNIT, (byte) 0x9, CLValueUnit.class, CLTypeUnit.class),
+ STRING(AbstractCLType.STRING, (byte) 0xA, CLValueString.class, CLTypeString.class),
+ UREF(AbstractCLType.UREF, (byte) 0xB, CLValueURef.class, CLTypeURef.class),
+ KEY(AbstractCLType.KEY, (byte) 0xC, CLValueKey.class, CLTypeKey.class),
+ OPTION(AbstractCLType.OPTION, (byte) 0xD, CLValueOption.class, CLTypeOption.class),
+ LIST(AbstractCLType.LIST, (byte) 0xE, CLValueList.class, CLTypeList.class),
+ FIXED_LIST(AbstractCLType.FIXED_LIST, (byte) 0xF, CLValueFixedList.class, CLTypeFixedList.class),
+ RESULT(AbstractCLType.RESULT, (byte) 0x10, CLValueResult.class, CLTypeResult.class),
+ MAP(AbstractCLType.MAP, (byte) 0x11, CLValueMap.class, CLTypeMap.class),
+ TUPLE1(AbstractCLType.TUPLE1, (byte) 0x12, CLValueTuple1.class, CLTypeTuple1.class),
+ TUPLE2(AbstractCLType.TUPLE2, (byte) 0x13, CLValueTuple2.class, CLTypeTuple2.class),
+ TUPLE3(AbstractCLType.TUPLE3, (byte) 0x14, CLValueTuple3.class, CLTypeTuple3.class),
+ ANY(AbstractCLType.ANY, (byte) 0x15, CLValueAny.class, CLTypeAny.class),
+ PUBLIC_KEY(AbstractCLType.PUBLIC_KEY, (byte) 0x16, CLValuePublicKey.class, CLTypePublicKey.class),
+ BYTE_ARRAY(AbstractCLType.BYTE_ARRAY, (byte) 0x17, CLValueByteArray.class, CLTypeByteArray.class);
+
+ private final String clTypeName;
+ private final byte serializationTag;
+ private final Class extends AbstractCLValue, ?>> clazz;
+ private final Class extends AbstractCLType> clTypeClass;
+
+ /**
+ * Retrieve CLType by its serialization tag
+ *
+ * @param serializationTag the serialization tag to find
+ * @return the requested {@link CLTypeData}
+ * @throws NoSuchTypeException raised when the clType is not valid/found
+ */
+ public static CLTypeData getTypeBySerializationTag(byte serializationTag) throws NoSuchTypeException {
+ for (CLTypeData clType : values()) {
+ if (clType.serializationTag == serializationTag) {
+ return clType;
+ }
+ }
+ throw new NoSuchTypeException();
+ }
+
+ /**
+ * Retrieve CLValue implementation class from CLType name
+ *
+ * @param name the type's name
+ * @return the {@link Class} object holding the requested
+ * {@link AbstractCLValue}
+ * @throws NoSuchTypeException raised when the clType is not valid/found
+ */
+ public static Class> getClassByName(String name) throws NoSuchTypeException {
+ for (CLTypeData clType : values()) {
+ if (clType.clTypeName.equals(name)) {
+ return clType.getClazz();
+ }
+ }
+ throw new NoSuchTypeException();
+ }
+
+ /**
+ * Retrieve CLType class from CLType name
+ *
+ * @param name the type's name
+ * @return the {@link Class} object holding the requested {@link AbstractCLType}
+ * @throws NoSuchTypeException raised when the clType is not valid/found
+ */
+ public static Class> getCLTypeClassByName(String name) throws NoSuchTypeException {
+ for (CLTypeData clType : values()) {
+ if (clType.clTypeName.equals(name)) {
+ return clType.getClTypeClass();
+ }
+ }
+ throw new NoSuchTypeException();
+ }
+
+ /**
+ * Retrieve CLType from its name
+ *
+ * @param name the type's name
+ * @return the requested {@link CLTypeData}
+ * @throws NoSuchTypeException raised when the clType is not valid/found
+ */
+ public static CLTypeData getTypeByName(String name) throws NoSuchTypeException {
+ for (CLTypeData clType : values()) {
+ if (clType.clTypeName.equals(name)) {
+ return clType;
+ }
+ }
+ throw new NoSuchTypeException();
+ }
+
+ /**
+ * Dynamically instantiate a CLValue when needed for decoding children objects
+ *
+ * @param clValueName the name of the {@link AbstractCLValue} to instantiate
+ * @return the desired {@link AbstractCLValue} implementation
+ * @throws DynamicInstanceException error while dynamically instantiating the
+ * clValue
+ * @throws NoSuchTypeException raised when the clType is not valid/found
+ */
+ public static AbstractCLValue, ?> createCLValueFromCLTypeName(String clValueName)
+ throws DynamicInstanceException, NoSuchTypeException {
+ return CLTypeData.createCLValueFromCLTypeData(CLTypeData.getTypeByName(clValueName));
+ }
+
+ /**
+ * Dynamically instantiate a CLValue when needed for decoding children objects
+ *
+ * @param clTypeData the {@link CLTypeData} to instantiate
+ * @return the desired {@link AbstractCLValue} implementation
+ * @throws DynamicInstanceException error while dynamically instantiating the
+ * clValue
+ */
+ public static AbstractCLValue, ?> createCLValueFromCLTypeData(CLTypeData clTypeData)
+ throws DynamicInstanceException {
+ Class> clazz = clTypeData.getClazz();
+
+ try {
+ return (AbstractCLValue, ?>) clazz.getConstructor().newInstance();
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
+ | NoSuchMethodException | SecurityException e) {
+ throw new DynamicInstanceException(String.format("Error while instantiating %s", clazz.getName()), e);
+ }
+ }
+
+ /**
+ * Dynamically instantiate a CLType when needed for decoding children objects
+ *
+ * @param clTypeName the name of the {@link AbstractCLType} to instantiate
+ * @return the desired {@link AbstractCLType} implementation
+ * @throws DynamicInstanceException error while dynamically instantiating the
+ * clValue
+ * @throws NoSuchTypeException raised when the clType is not valid/found
+ */
+ public static AbstractCLType createCLTypeFromCLTypeName(String clTypeName)
+ throws DynamicInstanceException, NoSuchTypeException {
+ return CLTypeData.createCLTypeFromCLTypeData(CLTypeData.getTypeByName(clTypeName));
+ }
+
+ /**
+ * Dynamically instantiate a CLType when needed for decoding children objects
+ *
+ * @param clTypeData the {@link CLTypeData} to instantiate
+ * @return the desired {@link AbstractCLType} implementation
+ * @throws DynamicInstanceException error while dynamically instantiating the
+ * clValue
+ */
+ public static AbstractCLType createCLTypeFromCLTypeData(CLTypeData clTypeData) throws DynamicInstanceException {
+ Class> clazz = clTypeData.getClTypeClass();
+
+ try {
+ return (AbstractCLType) clazz.getConstructor().newInstance();
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
+ | NoSuchMethodException | SecurityException e) {
+ throw new DynamicInstanceException(String.format("Error while instantiating %s", clazz.getName()), e);
+ }
+ }
+}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeFixedList.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeFixedList.java
index 9abcc1ab..f04a897a 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeFixedList.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeFixedList.java
@@ -4,21 +4,20 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
/**
* CLType for {@link AbstractCLType#FIXED_LIST}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
* @since 0.0.1
*/
@Getter
-@EqualsAndHashCode(callSuper = false, of = { "typeName", "listType" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName", "listType"})
public class CLTypeFixedList extends AbstractCLType {
private final String typeName = AbstractCLType.FIXED_LIST;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeI32.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeI32.java
index 9c2e37ba..74a75783 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeI32.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeI32.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#I32}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -16,7 +15,7 @@
*/
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeI32 extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.I32;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeI64.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeI64.java
index c1bde3f8..38ba5aa8 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeI64.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeI64.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#I64}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -16,7 +15,7 @@
*/
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeI64 extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.I64;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeKey.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeKey.java
index c8ad234f..96bd5eee 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeKey.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeKey.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#KEY}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -16,7 +15,7 @@
*/
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeKey extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.KEY;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeList.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeList.java
index 972a44aa..0003b0dd 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeList.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeList.java
@@ -4,21 +4,20 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
/**
* CLType for {@link AbstractCLType#LIST}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
* @since 0.0.1
*/
@Getter
-@EqualsAndHashCode(callSuper = false, of = { "typeName", "listType" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName", "listType"})
public class CLTypeList extends AbstractCLType {
private final String typeName = AbstractCLType.LIST;
@@ -28,13 +27,13 @@ public class CLTypeList extends AbstractCLType {
@JsonSetter(AbstractCLType.LIST)
@ExcludeFromJacocoGeneratedReport
- protected void setJsonValue(AbstractCLType clType) {
+ protected void setJsonValue(AbstractCLType clType) {
this.listType = clType;
}
@JsonGetter(AbstractCLType.LIST)
@ExcludeFromJacocoGeneratedReport
- protected Object getJsonValue() {
+ protected Object getJsonValue() {
if (this.listType instanceof AbstractCLTypeBasic) {
return this.listType.getTypeName();
} else {
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeMap.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeMap.java
index a1a62b4e..d76f938a 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeMap.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeMap.java
@@ -5,9 +5,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
-
import lombok.AllArgsConstructor;
-import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -15,27 +13,29 @@
/**
* CLType for {@link AbstractCLType#MAP}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
* @since 0.0.1
*/
@Getter
-@EqualsAndHashCode(callSuper = false, of = { "typeName", "keyValueTypes" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName", "keyValueTypes"})
public class CLTypeMap extends AbstractCLType {
/**
* Support class for {@link AbstractCLType#MAP} entry types
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
* @since 0.0.1
*/
- @Data
+ @Getter
+ @Setter
+ @EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
- public class CLTypeMapEntryType {
+ public static class CLTypeMapEntryType {
@JsonIgnore
private AbstractCLType keyType;
@JsonIgnore
@@ -43,13 +43,13 @@ public class CLTypeMapEntryType {
@JsonSetter("key")
@ExcludeFromJacocoGeneratedReport
- protected void setJsonKey(AbstractCLType clType) {
+ protected void setJsonKey(AbstractCLType clType) {
this.keyType = clType;
}
@JsonGetter("key")
@ExcludeFromJacocoGeneratedReport
- protected Object getJsonKey() {
+ protected Object getJsonKey() {
if (this.keyType instanceof AbstractCLTypeBasic) {
return this.keyType.getTypeName();
} else {
@@ -59,13 +59,13 @@ protected Object getJsonKey() {
@JsonSetter("value")
@ExcludeFromJacocoGeneratedReport
- protected void setJsonValue(AbstractCLType clType) {
+ protected void setJsonValue(AbstractCLType clType) {
this.valueType = clType;
}
@JsonGetter("value")
@ExcludeFromJacocoGeneratedReport
- protected Object getJsonValue() {
+ protected Object getJsonValue() {
if (this.valueType instanceof AbstractCLTypeBasic) {
return this.valueType.getTypeName();
} else {
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeOption.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeOption.java
index e0af0a79..e1ac7509 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeOption.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeOption.java
@@ -4,7 +4,6 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -12,7 +11,7 @@
/**
* CLType for {@link AbstractCLType#OPTION}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -20,7 +19,7 @@
*/
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeOption extends AbstractCLType {
private final String typeName = AbstractCLType.OPTION;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypePublicKey.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypePublicKey.java
index 26ab65be..ba9f260f 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypePublicKey.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypePublicKey.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#PUBLIC_KEY}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -16,7 +15,7 @@
*/
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypePublicKey extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.PUBLIC_KEY;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeResult.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeResult.java
index 096d8055..6252226b 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeResult.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeResult.java
@@ -5,9 +5,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
-
import lombok.AllArgsConstructor;
-import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -15,28 +13,30 @@
/**
* CLType for {@link AbstractCLType#RESULT}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
* @since 0.0.1
*/
@Getter
-@EqualsAndHashCode(callSuper = false, of = { "typeName", "okErrTypes" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName", "okErrTypes"})
public class CLTypeResult extends AbstractCLType {
/**
* Support class for {@link AbstractCLType#RESULT} ok/err types
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
* @since 0.0.1
*/
- @Data
+ @Getter
+ @Setter
+ @EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
- public class CLTypeResultOkErrTypes {
+ public static class CLTypeResultOkErrTypes {
@JsonIgnore
private AbstractCLType okClType;
@JsonIgnore
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeString.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeString.java
index 46e49757..4bbd5ad3 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeString.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeString.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#STRING}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -16,7 +15,7 @@
*/
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeString extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.STRING;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeTuple1.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeTuple1.java
index f5c61db4..a3ff3950 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeTuple1.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeTuple1.java
@@ -1,24 +1,23 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
-import java.lang.reflect.InvocationTargetException;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.exception.NoSuchTypeException;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
/**
* CLType for {@link AbstractCLType#TUPLE1}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
* @since 0.0.1
*/
@Getter
-@EqualsAndHashCode(callSuper = true, of = { "typeName" })
+@EqualsAndHashCode(callSuper = true, of = {"typeName"})
public class CLTypeTuple1 extends AbstractCLTypeWithChildren {
private final String typeName = AbstractCLType.TUPLE1;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeTuple2.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeTuple2.java
index d9038496..bd295d95 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeTuple2.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeTuple2.java
@@ -1,24 +1,23 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
-import java.lang.reflect.InvocationTargetException;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.exception.NoSuchTypeException;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
/**
* CLType for {@link AbstractCLType#TUPLE2}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
* @since 0.0.1
*/
@Getter
-@EqualsAndHashCode(callSuper = true, of = { "typeName" })
+@EqualsAndHashCode(callSuper = true, of = {"typeName"})
public class CLTypeTuple2 extends AbstractCLTypeWithChildren {
private final String typeName = AbstractCLType.TUPLE2;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeTuple3.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeTuple3.java
index a9d54524..927c34ba 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeTuple3.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeTuple3.java
@@ -1,24 +1,23 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
-import java.lang.reflect.InvocationTargetException;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.exception.NoSuchTypeException;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
/**
* CLType for {@link AbstractCLType#TUPLE3}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
* @since 0.0.1
*/
@Getter
-@EqualsAndHashCode(callSuper = true, of = { "typeName" })
+@EqualsAndHashCode(callSuper = true, of = {"typeName"})
public class CLTypeTuple3 extends AbstractCLTypeWithChildren {
private final String typeName = AbstractCLType.TUPLE3;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU128.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU128.java
index f44760f0..81289b7e 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU128.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU128.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#U128}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -17,7 +16,7 @@
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeU128 extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.U128;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU256.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU256.java
index 16b130a5..3de6a12f 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU256.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU256.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#U256}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -17,7 +16,7 @@
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeU256 extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.U256;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU32.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU32.java
index fb114277..37f167db 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU32.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU32.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#U32}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -16,7 +15,7 @@
*/
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeU32 extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.U32;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU512.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU512.java
index b27150d7..6e3cea22 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU512.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU512.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#U512}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -17,7 +16,7 @@
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeU512 extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.U512;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU64.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU64.java
index 741529dd..b64d2197 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU64.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU64.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#U64}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -17,7 +16,7 @@
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeU64 extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.U64;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU8.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU8.java
index 3dcc0f15..c7b4bec8 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU8.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeU8.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#U8}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -16,7 +15,7 @@
*/
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeU8 extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.U8;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeURef.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeURef.java
index e343be6e..0030b930 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeURef.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeURef.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#UREF}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -17,7 +16,7 @@
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeURef extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.UREF;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeUnit.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeUnit.java
index 9468eb8a..5d1654fc 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeUnit.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/cltype/CLTypeUnit.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.clvalue.cltype;
import com.fasterxml.jackson.annotation.JsonCreator;
-
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* CLType for {@link AbstractCLType#UNIT}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLType
@@ -17,7 +16,7 @@
@Getter
@NoArgsConstructor
-@EqualsAndHashCode(callSuper = false, of = { "typeName" })
+@EqualsAndHashCode(callSuper = false, of = {"typeName"})
public class CLTypeUnit extends AbstractCLTypeBasic {
private final String typeName = AbstractCLType.UNIT;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/CLValueDecoder.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/CLValueDecoder.java
index 5dc85202..ed2697a6 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/CLValueDecoder.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/CLValueDecoder.java
@@ -1,12 +1,5 @@
package com.syntifi.casper.sdk.model.clvalue.encdec;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.math.BigInteger;
-import java.security.NoSuchAlgorithmException;
-
import com.syntifi.casper.sdk.exception.BufferEndCLValueDecodeException;
import com.syntifi.casper.sdk.exception.CLValueDecodeException;
import com.syntifi.casper.sdk.exception.InvalidByteStringException;
@@ -29,13 +22,19 @@
import com.syntifi.casper.sdk.model.clvalue.cltype.CLTypeData;
import com.syntifi.casper.sdk.model.key.Key;
import com.syntifi.casper.sdk.model.key.PublicKey;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.math.BigInteger;
+import java.security.NoSuchAlgorithmException;
+
/**
* Casper CLValue Decoding methods
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see AbstractCLValue
@@ -50,12 +49,12 @@ public class CLValueDecoder extends ByteArrayInputStream {
private static final String LOG_DECODED_VALUE_MESSAGE_STRING = "Decoded value for {}: {}";
private static final String DECODE_EXCEPTION_BUFFER_END_EMPTY_MESSAGE_STRING = "Buffer empty, could not read data";
private static final String DECODE_EXCEPTION_BUFFER_END_MESSAGE_STRING = "Buffer ended, could not read more data";
- private static final String DECODE_EXCEPTION_WRONG_LENGHT_MESSAGE_STRING = "Could not read %s (Expected length: %d, Actual length: %d)";
+ private static final String DECODE_EXCEPTION_WRONG_LENGTH_MESSAGE_STRING = "Could not read %s (Expected length: %d, Actual length: %d)";
private static final String DECODE_EXCEPTION_OUT_OF_BOUNDS_MESSAGE_STRING = "Value %s out of bounds for expected type %s";
/**
* Initializes buffer with decoded bytes from hex-encoded {@link String}
- *
+ *
* @param hexString hex-encoded {@link String} of a CLValue
* @throws InvalidByteStringException if the byte string is invalid or can't be parsed
*/
@@ -68,16 +67,16 @@ public CLValueDecoder(String hexString) throws InvalidByteStringException {
/**
* Boolean values serialize as a single byte; true maps to 1, while false maps
* to 0.
- *
+ *
* @param clValue target {@link CLValueBool}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
*/
public void readBool(CLValueBool clValue) throws IOException, CLValueDecodeException {
int length = 1;
byte[] buf = new byte[length];
- int readBytes = 0;
+ int readBytes;
if ((readBytes = this.read(buf)) != length) {
throwReadBytesError(Boolean.class.getSimpleName(), length, readBytes);
}
@@ -96,14 +95,14 @@ public void readBool(CLValueBool clValue) throws IOException, CLValueDecodeExcep
}
/**
- * Numeric values consisting of 64 bits or less serialize in the two’s
+ * Numeric values consisting of 64 bits or fewer serialize in the two’s
* complement representation with little-endian byte order, and the appropriate
* number of bytes for the bit-width.
- *
+ *
* E.g. 7u8 serializes as 0x07
- *
+ *
* @param clValue target {@link CLValueU8}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
*/
public void readU8(CLValueU8 clValue) throws IOException, CLValueDecodeException {
@@ -111,17 +110,17 @@ public void readU8(CLValueU8 clValue) throws IOException, CLValueDecodeException
LOGGER.debug(LOG_DECODED_VALUE_MESSAGE_STRING, Byte.class.getSimpleName(), u8);
- clValue.setBytes(StringByteHelper.convertBytesToHex(new byte[] { u8 }));
+ clValue.setBytes(StringByteHelper.convertBytesToHex(new byte[]{u8}));
clValue.setValue(u8);
}
/**
- * Reads a byteArrayy into a clvalue
- *
+ * Reads a byteArray into a clvalue
+ *
* @param clValue target {@link CLValueByteArray}
- * @param length the length of the array
+ * @param length the length of the array
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
*/
public void readByteArray(CLValueByteArray clValue, int length) throws CLValueDecodeException, IOException {
byte[] bytes = readBytes(length);
@@ -133,21 +132,21 @@ public void readByteArray(CLValueByteArray clValue, int length) throws CLValueDe
}
/**
- * Numeric values consisting of 64 bits or less serialize in the two’s
+ * Numeric values consisting of 64 bits or fewer serialize in the two’s
* complement representation with little-endian byte order, and the appropriate
* number of bytes for the bit-width.
- *
+ *
* E.g. 7u32 serializes as 0x07000000 E.g. 1024u32 serializes as 0x00040000
- *
+ *
* @param clValue target {@link CLValueI32}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
*/
public void readI32(CLValueI32 clValue) throws IOException, CLValueDecodeException {
int length = 4;
byte[] buf = new byte[length];
- int readBytes = 0;
+ int readBytes;
if ((readBytes = this.read(buf)) != length) {
throwReadBytesError(Integer.class.getSimpleName(), length, readBytes);
}
@@ -168,16 +167,16 @@ public void readI32(CLValueI32 clValue) throws IOException, CLValueDecodeExcepti
/**
* Reads a {@link Long} value from buffer, representing an Unsigned
* {@link Integer} (U32)
- *
+ *
* @param clValue target {@link CLValueU32}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
*/
public void readU32(CLValueU32 clValue) throws IOException, CLValueDecodeException {
int length = 4;
byte[] buf = new byte[length];
- int readBytes = 0;
+ int readBytes;
if ((readBytes = this.read(buf)) != length) {
throwReadBytesError(Long.class.getSimpleName(), length, readBytes);
}
@@ -198,22 +197,22 @@ public void readU32(CLValueU32 clValue) throws IOException, CLValueDecodeExcepti
}
/**
- * Numeric values consisting of 64 bits or less serialize in the two’s
+ * Numeric values consisting of 64 bits or fewer serialize in the two’s
* complement representation with little-endian byte order, and the appropriate
* number of bytes for the bit-width.
- *
+ *
* E.g. 7u8 serializes as 0x07 E.g. 7u32 serializes as 0x07000000 E.g. 1024u32
* serializes as 0x00040000
- *
+ *
* @param clValue target {@link CLValueI64}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
*/
public void readI64(CLValueI64 clValue) throws IOException, CLValueDecodeException {
int length = 8;
byte[] buf = new byte[length];
- int readBytes = 0;
+ int readBytes;
if ((readBytes = this.read(buf)) != length) {
throwReadBytesError(Long.class.getSimpleName(), length, readBytes);
}
@@ -235,16 +234,16 @@ public void readI64(CLValueI64 clValue) throws IOException, CLValueDecodeExcepti
/**
* Reads a {@link BigInteger} value from buffer, representing an Unsigned
* {@link Long} (U32)
- *
+ *
* @param clValue target {@link CLValueU64}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
*/
public void readU64(CLValueU64 clValue) throws IOException, CLValueDecodeException {
int length = 8;
byte[] buf = new byte[length];
- int readBytes = 0;
+ int readBytes;
if ((readBytes = this.read(buf)) != length) {
throwReadBytesError(BigInteger.class.getSimpleName(), length, readBytes);
}
@@ -272,9 +271,9 @@ public void readU64(CLValueU64 clValue) throws IOException, CLValueDecodeExcepti
/**
* Reads U128 from buffer
- *
+ *
* @param clValue target {@link CLValueU128}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
*/
public void readU128(CLValueU128 clValue) throws IOException, CLValueDecodeException {
@@ -283,9 +282,9 @@ public void readU128(CLValueU128 clValue) throws IOException, CLValueDecodeExcep
/**
* Reads U256 from buffer
- *
+ *
* @param clValue target {@link CLValueU256}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
*/
public void readU256(CLValueU256 clValue) throws IOException, CLValueDecodeException {
@@ -294,9 +293,9 @@ public void readU256(CLValueU256 clValue) throws IOException, CLValueDecodeExcep
/**
* Reads U512 from buffer
- *
+ *
* @param clValue target {@link CLValueU512}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
*/
public void readU512(CLValueU512 clValue) throws IOException, CLValueDecodeException {
@@ -310,21 +309,21 @@ public void readU512(CLValueU512 clValue) throws IOException, CLValueDecodeExcep
* chosen as small as possible to represent the given number. This is done to
* reduce the serialization size when small numbers are represented within a
* wide data type.
- *
+ *
* E.g. U512::from(7) serializes as 0x0107 E.g. U512::from(1024) serializes as
* 0x020004 E.g. U512::from("123456789101112131415") serializes as
* 0x0957ff1ada959f4eb106
- *
+ *
* @param clValue target {@link AbstractCLValue}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
*/
protected void readBigInteger(AbstractCLValue clValue) throws IOException, CLValueDecodeException {
byte[] buf = new byte[1];
- int readBytes = 0;
+ int readBytes;
if ((readBytes = this.read(buf)) != 1) {
- throw new CLValueDecodeException(String.format(DECODE_EXCEPTION_WRONG_LENGHT_MESSAGE_STRING,
+ throw new CLValueDecodeException(String.format(DECODE_EXCEPTION_WRONG_LENGTH_MESSAGE_STRING,
Byte.class.getSimpleName(), 1, readBytes));
}
@@ -338,7 +337,7 @@ protected void readBigInteger(AbstractCLValue clValue) throws IOE
throwReadBytesError(BigInteger.class.getSimpleName(), lengthOfNextNumber, readBytes);
}
- clValue.setBytes(StringByteHelper.convertBytesToHex(new byte[] { lengthOfNextNumber })
+ clValue.setBytes(StringByteHelper.convertBytesToHex(new byte[]{lengthOfNextNumber})
+ StringByteHelper.convertBytesToHex(buf));
StringByteHelper.reverse(buf);
@@ -354,16 +353,16 @@ protected void readBigInteger(AbstractCLValue clValue) throws IOE
/**
* Reads a {@link CLValueString} value from buffer
- *
+ *
* @param clValue target {@link CLValueString}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
*/
public void readString(CLValueString clValue) throws IOException, CLValueDecodeException {
int numberByteLength = 4;
byte[] bufLength = new byte[numberByteLength];
- int readBytes = 0;
+ int readBytes;
if ((readBytes = this.read(bufLength)) != numberByteLength) {
throwReadBytesError(Integer.class.getSimpleName(), numberByteLength, readBytes);
}
@@ -395,11 +394,11 @@ public void readString(CLValueString clValue) throws IOException, CLValueDecodeE
/**
* Reads a {@link CLValuePublicKey} value from buffer
- *
+ *
* @param clValue target {@link CLValuePublicKey}
* @throws NoSuchAlgorithmException the requested algorithm was not found
- * @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
- * @throws IOException error with input/output while reading the byte array
+ * @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
+ * @throws IOException error with input/output while reading the byte array
*/
public void readPublicKey(CLValuePublicKey clValue) throws NoSuchAlgorithmException, CLValueDecodeException, IOException {
byte[] key = this.readBytes(buf.length);
@@ -409,11 +408,11 @@ public void readPublicKey(CLValuePublicKey clValue) throws NoSuchAlgorithmExcept
/**
* Reads a {@link CLValueKey} value from buffer
- *
+ *
* @param clValue target {@link CLValueKey}
- * @throws NoSuchKeyTagException the requested key tag was not found
+ * @throws NoSuchKeyTagException the requested key tag was not found
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
*/
public void readKey(CLValueKey clValue) throws NoSuchKeyTagException, CLValueDecodeException, IOException {
byte[] key = this.readBytes(buf.length);
@@ -423,9 +422,9 @@ public void readKey(CLValueKey clValue) throws NoSuchKeyTagException, CLValueDec
/**
* Reads all bytes as a generic {@link Object} into a {@link CLValueAny}
- *
+ *
* @param clValue target {@link CLValueAny}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
*/
public void readAny(CLValueAny clValue) throws IOException, CLValueDecodeException {
@@ -439,10 +438,10 @@ public void readAny(CLValueAny clValue) throws IOException, CLValueDecodeExcepti
/**
* Reads a single byte
- *
+ *
* @return the byte read
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
*/
protected byte readByte() throws CLValueDecodeException, IOException {
return this.readBytes(1)[0];
@@ -450,16 +449,16 @@ protected byte readByte() throws CLValueDecodeException, IOException {
/**
* Reads a specified number of bytes
- *
+ *
* @param length the number of bytes to read
* @return bytes read
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
- * @throws IOException error with input/output while reading the byte array
+ * @throws IOException error with input/output while reading the byte array
*/
protected byte[] readBytes(int length) throws CLValueDecodeException, IOException {
byte[] buf = new byte[length];
- int readBytes = 0;
+ int readBytes;
if ((readBytes = this.read(buf)) != length) {
throwReadBytesError(Byte.class.getSimpleName(), length, readBytes);
}
@@ -470,19 +469,18 @@ protected byte[] readBytes(int length) throws CLValueDecodeException, IOExceptio
}
/**
- *
- * @param simpleName the object's simple name
- * @param expectedLength the expected length
+ * @param simpleName the object's simple name
+ * @param expectedLength the expected length
* @param readBytesLength the actual read bytes length
* @throws CLValueDecodeException exception holding information of failure to decode a {@link AbstractCLValue}
*/
private void throwReadBytesError(String simpleName, int expectedLength, int readBytesLength) throws CLValueDecodeException {
if (this.buf.length == 0) {
throw new BufferEndCLValueDecodeException(DECODE_EXCEPTION_BUFFER_END_EMPTY_MESSAGE_STRING);
- } else if (this.buf.length > 0 && readBytesLength == -1) {
+ } else if (readBytesLength == -1) {
throw new BufferEndCLValueDecodeException(DECODE_EXCEPTION_BUFFER_END_MESSAGE_STRING);
} else {
- throw new CLValueDecodeException(String.format(DECODE_EXCEPTION_WRONG_LENGHT_MESSAGE_STRING, simpleName,
+ throw new CLValueDecodeException(String.format(DECODE_EXCEPTION_WRONG_LENGTH_MESSAGE_STRING, simpleName,
expectedLength, readBytesLength));
}
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/CLValueEncoder.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/CLValueEncoder.java
index 1174dec3..4c4ad7c9 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/CLValueEncoder.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/CLValueEncoder.java
@@ -1,360 +1,416 @@
-package com.syntifi.casper.sdk.model.clvalue.encdec;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-
-import com.syntifi.casper.sdk.exception.CLValueEncodeException;
-import com.syntifi.casper.sdk.exception.NoSuchTypeException;
-import com.syntifi.casper.sdk.model.clvalue.AbstractCLValue;
-import com.syntifi.casper.sdk.model.clvalue.CLValueAny;
-import com.syntifi.casper.sdk.model.clvalue.CLValueBool;
-import com.syntifi.casper.sdk.model.clvalue.CLValueByteArray;
-import com.syntifi.casper.sdk.model.clvalue.CLValueI32;
-import com.syntifi.casper.sdk.model.clvalue.CLValueI64;
-import com.syntifi.casper.sdk.model.clvalue.CLValueKey;
-import com.syntifi.casper.sdk.model.clvalue.CLValuePublicKey;
-import com.syntifi.casper.sdk.model.clvalue.CLValueString;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU128;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU256;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU32;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU512;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU64;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU8;
-import com.syntifi.casper.sdk.model.clvalue.cltype.CLTypeData;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Casper CLValue Encoding methods
- *
- * @author Alexandre Carvalho
- * @author Andre Bertolace
- * @see AbstractCLValue
- * @since 0.0.1
- */
-public class CLValueEncoder extends ByteArrayOutputStream {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(CLValueEncoder.class);
-
- public static final BigInteger ZERO = new BigInteger("0", 10);
- public static final BigInteger ONE = new BigInteger("1", 10);
- public static final BigInteger TWO = new BigInteger("2", 10);
- public static final BigInteger MAX_U64 = TWO.pow(64).subtract(ONE);
- public static final BigInteger MAX_U128 = TWO.pow(128).subtract(ONE);
- public static final BigInteger MAX_U256 = TWO.pow(256).subtract(ONE);
- public static final BigInteger MAX_U512 = TWO.pow(512).subtract(ONE);
-
- private static final String LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING = "Writing CLType {} from Java Type {}: {}";
- private static final String ENCODE_EXCEPTION_OUT_OF_BOUNDS_MESSAGE_STRING = "Value %s out of bounds for expected type %s";
-
- /**
- * Initializes buffer as zero-length
- */
- public CLValueEncoder() {
- super(0);
- }
-
- /**
- * Writes a boolean value to the CLValue byte buffer
- *
- * @param clValue {@link CLValueBool} value to encode
- * @throws IOException
- */
- public void writeBool(CLValueBool clValue) throws IOException {
- LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.BOOL, Boolean.class.getSimpleName(),
- clValue.getValue());
-
- ByteBuffer boolByteBuffer = ByteBuffer.allocate(1)
- .put(Boolean.TRUE.equals(clValue.getValue()) ? (byte) 0x01 : (byte) 0x00);
-
- byte[] boolBytes = boolByteBuffer.array();
-
- this.write(boolBytes);
-
- clValue.setBytes(StringByteHelper.convertBytesToHex(boolBytes));
- }
-
- /**
- * Writes a single byte value to the CLValue byte buffer
- *
- * @param clValue {@link CLValueU8} value to encode
- */
- public void writeU8(CLValueU8 clValue) {
- LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.U8, Byte.class.getSimpleName(),
- clValue.getValue());
-
- this.write(clValue.getValue());
-
- clValue.setBytes(StringByteHelper.convertBytesToHex(new byte[] { clValue.getValue().byteValue() }));
- }
-
- /**
- * Writes a byte array value to the CLValue byte buffer
- *
- * @param clValue {@link CLValueByteArray} value to encode
- * @throws IOException
- */
- public void writeByteArray(CLValueByteArray clValue) throws IOException {
- LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.BYTE_ARRAY, byte[].class.getSimpleName(),
- clValue.getValue());
-
- this.write(clValue.getValue());
-
- clValue.getClType().setLength(clValue.getValue().length);
- clValue.setBytes(StringByteHelper.convertBytesToHex(clValue.getValue()));
- }
-
- /**
- * Writes an Integer/I32 value to the CLValue byte buffer
- *
- * @param clValue {@link CLValueI32} value to encode
- * @throws IOException
- */
- public void writeI32(CLValueI32 clValue) throws IOException {
- LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.I32, Integer.class.getSimpleName(),
- clValue.getValue());
-
- ByteBuffer intByteBuffer = ByteBuffer.allocate(4).putInt(clValue.getValue());
-
- byte[] intByteArray = intByteBuffer.array();
-
- StringByteHelper.reverse(intByteArray);
-
- this.write(intByteArray);
-
- clValue.setBytes(StringByteHelper.convertBytesToHex(intByteArray));
- }
-
- /**
- * Writes an Unsigned Integer (Long)/U32 value to the CLValue byte buffer
- *
- * @param clValue {@link CLValueU32} value to encode
- * @throws IOException
- */
- public void writeU32(CLValueU32 clValue) throws IOException {
- LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.U32, Long.class.getSimpleName(),
- clValue.getValue());
-
- int unsignedInteger = clValue.getValue().intValue();
-
- ByteBuffer unsignedIntegerByteBuffer = ByteBuffer.allocate(4).putInt(unsignedInteger);
-
- byte[] unsignedIntegerByteArray = unsignedIntegerByteBuffer.array();
-
- StringByteHelper.reverse(unsignedIntegerByteArray);
-
- this.write(unsignedIntegerByteArray);
-
- clValue.setBytes(StringByteHelper.convertBytesToHex(unsignedIntegerByteArray));
- }
-
- /**
- * Writes a Long/I64 value to the CLValue byte buffer
- *
- * @param clValue {@link CLValueI64} value to encode
- * @throws IOException
- */
- public void writeI64(CLValueI64 clValue) throws IOException {
- LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.I64, Long.class.getSimpleName(),
- clValue.getValue());
-
- ByteBuffer longByteBuffer = ByteBuffer.allocate(8).putLong(clValue.getValue());
-
- byte[] longByteArray = longByteBuffer.array();
-
- StringByteHelper.reverse(longByteArray);
-
- this.write(longByteArray);
-
- clValue.setBytes(StringByteHelper.convertBytesToHex(longByteArray));
- }
-
- /**
- * Writes an Unsigned Long (BigInteger)/U64 to the CLValue byte buffer
- *
- * @param clValue {@link CLValueU64} value to encode
- * @throws IOException
- * @throws CLValueEncodeException
- */
- public void writeU64(CLValueU64 clValue) throws IOException, CLValueEncodeException {
- checkBoundsFor(clValue.getValue(), CLTypeData.U64);
-
- LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.U64, BigInteger.class.getSimpleName(),
- clValue.getValue());
-
- ByteBuffer unsignedLongByteBuffer = ByteBuffer.allocate(8).putLong(clValue.getValue().longValue());
-
- byte[] unsignedLongByteArray = unsignedLongByteBuffer.array();
-
- StringByteHelper.reverse(unsignedLongByteArray);
-
- this.write(unsignedLongByteArray);
-
- clValue.setBytes(StringByteHelper.convertBytesToHex(unsignedLongByteArray));
- }
-
- /**
- * Writes a BigInteger/U128 to the CLValue byte buffer
- *
- * @param clValue {@link CLValueU128} value to encode
- * @throws IOException
- * @throws CLValueEncodeException
- */
- public void writeU128(CLValueU128 clValue) throws IOException, CLValueEncodeException {
- writeBigInteger(clValue, CLTypeData.U128);
- }
-
- /**
- * Writes a BigInteger/U256 to the CLValue byte buffer
- *
- * @param clValue {@link CLValueU256} value to encode
- * @throws IOException
- * @throws CLValueEncodeException
- */
- public void writeU256(CLValueU256 clValue) throws IOException, CLValueEncodeException {
- writeBigInteger(clValue, CLTypeData.U256);
- }
-
- /**
- * Writes a BigInteger/U512 to the CLValue byte buffer
- *
- * @param clValue {@link CLValueU512} value to encode
- * @throws IOException
- * @throws CLValueEncodeException
- */
- public void writeU512(CLValueU512 clValue) throws IOException, CLValueEncodeException {
- writeBigInteger(clValue, CLTypeData.U512);
- }
-
- /**
- * Writes a BigInteger/U128-U256-U512 to the CLValue byte buffer
- *
- * @param clValue {@link AbstractCLValue} value to encode
- * @param clValue {@link CLTypeData} CLTypeData of BigInteger
- * @throws IOException
- * @throws CLValueEncodeException
- */
- protected void writeBigInteger(AbstractCLValue clValue, CLTypeData type)
- throws IOException, CLValueEncodeException {
- checkBoundsFor(clValue.getValue(), type);
-
- LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, type.getClTypeName(), BigInteger.class.getSimpleName(),
- clValue.getValue());
-
- byte bigIntegerLength = (byte) (Math.ceil(clValue.getValue().bitLength() / 8.0));
-
- this.write(bigIntegerLength);
-
- byte[] byteArray = clValue.getValue().toByteArray();
-
- // Removing leading zeroes
- int i = 0;
- boolean both = false;
- while (byteArray[i] == 0) {
- if (both) {
- i++;
- }
- both = !both;
- }
-
- byte[] valueByteArray = Arrays.copyOfRange(byteArray, i, bigIntegerLength + i);
-
- StringByteHelper.reverse(valueByteArray);
-
- ByteBuffer valueByteBuffer = ByteBuffer.allocate(bigIntegerLength).put(valueByteArray);
-
- byte[] bigIntegerBytes = valueByteBuffer.array();
-
- this.write(bigIntegerBytes);
-
- clValue.setBytes(StringByteHelper.convertBytesToHex(new byte[] { bigIntegerLength })
- + StringByteHelper.convertBytesToHex(bigIntegerBytes));
- }
-
- /**
- * Writes a String/String to the CLValue byte buffer
- *
- * @param clValue {@link CLValueString} value to encode
- * @throws IOException
- */
- public void writeString(CLValueString clValue) throws IOException {
- LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.STRING, String.class.getSimpleName(),
- clValue.getValue());
-
- ByteBuffer intByteBuffer = ByteBuffer.allocate(4).putInt(clValue.getValue().length());
-
- byte[] intByteArray = intByteBuffer.array();
-
- StringByteHelper.reverse(intByteArray);
-
- this.write(intByteArray);
-
- byte[] stringBytes = clValue.getValue().getBytes();
-
- this.write(stringBytes);
-
- clValue.setBytes(
- StringByteHelper.convertBytesToHex(intByteArray) + StringByteHelper.convertBytesToHex(stringBytes));
- }
-
- /**
- * Writes a AlgorithmTag/Key Hex string to CLValue byte buffer
- *
- * @param clValue {@link CLValuePublicKey} value to encode
- */
- public void writePublicKey(CLValuePublicKey clValue) {
- clValue.setBytes(StringByteHelper.convertBytesToHex(new byte[] { clValue.getValue().getTag().getByteTag() })
- + StringByteHelper.convertBytesToHex(clValue.getValue().getKey()));
- }
-
- /**
- * Writes a Tag/Key Hex string to CLValue byte buffer
- *
- * @param clValue {@link CLValueKey} value to encode
- */
- public void writeKey(CLValueKey clValue) {
- clValue.setBytes(StringByteHelper.convertBytesToHex(new byte[] { clValue.getValue().getTag().getByteTag() })
- + StringByteHelper.convertBytesToHex(clValue.getValue().getKey()));
- }
-
- public void writeAny(CLValueAny clValue) throws IOException {
- try (ObjectOutputStream oos = new ObjectOutputStream(this)) {
- oos.writeObject(clValue.getValue());
- }
-
- clValue.setBytes(StringByteHelper.convertBytesToHex(this.toByteArray()));
- }
-
- /**
- * Checks if the value is within valid bounds for given CLType
- *
- * @param value the value to check
- * @param type the cltype to check against
- * @throws CLValueEncodeException
- */
- private void checkBoundsFor(BigInteger value, CLTypeData type) throws CLValueEncodeException {
- BigInteger max;
- if (type.equals(CLTypeData.U64)) {
- max = MAX_U64;
- } else if (type.equals(CLTypeData.U128)) {
- max = MAX_U128;
- } else if (type.equals(CLTypeData.U256)) {
- max = MAX_U256;
- } else if (type.equals(CLTypeData.U512)) {
- max = MAX_U512;
- } else {
- throw new CLValueEncodeException("Error checking numeric bounds", new NoSuchTypeException(
- String.format("%s is not a numeric type with check bounds for encoding", type.getClTypeName())));
- }
-
- if (value.compareTo(max) > 0 || value.compareTo(ZERO) < 0) {
- throw new CLValueEncodeException(String.format(ENCODE_EXCEPTION_OUT_OF_BOUNDS_MESSAGE_STRING,
- value.toString(), type.getClTypeName()));
- }
- }
-}
+package com.syntifi.casper.sdk.model.clvalue.encdec;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.AbstractCLValue;
+import com.syntifi.casper.sdk.model.clvalue.CLValueAny;
+import com.syntifi.casper.sdk.model.clvalue.CLValueBool;
+import com.syntifi.casper.sdk.model.clvalue.CLValueByteArray;
+import com.syntifi.casper.sdk.model.clvalue.CLValueI32;
+import com.syntifi.casper.sdk.model.clvalue.CLValueI64;
+import com.syntifi.casper.sdk.model.clvalue.CLValueKey;
+import com.syntifi.casper.sdk.model.clvalue.CLValuePublicKey;
+import com.syntifi.casper.sdk.model.clvalue.CLValueString;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU128;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU256;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU32;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU512;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU64;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU8;
+import com.syntifi.casper.sdk.model.clvalue.cltype.CLTypeData;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Casper CLValue Encoding methods
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @see AbstractCLValue
+ * @since 0.0.1
+ */
+
+public class CLValueEncoder extends ByteArrayOutputStream {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CLValueEncoder.class);
+
+ public static final BigInteger ZERO = new BigInteger("0", 10);
+ public static final BigInteger ONE = new BigInteger("1", 10);
+ public static final BigInteger TWO = new BigInteger("2", 10);
+ public static final BigInteger MAX_U64 = TWO.pow(64).subtract(ONE);
+ public static final BigInteger MAX_U128 = TWO.pow(128).subtract(ONE);
+ public static final BigInteger MAX_U256 = TWO.pow(256).subtract(ONE);
+ public static final BigInteger MAX_U512 = TWO.pow(512).subtract(ONE);
+
+ private static final String LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING = "Writing CLType {} from Java Type {}: {}";
+ private static final String ENCODE_EXCEPTION_OUT_OF_BOUNDS_MESSAGE_STRING = "Value %s out of bounds for expected type %s";
+
+ /**
+ * Initializes buffer as zero-length
+ */
+ public CLValueEncoder() {
+ super(0);
+ }
+
+ /**
+ * Writes a boolean value to the CLValue byte buffer
+ *
+ * @param clValue {@link CLValueBool} value to encode
+ * @throws IOException thrown when an error occurs while writing bytes
+ */
+ public void writeBool(CLValueBool clValue) throws IOException {
+ LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.BOOL, Boolean.class.getSimpleName(),
+ clValue.getValue());
+
+ ByteBuffer boolByteBuffer = ByteBuffer.allocate(1)
+ .put(Boolean.TRUE.equals(clValue.getValue()) ? (byte) 0x01 : (byte) 0x00);
+
+ byte[] boolBytes = boolByteBuffer.array();
+
+ this.write(boolBytes);
+
+ clValue.setBytes(StringByteHelper.convertBytesToHex(boolBytes));
+ }
+
+ /**
+ * Writes a single byte value to the CLValue byte buffer
+ *
+ * @param clValue {@link CLValueU8} value to encode
+ */
+ public void writeU8(CLValueU8 clValue) {
+ LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.U8, Byte.class.getSimpleName(),
+ clValue.getValue());
+
+ this.write(clValue.getValue());
+
+ clValue.setBytes(StringByteHelper.convertBytesToHex(new byte[] {clValue.getValue()}));
+ }
+
+ /**
+ * Writes a byte array value to the CLValue byte buffer
+ *
+ * @param clValue {@link CLValueByteArray} value to encode
+ * @throws IOException thrown when an error occurs while writing bytes
+ */
+ public void writeByteArray(CLValueByteArray clValue) throws IOException {
+ LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.BYTE_ARRAY, byte[].class.getSimpleName(),
+ clValue.getValue());
+
+ this.write(clValue.getValue());
+
+ clValue.getClType().setLength(clValue.getValue().length);
+ clValue.setBytes(StringByteHelper.convertBytesToHex(clValue.getValue()));
+ }
+
+ /**
+ * Writes an Integer/I32 value to the CLValue byte buffer
+ *
+ * @param clValue {@link CLValueI32} value to encode
+ * @throws IOException thrown when an error occurs while writing bytes
+ */
+ public void writeI32(CLValueI32 clValue) throws IOException {
+ LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.I32, Integer.class.getSimpleName(),
+ clValue.getValue());
+
+ byte[] intByteArray = writeInt(clValue.getValue());
+
+ clValue.setBytes(StringByteHelper.convertBytesToHex(intByteArray));
+ }
+
+ /**
+ * Writes an Unsigned Integer (Long)/U32 value to the CLValue byte buffer
+ *
+ * @param clValue {@link CLValueU32} value to encode
+ * @throws IOException thrown when an error occurs while writing bytes
+ */
+ public void writeU32(CLValueU32 clValue) throws IOException {
+ LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.U32, Long.class.getSimpleName(),
+ clValue.getValue());
+
+ byte[] uIntByteArray = writeInt(clValue.getValue().intValue());
+
+ clValue.setBytes(StringByteHelper.convertBytesToHex(uIntByteArray));
+ }
+
+ /**
+ * Writes an Integer value to byte buffer
+ *
+ * @param value the value to write
+ * @return byte[]
+ * @throws IOException thrown when an error occurs while writing bytes
+ */
+ public byte[] writeInt(Integer value) throws IOException {
+ LOGGER.debug("Writing Java Type {}: {}", Integer.class.getSimpleName(), value);
+
+ ByteBuffer intByteBuffer = ByteBuffer.allocate(4).putInt(value);
+
+ byte[] intByteArray = intByteBuffer.array();
+
+ StringByteHelper.reverse(intByteArray);
+
+ this.write(intByteArray);
+ return intByteArray;
+ }
+
+ /**
+ * Writes a Long/I64 value to the CLValue byte buffer
+ *
+ * @param clValue {@link CLValueI64} value to encode
+ * @throws IOException thrown when an error occurs while writing bytes
+ */
+ public void writeI64(CLValueI64 clValue) throws IOException {
+ LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.I64, Long.class.getSimpleName(),
+ clValue.getValue());
+
+ byte[] longByteArray = writeLong(clValue.getValue());
+
+ clValue.setBytes(StringByteHelper.convertBytesToHex(longByteArray));
+ }
+
+ /**
+ * Writes a Long value to byte buffer
+ *
+ * @param value the value to write
+ * @return byte[]
+ * @throws IOException thrown when an error occurs while writing bytes
+ */
+ public byte[] writeLong(Long value) throws IOException {
+ LOGGER.debug("Writing Java Type {}: {}", Long.class.getSimpleName(), value);
+
+ ByteBuffer longByteBuffer = ByteBuffer.allocate(8).putLong(value);
+
+ byte[] longByteArray = longByteBuffer.array();
+
+ StringByteHelper.reverse(longByteArray);
+
+ this.write(longByteArray);
+ return longByteArray;
+ }
+
+ /**
+ * Writes an Unsigned Long (BigInteger)/U64 to the CLValue byte buffer
+ *
+ * @param clValue {@link CLValueU64} value to encode
+ * @throws IOException thrown when an error occurs while writing bytes
+ * @throws CLValueEncodeException thrown when a clvalue encoding throws an error
+ */
+ public void writeU64(CLValueU64 clValue) throws IOException, CLValueEncodeException {
+ checkBoundsFor(clValue.getValue(), CLTypeData.U64);
+
+ LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.U64, BigInteger.class.getSimpleName(),
+ clValue.getValue());
+
+ ByteBuffer unsignedLongByteBuffer = ByteBuffer.allocate(8).putLong(clValue.getValue().longValue());
+
+ byte[] unsignedLongByteArray = unsignedLongByteBuffer.array();
+
+ StringByteHelper.reverse(unsignedLongByteArray);
+
+ this.write(unsignedLongByteArray);
+
+ clValue.setBytes(StringByteHelper.convertBytesToHex(unsignedLongByteArray));
+ }
+
+ /**
+ * Writes a BigInteger/U128 to the CLValue byte buffer
+ *
+ * @param clValue {@link CLValueU128} value to encode
+ * @throws IOException thrown when an error occurs while writing bytes
+ * @throws CLValueEncodeException thrown when a clvalue encoding throws an error
+ */
+ public void writeU128(CLValueU128 clValue) throws IOException, CLValueEncodeException {
+ writeBigInteger(clValue, CLTypeData.U128);
+ }
+
+ /**
+ * Writes a BigInteger/U256 to the CLValue byte buffer
+ *
+ * @param clValue {@link CLValueU256} value to encode
+ * @throws IOException thrown when an error occurs while writing bytes
+ * @throws CLValueEncodeException thrown when a clvalue encoding throws an error
+ */
+ public void writeU256(CLValueU256 clValue) throws IOException, CLValueEncodeException {
+ writeBigInteger(clValue, CLTypeData.U256);
+ }
+
+ /**
+ * Writes a BigInteger/U512 to the CLValue byte buffer
+ *
+ * @param clValue {@link CLValueU512} value to encode
+ * @throws IOException thrown when an error occurs while writing bytes
+ * @throws CLValueEncodeException thrown when a clvalue encoding throws an error
+ */
+ public void writeU512(CLValueU512 clValue) throws IOException, CLValueEncodeException {
+ writeBigInteger(clValue, CLTypeData.U512);
+ }
+
+ /**
+ * Writes a BigInteger/U128-U256-U512 to the CLValue byte buffer
+ *
+ * @param clValue {@link AbstractCLValue} value to encode
+ * @param type {@link CLTypeData} CLTypeData of BigInteger
+ * @throws IOException thrown when an error occurs while writing bytes
+ * @throws CLValueEncodeException thrown when a clvalue encoding throws an error
+ */
+ protected void writeBigInteger(AbstractCLValue clValue, CLTypeData type)
+ throws IOException, CLValueEncodeException {
+ checkBoundsFor(clValue.getValue(), type);
+
+ LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, type.getClTypeName(), BigInteger.class.getSimpleName(),
+ clValue.getValue());
+
+ byte bigIntegerLength = (byte) (Math.ceil(clValue.getValue().bitLength() / 8.0));
+ byte[] bigIntegerBytes = writeBigInteger(clValue.getValue());
+
+ clValue.setBytes(StringByteHelper.convertBytesToHex(new byte[] { bigIntegerLength })
+ + StringByteHelper.convertBytesToHex(bigIntegerBytes));
+ }
+
+ /**
+ * Writes a BigInteger to the CLValue byte buffer
+ *
+ * @param bigInteger the biginteger to write
+ * @return a byte array
+ * @throws IOException thrown when an error occurs while writing bytes
+ */
+ public byte[] writeBigInteger(BigInteger bigInteger) throws IOException {
+ LOGGER.debug("Writing Java Type {}: {}", BigInteger.class.getSimpleName(), bigInteger);
+
+ byte bigIntegerLength = (byte) (Math.ceil(bigInteger.bitLength() / 8.0));
+
+ this.write(bigIntegerLength);
+
+ byte[] byteArray = bigInteger.toByteArray();
+
+ // Removing leading zeroes
+ int i = 0;
+ boolean both = false;
+ while (byteArray[i] == 0) {
+ if (both) {
+ i++;
+ }
+ both = !both;
+ }
+
+ byte[] valueByteArray = Arrays.copyOfRange(byteArray, i, bigIntegerLength + i);
+
+ StringByteHelper.reverse(valueByteArray);
+
+ ByteBuffer valueByteBuffer = ByteBuffer.allocate(bigIntegerLength).put(valueByteArray);
+
+ byte[] bigIntegerBytes = valueByteBuffer.array();
+
+ this.write(bigIntegerBytes);
+
+ return bigIntegerBytes;
+ }
+
+ /**
+ * Writes a String/String to the CLValue byte buffer
+ *
+ * @param clValue {@link CLValueString} value to encode
+ * @throws IOException thrown when an error occurs while writing bytes
+ */
+ public void writeString(CLValueString clValue) throws IOException {
+ LOGGER.debug(LOG_BUFFER_WRITE_TYPE_VALUE_MESSAGE_STRING, CLTypeData.STRING, String.class.getSimpleName(),
+ clValue.getValue());
+
+ byte[] stringBytes = writeString(clValue.getValue());
+
+ clValue.setBytes(StringByteHelper.convertBytesToHex(stringBytes));
+ }
+
+ /**
+ * Writes a String to the byte buffer
+ *
+ * @param string to encode
+ * @return byte[]
+ * @throws IOException thrown when an error occurs while writing bytes
+ */
+ public byte[] writeString(String string) throws IOException {
+ LOGGER.debug("Writing Java Type {}: {}", String.class.getSimpleName(), string);
+
+ ByteBuffer intByteBuffer = ByteBuffer.allocate(4).putInt(string.length());
+
+ byte[] intByteArray = intByteBuffer.array();
+
+ StringByteHelper.reverse(intByteArray);
+
+ ByteBuffer stringBuffer = ByteBuffer.allocate(4 + string.length());
+ stringBuffer.put(intByteArray);
+ stringBuffer.put(string.getBytes());
+
+ byte[] stringBytes = stringBuffer.array();
+
+ this.write(stringBytes);
+
+ return stringBytes;
+ }
+
+ /**
+ * Writes a AlgorithmTag/Key Hex string to CLValue byte buffer
+ *
+ * @param clValue {@link CLValuePublicKey} value to encode
+ */
+ public void writePublicKey(CLValuePublicKey clValue) throws IOException {
+ byte[] tag = new byte[] { clValue.getValue().getTag().getByteTag() };
+ clValue.setBytes(StringByteHelper.convertBytesToHex(tag)
+ + StringByteHelper.convertBytesToHex(clValue.getValue().getKey()));
+ this.write(tag);
+ this.write(clValue.getValue().getKey());
+ }
+
+ /**
+ * Writes a Tag/Key Hex string to CLValue byte buffer
+ *
+ * @param clValue {@link CLValueKey} value to encode
+ */
+ public void writeKey(CLValueKey clValue) {
+ clValue.setBytes(StringByteHelper.convertBytesToHex(new byte[] { clValue.getValue().getTag().getByteTag() })
+ + StringByteHelper.convertBytesToHex(clValue.getValue().getKey()));
+ }
+
+ public void writeAny(CLValueAny clValue) throws IOException {
+ try (ObjectOutputStream oos = new ObjectOutputStream(this)) {
+ oos.writeObject(clValue.getValue());
+ }
+
+ clValue.setBytes(StringByteHelper.convertBytesToHex(this.toByteArray()));
+ }
+
+ /**
+ * Checks if the value is within valid bounds for given CLType
+ *
+ * @param value the value to check
+ * @param type the cltype to check against
+ * @throws CLValueEncodeException thrown when a clvalue encoding throws an error
+ */
+ private void checkBoundsFor(BigInteger value, CLTypeData type) throws CLValueEncodeException {
+ BigInteger max;
+ if (type.equals(CLTypeData.U64)) {
+ max = MAX_U64;
+ } else if (type.equals(CLTypeData.U128)) {
+ max = MAX_U128;
+ } else if (type.equals(CLTypeData.U256)) {
+ max = MAX_U256;
+ } else if (type.equals(CLTypeData.U512)) {
+ max = MAX_U512;
+ } else {
+ throw new CLValueEncodeException("Error checking numeric bounds", new NoSuchTypeException(
+ String.format("%s is not a numeric type with check bounds for encoding", type.getClTypeName())));
+ }
+
+ if (value.compareTo(max) > 0 || value.compareTo(ZERO) < 0) {
+ throw new CLValueEncodeException(String.format(ENCODE_EXCEPTION_OUT_OF_BOUNDS_MESSAGE_STRING,
+ value, type.getClTypeName()));
+ }
+ }
+}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/StringByteHelper.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/StringByteHelper.java
index d9e08976..4fb98820 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/StringByteHelper.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/StringByteHelper.java
@@ -2,13 +2,12 @@
import com.syntifi.casper.sdk.exception.InvalidByteStringException;
import com.syntifi.casper.sdk.model.clvalue.cltype.CLTypeData;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Helper methods for working with hex encoded string and bytes
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see CLTypeData
@@ -22,8 +21,8 @@ private StringByteHelper() {
}
/**
- * Reverses a byte array, used to go from little to big endianess
- *
+ * Reverses a byte array, used to go from little to big endianness
+ *
* @param bytes array of bytes to reverse
*/
public static void reverse(byte[] bytes) {
@@ -38,14 +37,14 @@ public static void reverse(byte[] bytes) {
/**
* Helper method which converts hex-encoded {@link String} to byte array
- *
+ *
* @param hexString the hex-encoded {@link String} to decode
* @return decoded array of bytes
*/
public static byte[] hexStringToByteArray(String hexString) throws InvalidByteStringException {
int len = hexString.length();
if (len % 2 != 0) {
- throw new InvalidByteStringException("Hexstring must have an even number of hex digits.");
+ throw new InvalidByteStringException("Hex string must have an even number of hex digits.");
}
byte[] bytes = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
@@ -58,7 +57,7 @@ public static byte[] hexStringToByteArray(String hexString) throws InvalidByteSt
/**
* Helper method which returns byte arrays as hex strings
- *
+ *
* @param bytes the byte array to encode
* @return hex-encoded value {@link String}
*/
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/interfaces/DecodableValue.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/interfaces/DecodableValue.java
index 13d96e15..69d586ea 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/interfaces/DecodableValue.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/interfaces/DecodableValue.java
@@ -1,15 +1,15 @@
package com.syntifi.casper.sdk.model.clvalue.encdec.interfaces;
-import java.io.IOException;
-
import com.syntifi.casper.sdk.exception.CLValueDecodeException;
import com.syntifi.casper.sdk.exception.DynamicInstanceException;
import com.syntifi.casper.sdk.exception.NoSuchTypeException;
import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueDecoder;
+import java.io.IOException;
+
/**
* Defines an object as being capable of decoding with {@link CLValueDecoder}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -17,13 +17,13 @@
public interface DecodableValue {
/**
* Called when the object's values must be decoded after deserializing
- *
+ *
* @param clvd the decoder to be used
- * @throws IOException
- * @throws CLValueDecodeException
- * @throws DynamicInstanceException
- * @throws NoSuchTypeException
+ * @throws NoSuchTypeException thrown if type not found
+ * @throws DynamicInstanceException thrown if it could not instantiate a type
+ * @throws CLValueDecodeException thrown if failed to decode a cl value
+ * @throws IOException thrown if an IO error occurs
*/
- public void decode(CLValueDecoder clvd)
+ void decode(CLValueDecoder clvd)
throws IOException, CLValueDecodeException, DynamicInstanceException, NoSuchTypeException;
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/interfaces/EncodableValue.java b/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/interfaces/EncodableValue.java
index b350c6da..60bbef6c 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/interfaces/EncodableValue.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/clvalue/encdec/interfaces/EncodableValue.java
@@ -1,29 +1,30 @@
-package com.syntifi.casper.sdk.model.clvalue.encdec.interfaces;
-
-import java.io.IOException;
-
-import com.syntifi.casper.sdk.exception.CLValueEncodeException;
-import com.syntifi.casper.sdk.exception.DynamicInstanceException;
-import com.syntifi.casper.sdk.exception.NoSuchTypeException;
-import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
-
-/**
- * Defines an object as being capable of encoding with {@link CLValueEncoder}
- *
- * @author Alexandre Carvalho
- * @author Andre Bertolace
- * @since 0.0.1
- */
-public interface EncodableValue {
- /**
- * Called when the object's values must be encoded for serializing
- *
- * @param clve the encoder to be used
- * @throws IOException
- * @throws CLValueEncodeException
- * @throws DynamicInstanceException
- * @throws NoSuchTypeException
- */
- public void encode(CLValueEncoder clve)
- throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException;
-}
+package com.syntifi.casper.sdk.model.clvalue.encdec.interfaces;
+
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
+
+import java.io.IOException;
+
+/**
+ * Defines an object as being capable of encoding with {@link CLValueEncoder}
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+public interface EncodableValue {
+ /**
+ * Called when the object's values must be encoded for serializing
+ *
+ * @param clve the encoder to be used
+ * @param encodeType append encoded type?
+ * @throws NoSuchTypeException thrown if type not found
+ * @throws DynamicInstanceException thrown if it could not instantiate a type
+ * @throws CLValueEncodeException thrown if failed to encode a cl value
+ * @throws IOException thrown if an IO error occurs
+ */
+ void encode(CLValueEncoder clve, boolean encodeType)
+ throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException;
+}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/common/Digest.java b/src/main/java/com/syntifi/casper/sdk/model/common/Digest.java
new file mode 100644
index 00000000..908d44fe
--- /dev/null
+++ b/src/main/java/com/syntifi/casper/sdk/model/common/Digest.java
@@ -0,0 +1,56 @@
+package com.syntifi.casper.sdk.model.common;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
+import com.syntifi.casper.sdk.model.clvalue.encdec.interfaces.EncodableValue;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.bouncycastle.util.encoders.Hex;
+
+import java.io.IOException;
+
+/**
+ * Digest for Hex String
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class Digest implements EncodableValue {
+ @JsonValue
+ private String digest;
+
+ public byte[] getDigest() {
+ return Hex.decode(this.digest);
+ }
+
+ public void setDigest(byte[] hash) {
+ this.digest = Hex.toHexString(hash);
+ }
+
+ public static Digest digestFromBytes(byte[] bytes) {
+ Digest digest = new Digest();
+ digest.setDigest(bytes);
+ return digest;
+ }
+
+ /**
+ * Implements Digest encoder
+ */
+ @Override
+ public void encode(CLValueEncoder clve, boolean encodeType)
+ throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
+ clve.write(getDigest());
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/syntifi/casper/sdk/model/common/Ttl.java b/src/main/java/com/syntifi/casper/sdk/model/common/Ttl.java
new file mode 100644
index 00000000..60255f32
--- /dev/null
+++ b/src/main/java/com/syntifi/casper/sdk/model/common/Ttl.java
@@ -0,0 +1,56 @@
+package com.syntifi.casper.sdk.model.common;
+
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
+import com.syntifi.casper.sdk.model.clvalue.encdec.interfaces.EncodableValue;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.joda.time.Period;
+import org.joda.time.format.PeriodFormatter;
+import org.joda.time.format.PeriodFormatterBuilder;
+
+import java.io.IOException;
+
+/**
+ * TTL wrapper
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class Ttl implements EncodableValue {
+ @JsonValue
+ private String ttl;
+
+ public Long getTtl() {
+ PeriodFormatter formatter = new PeriodFormatterBuilder()
+ .appendDays().appendSuffix("d")
+ .appendHours().appendSuffix("h")
+ .appendMinutes().appendSuffix("m")
+ .toFormatter();
+
+ Period p = formatter.parsePeriod(ttl);
+ return p.toStandardDuration().getMillis();
+ }
+
+ /**
+ * Implements EncodableValue
+ */
+ @Override
+ public void encode(CLValueEncoder clve, boolean encodeType)
+ throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
+ clve.writeLong(getTtl());
+ }
+}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/contract/Contract.java b/src/main/java/com/syntifi/casper/sdk/model/contract/Contract.java
index f7cccb09..55c19004 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/contract/Contract.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/contract/Contract.java
@@ -1,19 +1,26 @@
package com.syntifi.casper.sdk.model.contract;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.util.List;
/**
* Methods and type signatures supported by a contract.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class Contract {
/**
@@ -21,7 +28,7 @@ public class Contract {
*/
@JsonProperty("contract_package_hash")
private String packageHash;
-
+
/**
* contract_wasm_hash(String) The hash address of the contract wasm.
*/
diff --git a/src/main/java/com/syntifi/casper/sdk/model/contract/ContractPackage.java b/src/main/java/com/syntifi/casper/sdk/model/contract/ContractPackage.java
index fe2c826b..f62c964e 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/contract/ContractPackage.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/contract/ContractPackage.java
@@ -1,19 +1,26 @@
package com.syntifi.casper.sdk.model.contract;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.util.List;
/**
* Contract definition, metadata, and security container
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class ContractPackage {
/**
diff --git a/src/main/java/com/syntifi/casper/sdk/model/contract/ContractVersion.java b/src/main/java/com/syntifi/casper/sdk/model/contract/ContractVersion.java
index 5fd3741a..d4823ffe 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/contract/ContractVersion.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/contract/ContractVersion.java
@@ -1,17 +1,24 @@
package com.syntifi.casper.sdk.model.contract;
import com.fasterxml.jackson.annotation.JsonProperty;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Contract version information
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class ContractVersion {
/**
diff --git a/src/main/java/com/syntifi/casper/sdk/model/contract/ContractWasm.java b/src/main/java/com/syntifi/casper/sdk/model/contract/ContractWasm.java
index 627b8eff..d9acd40c 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/contract/ContractWasm.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/contract/ContractWasm.java
@@ -1,17 +1,24 @@
package com.syntifi.casper.sdk.model.contract;
import com.fasterxml.jackson.annotation.JsonProperty;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* A contract's Wasm.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class ContractWasm {
/**
diff --git a/src/main/java/com/syntifi/casper/sdk/model/contract/DisabledVersion.java b/src/main/java/com/syntifi/casper/sdk/model/contract/DisabledVersion.java
index ffef99b3..3e6a8ea4 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/contract/DisabledVersion.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/contract/DisabledVersion.java
@@ -1,17 +1,24 @@
package com.syntifi.casper.sdk.model.contract;
import com.fasterxml.jackson.annotation.JsonProperty;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Contract disabled version information
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class DisabledVersion {
/**
diff --git a/src/main/java/com/syntifi/casper/sdk/model/contract/EntryPoint.java b/src/main/java/com/syntifi/casper/sdk/model/contract/EntryPoint.java
index 539531b9..bd14668b 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/contract/EntryPoint.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/contract/EntryPoint.java
@@ -1,8 +1,5 @@
package com.syntifi.casper.sdk.model.contract;
-import java.util.ArrayList;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -10,23 +7,31 @@
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
import com.syntifi.casper.sdk.model.clvalue.cltype.AbstractCLType;
import com.syntifi.casper.sdk.model.clvalue.cltype.AbstractCLTypeBasic;
-
import lombok.AllArgsConstructor;
-import lombok.Data;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.util.ArrayList;
+import java.util.List;
/**
* No description available
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class EntryPoint {
public interface EntryPointAccess {
- public Object getValue();
+ Object getValue();
}
public enum EntryPointAccessEnum implements EntryPointAccess {
@@ -40,10 +45,10 @@ public EntryPointAccessEnum getValue() {
}
@AllArgsConstructor
- public class EntryPointAccessList implements EntryPointAccess {
+ public static class EntryPointAccessList implements EntryPointAccess {
@Getter
- private List groups = new ArrayList<>();
+ private List groups;
@Override
public List getValue() {
@@ -57,7 +62,7 @@ public List getValue() {
public enum EntryPointType {
@JsonProperty("Session")
SESSION, @JsonProperty("Contract")
- CONTRACT;
+ CONTRACT
}
/**
@@ -72,7 +77,7 @@ public enum EntryPointType {
@JsonProperty("args")
private List args;
- /**
+ /**
* the {@link EntryPointType} Context of method execution
*/
@JsonProperty("entry_point_type")
@@ -92,8 +97,8 @@ public enum EntryPointType {
/**
* Accessor for jackson serialization
- *
- * @return String if access is enum, List if list.
+ *
+ * @return String if access is enum, List if is list.
*/
@JsonGetter("access")
private Object getJsonAccess() {
@@ -102,10 +107,11 @@ private Object getJsonAccess() {
/**
* Accessor for jackson serialization
- *
- * @param access
+ *
+ * @param access the access type of entry point
*/
@JsonSetter("access")
+ @SuppressWarnings("unchecked")
private void setJsonAccess(Object access) {
if (access instanceof String) {
this.access = EntryPointAccessEnum.PUBLIC;
@@ -116,8 +122,8 @@ private void setJsonAccess(Object access) {
/**
* Accessor for jackson serialization
- *
- * @param clType
+ *
+ * @param clType the cltype for ret
*/
@JsonSetter("ret")
@ExcludeFromJacocoGeneratedReport
@@ -127,7 +133,7 @@ protected void setJsonRet(AbstractCLType clType) {
/**
* Accessor for jackson serialization
- *
+ *
* @return String if cl_type is basic type, CLType object if not.
*/
@JsonGetter("ret")
diff --git a/src/main/java/com/syntifi/casper/sdk/model/contract/Group.java b/src/main/java/com/syntifi/casper/sdk/model/contract/Group.java
index db8203c3..27df0a3d 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/contract/Group.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/contract/Group.java
@@ -1,16 +1,24 @@
package com.syntifi.casper.sdk.model.contract;
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* A (labelled) "user group". Each method of a versioned contract may be
* associated with one or more user groups which are allowed to call it
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class Group {
private String name;
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/contract/Groups.java b/src/main/java/com/syntifi/casper/sdk/model/contract/Groups.java
index 17936094..ce650043 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/contract/Groups.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/contract/Groups.java
@@ -1,19 +1,26 @@
package com.syntifi.casper.sdk.model.contract;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.util.List;
/**
* Groups
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class Groups {
/**
diff --git a/src/main/java/com/syntifi/casper/sdk/model/contract/NamedKey.java b/src/main/java/com/syntifi/casper/sdk/model/contract/NamedKey.java
index d7edafad..cbce9555 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/contract/NamedKey.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/contract/NamedKey.java
@@ -1,17 +1,24 @@
package com.syntifi.casper.sdk.model.contract;
import com.fasterxml.jackson.annotation.JsonProperty;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* A named key.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class NamedKey {
/**
diff --git a/src/main/java/com/syntifi/casper/sdk/model/contract/Parameter.java b/src/main/java/com/syntifi/casper/sdk/model/contract/Parameter.java
index 453e6598..72d11f2c 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/contract/Parameter.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/contract/Parameter.java
@@ -7,17 +7,24 @@
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
import com.syntifi.casper.sdk.model.clvalue.cltype.AbstractCLType;
import com.syntifi.casper.sdk.model.clvalue.cltype.AbstractCLTypeBasic;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Parameter to a method
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class Parameter {
/**
@@ -40,7 +47,7 @@ protected void setJsonClType(AbstractCLType clType) {
/**
* The accessor for jackson serialization
- *
+ *
* @return String if cl_type is basic type, CLType object if not.
*/
@JsonGetter("cl_type")
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/Approval.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/Approval.java
index 4321fd85..1eeec6c9 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/Approval.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/Approval.java
@@ -1,19 +1,33 @@
package com.syntifi.casper.sdk.model.deploy;
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
+import com.syntifi.casper.sdk.model.clvalue.encdec.interfaces.EncodableValue;
import com.syntifi.casper.sdk.model.key.PublicKey;
import com.syntifi.casper.sdk.model.key.Signature;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.io.IOException;
/**
* A struct containing a signature and the public key of the signer
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
-public class Approval {
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class Approval implements EncodableValue {
/**
* @see PublicKey
@@ -24,4 +38,13 @@ public class Approval {
* @see Signature
*/
private Signature signature;
+
+ /**
+ * Implements Approval encoder
+ */
+ @Override
+ public void encode(CLValueEncoder clve, boolean encodeType) throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
+ signer.encode(clve, encodeType);
+ signature.encode(clve, encodeType);
+ }
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/Delegator.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/Delegator.java
index 207f9773..d723ffe5 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/Delegator.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/Delegator.java
@@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.key.PublicKey;
-
+import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -11,14 +11,15 @@
@Getter
@Setter
-@EqualsAndHashCode(callSuper = true)
+@AllArgsConstructor
@NoArgsConstructor
+@EqualsAndHashCode(callSuper = true)
@JsonTypeName("Delegator")
public class Delegator extends SeigniorageAllocation {
/**
* Delegator's public key
- *
+ *
* @see PublicKey
*/
@JsonProperty("delegator_public_key")
@@ -26,7 +27,7 @@ public class Delegator extends SeigniorageAllocation {
/**
* Validator's public key
- *
+ *
* @see PublicKey
*/
@JsonProperty("validator_public_key")
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/Deploy.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/Deploy.java
index 55a10c1f..ca10c5eb 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/Deploy.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/Deploy.java
@@ -1,26 +1,40 @@
package com.syntifi.casper.sdk.model.deploy;
-import java.util.List;
-
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
+import com.syntifi.casper.sdk.model.clvalue.encdec.interfaces.EncodableValue;
+import com.syntifi.casper.sdk.model.common.Digest;
import com.syntifi.casper.sdk.model.deploy.executabledeploy.ExecutableDeployItem;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.io.IOException;
+import java.util.List;
/**
- * A deploy; an item containing a smart contract along with the requester's
+ * Deploy an item containing a smart contract along with the requesters'
* signature(s)
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
-public class Deploy {
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class Deploy implements EncodableValue {
/**
* Hex-encoded deploy hash
*/
- private String hash;
+ private Digest hash;
/**
* @see DeployHeader
@@ -41,4 +55,20 @@ public class Deploy {
* @see ExecutableDeployItem
*/
private ExecutableDeployItem session;
+
+ /**
+ * Implements Deploy encoder
+ */
+ @Override
+ public void encode(CLValueEncoder clve, boolean encodeType) throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
+ header.encode(clve, true);
+ hash.encode(clve, true);
+ payment.encode(clve, true);
+ session.encode(clve, true);
+ clve.writeInt(approvals.size());
+ for (Approval approval : approvals) {
+ approval.encode(clve, true);
+ }
+ }
}
+
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployData.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployData.java
index 4690d3ec..1bab1ac3 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployData.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployData.java
@@ -1,19 +1,26 @@
package com.syntifi.casper.sdk.model.deploy;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.util.List;
/**
* Root class for a Casper deploy request
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class DeployData {
/**
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployHeader.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployHeader.java
index cd524bd7..44647977 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployHeader.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployHeader.java
@@ -1,35 +1,49 @@
package com.syntifi.casper.sdk.model.deploy;
-import java.math.BigInteger;
-import java.util.Date;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
+import com.syntifi.casper.sdk.model.clvalue.encdec.interfaces.EncodableValue;
+import com.syntifi.casper.sdk.model.common.Digest;
+import com.syntifi.casper.sdk.model.common.Ttl;
import com.syntifi.casper.sdk.model.key.PublicKey;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
/**
* The header portion of a [`Deploy`](struct.Deploy.html).
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
-public class DeployHeader {
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class DeployHeader implements EncodableValue {
/**
* @see PublicKey
*/
- private PublicKey account;
+ private PublicKey account;
/**
* Body hash
*/
@JsonProperty("body_hash")
- private String bodyHash;
+ private Digest bodyHash;
/**
* Chain name
@@ -40,13 +54,13 @@ public class DeployHeader {
/**
* Dependencies
*/
- private List dependencies;
+ private List dependencies;
/**
- * Gas price
+ * Gas price
*/
@JsonProperty("gas_price")
- private BigInteger gasPrice;
+ private Long gasPrice;
/**
* Timestamp formatted as per RFC 3339
@@ -58,5 +72,24 @@ public class DeployHeader {
/**
* Human-readable duration
*/
- private String ttl;
+ private Ttl ttl;
+
+ /**
+ * Implements DeployHearder encoder
+ */
+ @Override
+ public void encode(CLValueEncoder clve, boolean encodeType) throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
+ account.encode(clve, encodeType);
+ clve.writeLong(timeStamp.getTime());
+ ttl.encode(clve, encodeType);
+ clve.writeLong(gasPrice);
+ bodyHash.encode(clve, encodeType);
+ if (dependencies != null) {
+ clve.writeInt(dependencies.size());
+ for (Digest dependency : dependencies) {
+ clve.write(dependency.getDigest());
+ }
+ }
+ clve.writeString(chainName);
+ }
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployInfo.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployInfo.java
index 035d5ef1..0122aebb 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployInfo.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployInfo.java
@@ -1,23 +1,30 @@
package com.syntifi.casper.sdk.model.deploy;
-import java.math.BigInteger;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
import com.syntifi.casper.sdk.model.uref.URef;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.math.BigInteger;
+import java.util.List;
/**
* Information relating to the given Deploy
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class DeployInfo {
/**
@@ -39,7 +46,7 @@ public class DeployInfo {
/**
* Source purse used for payment of the Deploy.
- *
+ *
* @see URef
*/
private URef source;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployResult.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployResult.java
index fd18fd4a..c6e92f9a 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployResult.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/DeployResult.java
@@ -1,17 +1,24 @@
package com.syntifi.casper.sdk.model.deploy;
import com.fasterxml.jackson.annotation.JsonProperty;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Result for the account_put_deploy RPC response
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class DeployResult {
/**
@@ -27,5 +34,3 @@ public class DeployResult {
private String deployHash;
}
-
-
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/Entry.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/Entry.java
index 4f98bf2d..a86cc081 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/Entry.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/Entry.java
@@ -1,19 +1,26 @@
package com.syntifi.casper.sdk.model.deploy;
import com.syntifi.casper.sdk.model.deploy.transform.Transform;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* A transformation performed while executing a deploy.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class Entry {
-
+
/**
* The formatted string of the `Key`
*/
@@ -22,5 +29,5 @@ public class Entry {
/**
* @see Transform
*/
- private Transform transform;
+ private Transform transform;
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/EraInfo.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/EraInfo.java
index 954feeb2..dbebfb6e 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/EraInfo.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/EraInfo.java
@@ -1,21 +1,28 @@
package com.syntifi.casper.sdk.model.deploy;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.util.List;
/**
- * Auction metadata. Intended to be recorded at each era.
- *
+ * Auction metadata. Intended to be recorded at each era.
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class EraInfo {
-
+
/**
* @see SeigniorageAllocation
*/
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/ExecutionEffect.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/ExecutionEffect.java
index a1d1eaad..084a4a1c 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/ExecutionEffect.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/ExecutionEffect.java
@@ -1,19 +1,27 @@
package com.syntifi.casper.sdk.model.deploy;
-import java.util.List;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.util.List;
/**
* The effect of executing a single deploy
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class ExecutionEffect {
-
+
/**
* a list of {@link Operation}
*/
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/JsonExecutionResult.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/JsonExecutionResult.java
index 633a9cc0..166f6a56 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/JsonExecutionResult.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/JsonExecutionResult.java
@@ -2,20 +2,27 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.model.deploy.executionresult.ExecutionResult;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* The execution result of a single deploy.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class JsonExecutionResult {
-
- /**
+
+ /**
* The block hash.
*/
@JsonProperty("block_hash")
@@ -26,4 +33,3 @@ public class JsonExecutionResult {
*/
private ExecutionResult result;
}
-
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/NamedArg.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/NamedArg.java
index 53391662..c706a713 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/NamedArg.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/NamedArg.java
@@ -1,29 +1,78 @@
package com.syntifi.casper.sdk.model.deploy;
import com.fasterxml.jackson.annotation.JsonFormat;
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
import com.syntifi.casper.sdk.model.clvalue.AbstractCLValue;
+import com.syntifi.casper.sdk.model.clvalue.CLValueI32;
+import com.syntifi.casper.sdk.model.clvalue.CLValueI64;
+import com.syntifi.casper.sdk.model.clvalue.CLValueOption;
+import com.syntifi.casper.sdk.model.clvalue.CLValuePublicKey;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU128;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU256;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU32;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU512;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU64;
import com.syntifi.casper.sdk.model.clvalue.cltype.AbstractCLType;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
+import com.syntifi.casper.sdk.model.clvalue.encdec.interfaces.EncodableValue;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.io.IOException;
/**
* Named arguments to a contract
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
@JsonFormat(shape = JsonFormat.Shape.ARRAY)
-public class NamedArg {
+public class NamedArg implements EncodableValue {
- /**
- * The first value in the array is the type of the arg
- */
- private String type;
+ /**
+ * The first value in the array is the type of the arg
+ */
+ private String type;
- /**
- * The second value in the array is a CLValue type
- */
- private AbstractCLValue clValue;
+ /**
+ * The second value in the array is a CLValue type
+ */
+ private AbstractCLValue, P> clValue;
+
+ @Override
+ public void encode(CLValueEncoder clve, boolean encodeType)
+ throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
+ clve.writeString(type);
+ if (clValue instanceof CLValueI32 || clValue instanceof CLValueU32) {
+ clve.writeInt(32 / 8);
+ }
+ if (clValue instanceof CLValueI64 || clValue instanceof CLValueU64) {
+ clve.writeInt(64 / 8);
+ }
+ if (clValue instanceof CLValueU128 || clValue instanceof CLValueU256 ||
+ clValue instanceof CLValueU512 || clValue instanceof CLValuePublicKey){
+ CLValueEncoder localEncoder = new CLValueEncoder();
+ clValue.encode(localEncoder, false);
+ int size = localEncoder.toByteArray().length;
+ clve.writeInt(size); //removing the CLValue type byte at the end
+ }
+ if (clValue instanceof CLValueOption) {
+ CLValueEncoder localEncoder = new CLValueEncoder();
+ clValue.encode(localEncoder, false);
+ int size = localEncoder.toByteArray().length;
+ clve.writeInt(size); //removing the CLValue type byte at the end
+ }
+ clValue.encode(clve, encodeType);
+ }
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/OpKind.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/OpKind.java
index efa77ce5..35c21a7b 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/OpKind.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/OpKind.java
@@ -4,7 +4,7 @@
/**
* The type of operation performed while executing a deploy.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -15,7 +15,7 @@ public enum OpKind {
@JsonProperty("Write")
WRITE,
@JsonProperty("Add")
- ADD,
+ ADD,
@JsonProperty("NoOp")
- NOOP;
+ NOOP
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/Operation.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/Operation.java
index 5a68013e..84e01fd1 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/Operation.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/Operation.java
@@ -1,24 +1,32 @@
package com.syntifi.casper.sdk.model.deploy;
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* An operation performed while executing a deploy.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class Operation {
-
+
/**
* The formatted string of the `Key`
*/
private String key;
/**
- * @see OpKind
+ * @see OpKind
*/
private OpKind kind;
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/SeigniorageAllocation.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/SeigniorageAllocation.java
index 22260ec8..bd382c72 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/SeigniorageAllocation.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/SeigniorageAllocation.java
@@ -1,26 +1,33 @@
package com.syntifi.casper.sdk.model.deploy;
-import java.math.BigInteger;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.math.BigInteger;
/**
* Info about a seigniorage allocation for a validator
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
-@JsonSubTypes({ @JsonSubTypes.Type(value = Validator.class, name = "Validator"),
- @JsonSubTypes.Type(value = Delegator.class, name = "Delegator") })
+@JsonSubTypes({@JsonSubTypes.Type(value = Validator.class, name = "Validator"),
+ @JsonSubTypes.Type(value = Delegator.class, name = "Delegator")})
public class SeigniorageAllocation {
/**
@@ -31,13 +38,13 @@ public class SeigniorageAllocation {
@JsonProperty("amount")
@ExcludeFromJacocoGeneratedReport
- protected String getJsonAmount() {
+ protected String getJsonAmount() {
return this.amount.toString(10);
}
@JsonProperty("amount")
@ExcludeFromJacocoGeneratedReport
- protected void setJsonAmount(String value) {
+ protected void setJsonAmount(String value) {
this.amount = new BigInteger(value, 10);
}
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/UnbondingPurse.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/UnbondingPurse.java
index d3ae080f..4b4a7c2e 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/UnbondingPurse.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/UnbondingPurse.java
@@ -1,23 +1,30 @@
package com.syntifi.casper.sdk.model.deploy;
-import java.math.BigInteger;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
import com.syntifi.casper.sdk.model.key.PublicKey;
import com.syntifi.casper.sdk.model.uref.URef;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.math.BigInteger;
/**
* Unbonding Purse
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class UnbondingPurse {
/**
@@ -50,15 +57,25 @@ public class UnbondingPurse {
@JsonProperty("validator_public_key")
private PublicKey validatorPublicKey;
+ /**
+ * getter for unbondingAmount json serialization
+ *
+ * @return cost as expected for json serialization
+ */
@JsonProperty("unbonding_amount")
@ExcludeFromJacocoGeneratedReport
- protected String getJsonUnbondingAmount() {
+ protected String getJsonUnbondingAmount() {
return this.unbondingAmount.toString(10);
}
+ /**
+ * setter for unbondingAmount from json deserialized value
+ *
+ * @param value the deserialized value
+ */
@JsonProperty("unbonding_amount")
@ExcludeFromJacocoGeneratedReport
- protected void setJsonUnbondingAmount(String value) {
+ protected void setJsonUnbondingAmount(String value) {
this.unbondingAmount = new BigInteger(value, 10);
}
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/Validator.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/Validator.java
index 3226af0d..ab3cd4c2 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/Validator.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/Validator.java
@@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.key.PublicKey;
-
+import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -11,14 +11,15 @@
@Getter
@Setter
-@EqualsAndHashCode(callSuper = true)
+@AllArgsConstructor
@NoArgsConstructor
+@EqualsAndHashCode(callSuper = true)
@JsonTypeName("Validator")
public class Validator extends SeigniorageAllocation {
/**
* Validator's public key
- *
+ *
* @see PublicKey
*/
@JsonProperty("validator_public_key")
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/ExecutableDeployItem.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/ExecutableDeployItem.java
index 2ec9aab1..38fa9e08 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/ExecutableDeployItem.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/ExecutableDeployItem.java
@@ -1,29 +1,32 @@
package com.syntifi.casper.sdk.model.deploy.executabledeploy;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.syntifi.casper.sdk.model.clvalue.encdec.interfaces.EncodableValue;
/**
* Abstract Executable Deploy Item containing the runtime args of the contract.
* It can be any of the following types:
- *
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
* @see ModuleBytes
* @see StoredContractByHash
* @see StoredContractByName
* @see StoredVersionedContractByHash
* @see StoredVersionedContractByName
* @see Transfer
- *
- * @author Alexandre Carvalho
- * @author Andre Bertolace
* @since 0.0.1
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
-@JsonSubTypes({ @JsonSubTypes.Type(value = ModuleBytes.class, name = "ModuleBytes"),
+@JsonSubTypes({@JsonSubTypes.Type(value = ModuleBytes.class, name = "ModuleBytes"),
@JsonSubTypes.Type(value = StoredContractByHash.class, name = "StoredContractByHash"),
@JsonSubTypes.Type(value = StoredContractByName.class, name = "StoredContractByName"),
@JsonSubTypes.Type(value = StoredVersionedContractByHash.class, name = "StoredVersionedContractByHash"),
@JsonSubTypes.Type(value = StoredVersionedContractByName.class, name = "StoredVersionedContractByName"),
- @JsonSubTypes.Type(value = Transfer.class, name = "Transfer") })
-public interface ExecutableDeployItem {
+ @JsonSubTypes.Type(value = Transfer.class, name = "Transfer")})
+public interface ExecutableDeployItem extends EncodableValue {
+ @JsonIgnore
+ byte getOrder();
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/ModuleBytes.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/ModuleBytes.java
index 40e0c6a7..d5f8a681 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/ModuleBytes.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/ModuleBytes.java
@@ -1,22 +1,34 @@
package com.syntifi.casper.sdk.model.deploy.executabledeploy;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
import com.syntifi.casper.sdk.model.deploy.NamedArg;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.io.IOException;
+import java.util.List;
/**
* Abstract Executable Deploy Item containing the ModuleBytes of the contract.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
- * @since 0.0.1
* @see ExecutableDeployItem
+ * @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("ModuleBytes")
public class ModuleBytes implements ExecutableDeployItem {
@@ -29,5 +41,27 @@ public class ModuleBytes implements ExecutableDeployItem {
/**
* @see NamedArg
*/
- private List> args;
+ private List> args;
+
+
+ /**
+ * {@link ExecutableDeployItem} order 0
+ */
+ @Override
+ public byte getOrder() {
+ return 0x0;
+ }
+
+ /**
+ * Implements the ModuleBytes encoder
+ */
+ @Override
+ public void encode(CLValueEncoder clve, boolean encodeType) throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
+ clve.write(getOrder());
+ clve.writeString(getBytes());
+ clve.writeInt(args.size());
+ for (NamedArg> namedArg : args) {
+ namedArg.encode(clve, encodeType);
+ }
+ }
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredContractByHash.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredContractByHash.java
index 0df15928..91ef0603 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredContractByHash.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredContractByHash.java
@@ -1,29 +1,41 @@
package com.syntifi.casper.sdk.model.deploy.executabledeploy;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
import com.syntifi.casper.sdk.model.deploy.NamedArg;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.io.IOException;
+import java.util.List;
/**
* Abstract Executable Deploy Item containing the StoredContractByHash.
*
* @author Alexandre Carvalho
* @author Andre Bertolace
- * @since 0.0.1
* @see ExecutableDeployItem
+ * @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("StoredContractByHash")
public class StoredContractByHash implements ExecutableDeployItem {
/**
- * @see NamedArg
+ * Hex-encoded Hash
*/
- private List> args;
+ private String hash;
/**
* Entry Point
@@ -32,7 +44,31 @@ public class StoredContractByHash implements ExecutableDeployItem {
private String entryPoint;
/**
- * Hex-encoded Hash
+ * @see NamedArg
*/
- private String hash;
+ private List> args;
+
+ /**
+ * {@link ExecutableDeployItem} order 1
+ */
+ @Override
+ public byte getOrder() {
+ return 0x1;
+ }
+
+ /**
+ * Implements the StoredContractByHAsh encoder
+ */
+ @Override
+ public void encode(CLValueEncoder clve, boolean encodeType)
+ throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
+ clve.write(getOrder());
+ clve.writeString(getHash());
+ clve.writeString(getEntryPoint());
+ clve.writeInt(args.size());
+ for (NamedArg> namedArg : args) {
+ namedArg.encode(clve, true);
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredContractByName.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredContractByName.java
index 0035285c..ffed5e6b 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredContractByName.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredContractByName.java
@@ -1,29 +1,41 @@
package com.syntifi.casper.sdk.model.deploy.executabledeploy;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
import com.syntifi.casper.sdk.model.deploy.NamedArg;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.io.IOException;
+import java.util.List;
/**
* Abstract Executable Deploy Item containing the StoredContractByName.
*
* @author Alexandre Carvalho
* @author Andre Bertolace
- * @since 0.0.1
* @see ExecutableDeployItem
+ * @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("StoredContractByName")
public class StoredContractByName implements ExecutableDeployItem {
/**
- * @see NamedArg
+ * Contract name
*/
- private List> args;
+ private String name;
/**
* Entry Point
@@ -32,7 +44,30 @@ public class StoredContractByName implements ExecutableDeployItem {
private String entryPoint;
/**
- * Contract name
+ * @see NamedArg
*/
- private String name;
+ private List> args;
+
+ /**
+ * {@link ExecutableDeployItem} order 2
+ */
+ @Override
+ public byte getOrder() {
+ return 0x2;
+ }
+
+ /**
+ * Implements the StoredContractByHash encoder
+ */
+ @Override
+ public void encode(CLValueEncoder clve, boolean encodeType)
+ throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
+ clve.write(getOrder());
+ clve.writeString(getName());
+ clve.writeString(getEntryPoint());
+ clve.writeInt(args.size());
+ for (NamedArg> namedArg : args) {
+ namedArg.encode(clve, true);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredVersionedContractByHash.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredVersionedContractByHash.java
index e8fa6d92..6c4e88d5 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredVersionedContractByHash.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredVersionedContractByHash.java
@@ -1,29 +1,46 @@
package com.syntifi.casper.sdk.model.deploy.executabledeploy;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
import com.syntifi.casper.sdk.model.deploy.NamedArg;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.io.IOException;
+import java.util.List;
/**
* Abstract Executable Deploy Item containing the StoredVersionedContractByHash.
*
* @author Alexandre Carvalho
* @author Andre Bertolace
- * @since 0.0.1
* @see ExecutableDeployItem
+ * @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("StoredVersionedContractByHash")
public class StoredVersionedContractByHash implements ExecutableDeployItem {
/**
- * @see NamedArg
+ * Hex-encoded Hash
+ */
+ private String hash;
+
+ /**
+ * contract version
*/
- private List> args;
+ private long version;
/**
* Entry Point
@@ -32,13 +49,31 @@ public class StoredVersionedContractByHash implements ExecutableDeployItem {
private String entryPoint;
/**
- * Hex-encoded Hash
+ * @see NamedArg
*/
- private String hash;
+ private List> args;
/**
- * contract version
+ * {@link ExecutableDeployItem} order 3
*/
- private long version;
+ @Override
+ public byte getOrder() {
+ return 0x3;
+ }
+ /**
+ * Implements the StoredVersionedContractByHash encoder
+ */
+ @Override
+ public void encode(CLValueEncoder clve, boolean encodeType)
+ throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
+ clve.write(getOrder());
+ clve.writeString(getHash());
+ clve.writeLong(getVersion());
+ clve.writeString(getEntryPoint());
+ clve.writeInt(args.size());
+ for (NamedArg> namedArg : args) {
+ namedArg.encode(clve, true);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredVersionedContractByName.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredVersionedContractByName.java
index 42c901d7..5ec30d73 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredVersionedContractByName.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/StoredVersionedContractByName.java
@@ -1,29 +1,46 @@
package com.syntifi.casper.sdk.model.deploy.executabledeploy;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
import com.syntifi.casper.sdk.model.deploy.NamedArg;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.io.IOException;
+import java.util.List;
/**
* Abstract Executable Deploy Item containing the StoredVersionedContractByName.
*
* @author Alexandre Carvalho
* @author Andre Bertolace
- * @since 0.0.1
* @see ExecutableDeployItem
+ * @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("StoredVersionedContractByName")
public class StoredVersionedContractByName implements ExecutableDeployItem {
/**
- * List of @see NamedArg
+ * Contract Name
*/
- private List> args;
+ private String name;
+
+ /**
+ * contract version
+ */
+ private long version;
/**
* Entry Point
@@ -32,13 +49,32 @@ public class StoredVersionedContractByName implements ExecutableDeployItem {
private String entryPoint;
/**
- * Contract Name
+ * List of @see NamedArg
*/
- private String name;
+ private List> args;
/**
- * contract version
+ * {@link ExecutableDeployItem} order 4
*/
- private long version;
+ @Override
+ public byte getOrder() {
+ return 0x4;
+ }
+
+ /**
+ * Implements the StoredVersionedContractName encoder
+ */
+ @Override
+ public void encode(CLValueEncoder clve, boolean encodeType)
+ throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
+ clve.write(getOrder());
+ clve.writeString(getName());
+ clve.writeLong(getVersion());
+ clve.writeString(getEntryPoint());
+ clve.writeInt(args.size());
+ for (NamedArg> namedArg : args) {
+ namedArg.encode(clve, true);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/Transfer.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/Transfer.java
index 4812f639..99ccde1a 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/Transfer.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/executabledeploy/Transfer.java
@@ -1,27 +1,59 @@
package com.syntifi.casper.sdk.model.deploy.executabledeploy;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
import com.syntifi.casper.sdk.model.deploy.NamedArg;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.io.IOException;
+import java.util.List;
/**
* An AbstractExecutableDeployItem of Type Transfer containing the runtime args
* of the contract.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
@JsonTypeName("Transfer")
public class Transfer implements ExecutableDeployItem {
/**
- * List of @see NamedArg
+ * List of {@link NamedArg}
+ */
+ private List> args;
+
+ /**
+ * {@link ExecutableDeployItem} order 5
*/
- private List> args;
+ @Override
+ public byte getOrder() {
+ return 0x5;
+ }
+ /**
+ * Implements the Transfer encoder
+ */
+ @Override
+ public void encode(CLValueEncoder clve, boolean encodeType)
+ throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
+ clve.write(getOrder());
+ clve.writeInt(args.size());
+ for (NamedArg> namedArg : args) {
+ namedArg.encode(clve, true);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/executionresult/ExecutionResult.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/executionresult/ExecutionResult.java
index 973b8d71..89e6ed22 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/executionresult/ExecutionResult.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/executionresult/ExecutionResult.java
@@ -5,18 +5,18 @@
/**
* Abstract Executable Result containing the details of the contract execution.
- * It can be any of the following types:
- * @see Failure
- * @see Success
- *
+ * It can be any of the following types:
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Failure
+ * @see Success
* @since 0.0.1
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
@JsonSubTypes({
- @JsonSubTypes.Type(value = Failure.class, name = "Failure"),
- @JsonSubTypes.Type(value = Success.class, name = "Success")
+ @JsonSubTypes.Type(value = Failure.class, name = "Failure"),
+ @JsonSubTypes.Type(value = Success.class, name = "Success")
})
public interface ExecutionResult {
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/executionresult/Failure.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/executionresult/Failure.java
index b86e94f2..671126f9 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/executionresult/Failure.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/executionresult/Failure.java
@@ -1,26 +1,33 @@
package com.syntifi.casper.sdk.model.deploy.executionresult;
-import java.math.BigInteger;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
import com.syntifi.casper.sdk.model.deploy.ExecutionEffect;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.math.BigInteger;
+import java.util.List;
/**
* Abstract Executable Result of type Failure containing the details of the
* contract execution. It shows the result of a failed execution
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
- * @since 0.0.1
* @see ExecutionResult
+ * @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("Failure")
public class Failure implements ExecutionResult {
@@ -46,12 +53,22 @@ public class Failure implements ExecutionResult {
*/
private List transfers;
+ /**
+ * getter for cost json serialization
+ *
+ * @return cost as expected for json serialization
+ */
@JsonProperty("cost")
@ExcludeFromJacocoGeneratedReport
protected String getJsonCost() {
return this.cost.toString(10);
}
+ /**
+ * setter for cost from json deserialized value
+ *
+ * @param value the deserialized value
+ */
@JsonProperty("cost")
@ExcludeFromJacocoGeneratedReport
protected void setJsonCost(String value) {
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/executionresult/Success.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/executionresult/Success.java
index 7667365e..7a18cc57 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/executionresult/Success.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/executionresult/Success.java
@@ -1,26 +1,33 @@
package com.syntifi.casper.sdk.model.deploy.executionresult;
-import java.math.BigInteger;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
import com.syntifi.casper.sdk.model.deploy.ExecutionEffect;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.math.BigInteger;
+import java.util.List;
/**
* Abstract Executable Result of type Success containing the details of the
* contract execution. It shows the result of a successs execution
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
- * @since 0.0.1
* @see ExecutionResult
+ * @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("Success")
public class Success implements ExecutionResult {
@@ -40,12 +47,22 @@ public class Success implements ExecutionResult {
*/
private List transfers;
+ /**
+ * getter for cost json serialization
+ *
+ * @return cost as expected for json serialization
+ */
@JsonProperty("cost")
@ExcludeFromJacocoGeneratedReport
protected String getJsonCost() {
return this.cost.toString(10);
}
+ /**
+ * setter for cost from json deserialized value
+ *
+ * @param value the deserialized value
+ */
@JsonProperty("cost")
@ExcludeFromJacocoGeneratedReport
protected void setJsonCost(String value) {
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddInt32.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddInt32.java
index db06425f..b87e32ba 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddInt32.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddInt32.java
@@ -2,19 +2,25 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* An implmentation of Transform that Adds the given `i32`
- *
- * @see Transform
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Transform
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("AddInt32")
public class AddInt32 implements Transform {
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddKeys.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddKeys.java
index 7528f7be..8cc64ee8 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddKeys.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddKeys.java
@@ -1,23 +1,29 @@
package com.syntifi.casper.sdk.model.deploy.transform;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.contract.NamedKey;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.util.List;
/**
* An implmentation of Transform that Adds the given collection of named keys.
- *
- * @see Transform
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Transform
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("AddKeys")
public class AddKeys implements Transform {
@@ -26,5 +32,4 @@ public class AddKeys implements Transform {
*/
@JsonProperty("AddKeys")
private List addKeys;
-
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt128.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt128.java
index 5670f75d..9d58dd7f 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt128.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt128.java
@@ -7,7 +7,11 @@
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* An implmentation of Transform that Adds the given `u128`
@@ -18,7 +22,11 @@
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("AddUInt128")
public class AddUInt128 implements Transform {
@@ -28,15 +36,25 @@ public class AddUInt128 implements Transform {
@JsonIgnore
private BigInteger u128;
+ /**
+ * getter for u128 json serialization
+ *
+ * @return cost as expected for json serialization
+ */
@JsonProperty("AddUInt128")
@ExcludeFromJacocoGeneratedReport
- protected String getJsonU128() {
+ protected String getJsonU128() {
return this.u128.toString(10);
}
+ /**
+ * setter for u128 from json deserialized value
+ *
+ * @param value the deserialized value
+ */
@JsonProperty("AddUInt128")
@ExcludeFromJacocoGeneratedReport
- protected void setJsonU128(String value) {
+ protected void setJsonU128(String value) {
this.u128 = new BigInteger(value, 10);
}
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt256.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt256.java
index ac897030..f5e8a375 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt256.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt256.java
@@ -1,24 +1,30 @@
package com.syntifi.casper.sdk.model.deploy.transform;
-import java.math.BigInteger;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.math.BigInteger;
/**
* An implmentation of Transform that Adds the given `u256`
- *
- * @see Transform
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Transform
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("AddUInt256")
public class AddUInt256 implements Transform {
@@ -28,15 +34,25 @@ public class AddUInt256 implements Transform {
@JsonIgnore
private BigInteger u256;
+ /**
+ * getter for u256 json serialization
+ *
+ * @return cost as expected for json serialization
+ */
@JsonProperty("AddUInt256")
@ExcludeFromJacocoGeneratedReport
- protected String getJsonU256() {
+ protected String getJsonU256() {
return this.u256.toString(10);
}
+ /**
+ * setter for u256 from json deserialized value
+ *
+ * @param value the deserialized value
+ */
@JsonProperty("AddUInt256")
@ExcludeFromJacocoGeneratedReport
- protected void setJsonU256(String value) {
+ protected void setJsonU256(String value) {
this.u256 = new BigInteger(value, 10);
}
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt512.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt512.java
index c150e18e..d676495c 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt512.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt512.java
@@ -1,24 +1,30 @@
package com.syntifi.casper.sdk.model.deploy.transform;
-import java.math.BigInteger;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.math.BigInteger;
/**
* An implmentation of Transform that Adds the given `u512`
- *
- * @see Transform
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Transform
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("AddUInt512")
public class AddUInt512 implements Transform {
@@ -28,15 +34,25 @@ public class AddUInt512 implements Transform {
@JsonIgnore
private BigInteger u512;
+ /**
+ * getter for u512 json serialization
+ *
+ * @return cost as expected for json serialization
+ */
@JsonProperty("AddUInt512")
@ExcludeFromJacocoGeneratedReport
- protected String getJsonU512() {
+ protected String getJsonU512() {
return this.u512.toString(10);
}
+ /**
+ * setter for u512 from json deserialized value
+ *
+ * @param value the deserialized value
+ */
@JsonProperty("AddUInt512")
@ExcludeFromJacocoGeneratedReport
- protected void setJsonU512(String value) {
+ protected void setJsonU512(String value) {
this.u512 = new BigInteger(value, 10);
}
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt64.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt64.java
index b11fcc47..0ec62ef0 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt64.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/AddUInt64.java
@@ -1,24 +1,30 @@
package com.syntifi.casper.sdk.model.deploy.transform;
-import java.math.BigInteger;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.math.BigInteger;
/**
* An implmentation of Transform that Adds the given `u64`
- *
- * @see Transform
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Transform
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("AddUInt64")
public class AddUInt64 implements Transform {
@@ -28,16 +34,25 @@ public class AddUInt64 implements Transform {
@JsonIgnore
private BigInteger u64;
+ /**
+ * getter for u64 json serialization
+ *
+ * @return cost as expected for json serialization
+ */
@JsonProperty("AddUInt64")
@ExcludeFromJacocoGeneratedReport
- protected String getJsonU64() {
+ protected String getJsonU64() {
return this.u64.toString(10);
}
+ /**
+ * setter for u64 from json deserialized value
+ *
+ * @param value the deserialized value
+ */
@JsonProperty("AddUInt64")
@ExcludeFromJacocoGeneratedReport
- protected void setJsonU64(String value) {
+ protected void setJsonU64(String value) {
this.u64 = new BigInteger(value, 10);
}
-
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/Failure.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/Failure.java
index 201a1879..3c35153e 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/Failure.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/Failure.java
@@ -2,28 +2,33 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
- * An implmentation of Transform that gives details about a failed transformation,
+ * An implmentation of Transform that gives details about a failed
+ * transformation,
* containing an error message
- * @see Transform
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Transform
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("Failure")
public class Failure implements Transform {
-
+
/**
- * error message
+ * error message
*/
@JsonProperty("Failure")
private String failure;
-
}
-
-
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/Transform.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/Transform.java
index 5457c0e0..6b91bee0 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/Transform.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/Transform.java
@@ -6,8 +6,10 @@
/**
* Abstract Transform containing the actual transformation performed while
- * executing a deploy. It can be any of the following types:
- *
+ * executing a deployment. It can be any of the following types:
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
* @see AddInt32
* @see AddUInt64
* @see AddUInt128
@@ -23,9 +25,6 @@
* @see WriteEraInfo
* @see WriteTransfer
* @see WriteWithdraw
- *
- * @author Alexandre Carvalho
- * @author Andre Bertolace
* @since 0.0.1
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/TransformTypeData.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/TransformTypeData.java
index 02a586b1..f851df75 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/TransformTypeData.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/TransformTypeData.java
@@ -1,7 +1,6 @@
package com.syntifi.casper.sdk.model.deploy.transform;
import com.syntifi.casper.sdk.exception.NoSuchTypeException;
-
import lombok.Getter;
@Getter
@@ -28,17 +27,17 @@ public enum TransformTypeData {
private final String name;
private final Class> clazz;
- private TransformTypeData(String name, Class> clazz) {
+ TransformTypeData(String name, Class> clazz) {
this.name = name;
this.clazz = clazz;
}
/**
- * Retrieve Transform implementation class from Transform name
- *
+ * Retrieve Transform implementation class from Transform name
+ *
* @param name {@link TransformTypeData} class name
* @return the class object for the {@link TransformTypeData}
- * @throws NoSuchTypeException
+ * @throws NoSuchTypeException if no type is found for given name
*/
public static Class> getClassByName(String name) throws NoSuchTypeException {
for (TransformTypeData t : values()) {
@@ -47,5 +46,5 @@ public static Class> getClassByName(String name) throws NoSuchTypeException {
}
}
throw new NoSuchTypeException();
- }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteAccount.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteAccount.java
index 601d58f4..d32500ec 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteAccount.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteAccount.java
@@ -1,27 +1,32 @@
package com.syntifi.casper.sdk.model.deploy.transform;
-
+
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
- * An implmentation of Transform that Writes the given Account to global state.
- * @see Transform
- *
+ * An implementation of Transform that Writes the given Account to global state.
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Transform
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("WriteAccount")
public class WriteAccount implements Transform {
-
+
/**
- * Hex-encoded account hash
+ * Hex-encoded account hash
*/
@JsonProperty("WriteAccount")
private String account;
}
-
-
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteBid.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteBid.java
index c70afe37..e3203f28 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteBid.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteBid.java
@@ -3,27 +3,31 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.bid.Bid;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
- * An implmentation of Transform that Writes the given Bid to global state.
- * @see Transform
- *
+ * An implementation of Transform that Writes the given Bid to global state.
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Transform
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("WriteBid")
public class WriteBid implements Transform {
-
+
/**
- * @see Bid
+ * @see Bid
*/
@JsonProperty("WriteBid")
private Bid bid;
}
-
-
-
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteCLValue.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteCLValue.java
index 4a835f03..67c81135 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteCLValue.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteCLValue.java
@@ -1,25 +1,32 @@
package com.syntifi.casper.sdk.model.deploy.transform;
-
+
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.clvalue.AbstractCLValue;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
- * An implmentation of Transform that Writes the given CLValue to global state.
- * @see Transform
- *
+ * An implementation of Transform that Writes the given CLValue to global state.
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Transform
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("WriteCLValue")
public class WriteCLValue implements Transform {
-
+
/**
- * @see AbstractCLValue
+ * @see AbstractCLValue
*/
@JsonProperty("WriteCLValue")
private AbstractCLValue, ?> clvalue;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteContract.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteContract.java
index 21a99928..ba2135d9 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteContract.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteContract.java
@@ -5,30 +5,29 @@
import com.fasterxml.jackson.annotation.JsonUnwrapped;
/**
- * An implmentation of Transform that specifies any of the enum values
- * - Identity
+ * An implementation of Transform that specifies any of the enum values
+ * - Identity
* - WriteContractWasm
* - WriteContract
* - WriteContractPackage
- *
- * @see Transform
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Transform
* @since 0.0.1
*/
@JsonTypeName("WriteContract")
public enum WriteContract implements Transform {
@JsonProperty("Identity")
@JsonUnwrapped
- IDENTITY,
+ IDENTITY,
@JsonProperty("WriteContractWasm")
@JsonUnwrapped
- WRITE_CONTRACT_WASM,
+ WRITE_CONTRACT_WASM,
@JsonProperty("WriteContract")
@JsonUnwrapped
- WRITE_CONTRACT,
+ WRITE_CONTRACT,
@JsonProperty("WriteContractPackage")
@JsonUnwrapped
- WRITE_CONTRACT_PACKAGE;
+ WRITE_CONTRACT_PACKAGE
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteDeployInfo.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteDeployInfo.java
index 00356dc2..9264e096 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteDeployInfo.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteDeployInfo.java
@@ -3,27 +3,32 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.deploy.DeployInfo;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
- * An implmentation of Transform that Writes the given DeployInfo to global state.
- * @see Transform
- *
+ * An implementation of Transform that Writes the given DeployInfo to global
+ * state.
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Transform
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("WriteDeployInfo")
public class WriteDeployInfo implements Transform {
-
+
/**
- * @see DeployInfo
+ * @see DeployInfo
*/
@JsonProperty("WriteDeployInfo")
private DeployInfo deployInfo;
}
-
-
-
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteEraInfo.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteEraInfo.java
index 8b169e33..d6c706cc 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteEraInfo.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteEraInfo.java
@@ -3,28 +3,31 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.deploy.EraInfo;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
- * An implmentation of Transform that Writes the given EraInfo to global state.
- * @see Transform
- *
+ * An implementation of Transform that Writes the given EraInfo to global state.
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Transform
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("WriteEraInfo")
public class WriteEraInfo implements Transform {
-
+
/**
- * @see EraInfo
+ * @see EraInfo
*/
@JsonProperty("WriteEraInfo")
private EraInfo deployInfo;
}
-
-
-
-
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteTransfer.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteTransfer.java
index 0a258d03..39857bef 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteTransfer.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteTransfer.java
@@ -3,26 +3,31 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.transfer.Transfer;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
- * An implmentation of Transform that Writes the given Transfer to global state.
- * @see Transform
- *
+ * An implementation of Transform that Writes the given Transfer to global state.
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Transform
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("WriteTransfer")
public class WriteTransfer implements Transform {
-
+
/**
- * @see Transfer
+ * @see Transfer
*/
@JsonProperty("WriteTransfer")
private Transfer transfer;
}
-
-
diff --git a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteWithdraw.java b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteWithdraw.java
index 16479cff..d52182d7 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteWithdraw.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/deploy/transform/WriteWithdraw.java
@@ -1,29 +1,35 @@
package com.syntifi.casper.sdk.model.deploy.transform;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.deploy.UnbondingPurse;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.util.List;
/**
- * An implmentation of Transform that Writes the given Withdraw to global state.
- *
- * @see Transform
- *
+ * An implementation of Transform that Writes the given Withdraw to global state.
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
+ * @see Transform
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("WriteWithdraw")
public class WriteWithdraw implements Transform {
/**
* Array of UnbondingPurse
- *
+ *
* @see UnbondingPurse
*/
@JsonProperty("WriteWithdraw")
diff --git a/src/main/java/com/syntifi/casper/sdk/model/dictionary/DictionaryData.java b/src/main/java/com/syntifi/casper/sdk/model/dictionary/DictionaryData.java
index 6667df97..75300d07 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/dictionary/DictionaryData.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/dictionary/DictionaryData.java
@@ -1,23 +1,29 @@
package com.syntifi.casper.sdk.model.dictionary;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.model.storedvalue.StoredValue;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Dictionary key and stored value
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class DictionaryData {
-
+
/**
- * The RPC API version
+ * The RPC API version
*/
@JsonProperty("api_version")
private String apiVersion;
@@ -29,13 +35,13 @@ public class DictionaryData {
private String dictionaryKey;
/**
- * The merkle proof
+ * The merkle proof
*/
@JsonProperty("merkle_proof")
private String merkleProof;
/**
- * The stored value
+ * The stored value
*/
@JsonProperty("stored_value")
private StoredValue> storedValue;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/era/EraInfoData.java b/src/main/java/com/syntifi/casper/sdk/model/era/EraInfoData.java
index 64ad868b..3ddb6072 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/era/EraInfoData.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/era/EraInfoData.java
@@ -3,14 +3,20 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* An EraInfo from the network
- *
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class EraInfoData {
/**
diff --git a/src/main/java/com/syntifi/casper/sdk/model/era/EraSummary.java b/src/main/java/com/syntifi/casper/sdk/model/era/EraSummary.java
index 9bcd369c..b73d49bd 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/era/EraSummary.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/era/EraSummary.java
@@ -2,17 +2,22 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.model.storedvalue.StoredValueEraInfo;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* The summary of an era
- *
- *
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class EraSummary {
-
+
/**
* The block hash
*/
diff --git a/src/main/java/com/syntifi/casper/sdk/model/era/JsonEraEnd.java b/src/main/java/com/syntifi/casper/sdk/model/era/JsonEraEnd.java
index 6d5ebaf4..5b81f320 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/era/JsonEraEnd.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/era/JsonEraEnd.java
@@ -1,18 +1,29 @@
package com.syntifi.casper.sdk.model.era;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.util.List;
/**
* Casper block root Era data
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
+
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class JsonEraEnd {
-
+
/**
* @see JsonEraReport
*/
diff --git a/src/main/java/com/syntifi/casper/sdk/model/era/JsonEraReport.java b/src/main/java/com/syntifi/casper/sdk/model/era/JsonEraReport.java
index febededf..cfb6e8b9 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/era/JsonEraReport.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/era/JsonEraReport.java
@@ -1,36 +1,43 @@
package com.syntifi.casper.sdk.model.era;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.model.key.PublicKey;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.util.List;
/**
* Equivocation and reward information to be included in the terminal block.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see JsonEraEnd
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class JsonEraReport {
-
+
/**
- * List of @see PublicKey
+ * List of @see PublicKey
*/
@JsonProperty("inactive_validators")
private List inactiveValidators;
/**
- * List of @see PublicKey
+ * List of @see PublicKey
*/
private List equivocators;
-
+
/**
- * List of @see Reward
+ * List of @see Reward
*/
private List rewards;
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/era/JsonEraValidators.java b/src/main/java/com/syntifi/casper/sdk/model/era/JsonEraValidators.java
index 3bb24f6d..85c98976 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/era/JsonEraValidators.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/era/JsonEraValidators.java
@@ -1,20 +1,27 @@
package com.syntifi.casper.sdk.model.era;
-import java.math.BigInteger;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.math.BigInteger;
+import java.util.List;
/**
* An entry in the validator map.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class JsonEraValidators {
/**
diff --git a/src/main/java/com/syntifi/casper/sdk/model/era/JsonValidatorWeight.java b/src/main/java/com/syntifi/casper/sdk/model/era/JsonValidatorWeight.java
index 4b6e8342..6864e8b5 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/era/JsonValidatorWeight.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/era/JsonValidatorWeight.java
@@ -1,23 +1,30 @@
package com.syntifi.casper.sdk.model.era;
-import java.math.BigInteger;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
import com.syntifi.casper.sdk.model.key.PublicKey;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.math.BigInteger;
/**
* Casper block validator weight
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see JsonEraEnd
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class JsonValidatorWeight {
/**
diff --git a/src/main/java/com/syntifi/casper/sdk/model/era/Reward.java b/src/main/java/com/syntifi/casper/sdk/model/era/Reward.java
index 95c5d0ae..142fb2e3 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/era/Reward.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/era/Reward.java
@@ -1,25 +1,32 @@
package com.syntifi.casper.sdk.model.era;
import com.syntifi.casper.sdk.model.key.PublicKey;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Casper block era reward data
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see JsonEraReport
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class Reward {
-
+
/**
* @see PublicKey
*/
private PublicKey validator;
-
+
/**
* amount
*/
diff --git a/src/main/java/com/syntifi/casper/sdk/model/era/ValidatorWeight.java b/src/main/java/com/syntifi/casper/sdk/model/era/ValidatorWeight.java
index 934afbcc..108218be 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/era/ValidatorWeight.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/era/ValidatorWeight.java
@@ -1,23 +1,30 @@
package com.syntifi.casper.sdk.model.era;
-import java.math.BigInteger;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
import com.syntifi.casper.sdk.model.key.PublicKey;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.math.BigInteger;
/**
* Casper block validator weight
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see JsonEraEnd
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class ValidatorWeight {
/**
diff --git a/src/main/java/com/syntifi/casper/sdk/model/key/AbstractSerializedKeyTaggedHex.java b/src/main/java/com/syntifi/casper/sdk/model/key/AbstractSerializedKeyTaggedHex.java
index f6047511..3494e47e 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/key/AbstractSerializedKeyTaggedHex.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/key/AbstractSerializedKeyTaggedHex.java
@@ -2,19 +2,33 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
import com.syntifi.casper.sdk.model.clvalue.encdec.StringByteHelper;
+import com.syntifi.casper.sdk.model.clvalue.encdec.interfaces.EncodableValue;
+import lombok.AllArgsConstructor;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.io.IOException;
/**
* Hex-encoded key, including the tag byte.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
-public abstract class AbstractSerializedKeyTaggedHex {
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+@EqualsAndHashCode(of = {"tag", "key"})
+public abstract class AbstractSerializedKeyTaggedHex implements EncodableValue {
/**
* @see Tag
@@ -30,7 +44,17 @@ public abstract class AbstractSerializedKeyTaggedHex {
@JsonValue
public String getAlgoTaggedHex() {
- return StringByteHelper.convertBytesToHex(new byte[] { this.tag.getByteTag() })
+ return StringByteHelper.convertBytesToHex(new byte[]{this.tag.getByteTag()})
+ StringByteHelper.convertBytesToHex(this.getKey());
}
+
+ /**
+ * Implements TaggedHEx encoder
+ */
+ @Override
+ public void encode(CLValueEncoder clve, boolean encodeType)
+ throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
+ clve.write(getTag().getByteTag());
+ clve.write(getKey());
+ }
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/key/AlgorithmTag.java b/src/main/java/com/syntifi/casper/sdk/model/key/AlgorithmTag.java
index 3c2ee32b..0a38033b 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/key/AlgorithmTag.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/key/AlgorithmTag.java
@@ -1,16 +1,15 @@
package com.syntifi.casper.sdk.model.key;
-import java.security.NoSuchAlgorithmException;
-
import com.syntifi.casper.sdk.model.storedvalue.StoredValueData;
-
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
+import java.security.NoSuchAlgorithmException;
+
/**
* Algorithm byte tag
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see StoredValueData
diff --git a/src/main/java/com/syntifi/casper/sdk/model/key/Key.java b/src/main/java/com/syntifi/casper/sdk/model/key/Key.java
index d4b5bf79..ad2b7e80 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/key/Key.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/key/Key.java
@@ -1,25 +1,26 @@
package com.syntifi.casper.sdk.model.key;
-import java.util.Arrays;
-
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.syntifi.casper.sdk.exception.InvalidByteStringException;
import com.syntifi.casper.sdk.exception.NoSuchKeyTagException;
import com.syntifi.casper.sdk.jackson.deserializer.KeyDeserializer;
import com.syntifi.casper.sdk.model.clvalue.encdec.StringByteHelper;
-
+import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
+import java.util.Arrays;
+
/**
* Hex-encoded key, including the tag info.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@JsonDeserialize(using = KeyDeserializer.class)
@NoArgsConstructor
+@EqualsAndHashCode(callSuper = true)
public class Key extends AbstractSerializedKeyTaggedHex {
public static Key fromTaggedHexString(String hex) throws NoSuchKeyTagException, InvalidByteStringException {
diff --git a/src/main/java/com/syntifi/casper/sdk/model/key/KeyTag.java b/src/main/java/com/syntifi/casper/sdk/model/key/KeyTag.java
index 1a6eb9d2..8608627c 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/key/KeyTag.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/key/KeyTag.java
@@ -2,14 +2,11 @@
import com.syntifi.casper.sdk.exception.NoSuchKeyTagException;
import com.syntifi.casper.sdk.model.storedvalue.StoredValueData;
-
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
- *
- *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see StoredValueData
diff --git a/src/main/java/com/syntifi/casper/sdk/model/key/PublicKey.java b/src/main/java/com/syntifi/casper/sdk/model/key/PublicKey.java
index 008fb6dd..4c81a1f1 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/key/PublicKey.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/key/PublicKey.java
@@ -1,19 +1,22 @@
package com.syntifi.casper.sdk.model.key;
-import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
-
import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.syntifi.casper.sdk.exception.InvalidByteStringException;
import com.syntifi.casper.sdk.jackson.deserializer.PublicKeyDeserializer;
import com.syntifi.casper.sdk.model.clvalue.encdec.StringByteHelper;
-
+import com.syntifi.crypto.key.AbstractPublicKey;
+import com.syntifi.crypto.key.Ed25519PublicKey;
+import com.syntifi.crypto.key.Secp256k1PublicKey;
import lombok.NoArgsConstructor;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+
/**
* Hex-encoded cryptographic public key, including the algorithm tag prefix.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -24,17 +27,43 @@ public class PublicKey extends AbstractSerializedKeyTaggedHex {
public static PublicKey fromTaggedHexString(String hex)
throws NoSuchAlgorithmException, InvalidByteStringException {
- PublicKey object = new PublicKey();
byte[] bytes = StringByteHelper.hexStringToByteArray(hex);
+ return PublicKey.fromBytes(bytes);
+ }
+
+ public static PublicKey fromBytes(byte[] bytes) throws NoSuchAlgorithmException {
+ PublicKey object = new PublicKey();
object.setTag(AlgorithmTag.getByTag(bytes[0]));
object.setKey(Arrays.copyOfRange(bytes, 1, bytes.length));
+
return object;
}
+ public static PublicKey fromAbstractPublicKey(AbstractPublicKey key) {
+ PublicKey object = new PublicKey();
+ object.setTag((key instanceof Secp256k1PublicKey)
+ ? AlgorithmTag.SECP256K1
+ : AlgorithmTag.ED25519);
+ object.setKey(key.getKey());
+ return object;
+ }
+
+
@JsonCreator
public void createPublicKey(String key) throws NoSuchAlgorithmException, InvalidByteStringException {
PublicKey obj = PublicKey.fromTaggedHexString(key);
this.setTag(obj.getTag());
this.setKey(obj.getKey());
}
+
+ @JsonIgnore
+ public AbstractPublicKey getPubKey() throws NoSuchAlgorithmException {
+ if (getTag().equals(AlgorithmTag.ED25519)) {
+ return new Ed25519PublicKey(getKey());
+ } else if (getTag().equals(AlgorithmTag.SECP256K1)) {
+ return new Secp256k1PublicKey(getKey());
+ } else {
+ throw new NoSuchAlgorithmException();
+ }
+ }
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/key/Signature.java b/src/main/java/com/syntifi/casper/sdk/model/key/Signature.java
index 76f71d37..cd653876 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/key/Signature.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/key/Signature.java
@@ -2,9 +2,13 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.syntifi.casper.sdk.jackson.deserializer.SignatureDeserializer;
-
+import com.syntifi.crypto.key.AbstractPrivateKey;
+import com.syntifi.crypto.key.Secp256k1PrivateKey;
+import lombok.Builder;
import lombok.NoArgsConstructor;
+import java.security.GeneralSecurityException;
+
/**
* Hex-encoded cryptographic public key, including the algorithm tag prefix.
*
@@ -14,5 +18,16 @@
*/
@JsonDeserialize(using = SignatureDeserializer.class)
@NoArgsConstructor
+@Builder
public class Signature extends AbstractSerializedKeyTaggedHex {
+
+ public static Signature sign(AbstractPrivateKey key, byte[] msg) throws GeneralSecurityException {
+ byte[] signatureBytes = key.sign(msg);
+ Signature signature = new Signature();
+ signature.setKey(signatureBytes);
+ signature.setTag((key instanceof Secp256k1PrivateKey)
+ ? AlgorithmTag.SECP256K1
+ : AlgorithmTag.ED25519);
+ return signature;
+ }
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/key/Tag.java b/src/main/java/com/syntifi/casper/sdk/model/key/Tag.java
index f5fe2080..510263aa 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/key/Tag.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/key/Tag.java
@@ -2,11 +2,11 @@
/**
* Interface for tagged keys
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
public interface Tag {
- public byte getByteTag();
+ byte getByteTag();
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/peer/PeerData.java b/src/main/java/com/syntifi/casper/sdk/model/peer/PeerData.java
index d94f4073..32694e86 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/peer/PeerData.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/peer/PeerData.java
@@ -1,20 +1,27 @@
package com.syntifi.casper.sdk.model.peer;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.util.List;
/**
* Root class for a Casper peer info request
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see PeerData
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class PeerData {
/**
@@ -22,7 +29,7 @@ public class PeerData {
*/
@JsonProperty("api_version")
private String apiVersion;
-
+
/**
* List of @see PeerEntry
*/
diff --git a/src/main/java/com/syntifi/casper/sdk/model/peer/PeerEntry.java b/src/main/java/com/syntifi/casper/sdk/model/peer/PeerEntry.java
index df0a1965..dbcf2c13 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/peer/PeerEntry.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/peer/PeerEntry.java
@@ -1,24 +1,31 @@
package com.syntifi.casper.sdk.model.peer;
import com.fasterxml.jackson.annotation.JsonProperty;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* The node ID and network address of each connected peer.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class PeerEntry {
/**
* IP:PORT
*/
private String address;
-
+
/**
* node ID
*/
diff --git a/src/main/java/com/syntifi/casper/sdk/model/stateroothash/StateRootHashData.java b/src/main/java/com/syntifi/casper/sdk/model/stateroothash/StateRootHashData.java
index db48f2b2..03e5c42b 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/stateroothash/StateRootHashData.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/stateroothash/StateRootHashData.java
@@ -1,25 +1,32 @@
package com.syntifi.casper.sdk.model.stateroothash;
import com.fasterxml.jackson.annotation.JsonProperty;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Root class for a Casper state root hash request
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class StateRootHashData {
-
+
/**
* The RPC API version
*/
@JsonProperty("api_version")
private String apiVersion;
-
+
/**
* Hash
*/
diff --git a/src/main/java/com/syntifi/casper/sdk/model/status/ActivationPoint.java b/src/main/java/com/syntifi/casper/sdk/model/status/ActivationPoint.java
index 0e418ba4..96021f77 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/status/ActivationPoint.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/status/ActivationPoint.java
@@ -1,27 +1,34 @@
package com.syntifi.casper.sdk.model.status;
-import java.math.BigInteger;
-import java.sql.Date;
-
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.math.BigInteger;
+import java.sql.Date;
/**
* The first era to which the associated protocol version applies
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class ActivationPoint {
/**
- * Era ID
+ * Era ID
*/
@JsonIgnore
private BigInteger eraId;
@@ -35,13 +42,13 @@ public class ActivationPoint {
@JsonProperty("era_id")
@ExcludeFromJacocoGeneratedReport
- protected String getJsonEraId() {
+ protected String getJsonEraId() {
return this.eraId.toString(10);
}
@JsonProperty("era_id")
@ExcludeFromJacocoGeneratedReport
- protected void setJsonEraId(String value) {
+ protected void setJsonEraId(String value) {
this.eraId = new BigInteger(value, 10);
}
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/status/MinimalBlockInfo.java b/src/main/java/com/syntifi/casper/sdk/model/status/MinimalBlockInfo.java
index 5b68b565..30d3df63 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/status/MinimalBlockInfo.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/status/MinimalBlockInfo.java
@@ -1,24 +1,31 @@
package com.syntifi.casper.sdk.model.status;
-import java.math.BigInteger;
-import java.sql.Date;
-
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.model.key.PublicKey;
import com.syntifi.casper.sdk.model.peer.PeerData;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.math.BigInteger;
+import java.sql.Date;
/**
* Minimal info of a `Block`
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see PeerData
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class MinimalBlockInfo {
/**
diff --git a/src/main/java/com/syntifi/casper/sdk/model/status/NextUpgrade.java b/src/main/java/com/syntifi/casper/sdk/model/status/NextUpgrade.java
index 19dc4f41..f6db78b1 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/status/NextUpgrade.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/status/NextUpgrade.java
@@ -1,27 +1,37 @@
package com.syntifi.casper.sdk.model.status;
import com.fasterxml.jackson.annotation.JsonProperty;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Information about the next scheduled upgrade
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class NextUpgrade {
/**
* @see ActivationPoint
*/
@JsonProperty("activation_point")
- private ActivationPoint activationPoint;
+ //private ActivationPoint activationPoint;
+ // TODO: the response from the JSON-RPC is different from that specified in the RPC-JSON documentation.
+ // Here it is adapted to comply with the API response
+ private Integer activationPoint;
/**
- * Protocol version
+ * Protocol version
*/
@JsonProperty("protocol_version")
private String protocolVersion;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/status/StatusData.java b/src/main/java/com/syntifi/casper/sdk/model/status/StatusData.java
index 31982b93..419be353 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/status/StatusData.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/status/StatusData.java
@@ -1,21 +1,28 @@
package com.syntifi.casper.sdk.model.status;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.model.key.PublicKey;
import com.syntifi.casper.sdk.model.peer.PeerEntry;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.util.List;
/**
* Returns the current status of the node
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class StatusData {
/**
@@ -56,7 +63,7 @@ public class StatusData {
/**
* List of
- *
+ *
* @see PeerEntry
*/
private List peers;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValue.java b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValue.java
index 6c2379fd..0bb7d7c2 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValue.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValue.java
@@ -6,7 +6,7 @@
/**
* Stored Value interface and jackson resolver for subtypes
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -14,5 +14,5 @@
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
@JsonTypeResolver(StoredValueResolver.class)
public interface StoredValue {
- public T getValue();
+ T getValue();
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueAccount.java b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueAccount.java
index 6346f360..d11ad3c4 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueAccount.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueAccount.java
@@ -3,18 +3,27 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.account.Account;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Stored Value for {@link Account}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see StoredValue
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@EqualsAndHashCode
@JsonTypeName("Account")
public class StoredValueAccount implements StoredValue {
@JsonProperty("Account")
diff --git a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueBid.java b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueBid.java
index 0043ad09..d77a272e 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueBid.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueBid.java
@@ -3,18 +3,27 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.bid.Bid;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Stored Value for {@link Bid}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see StoredValue
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@EqualsAndHashCode
@JsonTypeName("Bid")
public class StoredValueBid implements StoredValue {
@JsonProperty("Bid")
diff --git a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueCLValue.java b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueCLValue.java
index c8ad0713..766805c1 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueCLValue.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueCLValue.java
@@ -4,20 +4,56 @@
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.clvalue.AbstractCLValue;
import com.syntifi.casper.sdk.model.clvalue.cltype.AbstractCLType;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.util.Objects;
/**
* Stored Value for {@link AbstractCLType}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see StoredValue
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@JsonTypeName("CLValue")
public class StoredValueCLValue implements StoredValue> {
@JsonProperty("CLValue")
private AbstractCLValue, ?> value;
+
+ @Override
+ public boolean equals(final Object o) {
+ if (o == this)
+ return true;
+ if (!(o instanceof StoredValueCLValue))
+ return false;
+ final StoredValueCLValue other = (StoredValueCLValue) o;
+ if (!other.canEqual(this))
+ return false;
+ final Object this$value = this.getValue();
+ final Object other$value = other.getValue();
+ return Objects.equals(this$value, other$value);
+ }
+
+ protected boolean canEqual(final Object other) {
+ return other instanceof StoredValueCLValue;
+ }
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final Object $value = this.getValue();
+ result = result * PRIME + ($value == null ? 43 : $value.hashCode());
+ return result;
+ }
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueContract.java b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueContract.java
index 9f1c30e3..eda386c2 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueContract.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueContract.java
@@ -3,18 +3,27 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.contract.Contract;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Stored Value for {@link Contract}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see StoredValue
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@EqualsAndHashCode
@JsonTypeName("Contract")
public class StoredValueContract implements StoredValue {
@JsonProperty("Contract")
diff --git a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueContractPackage.java b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueContractPackage.java
index bd2fa22a..3a7fb71c 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueContractPackage.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueContractPackage.java
@@ -3,18 +3,27 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.contract.ContractPackage;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Stored Value for {@link ContractPackage}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see StoredValue
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@EqualsAndHashCode
@JsonTypeName("ContractPackage")
public class StoredValueContractPackage implements StoredValue {
@JsonProperty("ContractPackage")
diff --git a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueData.java b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueData.java
index 3df09d88..7490c0ed 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueData.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueData.java
@@ -1,17 +1,24 @@
package com.syntifi.casper.sdk.model.storedvalue;
import com.fasterxml.jackson.annotation.JsonProperty;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Root class for a Casper Stored Value
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+@EqualsAndHashCode
public class StoredValueData {
@JsonProperty("api_version")
private String apiVersion;
diff --git a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueDeployInfo.java b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueDeployInfo.java
index 3e1a486f..f83327e3 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueDeployInfo.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueDeployInfo.java
@@ -3,18 +3,27 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.deploy.DeployInfo;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Stored Value for {@link DeployInfo}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see StoredValue
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@EqualsAndHashCode
@JsonTypeName("DeployInfo")
public class StoredValueDeployInfo implements StoredValue {
@JsonProperty("DeployInfo")
diff --git a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueEraInfo.java b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueEraInfo.java
index 3d065b96..61d9b021 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueEraInfo.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueEraInfo.java
@@ -3,18 +3,27 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.deploy.EraInfo;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Stored Value for {@link EraInfo}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see StoredValue
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@EqualsAndHashCode
@JsonTypeName("EraInfo")
public class StoredValueEraInfo implements StoredValue {
@JsonProperty("EraInfo")
diff --git a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueTransfer.java b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueTransfer.java
index 973e4599..a3c7d9a2 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueTransfer.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueTransfer.java
@@ -3,18 +3,27 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.transfer.Transfer;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* Stored Value for {@link Transfer}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see StoredValue
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@EqualsAndHashCode
@JsonTypeName("Transfer")
public class StoredValueTransfer implements StoredValue {
@JsonProperty("Transfer")
diff --git a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueTypeData.java b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueTypeData.java
index 7e6dd257..c83958b8 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueTypeData.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueTypeData.java
@@ -1,14 +1,13 @@
package com.syntifi.casper.sdk.model.storedvalue;
import com.syntifi.casper.sdk.exception.NoSuchTypeException;
-
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* Stored Value type data and class mapping
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see StoredValue
@@ -32,10 +31,10 @@ public enum StoredValueTypeData {
/**
* Retrieve Transform implementation class from Transform name
- *
- * @param name
- * @return
- * @throws NoSuchTypeException
+ *
+ * @param name the name to use for fetching class
+ * @return the class object for given name
+ * @throws NoSuchTypeException thrown if class type not found
*/
public static Class> getClassByName(String name) throws NoSuchTypeException {
for (StoredValueTypeData t : values()) {
diff --git a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueWithdraw.java b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueWithdraw.java
index 2f62ffd8..d85413cc 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueWithdraw.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueWithdraw.java
@@ -1,22 +1,31 @@
package com.syntifi.casper.sdk.model.storedvalue;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.syntifi.casper.sdk.model.transfer.Withdraw;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.util.List;
/**
* Stored Value for {@link Withdraw}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @see StoredValue
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@EqualsAndHashCode
@JsonTypeName("Withdraw")
public class StoredValueWithdraw implements StoredValue> {
@JsonProperty("Withdraw")
diff --git a/src/main/java/com/syntifi/casper/sdk/model/transfer/Transfer.java b/src/main/java/com/syntifi/casper/sdk/model/transfer/Transfer.java
index 95c7b63e..91f9c751 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/transfer/Transfer.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/transfer/Transfer.java
@@ -1,21 +1,28 @@
package com.syntifi.casper.sdk.model.transfer;
-import java.math.BigInteger;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.math.BigInteger;
/**
* Represents a transfer from one purse to another
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class Transfer {
@JsonProperty("id")
private BigInteger id;
@@ -64,25 +71,25 @@ public class Transfer {
@JsonProperty("amount")
@ExcludeFromJacocoGeneratedReport
- protected String getJsonAmount() {
+ protected String getJsonAmount() {
return this.amount.toString(10);
}
@JsonProperty("amount")
@ExcludeFromJacocoGeneratedReport
- protected void setJsonAmount(String value) {
+ protected void setJsonAmount(String value) {
this.amount = new BigInteger(value, 10);
}
@JsonProperty("gas")
@ExcludeFromJacocoGeneratedReport
- protected String getJsonGas() {
+ protected String getJsonGas() {
return this.gas.toString(10);
}
@JsonProperty("gas")
@ExcludeFromJacocoGeneratedReport
- protected void setJsonGas(String value) {
+ protected void setJsonGas(String value) {
this.gas = new BigInteger(value, 10);
}
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/transfer/TransferData.java b/src/main/java/com/syntifi/casper/sdk/model/transfer/TransferData.java
index ec720f43..8200645a 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/transfer/TransferData.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/transfer/TransferData.java
@@ -1,33 +1,40 @@
package com.syntifi.casper.sdk.model.transfer;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
-import lombok.Data;
+import java.util.List;
/**
* Root class for a Casper transfer request
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class TransferData {
-
+
/**
* The RPC API version
*/
@JsonProperty("api_version")
private String apiVersion;
-
+
/**
* Block hash
*/
@JsonProperty("block_hash")
private String blockHash;
-
+
/**
* List of @see Transfer
*/
diff --git a/src/main/java/com/syntifi/casper/sdk/model/transfer/Withdraw.java b/src/main/java/com/syntifi/casper/sdk/model/transfer/Withdraw.java
index 69ad532f..38fd81fe 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/transfer/Withdraw.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/transfer/Withdraw.java
@@ -1,17 +1,24 @@
package com.syntifi.casper.sdk.model.transfer;
import com.syntifi.casper.sdk.model.uref.URef;
-
-import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
* A withdraw.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
public class Withdraw {
/**
diff --git a/src/main/java/com/syntifi/casper/sdk/model/uref/URef.java b/src/main/java/com/syntifi/casper/sdk/model/uref/URef.java
index 14bb7746..5c991648 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/uref/URef.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/uref/URef.java
@@ -1,7 +1,5 @@
package com.syntifi.casper.sdk.model.uref;
-import java.io.IOException;
-
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;
@@ -10,25 +8,32 @@
import com.syntifi.casper.sdk.exception.InvalidByteStringException;
import com.syntifi.casper.sdk.model.clvalue.CLValueURef;
import com.syntifi.casper.sdk.model.clvalue.encdec.StringByteHelper;
-
import lombok.AllArgsConstructor;
-import lombok.Data;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.io.IOException;
/**
* URef is a tuple that contains the address of the URef and the access rights
* to that URef. The serialized representation of the URef is 33 bytes long. The
* first 32 bytes are the byte representation of the URef address, and the last
* byte contains the bits corresponding to the access rights of the URef.
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
- * @since 0.0.1
* @see CLValueURef
+ * @since 0.0.1
*/
-@Data
+@Getter
+@Setter
+@Builder
@AllArgsConstructor
@NoArgsConstructor
+@EqualsAndHashCode
public class URef {
@JsonIgnore
@@ -62,6 +67,6 @@ public void createURef(String uref) throws IOException, DynamicInstanceException
@ExcludeFromJacocoGeneratedReport
protected String getJsonURef() {
return "uref-" + StringByteHelper.convertBytesToHex(this.address) + "-0"
- + StringByteHelper.convertBytesToHex(new byte[] { this.accessRight.serializationTag });
+ + StringByteHelper.convertBytesToHex(new byte[]{this.accessRight.serializationTag});
}
}
diff --git a/src/main/java/com/syntifi/casper/sdk/model/uref/URefAccessRight.java b/src/main/java/com/syntifi/casper/sdk/model/uref/URefAccessRight.java
index d293852a..f7d7865e 100644
--- a/src/main/java/com/syntifi/casper/sdk/model/uref/URefAccessRight.java
+++ b/src/main/java/com/syntifi/casper/sdk/model/uref/URefAccessRight.java
@@ -2,35 +2,34 @@
import com.syntifi.casper.sdk.exception.DynamicInstanceException;
import com.syntifi.casper.sdk.model.clvalue.CLValueURef;
-
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
- * Casper CLValue URef access rights definitons
- *
+ * Casper CLValue URef access rights definitions
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
- * @see CLValueURef
+ * @see CLValueURef
* @since 0.0.1
*/
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum URefAccessRight {
- NONE((byte)0x0),
- READ((byte)0x1),
- WRITE((byte)0x2),
- READ_WRITE((byte)0x3),
- ADD((byte)0x4),
- READ_ADD((byte)0x5),
- ADD_WRITE((byte)0x6),
- READ_ADD_WRITE((byte)0x7);
+ NONE((byte) 0x0),
+ READ((byte) 0x1),
+ WRITE((byte) 0x2),
+ READ_WRITE((byte) 0x3),
+ ADD((byte) 0x4),
+ READ_ADD((byte) 0x5),
+ ADD_WRITE((byte) 0x6),
+ READ_ADD_WRITE((byte) 0x7);
public final byte serializationTag;
public static URefAccessRight getTypeBySerializationTag(byte serializationTag) throws DynamicInstanceException {
- for (URefAccessRight accessRight: values()) {
+ for (URefAccessRight accessRight : values()) {
if (accessRight.serializationTag == serializationTag) {
return accessRight;
}
diff --git a/src/main/java/com/syntifi/casper/sdk/service/CasperDeployService.java b/src/main/java/com/syntifi/casper/sdk/service/CasperDeployService.java
new file mode 100644
index 00000000..96bf81c7
--- /dev/null
+++ b/src/main/java/com/syntifi/casper/sdk/service/CasperDeployService.java
@@ -0,0 +1,164 @@
+package com.syntifi.casper.sdk.service;
+
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.clvalue.CLValueOption;
+import com.syntifi.casper.sdk.model.clvalue.CLValuePublicKey;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU512;
+import com.syntifi.casper.sdk.model.clvalue.CLValueU64;
+import com.syntifi.casper.sdk.model.clvalue.cltype.CLTypeOption;
+import com.syntifi.casper.sdk.model.clvalue.cltype.CLTypePublicKey;
+import com.syntifi.casper.sdk.model.clvalue.cltype.CLTypeU512;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
+import com.syntifi.casper.sdk.model.common.Digest;
+import com.syntifi.casper.sdk.model.common.Ttl;
+import com.syntifi.casper.sdk.model.deploy.Approval;
+import com.syntifi.casper.sdk.model.deploy.Deploy;
+import com.syntifi.casper.sdk.model.deploy.DeployHeader;
+import com.syntifi.casper.sdk.model.deploy.NamedArg;
+import com.syntifi.casper.sdk.model.deploy.executabledeploy.ModuleBytes;
+import com.syntifi.casper.sdk.model.deploy.executabledeploy.Transfer;
+import com.syntifi.casper.sdk.model.key.PublicKey;
+import com.syntifi.casper.sdk.model.key.Signature;
+import com.syntifi.crypto.key.AbstractPrivateKey;
+import com.syntifi.crypto.key.hash.Blake2b;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.GeneralSecurityException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Optional;
+import java.util.Random;
+
+/**
+ * Deploy Service class implementing the process to generate deploys
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.2.0
+ */
+public class CasperDeployService {
+
+ /**
+ * Method to generate a Transfer deploy
+ *
+ * @param fromPrivateKey sender private Key
+ * @param toPublicKey receiver public key
+ * @param amount amount to transfer
+ * @param chainName network name
+ * @return Deploy
+ * @throws NoSuchTypeException thrown if type not found
+ * @throws DynamicInstanceException thrown if it could not instantiate a type
+ * @throws CLValueEncodeException thrown if failed to encode a cl value
+ * @throws IOException thrown if an IO error occurs
+ * @throws GeneralSecurityException thrown when an error occurs with cryptographic keys
+ */
+ public static Deploy buildTransferDeploy(AbstractPrivateKey fromPrivateKey,
+ PublicKey toPublicKey, BigInteger amount, String chainName)
+ throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException,
+ GeneralSecurityException {
+ long id = Math.abs(new Random().nextInt());
+ BigInteger paymentAmount = BigInteger.valueOf(25000000000L);
+ long gasPrice = 1L;
+ Ttl ttl = Ttl
+ .builder()
+ .ttl("30m")
+ .build();
+ return CasperDeployService.buildTransferDeploy(fromPrivateKey,
+ toPublicKey, amount, chainName, id, paymentAmount,
+ gasPrice, ttl, new Date(), new ArrayList<>());
+ }
+
+
+ /**
+ * @param fromPrivateKey private key of the sender
+ * @param toPublicKey public key of the receiver
+ * @param amount amount to transfer
+ * @param id id field in the request to tag the transaction
+ * @param paymentAmount, the number of motes paying to the execution engine
+ * @param gasPrice gasPrice for native transfers can be set to 1
+ * @param ttl time to live in milliseconds (default value is 1800000
+ * ms (30 minutes))
+ * @return Deploy
+ * @throws NoSuchTypeException thrown if type not found
+ * @throws DynamicInstanceException thrown if it could not instantiate a type
+ * @throws CLValueEncodeException thrown if failed to encode a cl value
+ * @throws IOException thrown if an IO error occurs
+ * @throws GeneralSecurityException thrown when an error occurs with cryptographic keys
+ */
+ public static Deploy buildTransferDeploy(AbstractPrivateKey fromPrivateKey, PublicKey toPublicKey,
+ BigInteger amount, String chainName, Long id, BigInteger paymentAmount,
+ Long gasPrice, Ttl ttl, Date date, List dependencies)
+ throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException,
+ GeneralSecurityException {
+
+ List> transferArgs = new LinkedList<>();
+ NamedArg amountNamedArg = new NamedArg<>("amount",
+ new CLValueU512(amount));
+ transferArgs.add(amountNamedArg);
+ NamedArg publicKeyNamedArg = new NamedArg<>("target",
+ new CLValuePublicKey(toPublicKey));
+ transferArgs.add(publicKeyNamedArg);
+ CLValueOption idArg = new CLValueOption(Optional.of(
+ new CLValueU64(BigInteger.valueOf(682008))));
+ NamedArg idNamedArg = new NamedArg<>("id", idArg);
+ transferArgs.add(idNamedArg);
+
+ Transfer session = Transfer
+ .builder()
+ .args(transferArgs)
+ .build();
+ List> paymentArgs = new LinkedList<>();
+ NamedArg paymentArg = new NamedArg<>("amount",
+ new CLValueU512(paymentAmount));
+ paymentArgs.add(paymentArg);
+
+ ModuleBytes payment = ModuleBytes
+ .builder()
+ .args(paymentArgs)
+ .bytes("")
+ .build();
+ CLValueEncoder clve = new CLValueEncoder();
+ payment.encode(clve, true);
+ session.encode(clve, true);
+ byte[] sessionAnPaymentHash = Blake2b.digest(clve.toByteArray(), 32);
+ clve.flush();
+ clve.reset();
+
+ PublicKey fromPublicKey = PublicKey.fromAbstractPublicKey(fromPrivateKey.derivePublicKey());
+
+ DeployHeader deployHeader = DeployHeader
+ .builder()
+ .account(fromPublicKey)
+ .ttl(ttl)
+ .timeStamp(date)
+ .gasPrice(gasPrice)
+ .bodyHash(Digest.digestFromBytes(sessionAnPaymentHash))
+ .chainName(chainName)
+ .dependencies(dependencies)
+ .build();
+ deployHeader.encode(clve, true);
+ byte[] headerHash = Blake2b.digest(clve.toByteArray(), 32);
+
+ Signature signature = Signature.sign(fromPrivateKey, headerHash);
+
+ List approvals = new LinkedList<>();
+ approvals.add(Approval.builder()
+ .signer(PublicKey.fromAbstractPublicKey(fromPrivateKey.derivePublicKey()))
+ .signature(signature)
+ .build());
+
+ return Deploy.builder()
+ .hash(Digest.digestFromBytes(headerHash))
+ .header(deployHeader)
+ .payment(payment)
+ .session(session)
+ .approvals(approvals)
+ .build();
+
+ }
+}
diff --git a/src/main/java/com/syntifi/casper/sdk/service/CasperObjectMapper.java b/src/main/java/com/syntifi/casper/sdk/service/CasperObjectMapper.java
index 547541b5..c4efd315 100644
--- a/src/main/java/com/syntifi/casper/sdk/service/CasperObjectMapper.java
+++ b/src/main/java/com/syntifi/casper/sdk/service/CasperObjectMapper.java
@@ -4,7 +4,7 @@
/**
* Custom Jackson {@link ObjectMapper} for any customizations
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
diff --git a/src/main/java/com/syntifi/casper/sdk/service/CasperService.java b/src/main/java/com/syntifi/casper/sdk/service/CasperService.java
index c6468037..a8d93f72 100644
--- a/src/main/java/com/syntifi/casper/sdk/service/CasperService.java
+++ b/src/main/java/com/syntifi/casper/sdk/service/CasperService.java
@@ -1,11 +1,5 @@
package com.syntifi.casper.sdk.service;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import com.googlecode.jsonrpc4j.ExceptionResolver;
import com.googlecode.jsonrpc4j.JsonRpcHttpClient;
import com.googlecode.jsonrpc4j.JsonRpcMethod;
@@ -30,185 +24,191 @@
import com.syntifi.casper.sdk.model.storedvalue.StoredValueData;
import com.syntifi.casper.sdk.model.transfer.TransferData;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
/**
* Interface to be used as Dynamic Proxy for RPC method operation
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
public interface CasperService {
- /**
- * Get network peers data
- *
- * @return Object holding the api version and peer list
- */
- @JsonRpcMethod("info_get_peers")
- public PeerData getPeerData();
-
- /**
- * Get latest block info
- *
- * @return Object holding the api version and block
- */
- @JsonRpcMethod("chain_get_block")
- public JsonBlockData getBlock();
-
- /**
- * Retrieve block info by its {@link BlockIdentifier}
- *
- * @param blockIdentifier BlockIdentifier data
- * @return Object holding the api version and block
- */
- @JsonRpcMethod("chain_get_block")
- public JsonBlockData getBlock(@JsonRpcParam("block_identifier") BlockIdentifier blockIdentifier);
-
- /**
- * Retrieve last block's transfers
- *
- * @return Object holding the api version and transfer data
- */
- @JsonRpcMethod("chain_get_block_transfers")
- public TransferData getBlockTransfers();
-
- /**
- * Retrieve block transfers by its {@link BlockIdentifier}
- *
- * @param blockIdentifier BlockIdentifier data
- * @return Object holding the api version and transfer data
- */
- @JsonRpcMethod("chain_get_block_transfers")
- public TransferData getBlockTransfers(@JsonRpcParam("block_identifier") BlockIdentifier blockIdentifier);
-
- /**
- * Returns a state root hash at the last Block
- *
- * @return Object holding the api version and state root hash data
- */
- @JsonRpcMethod("chain_get_state_root_hash")
- public StateRootHashData getStateRootHash();
-
- /**
- * Returns a state root hash at a given a {@link BlockIdentifier}
- *
- * @param blockIdentifier BlockIdentifier data
- * @return Object holding the api version and state root hash data
- */
- @JsonRpcMethod("chain_get_state_root_hash")
- public StateRootHashData getStateRootHash(@JsonRpcParam("block_identifier") BlockIdentifier blockIdentifier);
-
- /**
- * Returns a stored value from the network
- *
- * @param stateRootHash Hash of the state root
- * @param key `casper_types::Key` as formatted string
- * @param path The path components starting from the key as base
- * @return Object holding the api version, the merkle proof and the stored value
- * data
- */
- @JsonRpcMethod("state_get_item")
- public StoredValueData getStateItem(@JsonRpcParam("state_root_hash") String stateRootHash,
- @JsonRpcParam("key") String key, @JsonRpcParam("path") List path);
-
- /**
- * Returns an EraInfo from the network
- *
- * @param blockIdentifier BlockIdentifier data
- * @return Object holding api version and EraInfo
- */
- @JsonRpcMethod("chain_get_era_info_by_switch_block")
- public EraInfoData getEraInfoBySwitchBlock(@JsonRpcParam("block_identifier") BlockIdentifier blockIdentifier);
-
- /**
- * Returns a Deploy from the network
- *
- * @param deployHash The deploy hash
- * @return Object holding the api version, the deploy and the map of block hash
- * to execution result
- */
- @JsonRpcMethod("info_get_deploy")
- public DeployData getDeploy(@JsonRpcParam("deploy_hash") String deployHash);
-
- /**
- * Returns the current status of the node
- *
- * @return Object holding the apiversion, minimal block information, build
- * version and other properties
- */
- @JsonRpcMethod("info_get_status")
- public StatusData getStatus();
-
- /**
- * Returns an Account from the network
- *
- * @param publicKey the account's public key
- * @param blockIdentifier BlockIdentifier data
- * @return Oject holding the api version, the account data and the merkle proof
- */
- @JsonRpcMethod("state_get_account_info")
- public AccountData getStateAccountInfo(@JsonRpcParam("public_key") String publicKey,
- @JsonRpcParam("block_identifier") BlockIdentifier blockIdentifier);
-
- /**
- * Returns the Auction info for a given block
- *
- * @param blockIdentifier BlockIdentifier data
- * @return Object holding the api version and auction state data
- */
- @JsonRpcMethod("state_get_auction_info")
- public AuctionData getStateAuctionInfo(@JsonRpcParam("block_identifier") BlockIdentifier blockIdentifier);
-
- /**
- * Lookup a dictionary item via an Contract's named keys. Returns an item from a
- * Dictionary given the AccountNamedKey/ContractNamedKey/Dictionary/Uref
- *
- * @param stateRootHash the hash of state root
- * @param dictionaryIdentifier any concrete DictionaryIdentifier
- * @return Object holding the api version, the dictionary key, the merkle proof
- * and the stored value
- */
- @JsonRpcMethod("state_get_dictionary_item")
- public DictionaryData getStateDictionaryItem(@JsonRpcParam("state_root_hash") String stateRootHash,
- @JsonRpcParam("dictionary_identifier") DictionaryIdentifier dictionaryIdentifier);
-
- /**
- * Fetches balance value
- *
- * @param stateRootHash the hash of state root
- * @param purseUref formatted URef
- * @return Result for "state_get_balance" RPC response
- */
- @JsonRpcMethod("state_get_balance")
- public BalanceData getBalance(@JsonRpcParam("state_root_hash") String stateRootHash,
- @JsonRpcParam("purse_uref") String purseUref);
-
- /**
- * Sends a deploy to be received by the network
- *
- * @param deploy the deploy object to send to the network
- * @return Object holding the api version and the deploy hash
- */
- @JsonRpcMethod(value = "account_put_deploy", paramsPassMode = JsonRpcParamsPassMode.ARRAY)
- public DeployResult putDeploy(Deploy deploy);
-
- /**
- * Builds a CasperService for the node ip/port pair
- *
- * @param ip the peer ip to connect to
- * @param port the service port of the peer
- * @return A Dynamic Proxy to CasperService
- * @throws MalformedURLException is thrown if ip/port are not compliant
- */
- public static CasperService usingPeer(String ip, int port) throws MalformedURLException {
- CasperObjectMapper objectMapper = new CasperObjectMapper();
- Map newHeaders = new HashMap<>();
- newHeaders.put("Content-Type", "application/json");
- JsonRpcHttpClient client = new JsonRpcHttpClient(objectMapper, new URL("http", ip, port, "/rpc"),
- newHeaders);
-
- ExceptionResolver exceptionResolver = new CasperClientExceptionResolver();
- client.setExceptionResolver(exceptionResolver);
-
- return ProxyUtil.createClientProxy(CasperService.class.getClassLoader(), CasperService.class, client);
- }
+ /**
+ * Get network peers data
+ *
+ * @return Object holding the api version and peer list
+ */
+ @JsonRpcMethod("info_get_peers")
+ PeerData getPeerData();
+
+ /**
+ * Get the latest block info
+ *
+ * @return Object holding the api version and block
+ */
+ @JsonRpcMethod("chain_get_block")
+ JsonBlockData getBlock();
+
+ /**
+ * Retrieve block info by its {@link BlockIdentifier}
+ *
+ * @param blockIdentifier BlockIdentifier data
+ * @return Object holding the api version and block
+ */
+ @JsonRpcMethod("chain_get_block")
+ JsonBlockData getBlock(@JsonRpcParam("block_identifier") BlockIdentifier blockIdentifier);
+
+ /**
+ * Retrieve last block's transfers
+ *
+ * @return Object holding the api version and transfer data
+ */
+ @JsonRpcMethod("chain_get_block_transfers")
+ TransferData getBlockTransfers();
+
+ /**
+ * Retrieve block transfers by its {@link BlockIdentifier}
+ *
+ * @param blockIdentifier BlockIdentifier data
+ * @return Object holding the api version and transfer data
+ */
+ @JsonRpcMethod("chain_get_block_transfers")
+ TransferData getBlockTransfers(@JsonRpcParam("block_identifier") BlockIdentifier blockIdentifier);
+
+ /**
+ * Returns a state root hash at the last Block
+ *
+ * @return Object holding the api version and state root hash data
+ */
+ @JsonRpcMethod("chain_get_state_root_hash")
+ StateRootHashData getStateRootHash();
+
+ /**
+ * Returns a state root hash at a given a {@link BlockIdentifier}
+ *
+ * @param blockIdentifier BlockIdentifier data
+ * @return Object holding the api version and state root hash data
+ */
+ @JsonRpcMethod("chain_get_state_root_hash")
+ StateRootHashData getStateRootHash(@JsonRpcParam("block_identifier") BlockIdentifier blockIdentifier);
+
+ /**
+ * Returns a stored value from the network
+ *
+ * @param stateRootHash Hash of the state root
+ * @param key `casper_types::Key` as formatted string
+ * @param path The path components starting from the key as base
+ * @return Object holding the api version, the merkle proof and the stored value
+ * data
+ */
+ @JsonRpcMethod("state_get_item")
+ StoredValueData getStateItem(@JsonRpcParam("state_root_hash") String stateRootHash,
+ @JsonRpcParam("key") String key, @JsonRpcParam("path") List path);
+
+ /**
+ * Returns an EraInfo from the network
+ *
+ * @param blockIdentifier BlockIdentifier data
+ * @return Object holding api version and EraInfo
+ */
+ @JsonRpcMethod("chain_get_era_info_by_switch_block")
+ EraInfoData getEraInfoBySwitchBlock(@JsonRpcParam("block_identifier") BlockIdentifier blockIdentifier);
+
+ /**
+ * Returns a Deploy from the network
+ *
+ * @param deployHash The deploy hash
+ * @return Object holding the api version, the deploy and the map of block hash
+ * to execution result
+ */
+ @JsonRpcMethod("info_get_deploy")
+ DeployData getDeploy(@JsonRpcParam("deploy_hash") String deployHash);
+
+ /**
+ * Returns the current status of the node
+ *
+ * @return Object holding the apiversion, minimal block information, build
+ * version and other properties
+ */
+ @JsonRpcMethod("info_get_status")
+ StatusData getStatus();
+
+ /**
+ * Returns an Account from the network
+ *
+ * @param publicKey the account's public key
+ * @param blockIdentifier BlockIdentifier data
+ * @return Object holding the api version, the account data and the merkle proof
+ */
+ @JsonRpcMethod("state_get_account_info")
+ AccountData getStateAccountInfo(@JsonRpcParam("public_key") String publicKey,
+ @JsonRpcParam("block_identifier") BlockIdentifier blockIdentifier);
+
+ /**
+ * Returns the Auction info for a given block
+ *
+ * @param blockIdentifier BlockIdentifier data
+ * @return Object holding the api version and auction state data
+ */
+ @JsonRpcMethod("state_get_auction_info")
+ AuctionData getStateAuctionInfo(@JsonRpcParam("block_identifier") BlockIdentifier blockIdentifier);
+
+ /**
+ * Lookup a dictionary item via a Contract's named keys. Returns an item from a
+ * Dictionary given the AccountNamedKey/ContractNamedKey/Dictionary/Uref
+ *
+ * @param stateRootHash the hash of state root
+ * @param dictionaryIdentifier any concrete DictionaryIdentifier
+ * @return Object holding the api version, the dictionary key, the merkle proof
+ * and the stored value
+ */
+ @JsonRpcMethod("state_get_dictionary_item")
+ DictionaryData getStateDictionaryItem(@JsonRpcParam("state_root_hash") String stateRootHash,
+ @JsonRpcParam("dictionary_identifier") DictionaryIdentifier dictionaryIdentifier);
+
+ /**
+ * Fetches balance value
+ *
+ * @param stateRootHash the hash of state root
+ * @param purseUref formatted URef
+ * @return Result for "state_get_balance" RPC response
+ */
+ @JsonRpcMethod("state_get_balance")
+ BalanceData getBalance(@JsonRpcParam("state_root_hash") String stateRootHash,
+ @JsonRpcParam("purse_uref") String purseUref);
+
+ /**
+ * Sends a deploy to be received by the network
+ *
+ * @param deploy the deploy object to send to the network
+ * @return Object holding the api version and the deploy hash
+ */
+ @JsonRpcMethod(value = "account_put_deploy", paramsPassMode = JsonRpcParamsPassMode.ARRAY)
+ DeployResult putDeploy(Deploy deploy);
+
+ /**
+ * Builds a CasperService for the node ip/port pair
+ *
+ * @param ip the peer ip to connect to
+ * @param port the service port of the peer
+ * @return A Dynamic Proxy to CasperService
+ * @throws MalformedURLException is thrown if ip/port are not compliant
+ */
+ static CasperService usingPeer(String ip, int port) throws MalformedURLException {
+ CasperObjectMapper objectMapper = new CasperObjectMapper();
+ Map newHeaders = new HashMap<>();
+ newHeaders.put("Content-Type", "application/json");
+ JsonRpcHttpClient client = new JsonRpcHttpClient(objectMapper, new URL("http", ip, port, "/rpc"),
+ newHeaders);
+
+ ExceptionResolver exceptionResolver = new CasperClientExceptionResolver();
+ client.setExceptionResolver(exceptionResolver);
+
+ return ProxyUtil.createClientProxy(CasperService.class.getClassLoader(), CasperService.class, client);
+ }
}
diff --git a/src/test/java/com/syntifi/casper/sdk/model/AbstractJsonTests.java b/src/test/java/com/syntifi/casper/sdk/model/AbstractJsonTests.java
index a242acfe..d9a597dc 100644
--- a/src/test/java/com/syntifi/casper/sdk/model/AbstractJsonTests.java
+++ b/src/test/java/com/syntifi/casper/sdk/model/AbstractJsonTests.java
@@ -23,23 +23,26 @@ public abstract class AbstractJsonTests {
/**
* Loads test json from resources
*
- * @param filename
- * @return
- * @throws IOException
+ * @param filename the file to load
+ * @return the file content as String
+ * @throws IOException thrown if error reading/accessing file
*/
protected String loadJsonFromFile(String filename) throws IOException {
String fileJson;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try (InputStream is = getClass().getClassLoader().getResourceAsStream(filename)) {
- //copy stream
- byte[] buffer = new byte[1024];
- int bytesRead;
- while ((bytesRead = is.read(buffer)) != -1) {
- baos.write(buffer, 0, bytesRead);
+ final int bufLen = 4 * 0x400; // 4KB
+ byte[] buf = new byte[bufLen];
+ int readLen;
+ try (InputStream is = getClass().getClassLoader().getResourceAsStream(filename)) {
+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
+ while (true) {
+ assert is != null;
+ if ((readLen = is.read(buf, 0, bufLen)) == -1) break;
+ outputStream.write(buf, 0, readLen);
+ }
+
+ fileJson = outputStream.toString();
}
-
- fileJson = new String(baos.toByteArray());
}
return fileJson;
}
@@ -49,8 +52,8 @@ protected String loadJsonFromFile(String filename) throws IOException {
*
* @param json json string to prettify
* @return prettified json
- * @throws JsonMappingException
- * @throws JsonProcessingException
+ * @throws JsonMappingException thrown if a mapping error occurs
+ * @throws JsonProcessingException thrown if a json procesing error
*/
protected String getPrettyJson(String json) throws JsonMappingException, JsonProcessingException {
Object jsonObject = OBJECT_MAPPER.readValue(json, Object.class);
@@ -62,8 +65,8 @@ protected String getPrettyJson(String json) throws JsonMappingException, JsonPro
*
* @param jsonObject object to serialize and prettify
* @return prettified json
- * @throws JsonMappingException
- * @throws JsonProcessingException
+ * @throws JsonMappingException thrown if a mapping error occurs
+ * @throws JsonProcessingException thrown if a json procesing error
*/
protected String getPrettyJson(Object jsonObject) throws JsonMappingException, JsonProcessingException {
return OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject);
diff --git a/src/test/java/com/syntifi/casper/sdk/model/account/AccountInfoTests.java b/src/test/java/com/syntifi/casper/sdk/model/account/AccountInfoTests.java
index c9ce32a5..93c5652b 100644
--- a/src/test/java/com/syntifi/casper/sdk/model/account/AccountInfoTests.java
+++ b/src/test/java/com/syntifi/casper/sdk/model/account/AccountInfoTests.java
@@ -1,20 +1,17 @@
package com.syntifi.casper.sdk.model.account;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.io.IOException;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.syntifi.casper.sdk.model.AbstractJsonTests;
import com.syntifi.casper.sdk.model.status.StatusDataTests;
-
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
/**
* Unit tests for {@link AccountData}
*
@@ -27,16 +24,16 @@ public class AccountInfoTests extends AbstractJsonTests {
private static final Logger LOGGER = LoggerFactory.getLogger(StatusDataTests.class);
@Test
- void validateAccountInfoMapping() throws JsonMappingException, JsonProcessingException, IOException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile("account-info-samples/account-info.json"));
+ void validateAccountInfoMapping() throws IOException, JSONException {
+ final String inputJson = getPrettyJson(loadJsonFromFile("account-info-samples/account-info.json"));
LOGGER.debug("Original JSON: {}", inputJson);
- AccountData ad = OBJECT_MAPPER.readValue(inputJson, AccountData.class);
+ final AccountData ad = OBJECT_MAPPER.readValue(inputJson, AccountData.class);
- assertTrue(ad.getAccount() instanceof Account);
+ assertNotNull(ad.getAccount());
- String expectedJson = getPrettyJson(ad);
+ final String expectedJson = getPrettyJson(ad);
LOGGER.debug("Serialized JSON: {}", expectedJson);
diff --git a/src/test/java/com/syntifi/casper/sdk/model/auction/AuctionInfoTest.java b/src/test/java/com/syntifi/casper/sdk/model/auction/AuctionInfoTest.java
index 292684c6..b5cecb38 100644
--- a/src/test/java/com/syntifi/casper/sdk/model/auction/AuctionInfoTest.java
+++ b/src/test/java/com/syntifi/casper/sdk/model/auction/AuctionInfoTest.java
@@ -1,20 +1,17 @@
package com.syntifi.casper.sdk.model.auction;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.io.IOException;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.syntifi.casper.sdk.model.AbstractJsonTests;
import com.syntifi.casper.sdk.model.status.StatusDataTests;
-
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
/**
* Unit tests for {@link AuctionData}
*
@@ -27,16 +24,16 @@ public class AuctionInfoTest extends AbstractJsonTests {
private static final Logger LOGGER = LoggerFactory.getLogger(StatusDataTests.class);
@Test
- void validateAuctionInfoMapping() throws JsonMappingException, JsonProcessingException, IOException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile("auction-info-samples/auction-info.json"));
+ void validateAuctionInfoMapping() throws IOException, JSONException {
+ final String inputJson = getPrettyJson(loadJsonFromFile("auction-info-samples/auction-info.json"));
LOGGER.debug("Original JSON: {}", inputJson);
- AuctionData ad = OBJECT_MAPPER.readValue(inputJson, AuctionData.class);
+ final AuctionData ad = OBJECT_MAPPER.readValue(inputJson, AuctionData.class);
- assertTrue(ad.getAuctionState() instanceof AuctionState);
+ assertNotNull(ad.getAuctionState());
- String expectedJson = getPrettyJson(ad);
+ final String expectedJson = getPrettyJson(ad);
LOGGER.debug("Serialized JSON: {}", expectedJson);
diff --git a/src/test/java/com/syntifi/casper/sdk/model/block/JsonBlockDataTest.java b/src/test/java/com/syntifi/casper/sdk/model/block/JsonBlockDataTest.java
index 0ee9b40b..68d6fc93 100644
--- a/src/test/java/com/syntifi/casper/sdk/model/block/JsonBlockDataTest.java
+++ b/src/test/java/com/syntifi/casper/sdk/model/block/JsonBlockDataTest.java
@@ -1,23 +1,20 @@
package com.syntifi.casper.sdk.model.block;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.io.IOException;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.syntifi.casper.sdk.model.AbstractJsonTests;
import com.syntifi.casper.sdk.model.status.StatusDataTests;
-
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
/**
* Unit tests for {@link JsonBlockDataTest}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -27,19 +24,19 @@ public class JsonBlockDataTest extends AbstractJsonTests {
private static final Logger LOGGER = LoggerFactory.getLogger(StatusDataTests.class);
@Test
- void validateJsonBlock_EraEndBlock() throws JsonMappingException, JsonProcessingException, IOException, JSONException {
+ void validateJsonBlock_EraEndBlock() throws IOException, JSONException {
// curl -X POST -H 'Content-Type: application/json' -d
// '{"id":"0","jsonrpc":"2.0","method":"chain_get_block",
// "params":{"block_identifier":{"Height":"246762"}}}' http://nodeIP:7777/rpc
- String inputJson = getPrettyJson(loadJsonFromFile("block-samples/block-end-era.json"));
+ final String inputJson = getPrettyJson(loadJsonFromFile("block-samples/block-end-era.json"));
LOGGER.debug("Original JSON: {}", inputJson);
- JsonBlockData block = OBJECT_MAPPER.readValue(inputJson, JsonBlockData.class);
+ final JsonBlockData block = OBJECT_MAPPER.readValue(inputJson, JsonBlockData.class);
- assertTrue(block.getBlock() instanceof JsonBlock);
+ assertNotNull(block.getBlock());
- String expectedJson = getPrettyJson(block);
+ final String expectedJson = getPrettyJson(block);
LOGGER.debug("Serialized JSON: {}", expectedJson);
diff --git a/src/test/java/com/syntifi/casper/sdk/model/clvalue/CLValueTests.java b/src/test/java/com/syntifi/casper/sdk/model/clvalue/CLValueTests.java
index 5b05d5f6..28a111a8 100644
--- a/src/test/java/com/syntifi/casper/sdk/model/clvalue/CLValueTests.java
+++ b/src/test/java/com/syntifi/casper/sdk/model/clvalue/CLValueTests.java
@@ -1,19 +1,15 @@
package com.syntifi.casper.sdk.model.clvalue;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
import com.syntifi.casper.sdk.exception.DynamicInstanceException;
import com.syntifi.casper.sdk.exception.NoSuchTypeException;
import com.syntifi.casper.sdk.model.clvalue.cltype.CLTypeAny;
import com.syntifi.casper.sdk.model.clvalue.cltype.CLTypeData;
-
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.junit.jupiter.api.Assertions.*;
+
public class CLValueTests {
private static final Logger LOGGER = LoggerFactory.getLogger(CLValueTests.class);
@@ -34,14 +30,14 @@ void allCLTypes_must_be_implemented() throws DynamicInstanceException, NoSuchTyp
}
@Test
- void getTypeBySerializationTag_should_return_correct_CLTypeData() throws DynamicInstanceException, NoSuchTypeException {
+ void getTypeBySerializationTag_should_return_correct_CLTypeData() throws NoSuchTypeException {
for (CLTypeData typeData : CLTypeData.values()) {
assertEquals(typeData, CLTypeData.getTypeBySerializationTag(typeData.getSerializationTag()));
}
}
@Test
- void createCLTypeFromCLTypeData_should_return_correct_CLType() throws DynamicInstanceException, NoSuchTypeException {
+ void createCLTypeFromCLTypeData_should_return_correct_CLType() throws DynamicInstanceException {
assertTrue(CLTypeData.createCLTypeFromCLTypeData(CLTypeData.ANY) instanceof CLTypeAny);
}
diff --git a/src/test/java/com/syntifi/casper/sdk/model/clvalue/encdec/EncoderDecoderTests.java b/src/test/java/com/syntifi/casper/sdk/model/clvalue/encdec/EncoderDecoderTests.java
index bb82defd..7467ad26 100644
--- a/src/test/java/com/syntifi/casper/sdk/model/clvalue/encdec/EncoderDecoderTests.java
+++ b/src/test/java/com/syntifi/casper/sdk/model/clvalue/encdec/EncoderDecoderTests.java
@@ -6,13 +6,11 @@
import java.io.IOException;
import java.math.BigInteger;
+import java.util.Arrays;
import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
import com.syntifi.casper.sdk.exception.CLValueDecodeException;
import com.syntifi.casper.sdk.exception.CLValueEncodeException;
-import com.syntifi.casper.sdk.exception.NoSuchTypeException;
import com.syntifi.casper.sdk.model.clvalue.CLValueBool;
import com.syntifi.casper.sdk.model.clvalue.CLValueByteArray;
import com.syntifi.casper.sdk.model.clvalue.CLValueI32;
@@ -34,7 +32,7 @@
/**
* Unit tests for {@link CLValueEncoder} and {@link CLValueDecoder}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -46,16 +44,16 @@ public class EncoderDecoderTests {
/**
* A container for test data to test CLValue Encoder/Decoder
*/
- private class TestData {
+ private static class TestData {
@Getter
- private String name;
+ private final String name;
@Getter
- private T value;
+ private final T value;
@Getter
- private String hexEncodedValue;
+ private final String hexEncodedValue;
@Getter
- private Class>[] supportTypes;
+ private final Class>[] supportTypes;
TestData(String name, T value, String hexEncodedValue, Class>[] supportTypes) {
this.name = name;
@@ -65,37 +63,34 @@ private class TestData {
}
}
- private List> successTestDataList = Stream.of(
- new TestData(AbstractCLType.BOOL, true, "01", null),
- new TestData(AbstractCLType.U8, Byte.valueOf("7"), "07", null),
- new TestData(AbstractCLType.U32, Long.valueOf(7), "07000000", null),
- new TestData(AbstractCLType.I32, Integer.valueOf(7), "07000000", null),
- new TestData(AbstractCLType.I64, Long.valueOf(7), "0700000000000000", null),
- new TestData(AbstractCLType.U64, new BigInteger("1024", 10), "0004000000000000", null),
- new TestData(AbstractCLType.U64, new BigInteger("18446744073709551615", 10), "ffffffffffffffff",
+ private final List> successTestDataList = Arrays.asList(
+ new TestData<>(AbstractCLType.BOOL, true, "01", null),
+ new TestData<>(AbstractCLType.U8, Byte.valueOf("7"), "07", null),
+ new TestData<>(AbstractCLType.U32, 7L, "07000000", null),
+ new TestData<>(AbstractCLType.I32, 7, "07000000", null),
+ new TestData<>(AbstractCLType.I64, 7L, "0700000000000000", null),
+ new TestData<>(AbstractCLType.U64, new BigInteger("1024", 10), "0004000000000000", null),
+ new TestData<>(AbstractCLType.U64, new BigInteger("18446744073709551615", 10), "ffffffffffffffff",
null),
- new TestData(AbstractCLType.U512, new BigInteger("7", 10), "0107", null),
- new TestData(AbstractCLType.U512, new BigInteger("1024", 10), "020004", null),
- new TestData(AbstractCLType.U512, new BigInteger("123456789101112131415", 10),
+ new TestData<>(AbstractCLType.U512, new BigInteger("7", 10), "0107", null),
+ new TestData<>(AbstractCLType.U512, new BigInteger("1024", 10), "020004", null),
+ new TestData<>(AbstractCLType.U512, new BigInteger("123456789101112131415", 10),
"0957ff1ada959f4eb106", null),
- new TestData(AbstractCLType.U512, new BigInteger("2500010000", 10), "0410200395", null),
- new TestData(AbstractCLType.STRING, "the string", "0a00000074686520737472696e67", null),
- new TestData(AbstractCLType.STRING, "Hello, World!", "0d00000048656c6c6f2c20576f726c6421", null))
- .collect(Collectors.toList());
+ new TestData<>(AbstractCLType.U512, new BigInteger("2500010000", 10), "0410200395", null),
+ new TestData<>(AbstractCLType.STRING, "the string", "0a00000074686520737472696e67", null),
+ new TestData<>(AbstractCLType.STRING, "Hello, World!", "0d00000048656c6c6f2c20576f726c6421", null));
- private List> lastValidNumberTestDataList = Stream.of(
- new TestData(AbstractCLType.U64, CLValueEncoder.MAX_U64, null, null),
- new TestData(AbstractCLType.U128, CLValueEncoder.MAX_U128, null, null),
- new TestData(AbstractCLType.U256, CLValueEncoder.MAX_U256, null, null),
- new TestData(AbstractCLType.U512, CLValueEncoder.MAX_U512, null, null))
- .collect(Collectors.toList());
+ private final List> lastValidNumberTestDataList = Arrays.asList(
+ new TestData<>(AbstractCLType.U64, CLValueEncoder.MAX_U64, null, null),
+ new TestData<>(AbstractCLType.U128, CLValueEncoder.MAX_U128, null, null),
+ new TestData<>(AbstractCLType.U256, CLValueEncoder.MAX_U256, null, null),
+ new TestData<>(AbstractCLType.U512, CLValueEncoder.MAX_U512, null, null));
- private List> outOfBoundsTestDataList = Stream.of(
- new TestData(AbstractCLType.U64, CLValueEncoder.MAX_U64.add(CLValueEncoder.ONE), null, null),
- new TestData(AbstractCLType.U128, CLValueEncoder.MAX_U128.add(CLValueEncoder.ONE), null, null),
- new TestData(AbstractCLType.U256, CLValueEncoder.MAX_U256.add(CLValueEncoder.ONE), null, null),
- new TestData(AbstractCLType.U512, CLValueEncoder.MAX_U512.add(CLValueEncoder.ONE), null, null))
- .collect(Collectors.toList());
+ private final List> outOfBoundsTestDataList = Arrays.asList(
+ new TestData<>(AbstractCLType.U64, CLValueEncoder.MAX_U64.add(CLValueEncoder.ONE), null, null),
+ new TestData<>(AbstractCLType.U128, CLValueEncoder.MAX_U128.add(CLValueEncoder.ONE), null, null),
+ new TestData<>(AbstractCLType.U256, CLValueEncoder.MAX_U256.add(CLValueEncoder.ONE), null, null),
+ new TestData<>(AbstractCLType.U512, CLValueEncoder.MAX_U512.add(CLValueEncoder.ONE), null, null));
@Test
void validateDecode_with_SampleData() throws IOException, CLValueDecodeException {
@@ -168,7 +163,7 @@ void validateDecode_with_SampleData() throws IOException, CLValueDecodeException
}
@Test
- void validateEncode_with_SampleData() throws IOException, CLValueEncodeException, NoSuchTypeException {
+ void validateEncode_with_SampleData() throws IOException, CLValueEncodeException {
for (TestData> testData : successTestDataList) {
try (CLValueEncoder encoder = new CLValueEncoder()) {
switch (testData.getName()) {
@@ -228,7 +223,7 @@ void validateEncode_with_SampleData() throws IOException, CLValueEncodeException
}
@Test
- void numbersShouldBeInsideTheirTypeBounds() throws IOException, CLValueEncodeException, NoSuchTypeException {
+ void numbersShouldBeInsideTheirTypeBounds() throws IOException, CLValueEncodeException {
for (TestData> testData : lastValidNumberTestDataList) {
try (CLValueEncoder encoder = new CLValueEncoder()) {
switch (testData.getName()) {
@@ -267,7 +262,7 @@ void numbersShouldBeInsideTheirTypeBounds() throws IOException, CLValueEncodeExc
@Test
void dataOutOfBounds_should_throw_CLValueEncodeException()
- throws IOException, CLValueEncodeException, NoSuchTypeException {
+ throws IOException {
for (TestData> testData : outOfBoundsTestDataList) {
try (CLValueEncoder encoder = new CLValueEncoder()) {
switch (testData.getName()) {
@@ -303,7 +298,7 @@ void dataOutOfBounds_should_throw_CLValueEncodeException()
@Test
void dataWithWrongInputLength_should_throw_CLValueDecodeException()
- throws IOException, CLValueDecodeException, NoSuchTypeException {
+ throws IOException, CLValueDecodeException {
try (CLValueDecoder decoder = new CLValueDecoder("")) {
assertThrows(CLValueDecodeException.class, () -> decoder.readBool(new CLValueBool()));
assertThrows(CLValueDecodeException.class, () -> decoder.readU32(new CLValueU32()));
diff --git a/src/test/java/com/syntifi/casper/sdk/model/deploy/DeployDataTests.java b/src/test/java/com/syntifi/casper/sdk/model/deploy/DeployDataTests.java
index a1b9fbdf..d9806b95 100644
--- a/src/test/java/com/syntifi/casper/sdk/model/deploy/DeployDataTests.java
+++ b/src/test/java/com/syntifi/casper/sdk/model/deploy/DeployDataTests.java
@@ -1,22 +1,19 @@
package com.syntifi.casper.sdk.model.deploy;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.io.IOException;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.syntifi.casper.sdk.model.AbstractJsonTests;
-
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
/**
* Unit tests for {@link DeployData}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -26,7 +23,7 @@ public class DeployDataTests extends AbstractJsonTests {
private static final Logger LOGGER = LoggerFactory.getLogger(DeployDataTests.class);
@Test
- void validateDeployDataMapping_1() throws JsonMappingException, JsonProcessingException, IOException, JSONException {
+ void validateDeployDataMapping_1() throws IOException, JSONException {
// curl -X POST -H 'Content-Type: application/json' -d
// '{"jsonrpc":"2.0","id":"1","method":"info_get_deploy",
// "params":{"deploy_hash":"614030ac705ed2067fed57d30545b3a4974ffc40a1c32f72e3b7b7442d6c83a3"}
@@ -37,8 +34,8 @@ void validateDeployDataMapping_1() throws JsonMappingException, JsonProcessingEx
DeployData dd = OBJECT_MAPPER.readValue(inputJson, DeployData.class);
- assertTrue(dd.getDeploy() instanceof Deploy);
- assertTrue(dd.getExecutionResults().get(0) instanceof JsonExecutionResult);
+ assertNotNull(dd.getDeploy());
+ assertNotNull(dd.getExecutionResults().get(0));
String expectedJson = getPrettyJson(dd);
@@ -48,14 +45,14 @@ void validateDeployDataMapping_1() throws JsonMappingException, JsonProcessingEx
}
@Test
- void validateDeployDataMapping_2() throws JsonMappingException, JsonProcessingException, IOException, JSONException {
+ void validateDeployDataMapping_2() throws IOException, JSONException {
String inputJson = getPrettyJson(loadJsonFromFile("deploy-samples/deploy-v2.json"));
LOGGER.debug("Original JSON: {}", inputJson);
DeployData dd = OBJECT_MAPPER.readValue(inputJson, DeployData.class);
- assertTrue(dd.getDeploy() instanceof Deploy);
+ assertNotNull(dd.getDeploy());
String expectedJson = getPrettyJson(dd);
@@ -65,16 +62,16 @@ void validateDeployDataMapping_2() throws JsonMappingException, JsonProcessingEx
}
@Test
- void validateDeployDataMapping_3() throws JsonMappingException, JsonProcessingException, IOException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile("deploy-samples/deploy-v3.json"));
+ void validateDeployDataMapping_3() throws IOException, JSONException {
+ final String inputJson = getPrettyJson(loadJsonFromFile("deploy-samples/deploy-v3.json"));
LOGGER.debug("Original JSON: {}", inputJson);
- DeployData dd = OBJECT_MAPPER.readValue(inputJson, DeployData.class);
+ final DeployData dd = OBJECT_MAPPER.readValue(inputJson, DeployData.class);
- assertTrue(dd.getDeploy() instanceof Deploy);
+ assertNotNull(dd.getDeploy());
- String expectedJson = getPrettyJson(dd);
+ final String expectedJson = getPrettyJson(dd);
LOGGER.debug("Serialized JSON: {}", expectedJson);
@@ -82,14 +79,14 @@ void validateDeployDataMapping_3() throws JsonMappingException, JsonProcessingEx
}
@Test
- void validateDeployResultMapping() throws JsonMappingException, JsonProcessingException, IOException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile("deploy-samples/deploy-result.json"));
+ void validateDeployResultMapping() throws IOException, JSONException {
+ final String inputJson = getPrettyJson(loadJsonFromFile("deploy-samples/deploy-result.json"));
LOGGER.debug("Original JSON: {}", inputJson);
- DeployResult deploy = OBJECT_MAPPER.readValue(inputJson, DeployResult.class);
+ final DeployResult deploy = OBJECT_MAPPER.readValue(inputJson, DeployResult.class);
- String expectedJson = getPrettyJson(deploy);
+ final String expectedJson = getPrettyJson(deploy);
LOGGER.debug("Serialized JSON: {}", expectedJson);
diff --git a/src/test/java/com/syntifi/casper/sdk/model/deploy/DeploySerializationTest.java b/src/test/java/com/syntifi/casper/sdk/model/deploy/DeploySerializationTest.java
new file mode 100644
index 00000000..0f225ef1
--- /dev/null
+++ b/src/test/java/com/syntifi/casper/sdk/model/deploy/DeploySerializationTest.java
@@ -0,0 +1,54 @@
+package com.syntifi.casper.sdk.model.deploy;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.AbstractJsonTests;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
+import com.syntifi.casper.sdk.model.common.Digest;
+
+import org.bouncycastle.util.encoders.Hex;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * Unit tests for {@link Deploy} serialization
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.2.0
+ */
+public class DeploySerializationTest extends AbstractJsonTests {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(DeployDataTests.class);
+
+ @Test
+ void deploySerialization() throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
+ Digest digest = Digest.builder().digest(
+ "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900ca856a4d37501000080ee36000000000001000000000000004811966d37fe5674a8af4001884ea0d9042d1c06668da0c963769c3a01ebd08f0100000001010101010101010101010101010101010101010101010101010101010101010e0000006361737065722d6578616d706c6501da3c604f71e0e7df83ff1ab4ef15bb04de64ca02e3d2b78de6950e8b5ee187020e0000006361737065722d6578616d706c65130000006578616d706c652d656e7472792d706f696e7401000000080000007175616e7469747904000000e803000001050100000006000000616d6f756e7404000000e8030000010100000001d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c012dbf03817a51794a8e19e0724884075e6d1fbec326b766ecfa6658b41f81290da85e23b24e88b1c8d9761185c961daee1adab0649912a6477bcd2e69bd91bd08")
+ .build();
+ String inputJson = getPrettyJson(loadJsonFromFile("deploy-samples/deploy-serialization.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ Deploy deploy = OBJECT_MAPPER.readValue(inputJson, Deploy.class);
+
+ assertNotNull(deploy);
+
+ CLValueEncoder clve = new CLValueEncoder();
+ deploy.encode(clve, true);
+ byte[] deployBytes = clve.toByteArray();
+ String val = Hex.toHexString(deployBytes);
+ assertEquals(Hex.toHexString(digest.getDigest()), val);
+ assertTrue(Arrays.equals(digest.getDigest(), deployBytes));
+ }
+
+}
diff --git a/src/test/java/com/syntifi/casper/sdk/model/dictionary/DictionaryDataTest.java b/src/test/java/com/syntifi/casper/sdk/model/dictionary/DictionaryDataTest.java
index daab01f5..73faed80 100644
--- a/src/test/java/com/syntifi/casper/sdk/model/dictionary/DictionaryDataTest.java
+++ b/src/test/java/com/syntifi/casper/sdk/model/dictionary/DictionaryDataTest.java
@@ -1,21 +1,18 @@
package com.syntifi.casper.sdk.model.dictionary;
-import java.io.IOException;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.syntifi.casper.sdk.model.AbstractJsonTests;
import com.syntifi.casper.sdk.model.status.StatusDataTests;
-
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+
/**
* Unit tests for {@link DictionaryData}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -25,14 +22,14 @@ public class DictionaryDataTest extends AbstractJsonTests {
private static final Logger LOGGER = LoggerFactory.getLogger(StatusDataTests.class);
@Test
- void validateDictionaryMapping() throws JsonMappingException, JsonProcessingException, IOException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile("dictionary-samples/dictionary1.json"));
+ void validateDictionaryMapping() throws IOException, JSONException {
+ final String inputJson = getPrettyJson(loadJsonFromFile("dictionary-samples/dictionary1.json"));
LOGGER.debug("Original JSON: {}", inputJson);
- DictionaryData dict = OBJECT_MAPPER.readValue(inputJson, DictionaryData.class);
+ final DictionaryData dict = OBJECT_MAPPER.readValue(inputJson, DictionaryData.class);
- String expectedJson = getPrettyJson(dict);
+ final String expectedJson = getPrettyJson(dict);
LOGGER.debug("Serialized JSON: {}", expectedJson);
diff --git a/src/test/java/com/syntifi/casper/sdk/model/stateroothash/StateRootHashTest.java b/src/test/java/com/syntifi/casper/sdk/model/stateroothash/StateRootHashTest.java
index edd06a01..1be04f37 100644
--- a/src/test/java/com/syntifi/casper/sdk/model/stateroothash/StateRootHashTest.java
+++ b/src/test/java/com/syntifi/casper/sdk/model/stateroothash/StateRootHashTest.java
@@ -1,18 +1,15 @@
package com.syntifi.casper.sdk.model.stateroothash;
-import java.io.IOException;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.syntifi.casper.sdk.model.AbstractJsonTests;
import com.syntifi.casper.sdk.model.status.StatusDataTests;
-
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+
/**
* Unit tests for {@link StateRootHashData}
*
@@ -25,17 +22,17 @@ public class StateRootHashTest extends AbstractJsonTests {
private static final Logger LOGGER = LoggerFactory.getLogger(StatusDataTests.class);
@Test
- void validateStateRootHashMapping() throws JsonMappingException, JsonProcessingException, IOException, JSONException {
+ void validateStateRootHashMapping() throws IOException, JSONException {
// curl -X POST -H 'Content-Type: application/json' -d
// '{"id":"1132050564","jsonrpc":"2.0","method":"chain_get_state_root_hash","params":{"block_identifier":{"Height":0}}}'
// http://nodeIP:7777/rpc
- String inputJson = getPrettyJson(loadJsonFromFile("block-samples/state-root-hash-block0.json"));
+ final String inputJson = getPrettyJson(loadJsonFromFile("block-samples/state-root-hash-block0.json"));
LOGGER.debug("Original JSON: {}", inputJson);
- StateRootHashData root = OBJECT_MAPPER.readValue(inputJson, StateRootHashData.class);
+ final StateRootHashData root = OBJECT_MAPPER.readValue(inputJson, StateRootHashData.class);
- String expectedJson = getPrettyJson(root);
+ final String expectedJson = getPrettyJson(root);
LOGGER.debug("Serialized JSON: {}", expectedJson);
diff --git a/src/test/java/com/syntifi/casper/sdk/model/status/StatusDataTests.java b/src/test/java/com/syntifi/casper/sdk/model/status/StatusDataTests.java
index 39efdc39..7e472c15 100644
--- a/src/test/java/com/syntifi/casper/sdk/model/status/StatusDataTests.java
+++ b/src/test/java/com/syntifi/casper/sdk/model/status/StatusDataTests.java
@@ -1,19 +1,16 @@
package com.syntifi.casper.sdk.model.status;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.io.IOException;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.syntifi.casper.sdk.model.AbstractJsonTests;
-
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
/**
* Unit tests for {@link StatusData}
*
@@ -26,16 +23,16 @@ public class StatusDataTests extends AbstractJsonTests {
private static final Logger LOGGER = LoggerFactory.getLogger(StatusDataTests.class);
@Test
- void validateStatusMapping() throws JsonMappingException, JsonProcessingException, IOException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile("status-samples/status-info.json"));
+ void validateStatusMapping() throws IOException, JSONException {
+ final String inputJson = getPrettyJson(loadJsonFromFile("status-samples/status-info.json"));
LOGGER.debug("Original JSON: {}", inputJson);
- StatusData st = OBJECT_MAPPER.readValue(inputJson, StatusData.class);
+ final StatusData st = OBJECT_MAPPER.readValue(inputJson, StatusData.class);
- assertTrue(st.getLastAddedBlockInfo() instanceof MinimalBlockInfo);
+ assertNotNull(st.getLastAddedBlockInfo());
- String expectedJson = getPrettyJson(st);
+ final String expectedJson = getPrettyJson(st);
LOGGER.debug("Serialized JSON: {}", expectedJson);
diff --git a/src/test/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueTests.java b/src/test/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueTests.java
index 177a973b..253e9f1a 100644
--- a/src/test/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueTests.java
+++ b/src/test/java/com/syntifi/casper/sdk/model/storedvalue/StoredValueTests.java
@@ -1,1036 +1,991 @@
-package com.syntifi.casper.sdk.model.storedvalue;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.io.IOException;
-import java.math.BigInteger;
-import java.util.Arrays;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Optional;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.syntifi.casper.sdk.exception.CLValueDecodeException;
-import com.syntifi.casper.sdk.exception.CLValueEncodeException;
-import com.syntifi.casper.sdk.exception.DynamicInstanceException;
-import com.syntifi.casper.sdk.exception.InvalidByteStringException;
-import com.syntifi.casper.sdk.exception.NoSuchTypeException;
-import com.syntifi.casper.sdk.model.AbstractJsonTests;
-import com.syntifi.casper.sdk.model.account.Account;
-import com.syntifi.casper.sdk.model.clvalue.AbstractCLValue;
-import com.syntifi.casper.sdk.model.clvalue.CLValueAny;
-import com.syntifi.casper.sdk.model.clvalue.CLValueBool;
-import com.syntifi.casper.sdk.model.clvalue.CLValueByteArray;
-import com.syntifi.casper.sdk.model.clvalue.CLValueFixedList;
-import com.syntifi.casper.sdk.model.clvalue.CLValueI32;
-import com.syntifi.casper.sdk.model.clvalue.CLValueI64;
-import com.syntifi.casper.sdk.model.clvalue.CLValueKey;
-import com.syntifi.casper.sdk.model.clvalue.CLValueList;
-import com.syntifi.casper.sdk.model.clvalue.CLValueMap;
-import com.syntifi.casper.sdk.model.clvalue.CLValueOption;
-import com.syntifi.casper.sdk.model.clvalue.CLValuePublicKey;
-import com.syntifi.casper.sdk.model.clvalue.CLValueResult;
-import com.syntifi.casper.sdk.model.clvalue.CLValueString;
-import com.syntifi.casper.sdk.model.clvalue.CLValueTuple1;
-import com.syntifi.casper.sdk.model.clvalue.CLValueTuple2;
-import com.syntifi.casper.sdk.model.clvalue.CLValueTuple3;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU128;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU256;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU32;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU512;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU64;
-import com.syntifi.casper.sdk.model.clvalue.CLValueU8;
-import com.syntifi.casper.sdk.model.clvalue.CLValueURef;
-import com.syntifi.casper.sdk.model.clvalue.CLValueUnit;
-import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
-import com.syntifi.casper.sdk.model.clvalue.encdec.StringByteHelper;
-import com.syntifi.casper.sdk.model.contract.Contract;
-import com.syntifi.casper.sdk.model.key.AlgorithmTag;
-import com.syntifi.casper.sdk.model.key.Key;
-import com.syntifi.casper.sdk.model.key.KeyTag;
-import com.syntifi.casper.sdk.model.key.PublicKey;
-import com.syntifi.casper.sdk.model.transfer.Transfer;
-import com.syntifi.casper.sdk.model.uref.URef;
-import com.syntifi.casper.sdk.model.uref.URefAccessRight;
-
-import org.javatuples.Pair;
-import org.javatuples.Triplet;
-import org.javatuples.Unit;
-import org.json.JSONException;
-import org.junit.jupiter.api.Test;
-import org.skyscreamer.jsonassert.JSONAssert;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Unit tests for {@link StoredValueData}
- *
- * @author Alexandre Carvalho
- * @author Andre Bertolace
- * @since 0.0.1
- */
-public class StoredValueTests extends AbstractJsonTests {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(StoredValueTests.class);
-
- private static final String API_VERSION = "1.3.2";
- private static final String MERKLE_PROOF = "-- erased --";
-
- @Test
- void validate_CLValueAny_Mapping()
- throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-any.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueAny
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueAny);
-
- CLValueAny expectedClValue = new CLValueAny("Any Object Test");
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- // assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueU8_Mapping()
- throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-u8.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueU8
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueU8);
-
- CLValueU8 expectedClValue = new CLValueU8((byte) 1);
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueU32_Mapping() throws IOException, CLValueEncodeException, DynamicInstanceException,
- NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-u32.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueU32
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueU32);
-
- CLValueU32 expectedClValue = new CLValueU32(4294967295L);
- expectedClValue.setParsed(expectedClValue.getValue().toString());
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueU64_Mapping() throws IOException, CLValueEncodeException, DynamicInstanceException,
- NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-u64.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueU64
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueU64);
- CLValueU64 expectedClValue = new CLValueU64(new BigInteger("18446744073709551615", 10));
- expectedClValue.setParsed(expectedClValue.getValue().toString(10));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueU128_Mapping() throws IOException, CLValueEncodeException, DynamicInstanceException,
- NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-u128.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueU128
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueU128);
- CLValueU128 expectedClValue = new CLValueU128(new BigInteger("340282366920938463463374607431768211455", 10));
- expectedClValue.setParsed(expectedClValue.getValue().toString(10));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueU256_Mapping() throws IOException, CLValueEncodeException, DynamicInstanceException,
- NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-u256.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueU256
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueU256);
- CLValueU256 expectedClValue = new CLValueU256(
- new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935", 10));
- expectedClValue.setParsed(expectedClValue.getValue().toString(10));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueI64_Mapping() throws IOException, CLValueEncodeException, DynamicInstanceException,
- NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-i64.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueI64
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueI64);
- CLValueI64 expectedClValue = new CLValueI64(9223372036854775807L);
- expectedClValue.setParsed(expectedClValue.getValue().toString());
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueString_Mapping()
- throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-string.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be string
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueString);
- CLValueString expectedClValue = new CLValueString("the string");
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueTuple1_Mapping_with_bool() throws IOException, CLValueEncodeException,
- DynamicInstanceException, CLValueEncodeException, NoSuchTypeException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-tuple1-bool.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueTuple1
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueTuple1);
- CLValueTuple1 expectedClValue = new CLValueTuple1(new Unit<>(new CLValueBool(true)));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueTuple2_Mapping_with_i32_string() throws IOException, CLValueEncodeException,
- DynamicInstanceException, CLValueEncodeException, NoSuchTypeException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-tuple2-i32-string.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueTuple2
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueTuple2);
- CLValueTuple2 expectedClValue = new CLValueTuple2(
- new Pair<>(new CLValueI32(1), new CLValueString("Hello, World!")));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueTuple3_Mapping_with_u8_string_bool() throws IOException, CLValueEncodeException,
- DynamicInstanceException, CLValueEncodeException, NoSuchTypeException, JSONException {
- String inputJson = getPrettyJson(
- loadJsonFromFile("stored-value-samples/stored-value-tuple3-u8-string-bool.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueTuple3
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueTuple3);
- CLValueTuple3 expectedClValue = new CLValueTuple3(
- new Triplet<>(new CLValueU8((byte) 1), new CLValueString("Hello, World!"), new CLValueBool(true)));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueTuple3_Mapping_with_i32_string_bool() throws IOException, CLValueEncodeException,
- DynamicInstanceException, CLValueEncodeException, NoSuchTypeException, JSONException {
- String inputJson = getPrettyJson(
- loadJsonFromFile("stored-value-samples/stored-value-tuple3-i32-string-bool.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueTuple3
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueTuple3);
- CLValueTuple3 expectedClValue = new CLValueTuple3(
- new Triplet<>(new CLValueI32(1), new CLValueString("Hello, World!"), new CLValueBool(true)));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueTuple3_Mapping_with_tuple1_bool_string_bool() throws IOException, CLValueEncodeException,
- DynamicInstanceException, CLValueEncodeException, NoSuchTypeException, JSONException {
- String inputJson = getPrettyJson(
- loadJsonFromFile("stored-value-samples/stored-value-tuple3-tuple1-bool-string-bool.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueTuple3
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueTuple3);
- CLValueTuple3 expectedClValue = new CLValueTuple3(new Triplet(
- new CLValueTuple1(new Unit(new CLValueBool(true))), new CLValueString("Hello, World!"),
- new CLValueBool(true)));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueTuple3_Mapping_with_tuple2_tuple1_u512_u512_tuple1_string_tuple1_bool()
- throws IOException, CLValueEncodeException, DynamicInstanceException, CLValueEncodeException,
- NoSuchTypeException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile(
- "stored-value-samples/stored-value-tuple3-tuple2-tuple1-u512-u512-tuple1-string-tuple1-bool.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueTuple3
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueTuple3);
- CLValueTuple3 expectedClValue = new CLValueTuple3(new Triplet(
- new CLValueTuple2(new Pair(
- new CLValueTuple1(new Unit(new CLValueU512(BigInteger.valueOf(2)))),
- new CLValueU512(BigInteger.valueOf(2)))),
- new CLValueTuple1(new Unit(new CLValueString("Hello, World!"))),
- new CLValueTuple1(new Unit(new CLValueBool(true)))));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueTuple3_Mapping_with_tuple1_u512_string_bool() throws IOException, CLValueEncodeException,
- DynamicInstanceException, CLValueEncodeException, NoSuchTypeException, JSONException {
- String inputJson = getPrettyJson(
- loadJsonFromFile("stored-value-samples/stored-value-tuple3-tuple1-u512-string-bool.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueTuple3
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueTuple3);
- CLValueTuple3 expectedClValue = new CLValueTuple3(new Triplet(
- new CLValueTuple1(new Unit(new CLValueU512(new BigInteger("123456789101112131415", 10)))),
- new CLValueString("Hello, World!"), new CLValueBool(true)));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
- String serializedExpected = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
- LOGGER.debug("Serialized Expected JSON: {}", serializedExpected);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueList_Mapping_with_i32() throws IOException, CLValueEncodeException, DynamicInstanceException,
- NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-list-i32.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueList
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueList);
- CLValueList expectedClValue = new CLValueList(
- Arrays.asList(new CLValueI32(1), new CLValueI32(2), new CLValueI32(3)));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueFixedList_Mapping_with_i32() throws IOException, CLValueEncodeException,
- DynamicInstanceException, NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-fixedlist-i32.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueList
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueFixedList);
- CLValueFixedList expectedClValue = new CLValueFixedList(
- Arrays.asList(new CLValueI32(1), new CLValueI32(2), new CLValueI32(3)));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueFixedList_Mapping_with_tuple1_i32() throws IOException, CLValueEncodeException,
- DynamicInstanceException, NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(
- loadJsonFromFile("stored-value-samples/stored-value-fixedlist-tuple1-i32.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueList
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueFixedList);
- CLValueFixedList expectedClValue = new CLValueFixedList(Arrays.asList(
- new CLValueTuple1(new Unit<>(new CLValueI32(1))), new CLValueTuple1(new Unit<>(new CLValueI32(2))),
- new CLValueTuple1(new Unit<>(new CLValueI32(3)))));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueFixedList_Mapping_with_i32_odd_byte_length() throws IOException, CLValueEncodeException,
- DynamicInstanceException, NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(
- loadJsonFromFile("stored-value-samples/stored-value-fixedlist-i32-odd-byte-length.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- Throwable exception = assertThrows(JsonMappingException.class,
- () -> OBJECT_MAPPER.readValue(inputJson, StoredValueData.class));
- assertEquals(InvalidByteStringException.class, exception.getCause().getClass());
- }
-
- @Test
- void validate_CLValueFixedList_Mapping_with_i32_wrong_byte_length()
- throws JsonMappingException, JsonProcessingException, IOException {
- String inputJson = getPrettyJson(
- loadJsonFromFile("stored-value-samples/stored-value-fixedlist-i32-wrong-byte-length.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- Throwable exception = assertThrows(JsonMappingException.class,
- () -> OBJECT_MAPPER.readValue(inputJson, StoredValueData.class));
- assertEquals(CLValueDecodeException.class, exception.getCause().getClass());
- }
-
- @Test
- void validate_CLValueList_Mapping_with_tuple2_i32_i32() throws IOException, CLValueEncodeException,
- DynamicInstanceException, NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(
- loadJsonFromFile("stored-value-samples/stored-value-list-tuple2-i32-i32.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueList
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueList);
- CLValueList expectedClValue = new CLValueList(
- Arrays.asList(new CLValueTuple2(new Pair<>(new CLValueI32(1), new CLValueI32(1))),
- new CLValueTuple2(new Pair<>(new CLValueI32(2), new CLValueI32(2))),
- new CLValueTuple2(new Pair<>(new CLValueI32(3), new CLValueI32(3)))));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueMap_Mapping_with_string_i32() throws IOException, CLValueEncodeException,
- DynamicInstanceException, NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-map-string-i32.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueMap
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueMap);
- Map map = new LinkedHashMap<>();
- map.put(new CLValueString("ABC"), new CLValueI32(10));
- CLValueMap expectedClValue = new CLValueMap(map);
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueMap_Mapping_with_string_tuple1_i32() throws IOException, CLValueEncodeException,
- DynamicInstanceException, NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(
- loadJsonFromFile("stored-value-samples/stored-value-map-string-tuple1-i32.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueMap
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueMap);
- Map map = new LinkedHashMap<>();
- map.put(new CLValueString("ABC"), new CLValueTuple1(new Unit(new CLValueI32(10))));
- CLValueMap expectedClValue = new CLValueMap(map);
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueResult_Mapping_with_i32_string() throws IOException, CLValueEncodeException,
- DynamicInstanceException, NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-result-i32-string.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueResult
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueResult);
- CLValueResult expectedClValue = new CLValueResult(new CLValueI32(10), new CLValueString("Uh oh"));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueResult_Mapping_with_i32_tuple1_string() throws IOException, CLValueEncodeException,
- DynamicInstanceException, NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(
- loadJsonFromFile("stored-value-samples/stored-value-result-i32-tuple1-string.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueResult
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueResult);
- CLValueResult expectedClValue = new CLValueResult(new CLValueI32(10),
- new CLValueTuple1(new Unit<>(new CLValueString("Uh oh"))));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueOption_Mapping_with_empty() throws IOException, CLValueEncodeException,
- DynamicInstanceException, NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-option-empty.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueOption
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueOption);
- CLValueOption expectedClValue = new CLValueOption(Optional.of(new CLValueBool(null)));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueOption_Mapping_with_bool() throws IOException, CLValueEncodeException,
- DynamicInstanceException, NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-option-bool.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueOption
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueOption);
- CLValueOption expectedClValue = new CLValueOption(Optional.of(new CLValueBool(true)));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueOption_Mapping_with_i32() throws IOException, CLValueEncodeException, DynamicInstanceException,
- NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-option-i32.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueOption
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueOption);
- CLValueOption expectedClValue = new CLValueOption(Optional.of(new CLValueI32(10)));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueOption_Mapping_with_tuple2_i32_string() throws IOException, CLValueEncodeException,
- DynamicInstanceException, NoSuchTypeException, JSONException, CLValueEncodeException {
- String inputJson = getPrettyJson(
- loadJsonFromFile("stored-value-samples/stored-value-option-tuple2-i32-string.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueOption
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueOption);
- CLValueOption expectedClValue = new CLValueOption(
- Optional.of(new CLValueTuple2(new Pair<>(new CLValueI32(1), new CLValueString("Hello, World!")))));
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueUnit_Mapping() throws IOException, CLValueEncodeException, DynamicInstanceException,
- CLValueEncodeException, NoSuchTypeException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-unit.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueUnit
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueUnit);
- CLValueUnit expectedClValue = new CLValueUnit();
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueURef_Mapping() throws IOException, CLValueEncodeException, DynamicInstanceException,
- NoSuchTypeException, JSONException, InvalidByteStringException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-uref.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValuURef
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueURef);
- CLValueURef expectedClValue = new CLValueURef(new URef(
- StringByteHelper
- .hexStringToByteArray("2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"),
- URefAccessRight.READ_ADD_WRITE));
- expectedClValue.setParsed("the uref");
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueKey_Mapping_of_account() throws IOException, CLValueEncodeException, DynamicInstanceException,
- NoSuchTypeException, JSONException, InvalidByteStringException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-key-account.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueKey
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueKey);
- Key key = new Key();
- key.setTag(KeyTag.ACCOUNT);
- key.setKey(StringByteHelper
- .hexStringToByteArray("2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"));
- CLValueKey expectedClValue = new CLValueKey(key);
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueKey_Mapping_of_hash() throws IOException, CLValueEncodeException, DynamicInstanceException,
- NoSuchTypeException, JSONException, InvalidByteStringException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-key-hash.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueKey
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueKey);
- Key key = new Key();
- key.setTag(KeyTag.HASH);
- key.setKey(StringByteHelper
- .hexStringToByteArray("2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"));
- CLValueKey expectedClValue = new CLValueKey(key);
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValuePublicKey_Mapping() throws IOException, CLValueEncodeException, DynamicInstanceException,
- NoSuchTypeException, JSONException, InvalidByteStringException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-publickey.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValuePublicKey
- assertTrue(sv.getStoredValue().getValue() instanceof CLValuePublicKey);
- PublicKey pk = new PublicKey();
- pk.setTag(AlgorithmTag.ED25519);
- pk.setKey(StringByteHelper
- .hexStringToByteArray("2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"));
- CLValuePublicKey expectedClValue = new CLValuePublicKey(pk);
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_CLValueByteArray_Mapping() throws IOException, CLValueEncodeException, DynamicInstanceException,
- CLValueEncodeException, NoSuchTypeException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-bytearray.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
- // Should be CLValueByteArray
- assertTrue(sv.getStoredValue().getValue() instanceof CLValueByteArray);
- CLValueByteArray expectedClValue = new CLValueByteArray(
- new byte[] { 122, -50, 107, 117, -83, -99, 95, 64, -35, 5, 34, 44, 108, -122, 69, -78, 28, -20, 71, 119,
- 98, 48, -34, 0, 111, -53, -39, 107, -38, 124, 73, -75 });
-
- StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
-
- assertEquals(expected, sv);
-
- String expectedJson = getPrettyJson(expected);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_Account_Mapping() throws JsonMappingException, JsonProcessingException, IOException, JSONException {
- /*
- * curl -X POST -H 'Content-Type: application/json' -d
- * '{"jsonrpc":"2.0","id":"1","method":"state_get_item",
- * "params":{"state_root_hash":
- * "09ac52260e370ed56bba5283a79b03d524b4f420bf964d7e629b0819dd1be09d", "key":
- * "account-hash-e1431ecb9f20f2a6e6571886b1e2f9dec49ebc6b2d3d640a53530abafba9bfa1"}
- * }' http://195.201.142.76:7777/rpc | json_pp
- */
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-account.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
-
- assertTrue(sv.getStoredValue().getValue() instanceof Account);
-
- String expectedJson = getPrettyJson(sv);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_Contract_Mapping() throws JsonMappingException, JsonProcessingException, IOException, JSONException {
- /*
- * curl -X POST -H 'Content-Type: application/json' -d
- * '{"jsonrpc":"2.0","id":"1","method":"state_get_item",
- * "params":{"state_root_hash":
- * "09ac52260e370ed56bba5283a79b03d524b4f420bf964d7e629b0819dd1be09d", "key":
- * "hash-d2469afeb99130f0be7c9ce230a84149e6d756e306ef8cf5b8a49d5182e41676"} }'
- * http://195.201.142.76:7777/rpc | json_pp
- */
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-contract.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
-
- assertTrue(sv.getStoredValue().getValue() instanceof Contract);
-
- String expectedJson = getPrettyJson(sv);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_Contract_Mapping_with_access_as_groups()
- throws JsonMappingException, JsonProcessingException, IOException, JSONException {
- String inputJson = getPrettyJson(
- loadJsonFromFile("stored-value-samples/stored-value-contract-access-groups.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
-
- assertTrue(sv.getStoredValue().getValue() instanceof Contract);
-
- String expectedJson = getPrettyJson(sv);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- @Test
- void validate_Transfer_Mapping() throws JsonMappingException, JsonProcessingException, IOException, JSONException {
- String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-transfer.json"));
-
- LOGGER.debug("Original JSON: {}", inputJson);
-
- StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
-
- assertTrue(sv.getStoredValue().getValue() instanceof Transfer);
-
- String expectedJson = getPrettyJson(sv);
-
- LOGGER.debug("Serialized JSON: {}", expectedJson);
-
- JSONAssert.assertEquals(inputJson, expectedJson, false);
- }
-
- private StoredValueData createAndInitExpectedStoredValueData(AbstractCLValue, ?> expectedClValue)
- throws IOException, CLValueEncodeException, DynamicInstanceException, NoSuchTypeException {
- StoredValueData expected = new StoredValueData();
- expected.setApiVersion(API_VERSION);
- expected.setMerkleProof(MERKLE_PROOF);
-
- StoredValueCLValue svClValue = new StoredValueCLValue();
- svClValue.setValue(expectedClValue);
- expected.setStoredValue(svClValue);
-
- // This is done here to account for the missing encode call made by jackson
- // serializer
- try (CLValueEncoder clve = new CLValueEncoder()) {
- expectedClValue.encode(clve);
- }
-
- return expected;
- }
+package com.syntifi.casper.sdk.model.storedvalue;
+
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.syntifi.casper.sdk.exception.*;
+import com.syntifi.casper.sdk.model.AbstractJsonTests;
+import com.syntifi.casper.sdk.model.account.Account;
+import com.syntifi.casper.sdk.model.clvalue.*;
+import com.syntifi.casper.sdk.model.clvalue.encdec.CLValueEncoder;
+import com.syntifi.casper.sdk.model.clvalue.encdec.StringByteHelper;
+import com.syntifi.casper.sdk.model.contract.Contract;
+import com.syntifi.casper.sdk.model.key.AlgorithmTag;
+import com.syntifi.casper.sdk.model.key.Key;
+import com.syntifi.casper.sdk.model.key.KeyTag;
+import com.syntifi.casper.sdk.model.key.PublicKey;
+import com.syntifi.casper.sdk.model.transfer.Transfer;
+import com.syntifi.casper.sdk.model.uref.URef;
+import com.syntifi.casper.sdk.model.uref.URefAccessRight;
+import org.javatuples.Pair;
+import org.javatuples.Triplet;
+import org.javatuples.Unit;
+import org.json.JSONException;
+import org.junit.jupiter.api.Test;
+import org.skyscreamer.jsonassert.JSONAssert;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * Unit tests for {@link StoredValueData}
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+public class StoredValueTests extends AbstractJsonTests {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(StoredValueTests.class);
+
+ private static final String API_VERSION = "1.3.2";
+ private static final String MERKLE_PROOF = "-- erased --";
+
+ @Test
+ void validate_CLValueAny_Mapping() throws IOException, CLValueEncodeException, NoSuchTypeException, JSONException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-any.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueAny
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueAny);
+
+ CLValueAny expectedClValue = new CLValueAny("Any Object Test");
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ // assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueU8_Mapping() throws IOException, CLValueEncodeException, NoSuchTypeException, JSONException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-u8.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueU8
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueU8);
+
+ CLValueU8 expectedClValue = new CLValueU8((byte) 1);
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueU32_Mapping() throws IOException, NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-u32.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueU32
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueU32);
+
+ CLValueU32 expectedClValue = new CLValueU32(4294967295L);
+ expectedClValue.setParsed(expectedClValue.getValue().toString());
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueU64_Mapping() throws IOException, NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-u64.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueU64
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueU64);
+ CLValueU64 expectedClValue = new CLValueU64(new BigInteger("18446744073709551615", 10));
+ expectedClValue.setParsed(expectedClValue.getValue().toString(10));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueU128_Mapping() throws IOException, NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-u128.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueU128
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueU128);
+ CLValueU128 expectedClValue = new CLValueU128(new BigInteger("340282366920938463463374607431768211455", 10));
+ expectedClValue.setParsed(expectedClValue.getValue().toString(10));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueU256_Mapping() throws IOException, NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-u256.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueU256
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueU256);
+ CLValueU256 expectedClValue = new CLValueU256(
+ new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935", 10));
+ expectedClValue.setParsed(expectedClValue.getValue().toString(10));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueI64_Mapping() throws IOException, NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-i64.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueI64
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueI64);
+ CLValueI64 expectedClValue = new CLValueI64(9223372036854775807L);
+ expectedClValue.setParsed(expectedClValue.getValue().toString());
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueString_Mapping() throws IOException, CLValueEncodeException, NoSuchTypeException, JSONException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-string.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be string
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueString);
+ CLValueString expectedClValue = new CLValueString("the string");
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueTuple1_Mapping_with_bool() throws IOException,
+ CLValueEncodeException, NoSuchTypeException, JSONException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-tuple1-bool.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueTuple1
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueTuple1);
+ CLValueTuple1 expectedClValue = new CLValueTuple1(new Unit<>(new CLValueBool(true)));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueTuple2_Mapping_with_i32_string() throws IOException,
+ CLValueEncodeException, NoSuchTypeException, JSONException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-tuple2-i32-string.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueTuple2
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueTuple2);
+ CLValueTuple2 expectedClValue = new CLValueTuple2(
+ new Pair<>(new CLValueI32(1), new CLValueString("Hello, World!")));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueTuple3_Mapping_with_u8_string_bool() throws IOException,
+ CLValueEncodeException, NoSuchTypeException, JSONException {
+ String inputJson = getPrettyJson(
+ loadJsonFromFile("stored-value-samples/stored-value-tuple3-u8-string-bool.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueTuple3
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueTuple3);
+ CLValueTuple3 expectedClValue = new CLValueTuple3(
+ new Triplet<>(new CLValueU8((byte) 1), new CLValueString("Hello, World!"), new CLValueBool(true)));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueTuple3_Mapping_with_i32_string_bool() throws IOException,
+ CLValueEncodeException, NoSuchTypeException, JSONException {
+ String inputJson = getPrettyJson(
+ loadJsonFromFile("stored-value-samples/stored-value-tuple3-i32-string-bool.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueTuple3
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueTuple3);
+ CLValueTuple3 expectedClValue = new CLValueTuple3(
+ new Triplet<>(new CLValueI32(1), new CLValueString("Hello, World!"), new CLValueBool(true)));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueTuple3_Mapping_with_tuple1_bool_string_bool() throws IOException, CLValueEncodeException, NoSuchTypeException, JSONException {
+ String inputJson = getPrettyJson(
+ loadJsonFromFile("stored-value-samples/stored-value-tuple3-tuple1-bool-string-bool.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueTuple3
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueTuple3);
+ CLValueTuple3 expectedClValue = new CLValueTuple3(new Triplet<>(
+ new CLValueTuple1(new Unit<>(new CLValueBool(true))), new CLValueString("Hello, World!"),
+ new CLValueBool(true)));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueTuple3_Mapping_with_tuple2_tuple1_u512_u512_tuple1_string_tuple1_bool()
+ throws IOException, CLValueEncodeException,
+ NoSuchTypeException, JSONException {
+ String inputJson = getPrettyJson(loadJsonFromFile(
+ "stored-value-samples/stored-value-tuple3-tuple2-tuple1-u512-u512-tuple1-string-tuple1-bool.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueTuple3
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueTuple3);
+ CLValueTuple3 expectedClValue = new CLValueTuple3(new Triplet<>(
+ new CLValueTuple2(new Pair<>(
+ new CLValueTuple1(new Unit<>(new CLValueU512(BigInteger.valueOf(2)))),
+ new CLValueU512(BigInteger.valueOf(2)))),
+ new CLValueTuple1(new Unit<>(new CLValueString("Hello, World!"))),
+ new CLValueTuple1(new Unit<>(new CLValueBool(true)))));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueTuple3_Mapping_with_tuple1_u512_string_bool() throws IOException, CLValueEncodeException, NoSuchTypeException, JSONException {
+ String inputJson = getPrettyJson(
+ loadJsonFromFile("stored-value-samples/stored-value-tuple3-tuple1-u512-string-bool.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueTuple3
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueTuple3);
+ CLValueTuple3 expectedClValue = new CLValueTuple3(new Triplet<>(
+ new CLValueTuple1(new Unit<>(new CLValueU512(new BigInteger("123456789101112131415", 10)))),
+ new CLValueString("Hello, World!"), new CLValueBool(true)));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+ String serializedExpected = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+ LOGGER.debug("Serialized Expected JSON: {}", serializedExpected);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueList_Mapping_with_i32() throws IOException,
+ NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-list-i32.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueList
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueList);
+ CLValueList expectedClValue = new CLValueList(
+ Arrays.asList(new CLValueI32(1), new CLValueI32(2), new CLValueI32(3)));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueFixedList_Mapping_with_i32() throws IOException,
+ NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-fixedlist-i32.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueList
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueFixedList);
+ CLValueFixedList expectedClValue = new CLValueFixedList(
+ Arrays.asList(new CLValueI32(1), new CLValueI32(2), new CLValueI32(3)));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueFixedList_Mapping_with_tuple1_i32() throws IOException, NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(
+ loadJsonFromFile("stored-value-samples/stored-value-fixedlist-tuple1-i32.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueList
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueFixedList);
+ CLValueFixedList expectedClValue = new CLValueFixedList(Arrays.asList(
+ new CLValueTuple1(new Unit<>(new CLValueI32(1))), new CLValueTuple1(new Unit<>(new CLValueI32(2))),
+ new CLValueTuple1(new Unit<>(new CLValueI32(3)))));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueFixedList_Mapping_with_i32_odd_byte_length() throws IOException {
+ String inputJson = getPrettyJson(
+ loadJsonFromFile("stored-value-samples/stored-value-fixedlist-i32-odd-byte-length.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ Throwable exception = assertThrows(JsonMappingException.class,
+ () -> OBJECT_MAPPER.readValue(inputJson, StoredValueData.class));
+ assertEquals(InvalidByteStringException.class, exception.getCause().getClass());
+ }
+
+ @Test
+ void validate_CLValueFixedList_Mapping_with_i32_wrong_byte_length()
+ throws IOException {
+ String inputJson = getPrettyJson(
+ loadJsonFromFile("stored-value-samples/stored-value-fixedlist-i32-wrong-byte-length.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ Throwable exception = assertThrows(JsonMappingException.class,
+ () -> OBJECT_MAPPER.readValue(inputJson, StoredValueData.class));
+ assertEquals(CLValueDecodeException.class, exception.getCause().getClass());
+ }
+
+ @Test
+ void validate_CLValueList_Mapping_with_tuple2_i32_i32() throws IOException, NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(
+ loadJsonFromFile("stored-value-samples/stored-value-list-tuple2-i32-i32.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueList
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueList);
+ CLValueList expectedClValue = new CLValueList(
+ Arrays.asList(new CLValueTuple2(new Pair<>(new CLValueI32(1), new CLValueI32(1))),
+ new CLValueTuple2(new Pair<>(new CLValueI32(2), new CLValueI32(2))),
+ new CLValueTuple2(new Pair<>(new CLValueI32(3), new CLValueI32(3)))));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueMap_Mapping_with_string_i32() throws IOException,
+ NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-map-string-i32.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueMap
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueMap);
+ Map map = new LinkedHashMap<>();
+ map.put(new CLValueString("ABC"), new CLValueI32(10));
+ CLValueMap expectedClValue = new CLValueMap(map);
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueMap_Mapping_with_string_tuple1_i32() throws IOException,
+ NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(
+ loadJsonFromFile("stored-value-samples/stored-value-map-string-tuple1-i32.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueMap
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueMap);
+ Map map = new LinkedHashMap<>();
+ map.put(new CLValueString("ABC"), new CLValueTuple1(new Unit<>(new CLValueI32(10))));
+ CLValueMap expectedClValue = new CLValueMap(map);
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueResult_Mapping_with_i32_string() throws IOException,
+ NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-result-i32-string.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueResult
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueResult);
+ CLValueResult expectedClValue = new CLValueResult(new CLValueI32(10), new CLValueString("Uh oh"));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueResult_Mapping_with_i32_tuple1_string() throws IOException,
+ NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(
+ loadJsonFromFile("stored-value-samples/stored-value-result-i32-tuple1-string.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueResult
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueResult);
+ CLValueResult expectedClValue = new CLValueResult(new CLValueI32(10),
+ new CLValueTuple1(new Unit<>(new CLValueString("Uh oh"))));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueOption_Mapping_with_empty() throws IOException,
+ NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-option-empty.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueOption
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueOption);
+ CLValueOption expectedClValue = new CLValueOption(Optional.of(new CLValueBool(null)));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueOption_Mapping_with_bool() throws IOException,
+ NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-option-bool.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueOption
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueOption);
+ CLValueOption expectedClValue = new CLValueOption(Optional.of(new CLValueBool(true)));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueOption_Mapping_with_i32() throws IOException,
+ NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-option-i32.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueOption
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueOption);
+ CLValueOption expectedClValue = new CLValueOption(Optional.of(new CLValueI32(10)));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueOption_Mapping_with_tuple2_i32_string() throws IOException,
+ NoSuchTypeException, JSONException, CLValueEncodeException {
+ String inputJson = getPrettyJson(
+ loadJsonFromFile("stored-value-samples/stored-value-option-tuple2-i32-string.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueOption
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueOption);
+ CLValueOption expectedClValue = new CLValueOption(
+ Optional.of(new CLValueTuple2(new Pair<>(new CLValueI32(1), new CLValueString("Hello, World!")))));
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueUnit_Mapping() throws IOException,
+ CLValueEncodeException, NoSuchTypeException, JSONException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-unit.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueUnit
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueUnit);
+ CLValueUnit expectedClValue = new CLValueUnit();
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueURef_Mapping() throws IOException, CLValueEncodeException,
+ NoSuchTypeException, JSONException, InvalidByteStringException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-uref.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValuURef
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueURef);
+ CLValueURef expectedClValue = new CLValueURef(new URef(
+ StringByteHelper
+ .hexStringToByteArray("2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"),
+ URefAccessRight.READ_ADD_WRITE));
+ expectedClValue.setParsed("the uref");
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueKey_Mapping_of_account() throws IOException, CLValueEncodeException,
+ NoSuchTypeException, JSONException, InvalidByteStringException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-key-account.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueKey
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueKey);
+ Key key = new Key();
+ key.setTag(KeyTag.ACCOUNT);
+ key.setKey(StringByteHelper
+ .hexStringToByteArray("2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"));
+ CLValueKey expectedClValue = new CLValueKey(key);
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueKey_Mapping_of_hash() throws IOException, CLValueEncodeException,
+ NoSuchTypeException, JSONException, InvalidByteStringException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-key-hash.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueKey
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueKey);
+ Key key = new Key();
+ key.setTag(KeyTag.HASH);
+ key.setKey(StringByteHelper
+ .hexStringToByteArray("2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"));
+ CLValueKey expectedClValue = new CLValueKey(key);
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValuePublicKey_Mapping() throws IOException, CLValueEncodeException,
+ NoSuchTypeException, JSONException, InvalidByteStringException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-publickey.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValuePublicKey
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValuePublicKey);
+ PublicKey pk = new PublicKey();
+ pk.setTag(AlgorithmTag.ED25519);
+ pk.setKey(StringByteHelper
+ .hexStringToByteArray("2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"));
+ CLValuePublicKey expectedClValue = new CLValuePublicKey(pk);
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_CLValueByteArray_Mapping() throws IOException,
+ CLValueEncodeException, NoSuchTypeException, JSONException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-bytearray.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+ // Should be CLValueByteArray
+ assertTrue(sv.getStoredValue().getValue() instanceof CLValueByteArray);
+ CLValueByteArray expectedClValue = new CLValueByteArray(
+ new byte[]{122, -50, 107, 117, -83, -99, 95, 64, -35, 5, 34, 44, 108, -122, 69, -78, 28, -20, 71, 119,
+ 98, 48, -34, 0, 111, -53, -39, 107, -38, 124, 73, -75});
+
+ StoredValueData expected = createAndInitExpectedStoredValueData(expectedClValue);
+
+ assertEquals(expected, sv);
+
+ String expectedJson = getPrettyJson(expected);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_Account_Mapping() throws IOException, JSONException {
+ /*
+ * curl -X POST -H 'Content-Type: application/json' -d
+ * '{"jsonrpc":"2.0","id":"1","method":"state_get_item",
+ * "params":{"state_root_hash":
+ * "09ac52260e370ed56bba5283a79b03d524b4f420bf964d7e629b0819dd1be09d", "key":
+ * "account-hash-e1431ecb9f20f2a6e6571886b1e2f9dec49ebc6b2d3d640a53530abafba9bfa1"}
+ * }' http://195.201.142.76:7777/rpc | json_pp
+ */
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-account.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+
+ assertTrue(sv.getStoredValue().getValue() instanceof Account);
+
+ String expectedJson = getPrettyJson(sv);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_Contract_Mapping() throws IOException, JSONException {
+ /*
+ * curl -X POST -H 'Content-Type: application/json' -d
+ * '{"jsonrpc":"2.0","id":"1","method":"state_get_item",
+ * "params":{"state_root_hash":
+ * "09ac52260e370ed56bba5283a79b03d524b4f420bf964d7e629b0819dd1be09d", "key":
+ * "hash-d2469afeb99130f0be7c9ce230a84149e6d756e306ef8cf5b8a49d5182e41676"} }'
+ * http://195.201.142.76:7777/rpc | json_pp
+ */
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-contract.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+
+ assertTrue(sv.getStoredValue().getValue() instanceof Contract);
+
+ String expectedJson = getPrettyJson(sv);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_Contract_Mapping_with_access_as_groups()
+ throws IOException, JSONException {
+ String inputJson = getPrettyJson(
+ loadJsonFromFile("stored-value-samples/stored-value-contract-access-groups.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+
+ assertTrue(sv.getStoredValue().getValue() instanceof Contract);
+
+ String expectedJson = getPrettyJson(sv);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ @Test
+ void validate_Transfer_Mapping() throws IOException, JSONException {
+ String inputJson = getPrettyJson(loadJsonFromFile("stored-value-samples/stored-value-transfer.json"));
+
+ LOGGER.debug("Original JSON: {}", inputJson);
+
+ StoredValueData sv = OBJECT_MAPPER.readValue(inputJson, StoredValueData.class);
+
+ assertTrue(sv.getStoredValue().getValue() instanceof Transfer);
+
+ String expectedJson = getPrettyJson(sv);
+
+ LOGGER.debug("Serialized JSON: {}", expectedJson);
+
+ JSONAssert.assertEquals(inputJson, expectedJson, false);
+ }
+
+ private StoredValueData createAndInitExpectedStoredValueData(AbstractCLValue, ?> expectedClValue)
+ throws IOException, CLValueEncodeException, NoSuchTypeException {
+ StoredValueData expected = new StoredValueData();
+ expected.setApiVersion(API_VERSION);
+ expected.setMerkleProof(MERKLE_PROOF);
+
+ StoredValueCLValue svClValue = new StoredValueCLValue();
+ svClValue.setValue(expectedClValue);
+ expected.setStoredValue(svClValue);
+
+ // This is done here to account for the missing encode call made by jackson
+ // serializer
+ try (CLValueEncoder clve = new CLValueEncoder()) {
+ expectedClValue.encode(clve, false);
+ }
+
+ return expected;
+ }
}
\ No newline at end of file
diff --git a/src/test/java/com/syntifi/casper/sdk/model/transfer/TransferDataTest.java b/src/test/java/com/syntifi/casper/sdk/model/transfer/TransferDataTest.java
index a986c3d9..6b5c20d5 100644
--- a/src/test/java/com/syntifi/casper/sdk/model/transfer/TransferDataTest.java
+++ b/src/test/java/com/syntifi/casper/sdk/model/transfer/TransferDataTest.java
@@ -1,23 +1,20 @@
package com.syntifi.casper.sdk.model.transfer;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.io.IOException;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.syntifi.casper.sdk.model.AbstractJsonTests;
import com.syntifi.casper.sdk.model.status.StatusDataTests;
-
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
/**
* Unit tests for {@link TransferData}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -27,19 +24,19 @@ public class TransferDataTest extends AbstractJsonTests {
private static final Logger LOGGER = LoggerFactory.getLogger(StatusDataTests.class);
@Test
- void validateDictionaryMapping() throws JsonMappingException, JsonProcessingException, IOException, JSONException {
+ void validateDictionaryMapping() throws IOException, JSONException {
// curl -X POST -H 'Content-Type: application/json' -d
// '{"id":"0","jsonrpc":"2.0","method":"chain_get_block_transfers","params":{"block_identifier":{"Height":198148}}}'
// http://195.201.142.76:7777/rpc
- String inputJson = getPrettyJson(loadJsonFromFile("transfer-samples/transfer.json"));
+ final String inputJson = getPrettyJson(loadJsonFromFile("transfer-samples/transfer.json"));
LOGGER.debug("Original JSON: {}", inputJson);
- TransferData transfer = OBJECT_MAPPER.readValue(inputJson, TransferData.class);
+ final TransferData transfer = OBJECT_MAPPER.readValue(inputJson, TransferData.class);
- assertTrue(transfer.getTransfers().get(0) instanceof Transfer);
+ assertNotNull(transfer.getTransfers().get(0));
- String expectedJson = getPrettyJson(transfer);
+ final String expectedJson = getPrettyJson(transfer);
LOGGER.debug("Serialized JSON: {}", expectedJson);
diff --git a/src/test/java/com/syntifi/casper/sdk/service/AbstractJsonRpcTests.java b/src/test/java/com/syntifi/casper/sdk/service/AbstractJsonRpcTests.java
index 2f7bb81a..c2810bb9 100644
--- a/src/test/java/com/syntifi/casper/sdk/service/AbstractJsonRpcTests.java
+++ b/src/test/java/com/syntifi/casper/sdk/service/AbstractJsonRpcTests.java
@@ -1,40 +1,40 @@
-package com.syntifi.casper.sdk.service;
-
-import java.net.MalformedURLException;
-
-import com.syntifi.casper.sdk.model.AbstractJsonTests;
-
-import org.junit.jupiter.api.BeforeAll;
-
-import lombok.AccessLevel;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-
-/**
- * Abstract class for testing json rpc methods
- *
- * @author Alexandre Carvalho
- * @author Andre Bertolace
- * @since 0.0.1
- */
-public abstract class AbstractJsonRpcTests extends AbstractJsonTests {
- @Getter
- @AllArgsConstructor(access = AccessLevel.PRIVATE)
- public enum CasperNetwork {
- MAIN_NET("74.208.245.69", 7777), TEST_NET("136.243.187.84", 7777);
-
- private String ip;
- private int port;
- }
-
- protected static CasperService casperServiceMainnet;
- protected static CasperService casperServiceTestnet;
-
- @BeforeAll
- public static void setUp() throws MalformedURLException {
- casperServiceMainnet = CasperService.usingPeer(CasperNetwork.MAIN_NET.getIp(),
- CasperNetwork.MAIN_NET.getPort());
- casperServiceTestnet = CasperService.usingPeer(CasperNetwork.TEST_NET.getIp(),
- CasperNetwork.TEST_NET.getPort());
- }
-}
+package com.syntifi.casper.sdk.service;
+
+import java.net.MalformedURLException;
+
+import com.syntifi.casper.sdk.model.AbstractJsonTests;
+
+import org.junit.jupiter.api.BeforeAll;
+
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * Abstract class for testing json rpc methods
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+public abstract class AbstractJsonRpcTests extends AbstractJsonTests {
+ @Getter
+ @AllArgsConstructor(access = AccessLevel.PRIVATE)
+ public enum CasperNetwork {
+ MAIN_NET("63.33.251.206", 7777), TEST_NET("139.180.189.141", 7777);
+
+ private final String ip;
+ private final int port;
+ }
+
+ protected static CasperService casperServiceMainnet;
+ protected static CasperService casperServiceTestnet;
+
+ @BeforeAll
+ public static void setUp() throws MalformedURLException {
+ casperServiceMainnet = CasperService.usingPeer(CasperNetwork.MAIN_NET.getIp(),
+ CasperNetwork.MAIN_NET.getPort());
+ casperServiceTestnet = CasperService.usingPeer(CasperNetwork.TEST_NET.getIp(),
+ CasperNetwork.TEST_NET.getPort());
+ }
+}
diff --git a/src/test/java/com/syntifi/casper/sdk/service/CasperDeployServiceTests.java b/src/test/java/com/syntifi/casper/sdk/service/CasperDeployServiceTests.java
new file mode 100644
index 00000000..28ea0855
--- /dev/null
+++ b/src/test/java/com/syntifi/casper/sdk/service/CasperDeployServiceTests.java
@@ -0,0 +1,80 @@
+package com.syntifi.casper.sdk.service;
+
+import com.syntifi.casper.sdk.exception.CLValueEncodeException;
+import com.syntifi.casper.sdk.exception.DynamicInstanceException;
+import com.syntifi.casper.sdk.exception.InvalidByteStringException;
+import com.syntifi.casper.sdk.exception.NoSuchTypeException;
+import com.syntifi.casper.sdk.model.common.Ttl;
+import com.syntifi.casper.sdk.model.deploy.Deploy;
+import com.syntifi.casper.sdk.model.deploy.DeployResult;
+import com.syntifi.casper.sdk.model.key.PublicKey;
+import com.syntifi.crypto.key.Ed25519PrivateKey;
+
+import org.bouncycastle.util.encoders.Hex;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.GeneralSecurityException;
+import java.net.URISyntaxException;
+import java.nio.file.Paths;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Objects;
+import java.util.Random;
+
+/**
+ * Casper Deploy Service test
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.2.0
+ */
+public class CasperDeployServiceTests extends AbstractJsonRpcTests {
+ private static final Logger LOGGER = LoggerFactory.getLogger(CasperDeployService.class);
+ /**
+ * Loads test key file from resources
+ *
+ * @param filename the file name
+ * @return a string with file path from resources
+ * @throws URISyntaxException thrown if it can't parse file url to URI for fetching the path
+ */
+ protected String getResourcesKeyPath(String filename) throws URISyntaxException {
+ return Paths.get(Objects.requireNonNull(getClass().getClassLoader().getResource(filename)).toURI()).toString();
+ }
+ @Test
+ void testDeployTransferOnTestnet() throws IOException, InvalidByteStringException, CLValueEncodeException, NoSuchTypeException, GeneralSecurityException, DynamicInstanceException, URISyntaxException {
+ Ed25519PrivateKey alice = new Ed25519PrivateKey();
+ Ed25519PrivateKey bob = new Ed25519PrivateKey();
+ alice.readPrivateKey(getResourcesKeyPath("deploy-accounts/Alice_SyntiFi_secret_key.pem"));
+ bob.readPrivateKey(getResourcesKeyPath("deploy-accounts/Bob_SyntiFi_secret_key.pem"));
+
+ long id = Math.abs(new Random().nextInt());
+ Ttl ttl = Ttl
+ .builder()
+ .ttl("30m")
+ .build();
+ Random rnd = new Random();
+ boolean coin = rnd.nextBoolean();
+ Ed25519PrivateKey from;
+ PublicKey to;
+ if (coin) {
+ from = alice;
+ to = PublicKey.fromAbstractPublicKey(bob.derivePublicKey());
+ } else {
+ from = bob;
+ to = PublicKey.fromAbstractPublicKey(alice.derivePublicKey());
+ }
+
+ Deploy deploy = CasperDeployService.buildTransferDeploy(from, to,
+ BigInteger.valueOf(2500000000L), "casper-test",
+ id, BigInteger.valueOf(100000000L), 1L, ttl, new Date(),
+ new ArrayList<>());
+ DeployResult deployResult = casperServiceTestnet.putDeploy(deploy);
+ Assertions.assertEquals(deployResult.getDeployHash(), Hex.toHexString(deploy.getHash().getDigest()));
+ }
+}
diff --git a/src/test/java/com/syntifi/casper/sdk/service/CasperServiceTests.java b/src/test/java/com/syntifi/casper/sdk/service/CasperServiceTests.java
index 640a60a8..3017fd07 100644
--- a/src/test/java/com/syntifi/casper/sdk/service/CasperServiceTests.java
+++ b/src/test/java/com/syntifi/casper/sdk/service/CasperServiceTests.java
@@ -8,20 +8,17 @@
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import com.syntifi.casper.sdk.identifier.block.HashBlockIdentifier;
import com.syntifi.casper.sdk.identifier.block.HeightBlockIdentifier;
-import com.syntifi.casper.sdk.model.account.Account;
import com.syntifi.casper.sdk.model.account.AccountData;
import com.syntifi.casper.sdk.model.auction.AuctionData;
-import com.syntifi.casper.sdk.model.auction.AuctionState;
import com.syntifi.casper.sdk.model.block.JsonBlock;
import com.syntifi.casper.sdk.model.block.JsonBlockData;
import com.syntifi.casper.sdk.model.clvalue.CLValueString;
import com.syntifi.casper.sdk.model.clvalue.encdec.StringByteHelper;
-import com.syntifi.casper.sdk.model.deploy.Deploy;
import com.syntifi.casper.sdk.model.deploy.DeployData;
import com.syntifi.casper.sdk.model.deploy.executabledeploy.ModuleBytes;
import com.syntifi.casper.sdk.model.deploy.executabledeploy.StoredContractByHash;
@@ -32,7 +29,6 @@
import com.syntifi.casper.sdk.model.key.PublicKey;
import com.syntifi.casper.sdk.model.peer.PeerData;
import com.syntifi.casper.sdk.model.stateroothash.StateRootHashData;
-import com.syntifi.casper.sdk.model.status.MinimalBlockInfo;
import com.syntifi.casper.sdk.model.status.StatusData;
import com.syntifi.casper.sdk.model.storedvalue.StoredValueAccount;
import com.syntifi.casper.sdk.model.storedvalue.StoredValueContract;
@@ -47,14 +43,13 @@
/**
* Unit tests for {@link CasperService}
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
public class CasperServiceTests extends AbstractJsonRpcTests {
-
- private static Logger LOGGER = LoggerFactory.getLogger(CasperServiceTests.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(CasperServiceTests.class);
/**
* Test if get block matches requested by height
@@ -99,8 +94,6 @@ void testFirstBlocksPublicKeySerialization() {
/**
* Retrieve peers list and assert it has elements
- *
- * @throws Throwable
*/
@Test
void retrieveNonEmptyListOfPeers() {
@@ -135,7 +128,7 @@ void getBlockByHeight() {
JsonBlock block = blockData.getBlock();
assertEquals("0000000000000000000000000000000000000000000000000000000000000000",
block.getHeader().getParentHash());
- assertEquals("2fe9630b7790852e4409d815b04ca98f37effcdf9097d317b9b9b8ad658f47c8", block.getHash().toLowerCase());
+ assertEquals("2fe9630b7790852e4409d815b04ca98f37effcdf9097d317b9b9b8ad658f47c8", block.getHash());
assertNotNull(blockData);
}
@@ -154,11 +147,11 @@ void getTransferByHeight() {
assertEquals(1, transferData.getTransfers().size());
Transfer transaction = transferData.getTransfers().get(0);
assertEquals("c22fab5364c793bb859fd259b808ea4c101be8421b7d638dc8f52490ab3c3539",
- transaction.getDeployHash().toLowerCase());
+ transaction.getDeployHash());
assertEquals("account-hash-2363d9065b1ecc26f50f108c22c8f3bbe6a891c81e37e0e454c68370708a6937",
- transaction.getFrom().toLowerCase());
+ transaction.getFrom());
assertEquals("account-hash-288797af5b4eeb5d4f36bd228b2e6479a77a27e808597ced1a7d6afe4c29febc",
- transaction.getTo().toLowerCase());
+ transaction.getTo());
assertEquals(BigInteger.valueOf(597335999990000L), transaction.getAmount());
}
@@ -170,11 +163,12 @@ void getTransferByHash() {
assertNotNull(transferData);
assertEquals(1, transferData.getTransfers().size());
Transfer transaction = transferData.getTransfers().get(0);
- assertEquals("c22fab5364c793bb859fd259b808ea4c101be8421b7d638dc8f52490ab3c3539", transaction.getDeployHash().toLowerCase());
+ assertEquals("c22fab5364c793bb859fd259b808ea4c101be8421b7d638dc8f52490ab3c3539",
+ transaction.getDeployHash());
assertEquals("account-hash-2363d9065b1ecc26f50f108c22c8f3bbe6a891c81e37e0e454c68370708a6937",
- transaction.getFrom().toLowerCase());
+ transaction.getFrom());
assertEquals("account-hash-288797af5b4eeb5d4f36bd228b2e6479a77a27e808597ced1a7d6afe4c29febc",
- transaction.getTo().toLowerCase());
+ transaction.getTo());
assertEquals(BigInteger.valueOf(597335999990000L), transaction.getAmount());
}
@@ -190,7 +184,7 @@ void getStateRootHashByHeight() {
StateRootHashData stateRootHashData = casperServiceMainnet.getStateRootHash(new HeightBlockIdentifier(0));
assertNotNull(stateRootHashData);
assertEquals("8e22e3983d5ca9bcf9804bd3a6724b8c24effdf317a1d9c05175125a1bf8b679",
- stateRootHashData.getStateRootHash().toLowerCase());
+ stateRootHashData.getStateRootHash());
}
@Test
@@ -200,7 +194,7 @@ void getStateRootHashByHash() {
assertNotNull(stateRootHashData);
assertEquals("8e22e3983d5ca9bcf9804bd3a6724b8c24effdf317a1d9c05175125a1bf8b679",
- stateRootHashData.getStateRootHash().toLowerCase());
+ stateRootHashData.getStateRootHash());
}
@Test
@@ -208,7 +202,7 @@ void getBlockState() {
// FIXME: This test fails on mainnet, no root hash.
String stateRootHash = "c0eb76e0c3c7a928a0cb43e82eb4fad683d9ad626bcd3b7835a466c0587b0fff";
String key = "account-hash-a9efd010c7cee2245b5bad77e70d9beb73c8776cbe4698b2d8fdf6c8433d5ba0";
- List path = Arrays.asList("special_value");
+ List path = Collections.singletonList("special_value");
StoredValueData result = casperServiceTestnet.getStateItem(stateRootHash, key, path);
assertTrue(result.getStoredValue().getValue() instanceof CLValueString);
@@ -223,22 +217,22 @@ void getDeploy() {
.getDeploy("614030ac705ed2067fed57d30545b3a4974ffc40a1c32f72e3b7b7442d6c83a3");
assertNotNull(deployData);
- assertTrue(deployData.getDeploy() instanceof Deploy);
+ assertNotNull(deployData.getDeploy());
assertTrue(deployData.getDeploy().getSession() instanceof StoredContractByHash);
assertTrue(deployData.getExecutionResults().get(0).getResult() instanceof Success);
- assertTrue(((Success) deployData.getExecutionResults().get(0).getResult()).getEffect().getTransforms().get(2)
+ assertTrue(((Success) deployData.getExecutionResults().get(0).getResult()).getEffect().getTransforms().get(0)
.getTransform() instanceof WriteCLValue);
assertTrue(deployData.getDeploy().getPayment() instanceof ModuleBytes);
assertTrue(deployData.getDeploy().getSession() instanceof StoredContractByHash);
String tmp = ((StoredContractByHash) deployData.getDeploy().getSession()).getHash();
- assertEquals("ccb576d6ce6dec84a551e48f0d0b7af89ddba44c7390b690036257a04a3ae9ea", tmp.toLowerCase());
+ assertEquals("ccb576d6ce6dec84a551e48f0d0b7af89ddba44c7390b690036257a04a3ae9ea", tmp);
}
@Test
void getStatus() {
StatusData status = casperServiceMainnet.getStatus();
assertNotNull(status);
- assertTrue(status.getLastAddedBlockInfo() instanceof MinimalBlockInfo);
+ assertNotNull(status.getLastAddedBlockInfo());
assertNotNull(status.getStartStateRootHash());
}
@@ -267,9 +261,9 @@ void getAccountStateInfoByBlockHash() {
new HashBlockIdentifier("721767b0bcf867ccab81b3a47b1443bbef38b2ee9e2b791288f6e2a427181931"));
assertNotNull(account);
- assertTrue(account.getAccount() instanceof Account);
+ assertNotNull(account.getAccount());
assertEquals("account-hash-f1075fce3b8cd4eab748b8705ca02444a5e35c0248662649013d8a5cb2b1a87c",
- account.getAccount().getHash().toLowerCase());
+ account.getAccount().getHash());
}
@Test
@@ -279,9 +273,9 @@ void getAccountStateInfoByBlockHeight() {
new HeightBlockIdentifier(236509));
assertNotNull(account);
- assertTrue(account.getAccount() instanceof Account);
+ assertNotNull(account.getAccount());
assertEquals("account-hash-f1075fce3b8cd4eab748b8705ca02444a5e35c0248662649013d8a5cb2b1a87c",
- account.getAccount().getHash().toLowerCase());
+ account.getAccount().getHash());
}
@Test
@@ -290,7 +284,7 @@ void getAuctionInfoByBlockHash() {
new HashBlockIdentifier("58e0BBfB1FFf590965b6B12898CBE8b2C12FFe73fA5360E1dA42a66c3B9416BC"));
assertNotNull(auction);
- assertTrue(auction.getAuctionState() instanceof AuctionState);
+ assertNotNull(auction.getAuctionState());
assertEquals(423571, auction.getAuctionState().getHeight());
}
@@ -299,7 +293,7 @@ void getAuctionInfoByBlockHeight() {
AuctionData auction = casperServiceMainnet.getStateAuctionInfo(new HeightBlockIdentifier(423571));
assertNotNull(auction);
- assertTrue(auction.getAuctionState() instanceof AuctionState);
+ assertNotNull(auction.getAuctionState());
assertEquals(423571, auction.getAuctionState().getHeight());
}
@@ -309,12 +303,13 @@ void getEraInfoBySwitchBlockByHeight() throws JSONException, IOException {
assertNotNull(eraInfoData);
assertNotNull(eraInfoData.getEraSummary());
- assertEquals("57a4257ccae4dc00fc1b2a0bde545b07937b8cdd18ea5544a70496cd67872d71",
- eraInfoData.getEraSummary().getStateRootHash().toLowerCase());
+ assertEquals("57a4257ccae4dc00fc1b2a0bde545b07937b8cdd18ea5544a70496cd67872d71",
+ eraInfoData.getEraSummary().getStateRootHash());
- //String inputJson = getPrettyJson(loadJsonFromFile("era-info-samples/era-info-by-switch-block.json"));
+ // String inputJson =
+ // getPrettyJson(loadJsonFromFile("era-info-samples/era-info-by-switch-block.json"));
- //JSONAssert.assertEquals(inputJson, getPrettyJson(eraInfoData), false);
+ // JSONAssert.assertEquals(inputJson, getPrettyJson(eraInfoData), false);
}
@Test
@@ -325,26 +320,29 @@ void getEraInfoBySwitchBlockByHash() throws JSONException, IOException {
assertNotNull(eraInfoData);
assertNotNull(eraInfoData.getEraSummary());
assertEquals("485a33d5c737030432fba0c3b15c1cc6b372fd286677bf9f29d4ab8b1f0c9223",
- eraInfoData.getEraSummary().getStateRootHash().toLowerCase());
+ eraInfoData.getEraSummary().getStateRootHash());
- //String inputJson = getPrettyJson(loadJsonFromFile("era-info-samples/era-info-by-switch-block.json"));
+ // String inputJson =
+ // getPrettyJson(loadJsonFromFile("era-info-samples/era-info-by-switch-block.json"));
- //JSONAssert.assertEquals(inputJson, getPrettyJson(eraInfoData), false);
+ // JSONAssert.assertEquals(inputJson, getPrettyJson(eraInfoData), false);
}
/*
- @Test
- void getCasperClientExceptionExceptionBlockNotKnown() throws JSONException, IOException {
- String expectedMessage = "block not known (code: -32001)";
-
- BlockIdentifier blockIdentifier = new HashBlockIdentifier(
- "abc");
-
- EraInfoData test = casperServiceMainnet.getEraInfoBySwitchBlock(blockIdentifier);
- CasperClientException casperClientException = assertThrows(CasperClientException.class,
- () -> casperServiceMainnet.getEraInfoBySwitchBlock(blockIdentifier));
-
- assertEquals(expectedMessage, casperClientException.getMessage());
- }
- */
+ * @Test
+ * void getCasperClientExceptionExceptionBlockNotKnown() {
+ * String expectedMessage = "block not known (code: -32001)";
+ *
+ * BlockIdentifier blockIdentifier = new HashBlockIdentifier(
+ * "abc");
+ *
+ * EraInfoData test =
+ * casperServiceMainnet.getEraInfoBySwitchBlock(blockIdentifier);
+ * CasperClientException casperClientException =
+ * assertThrows(CasperClientException.class,
+ * () -> casperServiceMainnet.getEraInfoBySwitchBlock(blockIdentifier));
+ *
+ * assertEquals(expectedMessage, casperClientException.getMessage());
+ * }
+ */
}
diff --git a/src/test/resources/deploy-accounts/Alice_SyntiFi_secret_key.pem b/src/test/resources/deploy-accounts/Alice_SyntiFi_secret_key.pem
new file mode 100644
index 00000000..24e62f08
--- /dev/null
+++ b/src/test/resources/deploy-accounts/Alice_SyntiFi_secret_key.pem
@@ -0,0 +1,3 @@
+-----BEGIN PRIVATE KEY-----
+MC4CAQAwBQYDK2VwBCIEIH2M1kZw541526zK3ky6mMj30XeYgNZwad1VQLcFWdkf
+-----END PRIVATE KEY-----
diff --git a/src/test/resources/deploy-accounts/Bob_SyntiFi_secret_key.pem b/src/test/resources/deploy-accounts/Bob_SyntiFi_secret_key.pem
new file mode 100644
index 00000000..61d5b88f
--- /dev/null
+++ b/src/test/resources/deploy-accounts/Bob_SyntiFi_secret_key.pem
@@ -0,0 +1,3 @@
+-----BEGIN PRIVATE KEY-----
+MC4CAQAwBQYDK2VwBCIEII2NJBFjfK4o1Q2sDzWKPteRQskItesS69PsAXXfnJNP
+-----END PRIVATE KEY-----
diff --git a/src/test/resources/deploy-samples/deploy-serialization.json b/src/test/resources/deploy-samples/deploy-serialization.json
new file mode 100644
index 00000000..a83bc277
--- /dev/null
+++ b/src/test/resources/deploy-samples/deploy-serialization.json
@@ -0,0 +1,48 @@
+{
+ "hash": "01da3c604f71e0e7df83ff1ab4ef15bb04de64ca02e3d2b78de6950e8b5ee187",
+ "header": {
+ "account": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c",
+ "timestamp": "2020-11-17T00:39:24.072Z",
+ "ttl": "1h",
+ "gas_price": 1,
+ "body_hash": "4811966d37fe5674a8af4001884ea0d9042d1c06668da0c963769c3a01ebd08f",
+ "dependencies": ["0101010101010101010101010101010101010101010101010101010101010101"],
+ "chain_name": "casper-example"
+ },
+ "payment": {
+ "StoredContractByName": {
+ "name": "casper-example",
+ "entry_point": "example-entry-point",
+ "args": [
+ [
+ "quantity",
+ {
+ "cl_type": "I32",
+ "bytes": "e8030000",
+ "parsed": 1000
+ }
+ ]
+ ]
+ }
+ },
+ "session": {
+ "Transfer": {
+ "args": [
+ [
+ "amount",
+ {
+ "cl_type": "I32",
+ "bytes": "e8030000",
+ "parsed": 1000
+ }
+ ]
+ ]
+ }
+ },
+ "approvals": [
+ {
+ "signer": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c",
+ "signature": "012dbf03817a51794a8e19e0724884075e6d1fbec326b766ecfa6658b41f81290da85e23b24e88b1c8d9761185c961daee1adab0649912a6477bcd2e69bd91bd08"
+ }
+ ]
+}
\ No newline at end of file