Skip to content

Commit 6779f1c

Browse files
authored
Merge pull request #600 from tonkeeper/hashes_format
fix block hash format
2 parents 74adc64 + f4815bd commit 6779f1c

File tree

2 files changed

+16
-32
lines changed

2 files changed

+16
-32
lines changed

pkg/api/liteserver_converters.go

+14-24
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,26 @@ func errChain(mappings ...error) error {
2323
return nil
2424
}
2525

26-
func convertMasterchainInfo(info liteclient.LiteServerMasterchainInfoC) (*oas.GetRawMasterchainInfoOK, error) {
26+
func convertMasterchainInfo(info liteclient.LiteServerMasterchainInfoC) *oas.GetRawMasterchainInfoOK {
2727
convertedInfo := oas.GetRawMasterchainInfoOK{
2828
Last: oas.BlockRaw{
2929
Workchain: int32(info.Last.Workchain),
3030
Shard: fmt.Sprintf("%016x", info.Last.Shard),
3131
Seqno: int32(info.Last.Seqno),
32+
RootHash: fmt.Sprintf("%x", info.Last.RootHash),
33+
FileHash: fmt.Sprintf("%x", info.Last.FileHash),
3234
},
3335
Init: oas.InitStateRaw{
3436
Workchain: int32(info.Init.Workchain),
37+
RootHash: fmt.Sprintf("%x", info.Init.RootHash),
38+
FileHash: fmt.Sprintf("%x", info.Init.FileHash),
3539
},
40+
StateRootHash: fmt.Sprintf("%x", info.StateRootHash),
3641
}
37-
err := errChain(
38-
toJson(&convertedInfo.Last.RootHash, info.Last.RootHash),
39-
toJson(&convertedInfo.Last.FileHash, info.Last.FileHash),
40-
toJson(&convertedInfo.StateRootHash, info.StateRootHash),
41-
toJson(&convertedInfo.Init.RootHash, info.Init.RootHash),
42-
toJson(&convertedInfo.Init.FileHash, info.Init.FileHash),
43-
)
44-
if err != nil {
45-
return nil, err
46-
}
47-
return &convertedInfo, nil
42+
return &convertedInfo
4843
}
4944

50-
func convertMasterchainInfoExt(info liteclient.LiteServerMasterchainInfoExtC) (*oas.GetRawMasterchainInfoExtOK, error) {
45+
func convertMasterchainInfoExt(info liteclient.LiteServerMasterchainInfoExtC) *oas.GetRawMasterchainInfoExtOK {
5146
convertedInfo := oas.GetRawMasterchainInfoExtOK{
5247
Mode: int32(info.Mode),
5348
Version: int32(info.Version),
@@ -56,24 +51,19 @@ func convertMasterchainInfoExt(info liteclient.LiteServerMasterchainInfoExtC) (*
5651
Workchain: int32(info.Last.Workchain),
5752
Shard: fmt.Sprintf("%016x", info.Last.Shard),
5853
Seqno: int32(info.Last.Seqno),
54+
RootHash: fmt.Sprintf("%x", info.Last.RootHash),
55+
FileHash: fmt.Sprintf("%x", info.Last.FileHash),
5956
},
6057
LastUtime: int32(info.LastUtime),
6158
Now: int32(info.Now),
6259
Init: oas.InitStateRaw{
6360
Workchain: int32(info.Init.Workchain),
61+
RootHash: fmt.Sprintf("%x", info.Init.RootHash),
62+
FileHash: fmt.Sprintf("%x", info.Init.FileHash),
6463
},
64+
StateRootHash: fmt.Sprintf("%x", info.StateRootHash),
6565
}
66-
err := errChain(
67-
toJson(&convertedInfo.Last.RootHash, info.Last.RootHash),
68-
toJson(&convertedInfo.Last.FileHash, info.Last.FileHash),
69-
toJson(&convertedInfo.StateRootHash, info.StateRootHash),
70-
toJson(&convertedInfo.Init.RootHash, info.Init.RootHash),
71-
toJson(&convertedInfo.Init.FileHash, info.Init.FileHash),
72-
)
73-
if err != nil {
74-
return nil, err
75-
}
76-
return &convertedInfo, nil
66+
return &convertedInfo
7767
}
7868

7969
func convertBlock(block liteclient.LiteServerBlockDataC) (*oas.GetRawBlockchainBlockOK, error) {

pkg/api/liteserver_handlers.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ func (h *Handler) GetRawMasterchainInfo(ctx context.Context) (*oas.GetRawMasterc
1616
if err != nil {
1717
return nil, toError(http.StatusInternalServerError, err)
1818
}
19-
resp, err := convertMasterchainInfo(info)
20-
if err != nil {
21-
return nil, toError(http.StatusInternalServerError, err)
22-
}
19+
resp := convertMasterchainInfo(info)
2320
return resp, nil
2421
}
2522

@@ -28,10 +25,7 @@ func (h *Handler) GetRawMasterchainInfoExt(ctx context.Context, params oas.GetRa
2825
if err != nil {
2926
return nil, toError(http.StatusBadRequest, err)
3027
}
31-
resp, err := convertMasterchainInfoExt(info)
32-
if err != nil {
33-
return nil, toError(http.StatusInternalServerError, err)
34-
}
28+
resp := convertMasterchainInfoExt(info)
3529
return resp, nil
3630
}
3731

0 commit comments

Comments
 (0)