diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Hash.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Hash.java index a7c3ac96b2..1db3383eba 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Hash.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Hash.java @@ -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); } diff --git a/util/src/main/java/tech/pegasys/pantheon/util/bytes/DelegatingBytes32.java b/util/src/main/java/tech/pegasys/pantheon/util/bytes/DelegatingBytes32.java index f43a64a044..626da14581 100644 --- a/util/src/main/java/tech/pegasys/pantheon/util/bytes/DelegatingBytes32.java +++ b/util/src/main/java/tech/pegasys/pantheon/util/bytes/DelegatingBytes32.java @@ -14,7 +14,15 @@ public class DelegatingBytes32 extends BaseDelegatingBytesValue 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