Skip to content

Commit

Permalink
Update mempool methods to include "accounts" parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksej-paschenko committed Nov 23, 2023
1 parent ec7e31c commit 1f281cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 9 additions & 2 deletions streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
// MempoolEventData represents the data part of a new-pending-message event.
type MempoolEventData struct {
BOC []byte `json:"boc"`
// InvolvedAccounts is a list of accounts that are involved in the corresponding trace of the message.
// The trace is a result of emulation.
// This field is only present when you subscribe to mempool events for a particular set of accounts.
InvolvedAccounts []tongo.AccountID `json:"involved_accounts"`
}

// TransactionEventData represents the data part of a new-transaction event.
Expand Down Expand Up @@ -115,7 +119,7 @@ type Websocket interface {
UnsubscribeFromTraces(accounts []string) error
// SubscribeToMempool subscribes to notifications about new messages in the TON network.

SubscribeToMempool() error
SubscribeToMempool(accounts []string) error
// UnsubscribeFromMempool unsubscribes from notifications about new messages in the TON network.
UnsubscribeFromMempool() error

Expand Down Expand Up @@ -177,8 +181,11 @@ func (s *StreamingAPI) SubscribeToTraces(ctx context.Context, accounts []string,
// When a new mempool event is received, the handler will be called.
// This function returns an error when the underlying connection fails or context is canceled.
// No automatic reconnection is performed.
func (s *StreamingAPI) SubscribeToMempool(ctx context.Context, handler MempoolHandler) error {
func (s *StreamingAPI) SubscribeToMempool(ctx context.Context, accounts []string, handler MempoolHandler) error {
url := fmt.Sprintf("%s/v2/sse/mempool", s.endpoint)
if len(accounts) > 0 {
url += "?accounts=" + strings.Join(accounts, ",")
}
return s.subscribe(ctx, url, s.apiKey, func(data []byte) {
eventData := MempoolEventData{}
if err := json.Unmarshal(data, &eventData); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ func (w *websocketConnection) UnsubscribeFromTraces(accounts []string) error {
return w.conn.WriteJSON(request)
}

func (w *websocketConnection) SubscribeToMempool() error {
func (w *websocketConnection) SubscribeToMempool(accounts []string) error {
request := JsonRPCRequest{ID: w.currentRequestID(), JSONRPC: "2.0", Method: "subscribe_mempool"}
if len(accounts) > 0 {
request.Params = []string{
fmt.Sprintf("accounts=%s", strings.Join(accounts, ",")),
}
}
w.mu.Lock()
defer w.mu.Unlock()
return w.conn.WriteJSON(request)
Expand Down

0 comments on commit 1f281cc

Please sign in to comment.