Browse Source

etherbase defaults to first account even if created during the session

zelig 10 years ago
parent
commit
1356daad27
2 changed files with 7 additions and 2 deletions
  1. 2 1
      cmd/geth/js_test.go
  2. 5 1
      eth/backend.go

+ 2 - 1
cmd/geth/js_test.go

@@ -159,7 +159,7 @@ func TestAccounts(t *testing.T) {
 	defer os.RemoveAll(tmp)
 
 	checkEvalJSON(t, repl, `eth.accounts`, `["`+testAddress+`"]`)
-	checkEvalJSON(t, repl, `eth.coinbase`, `null`)
+	checkEvalJSON(t, repl, `eth.coinbase`, `"`+testAddress+`"`)
 	val, err := repl.re.Run(`personal.newAccount("password")`)
 	if err != nil {
 		t.Errorf("expected no error, got %v", err)
@@ -170,6 +170,7 @@ func TestAccounts(t *testing.T) {
 	}
 
 	checkEvalJSON(t, repl, `eth.accounts`, `["`+testAddress+`","`+addr+`"]`)
+
 }
 
 func TestBlockChain(t *testing.T) {

+ 5 - 1
eth/backend.go

@@ -489,7 +489,11 @@ func (s *Ethereum) StartMining(threads int) error {
 func (s *Ethereum) Etherbase() (eb common.Address, err error) {
 	eb = s.etherbase
 	if (eb == common.Address{}) {
-		err = fmt.Errorf("etherbase address must be explicitly specified")
+		addr, e := s.AccountManager().AddressByIndex(0)
+		if e != nil {
+			err = fmt.Errorf("etherbase address must be explicitly specified")
+		}
+		eb = common.HexToAddress(addr)
 	}
 	return
 }