Skip to content

Commit

Permalink
Merge pull request #370 from bianjieai/release/v1.6.x
Browse files Browse the repository at this point in the history
merge irita commit
  • Loading branch information
towerkyoto authored Jul 17, 2023
2 parents c835543 + acba076 commit c1a6307
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 122 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.17

require (
github.com/cosmos/cosmos-sdk v0.45.1
github.com/cosmos/ibc-go v1.1.0
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
Expand Down
33 changes: 0 additions & 33 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions modules/farm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func GetCmdQueryFarmPools() *cobra.Command {
Example: fmt.Sprintf("$ %s query farm pools", version.AppName),
Short: "Query farm pools by page",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -71,7 +71,7 @@ func GetCmdQueryFarmPool() *cobra.Command {
Short: "Query a farm pool",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand All @@ -98,7 +98,7 @@ func GetCmdQueryFarmer() *cobra.Command {
Short: "Query farmer reward",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions modules/mt/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func GetCmdQueryDenoms() *cobra.Command {
Long: "Query all denoms.",
Example: fmt.Sprintf("$ %s query mt denoms", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -69,7 +69,7 @@ func GetCmdQueryDenom() *cobra.Command {
Example: fmt.Sprintf("$ %s query mt denom <denom-id>", version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func GetCmdQueryMTSupply() *cobra.Command {
Example: fmt.Sprintf("$ %s query mt supply <denom-id> <mt-id>", version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -127,7 +127,7 @@ func GetCmdQueryMTs() *cobra.Command {
Example: fmt.Sprintf("$ %s query mt tokens <denom-id>", version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -162,7 +162,7 @@ func GetCmdQueryMT() *cobra.Command {
Example: fmt.Sprintf("$ %s query mt token <denom-id> <mt-id>", version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func GetCmdQueryBalances() *cobra.Command {
Example: fmt.Sprintf("$ %s query mt balances <owner> <denom-id>", version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions modules/nft/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func GetCmdQuerySupply() *cobra.Command {
Example: fmt.Sprintf("$ %s query nft supply <denom-id>", version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -85,7 +85,7 @@ func GetCmdQueryOwner() *cobra.Command {
Example: fmt.Sprintf("$ %s query nft owner <address> --denom-id=<denom-id>", version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func GetCmdQueryCollection() *cobra.Command {
Example: fmt.Sprintf("$ %s query nft collection <denom-id>", version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -164,7 +164,7 @@ func GetCmdQueryDenoms() *cobra.Command {
Long: "Query all denominations of all collections of NFTs.",
Example: fmt.Sprintf("$ %s query nft denoms", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -194,7 +194,7 @@ func GetCmdQueryDenom() *cobra.Command {
Example: fmt.Sprintf("$ %s query nft denom <denom-id>", version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -223,7 +223,7 @@ func GetCmdQueryNFT() *cobra.Command {
Example: fmt.Sprintf("$ %s query nft token <denom-id> <nft-id>", version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion modules/nft/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewGenesisState(collections []Collection) *GenesisState {
// error for any failed validation criteria.
func ValidateGenesis(data GenesisState) error {
for _, c := range data.Collections {
if err := ValidateDenomID(c.Denom.Name); err != nil {
if err := ValidateDenomID(c.Denom.Id); err != nil {
return err
}

Expand Down
13 changes: 5 additions & 8 deletions modules/nft/types/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ var (
// IsBeginWithAlpha only begin with [a-z]
IsBeginWithAlpha = regexp.MustCompile(`^[a-z].*`).MatchString

tokenIdString = `[a-z0-9]{1,128}`
regexpTokenID = regexp.MustCompile(fmt.Sprintf(`^%s$`, tokenIdString)).MatchString

keywords = strings.Join([]string{ReservedPeg, ReservedIBC, ReservedHTLT, ReservedTIBC}, "|")
regexpKeywordsFmt = fmt.Sprintf("^(%s).*", keywords)
regexpKeyword = regexp.MustCompile(regexpKeywordsFmt).MatchString
)

// ValidateDenomID verifies whether the parameters are legal
func ValidateDenomID(denomID string) error {
if len(denomID) < MinDenomLen || len(denomID) > MaxDenomLen {
return sdkerrors.Wrapf(ErrInvalidDenom, "the length of denom(%s) only accepts value [%d, %d]", denomID, MinDenomLen, MaxDenomLen)
}
boolPrifix := strings.HasPrefix(denomID, "tibc-")
if !IsBeginWithAlpha(denomID) || !IsAlphaNumeric(denomID) && !boolPrifix {
return sdkerrors.Wrapf(ErrInvalidDenom, "the denom(%s) only accepts alphanumeric characters, and begin with an english letter", denomID)
Expand All @@ -48,11 +48,8 @@ func ValidateDenomID(denomID string) error {

// ValidateTokenID verify that the tokenID is legal
func ValidateTokenID(tokenID string) error {
if len(tokenID) < MinDenomLen || len(tokenID) > MaxDenomLen {
return sdkerrors.Wrapf(ErrInvalidTokenID, "the length of nft id(%s) only accepts value [%d, %d]", tokenID, MinDenomLen, MaxDenomLen)
}
if !IsBeginWithAlpha(tokenID) || !IsAlphaNumeric(tokenID) {
return sdkerrors.Wrapf(ErrInvalidTokenID, "nft id(%s) only accepts alphanumeric characters, and begin with an english letter", tokenID)
if !regexpTokenID(tokenID) {
return sdkerrors.Wrapf(ErrInvalidTokenID, "tokenID can only accept characters that match the regular expression: (%s),but got (%s)", tokenIdString, tokenID)
}
return nil
}
Expand Down
13 changes: 9 additions & 4 deletions modules/random/keeper/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package keeper

import (
"encoding/hex"
"math/rand"
"time"

"github.com/tidwall/gjson"

Expand Down Expand Up @@ -38,8 +36,15 @@ func (k Keeper) RequestService(ctx sdk.Context, consumer sdk.AccAddress, service
return nil, sdkerrors.ErrInsufficientFee
}

rand.Seed(time.Now().UnixNano())
provider, _ := sdk.AccAddressFromBech32(bindings[rand.Intn(len(bindings))].Provider)
prng := types.MakePRNG(
ctx.BlockHeader().LastBlockId.Hash,
ctx.BlockHeader().Time.UnixNano(),
consumer, nil, true)
provider, err := sdk.AccAddressFromBech32(bindings[prng.Intn(len(bindings))].Provider)
if err != nil {
return nil, err
}

timeout := k.serviceKeeper.GetParams(ctx).MaxRequestTimeout

return k.serviceKeeper.CreateRequestContext(
Expand Down
6 changes: 6 additions & 0 deletions modules/random/types/rng.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
"crypto/sha256"
"math/big"
"math/rand"

sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -59,6 +60,11 @@ func (p PRNG) GetRand() *big.Rat {
return random
}

func (p PRNG) Intn(n int) int {
rnd := rand.New(rand.NewSource(p.GetRand().Denom().Int64()))
return rnd.Intn(n)
}

// SHA256 wraps sha256.Sum256 with result converted to slice
func SHA256(data []byte) []byte {
sum := sha256.Sum256(data)
Expand Down
2 changes: 1 addition & 1 deletion modules/record/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func GetCmdQueryRecord() *cobra.Command {
Short: "Query a record",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit c1a6307

Please sign in to comment.