Skip to content

Commit

Permalink
native: add getCommitteeAddress method
Browse files Browse the repository at this point in the history
Port neo-project/neo#3154.

Close #3334

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
  • Loading branch information
AliceInHunterland committed Mar 19, 2024
1 parent 7e12cc1 commit 94869d9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/fakechain/fakechain.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ func (chain *FakeChain) GetCommittee() (keys.PublicKeys, error) {
panic("TODO")
}

// GetCommitteeAddress implements the Blockchainer interface.
func (chain *FakeChain) GetCommitteeAddress() (util.Uint160, error) {
panic("TODO")
}

// GetContractState implements the Blockchainer interface.
func (chain *FakeChain) GetContractState(hash util.Uint160) *state.Contract {
panic("TODO")
Expand Down
1 change: 1 addition & 0 deletions pkg/compiler/native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func TestNativeHelpersCompile(t *testing.T) {
{"getAllCandidates", nil},
{"getCandidateVote", []string{pub}},
{"getCommittee", nil},
{"getCommitteeAddress", nil},
{"getGasPerBlock", nil},
{"getNextBlockValidators", nil},
{"getRegisterPrice", nil},
Expand Down
5 changes: 5 additions & 0 deletions pkg/core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2758,6 +2758,11 @@ func (bc *Blockchain) GetCommittee() (keys.PublicKeys, error) {
return pubs, nil
}

// GetCommitteeAddress returns the script hash of the committee multi-sig contract.
func (bc *Blockchain) GetCommitteeAddress() (util.Uint160, error) {
return bc.contracts.NEO.GetCommitteeAddress(bc.dao), nil
}

// ComputeNextBlockValidators returns current validators. Validators list
// returned from this method is updated once per CommitteeSize number of blocks.
// For the last block in the dBFT epoch this method returns the list of validators
Expand Down
7 changes: 7 additions & 0 deletions pkg/core/native/native_neo.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ func newNEO(cfg config.ProtocolConfiguration) *NEO {
md = newMethodAndPrice(n.getCommittee, 1<<16, callflag.ReadStates)
n.AddMethod(md, desc)

desc = newDescriptor("getCommitteeAddress", smartcontract.ArrayType)
md = newMethodAndPrice(n.GetCommitteeAddressCall, 1<<16, callflag.ReadStates)
n.AddMethod(md, desc)

desc = newDescriptor("getNextBlockValidators", smartcontract.ArrayType)
md = newMethodAndPrice(n.getNextBlockValidators, 1<<16, callflag.ReadStates)
n.AddMethod(md, desc)
Expand Down Expand Up @@ -1051,6 +1055,9 @@ func (n *NEO) getCandidatesCall(ic *interop.Context, _ []stackitem.Item) stackit
return stackitem.NewArray(arr)
}

func (n *NEO) GetCommitteeAddressCall(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
return stackitem.NewByteArray(n.GetCommitteeAddress(ic.DAO).BytesBE())
}
func (n *NEO) getAllCandidatesCall(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
ctx, cancel := context.WithCancel(context.Background())
prefix := []byte{prefixCandidate}
Expand Down
10 changes: 10 additions & 0 deletions pkg/core/native/native_test/neo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ func TestNEO_RecursiveGASMint(t *testing.T) {
neoValidatorInvoker.Invoke(t, true, "transfer", e.Validator.ScriptHash(), c.Hash, int64(1), nil)
}

func TestNEO_GetCommitteeAddress(t *testing.T) {
neoValidatorInvoker := newNeoValidatorsClient(t)
e := neoValidatorInvoker.Executor
committeeAddress, err := e.Chain.GetCommitteeAddress()
require.NoError(t, err)
stack, err := neoValidatorInvoker.TestInvoke(t, "getCommitteeAddress")
require.NoError(t, err)
require.Equal(t, committeeAddress.BytesBE(), stack.Pop().Item().Value().([]byte))
}

func TestNEO_GetAccountState(t *testing.T) {
neoValidatorInvoker := newNeoValidatorsClient(t)
e := neoValidatorInvoker.Executor
Expand Down
6 changes: 6 additions & 0 deletions pkg/interop/native/neo/neo.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,9 @@ func UnclaimedGAS(addr interop.Hash160, end int) int {
func GetAccountState(addr interop.Hash160) *AccountState {
return neogointernal.CallWithToken(Hash, "getAccountState", int(contract.ReadStates), addr).(*AccountState)
}

// GetCommitteeAddress represents `getCommitteeAddress` method of NEO native contract.
func GetCommitteeAddress() interop.Hash160 {
return neogointernal.CallWithToken(Hash, "getCommitteeAddress", int(contract.ReadStates)).(interop.Hash160)

}

0 comments on commit 94869d9

Please sign in to comment.