Skip to content

Commit

Permalink
Fixed state deserialize which is an uint enum in contract definition. (
Browse files Browse the repository at this point in the history
…hyperledger#467)

Signed-off-by: Luciano da Silva Ribas <[email protected]>

Co-authored-by: Matthew B White <[email protected]>
  • Loading branch information
2 people authored and fraVlaca committed Sep 3, 2021
1 parent d15e09b commit 25594f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class CommercialPaper extends State {
public final static String ISSUED = "ISSUED";
public final static String TRADING = "TRADING";
public final static String REDEEMED = "REDEEMED";
public final static String[] STATES = new String[] {ISSUED, TRADING, REDEEMED};

@Property()
private String state="";
Expand Down Expand Up @@ -161,8 +162,9 @@ public static CommercialPaper deserialize(byte[] data) {
String maturityDateTime = json.getString("maturityDateTime");
String owner = json.getString("owner");
int faceValue = json.getInt("faceValue");
String state = json.getString("state");
return createInstance(issuer, paperNumber, issueDateTime, maturityDateTime, faceValue,owner,state);
int currentState = json.getInt("currentState");
String state = STATES[currentState-1];
return createInstance(issuer, paperNumber, issueDateTime, maturityDateTime, faceValue, owner, state);
}

public static byte[] serialize(CommercialPaper paper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class CommercialPaper extends State {
public final static String ISSUED = "ISSUED";
public final static String TRADING = "TRADING";
public final static String REDEEMED = "REDEEMED";
public final static String[] STATES = new String[] {ISSUED, TRADING, REDEEMED};

@Property()
private String state="";
Expand Down Expand Up @@ -162,7 +163,8 @@ public static CommercialPaper deserialize(byte[] data) {
String maturityDateTime = json.getString("maturityDateTime");
String owner = json.getString("owner");
int faceValue = json.getInt("faceValue");
String state = json.getString("state");
int currentState = json.getInt("currentState");
String state = STATES[currentState-1];
return createInstance(issuer, paperNumber, issueDateTime, maturityDateTime, faceValue, owner, state);
}

Expand Down

0 comments on commit 25594f8

Please sign in to comment.