mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 19:29:39 +00:00
binding: avoid name conflicts with Go keywords
And clashing one name on another after rename.
This commit is contained in:
parent
3b635164b7
commit
02ce59cfd5
3 changed files with 28 additions and 5 deletions
|
@ -45,6 +45,15 @@ func TestGenerate(t *testing.T) {
|
|||
ReturnType: smartcontract.IntegerType,
|
||||
Safe: true,
|
||||
},
|
||||
manifest.Method{
|
||||
Name: "zum",
|
||||
Parameters: []manifest.Parameter{
|
||||
manifest.NewParameter("type", smartcontract.IntegerType),
|
||||
manifest.NewParameter("typev", smartcontract.IntegerType),
|
||||
manifest.NewParameter("func", smartcontract.IntegerType),
|
||||
},
|
||||
ReturnType: smartcontract.IntegerType,
|
||||
},
|
||||
manifest.Method{
|
||||
Name: "justExecute",
|
||||
Parameters: []manifest.Parameter{
|
||||
|
@ -172,6 +181,11 @@ func Sum3() int {
|
|||
return neogointernal.CallWithToken(Hash, "sum3", int(contract.ReadOnly)).(int)
|
||||
}
|
||||
|
||||
// Zum invokes ` + "`zum`" + ` method of contract.
|
||||
func Zum(typev int, typev_ int, funcv int) int {
|
||||
return neogointernal.CallWithToken(Hash, "zum", int(contract.All), typev, typev_, funcv).(int)
|
||||
}
|
||||
|
||||
// JustExecute invokes ` + "`justExecute`" + ` method of contract.
|
||||
func JustExecute(arr []interface{}) {
|
||||
neogointernal.CallWithTokenNoRet(Hash, "justExecute", int(contract.All), arr)
|
||||
|
|
|
@ -47,8 +47,8 @@ func (c *ContractReader) IsAvailable(name string) (bool, error) {
|
|||
}
|
||||
|
||||
// GetRecord invokes `getRecord` method of contract.
|
||||
func (c *ContractReader) GetRecord(name string, type *big.Int) (string, error) {
|
||||
return unwrap.UTF8String(c.invoker.Call(Hash, "getRecord", name, type))
|
||||
func (c *ContractReader) GetRecord(name string, typev *big.Int) (string, error) {
|
||||
return unwrap.UTF8String(c.invoker.Call(Hash, "getRecord", name, typev))
|
||||
}
|
||||
|
||||
// GetAllRecords invokes `getAllRecords` method of contract.
|
||||
|
@ -57,6 +57,6 @@ func (c *ContractReader) GetAllRecords(name string) (stackitem.Item, error) {
|
|||
}
|
||||
|
||||
// Resolve invokes `resolve` method of contract.
|
||||
func (c *ContractReader) Resolve(name string, type *big.Int) (string, error) {
|
||||
return unwrap.UTF8String(c.invoker.Call(Hash, "resolve", name, type))
|
||||
func (c *ContractReader) Resolve(name string, typev *big.Int) (string, error) {
|
||||
return unwrap.UTF8String(c.invoker.Call(Hash, "resolve", name, typev))
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package binding
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/token"
|
||||
"io"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
@ -201,6 +202,8 @@ func TemplateFromManifest(cfg Config, scTypeConverter func(string, smartcontract
|
|||
} else if m.Safe {
|
||||
mtd.CallFlag = callflag.ReadOnly.String()
|
||||
}
|
||||
|
||||
var varnames = make(map[string]bool)
|
||||
for i := range m.Parameters {
|
||||
name := m.Parameters[i].Name
|
||||
if name == "" {
|
||||
|
@ -211,7 +214,13 @@ func TemplateFromManifest(cfg Config, scTypeConverter func(string, smartcontract
|
|||
if pkg != "" {
|
||||
imports[pkg] = struct{}{}
|
||||
}
|
||||
|
||||
if token.IsKeyword(name) {
|
||||
name = name + "v"
|
||||
}
|
||||
for varnames[name] {
|
||||
name = name + "_"
|
||||
}
|
||||
varnames[name] = true
|
||||
mtd.Arguments = append(mtd.Arguments, ParamTmpl{
|
||||
Name: name,
|
||||
Type: typeStr,
|
||||
|
|
Loading…
Reference in a new issue