Skip to content

Reuse code for parsing integer slices from string #722

Closed
@ValarDragon

Description

@ValarDragon

There are several places in the codebase (CLI folders) where we ad-hoc write parsing of a comma-delimited string into []uint64 ro []sdk.Int. We should have a single method we call for this, not ad-hoc implemented in line.

The function for []uint64 is written here:

// TODO: move somewhere common, make more commands use it
func parseUint64SliceFromString(s string, seperator string) ([]uint64, error) {
var ids []uint64
for _, s := range strings.Split(s, seperator) {
s = strings.TrimSpace(s)
base := 10
bitlen := 64
parsed, err := strconv.ParseUint(s, base, bitlen)
if err != nil {
return []uint64{}, err
}
ids = append(ids, parsed)
}
return ids, nil
}

We should move that function and write one for SDK.Int in
https://github.com/osmosis-labs/osmosis/blob/main/osmotestutils/cli_helpers.go

We should then switch balances_from_state_export, and pool incentives CLI's to use this.

This is implemented in-line in the pool-incentives CLI code here: https://github.com/osmosis-labs/osmosis/blob/main/x/pool-incentives/client/cli/tx.go#L49-L69 & https://github.com/osmosis-labs/osmosis/blob/main/x/pool-incentives/client/cli/tx.go#L143-L163

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status

      Done ✅

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions