Skip to content

Commit

Permalink
Merge pull request #878 from kaleido-io/definitions2
Browse files Browse the repository at this point in the history
Enable non-multiparty namespaces
  • Loading branch information
awrichar authored Jul 6, 2022
2 parents 1c398f0 + 784a4db commit 3b19da1
Show file tree
Hide file tree
Showing 128 changed files with 2,729 additions and 1,671 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ $(eval $(call makemock, internal/broadcast, Manager, broadcast
$(eval $(call makemock, internal/privatemessaging, Manager, privatemessagingmocks))
$(eval $(call makemock, internal/shareddownload, Manager, shareddownloadmocks))
$(eval $(call makemock, internal/shareddownload, Callbacks, shareddownloadmocks))
$(eval $(call makemock, internal/definitions, DefinitionHandler, definitionsmocks))
$(eval $(call makemock, internal/definitions, Handler, definitionsmocks))
$(eval $(call makemock, internal/definitions, Sender, definitionsmocks))
$(eval $(call makemock, internal/events, EventManager, eventmocks))
$(eval $(call makemock, internal/namespace, Manager, namespacemocks))
$(eval $(call makemock, internal/networkmap, Manager, networkmapmocks))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- No down migration (can't add back NOT NULL constraint)
16 changes: 16 additions & 0 deletions db/migrations/postgres/000094_allow_local_definitions.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BEGIN;
ALTER TABLE identities RENAME COLUMN messages_claim TO messages_claim_old;
ALTER TABLE identities ADD COLUMN messages_claim UUID;
UPDATE identities SET messages_claim = messages_claim_old;
ALTER TABLE identities DROP COLUMN messages_claim_old;

ALTER TABLE ffi RENAME COLUMN message_id TO message_id_old;
ALTER TABLE ffi ADD COLUMN message_id UUID;
UPDATE ffi SET message_id = message_id_old;
ALTER TABLE ffi DROP COLUMN message_id_old;

ALTER TABLE contractapis RENAME COLUMN message_id TO message_id_old;
ALTER TABLE contractapis ADD COLUMN message_id UUID;
UPDATE contractapis SET message_id = message_id_old;
ALTER TABLE contractapis DROP COLUMN message_id_old;
COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- No down migration (can't add back NOT NULL constraint)
14 changes: 14 additions & 0 deletions db/migrations/sqlite/000094_allow_local_definitions.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ALTER TABLE identities RENAME COLUMN messages_claim TO messages_claim_old;
ALTER TABLE identities ADD COLUMN messages_claim UUID;
UPDATE identities SET messages_claim = messages_claim_old;
ALTER TABLE identities DROP COLUMN messages_claim_old;

ALTER TABLE ffi RENAME COLUMN message_id TO message_id_old;
ALTER TABLE ffi ADD COLUMN message_id UUID;
UPDATE ffi SET message_id = message_id_old;
ALTER TABLE ffi DROP COLUMN message_id_old;

ALTER TABLE contractapis RENAME COLUMN message_id TO message_id_old;
ALTER TABLE contractapis ADD COLUMN message_id UUID;
UPDATE contractapis SET message_id = message_id_old;
ALTER TABLE contractapis DROP COLUMN message_id_old;
6 changes: 3 additions & 3 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ nav_order: 2

|Key|Description|Type|Default Value|
|---|-----------|----|-------------|
|type|The Data Exchange plugin to use|`string`|`ffdx`
|type|The Data Exchange plugin to use|`string`|`<nil>`

## dataexchange.ffdx

Expand Down Expand Up @@ -585,11 +585,11 @@ nav_order: 2

|Key|Description|Type|Default Value|
|---|-----------|----|-------------|
|defaultKey|A default signing key for blockchain transactions within this namespace|`string`|`<nil>`
|defaultkey|A default signing key for blockchain transactions within this namespace|`string`|`<nil>`
|description|A description for the namespace|`string`|`<nil>`
|name|The name of the namespace (must be unique)|`string`|`<nil>`
|plugins|The list of plugins for this namespace|`string`|`<nil>`
|remoteName|The namespace name to be sent in plugin calls, if it differs from namespace name|`string`|`<nil>`
|remotename|The namespace name to be sent in plugin calls, if it differs from namespace name|`string`|`<nil>`

## namespaces.predefined[].multiparty

Expand Down
4 changes: 4 additions & 0 deletions internal/apiserver/route_get_data_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/hyperledger/firefly-common/pkg/ffapi"
"github.com/hyperledger/firefly/internal/coremsgs"
"github.com/hyperledger/firefly/internal/orchestrator"
"github.com/hyperledger/firefly/pkg/core"
"github.com/hyperledger/firefly/pkg/database"
)
Expand All @@ -40,6 +41,9 @@ var getDataBlob = &ffapi.Route{
JSONOutputCodes: []int{http.StatusOK},
Extensions: &coreExtensions{
FilterFactory: database.MessageQueryFactory,
EnabledIf: func(or orchestrator.Orchestrator) bool {
return or.MultiParty() != nil
},
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
blob, reader, err := cr.or.Data().DownloadBlob(cr.ctx, r.PP["dataid"])
if err == nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/apiserver/route_get_data_blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/hyperledger/firefly-common/pkg/fftypes"
"github.com/hyperledger/firefly/mocks/datamocks"
"github.com/hyperledger/firefly/mocks/multipartymocks"
"github.com/hyperledger/firefly/pkg/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -33,6 +34,7 @@ func TestGetDataBlob(t *testing.T) {
o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("Data").Return(mdm)
o.On("MultiParty").Return(&multipartymocks.Manager{})
req := httptest.NewRequest("GET", "/api/v1/namespaces/mynamespace/data/abcd1234/blob", nil)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()
Expand Down
7 changes: 5 additions & 2 deletions internal/apiserver/route_get_group_by_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/hyperledger/firefly-common/pkg/ffapi"
"github.com/hyperledger/firefly/internal/coremsgs"
"github.com/hyperledger/firefly/internal/orchestrator"
"github.com/hyperledger/firefly/pkg/core"
)

Expand All @@ -37,9 +38,11 @@ var getGroupByHash = &ffapi.Route{
JSONOutputValue: func() interface{} { return &core.Group{} },
JSONOutputCodes: []int{http.StatusOK},
Extensions: &coreExtensions{
EnabledIf: func(or orchestrator.Orchestrator) bool {
return or.PrivateMessaging() != nil
},
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
output, err = cr.or.PrivateMessaging().GetGroupByID(cr.ctx, r.PP["hash"])
return output, err
return cr.or.PrivateMessaging().GetGroupByID(cr.ctx, r.PP["hash"])
},
},
}
4 changes: 4 additions & 0 deletions internal/apiserver/route_get_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/hyperledger/firefly-common/pkg/ffapi"
"github.com/hyperledger/firefly/internal/coremsgs"
"github.com/hyperledger/firefly/internal/orchestrator"
"github.com/hyperledger/firefly/pkg/core"
"github.com/hyperledger/firefly/pkg/database"
)
Expand All @@ -37,6 +38,9 @@ var getGroups = &ffapi.Route{
JSONOutputCodes: []int{http.StatusOK},
Extensions: &coreExtensions{
FilterFactory: database.GroupQueryFactory,
EnabledIf: func(or orchestrator.Orchestrator) bool {
return or.PrivateMessaging() != nil
},
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
return filterResult(cr.or.PrivateMessaging().GetGroups(cr.ctx, cr.filter))
},
Expand Down
7 changes: 5 additions & 2 deletions internal/apiserver/route_get_status_batchmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/hyperledger/firefly-common/pkg/ffapi"
"github.com/hyperledger/firefly/internal/batch"
"github.com/hyperledger/firefly/internal/coremsgs"
"github.com/hyperledger/firefly/internal/orchestrator"
)

var getStatusBatchManager = &ffapi.Route{
Expand All @@ -35,9 +36,11 @@ var getStatusBatchManager = &ffapi.Route{
JSONOutputValue: func() interface{} { return &batch.ManagerStatus{} },
JSONOutputCodes: []int{http.StatusOK},
Extensions: &coreExtensions{
EnabledIf: func(or orchestrator.Orchestrator) bool {
return or.BatchManager() != nil
},
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
output = cr.or.BatchManager().Status()
return output, nil
return cr.or.BatchManager().Status(), nil
},
},
}
4 changes: 4 additions & 0 deletions internal/apiserver/route_post_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/hyperledger/firefly-common/pkg/ffapi"
"github.com/hyperledger/firefly-common/pkg/fftypes"
"github.com/hyperledger/firefly/internal/coremsgs"
"github.com/hyperledger/firefly/internal/orchestrator"
"github.com/hyperledger/firefly/pkg/core"
)

Expand All @@ -46,6 +47,9 @@ var postData = &ffapi.Route{
JSONOutputValue: func() interface{} { return &core.Data{} },
JSONOutputCodes: []int{http.StatusCreated},
Extensions: &coreExtensions{
EnabledIf: func(or orchestrator.Orchestrator) bool {
return or.MultiParty() != nil
},
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
output, err = cr.or.Data().UploadJSON(cr.ctx, r.Input.(*core.DataRefOrValue))
return output, err
Expand Down
9 changes: 9 additions & 0 deletions internal/apiserver/route_post_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/hyperledger/firefly-common/pkg/log"
"github.com/hyperledger/firefly/mocks/datamocks"
"github.com/hyperledger/firefly/mocks/multipartymocks"
"github.com/hyperledger/firefly/pkg/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -34,6 +35,7 @@ import (
func TestPostDataJSON(t *testing.T) {
o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)
input := core.Data{}
var buf bytes.Buffer
Expand All @@ -52,6 +54,7 @@ func TestPostDataJSON(t *testing.T) {
func TestPostDataJSONDefaultNS(t *testing.T) {
o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)
input := core.Data{}
var buf bytes.Buffer
Expand All @@ -72,6 +75,7 @@ func TestPostDataBinary(t *testing.T) {

o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)

var b bytes.Buffer
Expand All @@ -97,6 +101,7 @@ func TestPostDataBinaryObjAutoMeta(t *testing.T) {

o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)

var b bytes.Buffer
Expand Down Expand Up @@ -143,6 +148,7 @@ func TestPostDataBinaryStringMetadata(t *testing.T) {

o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)

var b bytes.Buffer
Expand Down Expand Up @@ -176,6 +182,7 @@ func TestPostDataTrailingMetadata(t *testing.T) {

o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)

var b bytes.Buffer
Expand Down Expand Up @@ -207,6 +214,7 @@ func TestPostDataBinaryMissing(t *testing.T) {

o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)

var b bytes.Buffer
Expand All @@ -231,6 +239,7 @@ func TestPostDataBadForm(t *testing.T) {

o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)

var b bytes.Buffer
Expand Down
4 changes: 4 additions & 0 deletions internal/apiserver/route_post_network_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/hyperledger/firefly-common/pkg/ffapi"
"github.com/hyperledger/firefly/internal/coremsgs"
"github.com/hyperledger/firefly/internal/orchestrator"
"github.com/hyperledger/firefly/pkg/core"
)

Expand All @@ -35,6 +36,9 @@ var postNetworkAction = &ffapi.Route{
JSONOutputValue: func() interface{} { return &core.NetworkAction{} },
JSONOutputCodes: []int{http.StatusAccepted},
Extensions: &coreExtensions{
EnabledIf: func(or orchestrator.Orchestrator) bool {
return or.MultiParty() != nil
},
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
err = cr.or.SubmitNetworkAction(cr.ctx, r.Input.(*core.NetworkAction))
return r.Input, err
Expand Down
2 changes: 2 additions & 0 deletions internal/apiserver/route_post_network_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (
"net/http/httptest"
"testing"

"github.com/hyperledger/firefly/mocks/multipartymocks"
"github.com/hyperledger/firefly/pkg/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestPostNetworkAction(t *testing.T) {
o, r := newTestAPIServer()
o.On("MultiParty").Return(&multipartymocks.Manager{})
input := core.NetworkAction{}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(&input)
Expand Down
4 changes: 3 additions & 1 deletion internal/apiserver/route_post_new_contract_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ 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)
return cr.or.Contracts().BroadcastContractAPI(cr.ctx, cr.apiBaseURL, r.Input.(*core.ContractAPI), waitConfirm)
api := r.Input.(*core.ContractAPI)
err = cr.or.DefinitionSender().DefineContractAPI(cr.ctx, cr.apiBaseURL, api, waitConfirm)
return api, err
},
},
}
16 changes: 7 additions & 9 deletions internal/apiserver/route_post_new_contract_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,41 @@ import (
"net/http/httptest"
"testing"

"github.com/hyperledger/firefly/mocks/contractmocks"
"github.com/hyperledger/firefly/mocks/definitionsmocks"
"github.com/hyperledger/firefly/pkg/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestPostNewContractAPI(t *testing.T) {
o, r := newTestAPIServer()
mcm := &contractmocks.Manager{}
o.On("Contracts").Return(mcm)
mds := &definitionsmocks.Sender{}
o.On("DefinitionSender").Return(mds)
input := core.Datatype{}
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()

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

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

func TestPostNewContractAPISync(t *testing.T) {
o, r := newTestAPIServer()
mcm := &contractmocks.Manager{}
o.On("Contracts").Return(mcm)
mds := &definitionsmocks.Sender{}
o.On("DefinitionSender").Return(mds)
input := core.Datatype{}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(&input)
req := httptest.NewRequest("POST", "/api/v1/namespaces/ns1/apis?confirm", &buf)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

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

assert.Equal(t, 200, res.Result().StatusCode)
Expand Down
4 changes: 3 additions & 1 deletion internal/apiserver/route_post_new_contract_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ var postNewContractInterface = &ffapi.Route{
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
waitConfirm := strings.EqualFold(r.QP["confirm"], "true")
r.SuccessStatus = syncRetcode(waitConfirm)
return cr.or.Contracts().BroadcastFFI(cr.ctx, r.Input.(*core.FFI), waitConfirm)
ffi := r.Input.(*core.FFI)
err = cr.or.DefinitionSender().DefineFFI(cr.ctx, ffi, waitConfirm)
return ffi, err
},
},
}
Loading

0 comments on commit 3b19da1

Please sign in to comment.