Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add DownloadBlockchainBlockBoc handler #603

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions api/openapi.json
Original file line number Diff line number Diff line change
@@ -6691,7 +6691,7 @@
},
"/v2/accounts/{account_id}/events/emulate": {
"post": {
"description": "Emulate sending message to blockchain",
"description": "Emulate sending message to retrieve account-specific events",
"operationId": "emulateMessageToAccountEvent",
"parameters": [
{
@@ -7683,6 +7683,44 @@
]
}
},
"/v2/blockchain/blocks/{block_id}/boc": {
"get": {
"description": "Download blockchain block BOC",
"operationId": "downloadBlockchainBlockBoc",
"parameters": [
{
"$ref": "#/components/parameters/blockchainBlockIDParameter"
}
],
"responses": {
"200": {
"content": {
"application/octet-stream": {
"schema": {
"format": "binary",
"type": "string"
}
}
},
"description": "Block BOC file",
"headers": {
"Content-Disposition": {
"schema": {
"example": "attachment; filename=\"block.boc\"",
"type": "string"
}
}
}
},
"default": {
"$ref": "#/components/responses/Error"
}
},
"tags": [
"Blockchain"
]
}
},
"/v2/blockchain/blocks/{block_id}/transactions": {
"get": {
"description": "Get transactions from block",
@@ -8181,7 +8219,7 @@
},
"/v2/events/emulate": {
"post": {
"description": "Emulate sending message to blockchain",
"description": "Emulate sending message to retrieve general blockchain events",
"operationId": "emulateMessageToEvent",
"parameters": [
{
@@ -10720,7 +10758,7 @@
},
"/v2/traces/emulate": {
"post": {
"description": "Emulate sending message to blockchain",
"description": "Emulate sending message to retrieve with a detailed execution trace",
"operationId": "emulateMessageToTrace",
"parameters": [
{
@@ -10823,7 +10861,7 @@
},
"/v2/wallet/emulate": {
"post": {
"description": "Emulate sending message to blockchain",
"description": "Emulate sending message to retrieve the resulting wallet state",
"operationId": "emulateMessageToWallet",
"parameters": [
{
23 changes: 23 additions & 0 deletions api/openapi.yml
Original file line number Diff line number Diff line change
@@ -168,6 +168,29 @@ paths:
$ref: '#/components/schemas/BlockchainBlock'
'default':
$ref: '#/components/responses/Error'
/v2/blockchain/blocks/{block_id}/boc:
get:
description: Download blockchain block BOC
operationId: downloadBlockchainBlockBoc
tags:
- Blockchain
parameters:
- $ref: '#/components/parameters/blockchainBlockIDParameter'
responses:
'200':
description: Block BOC file
content:
application/octet-stream:
schema:
type: string
format: binary
headers:
Content-Disposition:
schema:
type: string
example: 'attachment; filename="block.boc"'
'default':
$ref: '#/components/responses/Error'
/v2/blockchain/masterchain/{masterchain_seqno}/shards:
get:
description: Get blockchain block shards
20 changes: 20 additions & 0 deletions pkg/api/blockchain_handlers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"bytes"
"context"
"encoding/json"
"errors"
@@ -72,6 +73,25 @@ func (h *Handler) GetBlockchainBlock(ctx context.Context, params oas.GetBlockcha
return &res, nil
}

func (h *Handler) DownloadBlockchainBlockBoc(ctx context.Context, params oas.DownloadBlockchainBlockBocParams) (*oas.DownloadBlockchainBlockBocOKHeaders, error) {
blockID, err := ton.ParseBlockID(params.BlockID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
}

bocBytes, err := h.storage.GetBlockchainBlock(ctx, blockID)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}

return &oas.DownloadBlockchainBlockBocOKHeaders{
ContentDisposition: oas.NewOptString(fmt.Sprintf(`attachment; filename="block_%s.boc"`, params.BlockID)),
Response: oas.DownloadBlockchainBlockBocOK{
Data: bytes.NewReader(bocBytes),
},
}, nil
}

func (h *Handler) GetBlockchainMasterchainShards(ctx context.Context, params oas.GetBlockchainMasterchainShardsParams) (r *oas.BlockchainBlockShards, _ error) {
shards, err := h.storage.GetBlockShards(ctx, ton.BlockID{Shard: 0x8000000000000000, Seqno: uint32(params.MasterchainSeqno), Workchain: -1})
if errors.Is(err, core.ErrEntityNotFound) {
1 change: 1 addition & 0 deletions pkg/api/interfaces.go
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ type storage interface {
GetReducedBlocks(ctx context.Context, from, to int64) ([]core.ReducedBlock, error)
GetBlockShards(ctx context.Context, id tongo.BlockID) ([]ton.BlockID, error)
LastMasterchainBlockHeader(ctx context.Context) (*core.BlockHeader, error)
GetBlockchainBlock(ctx context.Context, blockID ton.BlockID) ([]byte, error)
GetTransaction(ctx context.Context, hash tongo.Bits256) (*core.Transaction, error)
SearchTransactionByMessageHash(ctx context.Context, hash tongo.Bits256) (*tongo.Bits256, error)
// GetBlockTransactions returns low-level information about transactions in a particular block.
12 changes: 12 additions & 0 deletions pkg/litestorage/litestorage.go
Original file line number Diff line number Diff line change
@@ -574,3 +574,15 @@ func (s *LiteStorage) SaveTraceWithState(ctx context.Context, msgHash string, tr
func (s *LiteStorage) GetTraceWithState(ctx context.Context, msgHash string) (*core.Trace, int, []abi.MethodInvocation, error) {
return nil, 0, nil, fmt.Errorf("not implemented")
}

func (s *LiteStorage) GetBlockchainBlock(ctx context.Context, id ton.BlockID) ([]byte, error) {
idExt, _, err := s.client.LookupBlock(ctx, id, 1, nil, nil)
if err != nil {
return nil, err
}
block, err := s.client.GetBlockRaw(ctx, idExt)
if err != nil {
return nil, err
}
return block.Data, nil
}
125 changes: 121 additions & 4 deletions pkg/oas/oas_handlers_gen.go

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

66 changes: 66 additions & 0 deletions pkg/oas/oas_parameters_gen.go

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

34 changes: 34 additions & 0 deletions pkg/oas/oas_response_encoders_gen.go
128 changes: 103 additions & 25 deletions pkg/oas/oas_router_gen.go
40 changes: 40 additions & 0 deletions pkg/oas/oas_schemas_gen.go
14 changes: 10 additions & 4 deletions pkg/oas/oas_server_gen.go
17 changes: 13 additions & 4 deletions pkg/oas/oas_unimplemented_gen.go