Skip to content

Commit 4a2d6c8

Browse files
committed
extra currency transfer action
1 parent 30eb0a1 commit 4a2d6c8

13 files changed

+907
-67
lines changed

api/openapi.json

+67
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,9 @@
10631063
"ElectionsRecoverStake": {
10641064
"$ref": "#/components/schemas/ElectionsRecoverStakeAction"
10651065
},
1066+
"ExtraCurrencyTransfer": {
1067+
"$ref": "#/components/schemas/ExtraCurrencyTransferAction"
1068+
},
10661069
"InscriptionMint": {
10671070
"$ref": "#/components/schemas/InscriptionMintAction"
10681071
},
@@ -1127,6 +1130,7 @@
11271130
"type": {
11281131
"enum": [
11291132
"TonTransfer",
1133+
"ExtraCurrencyTransfer",
11301134
"JettonTransfer",
11311135
"JettonBurn",
11321136
"JettonMint",
@@ -3119,6 +3123,33 @@
31193123
],
31203124
"type": "object"
31213125
},
3126+
"EcPreview": {
3127+
"properties": {
3128+
"decimals": {
3129+
"example": 5,
3130+
"type": "integer"
3131+
},
3132+
"image": {
3133+
"example": "https://cache.tonapi.io/images/extra.jpg",
3134+
"type": "string"
3135+
},
3136+
"name": {
3137+
"example": "FMS",
3138+
"type": "string"
3139+
},
3140+
"symbol": {
3141+
"example": "FMS",
3142+
"type": "string"
3143+
}
3144+
},
3145+
"required": [
3146+
"name",
3147+
"symbol",
3148+
"decimals",
3149+
"image"
3150+
],
3151+
"type": "object"
3152+
},
31223153
"ElectionsDepositStakeAction": {
31233154
"properties": {
31243155
"amount": {
@@ -3263,6 +3294,42 @@
32633294
],
32643295
"type": "object"
32653296
},
3297+
"ExtraCurrencyTransferAction": {
3298+
"properties": {
3299+
"amount": {
3300+
"description": "amount in quanta of tokens",
3301+
"example": "1000000000",
3302+
"type": "string",
3303+
"x-js-format": "bigint"
3304+
},
3305+
"comment": {
3306+
"example": "Hi! This is your salary. \nFrom accounting with love.",
3307+
"type": "string"
3308+
},
3309+
"currency": {
3310+
"$ref": "#/components/schemas/EcPreview"
3311+
},
3312+
"encrypted_comment": {
3313+
"$ref": "#/components/schemas/EncryptedComment"
3314+
},
3315+
"recipient": {
3316+
"$ref": "#/components/schemas/AccountAddress"
3317+
},
3318+
"refund": {
3319+
"$ref": "#/components/schemas/Refund"
3320+
},
3321+
"sender": {
3322+
"$ref": "#/components/schemas/AccountAddress"
3323+
}
3324+
},
3325+
"required": [
3326+
"sender",
3327+
"recipient",
3328+
"amount",
3329+
"currency"
3330+
],
3331+
"type": "object"
3332+
},
32663333
"FoundAccounts": {
32673334
"properties": {
32683335
"addresses": {

api/openapi.yml

+49
Original file line numberDiff line numberDiff line change
@@ -5744,6 +5744,7 @@ components:
57445744
example: "TonTransfer"
57455745
enum:
57465746
- TonTransfer
5747+
- ExtraCurrencyTransfer
57475748
- JettonTransfer
57485749
- JettonBurn
57495750
- JettonMint
@@ -5772,6 +5773,8 @@ components:
57725773
- failed
57735774
TonTransfer:
57745775
$ref: '#/components/schemas/TonTransferAction'
5776+
ExtraCurrencyTransfer:
5777+
$ref: '#/components/schemas/ExtraCurrencyTransferAction'
57755778
ContractDeploy:
57765779
$ref: '#/components/schemas/ContractDeployAction'
57775780
JettonTransfer:
@@ -5842,6 +5845,52 @@ components:
58425845
$ref: '#/components/schemas/EncryptedComment'
58435846
refund:
58445847
$ref: '#/components/schemas/Refund'
5848+
EcPreview:
5849+
type: object
5850+
required:
5851+
- name
5852+
- symbol
5853+
- decimals
5854+
- image
5855+
properties:
5856+
name:
5857+
type: string
5858+
example: FMS
5859+
symbol:
5860+
type: string
5861+
example: FMS
5862+
decimals:
5863+
type: integer
5864+
example: 5
5865+
image:
5866+
type: string
5867+
example: https://cache.tonapi.io/images/extra.jpg
5868+
ExtraCurrencyTransferAction:
5869+
type: object
5870+
required:
5871+
- sender
5872+
- recipient
5873+
- amount
5874+
- currency
5875+
properties:
5876+
sender:
5877+
$ref: '#/components/schemas/AccountAddress'
5878+
recipient:
5879+
$ref: '#/components/schemas/AccountAddress'
5880+
amount:
5881+
type: string
5882+
x-js-format: bigint
5883+
example: "1000000000"
5884+
description: amount in quanta of tokens
5885+
comment:
5886+
type: string
5887+
example: "Hi! This is your salary. \nFrom accounting with love."
5888+
encrypted_comment:
5889+
$ref: '#/components/schemas/EncryptedComment'
5890+
refund:
5891+
$ref: '#/components/schemas/Refund'
5892+
currency:
5893+
$ref: '#/components/schemas/EcPreview'
58455894
SmartContractAction:
58465895
type: object
58475896
required:

pkg/api/account_converters.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
imgGenerator "github.com/tonkeeper/opentonapi/pkg/image"
66
"github.com/tonkeeper/opentonapi/pkg/references"
7+
"math/big"
78
"sort"
89

910
"github.com/tonkeeper/tongo/abi"
@@ -60,7 +61,8 @@ func convertToRawAccount(account *core.Account) (oas.BlockchainRawAccount, error
6061
if account.ExtraBalances != nil {
6162
balances := make(map[string]string, len(account.ExtraBalances))
6263
for key, value := range account.ExtraBalances {
63-
balances[fmt.Sprintf("%v", int32(key))] = fmt.Sprintf("%v", value)
64+
v := big.Int(value)
65+
balances[fmt.Sprintf("%v", key)] = fmt.Sprintf("%v", v.String())
6466
}
6567
rawAccount.ExtraBalance = oas.NewOptBlockchainRawAccountExtraBalance(balances)
6668
}
@@ -76,15 +78,15 @@ func convertToRawAccount(account *core.Account) (oas.BlockchainRawAccount, error
7678
func convertExtraCurrencies(extraBalances core.ExtraCurrencies) []oas.ExtraCurrency {
7779
res := make([]oas.ExtraCurrency, 0, len(extraBalances))
7880
for k, v := range extraBalances {
81+
amount := big.Int(v)
82+
meta := references.GetExtraCurrencyMeta(k)
7983
cur := oas.ExtraCurrency{
80-
ID: int32(k),
81-
Amount: v.String(),
82-
Decimals: 9, // TODO: or replace with default const
84+
ID: k,
85+
Amount: amount.String(),
86+
Decimals: meta.Decimals,
8387
}
84-
meta, ok := references.ExtraCurrencies[int32(k)]
85-
if ok {
88+
if meta.Name != "" {
8689
cur.Name.SetTo(meta.Name)
87-
cur.Decimals = meta.Decimals
8890
}
8991
res = append(res, cur)
9092
}

pkg/api/event_converters.go

+34
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,38 @@ func (h *Handler) convertActionTonTransfer(t *bath.TonTransferAction, acceptLang
151151
return action, simplePreview
152152
}
153153

154+
func (h *Handler) convertActionExtraCurrencyTransfer(t *bath.ExtraCurrencyTransferAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptExtraCurrencyTransferAction, oas.ActionSimplePreview) {
155+
var action oas.OptExtraCurrencyTransferAction
156+
amount := big.Int(t.Amount)
157+
meta := references.GetExtraCurrencyMeta(t.CurrencyID)
158+
action.SetTo(oas.ExtraCurrencyTransferAction{
159+
Amount: amount.String(),
160+
Comment: g.Opt(t.Comment),
161+
Recipient: convertAccountAddress(t.Recipient, h.addressBook),
162+
Sender: convertAccountAddress(t.Sender, h.addressBook),
163+
EncryptedComment: convertEncryptedComment(t.EncryptedComment),
164+
Currency: oas.EcPreview{
165+
Name: meta.Name,
166+
Symbol: meta.Symbol,
167+
Decimals: meta.Decimals,
168+
Image: meta.Image,
169+
},
170+
})
171+
if t.Refund != nil {
172+
action.Value.Refund.SetTo(oas.Refund{
173+
Type: oas.RefundType(t.Refund.Type),
174+
Origin: t.Refund.Origin,
175+
})
176+
}
177+
simplePreview := oas.ActionSimplePreview{
178+
Name: "Extra Currency Transfer",
179+
Description: "", // TODO: add description
180+
Accounts: distinctAccounts(viewer, h.addressBook, &t.Sender, &t.Recipient),
181+
// TODO: add value
182+
}
183+
return action, simplePreview
184+
}
185+
154186
func (h *Handler) convertActionNftTransfer(t *bath.NftTransferAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptNftItemTransferAction, oas.ActionSimplePreview) {
155187
var action oas.OptNftItemTransferAction
156188
action.SetTo(oas.NftItemTransferAction{
@@ -428,6 +460,8 @@ func (h *Handler) convertAction(ctx context.Context, viewer *tongo.AccountID, a
428460
switch a.Type {
429461
case bath.TonTransfer:
430462
action.TonTransfer, action.SimplePreview = h.convertActionTonTransfer(a.TonTransfer, acceptLanguage.Value, viewer)
463+
case bath.ExtraCurrencyTransfer:
464+
action.ExtraCurrencyTransfer, action.SimplePreview = h.convertActionExtraCurrencyTransfer(a.ExtraCurrencyTransfer, acceptLanguage.Value, viewer)
431465
case bath.NftItemTransfer:
432466
action.NftItemTransfer, action.SimplePreview = h.convertActionNftTransfer(a.NftItemTransfer, acceptLanguage.Value, viewer)
433467
case bath.JettonTransfer:

pkg/bath/actions.go

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
const (
2121
TonTransfer ActionType = "TonTransfer"
22+
ExtraCurrencyTransfer ActionType = "ExtraCurrencyTransfer"
2223
SmartContractExec ActionType = "SmartContractExec"
2324
NftItemTransfer ActionType = "NftItemTransfer"
2425
NftPurchase ActionType = "NftPurchase"
@@ -69,6 +70,7 @@ type (
6970

7071
Action struct {
7172
TonTransfer *TonTransferAction `json:",omitempty"`
73+
ExtraCurrencyTransfer *ExtraCurrencyTransferAction `json:",omitempty"`
7274
SmartContractExec *SmartContractAction `json:",omitempty"`
7375
NftItemTransfer *NftTransferAction `json:",omitempty"`
7476
NftPurchase *NftPurchaseAction `json:",omitempty"`
@@ -101,6 +103,15 @@ type (
101103
Sender tongo.AccountID
102104
Refund *Refund
103105
}
106+
ExtraCurrencyTransferAction struct {
107+
CurrencyID int32
108+
Amount tlb.VarUInteger32
109+
Comment *string
110+
EncryptedComment *EncryptedComment
111+
Recipient tongo.AccountID
112+
Sender tongo.AccountID
113+
Refund *Refund
114+
}
104115
SmartContractAction struct {
105116
TonAttached int64
106117
Executor tongo.AccountID

pkg/bath/bubble.go

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func fromTrace(trace *core.Trace) *Bubble {
7878
btx.bounced = msg.Bounced
7979
btx.inputAmount += msg.Value
8080
btx.inputAmount += msg.IhrFee
81+
btx.inputExtraAmount = msg.ValueExtra
8182
btx.opCode = msg.OpCode
8283
btx.decodedBody = msg.DecodedBody
8384
btx.inputFrom = source
@@ -95,6 +96,7 @@ func fromTrace(trace *core.Trace) *Bubble {
9596
Children: make([]*Bubble, len(trace.Children)),
9697
ValueFlow: &ValueFlow{
9798
Accounts: map[tongo.AccountID]*AccountValueFlow{
99+
// TODO: add extra currency
98100
trace.Account: {
99101
Ton: inputAmount,
100102
},

0 commit comments

Comments
 (0)