Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
chain: Final cleanup for Wenchang release
Browse files Browse the repository at this point in the history
  • Loading branch information
sorawit committed Apr 1, 2020
1 parent b6a1bf7 commit d4db672
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 136 deletions.
2 changes: 1 addition & 1 deletion chain/app/db_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewDBBandApp(
app := NewBandApp(logger, db, traceStore, loadLatest, invCheckPeriod, baseAppOptions...)

dbBand.StakingKeeper = app.StakingKeeper
dbBand.ZoracleKeeper = app.ZoracleKeeper
// dbBand.ZoracleKeeper = app.ZoracleKeeper
return &dbBandApp{bandApp: app, dbBand: dbBand}
}

Expand Down
146 changes: 72 additions & 74 deletions chain/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app

import (
"encoding/json"
"io/ioutil"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -17,8 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"

"github.com/bandprotocol/bandchain/chain/x/zoracle"
// "github.com/bandprotocol/bandchain/chain/x/zoracle"
)

// GenesisState defines a type alias for the Gaia genesis application state.
Expand Down Expand Up @@ -114,82 +112,82 @@ func NewDefaultGenesisState() GenesisState {
supply.ModuleName: supply.ModuleCdc.MustMarshalJSON(supply.GenesisState{
Supply: sdk.NewCoins(),
}),
zoracle.ModuleName: zoracle.ModuleCdc.MustMarshalJSON(zoracle.DefaultGenesisState()),
// zoracle.ModuleName: zoracle.ModuleCdc.MustMarshalJSON(zoracle.DefaultGenesisState()),
genutil.ModuleName: genutil.ModuleCdc.MustMarshalJSON(genutil.GenesisState{
GenTxs: []json.RawMessage{},
}),
}
}

func GetDefaultDataSourcesAndOracleScripts(owner sdk.AccAddress) json.RawMessage {
state := zoracle.DefaultGenesisState()
dataSources := []struct {
name string
description string
path string
}{
{
"Coingecko script",
"The Script that queries crypto price from https://coingecko.com",
"./datasources/coingecko_price.sh",
},
{
"Crypto compare script",
"The Script that queries crypto price from https://cryptocompare.com",
"./datasources/crypto_compare_price.sh",
},
{
"Binance price",
"The Script that queries crypto price from https://www.binance.com/en",
"./datasources/binance_price.sh",
},
{
"Open weather",
"The script that queries current weather",
"./datasources/open_weather_map.sh",
},
}
// func GetDefaultDataSourcesAndOracleScripts(owner sdk.AccAddress) json.RawMessage {
// state := zoracle.DefaultGenesisState()
// dataSources := []struct {
// name string
// description string
// path string
// }{
// {
// "Coingecko script",
// "The Script that queries crypto price from https://coingecko.com",
// "./datasources/coingecko_price.sh",
// },
// {
// "Crypto compare script",
// "The Script that queries crypto price from https://cryptocompare.com",
// "./datasources/crypto_compare_price.sh",
// },
// {
// "Binance price",
// "The Script that queries crypto price from https://www.binance.com/en",
// "./datasources/binance_price.sh",
// },
// {
// "Open weather",
// "The script that queries current weather",
// "./datasources/open_weather_map.sh",
// },
// }

// TODO: Find a better way to specify path to data sources
state.DataSources = make([]zoracle.DataSource, len(dataSources))
for i, dataSource := range dataSources {
script, err := ioutil.ReadFile(dataSource.path)
if err != nil {
panic(err)
}
state.DataSources[i] = zoracle.NewDataSource(
owner,
dataSource.name,
dataSource.description,
sdk.Coins{},
script,
)
}
// // TODO: Find a better way to specify path to data sources
// state.DataSources = make([]zoracle.DataSource, len(dataSources))
// for i, dataSource := range dataSources {
// script, err := ioutil.ReadFile(dataSource.path)
// if err != nil {
// panic(err)
// }
// state.DataSources[i] = zoracle.NewDataSource(
// owner,
// dataSource.name,
// dataSource.description,
// sdk.Coins{},
// script,
// )
// }

// TODO: Find a better way to specify path to oracle scripts
oracleScripts := []struct {
name string
description string
path string
}{
{
"Crypto price script",
"Oracle script for getting an average crypto price from many sources.",
"./owasm/res/crypto_price.wasm",
},
}
state.OracleScripts = make([]zoracle.OracleScript, len(oracleScripts))
for i, oracleScript := range oracleScripts {
code, err := ioutil.ReadFile(oracleScript.path)
if err != nil {
panic(err)
}
state.OracleScripts[i] = zoracle.NewOracleScript(
owner,
oracleScript.name,
oracleScript.description,
code,
)
}
return zoracle.ModuleCdc.MustMarshalJSON(state)
}
// // TODO: Find a better way to specify path to oracle scripts
// oracleScripts := []struct {
// name string
// description string
// path string
// }{
// {
// "Crypto price script",
// "Oracle script for getting an average crypto price from many sources.",
// "./owasm/res/crypto_price.wasm",
// },
// }
// state.OracleScripts = make([]zoracle.OracleScript, len(oracleScripts))
// for i, oracleScript := range oracleScripts {
// code, err := ioutil.ReadFile(oracleScript.path)
// if err != nil {
// panic(err)
// }
// state.OracleScripts[i] = zoracle.NewOracleScript(
// owner,
// oracleScript.name,
// oracleScript.description,
// code,
// )
// }
// return zoracle.ModuleCdc.MustMarshalJSON(state)
// }
4 changes: 2 additions & 2 deletions chain/cmd/bandcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path"

"github.com/bandprotocol/bandchain/chain/app"
bandclient "github.com/bandprotocol/bandchain/chain/client"
// bandclient "github.com/bandprotocol/bandchain/chain/client"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/keys"
Expand Down Expand Up @@ -68,7 +68,7 @@ func main() {
}

func registerRoutes(rs *lcd.RestServer) {
bandclient.RegisterRoutes(rs.CliCtx, rs.Mux)
// bandclient.RegisterRoutes(rs.CliCtx, rs.Mux)
client.RegisterRoutes(rs.CliCtx, rs.Mux)
authrest.RegisterTxRoutes(rs.CliCtx, rs.Mux)
app.ModuleBasics.RegisterRESTRoutes(rs.CliCtx, rs.Mux)
Expand Down
23 changes: 11 additions & 12 deletions chain/cmd/bandd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import (
"github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/types"

"github.com/bandprotocol/bandchain/chain/x/zoracle"
// "github.com/bandprotocol/bandchain/chain/x/zoracle"
)

const (
flagOverwrite = "overwrite"
flagClientHome = "home-client"
flagZoracle = "zoracle"
// flagZoracle = "zoracle"
)

type printInfo struct {
Expand Down Expand Up @@ -100,7 +99,7 @@ func InitCmd(
ctx *server.Context,
cdc *codec.Codec,
customAppState map[string]json.RawMessage,
getDefaultDataSourcesAndOracleScripts func(sdk.AccAddress) json.RawMessage,
// getDefaultDataSourcesAndOracleScripts func(sdk.AccAddress) json.RawMessage,
defaultNodeHome string,
) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -135,13 +134,13 @@ func InitCmd(
if !viper.GetBool(flagOverwrite) && common.FileExists(genFile) {
return fmt.Errorf("genesis.json file already exists: %v", genFile)
}
if viper.IsSet(flagZoracle) {
owner, err := sdk.AccAddressFromBech32(viper.GetString(flagZoracle))
if err != nil {
return err
}
customAppState[zoracle.ModuleName] = getDefaultDataSourcesAndOracleScripts(owner)
}
// if viper.IsSet(flagZoracle) {
// owner, err := sdk.AccAddressFromBech32(viper.GetString(flagZoracle))
// if err != nil {
// return err
// }
// customAppState[zoracle.ModuleName] = getDefaultDataSourcesAndOracleScripts(owner)
// }
appState, err := codec.MarshalJSONIndent(cdc, customAppState)
if err != nil {
return err
Expand Down Expand Up @@ -187,7 +186,7 @@ func InitCmd(
cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory")
cmd.Flags().BoolP(flagOverwrite, "o", false, "overwrite the genesis.json file")
cmd.Flags().String(client.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
cmd.Flags().String(flagZoracle, "band15d4apf20449ajvwycq8ruaypt7v6d345n9fpt9", "owner of these data sources and oracle scripts")
// cmd.Flags().String(flagZoracle, "band15d4apf20449ajvwycq8ruaypt7v6d345n9fpt9", "owner of these data sources and oracle scripts")

return cmd
}
2 changes: 1 addition & 1 deletion chain/cmd/bandd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func main() {
}
// CLI commands to initialize the chain
rootCmd.AddCommand(
InitCmd(ctx, cdc, app.NewDefaultGenesisState(), app.GetDefaultDataSourcesAndOracleScripts, app.DefaultNodeHome),
InitCmd(ctx, cdc, app.NewDefaultGenesisState() /* app.GetDefaultDataSourcesAndOracleScripts, */, app.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(ctx, cdc, genaccounts.AppModuleBasic{}, app.DefaultNodeHome),
genutilcli.MigrateGenesisCmd(ctx, cdc),
genutilcli.GenTxCmd(
Expand Down
2 changes: 1 addition & 1 deletion chain/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type BandDB struct {
ctx sdk.Context

StakingKeeper staking.Keeper
ZoracleKeeper zoracle.Keeper
// ZoracleKeeper zoracle.Keeper
}

func NewDB(dialect, path string, metadata map[string]string) (*BandDB, error) {
Expand Down
38 changes: 19 additions & 19 deletions chain/db/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ func (b *BandDB) handleMsgReportData(
return err
}

for _, data := range msg.DataSet {
rawDataRequest, errSdk := b.ZoracleKeeper.GetRawDataRequest(
b.ctx, msg.RequestID, data.ExternalDataID,
)
if errSdk != nil {
return errSdk
}
err := b.tx.Create(&ReportDetail{
RequestID: int64(msg.RequestID),
Validator: msg.Validator.String(),
ExternalID: int64(data.ExternalDataID),
DataSourceID: int64(rawDataRequest.DataSourceID),
Data: data.Data,
Exitcode: data.ExitCode,
}).Error
// for _, data := range msg.DataSet {
// rawDataRequest, errSdk := b.ZoracleKeeper.GetRawDataRequest(
// b.ctx, msg.RequestID, data.ExternalDataID,
// )
// if errSdk != nil {
// return errSdk
// }
// err := b.tx.Create(&ReportDetail{
// RequestID: int64(msg.RequestID),
// Validator: msg.Validator.String(),
// ExternalID: int64(data.ExternalDataID),
// DataSourceID: int64(rawDataRequest.DataSourceID),
// Data: data.Data,
// Exitcode: data.ExitCode,
// }).Error

if err != nil {
return err
}
}
// if err != nil {
// return err
// }
// }

return nil
}
52 changes: 26 additions & 26 deletions chain/db/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,32 +136,32 @@ func (b *BandDB) handleMsgRequestData(
return err
}

req, err := b.ZoracleKeeper.GetRequest(b.ctx, zoracle.RequestID(id))
if err != nil {
return err
}

for _, validatorAddress := range req.RequestedValidators {
requestedValidator := createRequestedValidator(id, validatorAddress.String())
err = b.tx.Save(&requestedValidator).Error
if err != nil {
return err
}
}

for _, raw := range b.ZoracleKeeper.GetRawDataRequestWithExternalIDs(b.ctx, zoracle.RequestID(id)) {
rawDataRequests := createRawDataRequests(id, int64(raw.ExternalID), int64(raw.RawDataRequest.DataSourceID), raw.RawDataRequest.Calldata)
err = b.tx.Save(&rawDataRequests).Error
if err != nil {
return err
}

b.tx.FirstOrCreate(&RelatedDataSources{
DataSourceID: int64(raw.RawDataRequest.DataSourceID),
OracleScriptID: int64(msg.OracleScriptID),
})

}
// req, err := b.ZoracleKeeper.GetRequest(b.ctx, zoracle.RequestID(id))
// if err != nil {
// return err
// }

// for _, validatorAddress := range req.RequestedValidators {
// requestedValidator := createRequestedValidator(id, validatorAddress.String())
// err = b.tx.Save(&requestedValidator).Error
// if err != nil {
// return err
// }
// }

// for _, raw := range b.ZoracleKeeper.GetRawDataRequestWithExternalIDs(b.ctx, zoracle.RequestID(id)) {
// rawDataRequests := createRawDataRequests(id, int64(raw.ExternalID), int64(raw.RawDataRequest.DataSourceID), raw.RawDataRequest.Calldata)
// err = b.tx.Save(&rawDataRequests).Error
// if err != nil {
// return err
// }

// b.tx.FirstOrCreate(&RelatedDataSources{
// DataSourceID: int64(raw.RawDataRequest.DataSourceID),
// OracleScriptID: int64(msg.OracleScriptID),
// })

// }

return nil
}

0 comments on commit d4db672

Please sign in to comment.