2020-08-12 13:47:59 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
2021-03-23 09:00:07 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/common/hexutil"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/core/types"
|
2020-08-12 13:47:59 +00:00
|
|
|
)
|
|
|
|
|
2020-10-24 17:03:52 +00:00
|
|
|
// Coinbase implements eth_coinbase. Returns the current client coinbase address.
|
2021-03-23 09:00:07 +00:00
|
|
|
func (api *APIImpl) Coinbase(ctx context.Context) (common.Address, error) {
|
|
|
|
return api.ethBackend.Etherbase(ctx)
|
2020-08-12 13:47:59 +00:00
|
|
|
}
|
2020-10-12 08:39:33 +00:00
|
|
|
|
2020-10-24 17:03:52 +00:00
|
|
|
// Hashrate implements eth_hashrate. Returns the number of hashes per second that the node is mining with.
|
2021-03-23 09:00:07 +00:00
|
|
|
func (api *APIImpl) Hashrate(ctx context.Context) (uint64, error) {
|
|
|
|
return api.ethBackend.GetHashRate(ctx)
|
2020-10-14 15:59:42 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 09:00:07 +00:00
|
|
|
// Mining returns an indication if this node is currently mining.
|
|
|
|
func (api *APIImpl) Mining(ctx context.Context) (bool, error) {
|
|
|
|
return api.ethBackend.Mining(ctx)
|
2020-10-14 15:59:42 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 09:00:07 +00:00
|
|
|
// GetWork returns a work package for external miner.
|
|
|
|
//
|
|
|
|
// The work package consists of 3 strings:
|
|
|
|
// result[0] - 32 bytes hex encoded current block header pow-hash
|
|
|
|
// result[1] - 32 bytes hex encoded seed hash used for DAG
|
|
|
|
// result[2] - 32 bytes hex encoded boundary condition ("target"), 2^256/difficulty
|
|
|
|
// result[3] - hex encoded block number
|
|
|
|
func (api *APIImpl) GetWork(ctx context.Context) ([4]string, error) {
|
|
|
|
return api.ethBackend.GetWork(ctx)
|
2020-10-14 15:59:42 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 09:00:07 +00:00
|
|
|
// SubmitWork can be used by external miner to submit their POW solution.
|
|
|
|
// It returns an indication if the work was accepted.
|
|
|
|
// Note either an invalid solution, a stale work a non-existent work will return false.
|
|
|
|
func (api *APIImpl) SubmitWork(ctx context.Context, nonce types.BlockNonce, powHash, digest common.Hash) (bool, error) {
|
|
|
|
return api.ethBackend.SubmitWork(ctx, nonce, powHash, digest)
|
2020-10-14 15:59:42 +00:00
|
|
|
}
|
2020-10-12 08:39:33 +00:00
|
|
|
|
2021-03-23 09:00:07 +00:00
|
|
|
// SubmitHashrate can be used for remote miners to submit their hash rate.
|
|
|
|
// This enables the node to report the combined hash rate of all miners
|
|
|
|
// which submit work through this node.
|
|
|
|
//
|
|
|
|
// It accepts the miner hash rate and an identifier which must be unique
|
|
|
|
func (api *APIImpl) SubmitHashrate(ctx context.Context, hashRate hexutil.Uint64, id common.Hash) (bool, error) {
|
|
|
|
return api.ethBackend.SubmitHashRate(ctx, hashRate, id)
|
2020-10-14 15:59:42 +00:00
|
|
|
}
|