mirror of
https://github.com/kvazar-network/keva-stratum.git
synced 2025-01-11 15:48:00 +00:00
Tidy up handlers
This commit is contained in:
parent
39b176367a
commit
9c4a41923e
@ -17,7 +17,7 @@ func init() {
|
|||||||
noncePattern, _ = regexp.Compile("^[0-9a-f]{8}$")
|
noncePattern, _ = regexp.Compile("^[0-9a-f]{8}$")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StratumServer) handleLoginRPC(cs *Session, e *Endpoint, params *LoginParams) (*JobReply, *ErrorReply) {
|
func (s *StratumServer) handleLoginRPC(cs *Session, params *LoginParams) (*JobReply, *ErrorReply) {
|
||||||
if !s.config.BypassAddressValidation && !util.ValidateAddress(params.Login, s.config.Address) {
|
if !s.config.BypassAddressValidation && !util.ValidateAddress(params.Login, s.config.Address) {
|
||||||
return nil, &ErrorReply{Code: -1, Message: "Invalid address used for login"}
|
return nil, &ErrorReply{Code: -1, Message: "Invalid address used for login"}
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ func (s *StratumServer) handleLoginRPC(cs *Session, e *Endpoint, params *LoginPa
|
|||||||
return &JobReply{Id: id, Job: cs.getJob(t), Status: "OK"}, nil
|
return &JobReply{Id: id, Job: cs.getJob(t), Status: "OK"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StratumServer) handleGetJobRPC(cs *Session, e *Endpoint, params *GetJobParams) (*JobReplyData, *ErrorReply) {
|
func (s *StratumServer) handleGetJobRPC(cs *Session, params *GetJobParams) (*JobReplyData, *ErrorReply) {
|
||||||
miner, ok := s.miners.Get(params.Id)
|
miner, ok := s.miners.Get(params.Id)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, &ErrorReply{Code: -1, Message: "Unauthenticated"}
|
return nil, &ErrorReply{Code: -1, Message: "Unauthenticated"}
|
||||||
@ -55,7 +55,7 @@ func (s *StratumServer) handleGetJobRPC(cs *Session, e *Endpoint, params *GetJob
|
|||||||
return cs.getJob(t), nil
|
return cs.getJob(t), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StratumServer) handleSubmitRPC(cs *Session, e *Endpoint, params *SubmitParams) (*SubmitReply, *ErrorReply) {
|
func (s *StratumServer) handleSubmitRPC(cs *Session, params *SubmitParams) (*SubmitReply, *ErrorReply) {
|
||||||
miner, ok := s.miners.Get(params.Id)
|
miner, ok := s.miners.Get(params.Id)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, &ErrorReply{Code: -1, Message: "Unauthenticated"}
|
return nil, &ErrorReply{Code: -1, Message: "Unauthenticated"}
|
||||||
@ -84,14 +84,14 @@ func (s *StratumServer) handleSubmitRPC(cs *Session, e *Endpoint, params *Submit
|
|||||||
return nil, &ErrorReply{Code: -1, Message: "Block expired"}
|
return nil, &ErrorReply{Code: -1, Message: "Block expired"}
|
||||||
}
|
}
|
||||||
|
|
||||||
validShare := miner.processShare(s, e, job, t, nonce, params.Result)
|
validShare := miner.processShare(s, cs.endpoint, job, t, nonce, params.Result)
|
||||||
if !validShare {
|
if !validShare {
|
||||||
return nil, &ErrorReply{Code: -1, Message: "Low difficulty share"}
|
return nil, &ErrorReply{Code: -1, Message: "Low difficulty share"}
|
||||||
}
|
}
|
||||||
return &SubmitReply{Status: "OK"}, nil
|
return &SubmitReply{Status: "OK"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StratumServer) handleUnknownRPC(cs *Session, req *JSONRpcReq) *ErrorReply {
|
func (s *StratumServer) handleUnknownRPC(req *JSONRpcReq) *ErrorReply {
|
||||||
log.Printf("Unknown RPC method: %v", req)
|
log.Printf("Unknown RPC method: %v", req)
|
||||||
return &ErrorReply{Code: -1, Message: "Invalid method"}
|
return &ErrorReply{Code: -1, Message: "Invalid method"}
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ func (cs *Session) handleMessage(s *StratumServer, e *Endpoint, req *JSONRpcReq)
|
|||||||
log.Println("Unable to parse params")
|
log.Println("Unable to parse params")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
reply, errReply := s.handleLoginRPC(cs, e, ¶ms)
|
reply, errReply := s.handleLoginRPC(cs, ¶ms)
|
||||||
if errReply != nil {
|
if errReply != nil {
|
||||||
return cs.sendError(req.Id, errReply, true)
|
return cs.sendError(req.Id, errReply, true)
|
||||||
}
|
}
|
||||||
@ -247,7 +247,7 @@ func (cs *Session) handleMessage(s *StratumServer, e *Endpoint, req *JSONRpcReq)
|
|||||||
log.Println("Unable to parse params")
|
log.Println("Unable to parse params")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
reply, errReply := s.handleGetJobRPC(cs, e, ¶ms)
|
reply, errReply := s.handleGetJobRPC(cs, ¶ms)
|
||||||
if errReply != nil {
|
if errReply != nil {
|
||||||
return cs.sendError(req.Id, errReply, true)
|
return cs.sendError(req.Id, errReply, true)
|
||||||
}
|
}
|
||||||
@ -259,13 +259,13 @@ func (cs *Session) handleMessage(s *StratumServer, e *Endpoint, req *JSONRpcReq)
|
|||||||
log.Println("Unable to parse params")
|
log.Println("Unable to parse params")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
reply, errReply := s.handleSubmitRPC(cs, e, ¶ms)
|
reply, errReply := s.handleSubmitRPC(cs, ¶ms)
|
||||||
if errReply != nil {
|
if errReply != nil {
|
||||||
return cs.sendError(req.Id, errReply, false)
|
return cs.sendError(req.Id, errReply, false)
|
||||||
}
|
}
|
||||||
return cs.sendResult(req.Id, &reply)
|
return cs.sendResult(req.Id, &reply)
|
||||||
default:
|
default:
|
||||||
errReply := s.handleUnknownRPC(cs, req)
|
errReply := s.handleUnknownRPC(req)
|
||||||
return cs.sendError(req.Id, errReply, true)
|
return cs.sendError(req.Id, errReply, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user