diff --git a/internal/apiserver/route_get_contract_api_by_name.go b/internal/apiserver/route_get_contract_api_by_name.go index 760f86c44..dc87e580d 100644 --- a/internal/apiserver/route_get_contract_api_by_name.go +++ b/internal/apiserver/route_get_contract_api_by_name.go @@ -38,7 +38,7 @@ var getContractAPIByName = &ffapi.Route{ JSONOutputCodes: []int{http.StatusOK}, Extensions: &coreExtensions{ CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { - return cr.or.Contracts().GetContractAPI(cr.ctx, cr.apiBaseURL, extractNamespace(r.PP), r.PP["apiName"]) + return cr.or.Contracts().GetContractAPI(cr.ctx, cr.apiBaseURL, r.PP["apiName"]) }, }, } diff --git a/internal/apiserver/route_get_contract_api_by_name_test.go b/internal/apiserver/route_get_contract_api_by_name_test.go index f658907bd..1dad43de8 100644 --- a/internal/apiserver/route_get_contract_api_by_name_test.go +++ b/internal/apiserver/route_get_contract_api_by_name_test.go @@ -39,7 +39,7 @@ func TestGetContractAPIByName(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mcm.On("GetContractAPI", mock.Anything, "http://127.0.0.1:5000/api/v1", "ns1", "banana"). + mcm.On("GetContractAPI", mock.Anything, "http://127.0.0.1:5000/api/v1", "banana"). Return(&core.ContractAPI{}, nil) r.ServeHTTP(res, req) diff --git a/internal/apiserver/route_get_contract_api_interface.go b/internal/apiserver/route_get_contract_api_interface.go index 4e997bc46..8ca6720ea 100644 --- a/internal/apiserver/route_get_contract_api_interface.go +++ b/internal/apiserver/route_get_contract_api_interface.go @@ -38,7 +38,7 @@ var getContractAPIInterface = &ffapi.Route{ JSONOutputCodes: []int{http.StatusOK}, Extensions: &coreExtensions{ CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { - return cr.or.Contracts().GetContractAPIInterface(cr.ctx, extractNamespace(r.PP), r.PP["apiName"]) + return cr.or.Contracts().GetContractAPIInterface(cr.ctx, r.PP["apiName"]) }, }, } diff --git a/internal/apiserver/route_get_contract_api_interface_test.go b/internal/apiserver/route_get_contract_api_interface_test.go index 139122e23..d906df2b6 100644 --- a/internal/apiserver/route_get_contract_api_interface_test.go +++ b/internal/apiserver/route_get_contract_api_interface_test.go @@ -39,7 +39,7 @@ func TestGetContractAPIInterface(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mcm.On("GetContractAPIInterface", mock.Anything, "ns1", "banana"). + mcm.On("GetContractAPIInterface", mock.Anything, "banana"). Return(&core.FFI{}, nil) r.ServeHTTP(res, req) diff --git a/internal/apiserver/route_get_contract_apis.go b/internal/apiserver/route_get_contract_apis.go index 985896a20..6a739f4fc 100644 --- a/internal/apiserver/route_get_contract_apis.go +++ b/internal/apiserver/route_get_contract_apis.go @@ -38,7 +38,7 @@ var getContractAPIs = &ffapi.Route{ Extensions: &coreExtensions{ FilterFactory: database.ContractAPIQueryFactory, CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { - return filterResult(cr.or.Contracts().GetContractAPIs(cr.ctx, cr.apiBaseURL, extractNamespace(r.PP), cr.filter)) + return filterResult(cr.or.Contracts().GetContractAPIs(cr.ctx, cr.apiBaseURL, cr.filter)) }, }, } diff --git a/internal/apiserver/route_get_contract_apis_test.go b/internal/apiserver/route_get_contract_apis_test.go index 6e5a14fe6..6405c0b06 100644 --- a/internal/apiserver/route_get_contract_apis_test.go +++ b/internal/apiserver/route_get_contract_apis_test.go @@ -39,7 +39,7 @@ func TestGetContractAPIs(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mcm.On("GetContractAPIs", mock.Anything, "http://127.0.0.1:5000/api/v1", "ns1", mock.Anything). + mcm.On("GetContractAPIs", mock.Anything, "http://127.0.0.1:5000/api/v1", mock.Anything). Return([]*core.ContractAPI{}, nil, nil) r.ServeHTTP(res, req) diff --git a/internal/apiserver/route_post_contract_api_invoke.go b/internal/apiserver/route_post_contract_api_invoke.go index 41a7307a9..dbc4e0807 100644 --- a/internal/apiserver/route_post_contract_api_invoke.go +++ b/internal/apiserver/route_post_contract_api_invoke.go @@ -46,7 +46,7 @@ var postContractAPIInvoke = &ffapi.Route{ r.SuccessStatus = syncRetcode(waitConfirm) req := r.Input.(*core.ContractCallRequest) req.Type = core.CallTypeInvoke - return cr.or.Contracts().InvokeContractAPI(cr.ctx, extractNamespace(r.PP), r.PP["apiName"], r.PP["methodPath"], req, waitConfirm) + return cr.or.Contracts().InvokeContractAPI(cr.ctx, r.PP["apiName"], r.PP["methodPath"], req, waitConfirm) }, }, } diff --git a/internal/apiserver/route_post_contract_api_invoke_test.go b/internal/apiserver/route_post_contract_api_invoke_test.go index 4f8055bee..e38d93c51 100644 --- a/internal/apiserver/route_post_contract_api_invoke_test.go +++ b/internal/apiserver/route_post_contract_api_invoke_test.go @@ -39,7 +39,7 @@ func TestPostContractAPIInvoke(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mcm.On("InvokeContractAPI", mock.Anything, "ns1", "banana", "peel", mock.MatchedBy(func(req *core.ContractCallRequest) bool { + mcm.On("InvokeContractAPI", mock.Anything, "banana", "peel", mock.MatchedBy(func(req *core.ContractCallRequest) bool { return req.Type == core.CallTypeInvoke }), false).Return("banana", nil) r.ServeHTTP(res, req) diff --git a/internal/apiserver/route_post_contract_api_query.go b/internal/apiserver/route_post_contract_api_query.go index 938f4a4bf..004b0e9d9 100644 --- a/internal/apiserver/route_post_contract_api_query.go +++ b/internal/apiserver/route_post_contract_api_query.go @@ -41,7 +41,7 @@ var postContractAPIQuery = &ffapi.Route{ CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { req := r.Input.(*core.ContractCallRequest) req.Type = core.CallTypeQuery - return cr.or.Contracts().InvokeContractAPI(cr.ctx, extractNamespace(r.PP), r.PP["apiName"], r.PP["methodPath"], req, true) + return cr.or.Contracts().InvokeContractAPI(cr.ctx, r.PP["apiName"], r.PP["methodPath"], req, true) }, }, } diff --git a/internal/apiserver/route_post_contract_api_query_test.go b/internal/apiserver/route_post_contract_api_query_test.go index 22f042672..ee616da70 100644 --- a/internal/apiserver/route_post_contract_api_query_test.go +++ b/internal/apiserver/route_post_contract_api_query_test.go @@ -39,7 +39,7 @@ func TestPostContractAPIQuery(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mcm.On("InvokeContractAPI", mock.Anything, "ns1", "banana", "peel", mock.MatchedBy(func(req *core.ContractCallRequest) bool { + mcm.On("InvokeContractAPI", mock.Anything, "banana", "peel", mock.MatchedBy(func(req *core.ContractCallRequest) bool { return req.Type == core.CallTypeQuery }), true).Return("banana", nil) r.ServeHTTP(res, req) diff --git a/internal/apiserver/route_post_contract_invoke.go b/internal/apiserver/route_post_contract_invoke.go index 38f294e08..02779e311 100644 --- a/internal/apiserver/route_post_contract_invoke.go +++ b/internal/apiserver/route_post_contract_invoke.go @@ -43,7 +43,7 @@ var postContractInvoke = &ffapi.Route{ r.SuccessStatus = syncRetcode(waitConfirm) req := r.Input.(*core.ContractCallRequest) req.Type = core.CallTypeInvoke - return cr.or.Contracts().InvokeContract(cr.ctx, extractNamespace(r.PP), req, waitConfirm) + return cr.or.Contracts().InvokeContract(cr.ctx, req, waitConfirm) }, }, } diff --git a/internal/apiserver/route_post_contract_invoke_test.go b/internal/apiserver/route_post_contract_invoke_test.go index 4972486d6..be0a5e47b 100644 --- a/internal/apiserver/route_post_contract_invoke_test.go +++ b/internal/apiserver/route_post_contract_invoke_test.go @@ -39,7 +39,7 @@ func TestPostContractInvoke(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mcm.On("InvokeContract", mock.Anything, "ns1", mock.MatchedBy(func(req *core.ContractCallRequest) bool { + mcm.On("InvokeContract", mock.Anything, mock.MatchedBy(func(req *core.ContractCallRequest) bool { return req.Type == core.CallTypeInvoke }), false).Return("banana", nil) r.ServeHTTP(res, req) diff --git a/internal/apiserver/route_post_contract_query.go b/internal/apiserver/route_post_contract_query.go index c74dc052f..e7fd49df1 100644 --- a/internal/apiserver/route_post_contract_query.go +++ b/internal/apiserver/route_post_contract_query.go @@ -38,7 +38,7 @@ var postContractQuery = &ffapi.Route{ CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { req := r.Input.(*core.ContractCallRequest) req.Type = core.CallTypeQuery - return cr.or.Contracts().InvokeContract(cr.ctx, extractNamespace(r.PP), req, true) + return cr.or.Contracts().InvokeContract(cr.ctx, req, true) }, }, } diff --git a/internal/apiserver/route_post_contract_query_test.go b/internal/apiserver/route_post_contract_query_test.go index 1d57976f5..fa3787b22 100644 --- a/internal/apiserver/route_post_contract_query_test.go +++ b/internal/apiserver/route_post_contract_query_test.go @@ -39,7 +39,7 @@ func TestPostContractQuery(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mcm.On("InvokeContract", mock.Anything, "ns1", mock.MatchedBy(func(req *core.ContractCallRequest) bool { + mcm.On("InvokeContract", mock.Anything, mock.MatchedBy(func(req *core.ContractCallRequest) bool { return req.Type == core.CallTypeQuery }), true).Return("banana", nil) r.ServeHTTP(res, req) diff --git a/internal/apiserver/route_post_new_contract_api.go b/internal/apiserver/route_post_new_contract_api.go index 5e658ca24..a2d777fa4 100644 --- a/internal/apiserver/route_post_new_contract_api.go +++ b/internal/apiserver/route_post_new_contract_api.go @@ -41,7 +41,7 @@ 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, extractNamespace(r.PP), r.Input.(*core.ContractAPI), waitConfirm) + return cr.or.Contracts().BroadcastContractAPI(cr.ctx, cr.apiBaseURL, r.Input.(*core.ContractAPI), waitConfirm) }, }, } diff --git a/internal/apiserver/route_post_new_contract_api_test.go b/internal/apiserver/route_post_new_contract_api_test.go index 257bfaa52..127716835 100644 --- a/internal/apiserver/route_post_new_contract_api_test.go +++ b/internal/apiserver/route_post_new_contract_api_test.go @@ -39,7 +39,7 @@ func TestPostNewContractAPI(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mcm.On("BroadcastContractAPI", mock.Anything, mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), false). + mcm.On("BroadcastContractAPI", mock.Anything, mock.Anything, mock.AnythingOfType("*core.ContractAPI"), false). Return(&core.ContractAPI{}, nil) r.ServeHTTP(res, req) @@ -57,7 +57,7 @@ func TestPostNewContractAPISync(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mcm.On("BroadcastContractAPI", mock.Anything, mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), true). + mcm.On("BroadcastContractAPI", mock.Anything, mock.Anything, mock.AnythingOfType("*core.ContractAPI"), true). Return(&core.ContractAPI{}, nil) r.ServeHTTP(res, req) diff --git a/internal/apiserver/route_put_contract_api.go b/internal/apiserver/route_put_contract_api.go index 535ec0e68..90a0707ed 100644 --- a/internal/apiserver/route_put_contract_api.go +++ b/internal/apiserver/route_put_contract_api.go @@ -48,7 +48,7 @@ var putContractAPI = &ffapi.Route{ api.ID, err = fftypes.ParseUUID(cr.ctx, r.PP["id"]) var res interface{} if err == nil { - res, err = cr.or.Contracts().BroadcastContractAPI(cr.ctx, cr.apiBaseURL, extractNamespace(r.PP), api, waitConfirm) + res, err = cr.or.Contracts().BroadcastContractAPI(cr.ctx, cr.apiBaseURL, api, waitConfirm) } return res, err }, diff --git a/internal/apiserver/route_put_contract_api_test.go b/internal/apiserver/route_put_contract_api_test.go index d2e1f5491..9b5a495bb 100644 --- a/internal/apiserver/route_put_contract_api_test.go +++ b/internal/apiserver/route_put_contract_api_test.go @@ -39,7 +39,7 @@ func TestPutContractAPI(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mcm.On("BroadcastContractAPI", mock.Anything, mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), false). + mcm.On("BroadcastContractAPI", mock.Anything, mock.Anything, mock.AnythingOfType("*core.ContractAPI"), false). Return(&core.ContractAPI{}, nil) r.ServeHTTP(res, req) @@ -57,7 +57,7 @@ func TestPutContractAPISync(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mcm.On("BroadcastContractAPI", mock.Anything, mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), true). + mcm.On("BroadcastContractAPI", mock.Anything, mock.Anything, mock.AnythingOfType("*core.ContractAPI"), true). Return(&core.ContractAPI{}, nil) r.ServeHTTP(res, req) diff --git a/internal/apiserver/server.go b/internal/apiserver/server.go index 787a73b29..1dc914961 100644 --- a/internal/apiserver/server.go +++ b/internal/apiserver/server.go @@ -201,7 +201,7 @@ func (as *apiServer) contractSwaggerGenerator(mgr namespace.Manager, apiBaseURL return func(req *http.Request) (*openapi3.T, error) { vars := mux.Vars(req) cm := mgr.Orchestrator(vars["ns"]).Contracts() - api, err := cm.GetContractAPI(req.Context(), apiBaseURL, vars["ns"], vars["apiName"]) + api, err := cm.GetContractAPI(req.Context(), apiBaseURL, vars["apiName"]) if err != nil { return nil, err } else if api == nil || api.Interface == nil { diff --git a/internal/apiserver/server_test.go b/internal/apiserver/server_test.go index 3821e660d..8600db82a 100644 --- a/internal/apiserver/server_test.go +++ b/internal/apiserver/server_test.go @@ -261,7 +261,7 @@ func TestContractAPISwaggerJSON(t *testing.T) { }, } - mcm.On("GetContractAPI", mock.Anything, "http://127.0.0.1:5000/api/v1", "default", "my-api").Return(api, nil) + mcm.On("GetContractAPI", mock.Anything, "http://127.0.0.1:5000/api/v1", "my-api").Return(api, nil) mcm.On("GetFFIByIDWithChildren", mock.Anything, api.Interface.ID).Return(ffi, nil) mffi.On("Generate", mock.Anything, "http://127.0.0.1:5000/api/v1/namespaces/default/apis/my-api", api, ffi).Return(&openapi3.T{}) @@ -278,7 +278,7 @@ func TestContractAPISwaggerJSONGetAPIFail(t *testing.T) { s := httptest.NewServer(r) defer s.Close() - mcm.On("GetContractAPI", mock.Anything, "http://127.0.0.1:5000/api/v1", "default", "my-api").Return(nil, fmt.Errorf("pop")) + mcm.On("GetContractAPI", mock.Anything, "http://127.0.0.1:5000/api/v1", "my-api").Return(nil, fmt.Errorf("pop")) res, err := http.Get(fmt.Sprintf("http://%s/api/v1/namespaces/default/apis/my-api/api/swagger.json", s.Listener.Addr())) assert.NoError(t, err) @@ -293,7 +293,7 @@ func TestContractAPISwaggerJSONGetAPINotFound(t *testing.T) { s := httptest.NewServer(r) defer s.Close() - mcm.On("GetContractAPI", mock.Anything, "http://127.0.0.1:5000/api/v1", "default", "my-api").Return(nil, nil) + mcm.On("GetContractAPI", mock.Anything, "http://127.0.0.1:5000/api/v1", "my-api").Return(nil, nil) res, err := http.Get(fmt.Sprintf("http://%s/api/v1/namespaces/default/apis/my-api/api/swagger.json", s.Listener.Addr())) assert.NoError(t, err) @@ -314,7 +314,7 @@ func TestContractAPISwaggerJSONGetFFIFail(t *testing.T) { }, } - mcm.On("GetContractAPI", mock.Anything, "http://127.0.0.1:5000/api/v1", "default", "my-api").Return(api, nil) + mcm.On("GetContractAPI", mock.Anything, "http://127.0.0.1:5000/api/v1", "my-api").Return(api, nil) mcm.On("GetFFIByIDWithChildren", mock.Anything, api.Interface.ID).Return(nil, fmt.Errorf("pop")) res, err := http.Get(fmt.Sprintf("http://%s/api/v1/namespaces/default/apis/my-api/api/swagger.json", s.Listener.Addr())) diff --git a/internal/contracts/manager.go b/internal/contracts/manager.go index 1f18fd5d1..f393285a3 100644 --- a/internal/contracts/manager.go +++ b/internal/contracts/manager.go @@ -45,12 +45,12 @@ type Manager interface { GetFFIByIDWithChildren(ctx context.Context, id *fftypes.UUID) (*core.FFI, error) GetFFIs(ctx context.Context, filter database.AndFilter) ([]*core.FFI, *database.FilterResult, error) - InvokeContract(ctx context.Context, ns string, req *core.ContractCallRequest, waitConfirm bool) (interface{}, error) - InvokeContractAPI(ctx context.Context, ns, apiName, methodPath string, req *core.ContractCallRequest, waitConfirm bool) (interface{}, error) - GetContractAPI(ctx context.Context, httpServerURL, ns, apiName string) (*core.ContractAPI, error) - GetContractAPIInterface(ctx context.Context, ns, apiName string) (*core.FFI, error) - GetContractAPIs(ctx context.Context, httpServerURL, ns string, filter database.AndFilter) ([]*core.ContractAPI, *database.FilterResult, error) - BroadcastContractAPI(ctx context.Context, httpServerURL, ns string, api *core.ContractAPI, waitConfirm bool) (output *core.ContractAPI, err error) + InvokeContract(ctx context.Context, req *core.ContractCallRequest, waitConfirm bool) (interface{}, error) + InvokeContractAPI(ctx context.Context, apiName, methodPath string, req *core.ContractCallRequest, waitConfirm bool) (interface{}, error) + GetContractAPI(ctx context.Context, httpServerURL, apiName string) (*core.ContractAPI, error) + GetContractAPIInterface(ctx context.Context, apiName string) (*core.FFI, error) + GetContractAPIs(ctx context.Context, httpServerURL string, filter database.AndFilter) ([]*core.ContractAPI, *database.FilterResult, error) + BroadcastContractAPI(ctx context.Context, httpServerURL string, api *core.ContractAPI, waitConfirm bool) (output *core.ContractAPI, err error) ValidateFFIAndSetPathnames(ctx context.Context, ffi *core.FFI) error @@ -218,7 +218,7 @@ func (cm *contractManager) writeInvokeTransaction(ctx context.Context, req *core return op, err } -func (cm *contractManager) InvokeContract(ctx context.Context, ns string, req *core.ContractCallRequest, waitConfirm bool) (res interface{}, err error) { +func (cm *contractManager) InvokeContract(ctx context.Context, req *core.ContractCallRequest, waitConfirm bool) (res interface{}, err error) { req.Key, err = cm.identity.NormalizeSigningKey(ctx, req.Key, identity.KeyNormalizationBlockchainPlugin) if err != nil { return nil, err @@ -226,7 +226,7 @@ func (cm *contractManager) InvokeContract(ctx context.Context, ns string, req *c var op *core.Operation err = cm.database.RunAsGroup(ctx, func(ctx context.Context) (err error) { - if err = cm.resolveInvokeContractRequest(ctx, ns, req); err != nil { + if err = cm.resolveInvokeContractRequest(ctx, req); err != nil { return err } if err := cm.validateInvokeContractRequest(ctx, req); err != nil { @@ -262,8 +262,8 @@ func (cm *contractManager) InvokeContract(ctx context.Context, ns string, req *c } } -func (cm *contractManager) InvokeContractAPI(ctx context.Context, ns, apiName, methodPath string, req *core.ContractCallRequest, waitConfirm bool) (interface{}, error) { - api, err := cm.database.GetContractAPIByName(ctx, ns, apiName) +func (cm *contractManager) InvokeContractAPI(ctx context.Context, apiName, methodPath string, req *core.ContractCallRequest, waitConfirm bool) (interface{}, error) { + api, err := cm.database.GetContractAPIByName(ctx, cm.namespace, apiName) if err != nil { return nil, err } else if api == nil || api.Interface == nil { @@ -274,15 +274,15 @@ func (cm *contractManager) InvokeContractAPI(ctx context.Context, ns, apiName, m if api.Location != nil { req.Location = api.Location } - return cm.InvokeContract(ctx, ns, req, waitConfirm) + return cm.InvokeContract(ctx, req, waitConfirm) } -func (cm *contractManager) resolveInvokeContractRequest(ctx context.Context, ns string, req *core.ContractCallRequest) (err error) { +func (cm *contractManager) resolveInvokeContractRequest(ctx context.Context, req *core.ContractCallRequest) (err error) { if req.Method == nil { if req.MethodPath == "" || req.Interface == nil { return i18n.NewError(ctx, coremsgs.MsgContractMethodNotSet) } - req.Method, err = cm.database.GetFFIMethod(ctx, ns, req.Interface, req.MethodPath) + req.Method, err = cm.database.GetFFIMethod(ctx, cm.namespace, req.Interface, req.MethodPath) if err != nil || req.Method == nil { return i18n.NewError(ctx, coremsgs.MsgContractMethodResolveError, err) } @@ -299,23 +299,22 @@ func (cm *contractManager) addContractURLs(httpServerURL string, api *core.Contr } } -func (cm *contractManager) GetContractAPI(ctx context.Context, httpServerURL, ns, apiName string) (*core.ContractAPI, error) { - api, err := cm.database.GetContractAPIByName(ctx, ns, apiName) +func (cm *contractManager) GetContractAPI(ctx context.Context, httpServerURL, apiName string) (*core.ContractAPI, error) { + api, err := cm.database.GetContractAPIByName(ctx, cm.namespace, apiName) cm.addContractURLs(httpServerURL, api) return api, err } -func (cm *contractManager) GetContractAPIInterface(ctx context.Context, ns, apiName string) (*core.FFI, error) { - api, err := cm.GetContractAPI(ctx, "", ns, apiName) +func (cm *contractManager) GetContractAPIInterface(ctx context.Context, apiName string) (*core.FFI, error) { + api, err := cm.GetContractAPI(ctx, "", apiName) if err != nil || api == nil { return nil, err } return cm.GetFFIByIDWithChildren(ctx, api.Interface.ID) } -func (cm *contractManager) GetContractAPIs(ctx context.Context, httpServerURL, ns string, filter database.AndFilter) ([]*core.ContractAPI, *database.FilterResult, error) { - filter = cm.scopeNS(ns, filter) - apis, fr, err := cm.database.GetContractAPIs(ctx, ns, filter) +func (cm *contractManager) GetContractAPIs(ctx context.Context, httpServerURL string, filter database.AndFilter) ([]*core.ContractAPI, *database.FilterResult, error) { + apis, fr, err := cm.database.GetContractAPIs(ctx, cm.namespace, filter) for _, api := range apis { cm.addContractURLs(httpServerURL, api) } @@ -351,9 +350,9 @@ func (cm *contractManager) resolveFFIReference(ctx context.Context, ref *core.FF } } -func (cm *contractManager) BroadcastContractAPI(ctx context.Context, httpServerURL, ns string, api *core.ContractAPI, waitConfirm bool) (output *core.ContractAPI, err error) { +func (cm *contractManager) BroadcastContractAPI(ctx context.Context, httpServerURL string, api *core.ContractAPI, waitConfirm bool) (output *core.ContractAPI, err error) { api.ID = fftypes.NewUUID() - api.Namespace = ns + api.Namespace = cm.namespace if api.Location != nil { if api.Location, err = cm.blockchain.NormalizeContractLocation(ctx, api.Location); err != nil { @@ -378,7 +377,7 @@ func (cm *contractManager) BroadcastContractAPI(ctx context.Context, httpServerU return nil, err } - msg, err := cm.broadcast.BroadcastDefinitionAsNode(ctx, ns, api, core.SystemTagDefineContractAPI, waitConfirm) + msg, err := cm.broadcast.BroadcastDefinitionAsNode(ctx, cm.namespace, api, core.SystemTagDefineContractAPI, waitConfirm) if err != nil { return nil, err } diff --git a/internal/contracts/manager_test.go b/internal/contracts/manager_test.go index b59954255..b98a03488 100644 --- a/internal/contracts/manager_test.go +++ b/internal/contracts/manager_test.go @@ -1287,7 +1287,7 @@ func TestInvokeContract(t *testing.T) { return op.Type == core.OpTypeBlockchainInvoke && data.Request == req })).Return(nil, nil) - _, err := cm.InvokeContract(context.Background(), "ns1", req, false) + _, err := cm.InvokeContract(context.Background(), req, false) assert.NoError(t, err) @@ -1333,7 +1333,7 @@ func TestInvokeContractConfirm(t *testing.T) { }). Return(&core.Operation{}, nil) - _, err := cm.InvokeContract(context.Background(), "ns1", req, true) + _, err := cm.InvokeContract(context.Background(), req, true) assert.NoError(t, err) @@ -1373,7 +1373,7 @@ func TestInvokeContractFail(t *testing.T) { return op.Type == core.OpTypeBlockchainInvoke && data.Request == req })).Return(nil, fmt.Errorf("pop")) - _, err := cm.InvokeContract(context.Background(), "ns1", req, false) + _, err := cm.InvokeContract(context.Background(), req, false) assert.EqualError(t, err, "pop") @@ -1395,7 +1395,7 @@ func TestInvokeContractFailNormalizeSigningKey(t *testing.T) { mim.On("NormalizeSigningKey", mock.Anything, "", identity.KeyNormalizationBlockchainPlugin).Return("", fmt.Errorf("pop")) - _, err := cm.InvokeContract(context.Background(), "ns1", req, false) + _, err := cm.InvokeContract(context.Background(), req, false) assert.Regexp(t, "pop", err) } @@ -1414,7 +1414,7 @@ func TestInvokeContractFailResolve(t *testing.T) { mim.On("NormalizeSigningKey", mock.Anything, "", identity.KeyNormalizationBlockchainPlugin).Return("key-resolved", nil) mbi.On("InvokeContract", mock.Anything, mock.AnythingOfType("*fftypes.UUID"), "key-resolved", req.Location, req.Method, req.Input).Return(nil) - _, err := cm.InvokeContract(context.Background(), "ns1", req, false) + _, err := cm.InvokeContract(context.Background(), req, false) assert.Regexp(t, "FF10313", err) } @@ -1439,7 +1439,7 @@ func TestInvokeContractTXFail(t *testing.T) { mim.On("NormalizeSigningKey", mock.Anything, "", identity.KeyNormalizationBlockchainPlugin).Return("key-resolved", nil) mth.On("SubmitNewTransaction", mock.Anything, core.TransactionTypeContractInvoke).Return(nil, fmt.Errorf("pop")) - _, err := cm.InvokeContract(context.Background(), "ns1", req, false) + _, err := cm.InvokeContract(context.Background(), req, false) assert.EqualError(t, err, "pop") } @@ -1459,7 +1459,7 @@ func TestInvokeContractMethodNotFound(t *testing.T) { mim.On("NormalizeSigningKey", mock.Anything, "", identity.KeyNormalizationBlockchainPlugin).Return("key-resolved", nil) mdb.On("GetFFIMethod", mock.Anything, "ns1", req.Interface, req.MethodPath).Return(nil, fmt.Errorf("pop")) - _, err := cm.InvokeContract(context.Background(), "ns1", req, false) + _, err := cm.InvokeContract(context.Background(), req, false) assert.Regexp(t, "FF10315", err) } @@ -1495,7 +1495,7 @@ func TestInvokeContractMethodBadInput(t *testing.T) { } mim.On("NormalizeSigningKey", mock.Anything, "", identity.KeyNormalizationBlockchainPlugin).Return("key-resolved", nil) - _, err := cm.InvokeContract(context.Background(), "ns1", req, false) + _, err := cm.InvokeContract(context.Background(), req, false) assert.Regexp(t, "FF10304", err) } @@ -1525,7 +1525,7 @@ func TestQueryContract(t *testing.T) { })).Return(nil) mbi.On("QueryContract", mock.Anything, req.Location, req.Method, req.Input, req.Options).Return(struct{}{}, nil) - _, err := cm.InvokeContract(context.Background(), "ns1", req, false) + _, err := cm.InvokeContract(context.Background(), req, false) assert.NoError(t, err) } @@ -1554,7 +1554,7 @@ func TestCallContractInvalidType(t *testing.T) { })).Return(nil) assert.PanicsWithValue(t, "unknown call type: ", func() { - cm.InvokeContract(context.Background(), "ns1", req, false) + cm.InvokeContract(context.Background(), req, false) }) } @@ -1793,7 +1793,7 @@ func TestInvokeContractAPI(t *testing.T) { return op.Type == core.OpTypeBlockchainInvoke && data.Request == req })).Return(nil, nil) - _, err := cm.InvokeContractAPI(context.Background(), "ns1", "banana", "peel", req, false) + _, err := cm.InvokeContractAPI(context.Background(), "banana", "peel", req, false) assert.NoError(t, err) @@ -1820,7 +1820,7 @@ func TestInvokeContractAPIFailContractLookup(t *testing.T) { mim.On("NormalizeSigningKey", mock.Anything, "", identity.KeyNormalizationBlockchainPlugin).Return("key-resolved", nil) mdb.On("GetContractAPIByName", mock.Anything, "ns1", "banana").Return(nil, fmt.Errorf("pop")) - _, err := cm.InvokeContractAPI(context.Background(), "ns1", "banana", "peel", req, false) + _, err := cm.InvokeContractAPI(context.Background(), "banana", "peel", req, false) assert.Regexp(t, "pop", err) } @@ -1841,7 +1841,7 @@ func TestInvokeContractAPIContractNotFound(t *testing.T) { mim.On("NormalizeSigningKey", mock.Anything, "", identity.KeyNormalizationBlockchainPlugin).Return("key-resolved", nil) mdb.On("GetContractAPIByName", mock.Anything, "ns1", "banana").Return(nil, nil) - _, err := cm.InvokeContractAPI(context.Background(), "ns1", "banana", "peel", req, false) + _, err := cm.InvokeContractAPI(context.Background(), "banana", "peel", req, false) assert.Regexp(t, "FF10109", err) } @@ -1856,7 +1856,7 @@ func TestGetContractAPI(t *testing.T) { } mdb.On("GetContractAPIByName", mock.Anything, "ns1", "banana").Return(api, nil) - result, err := cm.GetContractAPI(context.Background(), "http://localhost/api", "ns1", "banana") + result, err := cm.GetContractAPI(context.Background(), "http://localhost/api", "banana") assert.NoError(t, err) assert.Equal(t, "http://localhost/api/namespaces/ns1/apis/banana/api/swagger.json", result.URLs.OpenAPI) @@ -1876,7 +1876,7 @@ func TestGetContractAPIs(t *testing.T) { filter := database.ContractAPIQueryFactory.NewFilter(context.Background()).And() mdb.On("GetContractAPIs", mock.Anything, "ns1", filter).Return(apis, &database.FilterResult{}, nil) - results, _, err := cm.GetContractAPIs(context.Background(), "http://localhost/api", "ns1", filter) + results, _, err := cm.GetContractAPIs(context.Background(), "http://localhost/api", filter) assert.NoError(t, err) assert.Equal(t, 1, len(results)) @@ -1908,7 +1908,7 @@ func TestGetContractAPIInterface(t *testing.T) { return ev.Name == "event1" })).Return("event1Sig") - result, err := cm.GetContractAPIInterface(context.Background(), "ns1", "banana") + result, err := cm.GetContractAPIInterface(context.Background(), "banana") assert.NoError(t, err) assert.NotNil(t, result) @@ -1923,7 +1923,7 @@ func TestGetContractAPIInterfaceFail(t *testing.T) { mdb.On("GetContractAPIByName", mock.Anything, "ns1", "banana").Return(nil, fmt.Errorf("pop")) - _, err := cm.GetContractAPIInterface(context.Background(), "ns1", "banana") + _, err := cm.GetContractAPIInterface(context.Background(), "banana") assert.EqualError(t, err, "pop") @@ -1956,7 +1956,7 @@ func TestBroadcastContractAPI(t *testing.T) { mdb.On("GetFFIByID", mock.Anything, "ns1", api.Interface.ID).Return(&core.FFI{}, nil) mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(msg, nil) - api, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) + api, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) assert.NoError(t, err) assert.NotNil(t, api) @@ -1984,7 +1984,7 @@ func TestBroadcastContractAPIBadLocation(t *testing.T) { mbi.On("NormalizeContractLocation", context.Background(), api.Location).Return(nil, fmt.Errorf("pop")) - _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) + _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) assert.EqualError(t, err, "pop") @@ -2027,7 +2027,7 @@ func TestBroadcastContractAPIExisting(t *testing.T) { mdb.On("GetFFIByID", mock.Anything, "ns1", api.Interface.ID).Return(&core.FFI{}, nil) mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(msg, nil) - _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) + _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) assert.NoError(t, err) @@ -2064,7 +2064,7 @@ func TestBroadcastContractAPICannotChangeLocation(t *testing.T) { mbi.On("NormalizeContractLocation", context.Background(), api.Location).Return(api.Location, nil) mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(existing, nil) - _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) + _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) assert.Regexp(t, "FF10316", err) @@ -2100,7 +2100,7 @@ func TestBroadcastContractAPIInterfaceName(t *testing.T) { mdb.On("GetFFI", mock.Anything, "ns1", "my-ffi", "1").Return(&core.FFI{ID: interfaceID}, nil) mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(msg, nil) - _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) + _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) assert.NoError(t, err) assert.Equal(t, *interfaceID, *api.Interface.ID) @@ -2131,7 +2131,7 @@ func TestBroadcastContractAPIFail(t *testing.T) { mdb.On("GetFFIByID", mock.Anything, "ns1", api.Interface.ID).Return(&core.FFI{}, nil) mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(nil, fmt.Errorf("pop")) - _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) + _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) assert.Regexp(t, "pop", err) @@ -2155,7 +2155,7 @@ func TestBroadcastContractAPINoInterface(t *testing.T) { mbi.On("NormalizeContractLocation", context.Background(), api.Location).Return(api.Location, nil) mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil) - _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) + _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) assert.Regexp(t, "FF10303", err) @@ -2182,7 +2182,7 @@ func TestBroadcastContractAPIInterfaceIDFail(t *testing.T) { mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil) mdb.On("GetFFIByID", mock.Anything, "ns1", api.Interface.ID).Return(nil, fmt.Errorf("pop")) - _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) + _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) assert.EqualError(t, err, "pop") @@ -2209,7 +2209,7 @@ func TestBroadcastContractAPIInterfaceIDNotFound(t *testing.T) { mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil) mdb.On("GetFFIByID", mock.Anything, "ns1", api.Interface.ID).Return(nil, nil) - _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) + _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) assert.Regexp(t, "FF10303.*"+api.Interface.ID.String(), err) @@ -2237,7 +2237,7 @@ func TestBroadcastContractAPIInterfaceNameFail(t *testing.T) { mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil) mdb.On("GetFFI", mock.Anything, "ns1", "my-ffi", "1").Return(nil, fmt.Errorf("pop")) - _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) + _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) assert.EqualError(t, err, "pop") @@ -2265,7 +2265,7 @@ func TestBroadcastContractAPIInterfaceNameNotFound(t *testing.T) { mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil) mdb.On("GetFFI", mock.Anything, "ns1", "my-ffi", "1").Return(nil, nil) - _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) + _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) assert.Regexp(t, "FF10303.*my-ffi", err) @@ -2291,7 +2291,7 @@ func TestBroadcastContractAPIInterfaceNoVersion(t *testing.T) { mbi.On("NormalizeContractLocation", context.Background(), api.Location).Return(api.Location, nil) mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil) - _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) + _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) assert.Regexp(t, "FF10303.*my-ffi", err) diff --git a/internal/database/sqlcommon/contractapis_sql.go b/internal/database/sqlcommon/contractapis_sql.go index 4e5b30752..51ce704c0 100644 --- a/internal/database/sqlcommon/contractapis_sql.go +++ b/internal/database/sqlcommon/contractapis_sql.go @@ -154,9 +154,10 @@ func (s *SQLCommon) getContractAPIPred(ctx context.Context, desc string, pred in return api, nil } -func (s *SQLCommon) GetContractAPIs(ctx context.Context, ns string, filter database.AndFilter) (contractAPIs []*core.ContractAPI, res *database.FilterResult, err error) { +func (s *SQLCommon) GetContractAPIs(ctx context.Context, namespace string, filter database.AndFilter) (contractAPIs []*core.ContractAPI, res *database.FilterResult, err error) { - query, fop, fi, err := s.filterSelect(ctx, "", sq.Select(contractAPIsColumns...).From(contractapisTable).Where(sq.Eq{"namespace": ns}), filter, contractAPIsFilterFieldMap, []interface{}{"sequence"}) + query, fop, fi, err := s.filterSelect(ctx, "", sq.Select(contractAPIsColumns...).From(contractapisTable), + filter, contractAPIsFilterFieldMap, []interface{}{"sequence"}, sq.Eq{"namespace": namespace}) if err != nil { return nil, nil, err } @@ -180,10 +181,10 @@ func (s *SQLCommon) GetContractAPIs(ctx context.Context, ns string, filter datab } -func (s *SQLCommon) GetContractAPIByID(ctx context.Context, id *fftypes.UUID) (*core.ContractAPI, error) { - return s.getContractAPIPred(ctx, id.String(), sq.Eq{"id": id}) +func (s *SQLCommon) GetContractAPIByID(ctx context.Context, namespace string, id *fftypes.UUID) (*core.ContractAPI, error) { + return s.getContractAPIPred(ctx, id.String(), sq.Eq{"id": id, "namespace": namespace}) } -func (s *SQLCommon) GetContractAPIByName(ctx context.Context, ns, name string) (*core.ContractAPI, error) { - return s.getContractAPIPred(ctx, ns+":"+name, sq.And{sq.Eq{"namespace": ns}, sq.Eq{"name": name}}) +func (s *SQLCommon) GetContractAPIByName(ctx context.Context, namespace, name string) (*core.ContractAPI, error) { + return s.getContractAPIPred(ctx, namespace+":"+name, sq.Eq{"namespace": namespace, "name": name}) } diff --git a/internal/database/sqlcommon/contractapis_sql_test.go b/internal/database/sqlcommon/contractapis_sql_test.go index 154fb681a..e977fc596 100644 --- a/internal/database/sqlcommon/contractapis_sql_test.go +++ b/internal/database/sqlcommon/contractapis_sql_test.go @@ -61,7 +61,7 @@ func TestContractAPIE2EWithDB(t *testing.T) { assert.NoError(t, err) // Check we get the exact same ContractAPI back - dataRead, err := s.GetContractAPIByID(ctx, apiID) + dataRead, err := s.GetContractAPIByID(ctx, "ns1", apiID) assert.NoError(t, err) assert.NotNil(t, dataRead) assert.Equal(t, *apiID, *dataRead.ID) @@ -72,7 +72,7 @@ func TestContractAPIE2EWithDB(t *testing.T) { assert.NoError(t, err) // Check we get the exact same ContractAPI back - dataRead, err = s.GetContractAPIByID(ctx, apiID) + dataRead, err = s.GetContractAPIByID(ctx, "ns1", apiID) assert.NoError(t, err) assert.NotNil(t, dataRead) assert.Equal(t, *apiID, *dataRead.ID) @@ -145,7 +145,7 @@ func TestContractAPIDBFailScan(t *testing.T) { s, mock := newMockProvider().init() apiID := fftypes.NewUUID() mock.ExpectQuery("SELECT .*").WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow("only one")) - _, err := s.GetContractAPIByID(context.Background(), apiID) + _, err := s.GetContractAPIByID(context.Background(), "ns1", apiID) assert.Regexp(t, "FF10121", err) assert.NoError(t, mock.ExpectationsWereMet()) } @@ -154,7 +154,7 @@ func TestContractAPIDBSelectFail(t *testing.T) { s, mock := newMockProvider().init() apiID := fftypes.NewUUID() mock.ExpectQuery("SELECT .*").WillReturnError(fmt.Errorf("pop")) - _, err := s.GetContractAPIByID(context.Background(), apiID) + _, err := s.GetContractAPIByID(context.Background(), "ns1", apiID) assert.Regexp(t, "pop", err) assert.NoError(t, mock.ExpectationsWereMet()) } @@ -163,7 +163,7 @@ func TestContractAPIDBNoRows(t *testing.T) { s, mock := newMockProvider().init() apiID := fftypes.NewUUID() mock.ExpectQuery("SELECT .*").WillReturnRows(sqlmock.NewRows([]string{"id", "interface_id", "ledger", "location", "name", "namespace", "message_id"})) - _, err := s.GetContractAPIByID(context.Background(), apiID) + _, err := s.GetContractAPIByID(context.Background(), "ns1", apiID) assert.NoError(t, err) assert.NoError(t, mock.ExpectationsWereMet()) } diff --git a/internal/txcommon/event_enrich.go b/internal/txcommon/event_enrich.go index 39ce3b351..bec9bf46d 100644 --- a/internal/txcommon/event_enrich.go +++ b/internal/txcommon/event_enrich.go @@ -47,7 +47,7 @@ func (t *transactionHelper) EnrichEvent(ctx context.Context, event *core.Event) } e.BlockchainEvent = be case core.EventTypeContractAPIConfirmed: - contractAPI, err := t.database.GetContractAPIByID(ctx, event.Reference) + contractAPI, err := t.database.GetContractAPIByID(ctx, t.namespace, event.Reference) if err != nil { return nil, err } diff --git a/internal/txcommon/event_enrich_test.go b/internal/txcommon/event_enrich_test.go index ff84389d2..0af31defd 100644 --- a/internal/txcommon/event_enrich_test.go +++ b/internal/txcommon/event_enrich_test.go @@ -213,7 +213,7 @@ func TestEnrichContractAPISubmitted(t *testing.T) { ev1 := fftypes.NewUUID() // Setup enrichment - mdi.On("GetContractAPIByID", mock.Anything, ref1).Return(&core.ContractAPI{ + mdi.On("GetContractAPIByID", mock.Anything, "ns1", ref1).Return(&core.ContractAPI{ ID: ref1, }, nil) @@ -239,7 +239,7 @@ func TestEnrichContractAPItFail(t *testing.T) { ev1 := fftypes.NewUUID() // Setup enrichment - mdi.On("GetContractAPIByID", mock.Anything, ref1).Return(nil, fmt.Errorf("pop")) + mdi.On("GetContractAPIByID", mock.Anything, "ns1", ref1).Return(nil, fmt.Errorf("pop")) event := &core.Event{ ID: ev1, diff --git a/mocks/contractmocks/manager.go b/mocks/contractmocks/manager.go index 18223121a..d3bb9803f 100644 --- a/mocks/contractmocks/manager.go +++ b/mocks/contractmocks/manager.go @@ -65,13 +65,13 @@ func (_m *Manager) AddContractListener(ctx context.Context, ns string, listener return r0, r1 } -// BroadcastContractAPI provides a mock function with given fields: ctx, httpServerURL, ns, api, waitConfirm -func (_m *Manager) BroadcastContractAPI(ctx context.Context, httpServerURL string, ns string, api *core.ContractAPI, waitConfirm bool) (*core.ContractAPI, error) { - ret := _m.Called(ctx, httpServerURL, ns, api, waitConfirm) +// BroadcastContractAPI provides a mock function with given fields: ctx, httpServerURL, api, waitConfirm +func (_m *Manager) BroadcastContractAPI(ctx context.Context, httpServerURL string, api *core.ContractAPI, waitConfirm bool) (*core.ContractAPI, error) { + ret := _m.Called(ctx, httpServerURL, api, waitConfirm) var r0 *core.ContractAPI - if rf, ok := ret.Get(0).(func(context.Context, string, string, *core.ContractAPI, bool) *core.ContractAPI); ok { - r0 = rf(ctx, httpServerURL, ns, api, waitConfirm) + if rf, ok := ret.Get(0).(func(context.Context, string, *core.ContractAPI, bool) *core.ContractAPI); ok { + r0 = rf(ctx, httpServerURL, api, waitConfirm) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*core.ContractAPI) @@ -79,8 +79,8 @@ func (_m *Manager) BroadcastContractAPI(ctx context.Context, httpServerURL strin } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, string, *core.ContractAPI, bool) error); ok { - r1 = rf(ctx, httpServerURL, ns, api, waitConfirm) + if rf, ok := ret.Get(1).(func(context.Context, string, *core.ContractAPI, bool) error); ok { + r1 = rf(ctx, httpServerURL, api, waitConfirm) } else { r1 = ret.Error(1) } @@ -148,13 +148,13 @@ func (_m *Manager) GenerateFFI(ctx context.Context, ns string, generationRequest return r0, r1 } -// GetContractAPI provides a mock function with given fields: ctx, httpServerURL, ns, apiName -func (_m *Manager) GetContractAPI(ctx context.Context, httpServerURL string, ns string, apiName string) (*core.ContractAPI, error) { - ret := _m.Called(ctx, httpServerURL, ns, apiName) +// GetContractAPI provides a mock function with given fields: ctx, httpServerURL, apiName +func (_m *Manager) GetContractAPI(ctx context.Context, httpServerURL string, apiName string) (*core.ContractAPI, error) { + ret := _m.Called(ctx, httpServerURL, apiName) var r0 *core.ContractAPI - if rf, ok := ret.Get(0).(func(context.Context, string, string, string) *core.ContractAPI); ok { - r0 = rf(ctx, httpServerURL, ns, apiName) + if rf, ok := ret.Get(0).(func(context.Context, string, string) *core.ContractAPI); ok { + r0 = rf(ctx, httpServerURL, apiName) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*core.ContractAPI) @@ -162,8 +162,8 @@ func (_m *Manager) GetContractAPI(ctx context.Context, httpServerURL string, ns } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, string, string) error); ok { - r1 = rf(ctx, httpServerURL, ns, apiName) + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, httpServerURL, apiName) } else { r1 = ret.Error(1) } @@ -171,13 +171,13 @@ func (_m *Manager) GetContractAPI(ctx context.Context, httpServerURL string, ns return r0, r1 } -// GetContractAPIInterface provides a mock function with given fields: ctx, ns, apiName -func (_m *Manager) GetContractAPIInterface(ctx context.Context, ns string, apiName string) (*core.FFI, error) { - ret := _m.Called(ctx, ns, apiName) +// GetContractAPIInterface provides a mock function with given fields: ctx, apiName +func (_m *Manager) GetContractAPIInterface(ctx context.Context, apiName string) (*core.FFI, error) { + ret := _m.Called(ctx, apiName) var r0 *core.FFI - if rf, ok := ret.Get(0).(func(context.Context, string, string) *core.FFI); ok { - r0 = rf(ctx, ns, apiName) + if rf, ok := ret.Get(0).(func(context.Context, string) *core.FFI); ok { + r0 = rf(ctx, apiName) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*core.FFI) @@ -185,8 +185,8 @@ func (_m *Manager) GetContractAPIInterface(ctx context.Context, ns string, apiNa } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { - r1 = rf(ctx, ns, apiName) + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, apiName) } else { r1 = ret.Error(1) } @@ -226,13 +226,13 @@ func (_m *Manager) GetContractAPIListeners(ctx context.Context, ns string, apiNa return r0, r1, r2 } -// GetContractAPIs provides a mock function with given fields: ctx, httpServerURL, ns, filter -func (_m *Manager) GetContractAPIs(ctx context.Context, httpServerURL string, ns string, filter database.AndFilter) ([]*core.ContractAPI, *database.FilterResult, error) { - ret := _m.Called(ctx, httpServerURL, ns, filter) +// GetContractAPIs provides a mock function with given fields: ctx, httpServerURL, filter +func (_m *Manager) GetContractAPIs(ctx context.Context, httpServerURL string, filter database.AndFilter) ([]*core.ContractAPI, *database.FilterResult, error) { + ret := _m.Called(ctx, httpServerURL, filter) var r0 []*core.ContractAPI - if rf, ok := ret.Get(0).(func(context.Context, string, string, database.AndFilter) []*core.ContractAPI); ok { - r0 = rf(ctx, httpServerURL, ns, filter) + if rf, ok := ret.Get(0).(func(context.Context, string, database.AndFilter) []*core.ContractAPI); ok { + r0 = rf(ctx, httpServerURL, filter) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*core.ContractAPI) @@ -240,8 +240,8 @@ func (_m *Manager) GetContractAPIs(ctx context.Context, httpServerURL string, ns } var r1 *database.FilterResult - if rf, ok := ret.Get(1).(func(context.Context, string, string, database.AndFilter) *database.FilterResult); ok { - r1 = rf(ctx, httpServerURL, ns, filter) + if rf, ok := ret.Get(1).(func(context.Context, string, database.AndFilter) *database.FilterResult); ok { + r1 = rf(ctx, httpServerURL, filter) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(*database.FilterResult) @@ -249,8 +249,8 @@ func (_m *Manager) GetContractAPIs(ctx context.Context, httpServerURL string, ns } var r2 error - if rf, ok := ret.Get(2).(func(context.Context, string, string, database.AndFilter) error); ok { - r2 = rf(ctx, httpServerURL, ns, filter) + if rf, ok := ret.Get(2).(func(context.Context, string, database.AndFilter) error); ok { + r2 = rf(ctx, httpServerURL, filter) } else { r2 = ret.Error(2) } @@ -437,13 +437,13 @@ func (_m *Manager) GetFFIs(ctx context.Context, filter database.AndFilter) ([]*c return r0, r1, r2 } -// InvokeContract provides a mock function with given fields: ctx, ns, req, waitConfirm -func (_m *Manager) InvokeContract(ctx context.Context, ns string, req *core.ContractCallRequest, waitConfirm bool) (interface{}, error) { - ret := _m.Called(ctx, ns, req, waitConfirm) +// InvokeContract provides a mock function with given fields: ctx, req, waitConfirm +func (_m *Manager) InvokeContract(ctx context.Context, req *core.ContractCallRequest, waitConfirm bool) (interface{}, error) { + ret := _m.Called(ctx, req, waitConfirm) var r0 interface{} - if rf, ok := ret.Get(0).(func(context.Context, string, *core.ContractCallRequest, bool) interface{}); ok { - r0 = rf(ctx, ns, req, waitConfirm) + if rf, ok := ret.Get(0).(func(context.Context, *core.ContractCallRequest, bool) interface{}); ok { + r0 = rf(ctx, req, waitConfirm) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(interface{}) @@ -451,8 +451,8 @@ func (_m *Manager) InvokeContract(ctx context.Context, ns string, req *core.Cont } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *core.ContractCallRequest, bool) error); ok { - r1 = rf(ctx, ns, req, waitConfirm) + if rf, ok := ret.Get(1).(func(context.Context, *core.ContractCallRequest, bool) error); ok { + r1 = rf(ctx, req, waitConfirm) } else { r1 = ret.Error(1) } @@ -460,13 +460,13 @@ func (_m *Manager) InvokeContract(ctx context.Context, ns string, req *core.Cont return r0, r1 } -// InvokeContractAPI provides a mock function with given fields: ctx, ns, apiName, methodPath, req, waitConfirm -func (_m *Manager) InvokeContractAPI(ctx context.Context, ns string, apiName string, methodPath string, req *core.ContractCallRequest, waitConfirm bool) (interface{}, error) { - ret := _m.Called(ctx, ns, apiName, methodPath, req, waitConfirm) +// InvokeContractAPI provides a mock function with given fields: ctx, apiName, methodPath, req, waitConfirm +func (_m *Manager) InvokeContractAPI(ctx context.Context, apiName string, methodPath string, req *core.ContractCallRequest, waitConfirm bool) (interface{}, error) { + ret := _m.Called(ctx, apiName, methodPath, req, waitConfirm) var r0 interface{} - if rf, ok := ret.Get(0).(func(context.Context, string, string, string, *core.ContractCallRequest, bool) interface{}); ok { - r0 = rf(ctx, ns, apiName, methodPath, req, waitConfirm) + if rf, ok := ret.Get(0).(func(context.Context, string, string, *core.ContractCallRequest, bool) interface{}); ok { + r0 = rf(ctx, apiName, methodPath, req, waitConfirm) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(interface{}) @@ -474,8 +474,8 @@ func (_m *Manager) InvokeContractAPI(ctx context.Context, ns string, apiName str } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, string, string, *core.ContractCallRequest, bool) error); ok { - r1 = rf(ctx, ns, apiName, methodPath, req, waitConfirm) + if rf, ok := ret.Get(1).(func(context.Context, string, string, *core.ContractCallRequest, bool) error); ok { + r1 = rf(ctx, apiName, methodPath, req, waitConfirm) } else { r1 = ret.Error(1) } diff --git a/mocks/databasemocks/plugin.go b/mocks/databasemocks/plugin.go index 062ec930a..cbc06e45e 100644 --- a/mocks/databasemocks/plugin.go +++ b/mocks/databasemocks/plugin.go @@ -392,13 +392,13 @@ func (_m *Plugin) GetChartHistogram(ctx context.Context, namespace string, inter return r0, r1 } -// GetContractAPIByID provides a mock function with given fields: ctx, id -func (_m *Plugin) GetContractAPIByID(ctx context.Context, id *fftypes.UUID) (*core.ContractAPI, error) { - ret := _m.Called(ctx, id) +// GetContractAPIByID provides a mock function with given fields: ctx, namespace, id +func (_m *Plugin) GetContractAPIByID(ctx context.Context, namespace string, id *fftypes.UUID) (*core.ContractAPI, error) { + ret := _m.Called(ctx, namespace, id) var r0 *core.ContractAPI - if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID) *core.ContractAPI); ok { - r0 = rf(ctx, id) + if rf, ok := ret.Get(0).(func(context.Context, string, *fftypes.UUID) *core.ContractAPI); ok { + r0 = rf(ctx, namespace, id) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*core.ContractAPI) @@ -406,8 +406,8 @@ func (_m *Plugin) GetContractAPIByID(ctx context.Context, id *fftypes.UUID) (*co } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, *fftypes.UUID) error); ok { - r1 = rf(ctx, id) + if rf, ok := ret.Get(1).(func(context.Context, string, *fftypes.UUID) error); ok { + r1 = rf(ctx, namespace, id) } else { r1 = ret.Error(1) } diff --git a/pkg/database/plugin.go b/pkg/database/plugin.go index 6709eafad..789e2f63a 100644 --- a/pkg/database/plugin.go +++ b/pkg/database/plugin.go @@ -458,9 +458,16 @@ type iFFIEventCollection interface { } type iContractAPICollection interface { + // UpsertFFIEvent - Upsert a contract API UpsertContractAPI(ctx context.Context, cd *core.ContractAPI) error + + // GetContractAPIs - Get contract APIs GetContractAPIs(ctx context.Context, namespace string, filter AndFilter) ([]*core.ContractAPI, *FilterResult, error) - GetContractAPIByID(ctx context.Context, id *fftypes.UUID) (*core.ContractAPI, error) + + // GetContractAPIByID - Get a contract API by ID + GetContractAPIByID(ctx context.Context, namespace string, id *fftypes.UUID) (*core.ContractAPI, error) + + // GetContractAPIByName - Get a contract API by name GetContractAPIByName(ctx context.Context, namespace, name string) (*core.ContractAPI, error) }