AcceptSolution takes solution and find corresponding work and return associated share. It returns nil if the work is not found.
(s smartpool.Solution)
| 20 | // associated share. |
| 21 | // It returns nil if the work is not found. |
| 22 | func (wp WorkPool) AcceptSolution(s smartpool.Solution) smartpool.Share { |
| 23 | work := wp[s.WorkID()] |
| 24 | if work == nil { |
| 25 | smartpool.Output.Printf("work (%v) doesn't exist in workpool (len: %d)\n", s, len(wp)) |
| 26 | return nil |
| 27 | } |
| 28 | share := work.AcceptSolution(s).(*Share) |
| 29 | if share.SolutionState == FullBlockSolution { |
| 30 | delete(wp, s.WorkID()) |
| 31 | } |
| 32 | if share.SolutionState == InvalidShare { |
| 33 | smartpool.Output.Printf("Solution (%v) is invalid\n", s) |
| 34 | return nil |
| 35 | } else { |
| 36 | // smartpool.Output.Printf( |
| 37 | // "Create share for work: ID: %s - createdAt: %s - timestamp: 0x%s\n", |
| 38 | // work.ID(), |
| 39 | // work.CreatedAt(), |
| 40 | // work.BlockHeader().Time.Text(16), |
| 41 | // ) |
| 42 | return share |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | func (wp WorkPool) AddWork(w *Work) { |
| 47 | wp[w.ID()] = w |