This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 1620-implement-uptime-new-design2
- Loading branch information
Showing
15 changed files
with
435 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"path/filepath" | ||
|
||
"github.com/bandprotocol/bandchain/chain/pkg/filecache" | ||
codecstd "github.com/cosmos/cosmos-sdk/codec/std" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/genutil" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"github.com/tendermint/go-amino" | ||
"github.com/tendermint/tendermint/libs/cli" | ||
|
||
"github.com/bandprotocol/bandchain/chain/x/oracle" | ||
otypes "github.com/bandprotocol/bandchain/chain/x/oracle/types" | ||
) | ||
|
||
// AddGenesisDataSourceCmd returns add-data-source cobra Command. | ||
func AddGenesisDataSourceCmd( | ||
ctx *server.Context, depCdc *amino.Codec, cdc *codecstd.Codec, defaultNodeHome string, | ||
) *cobra.Command { | ||
|
||
cmd := &cobra.Command{ | ||
Use: "add-data-source [name] [description] [owner] [filepath]", | ||
Short: "Add a data source to genesis.json", | ||
Args: cobra.ExactArgs(4), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
config := ctx.Config | ||
config.SetRoot(viper.GetString(cli.HomeFlag)) | ||
f := filecache.New(filepath.Join(viper.GetString(cli.HomeFlag), "files")) | ||
data, err := ioutil.ReadFile(args[3]) | ||
if err != nil { | ||
return err | ||
} | ||
filename := f.AddFile(data) | ||
owner, err := sdk.AccAddressFromBech32(args[2]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
genFile := config.GenesisFile() | ||
appState, genDoc, err := genutil.GenesisStateFromGenFile(depCdc, genFile) | ||
if err != nil { | ||
return fmt.Errorf("failed to unmarshal genesis state: %w", err) | ||
} | ||
|
||
oracleGenState := oracle.GetGenesisStateFromAppState(depCdc, appState) | ||
oracleGenState.DataSources = append(oracleGenState.DataSources, otypes.NewDataSource( | ||
owner, args[0], args[1], filename, | ||
)) | ||
|
||
appState[oracle.ModuleName] = cdc.MustMarshalJSON(oracleGenState) | ||
appStateJSON := cdc.MustMarshalJSON(appState) | ||
genDoc.AppState = appStateJSON | ||
return genutil.ExportGenesisFile(genDoc, genFile) | ||
}, | ||
} | ||
|
||
cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"path/filepath" | ||
|
||
"github.com/bandprotocol/bandchain/chain/pkg/filecache" | ||
codecstd "github.com/cosmos/cosmos-sdk/codec/std" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/genutil" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"github.com/tendermint/go-amino" | ||
"github.com/tendermint/tendermint/libs/cli" | ||
|
||
"github.com/bandprotocol/bandchain/chain/x/oracle" | ||
otypes "github.com/bandprotocol/bandchain/chain/x/oracle/types" | ||
) | ||
|
||
// AddGenesisOracleScriptCmd returns add-oracle-script cobra Command. | ||
func AddGenesisOracleScriptCmd( | ||
ctx *server.Context, depCdc *amino.Codec, cdc *codecstd.Codec, defaultNodeHome string, | ||
) *cobra.Command { | ||
|
||
cmd := &cobra.Command{ | ||
Use: "add-oracle-script [name] [description] [schema] [url] [owner] [filepath]", | ||
Short: "Add a data source to genesis.json", | ||
Args: cobra.ExactArgs(6), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
config := ctx.Config | ||
config.SetRoot(viper.GetString(cli.HomeFlag)) | ||
f := filecache.New(filepath.Join(viper.GetString(cli.HomeFlag), "files")) | ||
data, err := ioutil.ReadFile(args[5]) | ||
if err != nil { | ||
return err | ||
} | ||
filename := f.AddFile(data) | ||
owner, err := sdk.AccAddressFromBech32(args[4]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
genFile := config.GenesisFile() | ||
appState, genDoc, err := genutil.GenesisStateFromGenFile(depCdc, genFile) | ||
if err != nil { | ||
return fmt.Errorf("failed to unmarshal genesis state: %w", err) | ||
} | ||
|
||
oracleGenState := oracle.GetGenesisStateFromAppState(depCdc, appState) | ||
oracleGenState.OracleScripts = append(oracleGenState.OracleScripts, otypes.NewOracleScript( | ||
owner, args[0], args[1], filename, args[2], args[3], | ||
)) | ||
|
||
appState[oracle.ModuleName] = cdc.MustMarshalJSON(oracleGenState) | ||
appStateJSON := cdc.MustMarshalJSON(appState) | ||
genDoc.AppState = appStateJSON | ||
return genutil.ExportGenesisFile(genDoc, genFile) | ||
}, | ||
} | ||
|
||
cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory") | ||
return cmd | ||
} |
Oops, something went wrong.