Skip to content

Commit

Permalink
feat: changed to filterTransferAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
xfiendx4life committed Sep 4, 2024
1 parent 0fcff90 commit 8b8bad9
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 43 deletions.
204 changes: 192 additions & 12 deletions mocks/service/mockService.go

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

2 changes: 1 addition & 1 deletion perpsv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ func (p *Perpsv3) init() error {
return err
}

srv, err := services.NewService(rpcClient, p.config, coreContact, perpsMarketContract)
srv, err := services.NewService(rpcClient, p.config, coreContact, perpsMarketContract, accountContract)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions services/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"

"github.com/gateway-fm/perpsv3-Go/config"
"github.com/gateway-fm/perpsv3-Go/contracts/Account"
"github.com/gateway-fm/perpsv3-Go/contracts/core"
"github.com/gateway-fm/perpsv3-Go/contracts/forwarder"
"github.com/gateway-fm/perpsv3-Go/errors"
Expand Down Expand Up @@ -798,7 +799,7 @@ func (s *Service) RetrieveChangeOwner(fromBlock, toBlock, limit uint64) ([]*mode

opts := s.getFilterOptsCore(startBlockOfIteration, &endBlockOfIteration)

iterator, err := s.core.FilterOwnerChanged(opts)
iterator, err := s.accountContract.FilterTransfer(opts, nil, nil, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -854,17 +855,16 @@ func permissionGrantedToPermissionChanged(revoked *core.CorePermissionGranted) (
}, nil
}

func (s *Service) toOwnerTransfered(changed *core.CoreOwnerChanged) (*models.AccountTransfer, error) {
func (s *Service) toOwnerTransfered(changed *Account.AccountTransfer) (*models.AccountTransfer, error) {
block, err := s.rpcClient.BlockByHash(context.Background(), changed.Raw.BlockHash)
if err != nil {
return nil, err
}
return &models.AccountTransfer{
From: changed.OldOwner,
To: changed.NewOwner,
From: changed.From,
To: changed.To,
BlockNumber: changed.Raw.BlockNumber,
BlockTimestamp: block.Time(),
//! We don't have account address in here
//! So we know from and to but do not know what
TokenID: changed.TokenId,
}, nil
}
12 changes: 9 additions & 3 deletions services/accounts_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package services

import (
"github.com/gateway-fm/perpsv3-Go/config"
"log"
"math/big"
"os"
"testing"

"github.com/gateway-fm/perpsv3-Go/config"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/require"

"github.com/gateway-fm/perpsv3-Go/contracts/Account"
"github.com/gateway-fm/perpsv3-Go/contracts/core"
"github.com/gateway-fm/perpsv3-Go/contracts/perpsMarket"
"github.com/gateway-fm/perpsv3-Go/models"
Expand All @@ -29,6 +31,8 @@ func TestService_FormatAccount_OnChain(t *testing.T) {
coreC, _ := core.NewCore(common.HexToAddress("0x76490713314fCEC173f44e99346F54c6e92a8E42"), rpcClient)
perps, _ := perpsMarket.NewPerpsMarket(common.HexToAddress("0xf272382cB3BE898A8CdB1A23BE056fA2Fcf4513b"), rpcClient)

acc, _ := Account.NewAccount(common.HexToAddress("0x63f4Dd0434BEB5baeCD27F3778a909278d8cf5b8"), rpcClient)

idPer := new(big.Int)
idPer.SetString("170141183460469231731687303715884105754", 10)

Expand Down Expand Up @@ -59,7 +63,7 @@ func TestService_FormatAccount_OnChain(t *testing.T) {
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
s, _ := NewService(rpcClient, conf, coreC, perps)
s, _ := NewService(rpcClient, conf, coreC, perps, acc)

res, err := s.FormatAccount(tt.id)

Expand All @@ -85,8 +89,10 @@ func TestService_FormatAccounts_OnChain_Limit(t *testing.T) {

coreC, _ := core.NewCore(common.HexToAddress("0x76490713314fCEC173f44e99346F54c6e92a8E42"), rpcClient)
perps, _ := perpsMarket.NewPerpsMarket(common.HexToAddress("0xf272382cB3BE898A8CdB1A23BE056fA2Fcf4513b"), rpcClient)
acc, _ := Account.NewAccount(common.HexToAddress("0x63f4Dd0434BEB5baeCD27F3778a909278d8cf5b8"), rpcClient)


s, _ := NewService(rpcClient, conf, coreC, perps)
s, _ := NewService(rpcClient, conf, coreC, perps, acc)

_, err := s.FormatAccountsLimit(20000)

Expand Down
Loading

0 comments on commit 8b8bad9

Please sign in to comment.