Skip to content

Commit 220f35e

Browse files
committed
fix comments
1 parent f218d63 commit 220f35e

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

pkg/api/event_handlers.go

+29-5
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,13 @@ func (h *Handler) EmulateMessageToAccountEvent(ctx context.Context, request *oas
392392
return nil, toError(http.StatusBadRequest, err)
393393
}
394394
hash, err := c.HashString()
395+
if err != nil {
396+
return nil, toError(http.StatusBadRequest, err)
397+
}
395398
trace, _, err := h.storage.GetTraceWithState(ctx, hash)
399+
if err != nil {
400+
h.logger.Warn("get trace from storage: ", zap.Error(err))
401+
}
396402
if trace == nil {
397403
configBase64, err := h.storage.TrimmedConfigBase64()
398404
if err != nil {
@@ -418,7 +424,7 @@ func (h *Handler) EmulateMessageToAccountEvent(ctx context.Context, request *oas
418424
if err != nil {
419425
return nil, toError(http.StatusInternalServerError, err)
420426
}
421-
err = h.storage.SaveTraceWithState(hash, trace, []abi.MethodInvocation{}, 24*time.Hour)
427+
err = h.storage.SaveTraceWithState(ctx, hash, trace, []abi.MethodInvocation{}, 24*time.Hour)
422428
if err != nil {
423429
fmt.Println("trace not saved: ", err)
424430
}
@@ -446,8 +452,14 @@ func (h *Handler) EmulateMessageToEvent(ctx context.Context, request *oas.Emulat
446452
}
447453
trace, prs := h.mempoolEmulate.traces.Get(hash)
448454
if !prs {
449-
hs, _ := c.HashString()
455+
hs, err := c.HashString()
456+
if err != nil {
457+
return nil, toError(http.StatusBadRequest, err)
458+
}
450459
trace, _, err = h.storage.GetTraceWithState(ctx, hs)
460+
if err != nil {
461+
h.logger.Warn("get trace from storage: ", zap.Error(err))
462+
}
451463
if trace == nil {
452464
var m tlb.Message
453465
if err := tlb.Unmarshal(c, &m); err != nil {
@@ -477,7 +489,7 @@ func (h *Handler) EmulateMessageToEvent(ctx context.Context, request *oas.Emulat
477489
if err != nil {
478490
return nil, toError(http.StatusInternalServerError, err)
479491
}
480-
err = h.storage.SaveTraceWithState(hs, trace, []abi.MethodInvocation{}, 24*time.Hour)
492+
err = h.storage.SaveTraceWithState(ctx, hs, trace, []abi.MethodInvocation{}, 24*time.Hour)
481493
if err != nil {
482494
fmt.Println("trace not saved: ", err)
483495
}
@@ -507,7 +519,13 @@ func (h *Handler) EmulateMessageToTrace(ctx context.Context, request *oas.Emulat
507519
trace, prs := h.mempoolEmulate.traces.Get(hash)
508520
if !prs {
509521
hs, err := c.HashString()
522+
if err != nil {
523+
return nil, toError(http.StatusBadRequest, err)
524+
}
510525
trace, _, err = h.storage.GetTraceWithState(ctx, hs)
526+
if err != nil {
527+
h.logger.Warn("get trace from storage: ", zap.Error(err))
528+
}
511529
if trace == nil {
512530
var m tlb.Message
513531
err = tlb.Unmarshal(c, &m)
@@ -538,7 +556,7 @@ func (h *Handler) EmulateMessageToTrace(ctx context.Context, request *oas.Emulat
538556
if err != nil {
539557
return nil, toError(http.StatusInternalServerError, err)
540558
}
541-
err = h.storage.SaveTraceWithState(hs, trace, []abi.MethodInvocation{}, 24*time.Hour)
559+
err = h.storage.SaveTraceWithState(ctx, hs, trace, []abi.MethodInvocation{}, 24*time.Hour)
542560
if err != nil {
543561
fmt.Println("trace not saved: ", err)
544562
}
@@ -630,7 +648,13 @@ func (h *Handler) EmulateMessageToWallet(ctx context.Context, request *oas.Emula
630648
}
631649

632650
hash, err := msgCell.HashString()
651+
if err != nil {
652+
return nil, toError(http.StatusBadRequest, err)
653+
}
633654
trace, _, err := h.storage.GetTraceWithState(ctx, hash)
655+
if err != nil {
656+
h.logger.Warn("get trace from storage: ", zap.Error(err))
657+
}
634658
if trace == nil {
635659
configBase64, err := h.storage.TrimmedConfigBase64()
636660
if err != nil {
@@ -672,7 +696,7 @@ func (h *Handler) EmulateMessageToWallet(ctx context.Context, request *oas.Emula
672696
if err != nil {
673697
return nil, toError(http.StatusInternalServerError, err)
674698
}
675-
err = h.storage.SaveTraceWithState(hash, trace, []abi.MethodInvocation{}, 24*time.Hour)
699+
err = h.storage.SaveTraceWithState(ctx, hash, trace, []abi.MethodInvocation{}, 24*time.Hour)
676700
if err != nil {
677701
fmt.Println("trace not saved: ", err)
678702
}

pkg/api/interfaces.go

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

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

118118
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)