mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-12 17:16:43 +00:00

* [NOD-275] Moved getBlockTemplate and related functionality to a separate file. * [NOD-275] Started moving handlers to separate files. * [NOD-275] Fixed merge errors. * [NOD-275] Moved all handlers out of rpcserver.go. * [NOD-275] Moved non-shared functions out of rpcserver.go. * [NOD-275] Moved handleGetAllManualNodesInfo to a separate file. * [NOD-275] Moved handlers out of rpcwebsocket.go to separate files. * [NOD-275] Fixed import error. * [NOD-275] Renamed all handler files to include underscores. * [NOD-275] Moved common rpc helper functions to common.go.
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package rpc
|
|
|
|
import (
|
|
"github.com/daglabs/btcd/btcjson"
|
|
"github.com/daglabs/btcd/config"
|
|
)
|
|
|
|
// handleSetGenerate implements the setGenerate command.
|
|
func handleSetGenerate(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
|
if config.MainConfig().SubnetworkID != nil {
|
|
return nil, &btcjson.RPCError{
|
|
Code: btcjson.ErrRPCInvalidRequest.Code,
|
|
Message: "`setGenerate` is not supported on partial nodes.",
|
|
}
|
|
}
|
|
|
|
c := cmd.(*btcjson.SetGenerateCmd)
|
|
|
|
// Disable generation regardless of the provided generate flag if the
|
|
// maximum number of threads (goroutines for our purposes) is 0.
|
|
// Otherwise enable or disable it depending on the provided flag.
|
|
generate := c.Generate
|
|
genProcLimit := -1
|
|
if c.GenProcLimit != nil {
|
|
genProcLimit = *c.GenProcLimit
|
|
}
|
|
if genProcLimit == 0 {
|
|
generate = false
|
|
}
|
|
|
|
if !generate {
|
|
s.cfg.CPUMiner.Stop()
|
|
} else {
|
|
// Respond with an error if there are no addresses to pay the
|
|
// created blocks to.
|
|
if len(config.MainConfig().MiningAddrs) == 0 {
|
|
return nil, &btcjson.RPCError{
|
|
Code: btcjson.ErrRPCInternal.Code,
|
|
Message: "No payment addresses specified " +
|
|
"via --miningaddr",
|
|
}
|
|
}
|
|
|
|
// It's safe to call start even if it's already started.
|
|
s.cfg.CPUMiner.SetNumWorkers(int32(genProcLimit))
|
|
s.cfg.CPUMiner.Start()
|
|
}
|
|
return nil, nil
|
|
}
|