Skip to content

Commit

Permalink
Merge pull request hyperledger-web3j#349 from mindro/master
Browse files Browse the repository at this point in the history
Added reward action to trace
  • Loading branch information
conor10 authored Feb 5, 2018
2 parents c74a874 + 5ddb4fe commit 231b15a
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,91 @@ public String toString() {
}
}

@JsonDeserialize()
public static class RewardAction implements Action {

private String author;
private String value;
private String rewardType;

public RewardAction() {
}

public RewardAction(String author, String value, String rewardType) {
this.author = author;
this.value = value;
this.rewardType = rewardType;
}

public BigInteger getValue() {
return Numeric.decodeQuantity(value);
}

public String getValueRaw() {
return value;
}

public void setValue(String value) {
this.value = value;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

public String getRewardType() {
return rewardType;
}

public void setRewardType(String rewardType) {
this.rewardType = rewardType;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof RewardAction)) {
return false;
}

RewardAction that = (RewardAction) o;

if (getAuthor() != null ? !getAuthor().equals(that.getAuthor())
: that.getAuthor() != null) {
return false;
}
if (getValueRaw() != null ? !getValueRaw().equals(that.getValueRaw())
: that.getValueRaw() != null) {
return false;
}
return getRewardType() != null ? getRewardType().equals(that.getRewardType())
: that.getRewardType() == null;
}

@Override
public int hashCode() {
int result = getAuthor() != null ? getAuthor().hashCode() : 0;
result = 31 * result + (getValueRaw() != null ? getValueRaw().hashCode() : 0);
result = 31 * result + (getRewardType() != null ? getRewardType().hashCode() : 0);
return result;
}

@Override
public String toString() {
return "RewardAction{"
+ "author='" + getAuthor() + '\''
+ ", value='" + getValueRaw() + '\''
+ ", rewardType='" + getRewardType() + '\''
+ '}';
}
}

public static class Result {

private String address;
Expand Down Expand Up @@ -675,6 +760,8 @@ public Action deserialize(JsonParser jsonParser, DeserializationContext context)
return objectMapper.convertValue(root, CreateAction.class);
} else if (root.has("refundAddress")) {
return objectMapper.convertValue(root, SuicideAction.class);
} else if (root.has("rewardType")) {
return objectMapper.convertValue(root, RewardAction.class);
}

return null;
Expand Down
26 changes: 26 additions & 0 deletions parity/src/test/java/org/web3j/protocol/parity/ResponseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,19 @@ public void testParityFullTraceResponseTraces() {
+ " \"transactionHash\": \"0xea6649db0f88d5400159853bf2c5b752ce724435dfb85b35f8725cf4cdc1ad6d\",\n"
+ " \"transactionPosition\": 2,\n"
+ " \"type\": \"suicide\"\n"
+ " }, {\n"
+ " \"action\": {\n"
+ " \"author\": \"0xb8d2ac822f3d0445f5b83d32b0b176c2cb3d0e60\",\n"
+ " \"value\": \"0x0\",\n"
+ " \"rewardType\": \"reward\"\n"
+ " },\n"
+ " \"blockHash\": \"0x8d9aff92ab07598b65ca3457dc68ee66de48ea0e1d4b0a658b6e39977b2a8542\",\n"
+ " \"blockNumber\": 5676554,\n"
+ " \"subtraces\": 0,\n"
+ " \"traceAddress\": [\n"
+ " 0\n"
+ " ],\n"
+ " \"type\": \"reward\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
Expand Down Expand Up @@ -409,12 +422,25 @@ public void testParityFullTraceResponseTraces() {
trace3.setTransactionHash("0xea6649db0f88d5400159853bf2c5b752ce724435dfb85b35f8725cf4cdc1ad6d");
trace3.setTransactionPosition(BigInteger.valueOf(2));
trace3.setType("suicide");

org.web3j.protocol.parity.methods.response.Trace trace4 = new org.web3j.protocol.parity.methods.response.Trace();
Trace.RewardAction action4 = new Trace.RewardAction();
action4.setAuthor("0xb8d2ac822f3d0445f5b83d32b0b176c2cb3d0e60");
action4.setValue("0x0");
action4.setRewardType("reward");
trace4.setAction(action4);
trace4.setBlockHash("0x8d9aff92ab07598b65ca3457dc68ee66de48ea0e1d4b0a658b6e39977b2a8542");
trace4.setBlockNumber(BigInteger.valueOf(5676554));
trace4.setSubtraces(BigInteger.ZERO);
trace4.setTraceAddress(Collections.singletonList(BigInteger.ZERO));
trace4.setType("reward");
//CHECKSTYLE:ON

List<org.web3j.protocol.parity.methods.response.Trace> traces = new ArrayList<>();
traces.add(trace1);
traces.add(trace2);
traces.add(trace3);
traces.add(trace4);
FullTraceInfo info = new FullTraceInfo("0x", null, traces, null);
assertThat(response.getFullTraceInfo(), equalTo(info));
}
Expand Down

0 comments on commit 231b15a

Please sign in to comment.