Skip to content

Commit

Permalink
chore_: remove deprecated api functions and associated code
Browse files Browse the repository at this point in the history
  • Loading branch information
dlipicar committed Dec 9, 2024
1 parent d1e0861 commit 00a5c59
Show file tree
Hide file tree
Showing 10 changed files with 1 addition and 673 deletions.
50 changes: 0 additions & 50 deletions services/wallet/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,56 +107,6 @@ type DerivedAddress struct {
AlreadyCreated bool `json:"alreadyCreated"`
}

// @deprecated
func (api *API) CheckRecentHistory(ctx context.Context, addresses []common.Address) error {
return api.s.transferController.CheckRecentHistory([]uint64{api.s.rpcClient.UpstreamChainID}, addresses)
}

// @deprecated
func (api *API) CheckRecentHistoryForChainIDs(ctx context.Context, chainIDs []uint64, addresses []common.Address) error {
return api.s.transferController.CheckRecentHistory(chainIDs, addresses)
}

func hexBigToBN(hexBig *hexutil.Big) *big.Int {
var bN *big.Int
if hexBig != nil {
bN = hexBig.ToInt()
}
return bN
}

// @deprecated
// GetTransfersByAddress returns transfers for a single address
func (api *API) GetTransfersByAddress(ctx context.Context, address common.Address, toBlock, limit *hexutil.Big, fetchMore bool) ([]transfer.View, error) {
logutils.ZapLogger().Debug("[WalletAPI:: GetTransfersByAddress] get transfers for an address", zap.Stringer("address", address))
var intLimit = int64(1)
if limit != nil {
intLimit = limit.ToInt().Int64()
}
return api.s.transferController.GetTransfersByAddress(ctx, api.s.rpcClient.UpstreamChainID, address, hexBigToBN(toBlock), intLimit, fetchMore)
}

// @deprecated
// LoadTransferByHash loads transfer to the database
// Only used by status-mobile
func (api *API) LoadTransferByHash(ctx context.Context, address common.Address, hash common.Hash) error {
logutils.ZapLogger().Debug("[WalletAPI:: LoadTransferByHash] get transfer by hash", zap.Stringer("address", address), zap.Stringer("hash", hash))
return api.s.transferController.LoadTransferByHash(ctx, api.s.rpcClient, address, hash)
}

// @deprecated
func (api *API) GetTransfersByAddressAndChainID(ctx context.Context, chainID uint64, address common.Address, toBlock, limit *hexutil.Big, fetchMore bool) ([]transfer.View, error) {
logutils.ZapLogger().Debug("[WalletAPI:: GetTransfersByAddressAndChainIDs] get transfers for an address", zap.Stringer("address", address))
return api.s.transferController.GetTransfersByAddress(ctx, chainID, address, hexBigToBN(toBlock), limit.ToInt().Int64(), fetchMore)
}

// @deprecated
func (api *API) GetTransfersForIdentities(ctx context.Context, identities []transfer.TransactionIdentity) ([]transfer.View, error) {
logutils.ZapLogger().Debug("wallet.api.GetTransfersForIdentities", zap.Int("identities.len", len(identities)))

return api.s.transferController.GetTransfersForIdentities(ctx, identities)
}

func (api *API) FetchDecodedTxData(ctx context.Context, data string) (*thirdparty.DataParsed, error) {
logutils.ZapLogger().Debug("[Wallet: FetchDecodedTxData]")

Expand Down
25 changes: 0 additions & 25 deletions services/wallet/routeexecution/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ import (
"database/sql"
"time"

"go.uber.org/zap"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"

"github.com/status-im/status-go/logutils"

status_common "github.com/status-im/status-go/common"
statusErrors "github.com/status-im/status-go/errors"
"github.com/status-im/status-go/services/wallet/requests"
Expand Down Expand Up @@ -209,26 +205,5 @@ func (m *Manager) SendRouterTransactionsWithSignatures(ctx context.Context, send
if tmpErr != nil {
log.Error("Error storing route data", "error", tmpErr)
}

var (
chainIDs []uint64
addresses []common.Address
)
for _, tx := range response.SentTransactions {
chainIDs = append(chainIDs, tx.FromChain)
addresses = append(addresses, common.Address(tx.FromAddress))
go func(chainId uint64, txHash common.Hash) {
defer status_common.LogOnPanic()
tmpErr = m.transactionManager.WatchTransaction(context.Background(), chainId, txHash)
if tmpErr != nil {
logutils.ZapLogger().Error("Error watching transaction", zap.Error(tmpErr))
return
}
}(tx.FromChain, common.Hash(tx.Hash))
}
tmpErr = m.transferController.CheckRecentHistory(chainIDs, addresses)
if tmpErr != nil {
logutils.ZapLogger().Error("Error checking recent history", zap.Error(tmpErr))
}
}()
}
240 changes: 0 additions & 240 deletions services/wallet/transfer/block_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,97 +22,10 @@ type Block struct {
Nonce *int64
}

type BlockView struct {
Address common.Address `json:"address"`
Number *big.Int `json:"blockNumber"`
Balance bigint.BigInt `json:"balance"`
Nonce *int64 `json:"nonce"`
}

func blocksToViews(blocks map[common.Address]*Block) []BlockView {
blocksViews := []BlockView{}
for address, block := range blocks {
view := BlockView{
Address: address,
Number: block.Number,
Balance: bigint.BigInt{Int: block.Balance},
Nonce: block.Nonce,
}
blocksViews = append(blocksViews, view)
}

return blocksViews
}

type BlockDAO struct {
db *sql.DB
}

// MergeBlocksRanges merge old blocks ranges if possible
func (b *BlockDAO) mergeBlocksRanges(chainIDs []uint64, accounts []common.Address) error {
for _, chainID := range chainIDs {
for _, account := range accounts {
err := b.mergeRanges(chainID, account)
if err != nil {
return err
}
}
}
return nil
}

func (b *BlockDAO) mergeRanges(chainID uint64, account common.Address) (err error) {
var (
tx *sql.Tx
)

ranges, err := b.getOldRanges(chainID, account)
if err != nil {
return err
}

logutils.ZapLogger().Info("merge old ranges",
zap.Stringer("account", account),
zap.Uint64("network", chainID),
zap.Int("ranges", len(ranges)),
)

if len(ranges) <= 1 {
return nil
}

tx, err = b.db.Begin()
if err != nil {
return err
}

defer func() {
if err == nil {
err = tx.Commit()
return
}
_ = tx.Rollback()
}()

newRanges, deletedRanges := getNewRanges(ranges)

for _, rangeToDelete := range deletedRanges {
err = deleteRange(chainID, tx, account, rangeToDelete.from, rangeToDelete.to)
if err != nil {
return err
}
}

for _, newRange := range newRanges {
err = insertRange(chainID, tx, account, newRange.from, newRange.to)
if err != nil {
return err
}
}

return nil
}

func (b *BlockDAO) insertRange(chainID uint64, account common.Address, from, to, balance *big.Int, nonce uint64) error {
logutils.ZapLogger().Debug(
"insert blocks range",
Expand All @@ -131,35 +44,6 @@ func (b *BlockDAO) insertRange(chainID uint64, account common.Address, from, to,
return err
}

func (b *BlockDAO) getOldRanges(chainID uint64, account common.Address) ([]*BlocksRange, error) {
query := `select blk_from, blk_to from blocks_ranges
where address = ?
and network_id = ?
order by blk_from`

rows, err := b.db.Query(query, account, chainID)
if err != nil {
return nil, err
}
defer rows.Close()
ranges := []*BlocksRange{}
for rows.Next() {
from := &big.Int{}
to := &big.Int{}
err = rows.Scan((*bigint.SQLBigInt)(from), (*bigint.SQLBigInt)(to))
if err != nil {
return nil, err
}

ranges = append(ranges, &BlocksRange{
from: from,
to: to,
})
}

return ranges, nil
}

// GetBlocksToLoadByAddress gets unloaded blocks for a given address.
func (b *BlockDAO) GetBlocksToLoadByAddress(chainID uint64, address common.Address, limit int) (rst []*big.Int, err error) {
query := `SELECT blk_number FROM blocks
Expand Down Expand Up @@ -205,56 +89,6 @@ func (b *BlockDAO) GetLastBlockByAddress(chainID uint64, address common.Address,
return nil, nil
}

func (b *BlockDAO) GetFirstSavedBlock(chainID uint64, address common.Address) (rst *DBHeader, err error) {
query := `SELECT blk_number, blk_hash, loaded
FROM blocks
WHERE network_id = ? AND address = ?
ORDER BY blk_number LIMIT 1`
rows, err := b.db.Query(query, chainID, address)
if err != nil {
return
}
defer rows.Close()

if rows.Next() {
header := &DBHeader{Hash: common.Hash{}, Number: new(big.Int)}
err = rows.Scan((*bigint.SQLBigInt)(header.Number), &header.Hash, &header.Loaded)
if err != nil {
return nil, err
}

return header, nil
}

return nil, nil
}

func (b *BlockDAO) GetFirstKnownBlock(chainID uint64, address common.Address) (rst *big.Int, err error) {
query := `SELECT blk_from FROM blocks_ranges
WHERE address = ?
AND network_id = ?
ORDER BY blk_from
LIMIT 1`

rows, err := b.db.Query(query, address, chainID)
if err != nil {
return
}
defer rows.Close()

if rows.Next() {
block := &big.Int{}
err = rows.Scan((*bigint.SQLBigInt)(block))
if err != nil {
return nil, err
}

return block, nil
}

return nil, nil
}

func (b *BlockDAO) GetLastKnownBlockByAddress(chainID uint64, address common.Address) (block *Block, err error) {
query := `SELECT blk_to, balance, nonce FROM blocks_ranges
WHERE address = ?
Expand Down Expand Up @@ -285,43 +119,6 @@ func (b *BlockDAO) GetLastKnownBlockByAddress(chainID uint64, address common.Add
return nil, nil
}

func (b *BlockDAO) getLastKnownBlocks(chainID uint64, addresses []common.Address) (map[common.Address]*Block, error) {
result := map[common.Address]*Block{}
for _, address := range addresses {
block, error := b.GetLastKnownBlockByAddress(chainID, address)
if error != nil {
return nil, error
}

if block != nil {
result[address] = block
}
}

return result, nil
}

// TODO Remove the method below, it is used in one place and duplicates getLastKnownBlocks method with slight unneeded change
func (b *BlockDAO) GetLastKnownBlockByAddresses(chainID uint64, addresses []common.Address) (map[common.Address]*Block, []common.Address, error) {
res := map[common.Address]*Block{}
accountsWithoutHistory := []common.Address{}
for _, address := range addresses {
block, err := b.GetLastKnownBlockByAddress(chainID, address)
if err != nil {
logutils.ZapLogger().Info("Can't get last block", zap.Error(err))
return nil, nil, err
}

if block != nil {
res[address] = block
} else {
accountsWithoutHistory = append(accountsWithoutHistory, address)
}
}

return res, accountsWithoutHistory, nil
}

func getNewRanges(ranges []*BlocksRange) ([]*BlocksRange, []*BlocksRange) {
initValue := big.NewInt(-1)
prevFrom := big.NewInt(-1)
Expand Down Expand Up @@ -369,27 +166,6 @@ func getNewRanges(ranges []*BlocksRange) ([]*BlocksRange, []*BlocksRange) {
return newRanges, deletedRanges
}

func deleteRange(chainID uint64, creator statementCreator, account common.Address, from *big.Int, to *big.Int) error {
logutils.ZapLogger().Info("delete blocks range",
zap.Stringer("account", account),
zap.Uint64("network", chainID),
zap.Stringer("from", from),
zap.Stringer("to", to),
)
delete, err := creator.Prepare(`DELETE FROM blocks_ranges
WHERE address = ?
AND network_id = ?
AND blk_from = ?
AND blk_to = ?`)
if err != nil {
logutils.ZapLogger().Info("some error", zap.Error(err))
return err
}

_, err = delete.Exec(account, chainID, (*bigint.SQLBigInt)(from), (*bigint.SQLBigInt)(to))
return err
}

func deleteAllRanges(creator statementCreator, account common.Address) error {
delete, err := creator.Prepare(`DELETE FROM blocks_ranges WHERE address = ?`)
if err != nil {
Expand All @@ -399,19 +175,3 @@ func deleteAllRanges(creator statementCreator, account common.Address) error {
_, err = delete.Exec(account)
return err
}

func insertRange(chainID uint64, creator statementCreator, account common.Address, from *big.Int, to *big.Int) error {
logutils.ZapLogger().Info("insert blocks range",
zap.Stringer("account", account),
zap.Uint64("network", chainID),
zap.Stringer("from", from),
zap.Stringer("to", to),
)
insert, err := creator.Prepare("INSERT INTO blocks_ranges (network_id, address, blk_from, blk_to) VALUES (?, ?, ?, ?)")
if err != nil {
return err
}

_, err = insert.Exec(chainID, account, (*bigint.SQLBigInt)(from), (*bigint.SQLBigInt)(to))
return err
}
2 changes: 1 addition & 1 deletion services/wallet/transfer/commands_sequential.go
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ func (c *loadBlocksAndTransfersCommand) areAllTransfersLoaded(account common.Add
if allBlocksLoaded {
headers, err := c.blockDAO.GetBlocksToLoadByAddress(c.chainClient.NetworkID(), account, 1)
if err != nil {
logutils.ZapLogger().Error("loadBlocksAndTransfersCommand GetFirstSavedBlock", zap.Error(err))
logutils.ZapLogger().Error("loadBlocksAndTransfersCommand GetBlocksToLoadByAddress", zap.Error(err))
return false, err
}

Expand Down
Loading

0 comments on commit 00a5c59

Please sign in to comment.