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

fix block hash format #600

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
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
38 changes: 14 additions & 24 deletions pkg/api/liteserver_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,26 @@ func errChain(mappings ...error) error {
return nil
}

func convertMasterchainInfo(info liteclient.LiteServerMasterchainInfoC) (*oas.GetRawMasterchainInfoOK, error) {
func convertMasterchainInfo(info liteclient.LiteServerMasterchainInfoC) *oas.GetRawMasterchainInfoOK {
convertedInfo := oas.GetRawMasterchainInfoOK{
Last: oas.BlockRaw{
Workchain: int32(info.Last.Workchain),
Shard: fmt.Sprintf("%016x", info.Last.Shard),
Seqno: int32(info.Last.Seqno),
RootHash: fmt.Sprintf("%x", info.Last.RootHash),
FileHash: fmt.Sprintf("%x", info.Last.FileHash),
},
Init: oas.InitStateRaw{
Workchain: int32(info.Init.Workchain),
RootHash: fmt.Sprintf("%x", info.Init.RootHash),
FileHash: fmt.Sprintf("%x", info.Init.FileHash),
},
StateRootHash: fmt.Sprintf("%x", info.StateRootHash),
}
err := errChain(
toJson(&convertedInfo.Last.RootHash, info.Last.RootHash),
toJson(&convertedInfo.Last.FileHash, info.Last.FileHash),
toJson(&convertedInfo.StateRootHash, info.StateRootHash),
toJson(&convertedInfo.Init.RootHash, info.Init.RootHash),
toJson(&convertedInfo.Init.FileHash, info.Init.FileHash),
)
if err != nil {
return nil, err
}
return &convertedInfo, nil
return &convertedInfo
}

func convertMasterchainInfoExt(info liteclient.LiteServerMasterchainInfoExtC) (*oas.GetRawMasterchainInfoExtOK, error) {
func convertMasterchainInfoExt(info liteclient.LiteServerMasterchainInfoExtC) *oas.GetRawMasterchainInfoExtOK {
convertedInfo := oas.GetRawMasterchainInfoExtOK{
Mode: int32(info.Mode),
Version: int32(info.Version),
Expand All @@ -56,24 +51,19 @@ func convertMasterchainInfoExt(info liteclient.LiteServerMasterchainInfoExtC) (*
Workchain: int32(info.Last.Workchain),
Shard: fmt.Sprintf("%016x", info.Last.Shard),
Seqno: int32(info.Last.Seqno),
RootHash: fmt.Sprintf("%x", info.Last.RootHash),
FileHash: fmt.Sprintf("%x", info.Last.FileHash),
},
LastUtime: int32(info.LastUtime),
Now: int32(info.Now),
Init: oas.InitStateRaw{
Workchain: int32(info.Init.Workchain),
RootHash: fmt.Sprintf("%x", info.Init.RootHash),
FileHash: fmt.Sprintf("%x", info.Init.FileHash),
},
StateRootHash: fmt.Sprintf("%x", info.StateRootHash),
}
err := errChain(
toJson(&convertedInfo.Last.RootHash, info.Last.RootHash),
toJson(&convertedInfo.Last.FileHash, info.Last.FileHash),
toJson(&convertedInfo.StateRootHash, info.StateRootHash),
toJson(&convertedInfo.Init.RootHash, info.Init.RootHash),
toJson(&convertedInfo.Init.FileHash, info.Init.FileHash),
)
if err != nil {
return nil, err
}
return &convertedInfo, nil
return &convertedInfo
}

func convertBlock(block liteclient.LiteServerBlockDataC) (*oas.GetRawBlockchainBlockOK, error) {
Expand Down
10 changes: 2 additions & 8 deletions pkg/api/liteserver_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ func (h *Handler) GetRawMasterchainInfo(ctx context.Context) (*oas.GetRawMasterc
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
resp, err := convertMasterchainInfo(info)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
resp := convertMasterchainInfo(info)
return resp, nil
}

Expand All @@ -28,10 +25,7 @@ func (h *Handler) GetRawMasterchainInfoExt(ctx context.Context, params oas.GetRa
if err != nil {
return nil, toError(http.StatusBadRequest, err)
}
resp, err := convertMasterchainInfoExt(info)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
resp := convertMasterchainInfoExt(info)
return resp, nil
}

Expand Down
Loading