Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
144 changes: 144 additions & 0 deletions doc-site/docs/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ paths:
description: The published name of the API within the multiparty
network
type: string
topics:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default system
topic. Each topic must be a non-empty string. Only used when the
definition is published to the multiparty network
items:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default
system topic. Each topic must be a non-empty string. Only used
when the definition is published to the multiparty network
type: string
type: array
type: object
required: true
responses:
Expand Down Expand Up @@ -1816,6 +1828,18 @@ paths:
description: An optional name to be used for publishing this definition
to the multiparty network, which may differ from the local name
type: string
topics:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default system
topic. Each topic must be a non-empty string. Only used when the
definition is published to the multiparty network
items:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default
system topic. Each topic must be a non-empty string. Only used
when the definition is published to the multiparty network
type: string
type: array
type: object
required: true
responses:
Expand Down Expand Up @@ -2455,6 +2479,18 @@ paths:
description: The published name of the API within the multiparty
network
type: string
topics:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default system
topic. Each topic must be a non-empty string. Only used when the
definition is published to the multiparty network
items:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default
system topic. Each topic must be a non-empty string. Only used
when the definition is published to the multiparty network
type: string
type: array
type: object
required: true
responses:
Expand Down Expand Up @@ -3992,6 +4028,18 @@ paths:
description: The published name of the FFI within the multiparty
network
type: string
topics:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default system
topic. Each topic must be a non-empty string. Only used when the
definition is published to the multiparty network
items:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default
system topic. Each topic must be a non-empty string. Only used
when the definition is published to the multiparty network
type: string
type: array
version:
description: A version for the FFI - use of semantic versioning
such as 'v1.0.1' is encouraged
Expand Down Expand Up @@ -4872,6 +4920,18 @@ paths:
description: An optional name to be used for publishing this definition
to the multiparty network, which may differ from the local name
type: string
topics:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default system
topic. Each topic must be a non-empty string. Only used when the
definition is published to the multiparty network
items:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default
system topic. Each topic must be a non-empty string. Only used
when the definition is published to the multiparty network
type: string
type: array
type: object
required: true
responses:
Expand Down Expand Up @@ -13765,6 +13825,18 @@ paths:
description: The published name of the API within the multiparty
network
type: string
topics:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default system
topic. Each topic must be a non-empty string. Only used when the
definition is published to the multiparty network
items:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default
system topic. Each topic must be a non-empty string. Only used
when the definition is published to the multiparty network
type: string
type: array
type: object
required: true
responses:
Expand Down Expand Up @@ -15626,6 +15698,18 @@ paths:
description: An optional name to be used for publishing this definition
to the multiparty network, which may differ from the local name
type: string
topics:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default system
topic. Each topic must be a non-empty string. Only used when the
definition is published to the multiparty network
items:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default
system topic. Each topic must be a non-empty string. Only used
when the definition is published to the multiparty network
type: string
type: array
type: object
required: true
responses:
Expand Down Expand Up @@ -16545,6 +16629,18 @@ paths:
description: The published name of the API within the multiparty
network
type: string
topics:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default system
topic. Each topic must be a non-empty string. Only used when the
definition is published to the multiparty network
items:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default
system topic. Each topic must be a non-empty string. Only used
when the definition is published to the multiparty network
type: string
type: array
type: object
required: true
responses:
Expand Down Expand Up @@ -18145,6 +18241,18 @@ paths:
description: The published name of the FFI within the multiparty
network
type: string
topics:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default system
topic. Each topic must be a non-empty string. Only used when the
definition is published to the multiparty network
items:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default
system topic. Each topic must be a non-empty string. Only used
when the definition is published to the multiparty network
type: string
type: array
version:
description: A version for the FFI - use of semantic versioning
such as 'v1.0.1' is encouraged
Expand Down Expand Up @@ -19053,6 +19161,18 @@ paths:
description: An optional name to be used for publishing this definition
to the multiparty network, which may differ from the local name
type: string
topics:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default system
topic. Each topic must be a non-empty string. Only used when the
definition is published to the multiparty network
items:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default
system topic. Each topic must be a non-empty string. Only used
when the definition is published to the multiparty network
type: string
type: array
type: object
required: true
responses:
Expand Down Expand Up @@ -36012,6 +36132,18 @@ paths:
description: An optional name to be used for publishing this definition
to the multiparty network, which may differ from the local name
type: string
topics:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default system
topic. Each topic must be a non-empty string. Only used when the
definition is published to the multiparty network
items:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default
system topic. Each topic must be a non-empty string. Only used
when the definition is published to the multiparty network
type: string
type: array
type: object
required: true
responses:
Expand Down Expand Up @@ -45562,6 +45694,18 @@ paths:
description: An optional name to be used for publishing this definition
to the multiparty network, which may differ from the local name
type: string
topics:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default system
topic. Each topic must be a non-empty string. Only used when the
definition is published to the multiparty network
items:
description: An optional list of custom topics to use for ordering
of the definition broadcast message, instead of the default
system topic. Each topic must be a non-empty string. Only used
when the definition is published to the multiparty network
type: string
type: array
type: object
required: true
responses:
Expand Down
2 changes: 1 addition & 1 deletion internal/apiserver/route_post_contract_api_publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var postContractAPIPublish = &ffapi.Route{
waitConfirm := strings.EqualFold(r.QP["confirm"], "true")
r.SuccessStatus = syncRetcode(waitConfirm)
input := r.Input.(*core.DefinitionPublish)
return cr.or.DefinitionSender().PublishContractAPI(cr.ctx, cr.apiBaseURL, r.PP["apiName"], input.NetworkName, waitConfirm)
return cr.or.DefinitionSender().PublishContractAPI(cr.ctx, cr.apiBaseURL, r.PP["apiName"], input.NetworkName, waitConfirm, input.Topics)
},
},
}
22 changes: 21 additions & 1 deletion internal/apiserver/route_post_contract_api_publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http/httptest"
"testing"

"github.com/hyperledger-firefly/common/pkg/fftypes"
"github.com/hyperledger-firefly/firefly/mocks/definitionsmocks"
"github.com/hyperledger-firefly/firefly/pkg/core"
"github.com/stretchr/testify/assert"
Expand All @@ -41,7 +42,26 @@ func TestPostContractAPIPublish(t *testing.T) {
res := httptest.NewRecorder()
api := &core.ContractAPI{}

mds.On("PublishContractAPI", mock.Anything, "http://127.0.0.1:5000/api/v1/namespaces/ns1", "banana", "banana-net", false).Return(api, nil)
mds.On("PublishContractAPI", mock.Anything, "http://127.0.0.1:5000/api/v1/namespaces/ns1", "banana", "banana-net", false, mock.Anything).Return(api, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 202, res.Result().StatusCode)
}

func TestPostContractAPIPublishWithTopics(t *testing.T) {
o, r := newTestAPIServer()
o.On("Authorize", mock.Anything, mock.Anything).Return(nil)
mds := &definitionsmocks.Sender{}
o.On("DefinitionSender").Return(mds)
input := core.DefinitionPublish{NetworkName: "banana-net", Topics: fftypes.FFStringArray{"my-topic"}}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(&input)
req := httptest.NewRequest("POST", "/api/v1/namespaces/ns1/apis/banana/publish", &buf)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()
api := &core.ContractAPI{}

mds.On("PublishContractAPI", mock.Anything, "http://127.0.0.1:5000/api/v1/namespaces/ns1", "banana", "banana-net", false, []string{"my-topic"}).Return(api, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 202, res.Result().StatusCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var postContractInterfacePublish = &ffapi.Route{
waitConfirm := strings.EqualFold(r.QP["confirm"], "true")
r.SuccessStatus = syncRetcode(waitConfirm)
input := r.Input.(*core.DefinitionPublish)
return cr.or.DefinitionSender().PublishFFI(cr.ctx, r.PP["name"], r.PP["version"], input.NetworkName, waitConfirm)
return cr.or.DefinitionSender().PublishFFI(cr.ctx, r.PP["name"], r.PP["version"], input.NetworkName, waitConfirm, input.Topics)
},
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,26 @@ func TestPostContractInterfacePublish(t *testing.T) {
res := httptest.NewRecorder()
ffi := &fftypes.FFI{}

mds.On("PublishFFI", mock.Anything, "ffi1", "1.0", "", false).Return(ffi, nil)
mds.On("PublishFFI", mock.Anything, "ffi1", "1.0", "", false, mock.Anything).Return(ffi, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 202, res.Result().StatusCode)
}

func TestPostContractInterfacePublishWithTopics(t *testing.T) {
o, r := newTestAPIServer()
o.On("Authorize", mock.Anything, mock.Anything).Return(nil)
mds := &definitionsmocks.Sender{}
o.On("DefinitionSender").Return(mds)
input := core.DefinitionPublish{Topics: fftypes.FFStringArray{"my-topic"}}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(&input)
req := httptest.NewRequest("POST", "/api/v1/namespaces/ns1/contracts/interfaces/ffi1/1.0/publish", &buf)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()
ffi := &fftypes.FFI{}

mds.On("PublishFFI", mock.Anything, "ffi1", "1.0", "", false, []string{"my-topic"}).Return(ffi, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 202, res.Result().StatusCode)
Expand Down
7 changes: 4 additions & 3 deletions internal/apiserver/route_post_new_contract_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var postNewContractAPI = &ffapi.Route{
{Name: "publish", Description: coremsgs.APIPublishQueryParam, IsBool: true},
},
Description: coremsgs.APIEndpointsPostNewContractAPI,
JSONInputValue: func() interface{} { return &core.ContractAPI{} },
JSONInputValue: func() interface{} { return &core.ContractAPIInput{} },
JSONOutputValue: func() interface{} { return &core.ContractAPI{} },
JSONOutputCodes: []int{http.StatusOK, http.StatusAccepted},
Extensions: &coreExtensions{
Expand All @@ -46,10 +46,11 @@ var postNewContractAPI = &ffapi.Route{
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
waitConfirm := strings.EqualFold(r.QP["confirm"], "true")
r.SuccessStatus = syncRetcode(waitConfirm)
api := r.Input.(*core.ContractAPI)
input := r.Input.(*core.ContractAPIInput)
api := &input.ContractAPI
api.ID = nil
api.Published = strings.EqualFold(r.QP["publish"], "true")
err = cr.or.DefinitionSender().DefineContractAPI(cr.ctx, cr.apiBaseURL, api, waitConfirm)
err = cr.or.DefinitionSender().DefineContractAPI(cr.ctx, cr.apiBaseURL, api, waitConfirm, input.Topics)
return api, err
},
},
Expand Down
24 changes: 22 additions & 2 deletions internal/apiserver/route_post_new_contract_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http/httptest"
"testing"

"github.com/hyperledger-firefly/common/pkg/fftypes"
"github.com/hyperledger-firefly/firefly/mocks/contractmocks"
"github.com/hyperledger-firefly/firefly/mocks/definitionsmocks"
"github.com/hyperledger-firefly/firefly/pkg/core"
Expand All @@ -42,7 +43,7 @@ func TestPostNewContractAPI(t *testing.T) {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mds.On("DefineContractAPI", mock.Anything, mock.Anything, mock.AnythingOfType("*core.ContractAPI"), false).Return(nil)
mds.On("DefineContractAPI", mock.Anything, mock.Anything, mock.AnythingOfType("*core.ContractAPI"), false, mock.Anything).Return(nil)
r.ServeHTTP(res, req)

assert.Equal(t, 202, res.Result().StatusCode)
Expand All @@ -61,8 +62,27 @@ func TestPostNewContractAPISync(t *testing.T) {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mds.On("DefineContractAPI", mock.Anything, mock.Anything, mock.AnythingOfType("*core.ContractAPI"), true).Return(nil)
mds.On("DefineContractAPI", mock.Anything, mock.Anything, mock.AnythingOfType("*core.ContractAPI"), true, mock.Anything).Return(nil)
r.ServeHTTP(res, req)

assert.Equal(t, 200, res.Result().StatusCode)
}

func TestPostNewContractAPIWithTopics(t *testing.T) {
o, r := newTestAPIServer()
o.On("Authorize", mock.Anything, mock.Anything).Return(nil)
mds := &definitionsmocks.Sender{}
o.On("Contracts").Return(&contractmocks.Manager{})
o.On("DefinitionSender").Return(mds)
input := core.ContractAPIInput{Topics: fftypes.FFStringArray{"my-topic"}}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(&input)
req := httptest.NewRequest("POST", "/api/v1/namespaces/ns1/apis", &buf)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mds.On("DefineContractAPI", mock.Anything, mock.Anything, mock.AnythingOfType("*core.ContractAPI"), false, []string{"my-topic"}).Return(nil)
r.ServeHTTP(res, req)

assert.Equal(t, 202, res.Result().StatusCode)
}
Loading
Loading