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] Make WebSocket responses from data providers consistent with Access REST API responses #6802

Merged
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3565546
Moved common used models to common rest models package, refactored re…
UlyanaAndrukhiv Dec 9, 2024
8716c92
Updated websocket response types for block headers and block digests,…
UlyanaAndrukhiv Dec 10, 2024
2785b93
Merge branch 'AndriiDiachuk/6588-events-data-provider' of github.com:…
UlyanaAndrukhiv Dec 10, 2024
e027b13
Updated blocks responses, added tests, merged with AndriiDiachuk/6588…
UlyanaAndrukhiv Dec 10, 2024
9d94c22
Updated websocket response for events
UlyanaAndrukhiv Dec 11, 2024
3f83d86
Merge branch 'AndriiDiachuk/6588-events-data-provider' of github.com:…
UlyanaAndrukhiv Dec 11, 2024
ada49d9
Updated websocket account statuses responses, updated tests
UlyanaAndrukhiv Dec 11, 2024
9795328
Merge branch 'AndriiDiachuk/6588-events-data-provider' of github.com:…
UlyanaAndrukhiv Dec 11, 2024
ad054f2
Merged with AndriiDiachuk/6588-events-data-provider
UlyanaAndrukhiv Dec 11, 2024
d3035cb
Added missed godoc
UlyanaAndrukhiv Dec 11, 2024
3d13ca2
Merged event response tests with AndriiDiachuk/6588-events-data-provider
UlyanaAndrukhiv Dec 11, 2024
ec025d6
Merged account statuses response tests with AndriiDiachuk/6588-events…
UlyanaAndrukhiv Dec 11, 2024
1033526
Fixed test, merged with AndriiDiachuk/6588-events-data-provider
UlyanaAndrukhiv Dec 11, 2024
396d87b
Linted, added more godoc
UlyanaAndrukhiv Dec 12, 2024
e1905d7
Added godoc for block digest rest model
UlyanaAndrukhiv Dec 12, 2024
8f184ca
Added helper Build for event response
UlyanaAndrukhiv Dec 12, 2024
5c4f672
Added account statuses response build helper
UlyanaAndrukhiv Dec 12, 2024
3f2906f
Updated unit tests to more readable
UlyanaAndrukhiv Dec 12, 2024
4f9df8c
Merge branch 'master' into UlyanaAndrukhiv/6775-websocket-responses
UlyanaAndrukhiv Dec 16, 2024
48802e1
Merged with AndriiDiachuk/6588-events-data-provider
UlyanaAndrukhiv Dec 17, 2024
1e16de9
Merge branch 'UlyanaAndrukhiv/6775-websocket-responses' of github.com…
UlyanaAndrukhiv Dec 17, 2024
9a34cb2
Merged with AndriiDiachuk/6586-tx-statuses-data-providers-impl
UlyanaAndrukhiv Dec 17, 2024
1b21753
Expanded block response by execution result for websockets, added test
UlyanaAndrukhiv Dec 18, 2024
504dbcc
Merged with master
UlyanaAndrukhiv Dec 18, 2024
fbeca5b
Merged with AndriiDiachuk/6588-events-data-provider
UlyanaAndrukhiv Dec 18, 2024
728bd92
Merge branch 'master' into UlyanaAndrukhiv/6775-websocket-responses
UlyanaAndrukhiv Dec 18, 2024
ee10bc9
Merge branch 'master' into UlyanaAndrukhiv/6775-websocket-responses
UlyanaAndrukhiv Dec 19, 2024
515db7b
Merge branch 'master' into UlyanaAndrukhiv/6775-websocket-responses
UlyanaAndrukhiv Dec 23, 2024
2704b94
Merged with AndriiDiachuk/6586-tx-statuses-data-providers-impl, updat…
UlyanaAndrukhiv Dec 26, 2024
3152ad7
Merge branch 'UlyanaAndrukhiv/6775-websocket-responses' of github.com…
UlyanaAndrukhiv Dec 26, 2024
6db6926
Merged with AndriiDiachuk/6586-tx-statuses-data-providers-impl
UlyanaAndrukhiv Dec 26, 2024
6a37fcd
Merge branch 'master' into UlyanaAndrukhiv/6775-websocket-responses
peterargue Dec 28, 2024
3909bcd
Merge branch 'master' into UlyanaAndrukhiv/6775-websocket-responses
UlyanaAndrukhiv Jan 2, 2025
ff8d51e
Merged with AndriiDiachuk/6586-tx-statuses-data-providers-impl
UlyanaAndrukhiv Jan 2, 2025
cbad3d9
Merge branch 'AndriiDiachuk/6586-tx-statuses-data-providers-impl' of …
UlyanaAndrukhiv Jan 2, 2025
8557068
Merge branch 'master' into UlyanaAndrukhiv/6775-websocket-responses
UlyanaAndrukhiv Jan 2, 2025
fd44611
Merge branch 'AndriiDiachuk/6586-tx-statuses-data-providers-impl' of …
UlyanaAndrukhiv Jan 2, 2025
526b248
Removed expand argument from websocket blocks subscription, removed e…
UlyanaAndrukhiv Jan 2, 2025
0eaf627
Merge branch 'master' into UlyanaAndrukhiv/6775-websocket-responses
UlyanaAndrukhiv Jan 2, 2025
10eb06f
Merge branch 'master' into UlyanaAndrukhiv/6775-websocket-responses
UlyanaAndrukhiv Jan 10, 2025
0fa3e8d
Merge branch 'master' into UlyanaAndrukhiv/6775-websocket-responses
UlyanaAndrukhiv Jan 13, 2025
a7a4c00
Merge branch 'master' into UlyanaAndrukhiv/6775-websocket-responses
peterargue Jan 13, 2025
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ generate-mocks: install-mock-generators
mockery --name 'BlockTracker' --dir="./engine/access/subscription" --case=underscore --output="./engine/access/subscription/mock" --outpkg="mock"
mockery --name 'DataProvider' --dir="./engine/access/rest/websockets/data_providers" --case=underscore --output="./engine/access/rest/websockets/data_providers/mock" --outpkg="mock"
mockery --name 'DataProviderFactory' --dir="./engine/access/rest/websockets/data_providers" --case=underscore --output="./engine/access/rest/websockets/data_providers/mock" --outpkg="mock"
mockery --name 'LinkGenerator' --dir="./engine/access/rest/common/models" --case=underscore --output="./engine/access/rest/common/models/mock" --outpkg="mock"
mockery --name 'WebsocketConnection' --dir="./engine/access/rest/websockets" --case=underscore --output="./engine/access/rest/websockets/mock" --outpkg="mock"
mockery --name 'ExecutionDataTracker' --dir="./engine/access/subscription" --case=underscore --output="./engine/access/subscription/mock" --outpkg="mock"
mockery --name 'ConnectionFactory' --dir="./engine/access/rpc/connection" --case=underscore --output="./engine/access/rpc/connection/mock" --outpkg="mock"
Expand All @@ -216,7 +217,6 @@ generate-mocks: install-mock-generators
mockery --name 'Storage' --dir=module/executiondatasync/tracker --case=underscore --output="module/executiondatasync/tracker/mock" --outpkg="mocktracker"
mockery --name 'ScriptExecutor' --dir=module/execution --case=underscore --output="module/execution/mock" --outpkg="mock"
mockery --name 'StorageSnapshot' --dir=fvm/storage/snapshot --case=underscore --output="fvm/storage/snapshot/mock" --outpkg="mock"
mockery --name 'WebsocketConnection' --dir=engine/access/rest/websockets --case=underscore --output="engine/access/rest/websockets/mock" --outpkg="mock"

#temporarily make insecure/ a non-module to allow mockery to create mocks
mv insecure/go.mod insecure/go2.mod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"github.com/onflow/flow-go/model/flow"
)

const ExpandableFieldPayload = "payload"
const ExpandableExecutionResult = "execution_result"

func (b *Block) Build(
block *flow.Block,
execResult *flow.ExecutionResult,
Expand All @@ -23,7 +26,6 @@ func (b *Block) Build(

// add the payload to the response if it is specified as an expandable field
b.Expandable = &BlockExpandable{}
const ExpandableFieldPayload = "payload"
if expand[ExpandableFieldPayload] {
var payload BlockPayload
err := payload.Build(block.Payload)
Expand All @@ -43,7 +45,6 @@ func (b *Block) Build(
// execution result might not yet exist
if execResult != nil {
// add the execution result to the response if it is specified as an expandable field
const ExpandableExecutionResult = "execution_result"
if expand[ExpandableExecutionResult] {
var exeResult ExecutionResult
err := exeResult.Build(execResult, link)
Expand Down
223 changes: 223 additions & 0 deletions engine/access/rest/common/models/mock/link_generator.go

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

10 changes: 1 addition & 9 deletions engine/access/rest/common/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Decorate(r *http.Request, chain flow.Chain) *Request {
}

if expandFields, found := middleware.GetFieldsToExpand(r); found {
decoratedReq.ExpandFields = sliceToMap(expandFields)
decoratedReq.ExpandFields = SliceToMap(expandFields)
}

if selectFields, found := middleware.GetFieldsToSelect(r); found {
Expand All @@ -64,14 +64,6 @@ func Decorate(r *http.Request, chain flow.Chain) *Request {
return decoratedReq
}

func sliceToMap(values []string) map[string]bool {
valueMap := make(map[string]bool, len(values))
for _, v := range values {
valueMap[v] = true
}
return valueMap
}

func toStringArray(in string) []string {
// currently, the swagger generated Go REST client is incorrectly doing a `fmt.Sprintf("%v", id)` for the id slice
// resulting in the client sending the ids in the format [id1 id2 id3...]. This is a temporary workaround to
Expand Down
11 changes: 11 additions & 0 deletions engine/access/rest/common/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package common

// SliceToMap converts a slice of strings into a map where each string
// in the slice becomes a key in the map with the value set to true.
func SliceToMap(values []string) map[string]bool {
valueMap := make(map[string]bool, len(values))
for _, v := range values {
valueMap[v] = true
}
return valueMap
}
2 changes: 1 addition & 1 deletion engine/access/rest/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/onflow/flow-go/access"
"github.com/onflow/flow-go/engine/access/rest/common"
"github.com/onflow/flow-go/engine/access/rest/http/models"
"github.com/onflow/flow-go/engine/access/rest/common/models"
"github.com/onflow/flow-go/engine/access/rest/util"
"github.com/onflow/flow-go/model/flow"
)
Expand Down
5 changes: 3 additions & 2 deletions engine/access/rest/http/models/account.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package models

import (
"github.com/onflow/flow-go/engine/access/rest/common/models"
"github.com/onflow/flow-go/engine/access/rest/util"
"github.com/onflow/flow-go/model/flow"
)

const expandableKeys = "keys"
const expandableContracts = "contracts"

func (a *Account) Build(flowAccount *flow.Account, link LinkGenerator, expand map[string]bool) error {
func (a *Account) Build(flowAccount *flow.Account, link models.LinkGenerator, expand map[string]bool) error {
a.Address = flowAccount.Address.String()
a.Balance = util.FromUint(flowAccount.Balance)
a.Expandable = &AccountExpandable{}
Expand All @@ -31,7 +32,7 @@ func (a *Account) Build(flowAccount *flow.Account, link LinkGenerator, expand ma
a.Expandable.Contracts = expandableContracts
}

var self Links
var self models.Links
err := self.Build(link.AccountLink(a.Address))
if err != nil {
return err
Expand Down
6 changes: 5 additions & 1 deletion engine/access/rest/http/models/model_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
*/
package models

import (
"github.com/onflow/flow-go/engine/access/rest/common/models"
)

type Account struct {
Address string `json:"address"`
// Flow balance of the account.
Balance string `json:"balance"`
Keys []AccountPublicKey `json:"keys,omitempty"`
Contracts map[string]string `json:"contracts,omitempty"`
Expandable *AccountExpandable `json:"_expandable"`
Links *Links `json:"_links,omitempty"`
Links *models.Links `json:"_links,omitempty"`
}
16 changes: 10 additions & 6 deletions engine/access/rest/http/models/model_transactions_body.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@
*/
package models

import (
"github.com/onflow/flow-go/engine/access/rest/common/models"
)

type TransactionsBody struct {
// Base64 encoded content of the Cadence script.
Script string `json:"script"`
// An array containing arguments each encoded as Base64 passed in the [JSON-Cadence interchange format](https://docs.onflow.org/cadence/json-cadence-spec/).
Arguments []string `json:"arguments"`
ReferenceBlockId string `json:"reference_block_id"`
// The limit on the amount of computation a transaction is allowed to preform.
GasLimit string `json:"gas_limit"`
Payer string `json:"payer"`
ProposalKey *ProposalKey `json:"proposal_key"`
Authorizers []string `json:"authorizers"`
PayloadSignatures []TransactionSignature `json:"payload_signatures"`
EnvelopeSignatures []TransactionSignature `json:"envelope_signatures"`
GasLimit string `json:"gas_limit"`
Payer string `json:"payer"`
ProposalKey *models.ProposalKey `json:"proposal_key"`
Authorizers []string `json:"authorizers"`
PayloadSignatures []models.TransactionSignature `json:"payload_signatures"`
EnvelopeSignatures []models.TransactionSignature `json:"envelope_signatures"`
}
2 changes: 1 addition & 1 deletion engine/access/rest/http/request/proposal_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package request
import (
"fmt"

"github.com/onflow/flow-go/engine/access/rest/http/models"
"github.com/onflow/flow-go/engine/access/rest/common/models"
"github.com/onflow/flow-go/engine/access/rest/util"
"github.com/onflow/flow-go/model/flow"
)
Expand Down
Loading
Loading