Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve smart contract interaction commands to support encrypted secrets manager #3

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion command/rootchain/validators/validator_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func runCommand(cmd *cobra.Command, _ []string) error {
outputter := command.InitializeOutputter(cmd)
defer outputter.WriteOutput()

validatorAccount, err := sidechainHelper.GetAccount(params.accountDir, params.accountConfig)
validatorAccount, err := sidechainHelper.GetAccount(params.accountDir, params.accountConfig, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion command/rootchain/withdraw/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func runCommand(cmd *cobra.Command, _ []string) error {
outputter := command.InitializeOutputter(cmd)
defer outputter.WriteOutput()

validatorAccount, err := sidechainHelper.GetAccount(params.accountDir, params.accountConfig)
validatorAccount, err := sidechainHelper.GetAccount(params.accountDir, params.accountConfig, false)
if err != nil {
return err
}
Expand Down
13 changes: 7 additions & 6 deletions command/sidechain/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
)

const (
SelfFlag = "self"
AmountFlag = "amount"
SelfFlag = "self"
AmountFlag = "amount"
InsecureLocalStoreFlag = "insecure"

DefaultGasPrice = 1879048192 // 0x70000000
)
Expand All @@ -37,9 +38,9 @@ func ValidateSecretFlags(dataDir, config string) error {
}

// GetAccount resolves secrets manager and returns an account object
func GetAccount(accountDir, accountConfig string) (*wallet.Account, error) {
func GetAccount(accountDir, accountConfig string, insecureLocalStore bool) (*wallet.Account, error) {
// resolve secrets manager instance and allow usage of insecure local secrets manager
secretsManager, err := polybftsecrets.GetSecretsManager(accountDir, accountConfig, true)
secretsManager, err := polybftsecrets.GetSecretsManager(accountDir, accountConfig, insecureLocalStore)
if err != nil {
return nil, err
}
Expand All @@ -48,8 +49,8 @@ func GetAccount(accountDir, accountConfig string) (*wallet.Account, error) {
}

// GetAccountFromDir returns an account object from local secrets manager
func GetAccountFromDir(accountDir string) (*wallet.Account, error) {
return GetAccount(accountDir, "")
func GetAccountFromDir(accountDir string, insecureLocalStore bool) (*wallet.Account, error) {
return GetAccount(accountDir, "", insecureLocalStore)
}

// Hydra TODO: Fix it to get validator info from child chain
Expand Down
11 changes: 6 additions & 5 deletions command/sidechain/registration/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ const (
)

type registerParams struct {
accountDir string
accountConfig string
jsonRPC string
stake string
chainID int64
accountDir string
accountConfig string
jsonRPC string
stake string
chainID int64
insecureLocalStore bool
}

func (rp *registerParams) validateFlags() error {
Expand Down
10 changes: 9 additions & 1 deletion command/sidechain/registration/register_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/command/helper"
"github.com/0xPolygon/polygon-edge/command/polybftsecrets"
"github.com/0xPolygon/polygon-edge/command/sidechain"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
bls "github.com/0xPolygon/polygon-edge/consensus/polybft/signer"
"github.com/0xPolygon/polygon-edge/consensus/polybft/wallet"
Expand Down Expand Up @@ -74,6 +75,13 @@ func setFlags(cmd *cobra.Command) {
"the ID of the chain",
)

cmd.Flags().BoolVar(
&params.insecureLocalStore,
sidechain.InsecureLocalStoreFlag,
false,
"a flag to indicate if the secrets used are encrypted. If set to true, the secrets are stored in plain text.",
)

helper.RegisterJSONRPCFlag(cmd)
cmd.MarkFlagsMutuallyExclusive(polybftsecrets.AccountConfigFlag, polybftsecrets.AccountDirFlag)
}
Expand All @@ -88,7 +96,7 @@ func runCommand(cmd *cobra.Command, _ []string) error {
outputter := command.InitializeOutputter(cmd)
defer outputter.WriteOutput()

secretsManager, err := polybftsecrets.GetSecretsManager(params.accountDir, params.accountConfig, true)
secretsManager, err := polybftsecrets.GetSecretsManager(params.accountDir, params.accountConfig, params.insecureLocalStore)
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions command/sidechain/rewards/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
)

type withdrawRewardsParams struct {
accountDir string
accountConfig string
jsonRPC string
accountDir string
accountConfig string
jsonRPC string
insecureLocalStore bool
}

type withdrawRewardResult struct {
Expand Down
10 changes: 9 additions & 1 deletion command/sidechain/rewards/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/0xPolygon/polygon-edge/command/helper"
"github.com/0xPolygon/polygon-edge/command/polybftsecrets"
rootHelper "github.com/0xPolygon/polygon-edge/command/rootchain/helper"
"github.com/0xPolygon/polygon-edge/command/sidechain"
sidechainHelper "github.com/0xPolygon/polygon-edge/command/sidechain"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/contracts"
Expand Down Expand Up @@ -50,6 +51,13 @@ func setFlags(cmd *cobra.Command) {
polybftsecrets.AccountConfigFlagDesc,
)

cmd.Flags().BoolVar(
&params.insecureLocalStore,
sidechain.InsecureLocalStoreFlag,
false,
"a flag to indicate if the secrets used are encrypted. If set to true, the secrets are stored in plain text.",
)

cmd.MarkFlagsMutuallyExclusive(polybftsecrets.AccountDirFlag, polybftsecrets.AccountConfigFlag)
}

Expand All @@ -63,7 +71,7 @@ func runCommand(cmd *cobra.Command, _ []string) error {
outputter := command.InitializeOutputter(cmd)
defer outputter.WriteOutput()

validatorAccount, err := sidechainHelper.GetAccount(params.accountDir, params.accountConfig)
validatorAccount, err := sidechainHelper.GetAccount(params.accountDir, params.accountConfig, params.insecureLocalStore)
if err != nil {
return err
}
Expand Down
13 changes: 7 additions & 6 deletions command/sidechain/staking/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ var (
)

type stakeParams struct {
accountDir string
accountConfig string
jsonRPC string
amount string
self bool
delegateAddress string
accountDir string
accountConfig string
jsonRPC string
amount string
self bool
delegateAddress string
insecureLocalStore bool
}

func (v *stakeParams) validateFlags() error {
Expand Down
10 changes: 9 additions & 1 deletion command/sidechain/staking/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/command/helper"
"github.com/0xPolygon/polygon-edge/command/polybftsecrets"
"github.com/0xPolygon/polygon-edge/command/sidechain"
sidechainHelper "github.com/0xPolygon/polygon-edge/command/sidechain"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/contracts"
Expand Down Expand Up @@ -74,6 +75,13 @@ func setFlags(cmd *cobra.Command) {
"account address to which stake should be delegated",
)

cmd.Flags().BoolVar(
&params.insecureLocalStore,
sidechain.InsecureLocalStoreFlag,
false,
"a flag to indicate if the secrets used are encrypted. If set to true, the secrets are stored in plain text.",
)

cmd.MarkFlagsMutuallyExclusive(sidechainHelper.SelfFlag, delegateAddressFlag)
cmd.MarkFlagsMutuallyExclusive(polybftsecrets.AccountDirFlag, polybftsecrets.AccountConfigFlag)
}
Expand All @@ -88,7 +96,7 @@ func runCommand(cmd *cobra.Command, _ []string) error {
outputter := command.InitializeOutputter(cmd)
defer outputter.WriteOutput()

validatorAccount, err := sidechainHelper.GetAccount(params.accountDir, params.accountConfig)
validatorAccount, err := sidechainHelper.GetAccount(params.accountDir, params.accountConfig, params.insecureLocalStore)
if err != nil {
return err
}
Expand Down
9 changes: 5 additions & 4 deletions command/sidechain/unstaking/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ var (
)

type unstakeParams struct {
accountDir string
accountConfig string
jsonRPC string
amount string
accountDir string
accountConfig string
jsonRPC string
amount string
insecureLocalStore bool

amountValue *big.Int
}
Expand Down
10 changes: 9 additions & 1 deletion command/sidechain/unstaking/unstake.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/command/helper"
"github.com/0xPolygon/polygon-edge/command/polybftsecrets"
"github.com/0xPolygon/polygon-edge/command/sidechain"
sidechainHelper "github.com/0xPolygon/polygon-edge/command/sidechain"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/contracts"
Expand Down Expand Up @@ -54,6 +55,13 @@ func setFlags(cmd *cobra.Command) {
"amount to unstake from validator",
)

cmd.Flags().BoolVar(
&params.insecureLocalStore,
sidechain.InsecureLocalStoreFlag,
false,
"a flag to indicate if the secrets used are encrypted. If set to true, the secrets are stored in plain text.",
)

cmd.MarkFlagsMutuallyExclusive(polybftsecrets.AccountDirFlag, polybftsecrets.AccountConfigFlag)
}

Expand All @@ -67,7 +75,7 @@ func runCommand(cmd *cobra.Command, _ []string) error {
outputter := command.InitializeOutputter(cmd)
defer outputter.WriteOutput()

validatorAccount, err := sidechainHelper.GetAccount(params.accountDir, params.accountConfig)
validatorAccount, err := sidechainHelper.GetAccount(params.accountDir, params.accountConfig, params.insecureLocalStore)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions command/sidechain/whitelist/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type whitelistParams struct {
accountConfig string
jsonRPC string
newValidatorAddress string
insecureLocalStore bool
}

func (ep *whitelistParams) validateFlags() error {
Expand Down
10 changes: 9 additions & 1 deletion command/sidechain/whitelist/whitelist_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/command/helper"
"github.com/0xPolygon/polygon-edge/command/polybftsecrets"
"github.com/0xPolygon/polygon-edge/command/sidechain"
sidechainHelper "github.com/0xPolygon/polygon-edge/command/sidechain"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/contracts"
Expand Down Expand Up @@ -58,6 +59,13 @@ func setFlags(cmd *cobra.Command) {
"account address of a possible validator",
)

cmd.Flags().BoolVar(
&params.insecureLocalStore,
sidechain.InsecureLocalStoreFlag,
false,
"a flag to indicate if the secrets used are encrypted. If set to true, the secrets are stored in plain text.",
)

cmd.MarkFlagsMutuallyExclusive(polybftsecrets.AccountDirFlag, polybftsecrets.AccountConfigFlag)
helper.RegisterJSONRPCFlag(cmd)
}
Expand All @@ -72,7 +80,7 @@ func runCommand(cmd *cobra.Command, _ []string) error {
outputter := command.InitializeOutputter(cmd)
defer outputter.WriteOutput()

governanceAccount, err := sidechainHelper.GetAccount(params.accountDir, params.accountConfig)
governanceAccount, err := sidechainHelper.GetAccount(params.accountDir, params.accountConfig, params.insecureLocalStore)
if err != nil {
return fmt.Errorf("enlist validator failed: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions command/sidechain/withdraw/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
)

type withdrawParams struct {
accountDir string
accountConfig string
jsonRPC string
accountDir string
accountConfig string
jsonRPC string
insecureLocalStore bool
}

func (w *withdrawParams) validateFlags() error {
Expand Down
10 changes: 9 additions & 1 deletion command/sidechain/withdraw/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/0xPolygon/polygon-edge/command/helper"
"github.com/0xPolygon/polygon-edge/command/polybftsecrets"
rootHelper "github.com/0xPolygon/polygon-edge/command/rootchain/helper"
"github.com/0xPolygon/polygon-edge/command/sidechain"
sidechainHelper "github.com/0xPolygon/polygon-edge/command/sidechain"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/contracts"
Expand Down Expand Up @@ -49,6 +50,13 @@ func setFlags(cmd *cobra.Command) {
polybftsecrets.AccountConfigFlagDesc,
)

cmd.Flags().BoolVar(
&params.insecureLocalStore,
sidechain.InsecureLocalStoreFlag,
false,
"a flag to indicate if the secrets used are encrypted. If set to true, the secrets are stored in plain text.",
)

cmd.MarkFlagsMutuallyExclusive(polybftsecrets.AccountDirFlag, polybftsecrets.AccountConfigFlag)
}

Expand All @@ -62,7 +70,7 @@ func runCommand(cmd *cobra.Command, _ []string) error {
outputter := command.InitializeOutputter(cmd)
defer outputter.WriteOutput()

validatorAccount, err := sidechainHelper.GetAccount(params.accountDir, params.accountConfig)
validatorAccount, err := sidechainHelper.GetAccount(params.accountDir, params.accountConfig, params.insecureLocalStore)
if err != nil {
return err
}
Expand Down
Loading