csgo

package module
v0.0.0-...-801b461 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2022 License: Zlib Imports: 14 Imported by: 0

README

CSGO Esports Algorand Oracle

This project is an oracle for esports match data in CSGO. Data is directly pulled from HLTV and pushed onto the Algorand blockchain via Siam. An instance of this oracle is currently running on the testnet: https://testnet.algoexplorer.io/application/45565315

DISCLAIMER: Use this software responsibly. Do not send out excessive number of requests to data endpoints like HLTV.

Configuration

Refer to Siam

License

This project is licensed under the permissive zlib license.

Relevant Resources

Documentation

Index

Constants

View Source
const PastMatchesTTL = time.Hour * 72 // 3 days

PastMatchesTTL is the minimum duration that a past match should live on the blockchain. The duration is measured starting from the model.Match Date field. A past match that is published on the chain will remain on it for this time.

Variables

This section is empty.

Functions

func ConstructDesiredState

func ConstructDesiredState(past []model.Match, future []model.Match, l int) map[string]string

ConstructDesiredState returns the desired state of a buffer of size l that the Oracle wishes to integrate onto the AlgorandBuffer. There are two factors for desirability.

  1. Past matches should remain on the buffer until their Date is older than the PastMatchesTTL
  2. Remove past matches that are older than their TTL.

The desired state also depends on the current time of the system (e.g. because of wanting to discard old data).

func CreateData

func CreateData()

func CreateWinnerMap

func CreateWinnerMap(m []model.Match) map[string]string

CreateWinnerMap converts a slice []Match into a map, where the key is the match ID, and the value is the Match winner. If there is no winner yet, the value will be empty.

func PopSlashSource

func PopSlashSource(selection *goquery.Selection) string

func ReverseMatches

func ReverseMatches(s []model.Match)

ReverseMatches reverses the order of a match array.

func SplitMatchesAge

func SplitMatchesAge(m []model.Match, threshold time.Duration, now time.Time) ([]model.Match, []model.Match)

SplitMatchesAge returns a partition of matches. The first return value contains matches that concluded longer than threshold ago, whereas the second return value contains matches that are at most threshold old. The distance is measured from a given present time `now`.

Types

type API

type API interface {
	// Fetch returns a list of past and future CSGO pro matches.
	// The reference implementation is provided by HLTV
	Fetch() (past, future []model.Match, err error)
}

API is a provider of CSGO match data. It provides methods for fetching past and future matches. Which matches are selected is up to the API implementation.

type HLTV

type HLTV struct {
	UpcomingPage *goquery.Document
	ResultsPage  *goquery.Document
}

func (*HLTV) Fetch

func (h *HLTV) Fetch() (past, future []model.Match, err error)

Fetch gets the latest version of the HLTV page. Note: Do not abuse this function. Exceeding certain rates can be interpreted as crawling and result in IP ban.

type Oracle

type Oracle struct {
	// contains filtered or unexported fields
}

Oracle fetches, compares, and pushes data to the Blockchain

func NewOracle

func NewOracle(b *siam.AlgorandBuffer, cfg *OracleConfig) *Oracle

NewOracle creates and initializes an Oracle struct. Requires an API to fetch and collect data, as well as a siam.AlgorandBuffer, in order to publish changes to the blockchain.

func (*Oracle) Serve

func (o *Oracle) Serve()

Serve spawns a cancelable goroutine that aims to keep the AlgorandBuffer in a desired state. See ConstructDesiredState.

Any goroutines spawned by the Oracle can be cancelled anytime via Stop.

func (*Oracle) Stop

func (o *Oracle) Stop()

Stop signals the Oracle to stop its goroutine and stop the siam.AlgorandBuffer managing routine. Stop will block until both goroutines have exited.

func (*Oracle) Wait

func (o *Oracle) Wait()

Wait blocks until all goroutines of the Oracle have finished execution. To stop execution of an Oracle, call Stop.

type OracleConfig

type OracleConfig struct {
	// PrimaryAPI is the primary source of information. Only data proposed from this API
	// is put onto the blockchain.
	PrimaryAPI API

	// VerificationAPIs is an optional list of verification APIs used to verify the correctness
	// of the PrimaryAPI. If the data proposed from the PrimaryAPI does not match data from each
	// of verification APIs, the data is not written to the blockchain.
	VerificationAPIs []API

	// MaxVerifyTime does not need to be set if VerificationAPIs is nil. If the VerificationAPIs
	// do not agree with the PrimaryAPI's proposal within MaxVerifyTime, then the proposed data
	// gets discarded
	MaxVerifyTime time.Duration

	// RefreshInterval is the pause between two API fetch commands.
	// If the API accesses a rate-limited resource, then set RefreshInterval high enough
	// as to not trigger a rate-limit or blacklist event.
	RefreshInterval time.Duration
}

OracleConfig defines the oracles behavior

type StubAPI

type StubAPI struct {
	Past      []model.Match
	Future    []model.Match
	Logger    *log.Logger
	LogActive bool
}

StubAPI is a stub that implements API. You can explicitly set the match data that shall be returned by the API functions, by modifying the public fields or calling SetMatches. You can also specify if the stub should return an error.

func (*StubAPI) Fetch

func (s *StubAPI) Fetch() (past, future []model.Match, err error)

Fetch returns a static list of past and future CSGO pro matches, which can be set via SetMatches.

func (*StubAPI) SetMatches

func (s *StubAPI) SetMatches(past []model.Match, future []model.Match)

SetMatches sets future and past matches to be returned by the API

Directories

Path Synopsis
Package generator contains functions for generating []csgo.Match data for testing purposes.
Package generator contains functions for generating []csgo.Match data for testing purposes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL