-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issues/262 - Push up common code in to AbstractStoredVersionedContract
- Loading branch information
Showing
4 changed files
with
73 additions
and
93 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...in/java/com/casper/sdk/model/deploy/executabledeploy/AbstractStoredVersionedContract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.casper.sdk.model.deploy.executabledeploy; | ||
|
||
import com.casper.sdk.exception.NoSuchTypeException; | ||
import com.casper.sdk.model.clvalue.AbstractCLValue; | ||
import com.casper.sdk.model.clvalue.CLValueOption; | ||
import com.casper.sdk.model.clvalue.CLValueU32; | ||
import com.casper.sdk.model.clvalue.serde.Target; | ||
import com.casper.sdk.model.deploy.NamedArg; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import dev.oak3.sbs4j.SerializerBuffer; | ||
import dev.oak3.sbs4j.exception.ValueSerializationException; | ||
import lombok.*; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Base class for versioned contracts. | ||
* | ||
* @author [email protected] | ||
*/ | ||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
abstract class AbstractStoredVersionedContract extends ExecutableDeployItemWithEntryPoint { | ||
|
||
/** contract version */ | ||
@JsonProperty("version") | ||
private Long version; | ||
|
||
/** Entry Point */ | ||
@JsonProperty("entry_point") | ||
private String entryPoint; | ||
|
||
/** @see NamedArg */ | ||
private List<NamedArg<?>> args; | ||
|
||
@JsonIgnore | ||
public Optional<Long> getVersion() { | ||
return Optional.ofNullable(version); | ||
} | ||
|
||
@Override | ||
public void serialize(final SerializerBuffer ser, final Target target) throws NoSuchTypeException, ValueSerializationException { | ||
ser.writeU8(getOrder()); | ||
serializeCustom(ser); | ||
|
||
final Optional<AbstractCLValue<?, ?>> innerValue; | ||
if (version == null) { | ||
innerValue = Optional.empty(); | ||
} else { | ||
innerValue = Optional.of(new CLValueU32(version)); | ||
} | ||
new CLValueOption(innerValue).serialize(ser, Target.JSON); | ||
|
||
ser.writeString(getEntryPoint()); | ||
serializeNamedArgs(ser, target); | ||
} | ||
|
||
protected abstract void serializeCustom(final SerializerBuffer ser); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
import static org.hamcrest.core.IsNull.notNullValue; | ||
|
||
/** | ||
* Unit tests for the StoredVersionedContractByHash class. | ||
* | ||
* @author [email protected] | ||
*/ | ||
class StoredVersionedContractByHashTest { | ||
|