@@ -45,42 +45,51 @@ func ExtractRiskFromRawMessages(rawMessages []tongoWallet.RawMessage) (*Risk, er
45
45
if err := tlb .Unmarshal (rawMsg .Message , & m ); err != nil {
46
46
return nil , err
47
47
}
48
- tonValue := uint64 ( m . MessageInternal . Value . Grams )
49
- destination , err := ton . AccountIDFromTlb ( m . MessageInternal . Dest )
48
+ var err error
49
+ risk , err = ExtractRiskFromMessage ( m , risk , rawMsg . Mode )
50
50
if err != nil {
51
51
return nil , err
52
52
}
53
- risk .Ton += tonValue
54
- msgBody := m .MessageInternal .Body .Value .Value
55
- if err != nil {
56
- continue
53
+ }
54
+ return & risk , nil
55
+ }
56
+
57
+ func ExtractRiskFromMessage (m abi.MessageRelaxed , risk Risk , mode byte ) (Risk , error ) {
58
+ if tongoWallet .IsMessageModeSet (int (mode ), tongoWallet .AttachAllRemainingBalance ) {
59
+ risk .TransferAllRemainingBalance = true
60
+ }
61
+ tonValue := uint64 (m .MessageInternal .Value .Grams )
62
+ destination , err := ton .AccountIDFromTlb (m .MessageInternal .Dest )
63
+ if err != nil {
64
+ return Risk {}, err
65
+ }
66
+ risk .Ton += tonValue
67
+ msgBody := m .MessageInternal .Body .Value .Value
68
+ switch x := msgBody .(type ) {
69
+ case abi.NftTransferMsgBody :
70
+ if destination == nil {
71
+ return risk , err
57
72
}
58
- switch x := msgBody .(type ) {
59
- case abi.NftTransferMsgBody :
60
- if destination == nil {
61
- continue
62
- }
63
- // here, destination is an NFT
64
- risk .Nfts = append (risk .Nfts , * destination )
65
- case abi.JettonBurnMsgBody :
66
- if destination == nil {
67
- continue
68
- }
69
- // here, destination is a jetton wallet
70
- amount := big .Int (x .Amount )
71
- currentJettons := risk .Jettons [* destination ]
72
- var total big.Int
73
- risk .Jettons [* destination ] = * total .Add (& currentJettons , & amount )
74
- case abi.JettonTransferMsgBody :
75
- if destination == nil {
76
- continue
77
- }
78
- // here, destination is a jetton wallet
79
- amount := big .Int (x .Amount )
80
- currentJettons := risk .Jettons [* destination ]
81
- var total big.Int
82
- risk .Jettons [* destination ] = * total .Add (& currentJettons , & amount )
73
+ // here, destination is an NFT
74
+ risk .Nfts = append (risk .Nfts , * destination )
75
+ case abi.JettonBurnMsgBody :
76
+ if destination == nil {
77
+ return risk , err
83
78
}
79
+ // here, destination is a jetton wallet
80
+ amount := big .Int (x .Amount )
81
+ currentJettons := risk .Jettons [* destination ]
82
+ var total big.Int
83
+ risk .Jettons [* destination ] = * total .Add (& currentJettons , & amount )
84
+ case abi.JettonTransferMsgBody :
85
+ if destination == nil {
86
+ return risk , err
87
+ }
88
+ // here, destination is a jetton wallet
89
+ amount := big .Int (x .Amount )
90
+ currentJettons := risk .Jettons [* destination ]
91
+ var total big.Int
92
+ risk .Jettons [* destination ] = * total .Add (& currentJettons , & amount )
84
93
}
85
- return & risk , nil
94
+ return risk , err
86
95
}
0 commit comments