Commit 31886222 authored by 王志文's avatar 王志文 Committed by vipwzw

eth private key to address

parent 7cc0d1c3
......@@ -49,3 +49,5 @@ build/sendstock.toml
build/*.csv
build/CHANGELOG.md
plugin/dapp/dex/boss/build/
plugin/dapp/bridgevmxgo/cmd/build/bridgevmxgo/
plugin/dapp/bridgevmxgo/cmd/build/dapptest/
......@@ -7,11 +7,13 @@ import (
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common"
chain33Common "github.com/33cn/chain33/common"
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes "github.com/33cn/chain33/rpc/types"
ebTypes "github.com/33cn/plugin/plugin/dapp/cross2eth/ebrelayer/types"
"github.com/33cn/plugin/plugin/dapp/cross2eth/ebrelayer/utils"
ethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/spf13/cobra"
)
......@@ -26,6 +28,7 @@ func EthereumRelayerCmd() *cobra.Command {
cmd.AddCommand(
ImportEthPrivateKeyCmd(),
GenEthPrivateKeyCmd(),
GetAddressFromPrivateKeyCmd(),
ShowValidatorsAddrCmd(),
ShowChain33TxsHashCmd(),
IsValidatorActiveCmd(),
......@@ -168,6 +171,34 @@ func importEthereumPrivatekey(cmd *cobra.Command, args []string) {
ctx.Run()
}
func GetAddressFromPrivateKeyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "get_eth_addr",
Short: "get addr from private key",
Run: getAddressFromPrivateKey,
}
cmd.Flags().StringP("key", "k", "", "ethereum private key")
_ = cmd.MarkFlagRequired("key")
return cmd
}
func getAddressFromPrivateKey(cmd *cobra.Command, args []string) {
key, _ := cmd.Flags().GetString("key")
privateKeySlice, err := chain33Common.FromHex(key)
if nil != err {
fmt.Println("private key error: ", err)
return
}
privateKey, err := crypto.ToECDSA(privateKeySlice)
if nil != err {
fmt.Println("private key error: ", err)
return
}
addr := crypto.PubkeyToAddress(privateKey.PublicKey)
fmt.Println("addr: ", addr)
}
//GenEthPrivateKeyCmd ...
func GenEthPrivateKeyCmd() *cobra.Command {
cmd := &cobra.Command{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment