Skip to content

Commit

Permalink
Add a toString for reject messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehearn committed Apr 15, 2014
1 parent d2def04 commit f19741d
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions core/src/main/java/com/google/bitcoin/core/RejectMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* A message sent by nodes when a message we sent was rejected (ie a transaction had too little fee/was invalid/etc)
Expand Down Expand Up @@ -141,6 +138,17 @@ public String getReasonString() {
return reason;
}

@Override
public String toString() {
Sha256Hash hash = getRejectedObjectHash();
if (hash != null)
return String.format("Reject: %s %s for reason '%s' (%d)", getRejectedMessage(), getRejectedObjectHash(),
getReasonString(), getReasonCode().code);
else
return String.format("Reject: %s for reason '%s' (%d)", getRejectedMessage(),
getReasonString(), getReasonCode().code);
}

@Override
public boolean equals(Object o) {
return o instanceof RejectMessage &&
Expand All @@ -149,4 +157,13 @@ public boolean equals(Object o) {
((RejectMessage) o).reason.equals(reason) &&
((RejectMessage) o).messageHash.equals(messageHash);
}

@Override
public int hashCode() {
int result = message.hashCode();
result = 31 * result + reason.hashCode();
result = 31 * result + code.hashCode();
result = 31 * result + messageHash.hashCode();
return result;
}
}

0 comments on commit f19741d

Please sign in to comment.