mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-27 03:58:06 +00:00
native: sort methods in manifest
This commit is contained in:
parent
2336415f42
commit
c8a07be58d
1 changed files with 12 additions and 1 deletions
|
@ -135,9 +135,20 @@ func NewContractMD(name string, id int32) *ContractMD {
|
||||||
|
|
||||||
// AddMethod adds new method to a native contract.
|
// AddMethod adds new method to a native contract.
|
||||||
func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method) {
|
func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method) {
|
||||||
c.Manifest.ABI.Methods = append(c.Manifest.ABI.Methods, *desc)
|
|
||||||
md.MD = desc
|
md.MD = desc
|
||||||
desc.Safe = md.RequiredFlags&(callflag.All^callflag.ReadOnly) == 0
|
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{
|
key := MethodAndArgCount{
|
||||||
Name: desc.Name,
|
Name: desc.Name,
|
||||||
ArgCount: len(desc.Parameters),
|
ArgCount: len(desc.Parameters),
|
||||||
|
|
Loading…
Reference in a new issue