Skip to content

Commit

Permalink
Merge pull request #189 from tonkeeper/add-jetton-preview-to-value-flow
Browse files Browse the repository at this point in the history
Add jetton preview to ValueFlow
  • Loading branch information
mr-tron authored Sep 11, 2023
2 parents e9f887c + 7d440b8 commit b95f247
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 18 deletions.
9 changes: 7 additions & 2 deletions api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3436,7 +3436,11 @@
"items": {
"properties": {
"account": {
"$ref": "#/components/schemas/AccountAddress"
"$ref": "#/components/schemas/AccountAddress",
"deprecated": true
},
"jetton": {
"$ref": "#/components/schemas/JettonPreview"
},
"quantity": {
"example": 10,
Expand All @@ -3446,7 +3450,8 @@
},
"required": [
"account",
"quantity"
"quantity",
"jetton"
],
"type": "object"
},
Expand Down
3 changes: 3 additions & 0 deletions api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3401,9 +3401,12 @@ components:
required:
- account
- quantity
- jetton
properties:
account:
$ref: '#/components/schemas/AccountAddress'
jetton:
$ref: '#/components/schemas/JettonPreview'
quantity:
type: integer
format: int64
Expand Down
23 changes: 19 additions & 4 deletions client/oas_json_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions client/oas_schemas_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions client/oas_validators_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions pkg/api/event_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"
"encoding/hex"
"fmt"
"github.com/tonkeeper/tongo/ton"
"math/big"
"strings"

"github.com/tonkeeper/tongo/ton"

"github.com/tonkeeper/opentonapi/pkg/references"

rules "github.com/tonkeeper/scam_backoffice_rules"
Expand Down Expand Up @@ -641,15 +642,16 @@ func (h Handler) convertAction(ctx context.Context, viewer *tongo.AccountID, a b
return action, spamDetected, nil
}

func convertAccountValueFlow(accountID tongo.AccountID, flow *bath.AccountValueFlow, book addressBook) oas.ValueFlow {
func convertAccountValueFlow(accountID tongo.AccountID, flow *bath.AccountValueFlow, book addressBook, previews map[tongo.AccountID]oas.JettonPreview) oas.ValueFlow {
valueFlow := oas.ValueFlow{
Account: convertAccountAddress(accountID, book),
Ton: flow.Ton,
Fees: flow.Fees,
}
for jettonItem, quantity := range flow.Jettons {
for jettonMaster, quantity := range flow.Jettons {
valueFlow.Jettons = append(valueFlow.Jettons, oas.ValueFlowJettonsItem{
Account: convertAccountAddress(jettonItem, book),
Account: convertAccountAddress(jettonMaster, book),
Jetton: previews[jettonMaster],
Quantity: quantity.Int64(),
})
}
Expand All @@ -674,8 +676,19 @@ func (h Handler) toEvent(ctx context.Context, trace *core.Trace, result *bath.Ac
event.IsScam = event.IsScam || spamDetected
event.Actions[i] = convertedAction
}

previews := make(map[tongo.AccountID]oas.JettonPreview)
for _, flow := range result.ValueFlow.Accounts {
for jettonMaster := range flow.Jettons {
if _, ok := previews[jettonMaster]; ok {
continue
}
meta := h.GetJettonNormalizedMetadata(ctx, jettonMaster)
previews[jettonMaster] = jettonPreview(jettonMaster, meta)
}
}
for accountID, flow := range result.ValueFlow.Accounts {
event.ValueFlow = append(event.ValueFlow, convertAccountValueFlow(accountID, flow, h.addressBook))
event.ValueFlow = append(event.ValueFlow, convertAccountValueFlow(accountID, flow, h.addressBook, previews))
}
return event, nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/bath/value_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (flow *ValueFlow) AddFee(accountID tongo.AccountID, amount int64) {
flow.Accounts[accountID] = &AccountValueFlow{Fees: amount}
}

func (flow *ValueFlow) AddJettons(accountID tongo.AccountID, jetton tongo.AccountID, value big.Int) {
func (flow *ValueFlow) AddJettons(accountID tongo.AccountID, jettonMaster tongo.AccountID, value big.Int) {
accountFlow, ok := flow.Accounts[accountID]
if !ok {
accountFlow = &AccountValueFlow{}
Expand All @@ -49,10 +49,10 @@ func (flow *ValueFlow) AddJettons(accountID tongo.AccountID, jetton tongo.Accoun
if accountFlow.Jettons == nil {
accountFlow.Jettons = make(map[tongo.AccountID]big.Int, 1)
}
current := accountFlow.Jettons[jetton]
current := accountFlow.Jettons[jettonMaster]
newValue := big.Int{}
newValue.Add(&current, &value)
accountFlow.Jettons[jetton] = newValue
accountFlow.Jettons[jettonMaster] = newValue
}

func (flow *ValueFlow) Merge(other *ValueFlow) {
Expand Down
23 changes: 19 additions & 4 deletions pkg/oas/oas_json_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions pkg/oas/oas_schemas_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b95f247

Please sign in to comment.