From 7b3334778f44e98e50bf6b0deb5a04a7a89a03de Mon Sep 17 00:00:00 2001 From: Devon Hudson Date: Tue, 31 Jan 2023 12:31:57 -0700 Subject: [PATCH] Use gmsl relay_txn response type --- relayapi/internal/perform.go | 4 ++-- relayapi/internal/perform_test.go | 4 ++-- relayapi/routing/relaytxn.go | 10 ++-------- relayapi/routing/relaytxn_test.go | 12 ++++++------ 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/relayapi/internal/perform.go b/relayapi/internal/perform.go index c00d0d0ed..62c7d446e 100644 --- a/relayapi/internal/perform.go +++ b/relayapi/internal/perform.go @@ -52,7 +52,7 @@ func (r *RelayInternalAPI) PerformRelayServerSync( logrus.Errorf("P2PGetTransactionFromRelay: %s", err.Error()) return err } - r.processTransaction(&asyncResponse.Txn) + r.processTransaction(&asyncResponse.Transaction) prevEntry = gomatrixserverlib.RelayEntry{EntryID: asyncResponse.EntryID} for asyncResponse.EntriesQueued { @@ -64,7 +64,7 @@ func (r *RelayInternalAPI) PerformRelayServerSync( logrus.Errorf("P2PGetTransactionFromRelay: %s", err.Error()) return err } - r.processTransaction(&asyncResponse.Txn) + r.processTransaction(&asyncResponse.Transaction) } return nil diff --git a/relayapi/internal/perform_test.go b/relayapi/internal/perform_test.go index 5673b1994..278706a3e 100644 --- a/relayapi/internal/perform_test.go +++ b/relayapi/internal/perform_test.go @@ -46,8 +46,8 @@ func (f *testFedClient) P2PGetTransactionFromRelay( } res = gomatrixserverlib.RespGetRelayTransaction{ - Txn: gomatrixserverlib.Transaction{}, - EntryID: 0, + Transaction: gomatrixserverlib.Transaction{}, + EntryID: 0, } if f.queueDepth > 0 { res.EntriesQueued = true diff --git a/relayapi/routing/relaytxn.go b/relayapi/routing/relaytxn.go index 76241a33b..63b42ec7d 100644 --- a/relayapi/routing/relaytxn.go +++ b/relayapi/routing/relaytxn.go @@ -25,12 +25,6 @@ import ( "github.com/sirupsen/logrus" ) -type RelayTransactionResponse struct { - Transaction gomatrixserverlib.Transaction `json:"transaction"` - EntryID int64 `json:"entry_id,omitempty"` - EntriesQueued bool `json:"entries_queued"` -} - // GetTransactionFromRelay implements GET /_matrix/federation/v1/relay_txn/{userID} // This endpoint can be extracted into a separate relay server service. func GetTransactionFromRelay( @@ -41,7 +35,7 @@ func GetTransactionFromRelay( ) util.JSONResponse { logrus.Infof("Processing relay_txn for %s", userID.Raw()) - previousEntry := gomatrixserverlib.RelayEntry{} + var previousEntry gomatrixserverlib.RelayEntry if err := json.Unmarshal(fedReq.Content(), &previousEntry); err != nil { return util.JSONResponse{ Code: http.StatusInternalServerError, @@ -65,7 +59,7 @@ func GetTransactionFromRelay( return util.JSONResponse{ Code: http.StatusOK, - JSON: RelayTransactionResponse{ + JSON: gomatrixserverlib.RespGetRelayTransaction{ Transaction: response.Transaction, EntryID: response.EntryID, EntriesQueued: response.EntriesQueued, diff --git a/relayapi/routing/relaytxn_test.go b/relayapi/routing/relaytxn_test.go index 3cb4c8adc..4c099a642 100644 --- a/relayapi/routing/relaytxn_test.go +++ b/relayapi/routing/relaytxn_test.go @@ -64,7 +64,7 @@ func TestGetEmptyDatabaseReturnsNothing(t *testing.T) { response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID) assert.Equal(t, http.StatusOK, response.Code) - jsonResponse := response.JSON.(routing.RelayTransactionResponse) + jsonResponse := response.JSON.(gomatrixserverlib.RespGetRelayTransaction) assert.Equal(t, false, jsonResponse.EntriesQueued) assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction) @@ -130,7 +130,7 @@ func TestGetReturnsSavedTransaction(t *testing.T) { response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID) assert.Equal(t, http.StatusOK, response.Code) - jsonResponse := response.JSON.(routing.RelayTransactionResponse) + jsonResponse := response.JSON.(gomatrixserverlib.RespGetRelayTransaction) assert.True(t, jsonResponse.EntriesQueued) assert.Equal(t, transaction, jsonResponse.Transaction) @@ -139,7 +139,7 @@ func TestGetReturnsSavedTransaction(t *testing.T) { response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID) assert.Equal(t, http.StatusOK, response.Code) - jsonResponse = response.JSON.(routing.RelayTransactionResponse) + jsonResponse = response.JSON.(gomatrixserverlib.RespGetRelayTransaction) assert.False(t, jsonResponse.EntriesQueued) assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction) @@ -193,7 +193,7 @@ func TestGetReturnsMultipleSavedTransactions(t *testing.T) { response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID) assert.Equal(t, http.StatusOK, response.Code) - jsonResponse := response.JSON.(routing.RelayTransactionResponse) + jsonResponse := response.JSON.(gomatrixserverlib.RespGetRelayTransaction) assert.True(t, jsonResponse.EntriesQueued) assert.Equal(t, transaction, jsonResponse.Transaction) @@ -201,7 +201,7 @@ func TestGetReturnsMultipleSavedTransactions(t *testing.T) { response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID) assert.Equal(t, http.StatusOK, response.Code) - jsonResponse = response.JSON.(routing.RelayTransactionResponse) + jsonResponse = response.JSON.(gomatrixserverlib.RespGetRelayTransaction) assert.True(t, jsonResponse.EntriesQueued) assert.Equal(t, transaction2, jsonResponse.Transaction) @@ -210,7 +210,7 @@ func TestGetReturnsMultipleSavedTransactions(t *testing.T) { response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID) assert.Equal(t, http.StatusOK, response.Code) - jsonResponse = response.JSON.(routing.RelayTransactionResponse) + jsonResponse = response.JSON.(gomatrixserverlib.RespGetRelayTransaction) assert.False(t, jsonResponse.EntriesQueued) assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)