2015-10-15 09:07:19 -05:00
|
|
|
// Copyright 2015 The go-ethereum Authors
|
2016-04-14 11:18:24 -05:00
|
|
|
// This file is part of the go-ethereum library.
|
2015-10-15 09:07:19 -05:00
|
|
|
//
|
2016-04-14 11:18:24 -05:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
2015-10-15 09:07:19 -05:00
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
2016-04-14 11:18:24 -05:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
2015-10-15 09:07:19 -05:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2016-04-14 11:18:24 -05:00
|
|
|
// GNU Lesser General Public License for more details.
|
2015-10-15 09:07:19 -05:00
|
|
|
//
|
2016-04-14 11:18:24 -05:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-10-15 09:07:19 -05:00
|
|
|
|
|
|
|
package eth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2016-12-17 08:39:55 -06:00
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
2015-10-15 09:07:19 -05:00
|
|
|
)
|
|
|
|
|
2022-06-21 04:05:43 -05:00
|
|
|
// EthereumAPI provides an API to access Ethereum full node-related information.
|
|
|
|
type EthereumAPI struct {
|
2016-06-30 05:03:26 -05:00
|
|
|
e *Ethereum
|
2016-01-27 10:01:30 -06:00
|
|
|
}
|
|
|
|
|
2022-06-21 04:05:43 -05:00
|
|
|
// NewEthereumAPI creates a new Ethereum protocol API for full nodes.
|
|
|
|
func NewEthereumAPI(e *Ethereum) *EthereumAPI {
|
|
|
|
return &EthereumAPI{e}
|
2015-10-15 09:07:19 -05:00
|
|
|
}
|
|
|
|
|
2022-06-15 02:29:23 -05:00
|
|
|
// Etherbase is the address that mining rewards will be send to.
|
2022-06-21 04:05:43 -05:00
|
|
|
func (api *EthereumAPI) Etherbase() (common.Address, error) {
|
2017-04-04 17:16:29 -05:00
|
|
|
return api.e.Etherbase()
|
2015-10-15 09:07:19 -05:00
|
|
|
}
|
|
|
|
|
2022-06-15 02:29:23 -05:00
|
|
|
// Coinbase is the address that mining rewards will be send to (alias for Etherbase).
|
2022-06-21 04:05:43 -05:00
|
|
|
func (api *EthereumAPI) Coinbase() (common.Address, error) {
|
2017-04-04 17:16:29 -05:00
|
|
|
return api.Etherbase()
|
2015-10-15 09:07:19 -05:00
|
|
|
}
|
|
|
|
|
2022-06-15 02:29:23 -05:00
|
|
|
// Hashrate returns the POW hashrate.
|
2022-06-21 04:05:43 -05:00
|
|
|
func (api *EthereumAPI) Hashrate() hexutil.Uint64 {
|
2021-04-29 04:02:30 -05:00
|
|
|
return hexutil.Uint64(api.e.Miner().Hashrate())
|
|
|
|
}
|
|
|
|
|
2016-02-09 08:03:04 -06:00
|
|
|
// Mining returns an indication if this node is currently mining.
|
2022-06-21 04:05:43 -05:00
|
|
|
func (api *EthereumAPI) Mining() bool {
|
2017-04-04 17:16:29 -05:00
|
|
|
return api.e.IsMining()
|
2016-02-09 08:03:04 -06:00
|
|
|
}
|