Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide jetton master for wallet in intentions #560

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pkg/api/event_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (h *Handler) GetEvent(ctx context.Context, params oas.GetEventParams) (*oas
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
result := bath.EnrichWithIntentions(trace, actions)
result := bath.EnrichWithIntentions(ctx, trace, actions, h.storage)
event, err := h.toEvent(ctx, trace, result, params.AcceptLanguage)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand Down Expand Up @@ -236,7 +236,7 @@ func (h *Handler) GetAccountEvents(ctx context.Context, params oas.GetAccountEve
continue
//return nil, toError(http.StatusInternalServerError, err)
}
result := bath.EnrichWithIntentions(trace, actions)
result := bath.EnrichWithIntentions(ctx, trace, actions, h.storage)
e, err := h.toAccountEvent(ctx, account.ID, trace, result, params.AcceptLanguage, params.SubjectOnly.Value)
if err != nil {
events = append(events, h.toUnknownAccountEvent(account.ID, traceID))
Expand All @@ -263,7 +263,7 @@ func (h *Handler) GetAccountEvents(ctx context.Context, params oas.GetAccountEve
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
result := bath.EnrichWithIntentions(trace, actions)
result := bath.EnrichWithIntentions(ctx, trace, actions, h.storage)
event, err := h.toAccountEvent(ctx, account.ID, trace, result, params.AcceptLanguage, params.SubjectOnly.Value)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand Down Expand Up @@ -314,7 +314,7 @@ func (h *Handler) GetAccountEvent(ctx context.Context, params oas.GetAccountEven
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
result := bath.EnrichWithIntentions(trace, actions)
result := bath.EnrichWithIntentions(ctx, trace, actions, h.storage)
event, err := h.toAccountEvent(ctx, account.ID, trace, result, params.AcceptLanguage, params.SubjectOnly.Value)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand Down Expand Up @@ -379,7 +379,7 @@ func (h *Handler) EmulateMessageToAccountEvent(ctx context.Context, request *oas
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
result := bath.EnrichWithIntentions(trace, actions)
result := bath.EnrichWithIntentions(ctx, trace, actions, h.storage)
event, err := h.toAccountEvent(ctx, account.ID, trace, result, params.AcceptLanguage, false)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand Down Expand Up @@ -431,7 +431,7 @@ func (h *Handler) EmulateMessageToEvent(ctx context.Context, request *oas.Emulat
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
result := bath.EnrichWithIntentions(trace, actions)
result := bath.EnrichWithIntentions(ctx, trace, actions, h.storage)
event, err := h.toEvent(ctx, trace, result, params.AcceptLanguage)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand Down Expand Up @@ -608,7 +608,7 @@ func (h *Handler) EmulateMessageToWallet(ctx context.Context, request *oas.Emula
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
result := bath.EnrichWithIntentions(trace, actions)
result := bath.EnrichWithIntentions(ctx, trace, actions, h.storage)
event, err := h.toAccountEvent(ctx, *walletAddress, trace, result, params.AcceptLanguage, true)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/bath/bath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func TestFindActions(t *testing.T) {
WithStraws(straws),
WithInformationSource(source))
require.Nil(t, err)
actionsList = EnrichWithIntentions(trace, actionsList)
actionsList = EnrichWithIntentions(context.Background(), trace, actionsList, source)
results := result{
Actions: actionsList.Actions,
}
Expand Down
17 changes: 14 additions & 3 deletions pkg/bath/intentions.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package bath

import (
"context"
"github.com/labstack/gommon/log"
"github.com/tonkeeper/opentonapi/internal/g"
"github.com/tonkeeper/opentonapi/pkg/core"
"github.com/tonkeeper/tongo"
Expand All @@ -17,14 +19,14 @@ type OutMessage struct {
tx *core.Transaction
}

func EnrichWithIntentions(trace *core.Trace, actions *ActionsList) *ActionsList {
func EnrichWithIntentions(ctx context.Context, trace *core.Trace, actions *ActionsList, source core.InformationSource) *ActionsList {
outMessages, inMsgCount := extractIntentions(trace)
if len(outMessages) <= inMsgCount {
return actions
}
outMessages = removeMatchedIntentions(trace, &outMessages)
for _, outMsg := range outMessages {
newAction := createActionFromMessage(outMsg)
newAction := createActionFromMessage(ctx, outMsg, source)
added := false
for i, action := range actions.Actions {
if slices.Contains(action.BaseTransactions, outMsg.tx.Hash) {
Expand Down Expand Up @@ -200,7 +202,7 @@ func getOutMessages(transaction *core.Transaction) []OutMessage {
return messages
}

func createActionFromMessage(msgOut OutMessage) Action {
func createActionFromMessage(ctx context.Context, msgOut OutMessage, source core.InformationSource) Action {
var action Action
switch body := msgOut.body.(type) {
case abi.TextCommentMsgBody:
Expand Down Expand Up @@ -258,11 +260,20 @@ func createActionFromMessage(msgOut OutMessage) Action {
if msgOut.tx != nil {
sender = &msgOut.tx.Account
}
var jetton tongo.AccountID
masters, err := source.JettonMastersForWallets(ctx, []tongo.AccountID{sendersWallet})
if err != nil {
log.Warn("error getting jetton master: ", err)
}
if value, ok := masters[sendersWallet]; ok {
jetton = value
}
action = Action{Type: JettonTransfer, JettonTransfer: &JettonTransferAction{
Recipient: recipient,
Sender: sender,
Amount: body.Amount,
SendersWallet: sendersWallet,
Jetton: jetton,
}}
default:
dest := parseAccount(msgOut.messageRelaxed.MessageInternal.Dest)
Expand Down
19 changes: 0 additions & 19 deletions pkg/bath/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,6 @@ func (ds BubbleWithdrawStake) ToAction() *Action {
}
}

var WithdrawStakeImmediatelyStraw = Straw[BubbleWithdrawStake]{
CheckFuncs: []bubbleCheck{Is(BubbleWithdrawStakeRequest{})},
Builder: func(newAction *BubbleWithdrawStake, bubble *Bubble) error {
req := bubble.Info.(BubbleWithdrawStakeRequest)
newAction.Pool = req.Pool
newAction.Staker = req.Staker
newAction.Amount = -req.attachedAmount
newAction.Implementation = req.Implementation
return nil
},
SingleChild: &Straw[BubbleWithdrawStake]{
CheckFuncs: []bubbleCheck{IsTx, AmountInterval(int64(ton.OneTON), 1<<63-1)},
Builder: func(newAction *BubbleWithdrawStake, bubble *Bubble) error {
newAction.Amount += bubble.Info.(BubbleTx).inputAmount
return nil
},
},
}

var DepositLiquidStakeStraw = Straw[BubbleDepositStake]{
CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.TonstakePoolDepositMsgOp)}, //todo: check interface HasInterface(abi.TonstakePool),
Builder: func(newAction *BubbleDepositStake, bubble *Bubble) error {
Expand Down
1 change: 0 additions & 1 deletion pkg/bath/straws.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ var DefaultStraws = []Merger{
ElectionsRecoverStakeStraw,
DepositTFStakeStraw,
WithdrawTFStakeRequestStraw,
WithdrawStakeImmediatelyStraw,
WithdrawLiquidStake,
DNSRenewStraw,
}
Expand Down
Loading