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