Skip to content

Commit

Permalink
add more nil checks in intentions
Browse files Browse the repository at this point in the history
  • Loading branch information
erokhinav committed Oct 3, 2024
1 parent d192d0d commit d49e531
Showing 1 changed file with 53 additions and 11 deletions.
64 changes: 53 additions & 11 deletions pkg/bath/intentions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bath
import (
"github.com/tonkeeper/opentonapi/internal/g"
"github.com/tonkeeper/opentonapi/pkg/core"
"github.com/tonkeeper/tongo"
"github.com/tonkeeper/tongo/abi"
"github.com/tonkeeper/tongo/boc"
"golang.org/x/exp/slices"
Expand Down Expand Up @@ -203,34 +204,75 @@ func createActionFromMessage(msgOut OutMessage) Action {
var action Action
switch body := msgOut.body.(type) {
case abi.TextCommentMsgBody:
var sender tongo.AccountID
if msgOut.tx != nil {
sender = msgOut.tx.Account
}
action = Action{Type: TonTransfer, TonTransfer: &TonTransferAction{
Recipient: parseAccount(msgOut.messageRelaxed.MessageInternal.Dest).Address,
Sender: msgOut.tx.Account,
Sender: sender,
Comment: g.Pointer(string(body.Text))}}
if msgOut.mode < 128 {
if msgOut.mode < 128 && msgOut.tx != nil {
action.TonTransfer.Amount = int64(msgOut.messageRelaxed.MessageInternal.Value.Grams)
if msgOut.tx.EndBalance < action.TonTransfer.Amount {
action.Error = g.Pointer("Not enough balance")
}
}
case abi.NftTransferMsgBody:
bodyNewOwner := parseAccount(body.NewOwner)
var recipient *tongo.AccountID
if bodyNewOwner != nil {
recipient = &bodyNewOwner.Address
}
var sender *tongo.AccountID
if msgOut.tx != nil {
sender = &msgOut.tx.Account
}
dest := parseAccount(msgOut.messageRelaxed.MessageInternal.Dest)
var nft tongo.AccountID
if dest != nil {
nft = dest.Address
}
action = Action{Type: NftItemTransfer, NftItemTransfer: &NftTransferAction{
Recipient: &parseAccount(body.NewOwner).Address,
Sender: &msgOut.tx.Account,
Nft: parseAccount(msgOut.messageRelaxed.MessageInternal.Dest).Address,
Recipient: recipient,
Sender: sender,
Nft: nft,
}}
case abi.JettonTransferMsgBody:
bodyDest := parseAccount(body.Destination)
var recipient *tongo.AccountID
if bodyDest != nil {
recipient = &bodyDest.Address
}
dest := parseAccount(msgOut.messageRelaxed.MessageInternal.Dest)
var sendersWallet tongo.AccountID
if dest != nil {
sendersWallet = dest.Address
}
var sender *tongo.AccountID
if msgOut.tx != nil {
sender = &msgOut.tx.Account
}
action = Action{Type: JettonTransfer, JettonTransfer: &JettonTransferAction{
Recipient: &parseAccount(body.Destination).Address,
Sender: &msgOut.tx.Account,
Recipient: recipient,
Sender: sender,
Amount: body.Amount,
SendersWallet: parseAccount(msgOut.messageRelaxed.MessageInternal.Dest).Address,
SendersWallet: sendersWallet,
}}
default:
dest := parseAccount(msgOut.messageRelaxed.MessageInternal.Dest)
var recipient tongo.AccountID
if dest != nil {
recipient = dest.Address
}
var sender tongo.AccountID
if msgOut.tx != nil {
sender = msgOut.tx.Account
}
action = Action{Type: TonTransfer, TonTransfer: &TonTransferAction{
Recipient: parseAccount(msgOut.messageRelaxed.MessageInternal.Dest).Address,
Sender: msgOut.tx.Account}}
if msgOut.mode < 128 {
Recipient: recipient,
Sender: sender}}
if msgOut.mode < 128 && msgOut.tx != nil {
action.TonTransfer.Amount = int64(msgOut.messageRelaxed.MessageInternal.Value.Grams)
if msgOut.tx.EndBalance < action.TonTransfer.Amount {
action.Error = g.Pointer("Not enough balance")
Expand Down

0 comments on commit d49e531

Please sign in to comment.