Skip to content

Commit

Permalink
fix connections leak
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-tron committed Jul 29, 2023
1 parent a6826d0 commit e2a2439
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 5 deletions.
56 changes: 56 additions & 0 deletions client/tonapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package client

//
//import (
// "context"
// "encoding/base64"
// "github.com/tonkeeper/tongo"
// "github.com/tonkeeper/tongo/tlb"
//)
//
//func (c *Client) GetSeqno(ctx context.Context, account tongo.AccountID) (uint32, error) {
// res, err := c.GetAccountSeqno(ctx, GetAccountSeqnoParams{AccountID: account.ToRaw()})
// if err != nil {
// return 0, err
// }
// return res.Seqno, nil
//}
//
//func (c *Client) SendMessage(ctx context.Context, payload []byte) (uint32, error) {
// err := c.SendMessageTemp(ctx, &SendMessageTempReq{Boc: base64.StdEncoding.EncodeToString(payload)})
// if err != nil {
// return 0, err
// }
// return 0, nil
//}
//
//func (c *Client) GetAccountState(ctx context.Context, accountID tongo.AccountID) (tlb.ShardAccount, error) {
// s, err := c.GetRawAccount(ctx, GetRawAccountParams{AccountID: accountID.ToRaw()})
// if err != nil {
// return tlb.ShardAccount{}, err
// }
// var a tlb.ShardAccount
//
// a.LastTransLt = uint64(s.LastTransactionLt)
// switch s.Status {
// case "nonexist":
// a.Account.SumType = "AccountNone"
// case "uninit":
// a.Account.SumType = "Account"
// a.Account.Account.Addr = accountID.ToMsgAddress()
// a.Account.Account.Storage.Balance.Grams = tlb.Grams(s.Balance)
// a.Account.Account.Storage.State.SumType = "AccountUninit"
// case "active":
// a.Account.SumType = "Account"
// a.Account.Account.Addr = accountID.ToMsgAddress()
// a.Account.Account.Storage.Balance.Grams = tlb.Grams(s.Balance)
// a.Account.Account.Storage.State.SumType = "AccountActive"
// a.Account.Account.Storage.State.AccountActive.StateInit.Code.Exists = len(s.Code.Value) > 0
// a.Account.Account.Storage.State.AccountActive.StateInit.Data.Exists = len(s.Data.Value) > 0
//
// case "frozen":
//
// }
// return a, nil
//
//}
10 changes: 5 additions & 5 deletions pkg/api/event_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (h Handler) EmulateMessageToAccountEvent(ctx context.Context, request *oas.
if err != nil {
return nil, toError(http.StatusBadRequest, err)
}
emulator, err := txemulator.NewTraceBuilder()
emulator, err := txemulator.NewTraceBuilder(txemulator.WithAccountsSource(h.storage))
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
Expand Down Expand Up @@ -212,7 +212,7 @@ func (h Handler) EmulateMessageToEvent(ctx context.Context, request *oas.Emulate
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
emulator, err := txemulator.NewTraceBuilder()
emulator, err := txemulator.NewTraceBuilder(txemulator.WithAccountsSource(h.storage))
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
Expand Down Expand Up @@ -245,7 +245,7 @@ func (h Handler) EmulateMessageToTrace(ctx context.Context, request *oas.Emulate
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
emulator, err := txemulator.NewTraceBuilder()
emulator, err := txemulator.NewTraceBuilder(txemulator.WithAccountsSource(h.storage))
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
Expand Down Expand Up @@ -302,7 +302,7 @@ func (h Handler) EmulateWalletMessage(ctx context.Context, request *oas.EmulateW
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
emulator, err := txemulator.NewTraceBuilder()
emulator, err := txemulator.NewTraceBuilder(txemulator.WithAccountsSource(h.storage))
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
Expand Down Expand Up @@ -347,7 +347,7 @@ func (h Handler) addToMempool(bytesBoc []byte) {
if err != nil {
return
}
emulator, err := txemulator.NewTraceBuilder()
emulator, err := txemulator.NewTraceBuilder(txemulator.WithAccountsSource(h.storage))
if err != nil {
return
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"context"
"crypto/ed25519"
"github.com/tonkeeper/tongo/boc"
"time"

"github.com/tonkeeper/tongo"
Expand Down Expand Up @@ -81,6 +82,9 @@ type storage interface {

GetSeqno(ctx context.Context, account tongo.AccountID) (uint32, error)

GetAccountState(ctx context.Context, a tongo.AccountID) (tlb.ShardAccount, error)
GetLibraries(ctx context.Context, libraries []tongo.Bits256) (map[tongo.Bits256]*boc.Cell, error)

liteStorageRaw
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/litestorage/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package litestorage

import (
"context"
"github.com/tonkeeper/tongo/tlb"

"github.com/tonkeeper/opentonapi/pkg/core"
"github.com/tonkeeper/tongo"
Expand All @@ -14,3 +15,7 @@ func (s *LiteStorage) GetSubscriptions(ctx context.Context, address tongo.Accoun
func (s *LiteStorage) GetSeqno(ctx context.Context, account tongo.AccountID) (uint32, error) {
return s.client.GetSeqno(ctx, account)
}

func (s *LiteStorage) GetAccountState(ctx context.Context, a tongo.AccountID) (tlb.ShardAccount, error) {
return s.client.GetAccountState(ctx, a)
}
5 changes: 5 additions & 0 deletions pkg/litestorage/litestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/ed25519"
"errors"
"fmt"
"github.com/tonkeeper/tongo/boc"
"math/big"
"time"

Expand Down Expand Up @@ -475,3 +476,7 @@ func (s *LiteStorage) GetDnsExpiring(ctx context.Context, id tongo.AccountID, pe
defer timer.ObserveDuration()
return nil, nil
}

func (s *LiteStorage) GetLibraries(ctx context.Context, libraries []tongo.Bits256) (map[tongo.Bits256]*boc.Cell, error) {
return s.client.GetLibraries(ctx, libraries)
}

0 comments on commit e2a2439

Please sign in to comment.