Skip to content

Commit 30720ea

Browse files
committed
get jetton master for wallet in intentions
1 parent e4107c9 commit 30720ea

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

pkg/api/event_handlers.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (h *Handler) GetEvent(ctx context.Context, params oas.GetEventParams) (*oas
186186
if err != nil {
187187
return nil, toError(http.StatusInternalServerError, err)
188188
}
189-
result := bath.EnrichWithIntentions(trace, actions)
189+
result := bath.EnrichWithIntentions(ctx, trace, actions, h.storage)
190190
event, err := h.toEvent(ctx, trace, result, params.AcceptLanguage)
191191
if err != nil {
192192
return nil, toError(http.StatusInternalServerError, err)
@@ -236,7 +236,7 @@ func (h *Handler) GetAccountEvents(ctx context.Context, params oas.GetAccountEve
236236
continue
237237
//return nil, toError(http.StatusInternalServerError, err)
238238
}
239-
result := bath.EnrichWithIntentions(trace, actions)
239+
result := bath.EnrichWithIntentions(ctx, trace, actions, h.storage)
240240
e, err := h.toAccountEvent(ctx, account.ID, trace, result, params.AcceptLanguage, params.SubjectOnly.Value)
241241
if err != nil {
242242
events = append(events, h.toUnknownAccountEvent(account.ID, traceID))
@@ -263,7 +263,7 @@ func (h *Handler) GetAccountEvents(ctx context.Context, params oas.GetAccountEve
263263
if err != nil {
264264
return nil, toError(http.StatusInternalServerError, err)
265265
}
266-
result := bath.EnrichWithIntentions(trace, actions)
266+
result := bath.EnrichWithIntentions(ctx, trace, actions, h.storage)
267267
event, err := h.toAccountEvent(ctx, account.ID, trace, result, params.AcceptLanguage, params.SubjectOnly.Value)
268268
if err != nil {
269269
return nil, toError(http.StatusInternalServerError, err)
@@ -314,7 +314,7 @@ func (h *Handler) GetAccountEvent(ctx context.Context, params oas.GetAccountEven
314314
if err != nil {
315315
return nil, toError(http.StatusInternalServerError, err)
316316
}
317-
result := bath.EnrichWithIntentions(trace, actions)
317+
result := bath.EnrichWithIntentions(ctx, trace, actions, h.storage)
318318
event, err := h.toAccountEvent(ctx, account.ID, trace, result, params.AcceptLanguage, params.SubjectOnly.Value)
319319
if err != nil {
320320
return nil, toError(http.StatusInternalServerError, err)
@@ -379,7 +379,7 @@ func (h *Handler) EmulateMessageToAccountEvent(ctx context.Context, request *oas
379379
if err != nil {
380380
return nil, toError(http.StatusInternalServerError, err)
381381
}
382-
result := bath.EnrichWithIntentions(trace, actions)
382+
result := bath.EnrichWithIntentions(ctx, trace, actions, h.storage)
383383
event, err := h.toAccountEvent(ctx, account.ID, trace, result, params.AcceptLanguage, false)
384384
if err != nil {
385385
return nil, toError(http.StatusInternalServerError, err)
@@ -431,7 +431,7 @@ func (h *Handler) EmulateMessageToEvent(ctx context.Context, request *oas.Emulat
431431
if err != nil {
432432
return nil, toError(http.StatusInternalServerError, err)
433433
}
434-
result := bath.EnrichWithIntentions(trace, actions)
434+
result := bath.EnrichWithIntentions(ctx, trace, actions, h.storage)
435435
event, err := h.toEvent(ctx, trace, result, params.AcceptLanguage)
436436
if err != nil {
437437
return nil, toError(http.StatusInternalServerError, err)
@@ -608,7 +608,7 @@ func (h *Handler) EmulateMessageToWallet(ctx context.Context, request *oas.Emula
608608
if err != nil {
609609
return nil, toError(http.StatusInternalServerError, err)
610610
}
611-
result := bath.EnrichWithIntentions(trace, actions)
611+
result := bath.EnrichWithIntentions(ctx, trace, actions, h.storage)
612612
event, err := h.toAccountEvent(ctx, *walletAddress, trace, result, params.AcceptLanguage, true)
613613
if err != nil {
614614
return nil, toError(http.StatusInternalServerError, err)

pkg/bath/bath_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ func TestFindActions(t *testing.T) {
448448
WithStraws(straws),
449449
WithInformationSource(source))
450450
require.Nil(t, err)
451-
actionsList = EnrichWithIntentions(trace, actionsList)
451+
actionsList = EnrichWithIntentions(context.Background(), trace, actionsList, source)
452452
results := result{
453453
Actions: actionsList.Actions,
454454
}

pkg/bath/intentions.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package bath
22

33
import (
4+
"context"
5+
"github.com/labstack/gommon/log"
46
"github.com/tonkeeper/opentonapi/internal/g"
57
"github.com/tonkeeper/opentonapi/pkg/core"
68
"github.com/tonkeeper/tongo"
@@ -17,14 +19,14 @@ type OutMessage struct {
1719
tx *core.Transaction
1820
}
1921

20-
func EnrichWithIntentions(trace *core.Trace, actions *ActionsList) *ActionsList {
22+
func EnrichWithIntentions(ctx context.Context, trace *core.Trace, actions *ActionsList, source core.InformationSource) *ActionsList {
2123
outMessages, inMsgCount := extractIntentions(trace)
2224
if len(outMessages) <= inMsgCount {
2325
return actions
2426
}
2527
outMessages = removeMatchedIntentions(trace, &outMessages)
2628
for _, outMsg := range outMessages {
27-
newAction := createActionFromMessage(outMsg)
29+
newAction := createActionFromMessage(ctx, outMsg, source)
2830
added := false
2931
for i, action := range actions.Actions {
3032
if slices.Contains(action.BaseTransactions, outMsg.tx.Hash) {
@@ -200,7 +202,7 @@ func getOutMessages(transaction *core.Transaction) []OutMessage {
200202
return messages
201203
}
202204

203-
func createActionFromMessage(msgOut OutMessage) Action {
205+
func createActionFromMessage(ctx context.Context, msgOut OutMessage, source core.InformationSource) Action {
204206
var action Action
205207
switch body := msgOut.body.(type) {
206208
case abi.TextCommentMsgBody:
@@ -258,11 +260,20 @@ func createActionFromMessage(msgOut OutMessage) Action {
258260
if msgOut.tx != nil {
259261
sender = &msgOut.tx.Account
260262
}
263+
var jetton tongo.AccountID
264+
masters, err := source.JettonMastersForWallets(ctx, []tongo.AccountID{sendersWallet})
265+
if err != nil {
266+
log.Warn("error getting jetton master: ", err)
267+
}
268+
if value, ok := masters[sendersWallet]; ok {
269+
jetton = value
270+
}
261271
action = Action{Type: JettonTransfer, JettonTransfer: &JettonTransferAction{
262272
Recipient: recipient,
263273
Sender: sender,
264274
Amount: body.Amount,
265275
SendersWallet: sendersWallet,
276+
Jetton: jetton,
266277
}}
267278
default:
268279
dest := parseAccount(msgOut.messageRelaxed.MessageInternal.Dest)

0 commit comments

Comments
 (0)