Skip to content

Commit 6bb327a

Browse files
committed
Fix lint errors, remove unused code and fix typos #2
1 parent 71a80eb commit 6bb327a

39 files changed

+221
-2224
lines changed

cmd/secretd/attestation.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ the node to the chain. This process, if successful, will output a certificate wh
5353
blockchain. Writes the certificate in DER format to ~/attestation_cert
5454
`,
5555
Args: cobra.ExactArgs(0),
56-
RunE: func(cmd *cobra.Command, args []string) error {
56+
RunE: func(cmd *cobra.Command, _ []string) error {
5757
sgxSecretsDir := os.Getenv("SCRT_SGX_STORAGE")
5858
if sgxSecretsDir == "" {
5959
sgxSecretsDir = os.ExpandEnv("/opt/secret/.sgx_secrets")
@@ -261,7 +261,7 @@ func DumpBin() *cobra.Command {
261261
Long: "Helper to display the contents of a binary file, and extract the public key of the secret node, which is used to" +
262262
"register the node, during node initialization",
263263
Args: cobra.ExactArgs(1),
264-
RunE: func(cmd *cobra.Command, args []string) error {
264+
RunE: func(_ *cobra.Command, args []string) error {
265265
data, err := os.ReadFile(args[0])
266266
if err != nil {
267267
return err
@@ -281,7 +281,7 @@ func MigrateSealings() *cobra.Command {
281281
Short: "Migrate sealed files to the current format",
282282
Long: "Re-create SGX-sealed files according to the current format",
283283
Args: cobra.ExactArgs(0),
284-
RunE: func(cmd *cobra.Command, args []string) error {
284+
RunE: func(_ *cobra.Command, _ []string) error {
285285
_, err := api.MigrateSealing()
286286
if err != nil {
287287
return fmt.Errorf("failed to start enclave. Enclave returned: %s", err)
@@ -356,7 +356,7 @@ func HealthCheck() *cobra.Command {
356356
Short: "Test enclave status",
357357
Long: "Help diagnose issues by performing a basic sanity test that SGX is working properly",
358358
Args: cobra.ExactArgs(0),
359-
RunE: func(_ *cobra.Command, args []string) error {
359+
RunE: func(_ *cobra.Command, _ []string) error {
360360
res, err := api.HealthCheck()
361361
if err != nil {
362362
return fmt.Errorf("failed to start enclave. Enclave returned: %s", err)
@@ -377,7 +377,7 @@ func ResetEnclave() *cobra.Command {
377377
Long: "This will delete all registration and enclave parameters. Use when something goes wrong and you want to start fresh." +
378378
"You will have to go through registration again to be able to start the node",
379379
Args: cobra.ExactArgs(0),
380-
RunE: func(cmd *cobra.Command, args []string) error {
380+
RunE: func(cmd *cobra.Command, _ []string) error {
381381
homeDir, err := cmd.Flags().GetString(flags.FlagHome)
382382
if err != nil {
383383
return err
@@ -445,7 +445,7 @@ func AutoRegisterNode() *cobra.Command {
445445
Please report any issues with this command
446446
`,
447447
Args: cobra.ExactArgs(0),
448-
RunE: func(cmd *cobra.Command, args []string) error {
448+
RunE: func(cmd *cobra.Command, _ []string) error {
449449
sgxSecretsFolder := os.Getenv("SCRT_SGX_STORAGE")
450450
if sgxSecretsFolder == "" {
451451
sgxSecretsFolder = os.ExpandEnv("/opt/secret/.sgx_secrets")

cmd/secretd/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package main
22

33
import (
4-
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
54
cmtcfg "github.com/cometbft/cometbft/config"
5+
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
66
"github.com/scrtlabs/SecretNetwork/x/compute"
77
)
88

cmd/secretd/genaccounts.go

Lines changed: 4 additions & 219 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,5 @@
11
package main
22

3-
// import (
4-
// "bufio"
5-
// "encoding/json"
6-
// "errors"
7-
// "fmt"
8-
// "os"
9-
// "runtime/debug"
10-
11-
// "cosmossdk.io/core/address"
12-
// "github.com/cosmos/cosmos-sdk/client"
13-
// "github.com/cosmos/cosmos-sdk/crypto/keyring"
14-
// authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
15-
// banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
16-
// genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
17-
// "github.com/gogo/protobuf/codec"
18-
19-
// "github.com/spf13/cobra"
20-
21-
// "github.com/cosmos/cosmos-sdk/client/flags"
22-
// "github.com/cosmos/cosmos-sdk/server"
23-
// sdk "github.com/cosmos/cosmos-sdk/types"
24-
// "github.com/cosmos/cosmos-sdk/x/genutil"
25-
// )
26-
27-
/*
28-
const (
29-
flagClientHome = "home-client"
30-
flagVestingStart = "vesting-start-time"
31-
flagVestingEnd = "vesting-end-time"
32-
flagVestingAmt = "vesting-amount"
33-
)
34-
*/
35-
363
import (
374
"bufio"
385
"encoding/json"
@@ -41,7 +8,6 @@ import (
418
"os"
429
"runtime/debug"
4310

44-
//"cosmossdk.io/core/address"
4511
"github.com/cosmos/cosmos-sdk/client"
4612
"github.com/cosmos/cosmos-sdk/crypto/keyring"
4713
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
@@ -70,169 +36,6 @@ const (
7036
flagModuleName = "module-name"
7137
)
7238

73-
// AddGenesisAccountCmd returns add-genesis-account cobra Command.
74-
func _AddGenesisAccountCmd(defaultNodeHome string) *cobra.Command {
75-
cmd := &cobra.Command{
76-
Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]",
77-
Short: "Add a genesis account to genesis.json",
78-
Long: `Add a genesis account to genesis.json. The provided account must specify
79-
the account address or key name and a list of initial coins. If a key name is given,
80-
the address will be looked up in the local Keybase. The list of initial tokens must
81-
contain valid denominations. Accounts may optionally be supplied with vesting parameters.
82-
`,
83-
Args: cobra.ExactArgs(2),
84-
RunE: func(cmd *cobra.Command, args []string) error {
85-
clientCtx := client.GetClientContextFromCmd(cmd)
86-
cdc := clientCtx.Codec
87-
88-
serverCtx := server.GetServerContextFromCmd(cmd)
89-
config := serverCtx.Config
90-
91-
config.SetRoot(clientCtx.HomeDir)
92-
93-
addr, err := sdk.AccAddressFromBech32(args[0])
94-
if err != nil {
95-
inBuf := bufio.NewReader(cmd.InOrStdin())
96-
keyringBackend, err := cmd.Flags().GetString(flags.FlagKeyringBackend)
97-
if err != nil {
98-
return err
99-
}
100-
101-
// attempt to lookup address from Keybase if no address was provided
102-
kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf, clientCtx.Codec)
103-
if err != nil {
104-
return err
105-
}
106-
107-
info, err := kb.Key(args[0])
108-
if err != nil {
109-
return fmt.Errorf("failed to get address from Keybase: %w", err)
110-
}
111-
112-
addr, _ = info.GetAddress()
113-
}
114-
115-
// create concrete account type based on input parameters
116-
var genAccount authtypes.GenesisAccount
117-
118-
coins, err := sdk.ParseCoinsNormalized(args[1])
119-
if err != nil {
120-
return fmt.Errorf("failed to parse coins: %w", err)
121-
}
122-
123-
balances := banktypes.Balance{Address: addr.String(), Coins: coins.Sort()}
124-
125-
/*
126-
127-
vestingStart, _ := cmd.Flags().GetInt64(flagVestingStart)
128-
vestingEnd, _ := cmd.Flags().GetInt64(flagVestingEnd)
129-
vestingAmtStr, _ := cmd.Flags().GetString(flagVestingAmt)
130-
131-
vestingAmt, err := sdk.ParseCoins(vestingAmtStr)
132-
if err != nil {
133-
return fmt.Errorf("failed to parse vesting amount: %w", err)
134-
}
135-
136-
baseAccount := authtypes.NewBaseAccount(addr, nil, 0, 0)
137-
138-
if !vestingAmt.IsZero() {
139-
baseVestingAccount := authvesting.NewBaseVestingAccount(baseAccount, vestingAmt.Sort(), vestingEnd)
140-
141-
if (balances.Coins.IsZero() && !baseVestingAccount.OriginalVesting.IsZero()) ||
142-
baseVestingAccount.OriginalVesting.IsAnyGT(balances.Coins) {
143-
return errors.New("vesting amount cannot be greater than total amount")
144-
}
145-
146-
switch {
147-
case vestingStart != 0 && vestingEnd != 0:
148-
genAccount = authvesting.NewContinuousVestingAccountRaw(baseVestingAccount, vestingStart)
149-
150-
case vestingEnd != 0:
151-
genAccount = authvesting.NewDelayedVestingAccountRaw(baseVestingAccount)
152-
153-
default:
154-
return errors.New("invalid vesting parameters; must supply start and end time or end time")
155-
}
156-
} else {
157-
genAccount = baseAccount
158-
}
159-
*/
160-
161-
// TODO: If vesting is enabled, should remove following lines:
162-
baseAccount := authtypes.NewBaseAccount(addr, nil, 0, 0)
163-
genAccount = baseAccount
164-
165-
if err := genAccount.Validate(); err != nil {
166-
return fmt.Errorf("failed to validate new genesis account: %w", err)
167-
}
168-
169-
genFile := config.GenesisFile()
170-
appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile)
171-
if err != nil {
172-
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
173-
}
174-
175-
authGenState := authtypes.GetGenesisStateFromAppState(cdc, appState)
176-
177-
accs, err := authtypes.UnpackAccounts(authGenState.Accounts)
178-
if err != nil {
179-
return fmt.Errorf("failed to get accounts from any: %w", err)
180-
}
181-
182-
if accs.Contains(addr) {
183-
return fmt.Errorf("cannot add account at existing address %s", addr)
184-
}
185-
186-
// Add the new account to the set of genesis accounts and sanitize the
187-
// accounts afterwards.
188-
accs = append(accs, genAccount)
189-
accs = authtypes.SanitizeGenesisAccounts(accs)
190-
191-
genAccs, err := authtypes.PackAccounts(accs)
192-
if err != nil {
193-
return fmt.Errorf("failed to convert accounts into any's: %w", err)
194-
}
195-
authGenState.Accounts = genAccs
196-
197-
authGenStateBz, err := cdc.MarshalJSON(&authGenState)
198-
if err != nil {
199-
return fmt.Errorf("failed to marshal auth genesis state: %w", err)
200-
}
201-
202-
appState[authtypes.ModuleName] = authGenStateBz
203-
204-
bankGenState := banktypes.GetGenesisStateFromAppState(cdc, appState)
205-
bankGenState.Balances = append(bankGenState.Balances, balances)
206-
bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances)
207-
208-
bankGenStateBz, err := cdc.MarshalJSON(bankGenState)
209-
if err != nil {
210-
return fmt.Errorf("failed to marshal bank genesis state: %w", err)
211-
}
212-
213-
appState[banktypes.ModuleName] = bankGenStateBz
214-
215-
appStateJSON, err := json.Marshal(appState)
216-
if err != nil {
217-
return fmt.Errorf("failed to marshal application genesis state: %w", err)
218-
}
219-
220-
genDoc.AppState = appStateJSON
221-
return genutil.ExportGenesisFile(genDoc, genFile)
222-
},
223-
}
224-
225-
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
226-
// cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)")
227-
// cmd.Flags().String(flagClientHome, defaultClientHome, "client's home directory")
228-
// cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts")
229-
// cmd.Flags().Uint64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts")
230-
// cmd.Flags().Uint64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts")
231-
flags.AddQueryFlagsToCmd(cmd)
232-
233-
return cmd
234-
}
235-
23639
func AddGenesisAccountCmd(defaultNodeHome string, eCfg app.EncodingConfig) *cobra.Command {
23740
addressCodec := eCfg.TxConfig.SigningContext().AddressCodec()
23841
cmd := &cobra.Command{
@@ -258,7 +61,6 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
25861

25962
var kr keyring.Keyring
26063
addr, err := addressCodec.StringToBytes(args[0])
261-
// fmt.Fprintf(os.Stderr, "address: [%s]\n", string(addr))
26264
if err != nil {
26365
inBuf := bufio.NewReader(cmd.InOrStdin())
26466
keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
@@ -267,7 +69,6 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
26769
var err error
26870
kr, err = keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf, clientCtx.Codec)
26971
if err != nil {
270-
// panic(err)
27172
return err
27273
}
27374
} else {
@@ -276,13 +77,11 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
27677
if kr != nil {
27778
k, err := kr.Key(args[0])
27879
if err != nil {
279-
// panic(err)
28080
return fmt.Errorf("failed to get address from Keyring: %w", err)
28181
}
28282

28383
addr, err = k.GetAddress()
28484
if err != nil {
285-
// panic(err)
28685
return err
28786
}
28887
}
@@ -320,21 +119,6 @@ func AddGenesisAccount(
320119
vestingStart, vestingEnd int64,
321120
moduleName string,
322121
) error {
323-
// Added for debug purposes
324-
// fmt.Fprintln(os.Stderr, "------------- AddGenesisAccount --------------")
325-
326-
// if tCodec, ok := cdc.(*codec.ProtoCodec); ok {
327-
// ir := tCodec.InterfaceRegistry()
328-
// ia := ir.ListAllInterfaces()
329-
// fmt.Fprintf(os.Stderr, "* AddGenesisAccount Codec inspection: %s\n", reflect.ValueOf(cdc).Type())
330-
// fmt.Fprintf(os.Stderr, "* AddGenesisAccount Interface Regist: %s\n", reflect.ValueOf(ir).Type())
331-
// for _, i := range ia {
332-
// ii := ir.ListImplementations(i)
333-
// fmt.Fprintf(os.Stderr, "\t%s -> %s\n", i, ii)
334-
// }
335-
// fmt.Fprintln(os.Stderr, "----------------------------------------------")
336-
// }
337-
338122
coins, err := sdk.ParseCoinsNormalized(amountStr)
339123
if err != nil {
340124
return fmt.Errorf("failed to parse coins: %w", err)
@@ -351,7 +135,8 @@ func AddGenesisAccount(
351135
balances := banktypes.Balance{Address: accAddr.String(), Coins: coins.Sort()}
352136
baseAccount := authtypes.NewBaseAccount(accAddr, nil, 0, 0)
353137

354-
if !vestingAmt.IsZero() {
138+
switch {
139+
case !vestingAmt.IsZero():
355140
baseVestingAccount, err := authvesting.NewBaseVestingAccount(baseAccount, vestingAmt.Sort(), vestingEnd)
356141
if err != nil {
357142
return fmt.Errorf("failed to create base vesting account: %w", err)
@@ -372,9 +157,9 @@ func AddGenesisAccount(
372157
default:
373158
return errors.New("invalid vesting parameters; must supply start and end time or end time")
374159
}
375-
} else if moduleName != "" {
160+
case moduleName != "":
376161
genAccount = authtypes.NewEmptyModuleAccount(moduleName, authtypes.Burner, authtypes.Minter)
377-
} else {
162+
default:
378163
genAccount = baseAccount
379164
}
380165

cmd/secretd/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package main
22

33
import (
4+
"os"
5+
46
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
57
"github.com/scrtlabs/SecretNetwork/app"
6-
"os"
78
)
89

910
func main() {

0 commit comments

Comments
 (0)