Skip to content

Instantly share code, notes, and snippets.

@megaherz
Last active March 1, 2021 18:14
Show Gist options
  • Save megaherz/bd2f4576c1e06b30604c80d9da530576 to your computer and use it in GitHub Desktop.
Save megaherz/bd2f4576c1e06b30604c80d9da530576 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"time"
"github.com/Decentr-net/ariadne"
decentr "github.com/Decentr-net/decentr/app"
)
func main() {
nodeAddr := "http://zeus.testnet.decentr.xyz:26657"
cdc := decentr.MakeCodec()
fetcher, err := ariadne.New(nodeAddr, cdc, time.Minute)
if err != nil {
panic(err)
}
b, err := fetcher.FetchBlock(0) // Fetch one block(the highest block)
if err != nil {
panic(err)
}
fmt.Printf("messages from block %d: \n%+v\n\n", b.Height, b.Messages())
fmt.Println("start fetching blocks")
fmt.Println(fetcher.FetchBlocks(context.Background(), b.Height, func(b ariadne.Block) error {
fmt.Printf("got new block %d. there are %d messages\n",
b.Height,
len(b.Messages()),
)
return nil
},
ariadne.WithErrHandler(func(h uint64, err error) {
fmt.Printf("got an error on height %d: %s\n", h, err.Error())
}),
ariadne.WithRetryInterval(time.Second*2),
ariadne.WithRetryLastBlockInterval(time.Second*5),
).Error())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment