8000 feat: add cosmosfaucet by ilgooz · Pull Request #630 · ignite/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add cosmosfaucet #630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 15, 2021
Merged
1 change: 1 addition & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ ports:
- port: 26657
- port: 8080
- port: 7575
- port: 4500
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ require (
golang.org/x/mod v0.4.0
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
golang.org/x/sys v0.0.0-20210113000019-eaf3bda374d2 // indirect
golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78 // indirect
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect
google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154 // indirect
google.golang.org/grpc v1.33.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,8 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210113000019-eaf3bda374d2 h1:F9vNgpIiamoF+Q1/c78bikg/NScXEtbZSNEpnRelOzs=
golang.org/x/sys v0.0.0-20210113000019-eaf3bda374d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78 h1:nVuTkr9L6Bq62qpUqKo/RnZCFfzDBL0bYo6w9OJUqZY=
golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
2 changes: 1 addition & 1 deletion starport/interface/cli/starport/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func newChainWithHomeFlags(cmd *cobra.Command, appPath string, chainOption ...ch
chainOption = append(chainOption, chain.CLIHomePath(cliHome))
}

return chain.New(appPath, chainOption...)
return chain.New(cmd.Context(), appPath, chainOption...)
}

func initOptionWithHomeFlags(cmd *cobra.Command, initOptions []networkbuilder.InitOption) ([]networkbuilder.InitOption, error) {
Expand Down
143 changes: 131 additions & 12 deletions starport/pkg/chaincmd/chaincmd.go
6D4E 9E7A
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const (
commandCollectGentxs = "collect-gentxs"
commandValidateGenesis = "validate-genesis"
commandShowNodeID = "show-node-id"
commandStatus = "status"
commandTx = "tx"
commandQuery = "query"

optionHome = "--home"
optionKeyringBackend = "--keyring-backend"
Expand All @@ -30,6 +33,7 @@ const (
optionValidatorCommissionMaxChangeRate = "--commission-max-change-rate"
optionValidatorMinSelfDelegation = "--min-self-delegation"
optionValidatorGasPrices = "--gas-prices"
optionYes = "--yes"
optionHomeClient = "--home-client"

constTendermint = "tendermint"
Expand All @@ -48,34 +52,48 @@ const (
)

type ChainCmd struct {
appCmd string
chainID string
homeDir string
keyringBackend KeyringBackend
cliCmd string
cliHome string
appCmd string
chainID string
homeDir string
keyringBackend KeyringBackend
keyringPassword string
cliCmd string
cliHome string
nodeAddress string

isAutoChainIDDetectionEnabled bool

sdkVersion cosmosver.Version
}

// New creates a new ChainCmd to launch command with the chain app
func New(appCmd string, options ...Option) ChainCmd {
chainCmd := ChainCmd{
c := ChainCmd{
appCmd: appCmd,
sdkVersion: cosmosver.Versions.Latest(),
}

// Apply the options provided by the user
for _, applyOption := range options {
applyOption(&chainCmd)
}
applyOptions(&c, options)

return chainCmd
return c
}

// Copy makes a copy of ChainCmd by overwriting its options with given options.
func (c ChainCmd) Copy(options ...Option) ChainCmd {
applyOptions(&c, options)

return c
}

// Option configures ChainCmd.
type Option func(*ChainCmd)

func applyOptions(c *ChainCmd, options []Option) {
for _, applyOption := range options {
applyOption(c)
}
}

// WithVersion sets the version of the blockchain.
// when this is not provided, latest version of SDK is assumed.
func WithVersion(v cosmosver.Version) Option {
Expand All @@ -98,13 +116,51 @@ func WithChainID(chainID string) Option {
}
}

// WithAutoChainIDDetection finds out the chain id by communicating with the node running.
func WithAutoChainIDDetection() Option {
return func(c *ChainCmd) {
c.isAutoChainIDDetectionEnabled = true
}
}

// WithKeyringBackend provides a specific keyring backend for the commands that accept this option
func WithKeyringBackend(keyringBackend KeyringBackend) Option {
return func(c *ChainCmd) {
c.keyringBackend = keyringBackend
}
}

// WithKeyringPassword provides a password to unlock keyring
func WithKeyringPassword(password string) Option {
return func(c *ChainCmd) {
c.keyringPassword = password
}
}

// WitNodeAddress sets the node address for the commands that needs to make an
// API request to the node that has a different node address other than the default one.
func WitNodeAddress(addr string) Option {
return func(c *ChainCmd) {
c.nodeAddress = addr
}
}

// WithLaunchpadCLI provides the CLI application name for the blockchain
// this is necessary for Launchpad applications since it has two different binaries but
// not needed by Stargate applications
func WithLaunchpadCLI(cliCmd string) Option {
return func(c *ChainCmd) {
c.cliCmd = cliCmd
}
}

// WithLaunchpadCLIHome replaces the default home used by the Launchpad chain CLI
func WithLaunchpadCLIHome(cliHome string) Option {
return func(c *ChainCmd) {
c.cliHome = cliHome
}
}

// StartCommand returns the command to start the daemon of the chain
func (c ChainCmd) StartCommand(options ...string) step.Option {
command := append([]string{
Expand Down Expand Up @@ -249,6 +305,14 @@ func GentxWithGasPrices(gasPrices string) GentxOption {
}
}

func (c ChainCmd) IsAutoChainIDDetectionEnabled() bool {
return c.isAutoChainIDDetectionEnabled
}

func (c ChainCmd) SDKVersion() cosmosver.Version {
return c.sdkVersion
}

// GentxCommand returns the command to generate a gentx for the chain
func (c ChainCmd) GentxCommand(
validatorName string,
Expand Down Expand Up @@ -328,6 +392,52 @@ func (c ChainCmd) ShowNodeIDCommand() step.Option {
return c.daemonCommand(command)
}

// BankSendCommand returns the command for transferring tokens.
func (c ChainCmd) BankSendCommand(fromAddress, toAddress, amount string) step.Option {
command := []string{
commandTx,
}

if c.sdkVersion.Major().Is(cosmosver.Stargate) {
command = append(command,
"bank",
)
}

command = append(command,
"send",
fromAddress,
toAddress,
amount,
optionYes,
)

command = c.attachChainID(command)
command = c.attachKeyringBackend(command)

return c.cliCommand(command)
}

// QueryTxEventsCommand returns the command to query events.
func (c ChainCmd) QueryTxEventsCommand(query string) step.Option {
command := []string{
commandQuery,
"txs",
"--events",
query,
"--page", "1",
"--limit", "1000",
}

if c.sdkVersion.Major().Is(cosmosver.Launchpad) {
command = append(command,
"--trust-node",
)
}

return c.cliCommand(command)
}

// LaunchpadSetConfigCommand returns the command to set config value
func (c ChainCmd) LaunchpadSetConfigCommand(name string, value string) step.Option {
// Check version
Expand All @@ -346,6 +456,15 @@ func (c ChainCmd) LaunchpadRestServerCommand(apiAddress string, rpcAddress strin
return c.launchpadRestServerCommand(apiAddress, rpcAddress)
}

// StatusCommand returns the command that fetches node's status.
func (c ChainCmd) StatusCommand() step.Option {
command := []string{
commandStatus,
}

return c.cliCommand(command)
}

// attachChainID appends the chain ID flag to the provided command
func (c ChainCmd) attachChainID(command []string) []string {
if c.chainID != "" {
Expand Down
16 changes: 0 additions & 16 deletions starport/pkg/chaincmd/launchpad.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@ const (
optionName = "--name"
)

// WithLaunchpadCLI provides the CLI application name for the blockchain
// this is necessary for Launchpad applications since it has two different binaries but
// not needed by Stargate applications
func WithLaunchpadCLI(cliCmd string) Option {
return func(c *ChainCmd) {
c.cliCmd = cliCmd
}
}

// WithLaunchpadCLIHome replaces the default home used by the Launchpad chain CLI
func WithLaunchpadCLIHome(cliHome string) Option {
return func(c *ChainCmd) {
c.cliHome = cliHome
}
}

// launchpadSetConfigCommand
func (c ChainCmd) launchpadSetConfigCommand(name string, value string) step.Option {
command := []string{
Expand Down
15 changes: 14 additions & 1 deletion starport/pkg/chaincmd/runner/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import (
"github.com/tendermint/starport/starport/pkg/cmdrunner/step"
)

var (
// ErrAccountAlreadyExists returned when an already exists account attempted to be imported.
ErrAccountAlreadyExists = errors.New("account already exists")

// ErrAccountDoesNotExist returned when account does not exit.
ErrAccountDoesNotExist = errors.New("account does not exit")
)

// AddAccount creates a new account or imports an account when mnemonic is provided.
// returns with an error if the operation went unsuccessful or an account with the provided name
// already exists.
Expand All @@ -26,7 +34,7 @@ func (r Runner) AddAccount(ctx context.Context, name, mnemonic string) (Account,
}
for _, account := range accounts {
if account.Name == name {
return Account{}, errors.New("account already exists")
return Account{}, ErrAccountAlreadyExists
}
}
b.Reset()
Expand Down Expand Up @@ -77,9 +85,14 @@ type Account struct {
// ShowAccount shows details of an account.
func (r Runner) ShowAccount(ctx context.Context, name string) (Account, error) {
b := &bytes.Buffer{}

if err := r.run(ctx, runOptions{stdout: b}, r.cc.ShowKeyAddressCommand(name)); err != nil {
if strings.Contains(err.Error(), "item could not be found") {
return Account{}, ErrAccountDoesNotExist
}
return Account{}, err
}

return Account{
Name: name,
Address: strings.TrimSpace(b.String()),
Expand Down
Loading
0