Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #158 from pascaldekloe/organise
Browse files Browse the repository at this point in the history
Organise
  • Loading branch information
pascaldekloe authored Mar 9, 2017
2 parents e4c6f35 + 812d812 commit 1f9eaca
Show file tree
Hide file tree
Showing 26 changed files with 259 additions and 645 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ os: Visual Studio 2015
environment:
GOPATH: c:\gopath
install:
- git describe > version.txt
- git describe --tags > version.txt
- set /p VERSION=<version.txt
- echo %VERSION%
- echo %PATH%
Expand All @@ -15,7 +15,7 @@ install:
- go get golang.org/x/sys/windows
build_script:
- go test ./...
- go build -ldflags -Xmain.Version="%VERSION% ./cmd/geth
- go build -ldflags "-X main.Version=%VERSION%" ./cmd/geth
artifacts:
- path: geth.exe
name: geth
Expand Down
18 changes: 9 additions & 9 deletions cmd/bootnode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"crypto/ecdsa"
"flag"
"fmt"
"log"
"os"

"github.com/ethereumproject/go-ethereum/cmd/utils"
"github.com/ethereumproject/go-ethereum/crypto"
"github.com/ethereumproject/go-ethereum/logger/glog"
"github.com/ethereumproject/go-ethereum/p2p/discover"
Expand Down Expand Up @@ -57,41 +57,41 @@ func main() {
if *genKey != "" {
key, err := crypto.GenerateKey()
if err != nil {
utils.Fatalf("could not generate key: %v", err)
log.Fatalf("could not generate key: %s", err)
}
if err := crypto.SaveECDSA(*genKey, key); err != nil {
utils.Fatalf("%v", err)
log.Fatal(err)
}
os.Exit(0)
}

natm, err := nat.Parse(*natdesc)
if err != nil {
utils.Fatalf("-nat: %v", err)
log.Fatalf("nat: %s", err)
}

var nodeKey *ecdsa.PrivateKey
switch {
case *nodeKeyFile == "" && *nodeKeyHex == "":
utils.Fatalf("Use -nodekey or -nodekeyhex to specify a private key")
log.Fatal("Use -nodekey or -nodekeyhex to specify a private key")
case *nodeKeyFile != "" && *nodeKeyHex != "":
utils.Fatalf("Options -nodekey and -nodekeyhex are mutually exclusive")
log.Fatal("Options -nodekey and -nodekeyhex are mutually exclusive")
case *nodeKeyFile != "":
var err error
nodeKey, err = crypto.LoadECDSA(*nodeKeyFile)
if err != nil {
utils.Fatalf("-nodekey: %v", err)
log.Fatalf("nodekey: %s", err)
}
case *nodeKeyHex != "":
var err error
nodeKey, err = crypto.HexToECDSA(*nodeKeyHex)
if err != nil {
utils.Fatalf("-nodekeyhex: %v", err)
log.Fatalf("nodekeyhex: %s", err)
}
}

if _, err := discover.ListenUDP(nodeKey, *listenAddr, natm, ""); err != nil {
utils.Fatalf("%v", err)
log.Fatal(err)
}
select {}
}
50 changes: 25 additions & 25 deletions cmd/geth/accountcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package main
import (
"fmt"
"io/ioutil"
"log"

"github.com/ethereumproject/go-ethereum/accounts"
"github.com/ethereumproject/go-ethereum/cmd/utils"
"github.com/ethereumproject/go-ethereum/console"
"github.com/ethereumproject/go-ethereum/crypto"
"github.com/ethereumproject/go-ethereum/logger"
Expand Down Expand Up @@ -168,7 +168,7 @@ nodes.
)

func accountList(ctx *cli.Context) error {
accman := utils.MakeAccountManager(ctx)
accman := MakeAccountManager(ctx)
for i, acct := range accman.Accounts() {
fmt.Printf("Account #%d: {%x} %s\n", i, acct.Address, acct.File)
}
Expand All @@ -177,9 +177,9 @@ func accountList(ctx *cli.Context) error {

// tries unlocking the specified account a few times.
func unlockAccount(ctx *cli.Context, accman *accounts.Manager, address string, i int, passwords []string) (accounts.Account, string) {
account, err := utils.MakeAddress(accman, address)
account, err := MakeAddress(accman, address)
if err != nil {
utils.Fatalf("Could not list accounts: %v", err)
log.Fatal("Could not list accounts: ", err)
}
for trials := 0; trials < 3; trials++ {
prompt := fmt.Sprintf("Unlocking account %s | Attempt %d/%d", address, trials+1, 3)
Expand All @@ -199,7 +199,7 @@ func unlockAccount(ctx *cli.Context, accman *accounts.Manager, address string, i
}
}
// All trials expended to unlock account, bail out
utils.Fatalf("Failed to unlock account %s (%v)", address, err)
log.Fatalf("Failed to unlock account %s (%v)", address, err)
return accounts.Account{}, ""
}

Expand All @@ -219,15 +219,15 @@ func getPassPhrase(prompt string, confirmation bool, i int, passwords []string)
}
password, err := console.Stdin.PromptPassword("Passphrase: ")
if err != nil {
utils.Fatalf("Failed to read passphrase: %v", err)
log.Fatal("Failed to read passphrase: ", err)
}
if confirmation {
confirm, err := console.Stdin.PromptPassword("Repeat passphrase: ")
if err != nil {
utils.Fatalf("Failed to read passphrase confirmation: %v", err)
log.Fatalf("Failed to read passphrase confirmation: ", err)
}
if password != confirm {
utils.Fatalf("Passphrases do not match")
log.Fatal("Passphrases do not match")
}
}
return password
Expand All @@ -247,7 +247,7 @@ func ambiguousAddrRecovery(am *accounts.Manager, err *accounts.AmbiguousAddrErro
}
}
if match == nil {
utils.Fatalf("None of the listed files could be unlocked.")
log.Fatal("None of the listed files could be unlocked.")
}
fmt.Printf("Your passphrase unlocked %s\n", match.File)
fmt.Println("In order to avoid this warning, you need to remove the following duplicate key files:")
Expand All @@ -261,12 +261,12 @@ func ambiguousAddrRecovery(am *accounts.Manager, err *accounts.AmbiguousAddrErro

// accountCreate creates a new account into the keystore defined by the CLI flags.
func accountCreate(ctx *cli.Context) error {
accman := utils.MakeAccountManager(ctx)
password := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx))
accman := MakeAccountManager(ctx)
password := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, MakePasswordList(ctx))

account, err := accman.NewAccount(password)
if err != nil {
utils.Fatalf("Failed to create account: %v", err)
log.Fatal("Failed to create account: ", err)
}
fmt.Printf("Address: {%x}\n", account.Address)
return nil
Expand All @@ -276,34 +276,34 @@ func accountCreate(ctx *cli.Context) error {
// one, also providing the possibility to change the pass-phrase.
func accountUpdate(ctx *cli.Context) error {
if len(ctx.Args()) == 0 {
utils.Fatalf("No accounts specified to update")
log.Fatal("No accounts specified to update")
}
accman := utils.MakeAccountManager(ctx)
accman := MakeAccountManager(ctx)

account, oldPassword := unlockAccount(ctx, accman, ctx.Args().First(), 0, nil)
newPassword := getPassPhrase("Please give a new password. Do not forget this password.", true, 0, nil)
if err := accman.Update(account, oldPassword, newPassword); err != nil {
utils.Fatalf("Could not update the account: %v", err)
log.Fatal("Could not update the account: ", err)
}
return nil
}

func importWallet(ctx *cli.Context) error {
keyfile := ctx.Args().First()
if len(keyfile) == 0 {
utils.Fatalf("keyfile must be given as argument")
log.Fatal("keyfile must be given as argument")
}
keyJson, err := ioutil.ReadFile(keyfile)
if err != nil {
utils.Fatalf("Could not read wallet file: %v", err)
log.Fatal("Could not read wallet file: ", err)
}

accman := utils.MakeAccountManager(ctx)
passphrase := getPassPhrase("", false, 0, utils.MakePasswordList(ctx))
accman := MakeAccountManager(ctx)
passphrase := getPassPhrase("", false, 0, MakePasswordList(ctx))

acct, err := accman.ImportPreSaleKey(keyJson, passphrase)
if err != nil {
utils.Fatalf("%v", err)
log.Fatal(err)
}
fmt.Printf("Address: {%x}\n", acct.Address)
return nil
Expand All @@ -312,17 +312,17 @@ func importWallet(ctx *cli.Context) error {
func accountImport(ctx *cli.Context) error {
keyfile := ctx.Args().First()
if len(keyfile) == 0 {
utils.Fatalf("keyfile must be given as argument")
log.Fatal("keyfile must be given as argument")
}
key, err := crypto.LoadECDSA(keyfile)
if err != nil {
utils.Fatalf("keyfile must be given as argument")
log.Fatal("keyfile must be given as argument")
}
accman := utils.MakeAccountManager(ctx)
passphrase := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx))
accman := MakeAccountManager(ctx)
passphrase := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, MakePasswordList(ctx))
acct, err := accman.ImportECDSA(key, passphrase)
if err != nil {
utils.Fatalf("Could not create the account: %v", err)
log.Fatal("Could not create the account: ", err)
}
fmt.Printf("Address: {%x}\n", acct.Address)
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/bootnodes.go → cmd/geth/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.

package utils
package main

import "github.com/ethereumproject/go-ethereum/p2p/discover"

Expand Down
64 changes: 32 additions & 32 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package main

import (
"fmt"
"log"
"os"
"path/filepath"
"strconv"
"time"

"github.com/ethereumproject/go-ethereum/cmd/utils"
"github.com/ethereumproject/go-ethereum/common"
"github.com/ethereumproject/go-ethereum/console"
"github.com/ethereumproject/go-ethereum/core"
Expand Down Expand Up @@ -73,61 +73,61 @@ Use "ethereum dump 0" to dump the genesis block.

func importChain(ctx *cli.Context) error {
if len(ctx.Args()) != 1 {
utils.Fatalf("This command requires an argument.")
log.Fatal("This command requires an argument.")
}
chain, chainDb := utils.MakeChain(ctx)
chain, chainDb := MakeChain(ctx)
start := time.Now()
err := utils.ImportChain(chain, ctx.Args().First())
err := ImportChain(chain, ctx.Args().First())
chainDb.Close()
if err != nil {
utils.Fatalf("Import error: %v", err)
log.Fatal("Import error: ", err)
}
fmt.Printf("Import done in %v", time.Since(start))
return nil
}

func exportChain(ctx *cli.Context) error {
if len(ctx.Args()) < 1 {
utils.Fatalf("This command requires an argument.")
log.Fatal("This command requires an argument.")
}
chain, _ := utils.MakeChain(ctx)
chain, _ := MakeChain(ctx)
start := time.Now()

var err error
fp := ctx.Args().First()
if len(ctx.Args()) < 3 {
err = utils.ExportChain(chain, fp)
if err := ExportChain(chain, fp); err != nil {
log.Fatal(err)
}
} else {
// This can be improved to allow for numbers larger than 9223372036854775807
first, ferr := strconv.ParseInt(ctx.Args().Get(1), 10, 64)
last, lerr := strconv.ParseInt(ctx.Args().Get(2), 10, 64)
if ferr != nil || lerr != nil {
utils.Fatalf("Export error in parsing parameters: block number not an integer\n")
first, err := strconv.ParseUint(ctx.Args().Get(1), 10, 64)
if err != nil {
log.Fatal("export paramater: ", err)
}
last, err := strconv.ParseUint(ctx.Args().Get(2), 10, 64)
if err != nil {
log.Fatal("export paramater: ", err)
}
if first < 0 || last < 0 {
utils.Fatalf("Export error: block number must be greater than 0\n")
if err = ExportAppendChain(chain, fp, first, last); err != nil {
log.Fatal(err)
}
err = utils.ExportAppendChain(chain, fp, uint64(first), uint64(last))
}

if err != nil {
utils.Fatalf("Export error: %v\n", err)
}
fmt.Printf("Export done in %v", time.Since(start))
return nil
}

func removeDB(ctx *cli.Context) error {
confirm, err := console.Stdin.PromptConfirm("Remove local database?")
if err != nil {
utils.Fatalf("%v", err)
log.Fatal(err)
}

if confirm {
fmt.Println("Removing chaindata...")
start := time.Now()

os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "chaindata"))
os.RemoveAll(filepath.Join(ctx.GlobalString(DataDirFlag.Name), "chaindata"))

fmt.Printf("Removed in %v\n", time.Since(start))
} else {
Expand All @@ -139,28 +139,28 @@ func removeDB(ctx *cli.Context) error {
func upgradeDB(ctx *cli.Context) error {
glog.Infoln("Upgrading blockchain database")

chain, chainDb := utils.MakeChain(ctx)
chain, chainDb := MakeChain(ctx)
bcVersion := core.GetBlockChainVersion(chainDb)
if bcVersion == 0 {
bcVersion = core.BlockChainVersion
}

// Export the current chain.
filename := fmt.Sprintf("blockchain_%d_%s.chain", bcVersion, time.Now().Format("20060102_150405"))
exportFile := filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), filename)
if err := utils.ExportChain(chain, exportFile); err != nil {
utils.Fatalf("Unable to export chain for reimport %s", err)
exportFile := filepath.Join(ctx.GlobalString(DataDirFlag.Name), filename)
if err := ExportChain(chain, exportFile); err != nil {
log.Fatal("Unable to export chain for reimport ", err)
}
chainDb.Close()
os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "chaindata"))
os.RemoveAll(filepath.Join(ctx.GlobalString(DataDirFlag.Name), "chaindata"))

// Import the chain file.
chain, chainDb = utils.MakeChain(ctx)
chain, chainDb = MakeChain(ctx)
core.WriteBlockChainVersion(chainDb, core.BlockChainVersion)
err := utils.ImportChain(chain, exportFile)
err := ImportChain(chain, exportFile)
chainDb.Close()
if err != nil {
utils.Fatalf("Import error %v (a backup is made in %s, use the import command to import it)", err, exportFile)
log.Fatalf("Import error %v (a backup is made in %s, use the import command to import it)", err, exportFile)
} else {
os.Remove(exportFile)
glog.Infoln("Import finished")
Expand All @@ -169,7 +169,7 @@ func upgradeDB(ctx *cli.Context) error {
}

func dump(ctx *cli.Context) error {
chain, chainDb := utils.MakeChain(ctx)
chain, chainDb := MakeChain(ctx)
for _, arg := range ctx.Args() {
var block *types.Block
if hashish(arg) {
Expand All @@ -180,11 +180,11 @@ func dump(ctx *cli.Context) error {
}
if block == nil {
fmt.Println("{}")
utils.Fatalf("block not found")
log.Fatal("block not found")
} else {
state, err := state.New(block.Root(), chainDb)
if err != nil {
utils.Fatalf("could not create new state: %v", err)
log.Fatal("could not create new state: ", err)
}
fmt.Printf("%s\n", state.Dump())
}
Expand Down
Loading

0 comments on commit 1f9eaca

Please sign in to comment.