-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #331 from /issues/330
Issues/330 - TransactionTarget Stored json serialization and deserialization
- Loading branch information
Showing
17 changed files
with
441 additions
and
141 deletions.
There are no files selected for viewing
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
45 changes: 45 additions & 0 deletions
45
src/main/java/com/casper/sdk/model/transaction/target/ByHash.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,45 @@ | ||
package com.casper.sdk.model.transaction.target; | ||
|
||
import com.casper.sdk.exception.NoSuchTypeException; | ||
import com.casper.sdk.model.clvalue.serde.Target; | ||
import com.casper.sdk.model.common.Digest; | ||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import dev.oak3.sbs4j.SerializerBuffer; | ||
import dev.oak3.sbs4j.exception.ValueSerializationException; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
/** | ||
* The address identifying the invocable entity. | ||
* | ||
* @author ian@meywood.com | ||
*/ | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Setter | ||
@Getter | ||
public class ByHash implements TransactionInvocationTarget { | ||
@JsonValue | ||
private Digest hashAddress; | ||
|
||
@JsonCreator | ||
public ByHash(String hashAddress) { | ||
this.hashAddress = new Digest(hashAddress); | ||
} | ||
|
||
@Override | ||
public void serialize(final SerializerBuffer ser, final Target target) throws ValueSerializationException, NoSuchTypeException { | ||
ser.writeU8(getByteTag()); | ||
ser.writeByteArray(hashAddress.getDigest()); | ||
} | ||
|
||
@JsonIgnore | ||
@Override | ||
public byte getByteTag() { | ||
return 0; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/casper/sdk/model/transaction/target/ByName.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,38 @@ | ||
package com.casper.sdk.model.transaction.target; | ||
|
||
import com.casper.sdk.exception.NoSuchTypeException; | ||
import com.casper.sdk.model.clvalue.serde.Target; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import dev.oak3.sbs4j.SerializerBuffer; | ||
import dev.oak3.sbs4j.exception.ValueSerializationException; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
/** | ||
* The alias identifying the invocable entity. | ||
* | ||
* @author ian@meywood.com | ||
*/ | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Setter | ||
@Getter | ||
public class ByName implements TransactionInvocationTarget { | ||
@JsonValue | ||
private String name; | ||
|
||
@Override | ||
public void serialize(final SerializerBuffer ser, final Target target) throws ValueSerializationException, NoSuchTypeException { | ||
ser.writeU8(getByteTag()); | ||
ser.writeString(name); | ||
} | ||
|
||
@JsonIgnore | ||
@Override | ||
public byte getByteTag() { | ||
return 1; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/com/casper/sdk/model/transaction/target/ByPackageHash.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,53 @@ | ||
package com.casper.sdk.model.transaction.target; | ||
|
||
import com.casper.sdk.exception.NoSuchTypeException; | ||
import com.casper.sdk.model.clvalue.serde.Target; | ||
import com.casper.sdk.model.common.Digest; | ||
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.Optional; | ||
|
||
/** | ||
* The address and optional version identifying the package. | ||
* | ||
* @author ian@meywood.com | ||
*/ | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Setter | ||
@Getter | ||
public class ByPackageHash implements TransactionInvocationTarget { | ||
/** The package address. */ | ||
private Digest addr; | ||
/** If `None`, the latest enabled version is implied. */ | ||
@Getter(AccessLevel.NONE) | ||
@JsonProperty("version") | ||
private Long version; | ||
|
||
@JsonIgnore | ||
public Optional<Long> getVersion() { | ||
return Optional.ofNullable(version); | ||
} | ||
|
||
@Override | ||
public void serialize(final SerializerBuffer ser, final Target target) throws ValueSerializationException, NoSuchTypeException { | ||
ser.writeU8(getByteTag()); | ||
ser.writeByteArray(addr.getDigest()); | ||
if (getVersion().isPresent()) { | ||
ser.writeBool(true); | ||
ser.writeU32(version); | ||
} else { | ||
ser.writeBool(false); | ||
} | ||
} | ||
|
||
@JsonIgnore | ||
@Override | ||
public byte getByteTag() { | ||
return 2; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/casper/sdk/model/transaction/target/ByPackageName.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,52 @@ | ||
package com.casper.sdk.model.transaction.target; | ||
|
||
import com.casper.sdk.exception.NoSuchTypeException; | ||
import com.casper.sdk.model.clvalue.serde.Target; | ||
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.Optional; | ||
|
||
/** | ||
* The address and optional version identifying the package. | ||
* | ||
* @author ian@meywood.com | ||
*/ | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Setter | ||
@Getter | ||
public class ByPackageName implements TransactionInvocationTarget { | ||
/** the package name */ | ||
private String name; | ||
/** If `None`, the latest enabled version is implied. */ | ||
@Getter(AccessLevel.NONE) | ||
@JsonProperty("version") | ||
private Long version; | ||
|
||
@JsonIgnore | ||
public Optional<Long> getVersion() { | ||
return Optional.ofNullable(version); | ||
} | ||
|
||
@Override | ||
public void serialize(final SerializerBuffer ser, final Target target) throws ValueSerializationException, NoSuchTypeException { | ||
ser.writeU8(getByteTag()); | ||
ser.writeString(name); | ||
if (getVersion().isPresent()) { | ||
ser.writeBool(true); | ||
ser.writeU32(version); | ||
} else { | ||
ser.writeBool(false); | ||
} | ||
} | ||
|
||
@JsonIgnore | ||
@Override | ||
public byte getByteTag() { | ||
return 3; | ||
} | ||
} |
19 changes: 0 additions & 19 deletions
19
src/main/java/com/casper/sdk/model/transaction/target/HashAddress.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.