gagliardetto / solana-go

Go SDK library and RPC client for the Solana Blockchain
Apache License 2.0
943 stars 267 forks source link

BlockSubscribe no data output. #196

Open kenneyLee opened 7 months ago

kenneyLee commented 7 months ago

I used BlockSubscribe, but found that there was no data output.But with the same endpoint, LogsSubscribe is running normally. `package main

import ( "context" "fmt" "math" "sync"

bin "github.com/gagliardetto/binary"
"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/programs/serum"
"github.com/gagliardetto/solana-go/rpc"

"github.com/gagliardetto/solana-go/programs/token"
"github.com/gagliardetto/solana-go/rpc/ws"

)

func main() { client, err := ws.Connect(context.Background(), rpc.MainNetBeta_WS)

if err != nil {
    panic(err)
}

filter := ws.NewBlockSubscribeFilterAll()
opts := &ws.BlockSubscribeOpts{
    Commitment: rpc.CommitmentConfirmed,
}

sub, err := client.BlockSubscribe(filter, opts)
if err != nil {

    panic(err)
}
defer sub.Unsubscribe()

for {
    res, err := sub.Recv()
    if err != nil {
        fmt.Println("BlockSubscribe error:", err)
        panic(err)
    }

    fmt.Println("Received block:", res.Value.Block)

    for _, transaction := range res.Value.Block.Transactions {
        fmt.Println("Transaction:", transaction)
    }
}

}`

gagliardetto commented 7 months ago

https://solana.com/docs/rpc/websocket/blocksubscribe

image