Skip to content

Commit 6de0ae5

Browse files
committed
use litestorage as blocksource
1 parent 5477357 commit 6de0ae5

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

cmd/api/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func main() {
6969
api.WithExecutor(storage),
7070
api.WithMessageSender(msgSender),
7171
api.WithSpamFilter(spamFilter),
72+
api.WithBlocksSource(storage),
7273
api.WithTonConnectSecret(cfg.TonConnect.Secret),
7374
)
7475
if err != nil {

pkg/api/blockchain_handlers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (h *Handler) DownloadBlockchainBlockBoc(ctx context.Context, params oas.Dow
7979
return nil, toError(http.StatusBadRequest, err)
8080
}
8181

82-
bocBytes, err := h.blockSource.GetBlockchainBlock(ctx, blockID.Workchain, blockID.Shard, blockID.Seqno)
82+
bocBytes, err := h.blockSource.GetBlockchainBlock(ctx, blockID)
8383
if err != nil {
8484
return nil, toError(http.StatusInternalServerError, err)
8585
}

pkg/api/interfaces.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,5 @@ type mempoolEmulate struct {
215215
}
216216

217217
type blockSource interface {
218-
GetBlockchainBlock(ctx context.Context, workchain int32, shard uint64, seqno uint32) ([]byte, error)
218+
GetBlockchainBlock(ctx context.Context, id tongo.BlockID) ([]byte, error)
219219
}

pkg/litestorage/litestorage.go

+12
Original file line numberDiff line numberDiff line change
@@ -574,3 +574,15 @@ func (s *LiteStorage) SaveTraceWithState(ctx context.Context, msgHash string, tr
574574
func (s *LiteStorage) GetTraceWithState(ctx context.Context, msgHash string) (*core.Trace, int, []abi.MethodInvocation, error) {
575575
return nil, 0, nil, fmt.Errorf("not implemented")
576576
}
577+
578+
func (s *LiteStorage) GetBlockchainBlock(ctx context.Context, id tongo.BlockID) ([]byte, error) {
579+
idExt, _, err := s.client.LookupBlock(ctx, id, 1, nil, nil)
580+
if err != nil {
581+
return nil, err
582+
}
583+
block, err := s.client.GetBlockRaw(ctx, idExt)
584+
if err != nil {
585+
return nil, err
586+
}
587+
return block.Data, nil
588+
}

0 commit comments

Comments
 (0)