diff --git a/internal/dataexchange/ffdx/ffdx.go b/internal/dataexchange/ffdx/ffdx.go index 531fccf53b..2300530306 100644 --- a/internal/dataexchange/ffdx/ffdx.go +++ b/internal/dataexchange/ffdx/ffdx.go @@ -148,6 +148,21 @@ func (h *FFDX) Capabilities() *dataexchange.Capabilities { return h.capabilities } +func (h *FFDX) dxEndpointArray(nodes []fftypes.DXInfo) []fftypes.JSONObject { + // The remote DataExchange connector HTTP API expects a flat array + // where "id" is in embedded in each entry - because that's how it + // originally passed the data to us. + // In the DXInfo contract on the Go plugin in FireFly we raise the "id" up + // to be a first class "peer" field, so it can be indexed outside of the opaque + // endpoint payload. + // This function just converts back to a flat array. + dxEndpointArray := make([]fftypes.JSONObject, len(nodes)) + for i, node := range nodes { + dxEndpointArray[i] = node.Endpoint + } + return dxEndpointArray +} + func (h *FFDX) beforeConnect(ctx context.Context) error { h.initMutex.Lock() defer h.initMutex.Unlock() @@ -156,7 +171,7 @@ func (h *FFDX) beforeConnect(ctx context.Context) error { h.initialized = false var status dxStatus res, err := h.client.R().SetContext(ctx). - SetBody(h.nodes). + SetBody(h.dxEndpointArray(h.nodes)). SetResult(&status). Post("/api/v1/init") if err != nil || !res.IsSuccess() { diff --git a/internal/dataexchange/ffdx/ffdx_test.go b/internal/dataexchange/ffdx/ffdx_test.go index 9515e241b9..66204c8516 100644 --- a/internal/dataexchange/ffdx/ffdx_test.go +++ b/internal/dataexchange/ffdx/ffdx_test.go @@ -528,7 +528,7 @@ func TestWebsocketWithReinit(t *testing.T) { utConfPrefix.Set(restclient.HTTPCustomClient, mockedClient) utConfPrefix.Set(DataExchangeInitEnabled, true) - first := true + count := 0 httpmock.RegisterResponder("POST", fmt.Sprintf("%s/api/v1/init", httpURL), func(req *http.Request) (*http.Response, error) { var reqNodes []fftypes.DXInfo @@ -538,12 +538,15 @@ func TestWebsocketWithReinit(t *testing.T) { assert.False(t, h.initialized) - if first { - first = false + count++ + if count == 1 { return httpmock.NewJsonResponse(200, fftypes.JSONObject{ "status": "notready", }) } + if count == 2 { + return nil, fmt.Errorf("pop") + } return httpmock.NewJsonResponse(200, fftypes.JSONObject{ "status": "ready", }) @@ -556,7 +559,7 @@ func TestWebsocketWithReinit(t *testing.T) { err = h.Start() assert.NoError(t, err) - assert.Equal(t, 2, httpmock.GetTotalCallCount()) + assert.Equal(t, 3, httpmock.GetTotalCallCount()) assert.True(t, h.initialized) }