Skip to content

Commit e0328cc

Browse files
native: add getCommitteeAddress method
Port neo-project/neo#3154. Close #3334 Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
1 parent 900ef46 commit e0328cc

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

pkg/compiler/native_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func TestNativeHelpersCompile(t *testing.T) {
163163
{"getAllCandidates", nil},
164164
{"getCandidateVote", []string{pub}},
165165
{"getCommittee", nil},
166+
{"getCommitteeAddress", nil},
166167
{"getGasPerBlock", nil},
167168
{"getNextBlockValidators", nil},
168169
{"getRegisterPrice", nil},

pkg/core/native/native_neo.go

+8
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ func newNEO(cfg config.ProtocolConfiguration) *NEO {
232232
md = newMethodAndPrice(n.getCommittee, 1<<16, callflag.ReadStates)
233233
n.AddMethod(md, desc)
234234

235+
desc = newDescriptor("getCommitteeAddress", smartcontract.Hash160Type)
236+
md = newMethodAndPrice(n.getCommitteeAddress, 1<<16, callflag.ReadStates)
237+
n.AddMethod(md, desc)
238+
235239
desc = newDescriptor("getNextBlockValidators", smartcontract.ArrayType)
236240
md = newMethodAndPrice(n.getNextBlockValidators, 1<<16, callflag.ReadStates)
237241
n.AddMethod(md, desc)
@@ -1071,6 +1075,10 @@ func (n *NEO) getCandidatesCall(ic *interop.Context, _ []stackitem.Item) stackit
10711075
return stackitem.NewArray(arr)
10721076
}
10731077

1078+
func (n *NEO) getCommitteeAddress(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
1079+
return stackitem.NewByteArray(n.GetCommitteeAddress(ic.DAO).BytesBE())
1080+
}
1081+
10741082
func (n *NEO) getAllCandidatesCall(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
10751083
ctx, cancel := context.WithCancel(context.Background())
10761084
prefix := []byte{prefixCandidate}

pkg/core/native/native_test/neo_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ import (
1818
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
1919
"github.com/nspcc-dev/neo-go/pkg/core/state"
2020
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
21+
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
2122
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
2223
"github.com/nspcc-dev/neo-go/pkg/io"
2324
"github.com/nspcc-dev/neo-go/pkg/neotest"
2425
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
26+
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
2527
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
2628
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
2729
"github.com/nspcc-dev/neo-go/pkg/util"
@@ -396,6 +398,19 @@ func TestNEO_RecursiveGASMint(t *testing.T) {
396398
neoValidatorInvoker.Invoke(t, true, "transfer", e.Validator.ScriptHash(), c.Hash, int64(1), nil)
397399
}
398400

401+
func TestNEO_GetCommitteeAddress(t *testing.T) {
402+
neoValidatorInvoker := newNeoValidatorsClient(t)
403+
e := neoValidatorInvoker.Executor
404+
standByCommitteePublicKeys, err := keys.NewPublicKeysFromStrings(e.Chain.GetConfig().StandbyCommittee)
405+
require.NoError(t, err)
406+
sort.Sort(standByCommitteePublicKeys)
407+
expectedCommitteeAddress, err := smartcontract.CreateMajorityMultiSigRedeemScript(standByCommitteePublicKeys)
408+
require.NoError(t, err)
409+
stack, err := neoValidatorInvoker.TestInvoke(t, "getCommitteeAddress")
410+
require.NoError(t, err)
411+
require.Equal(t, hash.Hash160(expectedCommitteeAddress).BytesBE(), stack.Pop().Item().Value().([]byte))
412+
}
413+
399414
func TestNEO_GetAccountState(t *testing.T) {
400415
neoValidatorInvoker := newNeoValidatorsClient(t)
401416
e := neoValidatorInvoker.Executor

pkg/interop/native/neo/neo.go

+6
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,9 @@ func UnclaimedGAS(addr interop.Hash160, end int) int {
126126
func GetAccountState(addr interop.Hash160) *AccountState {
127127
return neogointernal.CallWithToken(Hash, "getAccountState", int(contract.ReadStates), addr).(*AccountState)
128128
}
129+
130+
// GetCommitteeAddress represents `getCommitteeAddress` method of NEO native contract.
131+
func GetCommitteeAddress() interop.Hash160 {
132+
return neogointernal.CallWithToken(Hash, "getCommitteeAddress", int(contract.ReadStates)).(interop.Hash160)
133+
134+
}

pkg/rpcclient/neo/neo.go

+5
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ func (c *ContractReader) GetCommittee() (keys.PublicKeys, error) {
233233
return unwrap.ArrayOfPublicKeys(c.invoker.Call(Hash, "getCommittee"))
234234
}
235235

236+
// GetCommitteeAddress returns the committee address.
237+
func (c *ContractReader) GetCommitteeAddress() (util.Uint160, error) {
238+
return unwrap.Uint160(c.invoker.Call(Hash, "getCommitteeAddress"))
239+
}
240+
236241
// GetNextBlockValidators returns the list of validator keys that will sign the
237242
// next block. This method is mostly useful for historic invocations because the
238243
// RPC protocol provides direct getnextblockvalidators call that provides more

0 commit comments

Comments
 (0)