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 <ekt@morphbits.io>
This commit is contained in:
Ekaterina Pavlova 2024-01-24 11:38:06 +03:00
parent ef99a7a9e3
commit 9b7eff18c0
3 changed files with 12 additions and 17 deletions

View file

@ -174,8 +174,8 @@ func Sum(first int, second int) int {
return neogointernal.CallWithToken(Hash, "sum", int(contract.All), first, second).(int) return neogointernal.CallWithToken(Hash, "sum", int(contract.All), first, second).(int)
} }
// Sum_3 invokes ` + "`sum`" + ` method of contract. // Sum2 invokes ` + "`sum`" + ` method of contract.
func Sum_3(first int, second int, third int) int { func Sum2(first int, second int, third int) int {
return neogointernal.CallWithToken(Hash, "sum", int(contract.All), first, second, third).(int) return neogointernal.CallWithToken(Hash, "sum", int(contract.All), first, second, third).(int)
} }

View file

@ -256,25 +256,25 @@ func (c *Contract) RenewUnsigned(name string) (*transaction.Transaction, error)
return c.actor.MakeUnsignedCall(c.hash, "renew", nil, name) 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. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // 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) 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 // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // 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) 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. // 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, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // 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) return c.actor.MakeUnsignedCall(c.hash, "renew", nil, name, years)
} }

View file

@ -234,16 +234,11 @@ func TemplateFromManifest(cfg Config, scTypeConverter func(string, smartcontract
// Consider `perform(a)` and `perform(a, b)` methods. // Consider `perform(a)` and `perform(a, b)` methods.
// First, try to export the second method with `Perform2` name. // First, try to export the second method with `Perform2` name.
// If `perform2` is already in the manifest, use `perform_2` with as many underscores // If `perform2` is already in the manifest, use `perform3` with uprising suffix as many times
// as needed to eliminate name conflicts. It will produce long names in certain circumstances, // as needed to eliminate name conflicts. If `perform3` is already in the manifest, use `perform4` etc.
// but if the manifest contains lots of similar names with trailing underscores, delicate naming
// was probably not the goal.
name := m.Name name := m.Name
if v, ok := seen[name]; !ok || v { for suffix := 2; seen[name]; suffix++ {
suffix := strconv.Itoa(len(m.Parameters)) name = m.Name + strconv.Itoa(suffix)
for ; seen[name]; name = m.Name + suffix {
suffix = "_" + suffix
}
} }
seen[name] = true seen[name] = true