Skip to content

Commit

Permalink
Merge pull request #3439 from nspcc-dev/getnativecontracts
Browse files Browse the repository at this point in the history
state: drop NativeContract, fix #3430
  • Loading branch information
AnnaShaleva authored May 17, 2024
2 parents 0b69901 + b1bb12d commit 647b8c7
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion internal/fakechain/fakechain.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (*FakeChain) IsExtensibleAllowed(uint160 util.Uint160) bool {
}

// GetNatives implements the blockchainer.Blockchainer interface.
func (*FakeChain) GetNatives() []state.NativeContract {
func (*FakeChain) GetNatives() []state.Contract {
panic("TODO")
}

Expand Down
13 changes: 7 additions & 6 deletions pkg/core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2295,18 +2295,19 @@ func (bc *Blockchain) GetNativeContractScriptHash(name string) (util.Uint160, er
}

// GetNatives returns list of native contracts.
func (bc *Blockchain) GetNatives() []state.NativeContract {
res := make([]state.NativeContract, 0, len(bc.contracts.Contracts))
func (bc *Blockchain) GetNatives() []state.Contract {
res := make([]state.Contract, 0, len(bc.contracts.Contracts))
current := bc.getCurrentHF()
for _, c := range bc.contracts.Contracts {
activeIn := c.ActiveIn()
if !(activeIn == nil || activeIn.Cmp(current) <= 0) {
continue
}
md := c.Metadata().HFSpecificContractMD(&current)
res = append(res, state.NativeContract{
ContractBase: md.ContractBase,
})

st := bc.GetContractState(c.Metadata().Hash)
if st != nil { // Should never happen, but better safe than sorry.
res = append(res, *st)
}
}
return res
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/core/state/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ type ContractBase struct {
Manifest manifest.Manifest `json:"manifest"`
}

// NativeContract holds information about the native contract.
type NativeContract struct {
ContractBase
}

// ToStackItem converts state.Contract to stackitem.Item.
func (c *Contract) ToStackItem() (stackitem.Item, error) {
// Do not skip the NEF size check, it won't affect native Management related
Expand Down
4 changes: 2 additions & 2 deletions pkg/rpcclient/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ func (c *Client) getContractState(param any) (*state.Contract, error) {
}

// GetNativeContracts queries information about native contracts.
func (c *Client) GetNativeContracts() ([]state.NativeContract, error) {
var resp []state.NativeContract
func (c *Client) GetNativeContracts() ([]state.Contract, error) {
var resp []state.Contract
if err := c.performRequest("getnativecontracts", nil, &resp); err != nil {
return resp, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/rpcsrv/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type (
GetNEP11Contracts() []util.Uint160
GetNEP17Contracts() []util.Uint160
GetNativeContractScriptHash(string) (util.Uint160, error)
GetNatives() []state.NativeContract
GetNatives() []state.Contract
GetNextBlockValidators() ([]*keys.PublicKey, error)
GetNotaryContractScriptHash() util.Uint160
GetStateModule() core.StateRoot
Expand Down
6 changes: 3 additions & 3 deletions pkg/services/rpcsrv/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1192,13 +1192,13 @@ var rpcTestCases = map[string][]rpcTestCase{
{
params: "[]",
result: func(e *executor) any {
return new([]state.NativeContract)
return new([]state.Contract)
},
check: func(t *testing.T, e *executor, res any) {
lst := res.(*[]state.NativeContract)
lst := res.(*[]state.Contract)
for i := range *lst {
cs := e.chain.GetContractState((*lst)[i].Hash)
require.NotNil(t, cs)
require.Equal(t, *cs, (*lst)[i])
require.True(t, cs.ID <= 0)
}
},
Expand Down

0 comments on commit 647b8c7

Please sign in to comment.