aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-02-09 22:03:04 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-02-09 22:03:04 +0800
commitdda5af0e6ca3059649ff2ee36b92ab5acff20677 (patch)
tree6711f0644ab912368fbfe38527559189043577a3 /eth
parent8b5b635db7437b87259e10c442f6020443c07f47 (diff)
downloadgo-tangerine-dda5af0e6ca3059649ff2ee36b92ab5acff20677.tar
go-tangerine-dda5af0e6ca3059649ff2ee36b92ab5acff20677.tar.gz
go-tangerine-dda5af0e6ca3059649ff2ee36b92ab5acff20677.tar.bz2
go-tangerine-dda5af0e6ca3059649ff2ee36b92ab5acff20677.tar.lz
go-tangerine-dda5af0e6ca3059649ff2ee36b92ab5acff20677.tar.xz
go-tangerine-dda5af0e6ca3059649ff2ee36b92ab5acff20677.tar.zst
go-tangerine-dda5af0e6ca3059649ff2ee36b92ab5acff20677.zip
eth, miner: move the public miner api into eth to access etherbase
Diffstat (limited to 'eth')
-rw-r--r--eth/api.go52
-rw-r--r--eth/backend.go2
2 files changed, 53 insertions, 1 deletions
diff --git a/eth/api.go b/eth/api.go
index 526590589..09ae0c468 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -169,6 +169,58 @@ func (s *PublicEthereumAPI) Syncing() (interface{}, error) {
return false, nil
}
+// PublicMinerAPI provides an API to control the miner.
+// It offers only methods that operate on data that pose no security risk when it is publicly accessible.
+type PublicMinerAPI struct {
+ e *Ethereum
+ agent *miner.RemoteAgent
+}
+
+// NewPublicMinerAPI create a new PublicMinerAPI instance.
+func NewPublicMinerAPI(e *Ethereum) *PublicMinerAPI {
+ agent := miner.NewRemoteAgent()
+ e.Miner().Register(agent)
+
+ return &PublicMinerAPI{e, agent}
+}
+
+// Mining returns an indication if this node is currently mining.
+func (s *PublicMinerAPI) Mining() bool {
+ return s.e.IsMining()
+}
+
+// SubmitWork can be used by external miner to submit their POW solution. It returns an indication if the work was
+// accepted. Note, this is not an indication if the provided work was valid!
+func (s *PublicMinerAPI) SubmitWork(nonce rpc.HexNumber, solution, digest common.Hash) bool {
+ return s.agent.SubmitWork(nonce.Uint64(), digest, solution)
+}
+
+// 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
+func (s *PublicMinerAPI) GetWork() ([]string, error) {
+ if !s.e.IsMining() {
+ if err := s.e.StartMining(0, ""); err != nil {
+ return nil, err
+ }
+ }
+ if work, err := s.agent.GetWork(); err == nil {
+ return work[:], nil
+ } else {
+ glog.Infof("%v\n", err)
+ }
+ return nil, fmt.Errorf("mining not ready")
+}
+
+// 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 between nodes.
+func (s *PublicMinerAPI) SubmitHashrate(hashrate rpc.HexNumber, id common.Hash) bool {
+ s.agent.SubmitHashrate(id, hashrate.Uint64())
+ return true
+}
+
// PrivateMinerAPI provides private RPC methods to control the miner.
// These methods can be abused by external users and must be considered insecure for use by untrusted users.
type PrivateMinerAPI struct {
diff --git a/eth/backend.go b/eth/backend.go
index 352522f61..752a561d4 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -274,7 +274,7 @@ func (s *Ethereum) APIs() []rpc.API {
}, {
Namespace: "eth",
Version: "1.0",
- Service: miner.NewPublicMinerAPI(s.Miner()),
+ Service: NewPublicMinerAPI(s),
Public: true,
}, {
Namespace: "eth",