Skip to content

Commit

Permalink
Merge pull request #169 from casper-network/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
cnorburn authored Mar 22, 2023
2 parents 98db079 + 93ad2f3 commit 296cfc2
Show file tree
Hide file tree
Showing 69 changed files with 830 additions and 275 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
apply plugin: 'java'

group = 'network.casper'
version='2.1.0'
version='2.2.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sbs4jVersion=0.1.5
sbs4jVersion=0.1.6
cryptokeyVersion=0.4.0
lombokPluginVersion=6.2.0
jupiterVersion=5.9.0
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/com/casper/sdk/model/bid/VestingSchedule.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.casper.sdk.model.bid;

import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;

import java.math.BigInteger;
import java.util.LinkedList;
Expand Down Expand Up @@ -43,8 +39,10 @@ public class VestingSchedule {
@ExcludeFromJacocoGeneratedReport
protected void setJsonLockedAmounts(final List<String> lockedAmounts) {
List<BigInteger> list = new LinkedList<>();
for (String string : lockedAmounts) {
list.add(new BigInteger(string, 10));
if (lockedAmounts != null) {
for (String string : lockedAmounts) {
list.add(new BigInteger(string, 10));
}
}
this.lockedAmounts = list;
}
Expand Down
42 changes: 19 additions & 23 deletions src/main/java/com/casper/sdk/model/clvalue/AbstractCLValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,16 @@
import com.casper.sdk.model.clvalue.serde.CasperDeserializableObject;
import com.casper.sdk.model.clvalue.serde.CasperSerializableObject;
import com.casper.sdk.model.clvalue.serde.Target;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonTypeResolver;
import com.syntifi.crypto.key.encdec.Hex;
import dev.oak3.sbs4j.DeserializerBuffer;
import dev.oak3.sbs4j.SerializerBuffer;
import dev.oak3.sbs4j.exception.ValueDeserializationException;
import dev.oak3.sbs4j.exception.ValueSerializationException;
import dev.oak3.sbs4j.util.ByteUtils;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import lombok.*;

/**
* Base class for CLValues
Expand Down Expand Up @@ -54,6 +45,10 @@ public abstract class AbstractCLValue<T, P extends AbstractCLType>
@JsonIgnore
private T value;

public T getValue() {
return this.value;
}

public void setValue(T value) throws ValueSerializationException {
this.value = value;
this.serialize(new SerializerBuffer());
Expand Down Expand Up @@ -84,29 +79,30 @@ protected String getJsonBytes() {
return this.bytes;
}

@SneakyThrows({ValueDeserializationException.class})
@JsonSetter(value = "bytes")
@ExcludeFromJacocoGeneratedReport
protected void setJsonBytes(String bytes) {
this.bytes = bytes;

DeserializerBuffer deser = new DeserializerBuffer(this.bytes);

this.deserialize(deser);
}

@JsonIgnore
public abstract P getClType();

public abstract void setClType(P value);


protected void serializePrefixWithLength(SerializerBuffer ser) throws ValueSerializationException {
SerializerBuffer localSer = new SerializerBuffer();
serialize(localSer);
int size = localSer.toByteArray().length;
ser.writeI32(size);
}

@SneakyThrows({ValueDeserializationException.class})
@JsonSetter(value = "bytes")
@ExcludeFromJacocoGeneratedReport
protected void setJsonBytes(String bytes) {
this.bytes = bytes;

DeserializerBuffer deser = new DeserializerBuffer(this.bytes);

this.deserialize(deser);
}

@Override
public AbstractCLValue<?, ?> deserialize(DeserializerBuffer deser, Target target) throws ValueDeserializationException {
if (target.equals(Target.BYTE)) {
Expand All @@ -127,7 +123,7 @@ public void deserialize(DeserializerBuffer deserializerBuffer) throws ValueDeser
try {
this.deserializeCustom(deserializerBuffer);
} catch (Exception e) {
throw new ValueDeserializationException("Error serializing value", e);
throw new ValueDeserializationException("Error deserializing value", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.casper.sdk.model.clvalue;

import com.casper.sdk.model.clvalue.cltype.AbstractCLType;
import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
import com.casper.sdk.model.clvalue.cltype.AbstractCLTypeWithChildren;
import com.fasterxml.jackson.annotation.JsonSetter;
import dev.oak3.sbs4j.DeserializerBuffer;
import dev.oak3.sbs4j.exception.ValueDeserializationException;
import lombok.EqualsAndHashCode;
import lombok.SneakyThrows;

/**
* Abstract class for those CLValues which have a child collection
Expand All @@ -12,6 +17,40 @@
* @since 0.0.1
*/
@EqualsAndHashCode(callSuper = true)
public abstract class AbstractCLValueWithChildren<T, P extends AbstractCLType> extends AbstractCLValue<T, P> {
public abstract class AbstractCLValueWithChildren<T, P extends AbstractCLTypeWithChildren> extends AbstractCLValue<T, P> {
protected abstract void setChildTypes(T value);

/**
* This fires deserialization in case the json/jackson mapped bytes before CLType
* This only happens when whe have CLTypes with children types.
* <p>
* Should always be called in the end of the json setter for ClType within CLValueWithChildren
*/
@SneakyThrows({ValueDeserializationException.class})
protected void childTypesSet() {
if (getBytes().length() > 0) {
DeserializerBuffer deser = new DeserializerBuffer(this.getBytes());

this.deserialize(deser);
}
}

/**
* Sets the bytes and if the CLType is already set, fires bytes deserialization
*
* @param bytes the input bytes for this CLValue
*/
@Override
@SneakyThrows({ValueDeserializationException.class})
@JsonSetter(value = "bytes")
@ExcludeFromJacocoGeneratedReport
protected void setJsonBytes(String bytes) {
this.setBytes(bytes);

if (!getClType().getChildTypes().isEmpty()) {
DeserializerBuffer deser = new DeserializerBuffer(this.getBytes());

this.deserialize(deser);
}
}
}
7 changes: 6 additions & 1 deletion src/main/java/com/casper/sdk/model/clvalue/CLValueAny.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.oak3.sbs4j.DeserializerBuffer;
import dev.oak3.sbs4j.SerializerBuffer;
import dev.oak3.sbs4j.exception.ValueSerializationException;
import dev.oak3.sbs4j.util.ByteUtils;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -28,7 +29,6 @@
@Getter
@Setter
@NoArgsConstructor
//@EqualsAndHashCode(callSuper = true)
public class CLValueAny extends AbstractCLValue<byte[], CLTypeAny> {
private CLTypeAny clType = new CLTypeAny();

Expand Down Expand Up @@ -99,4 +99,9 @@ public int hashCode() {
result = result * PRIME + (thisClType == null ? 43 : thisClType.hashCode());
return result;
}

@Override
public String toString() {
return getValue() != null ? ByteUtils.encodeHexString(getValue()) : null;
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/casper/sdk/model/clvalue/CLValueBool.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ public void serialize(@NotNull SerializerBuffer ser, Target target) throws NoSuc
public void deserializeCustom(DeserializerBuffer deser) throws Exception {
this.setValue(deser.readBool());
}

@Override
public String toString() {
return getValue() != null ? getValue().toString() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.oak3.sbs4j.DeserializerBuffer;
import dev.oak3.sbs4j.SerializerBuffer;
import dev.oak3.sbs4j.exception.ValueSerializationException;
import dev.oak3.sbs4j.util.ByteUtils;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand Down Expand Up @@ -96,4 +97,9 @@ public int hashCode() {
result = result * PRIME + (thisClType == null ? 43 : thisClType.hashCode());
return result;
}

@Override
public String toString() {
return getValue() != null ? ByteUtils.encodeHexString(getValue()) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
* Casper List CLValue implementation
Expand Down Expand Up @@ -91,4 +92,9 @@ public void deserializeCustom(DeserializerBuffer deser) throws Exception {
protected void setListType(List<? extends AbstractCLValue<?, ?>> value) {
clType.setListType(value.get(0).getClType());
}

@Override
public String toString() {
return getValue() != null ? getValue().stream().map(item -> item.getValue().toString()).collect(Collectors.joining(", ")) : null;
}
}
11 changes: 6 additions & 5 deletions src/main/java/com/casper/sdk/model/clvalue/CLValueI32.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
import dev.oak3.sbs4j.DeserializerBuffer;
import dev.oak3.sbs4j.SerializerBuffer;
import dev.oak3.sbs4j.exception.ValueSerializationException;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;
import org.bouncycastle.util.encoders.Hex;

/**
Expand Down Expand Up @@ -69,4 +65,9 @@ public void serialize(SerializerBuffer ser, Target target) throws NoSuchTypeExce
public void deserializeCustom(DeserializerBuffer deser) throws Exception {
this.setValue(deser.readI32());
}

@Override
public String toString() {
return getValue() != null ? getValue().toString() : null;
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/casper/sdk/model/clvalue/CLValueI64.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public void serialize(SerializerBuffer ser, Target target) throws NoSuchTypeExce
public void deserializeCustom(DeserializerBuffer deser) throws Exception {
this.setValue(deser.readI64());
}

@Override
public String toString() {
return getValue() != null ? getValue().toString() : null;
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/casper/sdk/model/clvalue/CLValueKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ public void serialize(SerializerBuffer ser, Target target) throws NoSuchTypeExce
public void deserializeCustom(DeserializerBuffer deser) throws Exception {
this.setValue(Key.fromTaggedHexString(ByteUtils.encodeHexString(deser.readByteArray(33))));
}

@Override
public String toString() {
return getValue() != null ? getValue().toString() : null;
}
}
23 changes: 20 additions & 3 deletions src/main/java/com/casper/sdk/model/clvalue/CLValueList.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.casper.sdk.model.clvalue.cltype.AbstractCLTypeWithChildren;
import com.casper.sdk.model.clvalue.cltype.CLTypeData;
import com.casper.sdk.model.clvalue.cltype.CLTypeList;
import com.casper.sdk.model.clvalue.cltype.CLTypeMap;
import com.casper.sdk.model.clvalue.serde.Target;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import dev.oak3.sbs4j.DeserializerBuffer;
import dev.oak3.sbs4j.SerializerBuffer;
import dev.oak3.sbs4j.exception.ValueSerializationException;
Expand All @@ -15,8 +17,9 @@
import lombok.Setter;
import org.bouncycastle.util.encoders.Hex;

import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* Casper List CLValue implementation
Expand All @@ -34,6 +37,12 @@ public class CLValueList extends AbstractCLValueWithChildren<List<? extends Abst
@JsonProperty("cl_type")
private CLTypeList clType = new CLTypeList();

@JsonSetter("cl_type")
public void setClType(CLTypeList clType) {
this.clType = clType;
childTypesSet();
}

public CLValueList(List<? extends AbstractCLValue<?, ?>> value) throws ValueSerializationException {
setChildTypes(value);
this.setValue(value);
Expand Down Expand Up @@ -72,10 +81,13 @@ public void deserializeCustom(DeserializerBuffer deser) throws Exception {
CLValueI32 length = new CLValueI32();
length.deserializeCustom(deser);

List<AbstractCLValue<?, ?>> list = new LinkedList<>();
List<AbstractCLValue<?, ?>> list = new ArrayList<>();
for (int i = 0; i < length.getValue(); i++) {
AbstractCLValue<?, ?> child = CLTypeData.createCLValueFromCLTypeData(childrenType);
if (child.getClType() instanceof AbstractCLTypeWithChildren) {
if (child.getClType() instanceof CLTypeMap) {
((CLTypeMap) child.getClType())
.setKeyValueTypes(((CLTypeMap) clType.getListType()).getKeyValueTypes());
} else if (child.getClType() instanceof AbstractCLTypeWithChildren) {
((AbstractCLTypeWithChildren) child.getClType())
.setChildTypes(((AbstractCLTypeWithChildren) clType.getListType()).getChildTypes());
}
Expand All @@ -90,4 +102,9 @@ public void deserializeCustom(DeserializerBuffer deser) throws Exception {
protected void setChildTypes(List<? extends AbstractCLValue<?, ?>> value) {
clType.setListType(value.get(0).getClType());
}

@Override
public String toString() {
return getValue() != null ? getValue().stream().map(item -> item.getValue().toString()).collect(Collectors.joining(", ")) : null;
}
}
Loading

0 comments on commit 296cfc2

Please sign in to comment.