neoneo-go/examples/events/events.go

37 lines
916 B
Go
Raw Normal View History

package events
import (
rpcbinding: support map[any]any conversion for extended types Unfortunately, without pre-set user extended types configuration for events and without --guess-eventtypes flag set we are allowed to rely only on manifest information about types. Manifest can't give us a lot of information, but we still need to be able to generate RPC binding. Arrays and structs are correctly handled by the current code, but maps always rely on the fact that map's value type is set. It's not true in the described case, so make the maps type convertor handle this situation in a similar way how arrays are handled. Without this commit the following panic occurs on attempt to generate RPC binding: ``` --- FAIL: TestAssistedRPCBindings/testdata/notifications (0.01s) panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7f7c0e] goroutine 190 [running]: testing.tRunner.func1.2({0x109cb40, 0x1d58760}) /usr/local/go/src/testing/testing.go:1396 +0x24e testing.tRunner.func1() /usr/local/go/src/testing/testing.go:1399 +0x39f panic({0x109cb40, 0x1d58760}) /usr/local/go/src/runtime/panic.go:884 +0x212 github.com/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding.extendedTypeToGo({0x22, {0x0, 0x0}, {0x0, 0x0}, 0x0, 0x0, {0x0, 0x0, 0x0}}, ...) /home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding/binding.go:515 +0x36e github.com/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding.scTypeToGo({0xc000206d92?, 0xc000206d80?}, 0x22, 0xc0005d70e0) /home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding/binding.go:643 +0x138 github.com/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding.scTemplateToRPC({{0xc00049bb07, 0x7}, 0xc0004c89c0, {0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, ...}, ...}, ...) /home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding/binding.go:686 +0xbc4 github.com/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding.Generate({{0xc00049bb07, 0x7}, 0xc0004c89c0, {0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, ...}, ...}) /home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding/binding.go:421 +0x387 github.com/nspcc-dev/neo-go/cli/smartcontract.contractGenerateSomething(0xc00043e2c0, 0x137cd00) /home/anna/Documents/GitProjects/nspcc-dev/neo-go/cli/smartcontract/generate.go:99 +0x855 github.com/nspcc-dev/neo-go/cli/smartcontract.contractGenerateRPCWrapper(0xc00043e2c0?) /home/anna/Documents/GitProjects/nspcc-dev/neo-go/cli/smartcontract/generate.go:60 +0x25 github.com/urfave/cli.HandleAction({0x1048380?, 0x137c660?}, 0x13?) /home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:524 +0x50 github.com/urfave/cli.Command.Run({{0x123539d, 0x13}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0x12577ad, 0x2a}, {0x127ad35, ...}, ...}, ...) /home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:173 +0x65b github.com/urfave/cli.(*App).RunAsSubcommand(0xc0001f4000, 0xc00043e000) /home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:405 +0x91b github.com/urfave/cli.Command.startApp({{0x12281e1, 0x8}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0x1254d8a, 0x28}, {0x0, ...}, ...}, ...) /home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:372 +0x6e7 github.com/urfave/cli.Command.Run({{0x12281e1, 0x8}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0x1254d8a, 0x28}, {0x0, ...}, ...}, ...) /home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:102 +0x825 github.com/urfave/cli.(*App).Run(0xc00024e000, {0xc0004f6420, 0xb, 0xb}) /home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:277 +0x8a7 github.com/nspcc-dev/neo-go/cli/smartcontract.TestAssistedRPCBindings.func1.1(0x9f8829?) /home/anna/Documents/GitProjects/nspcc-dev/neo-go/cli/smartcontract/generate_test.go:395 +0x5fc testing.tRunner(0xc0006824e0, 0xc0004a3680) /usr/local/go/src/testing/testing.go:1446 +0x10b created by testing.(*T).Run /usr/local/go/src/testing/testing.go:1493 +0x35f ``` Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-03 16:13:05 +00:00
"github.com/nspcc-dev/neo-go/pkg/interop"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
)
// NotifySomeBytes emits notification with ByteArray.
func NotifySomeBytes(arg []byte) {
runtime.Notify("SomeBytes", arg)
}
// NotifySomeInteger emits notification with Integer.
func NotifySomeInteger(arg int) {
runtime.Notify("SomeInteger", arg)
}
// NotifySomeString emits notification with String.
func NotifySomeString(arg string) {
runtime.Notify("SomeString", arg)
}
// NotifySomeMap emits notification with Map.
func NotifySomeMap(arg map[string]int) {
runtime.Notify("SomeMap", arg)
}
rpcbinding: support map[any]any conversion for extended types Unfortunately, without pre-set user extended types configuration for events and without --guess-eventtypes flag set we are allowed to rely only on manifest information about types. Manifest can't give us a lot of information, but we still need to be able to generate RPC binding. Arrays and structs are correctly handled by the current code, but maps always rely on the fact that map's value type is set. It's not true in the described case, so make the maps type convertor handle this situation in a similar way how arrays are handled. Without this commit the following panic occurs on attempt to generate RPC binding: ``` --- FAIL: TestAssistedRPCBindings/testdata/notifications (0.01s) panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7f7c0e] goroutine 190 [running]: testing.tRunner.func1.2({0x109cb40, 0x1d58760}) /usr/local/go/src/testing/testing.go:1396 +0x24e testing.tRunner.func1() /usr/local/go/src/testing/testing.go:1399 +0x39f panic({0x109cb40, 0x1d58760}) /usr/local/go/src/runtime/panic.go:884 +0x212 github.com/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding.extendedTypeToGo({0x22, {0x0, 0x0}, {0x0, 0x0}, 0x0, 0x0, {0x0, 0x0, 0x0}}, ...) /home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding/binding.go:515 +0x36e github.com/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding.scTypeToGo({0xc000206d92?, 0xc000206d80?}, 0x22, 0xc0005d70e0) /home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding/binding.go:643 +0x138 github.com/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding.scTemplateToRPC({{0xc00049bb07, 0x7}, 0xc0004c89c0, {0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, ...}, ...}, ...) /home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding/binding.go:686 +0xbc4 github.com/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding.Generate({{0xc00049bb07, 0x7}, 0xc0004c89c0, {0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, ...}, ...}) /home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding/binding.go:421 +0x387 github.com/nspcc-dev/neo-go/cli/smartcontract.contractGenerateSomething(0xc00043e2c0, 0x137cd00) /home/anna/Documents/GitProjects/nspcc-dev/neo-go/cli/smartcontract/generate.go:99 +0x855 github.com/nspcc-dev/neo-go/cli/smartcontract.contractGenerateRPCWrapper(0xc00043e2c0?) /home/anna/Documents/GitProjects/nspcc-dev/neo-go/cli/smartcontract/generate.go:60 +0x25 github.com/urfave/cli.HandleAction({0x1048380?, 0x137c660?}, 0x13?) /home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:524 +0x50 github.com/urfave/cli.Command.Run({{0x123539d, 0x13}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0x12577ad, 0x2a}, {0x127ad35, ...}, ...}, ...) /home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:173 +0x65b github.com/urfave/cli.(*App).RunAsSubcommand(0xc0001f4000, 0xc00043e000) /home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:405 +0x91b github.com/urfave/cli.Command.startApp({{0x12281e1, 0x8}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0x1254d8a, 0x28}, {0x0, ...}, ...}, ...) /home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:372 +0x6e7 github.com/urfave/cli.Command.Run({{0x12281e1, 0x8}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0x1254d8a, 0x28}, {0x0, ...}, ...}, ...) /home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:102 +0x825 github.com/urfave/cli.(*App).Run(0xc00024e000, {0xc0004f6420, 0xb, 0xb}) /home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:277 +0x8a7 github.com/nspcc-dev/neo-go/cli/smartcontract.TestAssistedRPCBindings.func1.1(0x9f8829?) /home/anna/Documents/GitProjects/nspcc-dev/neo-go/cli/smartcontract/generate_test.go:395 +0x5fc testing.tRunner(0xc0006824e0, 0xc0004a3680) /usr/local/go/src/testing/testing.go:1446 +0x10b created by testing.(*T).Run /usr/local/go/src/testing/testing.go:1493 +0x35f ``` Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-03 16:13:05 +00:00
// NotifySomeCrazyMap emits notification with complicated Map.
func NotifySomeCrazyMap(arg map[int][]map[string][]interop.Hash160) {
runtime.Notify("SomeCrazyMap", arg)
}
// NotifySomeArray emits notification with Array.
func NotifySomeArray(arg []int) {
runtime.Notify("SomeArray", arg)
}