added ping message so ws client do not get disconnected from the server

added address public key in programResult
change some lock and unlock call timing
This commit is contained in:
billettc 2020-11-24 08:43:37 -05:00
parent 4d145fe4e8
commit d7226cdc7b
4 changed files with 19 additions and 13 deletions

View File

@ -21,16 +21,11 @@ import (
"log"
"os"
"github.com/dfuse-io/solana-go/text"
"github.com/dfuse-io/solana-go/token"
"github.com/dfuse-io/solana-go/rpc"
bin "github.com/dfuse-io/binary"
"github.com/dfuse-io/solana-go"
"github.com/dfuse-io/solana-go/rpc"
"github.com/dfuse-io/solana-go/text"
"github.com/dfuse-io/solana-go/token"
"github.com/spf13/cobra"
)

View File

@ -20,8 +20,6 @@ import (
"net/http"
bin "github.com/dfuse-io/binary"
//"github.com/dfuse-io/solana-go"
"github.com/dfuse-io/solana-go"
"github.com/ybbus/jsonrpc"
)

View File

@ -22,6 +22,7 @@ import (
"io"
"reflect"
"sync"
"time"
"github.com/dfuse-io/solana-go/rpc"
"github.com/gorilla/rpc/v2/json2"
@ -53,6 +54,15 @@ func Dial(ctx context.Context, rpcURL string) (c *Client, err error) {
return nil, fmt.Errorf("new ws client: dial: %w", err)
}
go func() {
for {
c.conn.SetWriteDeadline(time.Now().Add(10 * time.Second))
if err := c.conn.WriteMessage(websocket.PingMessage, nil); err != nil {
return
}
time.Sleep(20 * time.Second)
}
}()
go c.receiveMessages()
return c, nil
}
@ -200,6 +210,8 @@ func (c *Client) unsubscribe(subID uint64, method string) error {
}
func (c *Client) subscribe(params []interface{}, conf map[string]interface{}, subscriptionMethod, unsubscribeMethod string, commitment rpc.CommitmentType, resultType interface{}) (*Subscription, error) {
c.lock.Lock()
defer c.lock.Unlock()
if commitment != "" {
conf["commitment"] = string(commitment)
}
@ -214,10 +226,8 @@ func (c *Client) subscribe(params []interface{}, conf map[string]interface{}, su
c.closeSubscription(req.ID, err)
}, unsubscribeMethod)
c.lock.Lock()
c.subscriptionByRequestID[req.ID] = sub
zlog.Info("added new subscription to websocket client", zap.Int("count", len(c.subscriptionByRequestID)))
c.lock.Unlock()
zlog.Debug("writing data to conn", zap.String("data", string(data)))
err = c.conn.WriteMessage(websocket.TextMessage, data)

View File

@ -5,6 +5,8 @@ import (
"fmt"
"math/rand"
"github.com/dfuse-io/solana-go"
"github.com/dfuse-io/solana-go/rpc"
)
@ -51,6 +53,7 @@ type ProgramResult struct {
Slot uint64
} `json:"context"`
Value struct {
PubKey solana.PublicKey `json:"pub_key"`
Account rpc.Account `json:"account"`
} `json:"value"`
}