Skip to content

Commit 2a8ed5c

Browse files
Update examples
1 parent 329638a commit 2a8ed5c

File tree

8 files changed

+25
-10
lines changed

8 files changed

+25
-10
lines changed

examples/sse/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/tonkeeper/tonapi-go/examples/sse
22

3-
go 1.21.3
3+
go 1.20
44

5-
require github.com/tonkeeper/tonapi-go v0.0.1
5+
require github.com/tonkeeper/tonapi-go v0.0.2
66

77
require (
88
github.com/dlclark/regexp2 v1.10.0 // indirect

examples/sse/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
5353
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
5454
github.com/tonkeeper/tonapi-go v0.0.1 h1:miD7wFpocflt0seNhJ4kKhiXsWkozwotO2gJGlib4C0=
5555
github.com/tonkeeper/tonapi-go v0.0.1/go.mod h1:2n+LizNjCQbCZhvVSooKGnzxAgdIrgePsh6Kgea0NPY=
56+
github.com/tonkeeper/tonapi-go v0.0.2/go.mod h1:2n+LizNjCQbCZhvVSooKGnzxAgdIrgePsh6Kgea0NPY=
5657
github.com/tonkeeper/tongo v1.4.1 h1:QMIya/ongFuOyHgVOFmHF+Cu4nt23KumPRLApmp90zE=
5758
github.com/tonkeeper/tongo v1.4.1/go.mod h1:LdOBjpUz6vLp1EdX3E0XLNks9YI5XMSqaQahfOMrBEY=
5859
go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs=

examples/sse/main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67

78
"github.com/tonkeeper/tonapi-go"
@@ -11,8 +12,13 @@ func subscribeToMempool(token string) {
1112
streamingAPI := tonapi.NewStreamingAPI(tonapi.WithStreamingToken(token))
1213
for {
1314
err := streamingAPI.SubscribeToMempool(context.Background(),
15+
// this "accounts" parameter is optional,
16+
// if not set, you will receive all mempool events.
17+
// if defined, you will receive only mempool events that involve these accounts.
18+
[]string{"-1:5555555555555555555555555555555555555555555555555555555555555555"},
1419
func(data tonapi.MempoolEventData) {
15-
fmt.Printf("mempool event: %#v\n", len(data.BOC))
20+
value, _ := json.Marshal(data)
21+
fmt.Printf("mempool event: %#v\n", value)
1622
})
1723
if err != nil {
1824
fmt.Printf("mempool error: %v, reconnecting...\n", err)
@@ -23,7 +29,12 @@ func subscribeToMempool(token string) {
2329
func subscribeToTransactions(token string) {
2430
streamingAPI := tonapi.NewStreamingAPI(tonapi.WithStreamingToken(token))
2531
for {
26-
err := streamingAPI.SubscribeToTransactions(context.Background(), []string{"-1:5555555555555555555555555555555555555555555555555555555555555555"},
32+
err := streamingAPI.SubscribeToTransactions(context.Background(),
33+
[]string{"-1:5555555555555555555555555555555555555555555555555555555555555555"},
34+
// this "operations" is optional,
35+
// if not set, you will receive all transactions.
36+
// if defined, you will receive only transactions with these operations.
37+
nil,
2738
func(data tonapi.TransactionEventData) {
2839
fmt.Printf("New tx with hash: %v\n", data.TxHash)
2940
})

examples/tonapi-sdk/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/tonkeeper/tonapi-go/examples/tonapi-sdk
22

3-
go 1.21.3
3+
go 1.20
44

5-
require github.com/tonkeeper/tonapi-go v0.0.1
5+
require github.com/tonkeeper/tonapi-go v0.0.2
66

77
require (
88
github.com/dlclark/regexp2 v1.10.0 // indirect

examples/tonapi-sdk/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
5353
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
5454
github.com/tonkeeper/tonapi-go v0.0.1 h1:miD7wFpocflt0seNhJ4kKhiXsWkozwotO2gJGlib4C0=
5555
github.com/tonkeeper/tonapi-go v0.0.1/go.mod h1:2n+LizNjCQbCZhvVSooKGnzxAgdIrgePsh6Kgea0NPY=
56+
github.com/tonkeeper/tonapi-go v0.0.2/go.mod h1:2n+LizNjCQbCZhvVSooKGnzxAgdIrgePsh6Kgea0NPY=
5657
github.com/tonkeeper/tongo v1.4.1 h1:QMIya/ongFuOyHgVOFmHF+Cu4nt23KumPRLApmp90zE=
5758
github.com/tonkeeper/tongo v1.4.1/go.mod h1:LdOBjpUz6vLp1EdX3E0XLNks9YI5XMSqaQahfOMrBEY=
5859
go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs=

examples/websocket/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/tonkeeper/tonapi-go/examples/websocket
22

3-
go 1.21.3
3+
go 1.20
44

5-
require github.com/tonkeeper/tonapi-go v0.0.1
5+
require github.com/tonkeeper/tonapi-go v0.0.2
66

77
require (
88
github.com/dlclark/regexp2 v1.10.0 // indirect

examples/websocket/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
5353
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
5454
github.com/tonkeeper/tonapi-go v0.0.1 h1:miD7wFpocflt0seNhJ4kKhiXsWkozwotO2gJGlib4C0=
5555
github.com/tonkeeper/tonapi-go v0.0.1/go.mod h1:2n+LizNjCQbCZhvVSooKGnzxAgdIrgePsh6Kgea0NPY=
56+
github.com/tonkeeper/tonapi-go v0.0.2/go.mod h1:2n+LizNjCQbCZhvVSooKGnzxAgdIrgePsh6Kgea0NPY=
5657
github.com/tonkeeper/tongo v1.4.1 h1:QMIya/ongFuOyHgVOFmHF+Cu4nt23KumPRLApmp90zE=
5758
github.com/tonkeeper/tongo v1.4.1/go.mod h1:LdOBjpUz6vLp1EdX3E0XLNks9YI5XMSqaQahfOMrBEY=
5859
go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs=

examples/websocket/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ func main() {
2929
ws.SetTraceHandler(func(data tonapi.TraceEventData) {
3030
fmt.Printf("New trace with hash: %v\n", data.Hash)
3131
})
32-
if err := ws.SubscribeToMempool(); err != nil {
32+
33+
if err := ws.SubscribeToMempool(accounts); err != nil {
3334
return err
3435
}
35-
if err := ws.SubscribeToTransactions(accounts); err != nil {
36+
if err := ws.SubscribeToTransactions(accounts, nil); err != nil {
3637
return err
3738
}
3839
if err := ws.SubscribeToTraces(accounts); err != nil {

0 commit comments

Comments
 (0)