Categorygithub.com/MatrixLabsTech/flow-event-fetcher
modulepackage
1.0.1
Repository: https://github.com/matrixlabstech/flow-event-fetcher.git
Documentation: pkg.go.dev

# README

ultimate-flow-event-fetcher

Objectives ๐Ÿฏ

Flow is continuously adding new features and discovering and fixing bugs in the Flow node software. They also utilize a Spork as an opportunity to update the nodes with the latest releases.

However, as a DApp developer, it makes it somewhat inconvenient to collect events from the chain with an arbitrary block range.

To make life easier, we provide the SporkStore go module, which can internally handle spork endpoints as well as block range splitting.

Additionally, we wrap it in a rest service that can be easily deployed as a microservice via docker or docker-compose and integrated into your current flow project.

Features ๐Ÿฎ

  • Fetch arbitrary events from arbitrary block ranges

    Example: Use SporkStore module in go

  • Wrapped REST API service that can be quickly launched using Docker. rest-api

  • Query latest block height latest

  • Sync in-memory spork list syncspork

  • Query transactions

Structure

Usage ๐Ÿ‘€

Go Module

package main

import (
    "fmt"

    "github.com/MatrixLabsTech/flow-event-fetcher/spork"
)

func main() {
    sporkJsonUrl := "https://raw.githubusercontent.com/MatrixLabsTech/flow-spork-info/main/spork.json"
    maxQueryCount := 2000
    batchSize := 5
    sporkStore := spork.New(sporkJsonUrl, uint64(maxQueryCount), uint64(batchSize))

    event := "A.1654653399040a61.FlowToken.TokensDeposited"

    // store will automatically fetch events
    // {19050753 19051853 access.mainnet.nodes.onflow.org:9000}
    ret, err := sporkStore.QueryEventByBlockRange(event, 13405050, 13405100)
    if err != nil {
        panic(err)
    }
    fmt.Println("Total fetched blocks:", len(ret))
    jsonRet := spork.BlockEventsToJSON(ret)
    fmt.Println("Total fetched events:", len(jsonRet))
    fmt.Println("First Block's blockId:", jsonRet[0]["blockId"])

    ret, err = sporkStore.QueryEventByBlockRange(event, 13405050, 13406060)
    if err != nil {
        panic(err)
    }
    fmt.Println("Total fetched blocks:", len(ret))
    jsonRet = spork.BlockEventsToJSON(ret)
    fmt.Println("Total fetched events:", len(jsonRet))
    fmt.Println("First Block's blockId:", jsonRet[0]["blockId"])

    // store will automatically fetch events with
    // {11905073 19051853 access.mainnet.nodes.onflow.org:9000}
    ret, err = sporkStore.QueryEventByBlockRange(event, 19050753, 19051853)
    if err != nil {
        panic(err)
    }
    jsonRet = spork.BlockEventsToJSON(ret)
    fmt.Println("Total fetched events:", len(jsonRet))
    fmt.Println("First Block's blockId:", jsonRet[0]["blockId"])
}

REST API Service

docker build . -t onflow-fetcher-service
# mainnet
docker run -d \
    --rm \
    -p 8989:8989 \
    -e GIN_MODE=release \
    -e SPORK_JSON_URL=https://raw.githubusercontent.com/MatrixLabsTech/flow-spork-info/main/spork.json \
    -e PORT=8989 \
    onflow-fetcher-service

# testnet
docker run -d \
    --rm \
    -p 8989:8989 \
    -e GIN_MODE=release \
    -e SPORK_JSON_URL=https://raw.githubusercontent.com/MatrixLabsTech/flow-spork-info/main/spork.testnet.json \
    -e PORT=8989 \
    onflow-fetcher-service

๐ŸŽถ Spork information can be given as aย json-formatted resource's URI. We're keeping it in the repo: https://github.com/MatrixLabsTech/flow-spork-info

or simply use docker compose

# mainnet
docker-compose up --build

# testnet
docker-compose -f docker-compose-testnet.yaml up --build

Contribution

Welcome to contribute ๐Ÿ’Œ

MatrixLabs ๐ŸŽ† ChainIDE

# Packages

* * example/main.go * Copyright (c) 2021 Alvin(Xinyao) Sun <[email protected]> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
* * spork/sporkstore.go * Copyright (c) 2021 Alvin(Xinyao) Sun <[email protected]> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.

# Structs

No description provided by the author