diff --git a/main.go b/main.go index a1c626b..ec35cc4 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( c3pool_org "monero-blocks/pool/c3pool.org" monero_hashvault_pro "monero-blocks/pool/monero.hashvault.pro" moneroocean_stream "monero-blocks/pool/moneroocean.stream" + supportxmr_com "monero-blocks/pool/supportxmr.com" xmr_2miners_com "monero-blocks/pool/xmr.2miners.com" xmr_nanopool_org "monero-blocks/pool/xmr.nanopool.org" xmrpool_eu "monero-blocks/pool/xmrpool.eu" @@ -22,6 +23,7 @@ func main() { flag.Parse() pools := []pool.Pool{ + supportxmr_com.New(), monero_hashvault_pro.New(), xmr_nanopool_org.New(), xmr_2miners_com.New(), @@ -87,7 +89,7 @@ func main() { if smallIndex == -1 { break } - csvFile.Write([]string{strconv.FormatUint(allBlocks[smallIndex][0].Height, 10), allBlocks[smallIndex][0].Id.String(), strconv.FormatUint(allBlocks[smallIndex][0].Height, 10), strconv.FormatUint(allBlocks[smallIndex][0].Height, 10), pools[smallIndex].Name()}) + csvFile.Write([]string{strconv.FormatUint(allBlocks[smallIndex][0].Height, 10), allBlocks[smallIndex][0].Id.String(), strconv.FormatUint(allBlocks[smallIndex][0].Timestamp, 10), strconv.FormatUint(allBlocks[smallIndex][0].Reward, 10), pools[smallIndex].Name()}) allBlocks[smallIndex] = allBlocks[smallIndex][1:] } diff --git a/pool/supportxmr.com/pool.go b/pool/supportxmr.com/pool.go new file mode 100644 index 0000000..36787b2 --- /dev/null +++ b/pool/supportxmr.com/pool.go @@ -0,0 +1,99 @@ +package supportxmr_com + +import ( + "encoding/json" + "fmt" + "io" + "monero-blocks/pool" + "net/http" + "time" +) + +type Pool struct { + throttler <-chan time.Time +} + +type pagingToken struct { + page uint64 + id pool.Hash + height uint64 +} + +type blockJson struct { + Ts uint64 `json:"ts,string"` + Hash pool.Hash `json:"hash"` + Height uint64 `json:"height"` + Valid bool `json:"valid"` + Value uint64 `json:"value,string"` +} + +func New() *Pool { + return &Pool{ + throttler: time.Tick(time.Second * 5), //One request every five seconds + } +} + +func (p *Pool) Name() string { + return "supportxmr.com" +} + +func (p *Pool) GetBlocks(token pool.Token) ([]pool.Block, pool.Token) { + + var t *pagingToken + var ok bool + + var page uint64 + + if t, ok = token.(*pagingToken); token != nil && ok { + page = t.page + } else { + t = &pagingToken{} + } + + <-p.throttler + response, err := http.DefaultClient.Get(fmt.Sprintf("https://supportxmr.com/api/pool/blocks?page=%d&limit=500", page)) + if err != nil { + return nil, nil + } + defer response.Body.Close() + + blockData := make([]blockJson, 0, 500) + + if data, err := io.ReadAll(response.Body); err != nil { + return nil, nil + } else { + if err = json.Unmarshal(data, &blockData); err != nil { + return nil, nil + } + } + + var blocks []pool.Block + + start := t.id == pool.ZeroHash + for _, b := range blockData { + if b.Height < t.height { + start = true + } + if start && b.Valid { + blocks = append(blocks, pool.Block{ + Id: b.Hash, + Height: b.Height, + Reward: b.Value, + Timestamp: b.Ts, + }) + } + if b.Hash == t.id { + start = true + } + } + + if len(blocks) == 0 { + return nil, nil + } + + return blocks, &pagingToken{ + id: blocks[len(blocks)-1].Id, + page: page + 1, + height: blocks[len(blocks)-1].Height, + } +}