smartcontract: improve manifest validness errors
It should be clear from error what's wrong with ABI (specify bad method/event/parameter identifier).
This commit is contained in:
parent
606597b9a1
commit
15732580eb
3 changed files with 8 additions and 5 deletions
|
@ -2,6 +2,7 @@ package manifest
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
|
@ -53,12 +54,12 @@ func (a *ABI) GetEvent(name string) *Event {
|
|||
// IsValid checks ABI consistency and correctness.
|
||||
func (a *ABI) IsValid() error {
|
||||
if len(a.Methods) == 0 {
|
||||
return errors.New("ABI contains no methods")
|
||||
return errors.New("no methods")
|
||||
}
|
||||
for i := range a.Methods {
|
||||
err := a.Methods[i].IsValid()
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("method %q/%d: %w", a.Methods[i].Name, len(a.Methods[i].Parameters), err)
|
||||
}
|
||||
}
|
||||
if len(a.Methods) > 1 {
|
||||
|
@ -92,7 +93,7 @@ func (a *ABI) IsValid() error {
|
|||
for i := range a.Events {
|
||||
err := a.Events[i].IsValid()
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("event %q/%d: %w", a.Events[i].Name, len(a.Events[i].Parameters), err)
|
||||
}
|
||||
}
|
||||
if len(a.Events) > 1 {
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
ojson "github.com/nspcc-dev/go-ordered-json"
|
||||
|
@ -104,7 +105,7 @@ func (m *Manifest) IsValid(hash util.Uint160) error {
|
|||
}
|
||||
err = m.ABI.IsValid()
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("ABI: %w", err)
|
||||
}
|
||||
err = Groups(m.Groups).AreValid(hash)
|
||||
if err != nil {
|
||||
|
|
|
@ -2,6 +2,7 @@ package manifest
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
|
@ -75,7 +76,7 @@ func (p Parameters) AreValid() error {
|
|||
for i := range p {
|
||||
err := p[i].IsValid()
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("parameter #%d/%q: %w", i, p[i].Name, err)
|
||||
}
|
||||
}
|
||||
if len(p) < 2 {
|
||||
|
|
Loading…
Reference in a new issue