Skip to content

Commit

Permalink
Pass amount and asset to faucet command
Browse files Browse the repository at this point in the history
  • Loading branch information
tiero committed Jan 26, 2021
1 parent e78f8e5 commit 20c5565
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions cli/cmd/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
var FaucetCmd = &cobra.Command{
Args: func(cmd *cobra.Command, args []string) error {

if len(args) != 1 {
return errors.New("Insert receiving address")
if len(args) < 1 {
return errors.New("missing address")
}
return nil
},
Use: "faucet <address>",
Use: "faucet <address> [amount] [asset]",
Short: "Generate and send bitcoin to given address",
RunE: faucet,
PreRunE: faucetChecks,
Expand All @@ -40,7 +40,7 @@ func faucetChecks(cmd *cobra.Command, args []string) error {
if err := ctl.ParseDatadir(datadir); err != nil {
return err
}
if len(args) != 1 {
if len(args) < 1 {
return constants.ErrInvalidArgs
}

Expand All @@ -61,15 +61,26 @@ func faucetChecks(cmd *cobra.Command, args []string) error {
return nil
}

func faucet(cmd *cobra.Command, address []string) error {
func faucet(cmd *cobra.Command, args []string) error {
isLiquidService, err := cmd.Flags().GetBool("liquid")
datadir, _ := cmd.Flags().GetString("datadir")
if err != nil {
return err
}
request := map[string]string{
"address": address[0],
request := map[string]interface{}{
"address": args[0],
}
if len(args) >= 2 {
amountFloat, err := strconv.ParseFloat(args[1], 64)
if err != nil {
return fmt.Errorf("invalid amount: %v", err)
}
request["amount"] = amountFloat
}
if len(args) == 3 {
request["asset"] = args[2]
}

ctl, err := controller.NewController()
if err != nil {
return err
Expand Down Expand Up @@ -99,7 +110,7 @@ func faucet(cmd *cobra.Command, address []string) error {

var dat map[string]string
if err := json.Unmarshal([]byte(data), &dat); err != nil {
return errors.New("Internal error. Try again.")
return errors.New("internal error, please try again")
}
if dat["txId"] == "" {
return errors.New("Not Successful")
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func mintChecks(cmd *cobra.Command, args []string) error {
return err
}
if len(args) < 2 {
return errors.New("Missing required arguments.")
return errors.New("missing required arguments")
}

if isRunning, err := ctl.IsNigiriRunning(); err != nil {
Expand Down

0 comments on commit 20c5565

Please sign in to comment.