[#302] pkg/owner: Convert nil ID to nil message

Document that `ID.ToV2` method return `nil`
when called on `nil`. Document that `NewIDFromV2`
function return `nil` when called on `nil`. Write
corresponding unit tests.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-08 19:49:25 +03:00 committed by Alex Vanin
parent d802a994f5
commit 12574469e5
2 changed files with 21 additions and 0 deletions

View file

@ -16,6 +16,8 @@ type ID refs.OwnerID
var errInvalidIDString = errors.New("incorrect format of the string owner ID")
// NewIDFromV2 wraps v2 OwnerID message to ID.
//
// Nil refs.OwnerID converts to nil.
func NewIDFromV2(idV2 *refs.OwnerID) *ID {
return (*ID)(idV2)
}
@ -33,6 +35,8 @@ func (id *ID) SetNeo3Wallet(v *NEO3Wallet) {
}
// ToV2 returns the v2 owner ID message.
//
// Nil ID converts to nil.
func (id *ID) ToV2() *refs.OwnerID {
return (*refs.OwnerID)(id)
}