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

[Access] Update model Block REST API Response #6884

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
19 changes: 18 additions & 1 deletion engine/access/rest/common/models/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,27 @@ func (b *Block) Build(
}

b.Links = self
b.BlockStatus = blockStatus.String()

var status BlockStatus
status.Build(blockStatus)
b.BlockStatus = &status

return nil
}

func (b *BlockStatus) Build(status flow.BlockStatus) {
switch status {
case flow.BlockStatusUnknown:
*b = BLOCK_UNKNOWN
case flow.BlockStatusFinalized:
*b = BLOCK_FINALIZED
case flow.BlockStatusSealed:
*b = BLOCK_SEALED
default:
*b = ""
}
}

func (b *BlockPayload) Build(payload *flow.Payload) error {
var blockSeal BlockSeals
err := blockSeal.Build(payload.Seals)
Expand Down
6 changes: 6 additions & 0 deletions engine/access/rest/common/models/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ const (
SUCCESS_RESULT = SUCCESS_TransactionExecution
FAILURE_RESULT = FAILURE_TransactionExecution
)

const (
BLOCK_UNKNOWN = UNKNOWN_BlockStatus
BLOCK_FINALIZED = FINALIZED_BlockStatus
BLOCK_SEALED = SEALED_BlockStatus
)
4 changes: 2 additions & 2 deletions engine/access/rest/common/models/model_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Block struct {
Header *BlockHeader `json:"header"`
Payload *BlockPayload `json:"payload,omitempty"`
ExecutionResult *ExecutionResult `json:"execution_result,omitempty"`
Expandable *BlockExpandable `json:"_expandable"`
Expandable *BlockExpandable `json:"_expandable,omitempty"`
Links *Links `json:"_links,omitempty"`
BlockStatus string `json:"block_status"`
BlockStatus *BlockStatus `json:"block_status"`
}
19 changes: 19 additions & 0 deletions engine/access/rest/common/models/model_block_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Access API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 1.0.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package models

// BlockStatus : This value indicates the status of a block.
type BlockStatus string

// List of BlockStatus
const (
UNKNOWN_BlockStatus BlockStatus = "BLOCK_UNKNOWN"
FINALIZED_BlockStatus BlockStatus = "BLOCK_FINALIZED"
SEALED_BlockStatus BlockStatus = "BLOCK_SEALED"
)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ require (
github.com/onflow/flow-core-contracts/lib/go/contracts v1.4.0
github.com/onflow/flow-core-contracts/lib/go/templates v1.4.0
github.com/onflow/flow-go-sdk v1.3.1
github.com/onflow/flow/protobuf/go/flow v0.4.7
github.com/onflow/flow/protobuf/go/flow v0.4.9
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
github.com/pierrec/lz4 v2.6.1+incompatible
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,8 @@ github.com/onflow/flow-nft/lib/go/contracts v1.2.2 h1:XFERNVUDGbZ4ViZjt7P1cGD80m
github.com/onflow/flow-nft/lib/go/contracts v1.2.2/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY=
github.com/onflow/flow-nft/lib/go/templates v1.2.1 h1:SAALMZPDw9Eb9p5kSLnmnFxjyig1MLiT4JUlLp0/bSE=
github.com/onflow/flow-nft/lib/go/templates v1.2.1/go.mod h1:W6hOWU0xltPqNpv9gQX8Pj8Jtf0OmRxc1XX2V0kzJaI=
github.com/onflow/flow/protobuf/go/flow v0.4.7 h1:iP6DFx4wZ3ETORsyeqzHu7neFT3d1CXF6wdK+AOOjmc=
github.com/onflow/flow/protobuf/go/flow v0.4.7/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk=
github.com/onflow/flow/protobuf/go/flow v0.4.9 h1:UfsWWqj6VQbEHvaw8kSGvIawCpEfz3gOGZfcdugNxVE=
github.com/onflow/flow/protobuf/go/flow v0.4.9/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk=
github.com/onflow/go-ethereum v1.14.7 h1:gg3awYqI02e3AypRdpJKEvNTJ6kz/OhAqRti0h54Wlc=
github.com/onflow/go-ethereum v1.14.7/go.mod h1:zV14QLrXyYu5ucvcwHUA0r6UaqveqbXaehAVQJlSW+I=
github.com/onflow/nft-storefront/lib/go/contracts v1.0.0 h1:sxyWLqGm/p4EKT6DUlQESDG1ZNMN9GjPCm1gTq7NGfc=
Expand Down
2 changes: 1 addition & 1 deletion insecure/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ require (
github.com/onflow/flow-go-sdk v1.3.1 // indirect
github.com/onflow/flow-nft/lib/go/contracts v1.2.2 // indirect
github.com/onflow/flow-nft/lib/go/templates v1.2.1 // indirect
github.com/onflow/flow/protobuf/go/flow v0.4.7 // indirect
github.com/onflow/flow/protobuf/go/flow v0.4.9 // indirect
github.com/onflow/go-ethereum v1.14.7 // indirect
github.com/onflow/nft-storefront/lib/go/contracts v1.0.0 // indirect
github.com/onflow/sdks v0.6.0-preview.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions insecure/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,8 @@ github.com/onflow/flow-nft/lib/go/contracts v1.2.2 h1:XFERNVUDGbZ4ViZjt7P1cGD80m
github.com/onflow/flow-nft/lib/go/contracts v1.2.2/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY=
github.com/onflow/flow-nft/lib/go/templates v1.2.1 h1:SAALMZPDw9Eb9p5kSLnmnFxjyig1MLiT4JUlLp0/bSE=
github.com/onflow/flow-nft/lib/go/templates v1.2.1/go.mod h1:W6hOWU0xltPqNpv9gQX8Pj8Jtf0OmRxc1XX2V0kzJaI=
github.com/onflow/flow/protobuf/go/flow v0.4.7 h1:iP6DFx4wZ3ETORsyeqzHu7neFT3d1CXF6wdK+AOOjmc=
github.com/onflow/flow/protobuf/go/flow v0.4.7/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk=
github.com/onflow/flow/protobuf/go/flow v0.4.9 h1:UfsWWqj6VQbEHvaw8kSGvIawCpEfz3gOGZfcdugNxVE=
github.com/onflow/flow/protobuf/go/flow v0.4.9/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk=
github.com/onflow/go-ethereum v1.14.7 h1:gg3awYqI02e3AypRdpJKEvNTJ6kz/OhAqRti0h54Wlc=
github.com/onflow/go-ethereum v1.14.7/go.mod h1:zV14QLrXyYu5ucvcwHUA0r6UaqveqbXaehAVQJlSW+I=
github.com/onflow/nft-storefront/lib/go/contracts v1.0.0 h1:sxyWLqGm/p4EKT6DUlQESDG1ZNMN9GjPCm1gTq7NGfc=
Expand Down
2 changes: 1 addition & 1 deletion integration/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/onflow/flow-go v0.38.0-preview.0.0.20241021221952-af9cd6e99de1
github.com/onflow/flow-go-sdk v1.3.1
github.com/onflow/flow-go/insecure v0.0.0-00010101000000-000000000000
github.com/onflow/flow/protobuf/go/flow v0.4.7
github.com/onflow/flow/protobuf/go/flow v0.4.9
github.com/onflow/go-ethereum v1.14.7
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/client_model v0.5.0
Expand Down
4 changes: 2 additions & 2 deletions integration/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,8 @@ github.com/onflow/flow-nft/lib/go/contracts v1.2.2 h1:XFERNVUDGbZ4ViZjt7P1cGD80m
github.com/onflow/flow-nft/lib/go/contracts v1.2.2/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY=
github.com/onflow/flow-nft/lib/go/templates v1.2.1 h1:SAALMZPDw9Eb9p5kSLnmnFxjyig1MLiT4JUlLp0/bSE=
github.com/onflow/flow-nft/lib/go/templates v1.2.1/go.mod h1:W6hOWU0xltPqNpv9gQX8Pj8Jtf0OmRxc1XX2V0kzJaI=
github.com/onflow/flow/protobuf/go/flow v0.4.7 h1:iP6DFx4wZ3ETORsyeqzHu7neFT3d1CXF6wdK+AOOjmc=
github.com/onflow/flow/protobuf/go/flow v0.4.7/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk=
github.com/onflow/flow/protobuf/go/flow v0.4.9 h1:UfsWWqj6VQbEHvaw8kSGvIawCpEfz3gOGZfcdugNxVE=
github.com/onflow/flow/protobuf/go/flow v0.4.9/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk=
github.com/onflow/go-ethereum v1.14.7 h1:gg3awYqI02e3AypRdpJKEvNTJ6kz/OhAqRti0h54Wlc=
github.com/onflow/go-ethereum v1.14.7/go.mod h1:zV14QLrXyYu5ucvcwHUA0r6UaqveqbXaehAVQJlSW+I=
github.com/onflow/nft-storefront/lib/go/contracts v1.0.0 h1:sxyWLqGm/p4EKT6DUlQESDG1ZNMN9GjPCm1gTq7NGfc=
Expand Down
Loading