diff --git a/client/tonapi.go b/client/tonapi.go new file mode 100644 index 00000000..2d80e264 --- /dev/null +++ b/client/tonapi.go @@ -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 +// +//} diff --git a/pkg/api/event_handlers.go b/pkg/api/event_handlers.go index 71bda868..3dd1ec83 100644 --- a/pkg/api/event_handlers.go +++ b/pkg/api/event_handlers.go @@ -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) } @@ -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) } @@ -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) } @@ -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) } @@ -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 } diff --git a/pkg/api/interfaces.go b/pkg/api/interfaces.go index c2a5a870..1ce68aca 100644 --- a/pkg/api/interfaces.go +++ b/pkg/api/interfaces.go @@ -3,6 +3,7 @@ package api import ( "context" "crypto/ed25519" + "github.com/tonkeeper/tongo/boc" "time" "github.com/tonkeeper/tongo" @@ -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 } diff --git a/pkg/litestorage/account.go b/pkg/litestorage/account.go index d0a7003c..df88bcbf 100644 --- a/pkg/litestorage/account.go +++ b/pkg/litestorage/account.go @@ -2,6 +2,7 @@ package litestorage import ( "context" + "github.com/tonkeeper/tongo/tlb" "github.com/tonkeeper/opentonapi/pkg/core" "github.com/tonkeeper/tongo" @@ -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) +} diff --git a/pkg/litestorage/litestorage.go b/pkg/litestorage/litestorage.go index dd861ff4..33fc40b5 100644 --- a/pkg/litestorage/litestorage.go +++ b/pkg/litestorage/litestorage.go @@ -5,6 +5,7 @@ import ( "crypto/ed25519" "errors" "fmt" + "github.com/tonkeeper/tongo/boc" "math/big" "time" @@ -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) +}