forked from cerc-io/plugeth
settable etherbase
- etherbase flag for block reward destination - coinbase => etherbase - CLI- eth Config -> eth, xeth -> RPC / Miner - use primary instead of coinbase as the unlock magic wildcard - accounts: firstAddr/Coinbase -> Primary
This commit is contained in:
parent
b0b0939879
commit
b375bbee5f
@ -81,13 +81,7 @@ func (am *Manager) HasAccount(addr []byte) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Coinbase returns the account address that mining rewards are sent to.
|
func (am *Manager) Primary() (addr []byte, err error) {
|
||||||
func (am *Manager) Coinbase() (addr []byte, err error) {
|
|
||||||
// TODO: persist coinbase address on disk
|
|
||||||
return am.firstAddr()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (am *Manager) firstAddr() ([]byte, error) {
|
|
||||||
addrs, err := am.keyStore.GetKeyAddresses()
|
addrs, err := am.keyStore.GetKeyAddresses()
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil, ErrNoKeys
|
return nil, ErrNoKeys
|
||||||
|
@ -221,6 +221,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
|
|||||||
utils.LogJSONFlag,
|
utils.LogJSONFlag,
|
||||||
utils.LogLevelFlag,
|
utils.LogLevelFlag,
|
||||||
utils.MaxPeersFlag,
|
utils.MaxPeersFlag,
|
||||||
|
utils.EtherbaseFlag,
|
||||||
utils.MinerThreadsFlag,
|
utils.MinerThreadsFlag,
|
||||||
utils.MiningEnabledFlag,
|
utils.MiningEnabledFlag,
|
||||||
utils.NATFlag,
|
utils.NATFlag,
|
||||||
@ -322,10 +323,10 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) {
|
|||||||
|
|
||||||
account := ctx.GlobalString(utils.UnlockedAccountFlag.Name)
|
account := ctx.GlobalString(utils.UnlockedAccountFlag.Name)
|
||||||
if len(account) > 0 {
|
if len(account) > 0 {
|
||||||
if account == "coinbase" {
|
if account == "primary" {
|
||||||
accbytes, err := am.Coinbase()
|
accbytes, err := am.Primary()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("no coinbase account: %v", err)
|
utils.Fatalf("no primary account: %v", err)
|
||||||
}
|
}
|
||||||
account = common.ToHex(accbytes)
|
account = common.ToHex(accbytes)
|
||||||
}
|
}
|
||||||
@ -468,7 +469,6 @@ func dump(ctx *cli.Context) {
|
|||||||
} else {
|
} else {
|
||||||
statedb := state.New(block.Root(), stateDb)
|
statedb := state.New(block.Root(), stateDb)
|
||||||
fmt.Printf("%s\n", statedb.Dump())
|
fmt.Printf("%s\n", statedb.Dump())
|
||||||
// fmt.Println(block)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,10 +96,15 @@ var (
|
|||||||
Name: "mine",
|
Name: "mine",
|
||||||
Usage: "Enable mining",
|
Usage: "Enable mining",
|
||||||
}
|
}
|
||||||
|
EtherbaseFlag = cli.StringFlag{
|
||||||
|
Name: "Etherbase",
|
||||||
|
Usage: "public address for block mining rewards. By default the address of your primary account is used",
|
||||||
|
Value: "primary",
|
||||||
|
}
|
||||||
|
|
||||||
UnlockedAccountFlag = cli.StringFlag{
|
UnlockedAccountFlag = cli.StringFlag{
|
||||||
Name: "unlock",
|
Name: "unlock",
|
||||||
Usage: "unlock the account given until this program exits (prompts for password). '--unlock coinbase' unlocks the primary (coinbase) account",
|
Usage: "unlock the account given until this program exits (prompts for password). '--unlock primary' unlocks the primary account",
|
||||||
Value: "",
|
Value: "",
|
||||||
}
|
}
|
||||||
PasswordFileFlag = cli.StringFlag{
|
PasswordFileFlag = cli.StringFlag{
|
||||||
@ -215,6 +220,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
|
|||||||
LogFile: ctx.GlobalString(LogFileFlag.Name),
|
LogFile: ctx.GlobalString(LogFileFlag.Name),
|
||||||
LogLevel: ctx.GlobalInt(LogLevelFlag.Name),
|
LogLevel: ctx.GlobalInt(LogLevelFlag.Name),
|
||||||
LogJSON: ctx.GlobalString(LogJSONFlag.Name),
|
LogJSON: ctx.GlobalString(LogJSONFlag.Name),
|
||||||
|
Etherbase: ctx.GlobalString(EtherbaseFlag.Name),
|
||||||
MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name),
|
MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name),
|
||||||
AccountManager: GetAccountManager(ctx),
|
AccountManager: GetAccountManager(ctx),
|
||||||
VmDebug: ctx.GlobalBool(VMDebugFlag.Name),
|
VmDebug: ctx.GlobalBool(VMDebugFlag.Name),
|
||||||
|
@ -63,6 +63,7 @@ type Config struct {
|
|||||||
Shh bool
|
Shh bool
|
||||||
Dial bool
|
Dial bool
|
||||||
|
|
||||||
|
Etherbase string
|
||||||
MinerThreads int
|
MinerThreads int
|
||||||
AccountManager *accounts.Manager
|
AccountManager *accounts.Manager
|
||||||
|
|
||||||
@ -140,6 +141,7 @@ type Ethereum struct {
|
|||||||
|
|
||||||
Mining bool
|
Mining bool
|
||||||
DataDir string
|
DataDir string
|
||||||
|
etherbase common.Address
|
||||||
clientVersion string
|
clientVersion string
|
||||||
ethVersionId int
|
ethVersionId int
|
||||||
netVersionId int
|
netVersionId int
|
||||||
@ -185,6 +187,7 @@ func New(config *Config) (*Ethereum, error) {
|
|||||||
eventMux: &event.TypeMux{},
|
eventMux: &event.TypeMux{},
|
||||||
accountManager: config.AccountManager,
|
accountManager: config.AccountManager,
|
||||||
DataDir: config.DataDir,
|
DataDir: config.DataDir,
|
||||||
|
etherbase: common.HexToAddress(config.Etherbase),
|
||||||
clientVersion: config.Name, // TODO should separate from Name
|
clientVersion: config.Name, // TODO should separate from Name
|
||||||
ethVersionId: config.ProtocolVersion,
|
ethVersionId: config.ProtocolVersion,
|
||||||
netVersionId: config.NetworkId,
|
netVersionId: config.NetworkId,
|
||||||
@ -297,15 +300,31 @@ func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Ethereum) StartMining() error {
|
func (s *Ethereum) StartMining() error {
|
||||||
cb, err := s.accountManager.Coinbase()
|
eb, err := s.Etherbase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
servlogger.Errorf("Cannot start mining without coinbase: %v\n", err)
|
err = fmt.Errorf("Cannot start mining without etherbase address: %v", err)
|
||||||
return fmt.Errorf("no coinbase: %v", err)
|
servlogger.Errorln(err)
|
||||||
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
s.miner.Start(common.BytesToAddress(cb))
|
|
||||||
|
s.miner.Start(eb)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Ethereum) Etherbase() (eb common.Address, err error) {
|
||||||
|
eb = s.etherbase
|
||||||
|
if (eb == common.Address{}) {
|
||||||
|
var ebbytes []byte
|
||||||
|
ebbytes, err = s.accountManager.Primary()
|
||||||
|
eb = common.BytesToAddress(ebbytes)
|
||||||
|
if (eb == common.Address{}) {
|
||||||
|
err = fmt.Errorf("no accounts found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Ethereum) StopMining() { s.miner.Stop() }
|
func (s *Ethereum) StopMining() { s.miner.Stop() }
|
||||||
func (s *Ethereum) IsMining() bool { return s.miner.Mining() }
|
func (s *Ethereum) IsMining() bool { return s.miner.Mining() }
|
||||||
func (s *Ethereum) Miner() *miner.Miner { return s.miner }
|
func (s *Ethereum) Miner() *miner.Miner { return s.miner }
|
||||||
|
@ -250,8 +250,8 @@ func (self *XEth) IsListening() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *XEth) Coinbase() string {
|
func (self *XEth) Coinbase() string {
|
||||||
cb, _ := self.backend.AccountManager().Coinbase()
|
eb, _ := self.backend.Etherbase()
|
||||||
return common.ToHex(cb)
|
return eb.Hex()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *XEth) NumberToHuman(balance string) string {
|
func (self *XEth) NumberToHuman(balance string) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user