Skip to content

Commit

Permalink
fix: eibc client commands (#972)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Sep 18, 2024
1 parent 428ea8a commit 3e650ae
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 52 deletions.
14 changes: 8 additions & 6 deletions cmd/eibc/fulfill/denoms/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ import (
"os"
"path/filepath"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/utils/eibc"
"github.com/dymensionxyz/roller/utils/filesystem"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/utils/eibc"
"github.com/dymensionxyz/roller/utils/filesystem"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "remove",
Use: "remove <denom-id>",
Short: "Commands to manage the whitelist of RollApps to fulfill eibc orders for",
Args: cobra.MaximumNArgs(1),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
home, err := os.UserHomeDir()
if err != nil {
Expand Down Expand Up @@ -54,7 +55,8 @@ func Cmd() *cobra.Command {
return
}

config.RemoveChain(asset)
config.RemoveDenom(asset)
config.RemoveAllowedBalanceThreshold(asset)
updatedData, err := yaml.Marshal(&config)
fmt.Println(string(updatedData))
if err != nil {
Expand Down
12 changes: 4 additions & 8 deletions cmd/eibc/fulfill/denoms/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package set

import (
"fmt"
"math/big"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/pterm/pterm"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -60,12 +59,8 @@ instance.
ibcDenom := args[0]
value := args[1]

if !strings.HasPrefix(ibcDenom, "ibc/") {
pterm.Error.Println("invalid ibc denom")
return
}

valueFloat, err := strconv.ParseFloat(value, 32)
vf, _, err := big.ParseFloat(value, 10, 64, big.ToNearestEven)
valueFloat, _ := vf.Float32()
if err != nil {
pterm.Error.Println("failed to convert value to float", err)
return
Expand All @@ -79,6 +74,7 @@ instance.
// Get the actual content node (usually the first child of the document node)
updates := map[string]interface{}{
fmt.Sprintf("fulfill_criteria.min_fee_percentage.asset.%s", ibcDenom): valueFloat,
fmt.Sprintf("whale.allowed_balance_thresholds.%s", ibcDenom): "1000000000000000000",
}
err = yamlconfig.UpdateNestedYAML(eibcConfigPath, updates)
if err != nil {
Expand Down
15 changes: 9 additions & 6 deletions cmd/eibc/fulfill/order/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/dymensionxyz/roller/utils/bash"
"github.com/dymensionxyz/roller/utils/config/tomlconfig"
"github.com/dymensionxyz/roller/utils/eibc"
"github.com/dymensionxyz/roller/utils/filesystem"
"github.com/dymensionxyz/roller/utils/tx"
)

Expand All @@ -27,14 +26,16 @@ func Cmd() *cobra.Command {
return
}

home, err := filesystem.ExpandHomePath(cmd.Flag(utils.FlagNames.Home).Value.String())
home := utils.GetRollerRootDir()
if err != nil {
pterm.Error.Println("failed to expand home directory")
return
}
fmt.Println("home directory: ", home)

rollerCfg, err := tomlconfig.LoadRollerConfig(home)
if err != nil {
pterm.Error.Println("failed to load roller config: ", err)
return
}

Expand All @@ -47,25 +48,26 @@ func Cmd() *cobra.Command {
).Show()
}

var percentage string
var feeAmount string
if len(args) != 0 {
percentage = args[1]
feeAmount = args[1]
} else {
percentage, _ = pterm.DefaultInteractiveTextInput.WithDefaultText(
feeAmount, _ = pterm.DefaultInteractiveTextInput.WithDefaultText(
"provide the expected fee amount",
).Show()
}

fmt.Println("orders related to fulfillment of eibc orders")
gCmd, err := eibc.GetFulfillOrderCmd(
orderId,
percentage,
feeAmount,
rollerCfg.HubData,
)
if err != nil {
pterm.Error.Println("failed to fulfill order: ", err)
return
}
fmt.Println(gCmd.String())

txOutput, err := bash.ExecCommandWithInput(gCmd, "signatures")
if err != nil {
Expand All @@ -75,6 +77,7 @@ func Cmd() *cobra.Command {

txHash, err := bash.ExtractTxHash(txOutput)
if err != nil {
pterm.Error.Println("failed to extract tx hash", err)
return
}

Expand Down
11 changes: 6 additions & 5 deletions cmd/eibc/fulfill/rollapps/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import (
"os"
"path/filepath"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/utils/eibc"
"github.com/dymensionxyz/roller/utils/filesystem"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/utils/eibc"
"github.com/dymensionxyz/roller/utils/filesystem"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "remove",
Use: "remove <rollapp-id>",
Short: "Commands to manage the whitelist of RollApps to fulfill eibc orders for",
Args: cobra.MaximumNArgs(1),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
home, err := os.UserHomeDir()
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions cmd/eibc/fulfill/rollapps/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package set

import (
"fmt"
"math/big"
"os"
"path/filepath"
"strconv"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/utils/config/yamlconfig"
"github.com/dymensionxyz/roller/utils/filesystem"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
)

func Cmd() *cobra.Command {
Expand Down Expand Up @@ -49,7 +50,8 @@ instance.
rollAppID := args[0]
value := args[1]

valueFloat, err := strconv.ParseFloat(value, 32)
vf, _, err := big.ParseFloat(value, 10, 64, big.ToNearestEven)
valueFloat, _ := vf.Float32()
if err != nil {
pterm.Error.Println("failed to convert value to float", err)
return
Expand Down
11 changes: 0 additions & 11 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,3 @@ func init() {
rootCmd.AddCommand(version.Cmd())
rollerutils.AddGlobalFlags(rootCmd)
}

func test() *cobra.Command {
cmd := &cobra.Command{
Use: "test",
Short: "Runs the rollapp on the local machine.",
RunE: func(cmd *cobra.Command, args []string) error {
return nil
},
}
return cmd
}
36 changes: 29 additions & 7 deletions cmd/services/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"runtime"
"strings"

"github.com/dymensionxyz/roller/cmd/consts"
servicemanager "github.com/dymensionxyz/roller/utils/service_manager"
"github.com/pterm/pterm"
"github.com/spf13/cobra"

"github.com/dymensionxyz/roller/cmd/consts"
servicemanager "github.com/dymensionxyz/roller/utils/service_manager"
)

func RollappCmd() *cobra.Command {
Expand Down Expand Up @@ -97,16 +98,37 @@ func EibcCmd() *cobra.Command {
Use: "start",
Short: "Start the systemd services on local machine",
Run: func(cmd *cobra.Command, args []string) {
err := startSystemdServices(consts.EibcSystemdServices)
if err != nil {
pterm.Error.Println("failed to start systemd services:", err)
return
if runtime.GOOS == "linux" {
err := startSystemdServices(consts.EibcSystemdServices)
if err != nil {
pterm.Error.Println("failed to start systemd services:", err)
return
}
} else if runtime.GOOS == "darwin" {
err := startLaunchctlServices(consts.EibcSystemdServices)
if err != nil {
pterm.Error.Println("failed to start launchd services:", err)
return
}
} else {
pterm.Error.Printf(
"the %s commands currently support only darwin and linux operating systems",
cmd.Use,
)
}

pterm.Info.Println("next steps:")
pterm.Info.Printf(
pterm.Info.Println(
"that's all folks",
)

if runtime.GOOS == "linux" {
pterm.Info.Printf(
"run %s to view the current status of the eibc client\n",
pterm.DefaultBasicText.WithStyle(pterm.FgYellow.ToStyle()).
Sprintf("journalctl -fu eibc"),
)
}
},
}
return cmd
Expand Down
1 change: 0 additions & 1 deletion cmd/utils/key_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func GetAddressInfoBinary(keyConfig KeyConfig, binaryPath string) (*KeyInfo, err
"--output",
"json",
)
fmt.Println(showKeyCommand.String())

output, err := bash.ExecCommandWithStdout(showKeyCommand)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions utils/eibc/eibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"path/filepath"

"github.com/docker/docker/client"
"github.com/pterm/pterm"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
dockerutils "github.com/dymensionxyz/roller/utils/docker"
"github.com/dymensionxyz/roller/utils/keys"
"github.com/pterm/pterm"
)

func GetStartCmd() *exec.Cmd {
Expand Down Expand Up @@ -48,7 +49,7 @@ func GetFundsCmd() *exec.Cmd {
return cmd
}

func GetFulfillOrderCmd(orderId, percentage string, hd consts.HubData) (*exec.Cmd, error) {
func GetFulfillOrderCmd(orderId, fee string, hd consts.HubData) (*exec.Cmd, error) {
home, err := os.UserHomeDir()
if err != nil {
return nil, err
Expand All @@ -57,7 +58,7 @@ func GetFulfillOrderCmd(orderId, percentage string, hd consts.HubData) (*exec.Cm
cmd := exec.Command(
consts.Executables.Dymension,
"tx", "eibc", "fulfill-order",
orderId, percentage,
orderId, fee,
"--from", consts.KeysIds.Eibc,
"--home", filepath.Join(home, consts.ConfigDirName.Eibc),
"--fees", fmt.Sprintf("%d%s", consts.DefaultTxFee, consts.Denoms.Hub),
Expand All @@ -74,7 +75,7 @@ func GetFulfillOrderCmd(orderId, percentage string, hd consts.HubData) (*exec.Cm
func EnsureWhaleAccount() error {
home, _ := os.UserHomeDir()
kc := utils.KeyConfig{
Dir: consts.ConfigDirName.Eibc,
Dir: filepath.Join(home, consts.ConfigDirName.Eibc),
ID: consts.KeysIds.Eibc,
ChainBinary: consts.Executables.Dymension,
Type: "",
Expand Down
4 changes: 4 additions & 0 deletions utils/eibc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func (e *Config) RemoveChain(chainId string) {
delete(e.FulfillCriteria.MinFeePercentage.Chain, chainId)
}

func (e *Config) RemoveAllowedBalanceThreshold(denom string) {
delete(e.Whale.AllowedBalanceThresholds, denom)
}

func (e *Config) RemoveDenom(denom string) {
delete(e.FulfillCriteria.MinFeePercentage.Asset, denom)
}

0 comments on commit 3e650ae

Please sign in to comment.