Skip to content

Commit

Permalink
native: sort methods in manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
fyrchik committed Jan 29, 2021
1 parent cf0c1a4 commit abde16f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/core/interop/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,20 @@ func NewContractMD(name string, id int32) *ContractMD {

// AddMethod adds new method to a native contract.
func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method) {
c.Manifest.ABI.Methods = append(c.Manifest.ABI.Methods, *desc)
md.MD = desc
desc.Safe = md.RequiredFlags&(callflag.All^callflag.ReadOnly) == 0

index := sort.Search(len(c.Manifest.ABI.Methods), func(i int) bool {
md := c.Manifest.ABI.Methods[i]
if md.Name != desc.Name {
return md.Name >= desc.Name
}
return len(md.Parameters) > len(desc.Parameters)
})
c.Manifest.ABI.Methods = append(c.Manifest.ABI.Methods, manifest.Method{})
copy(c.Manifest.ABI.Methods[index+1:], c.Manifest.ABI.Methods[index:])
c.Manifest.ABI.Methods[index] = *desc

key := MethodAndArgCount{
Name: desc.Name,
ArgCount: len(desc.Parameters),
Expand Down

0 comments on commit abde16f

Please sign in to comment.