[BUG]: Argument parsing does not handle repeated fields
- Dominant language
- Go
- Stars
- 7
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Current behavior
If a contract has a function that has repeated fields in the argument struct, parsing fails.
### Expected behavior
There should be an elegant way for the CLI to interact with contracts utilizing this structure.
### Steps to reproduce
```
🔓 > register koindx 17e1q6Fh5RgnuA8K7v4KvXXH4k9qHgsT5s
Contract 'koindx' at address 17e1q6Fh5RgnuA8K7v4KvXXH4k9qHgsT5s registered
🔓 > koindx.swap_tokens_in 1NqLghiFRwkXZR7NBFHHiCJkF5gLHyJap1 1NqLghiFRwkXZR7NBFHHiCJkF5gLHyJap1 100000000 100000000 koin vhp
panic: proto: periphery.swap_tokens_in_arguments.path: assigning invalid type string
goroutine 1 [running]:
google.golang.org/protobuf/types/dynamicpb.typecheck(...)
/home/michael/go/pkg/mod/github.com/koinos/protobuf-go@v1.27.2-0.20211026185306-2456c83214fe/types/dynamicpb/dynamic.go:520
google.golang.org/protobuf/types/dynamicpb.(*Message).Set(0xc000626400, {0xb6b430?, 0xc000e0f2c0}, {{}, 0x8bfa60?, 0xc0005c5e68?, 0x0?})
/home/michael/go/pkg/mod/github.com/koinos/protobuf-go@v1.27.2-0.20211026185306-2456c83214fe/types/dynamicpb/dynamic.go:267 +0x2d6
github.com/koinos/koinos-cli/internal/cli.dataToMessage(0x0?, {0xb69520?, 0xc0002120d0}, {0x0, 0x0})
/home/michael/dev/koinos-cli/internal/cli/abi.go:412 +0x11b
github.com/koinos/koinos-cli/internal/cli.DataToMessage(...)
/home/michael/dev/koinos-cli/internal/cli/abi.go:301
github.com/koinos/koinos-cli/internal/cli.ParseResultToMessage(0xc000712090, 0xc00002a3f0?)
/home/michael/dev/koinos-cli/internal/cli/abi.go:425 +0x54
github.com/koinos/koinos-cli/internal/cli.(*WriteContractCommand).Execute(0xc00011e018, {0xb64050, 0xf006a0}, 0xc0002d8d20)
/home/michael/dev/koinos-cli/internal/cli/contract_commands.go:327 +0x11c
github.com/koinos/koinos-cli/internal/cli.(*ParseResults).Interpret(0xc000012498, 0xc000b70d80?)
/home/michael/dev/koinos-cli/internal/cli/interpreter.go:471 +0xd9
github.com/koinos/koinos-cli/internal/cli.ParseAndInterpret(0x4bf00000005?, 0x7f1c030000008a3b?, {0xc000b70d80?, 0xff16170f12ff?})
/home/michael/dev/koinos-cli/internal/cli/interpreter.go:536 +0x38c
github.com/koinos/koinos-cli/cmd/cli/interactive.(*KoinosPrompt).executor(0x529385?, {0xc000b70d80?, 0xe8da00?})
/home/michael/dev/koinos-cli/cmd/cli/interactive/interactive.go:117 +0x2b
github.com/koinos/go-prompt.(*Prompt).Run(0xc0003473b0)
/home/michael/go/pkg/mod/github.com/koinos/go-prompt@v0.0.0-20221201222302-dba4c3542a91/prompt.go:84 +0x73f
github.com/koinos/koinos-cli/cmd/cli/interactive.(*KoinosPrompt).Run(0xc0002d5040)
/home/michael/dev/koinos-cli/cmd/cli/interactive/interactive.go:125 +0xb3
main.main()
/home/michael/dev/koinos-cli/cmd/cli/main.go:117 +0x713
```
### Environment
_No response_
### Anything else?
Perhaps using `[` or `{` we can denote an array or sub-object to the CLI parser so that the command works as:
```
🔓 > koindx.swap_tokens_in 1NqLghiFRwkXZR7NBFHHiCJkF5gLHyJap1 1NqLghiFRwkXZR7NBFHHiCJkF5gLHyJap1 100000000 100000000 [koin vhp]
```
or
```
🔓 > koindx.swap_tokens_in 1NqLghiFRwkXZR7NBFHHiCJkF5gLHyJap1 1NqLghiFRwkXZR7NBFHHiCJkF5gLHyJap1 100000000 100000000 [koin, vhp]
Contributor guide
Research direction
Reproduce the repeated-field failure with the koindx.swap_tokens_in command, then inspect dataToMessage and ParseResultToMessage in internal/cli/abi.go, especially the reported failure around line 412. Determine how repeated argument values should be represented and verify that the command converts them without the dynamicpb type error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100