From 9b7eff18c05f44029038860414ff9543b8de1cc0 Mon Sep 17 00:00:00 2001 From: Ekaterina Pavlova Date: Wed, 24 Jan 2024 11:38:06 +0300 Subject: [PATCH] smartcontract: fix generation of nns wrapper for follow Go naming Autogenerated RPC wrapper used underscores to differentiate between methods/event overloads. Now it adds increasing suffices instead. Close #3296 Signed-off-by: Ekaterina Pavlova --- cli/smartcontract/generate_test.go | 4 ++-- cli/smartcontract/testdata/nameservice/nns.go | 12 ++++++------ pkg/smartcontract/binding/generate.go | 13 ++++--------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/cli/smartcontract/generate_test.go b/cli/smartcontract/generate_test.go index edd31b327..b54fc8fab 100644 --- a/cli/smartcontract/generate_test.go +++ b/cli/smartcontract/generate_test.go @@ -174,8 +174,8 @@ func Sum(first int, second int) int { return neogointernal.CallWithToken(Hash, "sum", int(contract.All), first, second).(int) } -// Sum_3 invokes ` + "`sum`" + ` method of contract. -func Sum_3(first int, second int, third int) int { +// Sum2 invokes ` + "`sum`" + ` method of contract. +func Sum2(first int, second int, third int) int { return neogointernal.CallWithToken(Hash, "sum", int(contract.All), first, second, third).(int) } diff --git a/cli/smartcontract/testdata/nameservice/nns.go b/cli/smartcontract/testdata/nameservice/nns.go index 999e34cf2..5205e4d90 100644 --- a/cli/smartcontract/testdata/nameservice/nns.go +++ b/cli/smartcontract/testdata/nameservice/nns.go @@ -256,25 +256,25 @@ func (c *Contract) RenewUnsigned(name string) (*transaction.Transaction, error) return c.actor.MakeUnsignedCall(c.hash, "renew", nil, name) } -// Renew_2 creates a transaction invoking `renew` method of the contract. +// Renew2 creates a transaction invoking `renew` method of the contract. // This transaction is signed and immediately sent to the network. // The values returned are its hash, ValidUntilBlock value and error if any. -func (c *Contract) Renew_2(name string, years *big.Int) (util.Uint256, uint32, error) { +func (c *Contract) Renew2(name string, years *big.Int) (util.Uint256, uint32, error) { return c.actor.SendCall(c.hash, "renew", name, years) } -// Renew_2Transaction creates a transaction invoking `renew` method of the contract. +// Renew2Transaction creates a transaction invoking `renew` method of the contract. // This transaction is signed, but not sent to the network, instead it's // returned to the caller. -func (c *Contract) Renew_2Transaction(name string, years *big.Int) (*transaction.Transaction, error) { +func (c *Contract) Renew2Transaction(name string, years *big.Int) (*transaction.Transaction, error) { return c.actor.MakeCall(c.hash, "renew", name, years) } -// Renew_2Unsigned creates a transaction invoking `renew` method of the contract. +// Renew2Unsigned creates a transaction invoking `renew` method of the contract. // This transaction is not signed, it's simply returned to the caller. // Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Nonce), fee values (NetworkFee, SystemFee) can be increased as well. -func (c *Contract) Renew_2Unsigned(name string, years *big.Int) (*transaction.Transaction, error) { +func (c *Contract) Renew2Unsigned(name string, years *big.Int) (*transaction.Transaction, error) { return c.actor.MakeUnsignedCall(c.hash, "renew", nil, name, years) } diff --git a/pkg/smartcontract/binding/generate.go b/pkg/smartcontract/binding/generate.go index b38ee416c..3b86f79d0 100644 --- a/pkg/smartcontract/binding/generate.go +++ b/pkg/smartcontract/binding/generate.go @@ -234,16 +234,11 @@ func TemplateFromManifest(cfg Config, scTypeConverter func(string, smartcontract // Consider `perform(a)` and `perform(a, b)` methods. // First, try to export the second method with `Perform2` name. - // If `perform2` is already in the manifest, use `perform_2` with as many underscores - // as needed to eliminate name conflicts. It will produce long names in certain circumstances, - // but if the manifest contains lots of similar names with trailing underscores, delicate naming - // was probably not the goal. + // If `perform2` is already in the manifest, use `perform3` with uprising suffix as many times + // as needed to eliminate name conflicts. If `perform3` is already in the manifest, use `perform4` etc. name := m.Name - if v, ok := seen[name]; !ok || v { - suffix := strconv.Itoa(len(m.Parameters)) - for ; seen[name]; name = m.Name + suffix { - suffix = "_" + suffix - } + for suffix := 2; seen[name]; suffix++ { + name = m.Name + strconv.Itoa(suffix) } seen[name] = true