diff --git a/cmd/api/handlers/project.go b/cmd/api/handlers/project.go index 0f4b357dd..cc7c4a79e 100644 --- a/cmd/api/handlers/project.go +++ b/cmd/api/handlers/project.go @@ -14,6 +14,7 @@ import ( // @ID get-contract-same // @Param network path string true "Network" // @Param address path string true "KT address" minlength(36) maxlength(36) +// @Param manager query string false "Manager" // @Param offset query integer false "Offset" // @Param size query integer false "Requested count" mininum(1) // @Accept json @@ -28,8 +29,8 @@ func (ctx *Context) GetSameContracts(c *gin.Context) { return } - var pageReq pageableRequest - if err := c.BindQuery(&pageReq); ctx.handleError(c, err, http.StatusBadRequest) { + var query sameContractRequest + if err := c.BindQuery(&query); ctx.handleError(c, err, http.StatusBadRequest) { return } @@ -39,7 +40,7 @@ func (ctx *Context) GetSameContracts(c *gin.Context) { return } - sameContracts, err := ctx.Contracts.GetSameContracts(contract, pageReq.Size, pageReq.Offset) + sameContracts, err := ctx.Contracts.GetSameContracts(contract, query.Manager, query.Size, query.Offset) if err != nil { if ctx.Storage.IsRecordNotFound(err) { c.JSON(http.StatusOK, []interface{}{}) diff --git a/cmd/api/handlers/requests.go b/cmd/api/handlers/requests.go index 94cd77370..cb3f30205 100644 --- a/cmd/api/handlers/requests.go +++ b/cmd/api/handlers/requests.go @@ -158,6 +158,11 @@ func (s subRequest) getMask() uint { return b } +type sameContractRequest struct { + pageableRequest + Manager string `form:"manager,omitempty"` +} + type voteRequest struct { SourceAddress string `json:"src" binding:"required,address"` SourceNetwork string `json:"src_network" binding:"required,network"` diff --git a/internal/elastic/contract/storage.go b/internal/elastic/contract/storage.go index c3e90827f..a6d419803 100644 --- a/internal/elastic/contract/storage.go +++ b/internal/elastic/contract/storage.go @@ -287,7 +287,7 @@ func getArrayFilter(fieldName string, arr ...string) core.Item { } // GetSameContracts - -func (storage *Storage) GetSameContracts(c contract.Contract, size, offset int64) (pcr contract.SameResponse, err error) { +func (storage *Storage) GetSameContracts(c contract.Contract, manager string, size, offset int64) (pcr contract.SameResponse, err error) { if c.Fingerprint == nil { return pcr, errors.Errorf("Invalid contract data") } @@ -298,11 +298,19 @@ func (storage *Storage) GetSameContracts(c contract.Contract, size, offset int64 size = core.MaxQuerySize - offset } + var filter core.Item + if manager == "" { + filter = core.Filter(core.MatchPhrase("hash", c.Hash)) + } else { + filter = core.Filter( + core.MatchPhrase("hash", c.Hash), + core.MatchPhrase("manager", manager), + ) + } + q := core.NewQuery().Query( core.Bool( - core.Filter( - core.MatchPhrase("hash", c.Hash), - ), + filter, core.MustNot( core.MatchPhrase("address", c.Address), ), diff --git a/internal/models/contract/repository.go b/internal/models/contract/repository.go index 25e68cbab..8fa5085d4 100644 --- a/internal/models/contract/repository.go +++ b/internal/models/contract/repository.go @@ -2,17 +2,17 @@ package contract // Repository - type Repository interface { - Get(map[string]interface{}) (Contract, error) - GetMany(map[string]interface{}) ([]Contract, error) + Get(by map[string]interface{}) (Contract, error) + GetMany(by map[string]interface{}) ([]Contract, error) GetRandom() (Contract, error) - GetAddressesByNetworkAndLevel(string, int64) ([]string, error) - GetIDsByAddresses([]string, string) ([]string, error) - IsFA(string, string) (bool, error) - UpdateMigrationsCount(string, string) error + GetAddressesByNetworkAndLevel(network string, maxLevel int64) ([]string, error) + GetIDsByAddresses(addresses []string, network string) ([]string, error) + IsFA(network, address string) (bool, error) + UpdateMigrationsCount(address, network string) error GetByAddresses(addresses []Address) ([]Contract, error) - GetTokens(string, string, int64, int64) ([]Contract, int64, error) + GetTokens(network, tokenInterface string, offset, size int64) ([]Contract, int64, error) GetProjectsLastContract(contract *Contract) ([]Contract, error) - GetSameContracts(Contract, int64, int64) (SameResponse, error) + GetSameContracts(contact Contract, manager string, size, offset int64) (SameResponse, error) GetSimilarContracts(Contract, int64, int64) ([]Similar, int, error) GetDiffTasks() ([]DiffTask, error) UpdateField(where []Contract, fields ...string) error diff --git a/internal/models/mock/contract/mock.go b/internal/models/mock/contract/mock.go index 8e825c20f..0728ffbed 100644 --- a/internal/models/mock/contract/mock.go +++ b/internal/models/mock/contract/mock.go @@ -1,7 +1,7 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: contract/repository.go +// Source: internal/models/contract/repository.go -// Package mock_contract is a generated GoMock package. +// Package contract is a generated GoMock package. package contract import ( @@ -34,33 +34,33 @@ func (m *MockRepository) EXPECT() *MockRepositoryMockRecorder { } // Get mocks base method -func (m *MockRepository) Get(arg0 map[string]interface{}) (contractModel.Contract, error) { +func (m *MockRepository) Get(by map[string]interface{}) (contractModel.Contract, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Get", arg0) + ret := m.ctrl.Call(m, "Get", by) ret0, _ := ret[0].(contractModel.Contract) ret1, _ := ret[1].(error) return ret0, ret1 } // Get indicates an expected call of Get -func (mr *MockRepositoryMockRecorder) Get(arg0 interface{}) *gomock.Call { +func (mr *MockRepositoryMockRecorder) Get(by interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockRepository)(nil).Get), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockRepository)(nil).Get), by) } // GetMany mocks base method -func (m *MockRepository) GetMany(arg0 map[string]interface{}) ([]contractModel.Contract, error) { +func (m *MockRepository) GetMany(by map[string]interface{}) ([]contractModel.Contract, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetMany", arg0) + ret := m.ctrl.Call(m, "GetMany", by) ret0, _ := ret[0].([]contractModel.Contract) ret1, _ := ret[1].(error) return ret0, ret1 } // GetMany indicates an expected call of GetMany -func (mr *MockRepositoryMockRecorder) GetMany(arg0 interface{}) *gomock.Call { +func (mr *MockRepositoryMockRecorder) GetMany(by interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMany", reflect.TypeOf((*MockRepository)(nil).GetMany), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMany", reflect.TypeOf((*MockRepository)(nil).GetMany), by) } // GetRandom mocks base method @@ -79,62 +79,62 @@ func (mr *MockRepositoryMockRecorder) GetRandom() *gomock.Call { } // GetAddressesByNetworkAndLevel mocks base method -func (m *MockRepository) GetAddressesByNetworkAndLevel(arg0 string, arg1 int64) ([]string, error) { +func (m *MockRepository) GetAddressesByNetworkAndLevel(network string, maxLevel int64) ([]string, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetAddressesByNetworkAndLevel", arg0, arg1) + ret := m.ctrl.Call(m, "GetAddressesByNetworkAndLevel", network, maxLevel) ret0, _ := ret[0].([]string) ret1, _ := ret[1].(error) return ret0, ret1 } // GetAddressesByNetworkAndLevel indicates an expected call of GetAddressesByNetworkAndLevel -func (mr *MockRepositoryMockRecorder) GetAddressesByNetworkAndLevel(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockRepositoryMockRecorder) GetAddressesByNetworkAndLevel(network, maxLevel interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAddressesByNetworkAndLevel", reflect.TypeOf((*MockRepository)(nil).GetAddressesByNetworkAndLevel), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAddressesByNetworkAndLevel", reflect.TypeOf((*MockRepository)(nil).GetAddressesByNetworkAndLevel), network, maxLevel) } // GetIDsByAddresses mocks base method -func (m *MockRepository) GetIDsByAddresses(arg0 []string, arg1 string) ([]string, error) { +func (m *MockRepository) GetIDsByAddresses(addresses []string, network string) ([]string, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetIDsByAddresses", arg0, arg1) + ret := m.ctrl.Call(m, "GetIDsByAddresses", addresses, network) ret0, _ := ret[0].([]string) ret1, _ := ret[1].(error) return ret0, ret1 } // GetIDsByAddresses indicates an expected call of GetIDsByAddresses -func (mr *MockRepositoryMockRecorder) GetIDsByAddresses(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockRepositoryMockRecorder) GetIDsByAddresses(addresses, network interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetIDsByAddresses", reflect.TypeOf((*MockRepository)(nil).GetIDsByAddresses), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetIDsByAddresses", reflect.TypeOf((*MockRepository)(nil).GetIDsByAddresses), addresses, network) } // IsFA mocks base method -func (m *MockRepository) IsFA(arg0, arg1 string) (bool, error) { +func (m *MockRepository) IsFA(network, address string) (bool, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsFA", arg0, arg1) + ret := m.ctrl.Call(m, "IsFA", network, address) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 } // IsFA indicates an expected call of IsFA -func (mr *MockRepositoryMockRecorder) IsFA(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockRepositoryMockRecorder) IsFA(network, address interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsFA", reflect.TypeOf((*MockRepository)(nil).IsFA), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsFA", reflect.TypeOf((*MockRepository)(nil).IsFA), network, address) } // UpdateMigrationsCount mocks base method -func (m *MockRepository) UpdateMigrationsCount(arg0, arg1 string) error { +func (m *MockRepository) UpdateMigrationsCount(address, network string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateMigrationsCount", arg0, arg1) + ret := m.ctrl.Call(m, "UpdateMigrationsCount", address, network) ret0, _ := ret[0].(error) return ret0 } // UpdateMigrationsCount indicates an expected call of UpdateMigrationsCount -func (mr *MockRepositoryMockRecorder) UpdateMigrationsCount(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockRepositoryMockRecorder) UpdateMigrationsCount(address, network interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateMigrationsCount", reflect.TypeOf((*MockRepository)(nil).UpdateMigrationsCount), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateMigrationsCount", reflect.TypeOf((*MockRepository)(nil).UpdateMigrationsCount), address, network) } // GetByAddresses mocks base method @@ -153,9 +153,9 @@ func (mr *MockRepositoryMockRecorder) GetByAddresses(addresses interface{}) *gom } // GetTokens mocks base method -func (m *MockRepository) GetTokens(arg0, arg1 string, arg2, arg3 int64) ([]contractModel.Contract, int64, error) { +func (m *MockRepository) GetTokens(network, tokenInterface string, offset, size int64) ([]contractModel.Contract, int64, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTokens", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "GetTokens", network, tokenInterface, offset, size) ret0, _ := ret[0].([]contractModel.Contract) ret1, _ := ret[1].(int64) ret2, _ := ret[2].(error) @@ -163,9 +163,9 @@ func (m *MockRepository) GetTokens(arg0, arg1 string, arg2, arg3 int64) ([]contr } // GetTokens indicates an expected call of GetTokens -func (mr *MockRepositoryMockRecorder) GetTokens(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockRepositoryMockRecorder) GetTokens(network, tokenInterface, offset, size interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTokens", reflect.TypeOf((*MockRepository)(nil).GetTokens), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTokens", reflect.TypeOf((*MockRepository)(nil).GetTokens), network, tokenInterface, offset, size) } // GetProjectsLastContract mocks base method @@ -184,18 +184,18 @@ func (mr *MockRepositoryMockRecorder) GetProjectsLastContract(contract interface } // GetSameContracts mocks base method -func (m *MockRepository) GetSameContracts(arg0 contractModel.Contract, arg1, arg2 int64) (contractModel.SameResponse, error) { +func (m *MockRepository) GetSameContracts(contact contractModel.Contract, manager string, size, offset int64) (contractModel.SameResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSameContracts", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "GetSameContracts", contact, manager, size, offset) ret0, _ := ret[0].(contractModel.SameResponse) ret1, _ := ret[1].(error) return ret0, ret1 } // GetSameContracts indicates an expected call of GetSameContracts -func (mr *MockRepositoryMockRecorder) GetSameContracts(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockRepositoryMockRecorder) GetSameContracts(contact, manager, size, offset interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSameContracts", reflect.TypeOf((*MockRepository)(nil).GetSameContracts), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSameContracts", reflect.TypeOf((*MockRepository)(nil).GetSameContracts), contact, manager, size, offset) } // GetSimilarContracts mocks base method diff --git a/internal/reindexer/contract/storage.go b/internal/reindexer/contract/storage.go index 0bb4eb3f2..949ae5724 100644 --- a/internal/reindexer/contract/storage.go +++ b/internal/reindexer/contract/storage.go @@ -150,7 +150,7 @@ func (storage *Storage) GetProjectsLastContract(c *contract.Contract) ([]contrac } // GetSameContracts - -func (storage *Storage) GetSameContracts(c contract.Contract, size, offset int64) (pcr contract.SameResponse, err error) { +func (storage *Storage) GetSameContracts(c contract.Contract, manager string, size, offset int64) (pcr contract.SameResponse, err error) { if c.Fingerprint == nil { return pcr, errors.Errorf("Invalid contract data") }