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