Skip to content

Commit

Permalink
Merge pull request #568 from tonkeeper/account_source
Browse files Browse the repository at this point in the history
update the account inspection method to get the source
  • Loading branch information
mr-tron authored Dec 13, 2024
2 parents c4c038d + 7f6f90f commit 1f9e6c3
Show file tree
Hide file tree
Showing 9 changed files with 814 additions and 310 deletions.
88 changes: 71 additions & 17 deletions api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1531,35 +1531,28 @@
},
"compiler": {
"enum": [
"func"
"func",
"fift",
"tact"
],
"type": "string"
},
"methods": {
"items": {
"properties": {
"id": {
"format": "int64",
"type": "integer"
},
"method": {
"example": "get_something",
"type": "string"
}
},
"required": [
"id",
"method"
],
"type": "object"
"$ref": "#/components/schemas/Method"
},
"type": "array"
},
"source": {
"$ref": "#/components/schemas/Source"
}
},
"required": [
"code",
"code_hash",
"methods"
"methods",
"compiler",
"source"
],
"type": "object"
},
Expand Down Expand Up @@ -4318,6 +4311,23 @@
],
"type": "object"
},
"Method": {
"properties": {
"id": {
"format": "int64",
"type": "integer"
},
"method": {
"example": "get_something",
"type": "string"
}
},
"required": [
"id",
"method"
],
"type": "object"
},
"MethodExecutionResult": {
"properties": {
"decoded": {},
Expand Down Expand Up @@ -5364,6 +5374,50 @@
],
"type": "object"
},
"Source": {
"properties": {
"files": {
"items": {
"$ref": "#/components/schemas/SourceFile"
},
"type": "array"
}
},
"required": [
"files"
],
"type": "object"
},
"SourceFile": {
"properties": {
"content": {
"type": "string"
},
"include_in_command": {
"example": false,
"type": "boolean"
},
"is_entrypoint": {
"example": false,
"type": "boolean"
},
"is_std_lib": {
"example": false,
"type": "boolean"
},
"name": {
"type": "string"
}
},
"required": [
"name",
"content",
"is_entrypoint",
"is_std_lib",
"include_in_command"
],
"type": "object"
},
"StateInit": {
"properties": {
"boc": {
Expand Down
101 changes: 70 additions & 31 deletions api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7398,6 +7398,8 @@ components:
- code
- code_hash
- methods
- compiler
- source
properties:
code:
type: string
Expand All @@ -7407,21 +7409,15 @@ components:
methods:
type: array
items:
type: object
required:
- id
- method
properties:
id:
type: integer
format: int64
method:
type: string
example: "get_something"
$ref: '#/components/schemas/Method'
compiler:
type: string
enum:
- func
- fift
- tact
source:
$ref: '#/components/schemas/Source'
PoolImplementationType:
type: string
enum:
Expand Down Expand Up @@ -7473,26 +7469,69 @@ components:
format: int64
example: 1668436763
ExtraCurrency:
type: object
required:
- id
- amount
- decimals
properties:
id:
type: integer
example: 239
format: int32
amount:
type: string
x-js-format: bigint
example: "1000000000"
name:
type: string
example: FMS
decimals:
type: integer
example: 5
type: object
required:
- id
- amount
- decimals
properties:
id:
type: integer
example: 239
format: int32
amount:
type: string
x-js-format: bigint
example: "1000000000"
name:
type: string
example: FMS
decimals:
type: integer
example: 5
SourceFile:
type: object
required:
- name
- content
- is_entrypoint
- is_std_lib
- include_in_command
properties:
name:
type: string
content:
type: string
is_entrypoint:
type: boolean
example: false
is_std_lib:
type: boolean
example: false
include_in_command:
type: boolean
example: false
Source:
type: object
required:
- files
properties:
files:
type: array
items:
$ref: '#/components/schemas/SourceFile'
Method:
type: object
required:
- id
- method
properties:
id:
type: integer
format: int64
method:
type: string
example: "get_something"

responses:
Error:
Expand Down
22 changes: 19 additions & 3 deletions pkg/api/account_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"encoding/json"
"errors"
"fmt"
"golang.org/x/exp/slices"
"net/http"
"sort"
"strings"
"time"

"golang.org/x/exp/slices"

"github.com/cespare/xxhash/v2"
"github.com/go-faster/jx"
"github.com/tonkeeper/opentonapi/internal/g"
Expand Down Expand Up @@ -487,14 +488,29 @@ func (h *Handler) BlockchainAccountInspect(ctx context.Context, params oas.Block
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
source, err := h.verifierSource.GetAccountSource(account.ID)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
sourceFiles := make([]oas.SourceFile, len(source.Files))
for idx, file := range source.Files {
sourceFiles[idx] = oas.SourceFile{
Name: file.Name,
Content: file.Content,
IsEntrypoint: file.IsEntrypoint,
IsStdLib: file.IsStdLib,
IncludeInCommand: file.IncludeInCommand,
}
}
resp := oas.BlockchainAccountInspect{
Code: hex.EncodeToString(rawAccount.Code),
CodeHash: hex.EncodeToString(codeHash),
Compiler: oas.NewOptBlockchainAccountInspectCompiler(oas.BlockchainAccountInspectCompilerFunc),
Compiler: oas.BlockchainAccountInspectCompiler(source.Compiler),
Source: oas.Source{Files: sourceFiles},
}
for _, methodID := range methods {
if method, ok := code.Methods[methodID]; ok {
resp.Methods = append(resp.Methods, oas.BlockchainAccountInspectMethodsItem{
resp.Methods = append(resp.Methods, oas.Method{
ID: methodID,
Method: string(method),
})
Expand Down
45 changes: 29 additions & 16 deletions pkg/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/tonkeeper/opentonapi/pkg/chainstate"
"github.com/tonkeeper/opentonapi/pkg/core"
"github.com/tonkeeper/opentonapi/pkg/rates"
"github.com/tonkeeper/opentonapi/pkg/verifier"
"github.com/tonkeeper/tongo"
"github.com/tonkeeper/tongo/contract/dns"
"github.com/tonkeeper/tongo/tep64"
Expand Down Expand Up @@ -37,11 +38,12 @@ type Handler struct {
executor executor
gasless Gasless

limits Limits
spamFilter SpamFilter
ratesSource ratesSource
metaCache metadataCache
tonConnect *tonconnect.Server
limits Limits
spamFilter SpamFilter
ratesSource ratesSource
metaCache metadataCache
tonConnect *tonconnect.Server
verifierSource verifierSource

// mempoolEmulate contains results of emulation of messages that are in the mempool.
mempoolEmulate mempoolEmulate
Expand Down Expand Up @@ -80,6 +82,7 @@ type Options struct {
tonConnectSecret string
ctxToDetails ctxToDetails
gasless Gasless
verifier verifierSource
}

type Option func(o *Options)
Expand Down Expand Up @@ -149,6 +152,12 @@ func WithGasless(gasless Gasless) Option {
}
}

func WithVerifier(verifier verifierSource) Option {
return func(o *Options) {
o.verifier = verifier
}
}

func NewHandler(logger *zap.Logger, opts ...Option) (*Handler, error) {
options := &Options{}
for _, o := range opts {
Expand Down Expand Up @@ -181,6 +190,9 @@ func NewHandler(logger *zap.Logger, opts ...Option) (*Handler, error) {
if err != nil {
return nil, err
}
if options.verifier == nil {
options.verifier = verifier.NewVerifier()
}
configPool := &sync.Pool{
New: func() interface{} {
config, err := tvm.CreateConfig(configBase64)
Expand All @@ -195,17 +207,18 @@ func NewHandler(logger *zap.Logger, opts ...Option) (*Handler, error) {
return nil, fmt.Errorf("failed to init tonconnect")
}
return &Handler{
logger: logger,
storage: options.storage,
state: options.chainState,
addressBook: options.addressBook,
msgSender: options.msgSender,
executor: options.executor,
limits: options.limits,
spamFilter: options.spamFilter,
ctxToDetails: options.ctxToDetails,
gasless: options.gasless,
ratesSource: rates.InitCalculator(options.ratesSource),
logger: logger,
storage: options.storage,
state: options.chainState,
addressBook: options.addressBook,
msgSender: options.msgSender,
executor: options.executor,
limits: options.limits,
spamFilter: options.spamFilter,
ctxToDetails: options.ctxToDetails,
gasless: options.gasless,
verifierSource: options.verifier,
ratesSource: rates.InitCalculator(options.ratesSource),
metaCache: metadataCache{
collectionsCache: cache.NewLRUCache[tongo.AccountID, tep64.Metadata](10000, "nft_metadata_cache"),
jettonsCache: cache.NewLRUCache[tongo.AccountID, tep64.Metadata](10000, "jetton_metadata_cache"),
Expand Down
5 changes: 5 additions & 0 deletions pkg/api/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/tonkeeper/opentonapi/pkg/gasless"
"github.com/tonkeeper/opentonapi/pkg/oas"
"github.com/tonkeeper/opentonapi/pkg/verifier"
"github.com/tonkeeper/tongo"
"github.com/tonkeeper/tongo/abi"
"github.com/tonkeeper/tongo/boc"
Expand Down Expand Up @@ -184,6 +185,10 @@ type SpamFilter interface {
NftTrust(address tongo.AccountID, collection *ton.AccountID, description, image string) core.TrustType
}

type verifierSource interface {
GetAccountSource(accountID ton.AccountID) (verifier.Source, error)
}

type metadataCache struct {
collectionsCache cache.Cache[tongo.AccountID, tep64.Metadata]
jettonsCache cache.Cache[tongo.AccountID, tep64.Metadata]
Expand Down
Loading

0 comments on commit 1f9e6c3

Please sign in to comment.