-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add eibc client support (#813)
- Loading branch information
1 parent
1d23104
commit 89dc1c6
Showing
14 changed files
with
1,646 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package eibc | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func Cmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "eibc", | ||
Short: "Commands for running and managing eibc client", | ||
} | ||
|
||
cmd.AddCommand(initCmd()) | ||
cmd.AddCommand(startCmd()) | ||
cmd.AddCommand(scaleCmd()) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package eibc | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/dymensionxyz/roller/cmd/consts" | ||
"github.com/dymensionxyz/roller/cmd/utils" | ||
global_utils "github.com/dymensionxyz/roller/utils" | ||
) | ||
|
||
func initCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "init", | ||
Short: "Initialize eibc client", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
home, _ := os.UserHomeDir() | ||
eibcHome := filepath.Join(home, ".order-client") | ||
ok, err := global_utils.DirNotEmpty(eibcHome) | ||
if err != nil { | ||
return | ||
} | ||
|
||
if ok { | ||
fmt.Println("eibc client already initialized") | ||
return | ||
} | ||
|
||
c := GetInitCommand() | ||
|
||
err = utils.ExecBashCmd(c) | ||
if err != nil { | ||
return | ||
} | ||
|
||
err = ensureWhaleAccount() | ||
if err != nil { | ||
log.Printf("failed to create whale account: %v\n", err) | ||
return | ||
} | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
func GetInitCommand() *exec.Cmd { | ||
cmd := exec.Command( | ||
consts.Executables.Eibc, | ||
"init", | ||
) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package eibc | ||
|
||
import ( | ||
"os/exec" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/dymensionxyz/roller/cmd/consts" | ||
"github.com/dymensionxyz/roller/cmd/utils" | ||
) | ||
|
||
func scaleCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "scale [count]", | ||
Short: "Start the eibc client", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
count := args[0] | ||
|
||
c := GetScaleCmd(count) | ||
|
||
err := utils.ExecBashCmdFollow(c) | ||
if err != nil { | ||
return | ||
} | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
func GetScaleCmd(count string) *exec.Cmd { | ||
cmd := exec.Command( | ||
consts.Executables.Eibc, | ||
"scale", | ||
count, | ||
) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package eibc | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/dymensionxyz/roller/cmd/consts" | ||
"github.com/dymensionxyz/roller/cmd/utils" | ||
global_utils "github.com/dymensionxyz/roller/utils" | ||
) | ||
|
||
func startCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "start", | ||
Short: "Start the eibc client", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
home, _ := os.UserHomeDir() | ||
eibcHome := filepath.Join(home, ".order-client") | ||
ok, err := global_utils.DirNotEmpty(eibcHome) | ||
if err != nil { | ||
return | ||
} | ||
|
||
if !ok { | ||
fmt.Println("eibc home directory not present, running init") | ||
c := GetInitCommand() | ||
|
||
_, err := utils.ExecBashCommandWithStdout(c) | ||
if err != nil { | ||
return | ||
} | ||
|
||
err = ensureWhaleAccount() | ||
if err != nil { | ||
log.Printf("failed to create whale account: %v\n", err) | ||
return | ||
} | ||
} | ||
|
||
err = createMongoDbContainer() | ||
if err != nil { | ||
return | ||
} | ||
|
||
c := GetStartCmd() | ||
err = utils.ExecBashCmdFollow(c) | ||
if err != nil { | ||
return | ||
} | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
func GetStartCmd() *exec.Cmd { | ||
cmd := exec.Command( | ||
consts.Executables.Eibc, | ||
"start", | ||
) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package eibc | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/docker/docker/client" | ||
|
||
initconfig "github.com/dymensionxyz/roller/cmd/config/init" | ||
"github.com/dymensionxyz/roller/cmd/consts" | ||
"github.com/dymensionxyz/roller/cmd/utils" | ||
) | ||
|
||
// ensureWhaleAccount function makes sure that eibc whale account is present in | ||
// the keyring. In eibc client, whale account is the wallet that acts as the bank | ||
// and distributes funds across a set of wallets that fulfill the eibc orders | ||
func ensureWhaleAccount() error { | ||
home, _ := os.UserHomeDir() | ||
kc := utils.KeyConfig{ | ||
Dir: consts.ConfigDirName.Eibc, | ||
ID: "client", | ||
ChainBinary: consts.Executables.Dymension, | ||
Type: "", | ||
} | ||
|
||
_, err := utils.GetAddressBinary(kc, consts.Executables.Dymension) | ||
if err != nil { | ||
fmt.Println("whale account not found in the keyring, creating it now") | ||
addressInfo, err := initconfig.CreateAddressBinaryWithSensitiveOutput(kc, home) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
whaleAddress := utils.SecretAddressData{ | ||
AddressData: utils.AddressData{ | ||
Name: addressInfo.Name, | ||
Addr: addressInfo.Address, | ||
}, | ||
Mnemonic: addressInfo.Mnemonic, | ||
} | ||
|
||
utils.PrintSecretAddressesWithTitle([]utils.SecretAddressData{whaleAddress}) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// createMongoDbContainer function creates a mongodb container using docker | ||
// sdk. Any 'DOCKER_HOST' can be used for this mongodb container. | ||
// Mongodb is used to store information about processed eibc orders | ||
func createMongoDbContainer() error { | ||
cc, err := client.NewClientWithOpts(client.FromEnv) | ||
if err != nil { | ||
fmt.Printf("failed to create docker client: %v\n", err) | ||
return err | ||
} | ||
|
||
err = utils.CheckAndCreateMongoDBContainer( | ||
context.Background(), | ||
cc, | ||
) | ||
if err != nil { | ||
fmt.Printf("failed to run mongodb container: %v\n", err) | ||
return err | ||
} | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.