Categorygithub.com/blockpane/go-hyperion-stream
repositorypackage
1.0.1
Repository: https://github.com/blockpane/go-hyperion-stream.git
Documentation: pkg.go.dev

# README

go-hyperion-stream

Go Reference Gosec Build Status Go Report Card Coverage Status

This is a (minimal) library for the Hyperion Stream API.

Example

Prints a stream of rewards paid for players of Alien Worlds on WAX

package main

import (
	stream "github.com/blockpane/go-hyperion-stream"
	"log"
)

var (
	url      = "ws://wax.eosusa.news"
	contract = "m.federation"
	action   = "logmine"
	account  = ""
)

func main() {
	results := make(chan stream.HyperionResponse)
	errors := make(chan error)

	client, err := stream.NewClient(url, results, errors)
	if err != nil {
		panic(err)
	}

	err = client.StreamActions(stream.NewActionsReq(contract, account, action))
	if err != nil {
		panic(err)
	}

	act := &stream.ActionTrace{}
	for {
		select {
		case <-client.Ctx.Done():
			return
			
		case e := <-errors:
			switch e.(type) {
			case stream.ExitError:
				panic(e)
			default:
				log.Println(e)
			}

		case response := <-results:
			switch response.Type() {
			case stream.RespActionType:
				act, err = response.Action()
				if err != nil {
					log.Println(err)
					continue
				}
				log.Printf("%13s <- %11v %-13s - %v\n", act.Act.Data["miner"], act.Act.Data["bounty"], act.Act.Data["planet_name"], act.Act.Data["land_id"])
			}
		}
	}
}

Outputs:

2021/01/28 14:06:21     pgqqy.wam <-  1.4961 TLM eyeke.world   - 1099512960814
2021/01/28 14:06:21     mnk4g.wam <-  1.0674 TLM neri.world    - 1099512958948
2021/01/28 14:06:21     v5bqy.wam <-  1.6872 TLM magor.world   - 1099512960536
2021/01/28 14:06:22     a.nqy.wam <-  0.1773 TLM kavian.world  - 1099512961065
2021/01/28 14:06:22     jgxqy.wam <-  0.9895 TLM eyeke.world   - 1099512961378
2021/01/28 14:06:22     ppjay.wam <-  2.4352 TLM magor.world   - 1099512959814
2021/01/28 14:06:22     i5jay.wam <-  0.7850 TLM kavian.world  - 1099512959254
2021/01/28 14:06:22     r53qy.wam <-  0.6678 TLM kavian.world  - 1099512958463
2021/01/28 14:06:23     x1gay.wam <-  0.4707 TLM neri.world    - 1099512958632
...