Skip to content

Commit

Permalink
Implemented 'Address' interface for 'AddressID'.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickeskov committed Aug 24, 2024
1 parent e7c188e commit fe06272
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions pkg/proto/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ const (

type AddressID [AddressIDSize]byte

func (a AddressID) ID() AddressID {
return a
}

func (a AddressID) String() string {
return base58.Encode(a[:])
}

func (a AddressID) Equal(address Address) bool {
return a == address.ID()
}

func (a AddressID) Bytes() []byte {
return a[:]
}
Expand All @@ -55,10 +67,6 @@ func (a AddressID) ToWavesAddress(scheme Scheme) (WavesAddress, error) {
return newWavesAddress(scheme, a)
}

func (a AddressID) Equal(id AddressID) bool {
return a == id
}

type Address interface {
ID() AddressID
Bytes() []byte
Expand Down Expand Up @@ -141,7 +149,7 @@ func (ea EthereumAddress) Equal(address Address) bool {
switch other := address.(type) {
case EthereumAddress, *EthereumAddress:
return bytes.Equal(ea.Bytes(), other.Bytes())
case WavesAddress, *WavesAddress:
case WavesAddress, *WavesAddress, AddressID, *AddressID:
return false
default:
panic(errors.Errorf("BUG, CREATE REPORT: unknown address type %T", address))
Expand Down Expand Up @@ -249,14 +257,7 @@ func (a WavesAddress) String() string {
}

func (a WavesAddress) Equal(address Address) bool {
switch other := address.(type) {
case WavesAddress, *WavesAddress:
return bytes.Equal(a.Bytes(), other.Bytes())
case EthereumAddress, *EthereumAddress:
return false
default:
panic(errors.Errorf("BUG, CREATE REPORT: unknown address type %T", address))
}
return bytes.Equal(a.Bytes(), address.Bytes())
}

func (a WavesAddress) ToWavesAddress(_ Scheme) (WavesAddress, error) {
Expand Down

0 comments on commit fe06272

Please sign in to comment.