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

Order risk #500

Open
wants to merge 2 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
6 changes: 1 addition & 5 deletions pkg/api/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,7 @@ func (h *Handler) convertMultisig(ctx context.Context, item core.Multisig) (*oas
for _, account := range order.Signers {
signers = append(signers, account.ToRaw())
}
messages, err := convertMultisigActionsToRawMessages(order.Actions)
if err != nil {
return nil, err
}
risk, err := walletPkg.ExtractRiskFromRawMessages(messages)
risk, err := walletPkg.ExtractRiskFromActions(order.Actions)
if err != nil {
return nil, err
}
Expand Down
53 changes: 53 additions & 0 deletions pkg/wallet/risk.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,56 @@ func ExtractRiskFromRawMessages(rawMessages []tongoWallet.RawMessage) (*Risk, er
}
return &risk, nil
}

func ExtractRiskFromActions(actions []abi.MultisigSendMessageAction) (*Risk, error) {
risk := Risk{
TransferAllRemainingBalance: false,
Jettons: map[tongo.AccountID]big.Int{},
}
for _, action := range actions {
if action.SumType != "SendMessage" {
continue
}
if tongoWallet.IsMessageModeSet(int(action.SendMessage.Field0.Mode), tongoWallet.AttachAllRemainingBalance) {
risk.TransferAllRemainingBalance = true
}
m := action.SendMessage.Field0.Message
tonValue := uint64(m.MessageInternal.Value.Grams)
destination, err := ton.AccountIDFromTlb(m.MessageInternal.Dest)
if err != nil {
return nil, err
}
risk.Ton += tonValue
msgBody := m.MessageInternal.Body.Value.Value
if err != nil {
continue
}
switch x := msgBody.(type) {
case abi.NftTransferMsgBody:
if destination == nil {
continue
}
// here, destination is an NFT
risk.Nfts = append(risk.Nfts, *destination)
case abi.JettonBurnMsgBody:
if destination == nil {
continue
}
// here, destination is a jetton wallet
amount := big.Int(x.Amount)
currentJettons := risk.Jettons[*destination]
var total big.Int
risk.Jettons[*destination] = *total.Add(&currentJettons, &amount)
case abi.JettonTransferMsgBody:
if destination == nil {
continue
}
// here, destination is a jetton wallet
amount := big.Int(x.Amount)
currentJettons := risk.Jettons[*destination]
var total big.Int
risk.Jettons[*destination] = *total.Add(&currentJettons, &amount)
}
}
return &risk, nil
}
Loading