diff --git a/subnet/id/id.go b/subnet/id/id.go index 3ae4a867..d1f530c2 100644 --- a/subnet/id/id.go +++ b/subnet/id/id.go @@ -87,3 +87,10 @@ func (x *ID) SetNumber(num uint32) { func IsZero(id ID) bool { return id.Equals(nil) } + +// MakeZero makes ID to refer to zero subnet. Arg must not be nil (it is already zero). +// +// Makes no sense to call on zero value (e.g. declared using var). +func MakeZero(id *ID) { + id.SetNumber(0) +} diff --git a/subnet/id/id_test.go b/subnet/id/id_test.go index 21e0f12f..f15e7f84 100644 --- a/subnet/id/id_test.go +++ b/subnet/id/id_test.go @@ -92,3 +92,15 @@ func TestSubnetIDEncoding(t *testing.T) { require.True(t, id2.Equals(id)) }) } + +func TestMakeZero(t *testing.T) { + var id subnetid.ID + + id.SetNumber(13) + + require.False(t, subnetid.IsZero(id)) + + subnetid.MakeZero(&id) + + require.True(t, subnetid.IsZero(id)) +}