Commit ec0dadf1 authored by Janos Guljas's avatar Janos Guljas

add Equal and IsZero methods to swarm.Address and tests

parent 5ed19983
...@@ -7,6 +7,8 @@ package swarm ...@@ -7,6 +7,8 @@ package swarm
import "encoding/hex" import "encoding/hex"
import "bytes"
// Address represents an address in Swarm metric space of // Address represents an address in Swarm metric space of
// Node and Chunk addresses. // Node and Chunk addresses.
type Address []byte type Address []byte
...@@ -20,3 +22,16 @@ func NewAddress(s string) (Address, error) { ...@@ -20,3 +22,16 @@ func NewAddress(s string) (Address, error) {
func (a Address) String() string { func (a Address) String() string {
return hex.EncodeToString(a) return hex.EncodeToString(a)
} }
// Equal returns true if two addresses are identical.
func (a Address) Equal(b Address) bool {
return bytes.Equal(a, b)
}
// IsZero returns true if the Address is not set to any value.
func (a Address) IsZero() bool {
return a.Equal(ZeroAddress)
}
// ZeroAddress is the address that has no value.
var ZeroAddress = Address(nil)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment