aboutsummaryrefslogtreecommitdiff
path: root/relayapi
diff options
context:
space:
mode:
authorDevon Hudson <devonhudson@librem.one>2023-01-31 12:31:57 -0700
committerDevon Hudson <devonhudson@librem.one>2023-01-31 12:31:57 -0700
commit7b3334778f44e98e50bf6b0deb5a04a7a89a03de (patch)
tree2a9f33c7555dd4fc6cc669c645234e15b609e11c /relayapi
parentf98003c030432074e0c411cd70e09bacae820940 (diff)
Use gmsl relay_txn response type
Diffstat (limited to 'relayapi')
-rw-r--r--relayapi/internal/perform.go4
-rw-r--r--relayapi/internal/perform_test.go4
-rw-r--r--relayapi/routing/relaytxn.go10
-rw-r--r--relayapi/routing/relaytxn_test.go12
4 files changed, 12 insertions, 18 deletions
diff --git a/relayapi/internal/perform.go b/relayapi/internal/perform.go
index c00d0d0e..62c7d446 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 5673b199..278706a3 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 76241a33..63b42ec7 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 3cb4c8ad..4c099a64 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)