From 2f26490e5903bd6ba082795b6cf749ce4f3e2d1c Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Mon, 8 Feb 2021 11:08:48 +0300 Subject: [PATCH] compiler: implement RoleManagement contract wrapper --- pkg/compiler/native_test.go | 7 +++++++ pkg/interop/native/roles/roles.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 pkg/interop/native/roles/roles.go diff --git a/pkg/compiler/native_test.go b/pkg/compiler/native_test.go index 1ad90c65b..b3de8fb15 100644 --- a/pkg/compiler/native_test.go +++ b/pkg/compiler/native_test.go @@ -5,9 +5,16 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/interop/native/nameservice" + "github.com/nspcc-dev/neo-go/pkg/interop/native/roles" "github.com/stretchr/testify/require" ) +func TestRoleManagementRole(t *testing.T) { + require.EqualValues(t, native.RoleOracle, roles.Oracle) + require.EqualValues(t, native.RoleStateValidator, roles.StateValidator) + require.EqualValues(t, native.RoleP2PNotary, roles.P2PNotary) +} + func TestNameServiceRecordType(t *testing.T) { require.EqualValues(t, native.RecordTypeA, nameservice.TypeA) require.EqualValues(t, native.RecordTypeCNAME, nameservice.TypeCNAME) diff --git a/pkg/interop/native/roles/roles.go b/pkg/interop/native/roles/roles.go new file mode 100644 index 000000000..d3fca9aa4 --- /dev/null +++ b/pkg/interop/native/roles/roles.go @@ -0,0 +1,31 @@ +package roles + +import ( + "github.com/nspcc-dev/neo-go/pkg/interop" + "github.com/nspcc-dev/neo-go/pkg/interop/contract" +) + +// Hash represents RoleManagement contract hash. +const Hash = "\x02\x8b\x00\x50\x70\xb6\x0d\xf1\xc8\xe2\x09\x78\x7b\x49\xce\xbb\x71\x14\x7b\x59" + +// Role represents node role. +type Role byte + +// Various node roles. +const ( + StateValidator Role = 4 + Oracle Role = 8 + P2PNotary Role = 128 +) + +// GetDesignatedByRole represents `getDesignatedByRole` method of RoleManagement native contract. +func GetDesignatedByRole(r Role, height uint32) []interop.PublicKey { + return contract.Call(interop.Hash160(Hash), "getDesignatedByRole", + contract.ReadStates, r, height).([]interop.PublicKey) +} + +// DesignateAsRole represents `designateAsRole` method of RoleManagement native contract. +func DesignateAsRole(r Role, pubs []interop.PublicKey) { + contract.Call(interop.Hash160(Hash), "designateAsRole", + contract.WriteStates, r, pubs) +}