From 6df1de81d8add4be2cffa9f2ce62858ae69d3dea Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Fri, 16 Oct 2020 11:47:53 -0500 Subject: [PATCH 1/2] derive contract addr --- cmd/deriveContract.go | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 cmd/deriveContract.go diff --git a/cmd/deriveContract.go b/cmd/deriveContract.go new file mode 100644 index 0000000..c2814e4 --- /dev/null +++ b/cmd/deriveContract.go @@ -0,0 +1,66 @@ +// Copyright © 2020 Vulcanize, Inc +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package cmd + +import ( + "fmt" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// keyGenCmd represents the keyGen command +var deriveContractCmd = &cobra.Command{ + Use: "deriveContract", + Short: "Derive contract address", + Long: `Derive the contract address created from an pubkey/address and nonce`, + Run: func(cmd *cobra.Command, args []string) { + deriveContract() + }, +} + +func deriveContract() { + // and their .toml config bindings + nonce := viper.GetUint64("keyGen.nonce") + addrStr := viper.GetString("keyGen.address") + var addr common.Address + if addrStr == "" { + keyPath := viper.GetString("keyGen.path") + key, err := crypto.LoadECDSA(keyPath) + if err != nil { + logWithCommand.Fatal(err) + } + addr = crypto.PubkeyToAddress(key.PublicKey) + } else { + addr = common.HexToAddress(addrStr) + } + contractAddr := crypto.CreateAddress(addr, nonce) + fmt.Println(contractAddr.Hex()) +} + +func init() { + rootCmd.AddCommand(keyGenCmd) + + keyGenCmd.PersistentFlags().Uint64("nonce", 0, "nonce to derive contract address from") + keyGenCmd.PersistentFlags().String("key-path", "", "path to public key to derive contract address from") + keyGenCmd.PersistentFlags().String("address", "", "address to derive contract address from") + + viper.BindPFlag("keyGen.nonce", keyGenCmd.PersistentFlags().Lookup("nonce")) + viper.BindPFlag("keyGen.path", keyGenCmd.PersistentFlags().Lookup("key-path")) + viper.BindPFlag("keyGen.address", keyGenCmd.PersistentFlags().Lookup("address")) +} From 25a79b0f50b40621bc16d250fb9387dbd0ad8c6c Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 19 Oct 2020 12:17:19 -0500 Subject: [PATCH 2/2] on main --- .github/workflows/{on-master.yml => on-main.yml} | 2 +- {environment => environments}/example.toml | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{on-master.yml => on-main.yml} (98%) rename {environment => environments}/example.toml (100%) diff --git a/.github/workflows/on-master.yml b/.github/workflows/on-main.yml similarity index 98% rename from .github/workflows/on-master.yml rename to .github/workflows/on-main.yml index 453da5d..b95433b 100644 --- a/.github/workflows/on-master.yml +++ b/.github/workflows/on-main.yml @@ -3,7 +3,7 @@ name: Docker Compose Build on: push: branches: - - master + - main jobs: build: diff --git a/environment/example.toml b/environments/example.toml similarity index 100% rename from environment/example.toml rename to environments/example.toml