This is an automated email from the ASF dual-hosted git repository.

toulmean pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git

commit de7cb3b4ca9276146c0e29fb2dd694c04eeda579
Author: Antoine Toulme <[email protected]>
AuthorDate: Wed Apr 22 23:30:00 2020 -0700

    Simplify address and hash classes
---
 .../main/java/org/apache/tuweni/eth/Address.java   | 43 ++----------------
 eth/src/main/java/org/apache/tuweni/eth/Hash.java  | 53 +++-------------------
 2 files changed, 10 insertions(+), 86 deletions(-)

diff --git a/eth/src/main/java/org/apache/tuweni/eth/Address.java 
b/eth/src/main/java/org/apache/tuweni/eth/Address.java
index 4e9d37f..db4c0c3 100644
--- a/eth/src/main/java/org/apache/tuweni/eth/Address.java
+++ b/eth/src/main/java/org/apache/tuweni/eth/Address.java
@@ -18,11 +18,12 @@ import static java.util.Objects.requireNonNull;
 import org.apache.tuweni.bytes.Bytes;
 
 import com.google.common.base.Objects;
+import org.apache.tuweni.bytes.DelegatingBytes;
 
 /**
  * An Ethereum account address.
  */
-public final class Address {
+public final class Address extends DelegatingBytes {
 
   /**
    * Create an address from Bytes.
@@ -55,45 +56,7 @@ public final class Address {
 
   private static final int SIZE = 20;
 
-  private final Bytes delegate;
-
   private Address(Bytes value) {
-    this.delegate = value;
-  }
-
-  @Override
-  public boolean equals(Object obj) {
-    if (this == obj) {
-      return true;
-    }
-    if (!(obj instanceof Address)) {
-      return false;
-    }
-    Address other = (Address) obj;
-    return delegate.equals(other.delegate);
-  }
-
-  @Override
-  public int hashCode() {
-    return Objects.hashCode(delegate);
-  }
-
-  @Override
-  public String toString() {
-    return "Address{" + delegate.toHexString() + '}';
-  }
-
-  /**
-   * @return A hex-encoded version of the address.
-   */
-  public String toHexString() {
-    return delegate.toHexString();
-  }
-
-  /**
-   * @return The bytes for this address.
-   */
-  public Bytes toBytes() {
-    return delegate;
+    super(value);
   }
 }
diff --git a/eth/src/main/java/org/apache/tuweni/eth/Hash.java 
b/eth/src/main/java/org/apache/tuweni/eth/Hash.java
index 236bf58..4017793 100644
--- a/eth/src/main/java/org/apache/tuweni/eth/Hash.java
+++ b/eth/src/main/java/org/apache/tuweni/eth/Hash.java
@@ -16,15 +16,17 @@ import static 
com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 import static org.apache.tuweni.crypto.Hash.keccak256;
 
+import org.apache.tuweni.bytes.AbstractBytes;
 import org.apache.tuweni.bytes.Bytes;
 import org.apache.tuweni.bytes.Bytes32;
 
 import com.google.common.base.Objects;
+import org.apache.tuweni.bytes.DelegatingBytes32;
 
 /**
  * An Ethereum hash.
  */
-public final class Hash {
+public final class Hash extends DelegatingBytes32 {
 
   /**
    * Create a Hash from Bytes.
@@ -52,6 +54,10 @@ public final class Hash {
     return new Hash(bytes);
   }
 
+  private Hash(Bytes delegate) {
+    super(delegate);
+  }
+
   /**
    * Parse a hexadecimal string into a {@link Hash}.
    *
@@ -68,49 +74,4 @@ public final class Hash {
   public static Hash hash(Bytes value) {
     return new Hash(keccak256(value));
   }
-
-  private static final int SIZE = 32;
-
-  private final Bytes32 delegate;
-
-  private Hash(Bytes32 value) {
-    requireNonNull(value);
-    this.delegate = value;
-  }
-
-  @Override
-  public boolean equals(Object obj) {
-    if (this == obj) {
-      return true;
-    }
-    if (!(obj instanceof Hash)) {
-      return false;
-    }
-    Hash hash = (Hash) obj;
-    return delegate.equals(hash.delegate);
-  }
-
-  @Override
-  public int hashCode() {
-    return Objects.hashCode(delegate);
-  }
-
-  @Override
-  public String toString() {
-    return "Hash{" + delegate.toHexString() + '}';
-  }
-
-  /**
-   * @return A hex-encoded version of the hash.
-   */
-  public String toHexString() {
-    return delegate.toHexString();
-  }
-
-  /**
-   * @return The bytes for this hash.
-   */
-  public Bytes32 toBytes() {
-    return delegate;
-  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to