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

feat: override private keys w/ env vars #87

Merged
merged 3 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 15 additions & 1 deletion ethereum/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package ethereum

import (
"fmt"
"os"
"strings"

"github.com/strangelove-ventures/noble-cctp-relayer/types"
)

Expand All @@ -24,11 +28,21 @@ type ChainConfig struct {
MetricsDenom string `yaml:"metrics-denom"`
MetricsExponent int `yaml:"metrics-exponent"`

// TODO move to keyring
MinterPrivateKey string `yaml:"minter-private-key"`
}

func (c *ChainConfig) Chain(name string) (types.Chain, error) {
envKey := strings.ToUpper(name) + "_PRIV_KEY"
joelsmith-2019 marked this conversation as resolved.
Show resolved Hide resolved
privKey := os.Getenv(envKey)

if len(c.MinterPrivateKey) == 0 || len(privKey) != 0 {
if len(privKey) == 0 {
return nil, fmt.Errorf("env variable %s is empty, priv key not found for chain %s", envKey, name)
} else {
c.MinterPrivateKey = privKey
}
}

return NewChain(
name,
c.Domain,
Expand Down
20 changes: 18 additions & 2 deletions noble/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package noble

import "github.com/strangelove-ventures/noble-cctp-relayer/types"
import (
"fmt"
"os"
"strings"

"github.com/strangelove-ventures/noble-cctp-relayer/types"
)

var _ types.ChainConfig = (*ChainConfig)(nil)

Expand All @@ -23,11 +29,21 @@ type ChainConfig struct {

MinMintAmount uint64 `yaml:"min-mint-amount"`

// TODO move to keyring
MinterPrivateKey string `yaml:"minter-private-key"`
}

func (c *ChainConfig) Chain(name string) (types.Chain, error) {
envKey := strings.ToUpper(name) + "_PRIV_KEY"
privKey := os.Getenv(envKey)

if len(c.MinterPrivateKey) == 0 || len(privKey) != 0 {
if len(privKey) == 0 {
return nil, fmt.Errorf("env variable %s is empty, priv key not found for chain %s", envKey, name)
} else {
c.MinterPrivateKey = privKey
}
}

return NewChain(
c.RPC,
c.ChainID,
Expand Down
Loading