Skip to content

Commit 1f9e6c3

Browse files
authored
Merge pull request #568 from tonkeeper/account_source
update the account inspection method to get the source
2 parents c4c038d + 7f6f90f commit 1f9e6c3

9 files changed

+814
-310
lines changed

api/openapi.json

+71-17
Original file line numberDiff line numberDiff line change
@@ -1531,35 +1531,28 @@
15311531
},
15321532
"compiler": {
15331533
"enum": [
1534-
"func"
1534+
"func",
1535+
"fift",
1536+
"tact"
15351537
],
15361538
"type": "string"
15371539
},
15381540
"methods": {
15391541
"items": {
1540-
"properties": {
1541-
"id": {
1542-
"format": "int64",
1543-
"type": "integer"
1544-
},
1545-
"method": {
1546-
"example": "get_something",
1547-
"type": "string"
1548-
}
1549-
},
1550-
"required": [
1551-
"id",
1552-
"method"
1553-
],
1554-
"type": "object"
1542+
"$ref": "#/components/schemas/Method"
15551543
},
15561544
"type": "array"
1545+
},
1546+
"source": {
1547+
"$ref": "#/components/schemas/Source"
15571548
}
15581549
},
15591550
"required": [
15601551
"code",
15611552
"code_hash",
1562-
"methods"
1553+
"methods",
1554+
"compiler",
1555+
"source"
15631556
],
15641557
"type": "object"
15651558
},
@@ -4318,6 +4311,23 @@
43184311
],
43194312
"type": "object"
43204313
},
4314+
"Method": {
4315+
"properties": {
4316+
"id": {
4317+
"format": "int64",
4318+
"type": "integer"
4319+
},
4320+
"method": {
4321+
"example": "get_something",
4322+
"type": "string"
4323+
}
4324+
},
4325+
"required": [
4326+
"id",
4327+
"method"
4328+
],
4329+
"type": "object"
4330+
},
43214331
"MethodExecutionResult": {
43224332
"properties": {
43234333
"decoded": {},
@@ -5364,6 +5374,50 @@
53645374
],
53655375
"type": "object"
53665376
},
5377+
"Source": {
5378+
"properties": {
5379+
"files": {
5380+
"items": {
5381+
"$ref": "#/components/schemas/SourceFile"
5382+
},
5383+
"type": "array"
5384+
}
5385+
},
5386+
"required": [
5387+
"files"
5388+
],
5389+
"type": "object"
5390+
},
5391+
"SourceFile": {
5392+
"properties": {
5393+
"content": {
5394+
"type": "string"
5395+
},
5396+
"include_in_command": {
5397+
"example": false,
5398+
"type": "boolean"
5399+
},
5400+
"is_entrypoint": {
5401+
"example": false,
5402+
"type": "boolean"
5403+
},
5404+
"is_std_lib": {
5405+
"example": false,
5406+
"type": "boolean"
5407+
},
5408+
"name": {
5409+
"type": "string"
5410+
}
5411+
},
5412+
"required": [
5413+
"name",
5414+
"content",
5415+
"is_entrypoint",
5416+
"is_std_lib",
5417+
"include_in_command"
5418+
],
5419+
"type": "object"
5420+
},
53675421
"StateInit": {
53685422
"properties": {
53695423
"boc": {

api/openapi.yml

+70-31
Original file line numberDiff line numberDiff line change
@@ -7398,6 +7398,8 @@ components:
73987398
- code
73997399
- code_hash
74007400
- methods
7401+
- compiler
7402+
- source
74017403
properties:
74027404
code:
74037405
type: string
@@ -7407,21 +7409,15 @@ components:
74077409
methods:
74087410
type: array
74097411
items:
7410-
type: object
7411-
required:
7412-
- id
7413-
- method
7414-
properties:
7415-
id:
7416-
type: integer
7417-
format: int64
7418-
method:
7419-
type: string
7420-
example: "get_something"
7412+
$ref: '#/components/schemas/Method'
74217413
compiler:
74227414
type: string
74237415
enum:
74247416
- func
7417+
- fift
7418+
- tact
7419+
source:
7420+
$ref: '#/components/schemas/Source'
74257421
PoolImplementationType:
74267422
type: string
74277423
enum:
@@ -7473,26 +7469,69 @@ components:
74737469
format: int64
74747470
example: 1668436763
74757471
ExtraCurrency:
7476-
type: object
7477-
required:
7478-
- id
7479-
- amount
7480-
- decimals
7481-
properties:
7482-
id:
7483-
type: integer
7484-
example: 239
7485-
format: int32
7486-
amount:
7487-
type: string
7488-
x-js-format: bigint
7489-
example: "1000000000"
7490-
name:
7491-
type: string
7492-
example: FMS
7493-
decimals:
7494-
type: integer
7495-
example: 5
7472+
type: object
7473+
required:
7474+
- id
7475+
- amount
7476+
- decimals
7477+
properties:
7478+
id:
7479+
type: integer
7480+
example: 239
7481+
format: int32
7482+
amount:
7483+
type: string
7484+
x-js-format: bigint
7485+
example: "1000000000"
7486+
name:
7487+
type: string
7488+
example: FMS
7489+
decimals:
7490+
type: integer
7491+
example: 5
7492+
SourceFile:
7493+
type: object
7494+
required:
7495+
- name
7496+
- content
7497+
- is_entrypoint
7498+
- is_std_lib
7499+
- include_in_command
7500+
properties:
7501+
name:
7502+
type: string
7503+
content:
7504+
type: string
7505+
is_entrypoint:
7506+
type: boolean
7507+
example: false
7508+
is_std_lib:
7509+
type: boolean
7510+
example: false
7511+
include_in_command:
7512+
type: boolean
7513+
example: false
7514+
Source:
7515+
type: object
7516+
required:
7517+
- files
7518+
properties:
7519+
files:
7520+
type: array
7521+
items:
7522+
$ref: '#/components/schemas/SourceFile'
7523+
Method:
7524+
type: object
7525+
required:
7526+
- id
7527+
- method
7528+
properties:
7529+
id:
7530+
type: integer
7531+
format: int64
7532+
method:
7533+
type: string
7534+
example: "get_something"
74967535

74977536
responses:
74987537
Error:

pkg/api/account_handlers.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import (
88
"encoding/json"
99
"errors"
1010
"fmt"
11-
"golang.org/x/exp/slices"
1211
"net/http"
1312
"sort"
1413
"strings"
1514
"time"
1615

16+
"golang.org/x/exp/slices"
17+
1718
"github.com/cespare/xxhash/v2"
1819
"github.com/go-faster/jx"
1920
"github.com/tonkeeper/opentonapi/internal/g"
@@ -487,14 +488,29 @@ func (h *Handler) BlockchainAccountInspect(ctx context.Context, params oas.Block
487488
if err != nil {
488489
return nil, toError(http.StatusInternalServerError, err)
489490
}
491+
source, err := h.verifierSource.GetAccountSource(account.ID)
492+
if err != nil {
493+
return nil, toError(http.StatusInternalServerError, err)
494+
}
495+
sourceFiles := make([]oas.SourceFile, len(source.Files))
496+
for idx, file := range source.Files {
497+
sourceFiles[idx] = oas.SourceFile{
498+
Name: file.Name,
499+
Content: file.Content,
500+
IsEntrypoint: file.IsEntrypoint,
501+
IsStdLib: file.IsStdLib,
502+
IncludeInCommand: file.IncludeInCommand,
503+
}
504+
}
490505
resp := oas.BlockchainAccountInspect{
491506
Code: hex.EncodeToString(rawAccount.Code),
492507
CodeHash: hex.EncodeToString(codeHash),
493-
Compiler: oas.NewOptBlockchainAccountInspectCompiler(oas.BlockchainAccountInspectCompilerFunc),
508+
Compiler: oas.BlockchainAccountInspectCompiler(source.Compiler),
509+
Source: oas.Source{Files: sourceFiles},
494510
}
495511
for _, methodID := range methods {
496512
if method, ok := code.Methods[methodID]; ok {
497-
resp.Methods = append(resp.Methods, oas.BlockchainAccountInspectMethodsItem{
513+
resp.Methods = append(resp.Methods, oas.Method{
498514
ID: methodID,
499515
Method: string(method),
500516
})

pkg/api/handler.go

+29-16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/tonkeeper/opentonapi/pkg/chainstate"
1010
"github.com/tonkeeper/opentonapi/pkg/core"
1111
"github.com/tonkeeper/opentonapi/pkg/rates"
12+
"github.com/tonkeeper/opentonapi/pkg/verifier"
1213
"github.com/tonkeeper/tongo"
1314
"github.com/tonkeeper/tongo/contract/dns"
1415
"github.com/tonkeeper/tongo/tep64"
@@ -37,11 +38,12 @@ type Handler struct {
3738
executor executor
3839
gasless Gasless
3940

40-
limits Limits
41-
spamFilter SpamFilter
42-
ratesSource ratesSource
43-
metaCache metadataCache
44-
tonConnect *tonconnect.Server
41+
limits Limits
42+
spamFilter SpamFilter
43+
ratesSource ratesSource
44+
metaCache metadataCache
45+
tonConnect *tonconnect.Server
46+
verifierSource verifierSource
4547

4648
// mempoolEmulate contains results of emulation of messages that are in the mempool.
4749
mempoolEmulate mempoolEmulate
@@ -80,6 +82,7 @@ type Options struct {
8082
tonConnectSecret string
8183
ctxToDetails ctxToDetails
8284
gasless Gasless
85+
verifier verifierSource
8386
}
8487

8588
type Option func(o *Options)
@@ -149,6 +152,12 @@ func WithGasless(gasless Gasless) Option {
149152
}
150153
}
151154

155+
func WithVerifier(verifier verifierSource) Option {
156+
return func(o *Options) {
157+
o.verifier = verifier
158+
}
159+
}
160+
152161
func NewHandler(logger *zap.Logger, opts ...Option) (*Handler, error) {
153162
options := &Options{}
154163
for _, o := range opts {
@@ -181,6 +190,9 @@ func NewHandler(logger *zap.Logger, opts ...Option) (*Handler, error) {
181190
if err != nil {
182191
return nil, err
183192
}
193+
if options.verifier == nil {
194+
options.verifier = verifier.NewVerifier()
195+
}
184196
configPool := &sync.Pool{
185197
New: func() interface{} {
186198
config, err := tvm.CreateConfig(configBase64)
@@ -195,17 +207,18 @@ func NewHandler(logger *zap.Logger, opts ...Option) (*Handler, error) {
195207
return nil, fmt.Errorf("failed to init tonconnect")
196208
}
197209
return &Handler{
198-
logger: logger,
199-
storage: options.storage,
200-
state: options.chainState,
201-
addressBook: options.addressBook,
202-
msgSender: options.msgSender,
203-
executor: options.executor,
204-
limits: options.limits,
205-
spamFilter: options.spamFilter,
206-
ctxToDetails: options.ctxToDetails,
207-
gasless: options.gasless,
208-
ratesSource: rates.InitCalculator(options.ratesSource),
210+
logger: logger,
211+
storage: options.storage,
212+
state: options.chainState,
213+
addressBook: options.addressBook,
214+
msgSender: options.msgSender,
215+
executor: options.executor,
216+
limits: options.limits,
217+
spamFilter: options.spamFilter,
218+
ctxToDetails: options.ctxToDetails,
219+
gasless: options.gasless,
220+
verifierSource: options.verifier,
221+
ratesSource: rates.InitCalculator(options.ratesSource),
209222
metaCache: metadataCache{
210223
collectionsCache: cache.NewLRUCache[tongo.AccountID, tep64.Metadata](10000, "nft_metadata_cache"),
211224
jettonsCache: cache.NewLRUCache[tongo.AccountID, tep64.Metadata](10000, "jetton_metadata_cache"),

pkg/api/interfaces.go

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/tonkeeper/opentonapi/pkg/gasless"
88
"github.com/tonkeeper/opentonapi/pkg/oas"
9+
"github.com/tonkeeper/opentonapi/pkg/verifier"
910
"github.com/tonkeeper/tongo"
1011
"github.com/tonkeeper/tongo/abi"
1112
"github.com/tonkeeper/tongo/boc"
@@ -184,6 +185,10 @@ type SpamFilter interface {
184185
NftTrust(address tongo.AccountID, collection *ton.AccountID, description, image string) core.TrustType
185186
}
186187

188+
type verifierSource interface {
189+
GetAccountSource(accountID ton.AccountID) (verifier.Source, error)
190+
}
191+
187192
type metadataCache struct {
188193
collectionsCache cache.Cache[tongo.AccountID, tep64.Metadata]
189194
jettonsCache cache.Cache[tongo.AccountID, tep64.Metadata]

0 commit comments

Comments
 (0)