Skip to content

Commit

Permalink
Merge pull request #946 from scrtlabs/fumpt
Browse files Browse the repository at this point in the history
gofumpt -w -l .
  • Loading branch information
assafmo authored Jul 14, 2022
2 parents a6071fa + e9430f4 commit 9c09c61
Show file tree
Hide file tree
Showing 81 changed files with 366 additions and 357 deletions.
20 changes: 9 additions & 11 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package app

import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"

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

Expand Down Expand Up @@ -94,11 +98,6 @@ import (
reg "github.com/enigmampc/SecretNetwork/x/registration"
"github.com/spf13/cast"

"io"
"net/http"
"os"
"path/filepath"

"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -242,13 +241,12 @@ func NewSecretNetworkApp(
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
//enabledProposals []compute.ProposalType,
// enabledProposals []compute.ProposalType,
bootstrap bool,
appOpts servertypes.AppOptions,
computeConfig *compute.WasmConfig,
baseAppOptions ...func(*baseapp.BaseApp),
) *SecretNetworkApp {

encodingConfig := MakeEncodingConfig()
appCodec, legacyAmino := encodingConfig.Marshaler, encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
Expand All @@ -258,7 +256,7 @@ func NewSecretNetworkApp(
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
//bApp.GRPCQueryRouter().RegisterSimulateService(bApp.Simulate, interfaceRegistry)
// bApp.GRPCQueryRouter().RegisterSimulateService(bApp.Simulate, interfaceRegistry)

keys := sdk.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
Expand Down Expand Up @@ -442,7 +440,7 @@ func NewSecretNetworkApp(

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
// we prefer to be more strict in what arguments the modules expect.
var skipGenesisInvariants = cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))
skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))

// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
Expand Down Expand Up @@ -538,7 +536,7 @@ func NewSecretNetworkApp(
govtypes.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
//custom modules
// custom modules
compute.ModuleName,
reg.ModuleName,

Expand Down Expand Up @@ -585,7 +583,7 @@ func NewSecretNetworkApp(
// evidence.NewAppModule(app.evidenceKeeper),
//)

//app.sm.RegisterStoreDecoders()
// app.sm.RegisterStoreDecoders()

// initialize stores
app.MountKVStores(keys)
Expand Down
75 changes: 36 additions & 39 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,44 +52,42 @@ import (
"github.com/enigmampc/SecretNetwork/x/registration"
)

var (
mbasics = module.NewBasicManager(
append([]module.AppModuleBasic{
authz.AppModuleBasic{},
// accounts, fees.
auth.AppModuleBasic{},
// genesis utilities
genutil.AppModuleBasic{},
// tokens, token balance.
bank.AppModuleBasic{},
capability.AppModuleBasic{},
// validator staking
staking.AppModuleBasic{},
// inflation
mint.AppModuleBasic{},
// distribution of fess and inflation
distr.AppModuleBasic{},
// governance functionality (voting)
gov.NewAppModuleBasic(
paramsclient.ProposalHandler, distrclient.ProposalHandler,
upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
),
// chain parameters
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
ibc.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
ica.AppModuleBasic{},
},
// our stuff
customModuleBasics()...,
)...,
)
var mbasics = module.NewBasicManager(
append([]module.AppModuleBasic{
authz.AppModuleBasic{},
// accounts, fees.
auth.AppModuleBasic{},
// genesis utilities
genutil.AppModuleBasic{},
// tokens, token balance.
bank.AppModuleBasic{},
capability.AppModuleBasic{},
// validator staking
staking.AppModuleBasic{},
// inflation
mint.AppModuleBasic{},
// distribution of fess and inflation
distr.AppModuleBasic{},
// governance functionality (voting)
gov.NewAppModuleBasic(
paramsclient.ProposalHandler, distrclient.ProposalHandler,
upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
),
// chain parameters
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
ibc.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
ica.AppModuleBasic{},
},
// our stuff
customModuleBasics()...,
)...,
)

func customKVStoreKeys() []string {
Expand Down Expand Up @@ -163,5 +161,4 @@ func transientStoreKeys() map[string]*sdk.TransientStoreKey {

func memStoreKeys() map[string]*sdk.MemoryStoreKey {
return sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)

}
2 changes: 1 addition & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"encoding/json"

servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand Down Expand Up @@ -103,7 +104,6 @@ func (app *SecretNetworkApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllow

// reinitialize all validators
app.stakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {

// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps := app.distrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
feePool := app.distrKeeper.GetFeePool(ctx)
Expand Down
3 changes: 2 additions & 1 deletion app/legacy/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package legacy
import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/x/authz"
"io/ioutil"
"time"

"github.com/cosmos/cosmos-sdk/x/authz"

"github.com/pkg/errors"
"github.com/spf13/cobra"
tmjson "github.com/tendermint/tendermint/libs/json"
Expand Down
1 change: 1 addition & 0 deletions app/legacy/v120/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package legacy

import (
"fmt"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
Expand Down
1 change: 0 additions & 1 deletion app/upgrades/v1.3/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const UpgradeName = "v1.3"
func CreateUpgradeHandler(mm *module.Manager, icamodule *icamodule.AppModule, configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {

// Assaf: Set version map for all modules because for some
// reason it's not already set in upgradekeepr.
// We upgrade from cosmos-sdk v0.44.5 to v0.45.4 and ibc-go v1.1.5 to v3.0.0
Expand Down
52 changes: 25 additions & 27 deletions cmd/secretd/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -19,25 +25,25 @@ import (
reg "github.com/enigmampc/SecretNetwork/x/registration"
ra "github.com/enigmampc/SecretNetwork/x/registration/remote_attestation"
"github.com/spf13/cobra"
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
)

const flagReset = "reset"
const flagPulsar = "pulsar"
const flagCustomRegistrationService = "registration-service"
const (
flagReset = "reset"
flagPulsar = "pulsar"
flagCustomRegistrationService = "registration-service"
)

const flagLegacyRegistrationNode = "registration-node"
const flagLegacyBootstrapNode = "node"
const (
flagLegacyRegistrationNode = "registration-node"
flagLegacyBootstrapNode = "node"
)

const mainnetRegistrationService = "https://mainnet-register.scrtlabs.com/api/registernode"
const pulsarRegistrationService = "https://testnet-register.scrtlabs.com/api/registernode"
const (
mainnetRegistrationService = "https://mainnet-register.scrtlabs.com/api/registernode"
pulsarRegistrationService = "https://testnet-register.scrtlabs.com/api/registernode"
)

func InitAttestation() *cobra.Command {

cmd := &cobra.Command{
Use: "init-enclave [output-file]",
Short: "Perform remote attestation of the enclave",
Expand All @@ -47,15 +53,14 @@ blockchain. Writes the certificate in DER format to ~/attestation_cert
`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {

sgxSecretsDir := os.Getenv("SCRT_SGX_STORAGE")
if sgxSecretsDir == "" {
sgxSecretsDir = os.ExpandEnv("/opt/secret/.sgx_secrets")
}

// create sgx secrets dir if it doesn't exist
if _, err := os.Stat(sgxSecretsDir); !os.IsNotExist(err) {
err := os.MkdirAll(sgxSecretsDir, 0777)
err := os.MkdirAll(sgxSecretsDir, 0o777)
if err != nil {
return err
}
Expand Down Expand Up @@ -109,7 +114,6 @@ blockchain. Writes the certificate in DER format to ~/attestation_cert
}

func InitBootstrapCmd() *cobra.Command {

cmd := &cobra.Command{
Use: "init-bootstrap [node-exchange-file] [io-exchange-file]",
Short: "Perform bootstrap initialization",
Expand Down Expand Up @@ -224,7 +228,6 @@ func ParseCert() *cobra.Command {
"register the node, during node initialization",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {

// parse coins trying to be sent
cert, err := ioutil.ReadFile(args[0])
if err != nil {
Expand All @@ -251,7 +254,6 @@ func ConfigureSecret() *cobra.Command {
"seed that was written on-chain",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {

cert, err := ioutil.ReadFile(args[0])
if err != nil {
return err
Expand Down Expand Up @@ -287,7 +289,7 @@ func ConfigureSecret() *cobra.Command {

seedFilePath := filepath.Join(nodeDir, reg.SecretNodeSeedConfig)

err = ioutil.WriteFile(seedFilePath, cfgBytes, 0664)
err = ioutil.WriteFile(seedFilePath, cfgBytes, 0o664)
if err != nil {
return err
}
Expand All @@ -306,7 +308,6 @@ func HealthCheck() *cobra.Command {
Long: "Help diagnose issues by performing a basic sanity test that SGX is working properly",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {

res, err := api.HealthCheck()
if err != nil {
return fmt.Errorf("failed to start enclave. Enclave returned: %s", err)
Expand All @@ -328,7 +329,6 @@ func ResetEnclave() *cobra.Command {
"You will have to go through registration again to be able to start the node",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {

homeDir, err := cmd.Flags().GetString(flags.FlagHome)
if err != nil {
return err
Expand Down Expand Up @@ -359,7 +359,7 @@ func ResetEnclave() *cobra.Command {
if err != nil {
return err
}
err := os.MkdirAll(sgxSecretsDir, 0777)
err := os.MkdirAll(sgxSecretsDir, 0o777)
if err != nil {
return err
}
Expand Down Expand Up @@ -393,7 +393,6 @@ type ErrorResponse struct {

// AutoRegisterNode *** EXPERIMENTAL ***
func AutoRegisterNode() *cobra.Command {

cmd := &cobra.Command{
Use: "auto-register",
Short: "Perform remote attestation of the enclave",
Expand All @@ -402,7 +401,6 @@ Please report any issues with this command
`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {

sgxSecretsFolder := os.Getenv("SCRT_SGX_STORAGE")
if sgxSecretsFolder == "" {
sgxSecretsFolder = os.ExpandEnv("/opt/secret/.sgx_secrets")
Expand Down Expand Up @@ -552,7 +550,7 @@ Please report any issues with this command
// create seed directory if it doesn't exist
_, err = os.Stat(seedCfgDir)
if os.IsNotExist(err) {
err = os.MkdirAll(seedCfgDir, 0777)
err = os.MkdirAll(seedCfgDir, 0o777)
if err != nil {
return fmt.Errorf("failed to create directory '%s': %w", seedCfgDir, err)
}
Expand All @@ -561,7 +559,7 @@ Please report any issues with this command
// write seed to file - if file doesn't exist, write it. If it does, delete the existing one and create this
_, err = os.Stat(seedCfgFile)
if os.IsNotExist(err) {
err = ioutil.WriteFile(seedCfgFile, cfgBytes, 0644)
err = ioutil.WriteFile(seedCfgFile, cfgBytes, 0o644)
if err != nil {
return err
}
Expand All @@ -571,7 +569,7 @@ Please report any issues with this command
return fmt.Errorf("failed to modify file '%s': %w", seedCfgFile, err)
}

err = ioutil.WriteFile(seedCfgFile, cfgBytes, 0644)
err = ioutil.WriteFile(seedCfgFile, cfgBytes, 0o644)
if err != nil {
return fmt.Errorf("failed to create file '%s': %w", seedCfgFile, err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/secretd/cli_attestation.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build secretcli
// +build secretcli

package main
Expand All @@ -9,7 +10,6 @@ import (
const flagReset = "reset"

func InitAttestation() *cobra.Command {

cmd := &cobra.Command{
Use: "init-enclave [output-file]",
Short: "Perform remote attestation of the enclave",
Expand All @@ -29,7 +29,6 @@ blockchain. Writes the certificate in DER format to ~/attestation_cert
}

func InitBootstrapCmd() *cobra.Command {

cmd := &cobra.Command{
Use: "init-bootstrap [node-exchange-file] [io-exchange-file]",
Short: "Perform bootstrap initialization",
Expand Down
Loading

0 comments on commit 9c09c61

Please sign in to comment.