Skip to content

Commit

Permalink
R4R: fix the type of flags (#33)
Browse files Browse the repository at this point in the history
* fix some bugs

* update flag files

* update flag files

Co-authored-by: 王迪 <wangdi@bianjie.ai>
  • Loading branch information
dgsbl and 王迪 committed Oct 26, 2020
1 parent 3142108 commit dc17759
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 55 deletions.
2 changes: 1 addition & 1 deletion modules/htlc/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ func init() {
FsCreateHTLC.BytesHex(FlagSecret, nil, "The secret for generating the hash lock, randomly generated if omitted")
FsCreateHTLC.BytesHex(FlagHashLock, nil, "The sha256 hash generated from secret (and timestamp if provided), generated according to the secret flag if omitted")
FsCreateHTLC.Uint64(FlagTimestamp, 0, "The timestamp in seconds for generating the hash lock if provided")
FsCreateHTLC.String(FlagTimeLock, "", "The number of blocks to wait before tokens may be refunded")
FsCreateHTLC.Uint64(FlagTimeLock, 0, "The number of blocks to wait before tokens may be refunded")
}
34 changes: 6 additions & 28 deletions modules/htlc/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package cli

import (
"crypto/rand"
"encoding/hex"
"fmt"
"strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -88,11 +85,11 @@ func GetCmdCreateHTLC() *cobra.Command {
return err
}

timestamp, err := cmd.Flags().GetInt64(FlagTimestamp)
timestamp, err := cmd.Flags().GetUint64(FlagTimestamp)
if err != nil {
return err
}
timeLock, err := cmd.Flags().GetInt64(FlagTimeLock)
timeLock, err := cmd.Flags().GetUint64(FlagTimeLock)
if err != nil {
return err
}
Expand All @@ -102,40 +99,21 @@ func GetCmdCreateHTLC() *cobra.Command {

flags := cmd.Flags()
if flags.Changed(FlagHashLock) {
rawHashLock, err := cmd.Flags().GetString(FlagHashLock)
hashLock, err = cmd.Flags().GetBytesHex(FlagHashLock)
if err != nil {
return err
}
hashLockStr := strings.TrimSpace(rawHashLock)
if hashLock, err = hex.DecodeString(hashLockStr); err != nil {
return err
}
} else {
rawSecret, err := cmd.Flags().GetString(FlagSecret)
secret, err = cmd.Flags().GetBytesHex(FlagSecret)
if err != nil {
return err
}
secretStr := strings.TrimSpace(rawSecret)
if len(secretStr) > 0 {
if len(secretStr) != 2*types.SecretLength {
return fmt.Errorf("length of the secret must be %d in bytes", types.SecretLength)
}

if secret, err = hex.DecodeString(secretStr); err != nil {
return err
}
} else {
if _, err := rand.Read(secret); err != nil {
return err
}
}

hashLock = types.GetHashLock(secret, uint64(timestamp))
hashLock = types.GetHashLock(secret, timestamp)
}

msg := types.NewMsgCreateHTLC(
sender, to, receiverOnOtherChain, amount,
hashLock, uint64(timestamp), uint64(timeLock),
hashLock, timestamp, timeLock,
)
if err := msg.ValidateBasic(); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion modules/oracle/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func init() {
FsCreateFeed.Int64(FlagTimeout, 0, "The maximum number of blocks to wait for a response since a request is sent, beyond which the request will be ignored")
FsCreateFeed.String(FlagServiceFeeCap, "", "Only providers charging a fee lower than the cap will be invoked")
FsCreateFeed.Uint64(FlagFrequency, 0, "The invocation frequency of sending repeated requests")
FsCreateFeed.Uint16(FlagThreshold, 0, "The minimum number of responses needed for aggregation, range [1, Length(providers)]")
FsCreateFeed.Uint32(FlagThreshold, 0, "The minimum number of responses needed for aggregation, range [1, Length(providers)]")
FsCreateFeed.String(FlagCreator, "", "Address of the feed creator")

FsStartFeed.String(FlagFeedName, "", "The unique identifier of the feed")
Expand Down
2 changes: 1 addition & 1 deletion modules/service/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func init() {
FsCallService.StringSlice(FlagProviders, []string{}, "provider list to request")
FsCallService.String(FlagServiceFeeCap, "", "maximum service fee to pay for a single request")
FsCallService.String(FlagData, "", "content or file path of the request input, which is an Input JSON schema instance")
FsCallService.Uint64(FlagTimeout, 0, "request timeout")
FsCallService.Int64(FlagTimeout, 0, "request timeout")
FsCallService.Bool(FlagSuperMode, false, "indicate if the signer is a super user")
FsCallService.Bool(FlagRepeated, false, "indicate if the request is repetitive")
FsCallService.Uint64(FlagFrequency, 0, "request frequency when repeated, default to timeout")
Expand Down
2 changes: 1 addition & 1 deletion modules/token/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func init() {
FsIssueToken.String(FlagSymbol, "", "the token symbol. Once created, it cannot be modified")
FsIssueToken.String(FlagName, "", "the token name, e.g. IRIS Network")
FsIssueToken.String(FlagMinUnit, "", "the minimum unit name of the token, e.g. wei")
FsIssueToken.Uint8(FlagScale, 0, "the token decimal. The maximum value is 18")
FsIssueToken.Uint32(FlagScale, 0, "the token decimal. The maximum value is 18")
FsIssueToken.Uint64(FlagInitialSupply, 0, "the initial supply of the token")
FsIssueToken.Uint64(FlagMaxSupply, types.MaximumMaxSupply, "the max supply of the token")
FsIssueToken.Bool(FlagMintable, false, "whether the token can be minted, default to false")
Expand Down
24 changes: 12 additions & 12 deletions modules/token/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ func GetQueryCmd() *cobra.Command {
}

queryCmd.AddCommand(
getCmdQueryToken(),
getCmdQueryTokens(),
getCmdQueryFee(),
getCmdQueryParams(),
GetCmdQueryToken(),
GetCmdQueryTokens(),
GetCmdQueryFee(),
GetCmdQueryParams(),
)

return queryCmd
}

// getCmdQueryToken implements the query token command.
func getCmdQueryToken() *cobra.Command {
// GetCmdQueryToken implements the query token command.
func GetCmdQueryToken() *cobra.Command {
cmd := &cobra.Command{
Use: "token [denom]",
Long: "Query a token by symbol or minUnit.",
Expand Down Expand Up @@ -69,8 +69,8 @@ func getCmdQueryToken() *cobra.Command {
return cmd
}

// getCmdQueryTokens implements the query tokens command.
func getCmdQueryTokens() *cobra.Command {
// GetCmdQueryTokens implements the query tokens command.
func GetCmdQueryTokens() *cobra.Command {
cmd := &cobra.Command{
Use: "tokens [owner]",
Long: "Query token by the owner.",
Expand Down Expand Up @@ -118,8 +118,8 @@ func getCmdQueryTokens() *cobra.Command {
return cmd
}

// getCmdQueryFee implements the query token related fees command.
func getCmdQueryFee() *cobra.Command {
// GetCmdQueryFee implements the query token related fees command.
func GetCmdQueryFee() *cobra.Command {
cmd := &cobra.Command{
Use: "fee [symbol]",
Args: cobra.ExactArgs(1),
Expand Down Expand Up @@ -157,8 +157,8 @@ func getCmdQueryFee() *cobra.Command {
return cmd
}

// getCmdQueryParams implements the query token related param command.
func getCmdQueryParams() *cobra.Command {
// GetCmdQueryParams implements the query token related param command.
func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Long: "Query values set as token parameters.",
Expand Down
22 changes: 11 additions & 11 deletions modules/token/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ func NewTxCmd() *cobra.Command {
}

txCmd.AddCommand(
getCmdIssueToken(),
getCmdEditToken(),
getCmdMintToken(),
getCmdTransferTokenOwner(),
GetCmdIssueToken(),
GetCmdEditToken(),
GetCmdMintToken(),
GetCmdTransferTokenOwner(),
)

return txCmd
}

// getCmdIssueToken implements the issue token command
func getCmdIssueToken() *cobra.Command {
// GetCmdIssueToken implements the issue token command
func GetCmdIssueToken() *cobra.Command {
cmd := &cobra.Command{
Use: "issue",
Long: "Issue a new token.",
Expand Down Expand Up @@ -153,8 +153,8 @@ func getCmdIssueToken() *cobra.Command {
return cmd
}

// getCmdEditToken implements the edit token command
func getCmdEditToken() *cobra.Command {
// GetCmdEditToken implements the edit token command
func GetCmdEditToken() *cobra.Command {
cmd := &cobra.Command{
Use: "edit [symbol]",
Long: "Edit an existing token.",
Expand Down Expand Up @@ -210,7 +210,7 @@ func getCmdEditToken() *cobra.Command {
return cmd
}

func getCmdMintToken() *cobra.Command {
func GetCmdMintToken() *cobra.Command {
cmd := &cobra.Command{
Use: "mint [symbol]",
Long: "Mint tokens to a specified address.",
Expand Down Expand Up @@ -298,8 +298,8 @@ func getCmdMintToken() *cobra.Command {
return cmd
}

// getCmdTransferTokenOwner implements the transfer token owner command
func getCmdTransferTokenOwner() *cobra.Command {
// GetCmdTransferTokenOwner implements the transfer token owner command
func GetCmdTransferTokenOwner() *cobra.Command {
cmd := &cobra.Command{
Use: "transfer [symbol]",
Long: "Transfer the owner of a token to a new owner.",
Expand Down

0 comments on commit dc17759

Please sign in to comment.