Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Unwrap DelegatingBytes32 and prevent Hash from wrapping other Hash in…
Browse files Browse the repository at this point in the history
…stances (#1423)
  • Loading branch information
ajsutton authored May 9, 2019
1 parent f7b9aee commit 0fdacbd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public static Hash hash(final BytesValue value) {
}

public static Hash wrap(final Bytes32 bytes) {
if (bytes instanceof Hash) {
return (Hash) bytes;
}
return new Hash(bytes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@

public class DelegatingBytes32 extends BaseDelegatingBytesValue<Bytes32> implements Bytes32 {
protected DelegatingBytes32(final Bytes32 wrapped) {
super(wrapped);
super(unwrap(wrapped));
}

// Make sure we don't end-up with giant chains of delegating through wrapping.
private static Bytes32 unwrap(final Bytes32 value) {
if (value instanceof DelegatingBytes32) {
return ((DelegatingBytes32) value).wrapped;
}
return value;
}

@Override
Expand Down

0 comments on commit 0fdacbd

Please sign in to comment.