Skip to content

Commit

Permalink
update: add accounts public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
asolovov committed Oct 29, 2023
1 parent 5dc6bee commit 2957a44
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
30 changes: 30 additions & 0 deletions mocks/service/mockService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions perpsv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
}
Expand Down
20 changes: 20 additions & 0 deletions services/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 2957a44

Please sign in to comment.