Skip to content

Commit 9782db5

Browse files
committed
extra value for messages
1 parent 4b7f55c commit 9782db5

10 files changed

+96
-33
lines changed

api/openapi.json

+6
Original file line numberDiff line numberDiff line change
@@ -4211,6 +4211,12 @@
42114211
"format": "int64",
42124212
"type": "integer",
42134213
"x-js-format": "bigint"
4214+
},
4215+
"value_extra": {
4216+
"items": {
4217+
"$ref": "#/components/schemas/ExtraCurrency"
4218+
},
4219+
"type": "array"
42144220
}
42154221
},
42164222
"required": [

api/openapi.yml

+4
Original file line numberDiff line numberDiff line change
@@ -3723,6 +3723,10 @@ components:
37233723
format: int64
37243724
x-js-format: bigint
37253725
example: 60000000
3726+
value_extra:
3727+
type: array
3728+
items:
3729+
$ref: '#/components/schemas/ExtraCurrency'
37263730
fwd_fee:
37273731
type: integer
37283732
format: int64

pkg/api/account_converters.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package api
22

33
import (
44
"fmt"
5-
"github.com/shopspring/decimal"
65
imgGenerator "github.com/tonkeeper/opentonapi/pkg/image"
76
"github.com/tonkeeper/opentonapi/pkg/references"
87
"sort"
@@ -75,7 +74,7 @@ func convertToRawAccount(account *core.Account) (oas.BlockchainRawAccount, error
7574
return rawAccount, nil
7675
}
7776

78-
func convertExtraCurrencies(extraBalances map[uint32]decimal.Decimal) []oas.ExtraCurrency {
77+
func convertExtraCurrencies(extraBalances core.ExtraCurrencies) []oas.ExtraCurrency {
7978
res := make([]oas.ExtraCurrency, 0, len(extraBalances))
8079
for k, v := range extraBalances {
8180
cur := oas.ExtraCurrency{

pkg/api/blockchain_converters.go

+3
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ func convertMessage(m core.Message, book addressBook) oas.Message {
269269
value, _ := json.Marshal(m.DecodedBody.Value)
270270
msg.DecodedBody = g.ChangeJsonKeys(value, g.CamelToSnake)
271271
}
272+
if m.ValueExtra != nil {
273+
msg.ValueExtra = convertExtraCurrencies(m.ValueExtra)
274+
}
272275
return msg
273276
}
274277

pkg/core/account.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/tonkeeper/tongo/abi"
77
"github.com/tonkeeper/tongo/ton"
88

9-
"github.com/shopspring/decimal"
109
"github.com/tonkeeper/tongo/tlb"
1110
)
1211

@@ -15,7 +14,7 @@ type Account struct {
1514
AccountAddress ton.AccountID
1615
Status tlb.AccountStatus
1716
TonBalance int64
18-
ExtraBalances map[uint32]decimal.Decimal
17+
ExtraBalances ExtraCurrencies
1918
LastTransactionLt uint64
2019
LastTransactionHash ton.Bits256
2120
Code []byte

pkg/core/converters.go

+16-9
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ func ConvertMessage(message tlb.Message, txLT uint64, cd *abi.ContractDescriptio
313313
if err != nil {
314314
return Message{}, err
315315
}
316+
316317
return Message{
317318
MessageID: MessageID{
318319
CreatedLt: info.CreatedLt,
@@ -324,6 +325,7 @@ func ConvertMessage(message tlb.Message, txLT uint64, cd *abi.ContractDescriptio
324325
Bounce: info.Bounce,
325326
Bounced: info.Bounced,
326327
Value: int64(info.Value.Grams),
328+
ValueExtra: extractExtraCurrencies(info.Value.Other),
327329
FwdFee: int64(info.FwdFee),
328330
IhrFee: int64(info.IhrFee),
329331
ImportFee: 0,
@@ -434,15 +436,7 @@ func ConvertToAccount(accountId tongo.AccountID, shardAccount tlb.ShardAccount)
434436
}
435437
balance := acc.Account.Storage.Balance
436438
res.TonBalance = int64(balance.Grams)
437-
items := balance.Other.Dict.Items()
438-
if len(items) > 0 {
439-
otherBalances := make(map[uint32]decimal.Decimal, len(items))
440-
for _, item := range items {
441-
value := big.Int(item.Value)
442-
otherBalances[uint32(item.Key)] = decimal.NewFromBigInt(&value, 0)
443-
}
444-
res.ExtraBalances = otherBalances
445-
}
439+
res.ExtraBalances = extractExtraCurrencies(balance.Other)
446440
res.LastTransactionLt = shardAccount.LastTransLt
447441
res.LastTransactionHash = tongo.Bits256(shardAccount.LastTransHash)
448442
if acc.Account.Storage.State.SumType == "AccountUninit" {
@@ -481,6 +475,19 @@ func ConvertToAccount(accountId tongo.AccountID, shardAccount tlb.ShardAccount)
481475
return res, nil
482476
}
483477

478+
func extractExtraCurrencies(extraCurrencyCollection tlb.ExtraCurrencyCollection) ExtraCurrencies {
479+
items := extraCurrencyCollection.Dict.Items()
480+
if len(items) > 0 {
481+
res := make(map[uint32]decimal.Decimal, len(items))
482+
for _, item := range items {
483+
value := big.Int(item.Value)
484+
res[uint32(item.Key)] = decimal.NewFromBigInt(&value, 0)
485+
}
486+
return res
487+
}
488+
return nil // TODO: or return empty map
489+
}
490+
484491
func ExtractTransactions(id tongo.BlockIDExt, block *tlb.Block) ([]*Transaction, error) {
485492
rawTransactions := block.AllTransactions()
486493
transactions := make([]*Transaction, 0, len(rawTransactions))

pkg/core/extra_currencies.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package core
2+
3+
import "github.com/shopspring/decimal"
4+
5+
type ExtraCurrencies map[uint32]decimal.Decimal

pkg/core/transactions.go

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ type Message struct {
163163
Bounce bool
164164
Bounced bool
165165
Value int64
166+
ValueExtra ExtraCurrencies
166167
FwdFee int64
167168
IhrFee int64
168169
ImportFee int64

pkg/oas/oas_json_gen.go

+48-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/oas/oas_schemas_gen.go

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)