From 2957a44e0e3d4220c5c440949606bc691d7db336 Mon Sep 17 00:00:00 2001 From: asolovov Date: Sun, 29 Oct 2023 20:07:04 +0300 Subject: [PATCH] update: add accounts public methods --- mocks/service/mockService.go | 30 ++++++++++++++++++++++++++++++ perpsv3.go | 14 ++++++++++++++ services/accounts.go | 20 ++++++++++++++++++++ services/service.go | 6 ++++++ 4 files changed, 70 insertions(+) diff --git a/mocks/service/mockService.go b/mocks/service/mockService.go index a4edede..0a0751a 100644 --- a/mocks/service/mockService.go +++ b/mocks/service/mockService.go @@ -80,6 +80,36 @@ func (mr *MockIServiceMockRecorder) FormatAccountsLimit(limit interface{}) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FormatAccountsLimit", reflect.TypeOf((*MockIService)(nil).FormatAccountsLimit), limit) } +// GetAccountLastInteraction mocks base method. +func (m *MockIService) GetAccountLastInteraction(accountId *big.Int) (*big.Int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccountLastInteraction", accountId) + ret0, _ := ret[0].(*big.Int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAccountLastInteraction indicates an expected call of GetAccountLastInteraction. +func (mr *MockIServiceMockRecorder) GetAccountLastInteraction(accountId interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccountLastInteraction", reflect.TypeOf((*MockIService)(nil).GetAccountLastInteraction), accountId) +} + +// GetAccountOwner mocks base method. +func (m *MockIService) GetAccountOwner(accountId *big.Int) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccountOwner", accountId) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAccountOwner indicates an expected call of GetAccountOwner. +func (mr *MockIServiceMockRecorder) GetAccountOwner(accountId interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccountOwner", reflect.TypeOf((*MockIService)(nil).GetAccountOwner), accountId) +} + // GetAvailableMargin mocks base method. func (m *MockIService) GetAvailableMargin(accountId *big.Int) (*big.Int, error) { m.ctrl.T.Helper() diff --git a/perpsv3.go b/perpsv3.go index 385750b..b5c7ef7 100644 --- a/perpsv3.go +++ b/perpsv3.go @@ -140,6 +140,12 @@ type IPerpsv3 interface { // GetFundingParameters is used to get funding params for given market ID GetFundingParameters(marketId *big.Int) (*models.FundingParameters, error) + // GetAccountLastInteraction is used to get accounts last interaction for given account ID + GetAccountLastInteraction(accountId *big.Int) (*big.Int, error) + + // GetAccountOwner is used to get accounts owner address for given account ID + GetAccountOwner(accountId *big.Int) (string, error) + // FormatAccount is used to get account, and it's additional data from the contract by given account id FormatAccount(id *big.Int) (*models.Account, error) @@ -290,6 +296,14 @@ func (p *Perpsv3) GetFundingParameters(marketId *big.Int) (*models.FundingParame return p.service.GetFundingParameters(marketId) } +func (p *Perpsv3) GetAccountLastInteraction(accountId *big.Int) (*big.Int, error) { + return p.service.GetAccountLastInteraction(accountId) +} + +func (p *Perpsv3) GetAccountOwner(accountId *big.Int) (string, error) { + return p.service.GetAccountOwner(accountId) +} + func (p *Perpsv3) FormatAccounts() ([]*models.Account, error) { return p.service.FormatAccounts() } diff --git a/services/accounts.go b/services/accounts.go index c7c8d08..942c2af 100644 --- a/services/accounts.go +++ b/services/accounts.go @@ -128,6 +128,26 @@ func (s *Service) GetAvailableMargin(accountId *big.Int) (*big.Int, error) { return margin, nil } +func (s *Service) GetAccountLastInteraction(accountId *big.Int) (*big.Int, error) { + time, err := s.perpsMarket.GetAccountLastInteraction(nil, accountId) + if err != nil { + logger.Log().WithField("layer", "Service-GetAccountLastInteraction").Errorf("get account last interaction error: %v", err.Error()) + return nil, errors.GetReadContractErr(err, "perps market", "GetAccountLastInteraction") + } + + return time, nil +} + +func (s *Service) GetAccountOwner(accountId *big.Int) (string, error) { + owner, err := s.perpsMarket.GetAccountOwner(nil, accountId) + if err != nil { + logger.Log().WithField("layer", "Service-GetAccountOwner").Errorf("get account owner error: %v", err.Error()) + return "", errors.GetReadContractErr(err, "perps market", "GetAccountOwner") + } + + return owner.Hex(), nil +} + // formatAccounts is used to get accounts from the contract using event filter function for 'AccountCreated' event // and given filter options func (s *Service) formatAccounts(opts *bind.FilterOpts) ([]*models.Account, error) { diff --git a/services/service.go b/services/service.go index 19f66b1..d834246 100644 --- a/services/service.go +++ b/services/service.go @@ -83,6 +83,12 @@ type IService interface { // GetFundingParameters is used to get funding params for given market ID GetFundingParameters(marketId *big.Int) (*models.FundingParameters, error) + // GetAccountLastInteraction is used to get accounts last interaction for given account ID + GetAccountLastInteraction(accountId *big.Int) (*big.Int, error) + + // GetAccountOwner is used to get accounts owner address for given account ID + GetAccountOwner(accountId *big.Int) (string, error) + // FormatAccount is used to get account, and it's additional data from the contract by given account id FormatAccount(id *big.Int) (*models.Account, error)