GithubHelp home page GithubHelp logo

antelope-hyperion-streamer's Introduction

antelope-hyperion-streamer

Listen to certain actions, with persitant checkpoint saving to allow for a gap free stream of actions (based on hyperion).

This package also contains an example stdout listener which can be used to store action traces in local files:

go run cmd/listener/listener.go -filter="account=eosio&act.name=sellram" | jq --unbuffered -r '.data.bytes' >> bytes.txt

This will store the amount of bytes sold in a file called bytes.txt, this also shows the power of combining this listener with jq to process the action traces. Once the action traces is printed to stdout, the last global_sequence is stored in a state file located at .state.

Usage in your project

For experiments storing action traces in files, processed via shell pipes is fine, but for usage in serious projects, you should store the global_sequence state along side the processed actions and commit both atomically to your store.

package main

import (
    "context"

    "github.com/openventures/antelope-hyperion-streamer/streamer"
)

func main() {
    ctx, cancel := context.WithCancel(context.TODO())
    defer cancel()

    head := DB.LoadHeadGlobalSequence(ctx)

    s := streamer.Streamer{
		BaseURL:   "https://some-hyperion-endpoint.example.com",
		PageLimit: 100,
	}
    batches, errC := s.Start(ctx, head, []streamer.Filter{{ Key: "account", Value: "eosio" }})

    for {
        select {
        case <-ctx.Done():
            return
        case err := <-errC:
            panic(fmt.Sprintf("loader stopped: %s", err.Error()))
        case b := <-batches:
            DB.InTransaction(ctx, func (tx *TX) {
                tx.StoreActions(b.Actions)
                tx.StoreHeadGlobalSequence(b.HeadGlobalSequence)
            })
        }
    }
}

This allows you to always restart the streamer and ensure a gap free of actions.

antelope-hyperion-streamer's People

Contributors

openventures avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.