-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.go
40 lines (33 loc) · 940 Bytes
/
example.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"context"
"fmt"
"time"
"github.com/TessorNetwork/ariadne"
)
func main() {
nodeAddr := "zeus.testnet.decentr.xyz:9090"
fetcher, err := ariadne.New(context.Background(), nodeAddr, time.Minute)
if err != nil {
panic(err)
}
b, err := fetcher.FetchBlock(context.Background(), 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())
}