Skip to content

Commit

Permalink
eliminate the random module's dependency on oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-zq committed Jun 25, 2024
1 parent cbfc764 commit c2cda47
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
2 changes: 0 additions & 2 deletions modules/random/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ require (
google.golang.org/grpc v1.60.1
google.golang.org/protobuf v1.32.0
mods.irisnet.org/api v1.0.0-beta
mods.irisnet.org/modules/oracle v1.0.0-beta
mods.irisnet.org/modules/service v1.0.0-beta
mods.irisnet.org/simapp v1.0.0-beta
)
Expand Down Expand Up @@ -201,7 +200,6 @@ replace (

// TODO
mods.irisnet.org/api => ../../api
mods.irisnet.org/modules/oracle => ../oracle
mods.irisnet.org/modules/service => ../service
mods.irisnet.org/simapp => ../../simapp
)
4 changes: 2 additions & 2 deletions modules/random/keeper/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (k Keeper) HandlerResponse(
}

outputBody := gjson.Get(responseOutput[0], servicetypes.PATH_BODY).String()
if err := servicetypes.ValidateResponseOutputBody(types.ServiceSchemas, outputBody); err != nil {
if err := servicetypes.ValidateResponseOutputBody(servicetypes.RandomServiceSchemas, outputBody); err != nil {
ctx.Logger().Error(
"invalid output body",
"body", outputBody,
Expand All @@ -141,7 +141,7 @@ func (k Keeper) HandlerResponse(
return
}

seedStr := gjson.Get(outputBody, types.ServiceValueJSONPath).String()
seedStr := gjson.Get(outputBody, servicetypes.RandomServiceValueJSONPath).String()
seed, err := hex.DecodeString(seedStr)
if err != nil || len(seed) != types.SeedBytesLength {
ctx.Logger().Error(
Expand Down
3 changes: 3 additions & 0 deletions modules/random/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const (

// RouterKey is the msg router key for the random module
RouterKey = ModuleName

// ServiceName is the name of the random service
ServiceName = ModuleName
)

var (
Expand Down
35 changes: 16 additions & 19 deletions modules/random/types/service.go → modules/service/types/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import (
"github.com/cometbft/cometbft/crypto"

sdk "github.com/cosmos/cosmos-sdk/types"

"mods.irisnet.org/modules/oracle/types"
servicetypes "mods.irisnet.org/modules/service/types"
)

const (
ServiceName = "random"
ServiceDesc = "system service definition of random module"
ServiceValueJSONPath = "seed"
AuthorDescription = "random module account"
ServiceSchemas = `
RandomServiceName = "random"
RandomServiceDesc = "system service definition of random module"
RandomServiceValueJSONPath = "seed"
RandomAuthorDescription = "random module account"
RandomServiceSchemas = `
{
"input": {
"$schema": "http://json-schema.org/draft-04/schema#",
Expand Down Expand Up @@ -44,17 +41,17 @@ const (
)

var (
ServiceTags = []string{types.ModuleName}
Author = sdk.AccAddress(crypto.AddressHash([]byte(types.ModuleName)))
RandomServiceTags = []string{"oracle"}
RandomAuthor = sdk.AccAddress(crypto.AddressHash([]byte("oracle")))
)

func GetSvcDefinition() servicetypes.ServiceDefinition {
return servicetypes.NewServiceDefinition(
ServiceName,
ServiceDesc,
ServiceTags,
Author,
AuthorDescription,
ServiceSchemas,
func GetRandomSvcDefinition() ServiceDefinition {
return NewServiceDefinition(
RandomServiceName,
RandomServiceDesc,
RandomServiceTags,
RandomAuthor,
RandomAuthorDescription,
RandomServiceSchemas,
)
}
}

0 comments on commit c2cda47

Please sign in to comment.