Skip to content

Commit

Permalink
fix: Do not require vega init when using private key on `bridge erc20…
Browse files Browse the repository at this point in the history
…` command
  • Loading branch information
ValentinTrinque authored and jeremyletang committed Apr 29, 2024
1 parent add2c56 commit 233084e
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions cmd/vega/commands/bridge/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
type ERC20Cmd struct {
config.VegaHomeFlag
config.PassphraseFlag
Config nodewallets.Config
PrivateKey string `description:"A ethereum private key to be use to sign the messages" long:"private-key" required:"false"`
ChainID string `description:"The chain-id of the EVM bridge. Not required if generating signatures for the Ethereum bridge" long:"chain-id" required:"false"`

Expand All @@ -60,38 +59,36 @@ type ERC20Cmd struct {
var erc20Cmd *ERC20Cmd

func (e *ERC20Cmd) GetSigner() (bridges.Signer, error) {
vegaPaths := paths.New(e.VegaHome)

_, conf, err := config.EnsureNodeConfig(vegaPaths)
if err != nil {
return nil, err
}

e.Config = conf.NodeWallet

var s bridges.Signer
if len(e.PrivateKey) <= 0 {
pass, err := erc20Cmd.PassphraseFile.Get("node wallet", false)
if err != nil {
return nil, err
}

s, err = nodewallets.GetEthereumWallet(vegaPaths, pass)
if err != nil {
return nil, fmt.Errorf("couldn't get Ethereum node wallet: %w", err)
vegaPaths := paths.New(e.VegaHome)

if _, _, err := config.EnsureNodeConfig(vegaPaths); err != nil {
return nil, err
}
} else {
s, err = NewPrivKeySigner(e.PrivateKey)

s, err := nodewallets.GetEthereumWallet(vegaPaths, pass)
if err != nil {
return nil, fmt.Errorf("couldn't load private key: %w", err)
return nil, fmt.Errorf("couldn't get Ethereum node wallet: %w", err)
}

return s, nil
}

s, err := NewPrivKeySigner(e.PrivateKey)
if err != nil {
return nil, fmt.Errorf("couldn't load private key: %w", err)
}

return s, nil
}

func ERC20() *ERC20Cmd {
erc20Cmd = &ERC20Cmd{
Config: nodewallets.NewDefaultConfig(),
AddSigner: ERC20AddSignerCmd{},
RemoveSigner: ERC20RemoveSignerCmd{},
SetThreshold: ERC20SetThresholdCmd{},
Expand Down Expand Up @@ -635,8 +632,6 @@ func (opts *ERC20VerifyGlobalResumeCmd) Execute(_ []string) error {
fmt.Printf("%v\n", v)
}
return nil

return nil
}

type ERC20SetAssetLimitsCmd struct {
Expand Down

0 comments on commit 233084e

Please sign in to comment.