From 4e2dd1c585c9e09b3d46e4f7d46f468d5e38cd99 Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Tue, 8 Nov 2022 11:32:29 -0500 Subject: [PATCH] Add forward compatibility with Go 1.19 Signed-off-by: Nicko Guyer --- ffconfig/main.go | 5 ++--- internal/data/data_manager.go | 4 ++-- internal/events/aggregator_batch_state.go | 22 +++++++++---------- internal/events/tokens_approved.go | 10 ++++----- internal/events/tokens_transferred.go | 10 ++++----- .../events/websockets/websocket_connection.go | 4 ++-- internal/shareddownload/operations.go | 3 +-- internal/spievents/websockets.go | 4 ++-- internal/tokens/fftokens/fftokens.go | 5 +++-- pkg/core/pin.go | 1 - pkg/database/plugin.go | 2 -- pkg/dataexchange/plugin.go | 9 ++++---- test/e2e/client/restclient.go | 3 +-- test/e2e/common.go | 3 +-- test/e2e/stack.go | 10 ++++----- 15 files changed, 44 insertions(+), 51 deletions(-) diff --git a/ffconfig/main.go b/ffconfig/main.go index ba5b2c45e3..37ea351a66 100644 --- a/ffconfig/main.go +++ b/ffconfig/main.go @@ -18,7 +18,6 @@ package main import ( "fmt" - "io/ioutil" "os" "github.com/hyperledger/firefly/ffconfig/migrate" @@ -38,7 +37,7 @@ var migrateCommand = &cobra.Command{ Use: "migrate", Short: "Migrate a config file to the current version", RunE: func(cmd *cobra.Command, args []string) error { - cfg, err := ioutil.ReadFile(cfgFile) + cfg, err := os.ReadFile(cfgFile) if err != nil { return err } @@ -50,7 +49,7 @@ var migrateCommand = &cobra.Command{ fmt.Print(string(out)) return nil } - return ioutil.WriteFile(outFile, out, 0600) + return os.WriteFile(outFile, out, 0600) }, } diff --git a/internal/data/data_manager.go b/internal/data/data_manager.go index 95dd36218a..0ebade7a2a 100644 --- a/internal/data/data_manager.go +++ b/internal/data/data_manager.go @@ -186,8 +186,8 @@ func (dm *dataManager) getValidatorForDatatype(ctx context.Context, validator co } // GetMessageWithData performs a cached lookup of a message with all of the associated data. -// - Use this in performance sensitive code, but note mutable fields like the status of the -// message CANNOT be relied upon (due to the caching). +// - Use this in performance sensitive code, but note mutable fields like the status of the +// message CANNOT be relied upon (due to the caching). func (dm *dataManager) GetMessageWithDataCached(ctx context.Context, msgID *fftypes.UUID, options ...CacheReadOption) (msg *core.Message, data core.DataArray, foundAllData bool, err error) { if mce := dm.queryMessageCache(ctx, msgID, options...); mce != nil { return mce.msg, mce.data, true, nil diff --git a/internal/events/aggregator_batch_state.go b/internal/events/aggregator_batch_state.go index 02c440157e..eacb47a9f3 100644 --- a/internal/events/aggregator_batch_state.go +++ b/internal/events/aggregator_batch_state.go @@ -81,17 +81,17 @@ type dispatchedMessage struct { // batchState is the object that tracks the in-memory state that builds up while processing a batch of pins, // that needs to be reconciled at the point the batch closes. // There are three phases: -// 1. Dispatch: Determines if messages are blocked, or can be dispatched. Calls the appropriate dispatch -// actions for that message type. Reads initial `pin` state for contexts from the DB, and then -// updates this in-memory throughout the batch, ready for flushing in the Finalize phase. -// Runs in a database operation group/tranaction. -// 2. Pre-finalize: Runs any PreFinalize callbacks registered by the handlers in (1). -// Intended to be used for cross-microservice REST/GRPC etc. calls that have side-effects. -// Runs outside any database operation group/tranaction. -// 3. Finalize: Flushes the `pin` state calculated in phase (1), and any Finalize actions registered by handlers -// during phase (1) or (2). -// Runs in a database operation group/tranaction, which will be the same as phase (1) if there -// are no pre-finalize handlers registered. +// 1. Dispatch: Determines if messages are blocked, or can be dispatched. Calls the appropriate dispatch +// actions for that message type. Reads initial `pin` state for contexts from the DB, and then +// updates this in-memory throughout the batch, ready for flushing in the Finalize phase. +// Runs in a database operation group/tranaction. +// 2. Pre-finalize: Runs any PreFinalize callbacks registered by the handlers in (1). +// Intended to be used for cross-microservice REST/GRPC etc. calls that have side-effects. +// Runs outside any database operation group/tranaction. +// 3. Finalize: Flushes the `pin` state calculated in phase (1), and any Finalize actions registered by handlers +// during phase (1) or (2). +// Runs in a database operation group/tranaction, which will be the same as phase (1) if there +// are no pre-finalize handlers registered. type batchState struct { core.BatchState diff --git a/internal/events/tokens_approved.go b/internal/events/tokens_approved.go index 9c46500af6..40bf493e2a 100644 --- a/internal/events/tokens_approved.go +++ b/internal/events/tokens_approved.go @@ -31,11 +31,11 @@ import ( // This will ensure that the original LocalID provided to the user can later be used in a lookup, and also causes requests that // use "confirm=true" to resolve as expected. // Must follow these rules to reuse the LocalID: -// - The transaction ID on the approval must match a transaction+operation initiated by this node. -// - The connector and pool for this event must match the connector and pool targeted by the initial operation. Connectors are -// allowed to trigger side-effects in other pools, but only the event from the targeted pool should use the original LocalID. -// - The LocalID must not have been used yet. Connectors are allowed to emit multiple events in response to a single operation, -// but only the first of them can use the original LocalID. +// - The transaction ID on the approval must match a transaction+operation initiated by this node. +// - The connector and pool for this event must match the connector and pool targeted by the initial operation. Connectors are +// allowed to trigger side-effects in other pools, but only the event from the targeted pool should use the original LocalID. +// - The LocalID must not have been used yet. Connectors are allowed to emit multiple events in response to a single operation, +// but only the first of them can use the original LocalID. func (em *eventManager) loadApprovalID(ctx context.Context, tx *fftypes.UUID, approval *core.TokenApproval) (*fftypes.UUID, error) { // Find a matching operation within the transaction fb := database.OperationQueryFactory.NewFilter(ctx) diff --git a/internal/events/tokens_transferred.go b/internal/events/tokens_transferred.go index 2c8891a98a..48bf0d9c04 100644 --- a/internal/events/tokens_transferred.go +++ b/internal/events/tokens_transferred.go @@ -31,11 +31,11 @@ import ( // This will ensure that the original LocalID provided to the user can later be used in a lookup, and also causes requests that // use "confirm=true" to resolve as expected. // Must follow these rules to reuse the LocalID: -// - The transaction ID on the transfer must match a transaction+operation initiated by this node. -// - The connector and pool for this event must match the connector and pool targeted by the initial operation. Connectors are -// allowed to trigger side-effects in other pools, but only the event from the targeted pool should use the original LocalID. -// - The LocalID must not have been used yet. Connectors are allowed to emit multiple events in response to a single operation, -// but only the first of them can use the original LocalID. +// - The transaction ID on the transfer must match a transaction+operation initiated by this node. +// - The connector and pool for this event must match the connector and pool targeted by the initial operation. Connectors are +// allowed to trigger side-effects in other pools, but only the event from the targeted pool should use the original LocalID. +// - The LocalID must not have been used yet. Connectors are allowed to emit multiple events in response to a single operation, +// but only the first of them can use the original LocalID. func (em *eventManager) loadTransferID(ctx context.Context, tx *fftypes.UUID, transfer *core.TokenTransfer) (*fftypes.UUID, error) { // Find a matching operation within the transaction fb := database.OperationQueryFactory.NewFilter(ctx) diff --git a/internal/events/websockets/websocket_connection.go b/internal/events/websockets/websocket_connection.go index 22378315f5..9f287c32f8 100644 --- a/internal/events/websockets/websocket_connection.go +++ b/internal/events/websockets/websocket_connection.go @@ -19,7 +19,7 @@ package websockets import ( "context" "encoding/json" - "io/ioutil" + "io" "net/http" "sync" @@ -138,7 +138,7 @@ func (wc *websocketConnection) receiveLoop() { var msgHeader core.WSActionBase _, reader, err := wc.wsConn.NextReader() if err == nil { - msgData, err = ioutil.ReadAll(reader) + msgData, err = io.ReadAll(reader) if err == nil { err = json.Unmarshal(msgData, &msgHeader) if err != nil { diff --git a/internal/shareddownload/operations.go b/internal/shareddownload/operations.go index 356a900bbb..fac07ab990 100644 --- a/internal/shareddownload/operations.go +++ b/internal/shareddownload/operations.go @@ -19,7 +19,6 @@ package shareddownload import ( "context" "io" - "io/ioutil" "github.com/docker/go-units" "github.com/hyperledger/firefly-common/pkg/fftypes" @@ -122,7 +121,7 @@ func (dm *downloadManager) downloadBatch(ctx context.Context, data downloadBatch // Read from the stream up to the limit maxReadLimit := dm.broadcastBatchPayloadLimit + 1024 limitedReader := io.LimitReader(reader, maxReadLimit) - batchBytes, err := ioutil.ReadAll(limitedReader) + batchBytes, err := io.ReadAll(limitedReader) if err != nil { return nil, false, i18n.WrapError(ctx, err, coremsgs.MsgDownloadSharedFailed, data.PayloadRef) } diff --git a/internal/spievents/websockets.go b/internal/spievents/websockets.go index c82c65b5a9..c78b5630c4 100644 --- a/internal/spievents/websockets.go +++ b/internal/spievents/websockets.go @@ -19,7 +19,7 @@ package spievents import ( "context" "encoding/json" - "io/ioutil" + "io" "sync" "time" @@ -153,7 +153,7 @@ func (wc *webSocket) receiveLoop() { var cmd core.WSChangeEventCommand _, reader, err := wc.wsConn.NextReader() if err == nil { - msgData, err = ioutil.ReadAll(reader) + msgData, err = io.ReadAll(reader) if err == nil { err = json.Unmarshal(msgData, &cmd) } diff --git a/internal/tokens/fftokens/fftokens.go b/internal/tokens/fftokens/fftokens.go index 930ec3da78..ed22f1b813 100644 --- a/internal/tokens/fftokens/fftokens.go +++ b/internal/tokens/fftokens/fftokens.go @@ -560,9 +560,10 @@ func (ft *FFTokens) eventLoop() { } // Parse a JSON error of the form: -// {"error": "Bad Request", "message": "Field 'x' is required"} +// {"error": "Bad Request", "message": "Field 'x' is required"} // into a message of the form: -// "Bad Request: Field 'x' is required" +// +// "Bad Request: Field 'x' is required" func wrapError(ctx context.Context, errRes *tokenError, res *resty.Response, err error) error { if errRes != nil && errRes.Message != "" { if errRes.Error != "" { diff --git a/pkg/core/pin.go b/pkg/core/pin.go index b5bcc2c02e..9a12f1f21c 100644 --- a/pkg/core/pin.go +++ b/pkg/core/pin.go @@ -37,7 +37,6 @@ import "github.com/hyperledger/firefly-common/pkg/fftypes" // moving separately to the batch. If we get the private message, then the batch, // before receiving the blob data - we have to upgrade a batch-park, to a pin-park. // This is because the sequence must be in the order the pins arrive. -// type Pin struct { Sequence int64 `ffstruct:"Pin" json:"sequence"` Namespace string `ffstruct:"Pin" json:"namespace"` diff --git a/pkg/database/plugin.go b/pkg/database/plugin.go index 95d125ad4e..2c7d655d2b 100644 --- a/pkg/database/plugin.go +++ b/pkg/database/plugin.go @@ -522,7 +522,6 @@ type iChartCollection interface { // interface. // For SQL databases the process of adding a new database is simplified via the common SQL layer. // For NoSQL databases, the code should be straight forward to map the collections, indexes, and operations. -// type PersistenceInterface interface { core.Named @@ -655,7 +654,6 @@ type PostCompletionHook func() // Events are emitted locally to the individual FireFly core process. However, a WebSocket interface is // available for remote listening to these events. That allows the UI to listen to the events, as well as // providing a building block for a cluster of FireFly servers to directly propgate events to each other. -// type Callbacks interface { // OrderedUUIDCollectionNSEvent emits the sequence on insert, but it will be -1 on update OrderedUUIDCollectionNSEvent(resType OrderedUUIDCollectionNS, eventType core.ChangeEventType, namespace string, id *fftypes.UUID, sequence int64) diff --git a/pkg/dataexchange/plugin.go b/pkg/dataexchange/plugin.go index 96bdd4e351..81a1b15b52 100644 --- a/pkg/dataexchange/plugin.go +++ b/pkg/dataexchange/plugin.go @@ -47,13 +47,12 @@ import ( // - Can be stored and retrieved separately from their transfer // - Transfers are initiated via reference (not in-line data) // - Are hashed by the DX plugin using the same hashing algorithm as FireFly (SHA256) -// - DX plugins can mainain their own internal IDs for Blobs within the following requirements: +// - DX plugins can maintain their own internal IDs for Blobs within the following requirements: // - Given a namespace and ID, map to a "payloadRef" string (<1024chars) that allows that same payload to be retrieved using only that payloadRef -// - Example would be a logical filesystem path like "local/namespace/ID" -// - When data is recevied from other members in the network, be able to return the hash when provided with the remote peerID string, namespace and ID -// - Could be done by having a data store to resolve the transfers, or simply a deterministic path to metadata like "receive/peerID/namespace/ID" +// - Example would be a logical filesystem path like "local/namespace/ID" +// - When data is received from other members in the network, be able to return the hash when provided with the remote peerID string, namespace and ID +// - Could be done by having a data store to resolve the transfers, or simply a deterministic path to metadata like "receive/peerID/namespace/ID" // - Events triggered for arrival of blobs must contain the payloadRef, and the hash -// type Plugin interface { core.Named diff --git a/test/e2e/client/restclient.go b/test/e2e/client/restclient.go index a3bcc65cf4..625733095c 100644 --- a/test/e2e/client/restclient.go +++ b/test/e2e/client/restclient.go @@ -23,7 +23,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "math/big" "net/http" "net/url" @@ -222,7 +221,7 @@ func (client *FireFlyClient) GetBlob(t *testing.T, data *core.Data, expectedStat Get(path) require.NoError(t, err) require.Equal(t, expectedStatus, resp.StatusCode(), "GET %s [%d]: %s", path, resp.StatusCode(), resp.String()) - blob, err := ioutil.ReadAll(resp.RawBody()) + blob, err := io.ReadAll(resp.RawBody()) require.NoError(t, err) return blob } diff --git a/test/e2e/common.go b/test/e2e/common.go index 134ff53af0..0270f8fd0c 100644 --- a/test/e2e/common.go +++ b/test/e2e/common.go @@ -19,7 +19,6 @@ package e2e import ( "crypto/rand" "fmt" - "io/ioutil" "os" "testing" @@ -30,7 +29,7 @@ import ( ) func ReadConfig(t *testing.T, configFile string) map[string]interface{} { - yfile, err := ioutil.ReadFile(configFile) + yfile, err := os.ReadFile(configFile) assert.NoError(t, err) data := make(map[string]interface{}) err = yaml.Unmarshal(yfile, &data) diff --git a/test/e2e/stack.go b/test/e2e/stack.go index 74f3225112..c4f2d0963f 100644 --- a/test/e2e/stack.go +++ b/test/e2e/stack.go @@ -18,7 +18,7 @@ package e2e import ( "encoding/json" - "io/ioutil" + "os" ) type Stack struct { @@ -47,7 +47,7 @@ type Member struct { } func GetMemberPort(filename string, n int) (int, error) { - jsonBytes, err := ioutil.ReadFile(filename) + jsonBytes, err := os.ReadFile(filename) if err != nil { return 0, err } @@ -62,7 +62,7 @@ func GetMemberPort(filename string, n int) (int, error) { } func GetMemberHostname(filename string, n int) (string, error) { - jsonBytes, err := ioutil.ReadFile(filename) + jsonBytes, err := os.ReadFile(filename) if err != nil { return "", err } @@ -77,7 +77,7 @@ func GetMemberHostname(filename string, n int) (string, error) { } func ReadStackFile(filename string) (*Stack, error) { - jsonBytes, err := ioutil.ReadFile(filename) + jsonBytes, err := os.ReadFile(filename) if err != nil { return nil, err } @@ -100,7 +100,7 @@ func ReadStackFile(filename string) (*Stack, error) { } func ReadStackStateFile(filename string) (*StackState, error) { - jsonBytes, err := ioutil.ReadFile(filename) + jsonBytes, err := os.ReadFile(filename) if err != nil { return nil, err }