[#283] pkg/owner: Implement Equal method of ID type

Implement `owner.ID.Equal` method which defines a comparison relationship
between two identifiers.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-28 10:25:30 +03:00 committed by Leonard Lyubich
parent 4f286f5175
commit 5fe5af5bf9
2 changed files with 32 additions and 1 deletions

View file

@ -1,6 +1,7 @@
package owner
import (
"bytes"
"errors"
"fmt"
@ -40,6 +41,16 @@ func (id *ID) String() string {
return base58.Encode((*refs.OwnerID)(id).GetValue())
}
// Equal defines a comparison relation on ID's.
//
// ID's are equal if they have the same binary representation.
func (id *ID) Equal(id2 *ID) bool {
return bytes.Equal(
(*refs.ObjectID)(id).GetValue(),
(*refs.ObjectID)(id2).GetValue(),
)
}
func ScriptHashBE(id fmt.Stringer) ([]byte, error) {
addr, err := address.StringToUint160(id.String())
if err != nil {