Skip to content

Commit 67be93d

Browse files
authored
Merge pull request #273 from /issues/272
Added WriteUnbonding transform data class
2 parents ebebb52 + a22b97f commit 67be93d

6 files changed

Lines changed: 1846 additions & 22 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ apply plugin: 'java'
1414

1515
group = 'network.casper'
1616
// Version number update for release
17-
version='2.5.5'
17+
version='2.5.6'
1818
sourceCompatibility = 1.8
1919
targetCompatibility = 1.8
2020

src/main/java/com/casper/sdk/model/deploy/UnbondingPurse.java

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.casper.sdk.annotation.ExcludeFromJacocoGeneratedReport;
44
import com.casper.sdk.model.key.PublicKey;
5-
import com.fasterxml.jackson.annotation.JsonIgnore;
65
import com.fasterxml.jackson.annotation.JsonProperty;
76
import com.casper.sdk.model.uref.URef;
87
import lombok.AllArgsConstructor;
@@ -19,6 +18,12 @@
1918
* @author Alexandre Carvalho
2019
* @author Andre Bertolace
2120
* @since 0.0.1
21+
*
22+
* Changed 5/24
23+
* @author Carl Norburn
24+
* Refactored to match the Casper documentation
25+
* <a href="https://docs.casper.network/concepts/serialization-standard/#unbondingpurse"></a>
26+
*
2227
*/
2328
@Getter
2429
@Setter
@@ -31,11 +36,11 @@ public class UnbondingPurse {
3136
* Unbonding amount
3237
*/
3338
@JsonProperty("amount")
34-
private BigInteger unbondingAmount;
35-
36-
@JsonIgnore
3739
private BigInteger amount;
3840

41+
@JsonProperty("new_validator")
42+
private BigInteger newValidator;
43+
3944
/**
4045
* the bondingPurse's {@link URef}
4146
*/
@@ -60,25 +65,16 @@ public class UnbondingPurse {
6065
@JsonProperty("validator_public_key")
6166
private PublicKey validatorPublicKey;
6267

63-
/**
64-
* getter for unbondingAmount json serialization
65-
*
66-
* @return cost as expected for json serialization
67-
*/
68-
@JsonProperty("unbonding_amount")
68+
@JsonProperty("amount")
6969
@ExcludeFromJacocoGeneratedReport
70-
protected String getJsonUnbondingAmount() {
71-
return this.unbondingAmount.toString(10);
70+
protected String getJsonAmount() {
71+
return this.amount.toString(10);
7272
}
7373

74-
/**
75-
* setter for unbondingAmount from json deserialized value
76-
*
77-
* @param value the deserialized value
78-
*/
79-
@JsonProperty("unbonding_amount")
74+
@JsonProperty("amount")
8075
@ExcludeFromJacocoGeneratedReport
81-
protected void setJsonUnbondingAmount(String value) {
82-
this.unbondingAmount = new BigInteger(value, 10);
76+
protected void setJsonAmount(String value) {
77+
this.amount = new BigInteger(value, 10);
8378
}
79+
8480
}

src/main/java/com/casper/sdk/model/deploy/transform/TransformTypeData.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public enum TransformTypeData {
2222
WRITE_DEPLOY_INFO("WriteDeployInfo", WriteDeployInfo.class),
2323
WRITE_ERA_INFO("WriteEraInfo", WriteEraInfo.class),
2424
WRITE_TRANSFER("WriteTransfer", WriteTransfer.class),
25-
WRITE_WITHDRAW("WriteWithdraw", WriteWithdraw.class);
25+
WRITE_WITHDRAW("WriteWithdraw", WriteWithdraw.class),
26+
WRITE_UNBONDING("WriteUnbonding", WriteUnbonding.class);
2627

2728
private final String name;
2829
private final Class<?> clazz;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.casper.sdk.model.deploy.transform;
2+
3+
import com.casper.sdk.model.deploy.UnbondingPurse;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.annotation.JsonTypeName;
6+
import lombok.*;
7+
8+
import java.util.List;
9+
10+
/**
11+
* An implementation of Transform that Writes the given Unbonding to global state.
12+
*
13+
* @author Carl Norburn
14+
* @see Transform
15+
* @since 2.5.6
16+
*/
17+
@Getter
18+
@Setter
19+
@Builder
20+
@AllArgsConstructor
21+
@NoArgsConstructor
22+
@JsonTypeName("WriteUnbonding")
23+
public class WriteUnbonding implements Transform {
24+
25+
@JsonProperty("WriteUnbonding")
26+
private List<UnbondingPurse> purses;
27+
28+
}

src/test/java/com/casper/sdk/model/deploy/DeployDataTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,22 @@ void validateDeployDataMapping_5() throws IOException, JSONException {
112112

113113
JSONAssert.assertEquals(inputJson, expectedJson, JSONCompareMode.NON_EXTENSIBLE);
114114
}
115+
@Test
116+
void validateDeployDataMapping_6() throws IOException, JSONException {
117+
final String inputJson = getPrettyJson(loadJsonFromFile("deploy-samples/deploy-v6.json"));
118+
119+
LOGGER.debug("Original JSON: {}", inputJson);
120+
121+
final DeployData dd = OBJECT_MAPPER.readValue(inputJson, DeployData.class);
122+
123+
assertNotNull(dd.getDeploy());
124+
125+
final String expectedJson = getPrettyJson(dd);
126+
127+
LOGGER.debug("Serialized JSON: {}", expectedJson);
128+
129+
JSONAssert.assertEquals(inputJson, expectedJson, JSONCompareMode.NON_EXTENSIBLE);
130+
}
115131

116132
@Test
117133
void validateDeployResultMapping() throws IOException, JSONException {

0 commit comments

Comments
 (0)