Skip to content

Commit 6ad60b2

Browse files
committed
fix comments
1 parent 2b8f911 commit 6ad60b2

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

pkg/api/event_handlers.go

+30-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"github.com/tonkeeper/tongo/abi"
11+
"go.uber.org/zap"
1112
"net/http"
1213
"strings"
1314
"time"
@@ -353,7 +354,13 @@ func (h *Handler) EmulateMessageToAccountEvent(ctx context.Context, request *oas
353354
return nil, toError(http.StatusBadRequest, err)
354355
}
355356
hash, err := c.HashString()
357+
if err != nil {
358+
return nil, toError(http.StatusBadRequest, err)
359+
}
356360
trace, _, err := h.storage.GetTraceWithState(ctx, hash)
361+
if err != nil {
362+
h.logger.Warn("get trace from storage: ", zap.Error(err))
363+
}
357364
if trace == nil {
358365
configBase64, err := h.storage.TrimmedConfigBase64()
359366
if err != nil {
@@ -379,7 +386,7 @@ func (h *Handler) EmulateMessageToAccountEvent(ctx context.Context, request *oas
379386
if err != nil {
380387
return nil, toError(http.StatusInternalServerError, err)
381388
}
382-
err = h.storage.SaveTraceWithState(hash, trace, []abi.MethodInvocation{}, 24*time.Hour)
389+
err = h.storage.SaveTraceWithState(ctx, hash, trace, []abi.MethodInvocation{}, 24*time.Hour)
383390
if err != nil {
384391
fmt.Println("trace not saved: ", err)
385392
}
@@ -407,8 +414,14 @@ func (h *Handler) EmulateMessageToEvent(ctx context.Context, request *oas.Emulat
407414
}
408415
trace, prs := h.mempoolEmulate.traces.Get(hash)
409416
if !prs {
410-
hs, _ := c.HashString()
417+
hs, err := c.HashString()
418+
if err != nil {
419+
return nil, toError(http.StatusBadRequest, err)
420+
}
411421
trace, _, err = h.storage.GetTraceWithState(ctx, hs)
422+
if err != nil {
423+
h.logger.Warn("get trace from storage: ", zap.Error(err))
424+
}
412425
if trace == nil {
413426
var m tlb.Message
414427
if err := tlb.Unmarshal(c, &m); err != nil {
@@ -438,7 +451,7 @@ func (h *Handler) EmulateMessageToEvent(ctx context.Context, request *oas.Emulat
438451
if err != nil {
439452
return nil, toError(http.StatusInternalServerError, err)
440453
}
441-
err = h.storage.SaveTraceWithState(hs, trace, []abi.MethodInvocation{}, 24*time.Hour)
454+
err = h.storage.SaveTraceWithState(ctx, hs, trace, []abi.MethodInvocation{}, 24*time.Hour)
442455
if err != nil {
443456
fmt.Println("trace not saved: ", err)
444457
}
@@ -468,7 +481,13 @@ func (h *Handler) EmulateMessageToTrace(ctx context.Context, request *oas.Emulat
468481
trace, prs := h.mempoolEmulate.traces.Get(hash)
469482
if !prs {
470483
hs, err := c.HashString()
484+
if err != nil {
485+
return nil, toError(http.StatusBadRequest, err)
486+
}
471487
trace, _, err = h.storage.GetTraceWithState(ctx, hs)
488+
if err != nil {
489+
h.logger.Warn("get trace from storage: ", zap.Error(err))
490+
}
472491
if trace == nil {
473492
var m tlb.Message
474493
err = tlb.Unmarshal(c, &m)
@@ -499,7 +518,7 @@ func (h *Handler) EmulateMessageToTrace(ctx context.Context, request *oas.Emulat
499518
if err != nil {
500519
return nil, toError(http.StatusInternalServerError, err)
501520
}
502-
err = h.storage.SaveTraceWithState(hs, trace, []abi.MethodInvocation{}, 24*time.Hour)
521+
err = h.storage.SaveTraceWithState(ctx, hs, trace, []abi.MethodInvocation{}, 24*time.Hour)
503522
if err != nil {
504523
fmt.Println("trace not saved: ", err)
505524
}
@@ -591,7 +610,13 @@ func (h *Handler) EmulateMessageToWallet(ctx context.Context, request *oas.Emula
591610
}
592611

593612
hash, err := msgCell.HashString()
613+
if err != nil {
614+
return nil, toError(http.StatusBadRequest, err)
615+
}
594616
trace, _, err := h.storage.GetTraceWithState(ctx, hash)
617+
if err != nil {
618+
h.logger.Warn("get trace from storage: ", zap.Error(err))
619+
}
595620
if trace == nil {
596621
configBase64, err := h.storage.TrimmedConfigBase64()
597622
if err != nil {
@@ -633,7 +658,7 @@ func (h *Handler) EmulateMessageToWallet(ctx context.Context, request *oas.Emula
633658
if err != nil {
634659
return nil, toError(http.StatusInternalServerError, err)
635660
}
636-
err = h.storage.SaveTraceWithState(hash, trace, []abi.MethodInvocation{}, 24*time.Hour)
661+
err = h.storage.SaveTraceWithState(ctx, hash, trace, []abi.MethodInvocation{}, 24*time.Hour)
637662
if err != nil {
638663
fmt.Println("trace not saved: ", err)
639664
}

pkg/api/interfaces.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ type storage interface {
111111
GetAccountMultisigs(ctx context.Context, accountID ton.AccountID) ([]core.Multisig, error)
112112
GetMultisigByID(ctx context.Context, accountID ton.AccountID) (*core.Multisig, error)
113113

114-
SaveTraceWithState(msgHash string, trace *core.Trace, getMethods []abi.MethodInvocation, ttl time.Duration) error
114+
SaveTraceWithState(ctx context.Context, msgHash string, trace *core.Trace, getMethods []abi.MethodInvocation, ttl time.Duration) error
115115
GetTraceWithState(ctx context.Context, msgHash string) (*core.Trace, []abi.MethodInvocation, error)
116116

117117
liteStorageRaw

pkg/litestorage/litestorage.go

+8
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,11 @@ func (s *LiteStorage) GetAccountMultisigs(ctx context.Context, accountID ton.Acc
566566
func (s *LiteStorage) GetMultisigByID(ctx context.Context, accountID ton.AccountID) (*core.Multisig, error) {
567567
return nil, fmt.Errorf("not implemented")
568568
}
569+
570+
func (s *LiteStorage) SaveTraceWithState(ctx context.Context, msgHash string, trace *core.Trace, getMethods []abi.MethodInvocation, ttl time.Duration) error {
571+
return fmt.Errorf("not implemented")
572+
}
573+
574+
func (s *LiteStorage) GetTraceWithState(ctx context.Context, msgHash string) (*core.Trace, []abi.MethodInvocation, error) {
575+
return nil, nil, fmt.Errorf("not implemented")
576+
}

0 commit comments

Comments
 (0)