Skip to content

Commit

Permalink
add delegation manager address
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Jan 29, 2024
1 parent 607c07b commit 2eff3e4
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 14 deletions.
45 changes: 31 additions & 14 deletions pkg/operator/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ import (
"github.com/urfave/cli/v2"
)

type ChainMetadata struct {
BlockExplorerUrl string
ELDelegationManagerAddress string
}

var chainMetadataMap = map[int64]ChainMetadata{
utils.MainnetChainId: {
BlockExplorerUrl: "https://etherscan.io/tx",
ELDelegationManagerAddress: "",
},
utils.GoerliChainId: {
BlockExplorerUrl: "https://goerli.etherscan.io/tx",
ELDelegationManagerAddress: "0x1b7b8F6b258f95Cf9596EabB9aa18B62940Eb0a8",
},
utils.HoleskyChainId: {
BlockExplorerUrl: "https://holesky.etherscan.io/tx",
ELDelegationManagerAddress: "",
},
}

func RegisterCmd(p utils.Prompter) *cli.Command {
registerCmd := &cli.Command{
Name: "register",
Expand Down Expand Up @@ -155,9 +175,14 @@ func validateAndMigrateConfigFile(path string) (*types.OperatorConfigNew, error)
}
if operatorCfgOld.ELSlasherAddress != "" || operatorCfgOld.BlsPublicKeyCompendiumAddress != "" {
fmt.Printf("%s Old config detected, migrating to new config\n", utils.EmojiCheckMark)
chainIDInt := operatorCfgOld.ChainId.Int64()
chainMetadata, ok := chainMetadataMap[chainIDInt]
if !ok {
return nil, fmt.Errorf("chain ID %d not supported", chainIDInt)
}
operatorCfg = types.OperatorConfigNew{
Operator: operatorCfgOld.Operator,
ELDelegationManager: operatorCfgOld.ELSlasherAddress, // How to get that?
ELDelegationManager: chainMetadata.ELDelegationManagerAddress, // How to get that?
EthRPCUrl: operatorCfgOld.EthRPCUrl,
PrivateKeyStorePath: operatorCfgOld.PrivateKeyStorePath,
SignerType: operatorCfgOld.SignerType,
Expand Down Expand Up @@ -191,19 +216,11 @@ func validateAndMigrateConfigFile(path string) (*types.OperatorConfigNew, error)
}

func getTransactionLink(txHash string, chainId *big.Int) string {
// Create chainId for eth and goerli
ethChainId := big.NewInt(1)
goerliChainId := big.NewInt(5)
holeskyChainId := big.NewInt(17000)

// Return link of chainId is a live network
if chainId.Cmp(ethChainId) == 0 {
return fmt.Sprintf("https://etherscan.io/tx/%s", txHash)
} else if chainId.Cmp(goerliChainId) == 0 {
return fmt.Sprintf("https://goerli.etherscan.io/tx/%s", txHash)
} else if chainId.Cmp(holeskyChainId) == 0 {
return fmt.Sprintf("https://holesky.etherscan.io/tx/%s", txHash)
} else {
chainIDInt := chainId.Int64()
chainMetadata, ok := chainMetadataMap[chainIDInt]
if !ok {
return txHash
} else {
return fmt.Sprintf("%s/%s", chainMetadata.BlockExplorerUrl, txHash)
}
}
50 changes: 50 additions & 0 deletions pkg/operator/register_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package operator

import (
"fmt"
"math/big"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetTransactionLink(t *testing.T) {
var tests = []struct {
name string
chainID *big.Int
txHash string
expectedTxLink string
}{
{
name: "Valid goerli tx hash",
chainID: big.NewInt(5),
txHash: "0x123",
expectedTxLink: fmt.Sprintf("%s/%s", "https://goerli.etherscan.io/tx", "0x123"),
},
{
name: "valid mainnet tx hash",
chainID: big.NewInt(1),
txHash: "0x123",
expectedTxLink: fmt.Sprintf("%s/%s", "https://etherscan.io/tx", "0x123"),
},
{
name: "valid holesky tx hash",
chainID: big.NewInt(17000),
txHash: "0x123",
expectedTxLink: fmt.Sprintf("%s/%s", "https://holesky.etherscan.io/tx", "0x123"),
},
{
name: "valid custom chain tx hash",
chainID: big.NewInt(100),
txHash: "0x123",
expectedTxLink: "0x123",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
txLink := getTransactionLink(tt.txHash, tt.chainID)
assert.Equal(t, tt.expectedTxLink, txLink)
})
}
}
4 changes: 4 additions & 0 deletions pkg/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ const (
EmojiWarning = "⚠️"
EmojiInfo = "ℹ️"
EmojiWait = "⏳"

GoerliChainId = 5
MainnetChainId = 1
HoleskyChainId = 17000
)

0 comments on commit 2eff3e4

Please sign in to comment.