Skip to content

Commit fcb9a07

Browse files
committed
chore: remove multi-transaction ID references and clean up code
- Eliminated multi-transaction ID from various structures and functions across the wallet service. - Updated related queries and database interactions to reflect the removal of multi-transaction handling. - Cleaned up related tests.
1 parent 6d9e183 commit fcb9a07

File tree

9 files changed

+170
-218
lines changed

9 files changed

+170
-218
lines changed

services/wallet/activity/common/types.go

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,29 +90,27 @@ type Token struct {
9090
}
9191

9292
type EntryData struct {
93-
PayloadType PayloadType `json:"payloadType"`
94-
Key string `json:"key"`
95-
Transaction *TransactionIdentity `json:"transaction,omitempty"`
96-
ID *common.MultiTransactionIDType `json:"id,omitempty"`
97-
Transactions []*TransactionIdentity `json:"transactions,omitempty"`
98-
Timestamp *int64 `json:"timestamp,omitempty"`
99-
ActivityType *Type `json:"activityType,omitempty"`
100-
ActivityStatus *Status `json:"activityStatus,omitempty"`
101-
AmountOut *hexutil.Big `json:"amountOut,omitempty"`
102-
AmountIn *hexutil.Big `json:"amountIn,omitempty"`
103-
TokenOut *Token `json:"tokenOut,omitempty"`
104-
TokenIn *Token `json:"tokenIn,omitempty"`
105-
SymbolOut *string `json:"symbolOut,omitempty"`
106-
SymbolIn *string `json:"symbolIn,omitempty"`
107-
Sender *eth.Address `json:"sender,omitempty"`
108-
Recipient *eth.Address `json:"recipient,omitempty"`
109-
ChainIDOut *common.ChainID `json:"chainIdOut,omitempty"`
110-
ChainIDIn *common.ChainID `json:"chainIdIn,omitempty"`
111-
TransferType *TransferType `json:"transferType,omitempty"`
112-
ContractAddress *eth.Address `json:"contractAddress,omitempty"`
113-
CommunityID *string `json:"communityId,omitempty"`
114-
InteractedContractAddress *eth.Address `json:"interactedContractAddress,omitempty"`
115-
ApprovalSpender *eth.Address `json:"approvalSpender,omitempty"`
93+
PayloadType PayloadType `json:"payloadType"`
94+
Key string `json:"key"`
95+
Transaction *TransactionIdentity `json:"transaction,omitempty"`
96+
Timestamp *int64 `json:"timestamp,omitempty"`
97+
ActivityType *Type `json:"activityType,omitempty"`
98+
ActivityStatus *Status `json:"activityStatus,omitempty"`
99+
AmountOut *hexutil.Big `json:"amountOut,omitempty"`
100+
AmountIn *hexutil.Big `json:"amountIn,omitempty"`
101+
TokenOut *Token `json:"tokenOut,omitempty"`
102+
TokenIn *Token `json:"tokenIn,omitempty"`
103+
SymbolOut *string `json:"symbolOut,omitempty"`
104+
SymbolIn *string `json:"symbolIn,omitempty"`
105+
Sender *eth.Address `json:"sender,omitempty"`
106+
Recipient *eth.Address `json:"recipient,omitempty"`
107+
ChainIDOut *common.ChainID `json:"chainIdOut,omitempty"`
108+
ChainIDIn *common.ChainID `json:"chainIdIn,omitempty"`
109+
TransferType *TransferType `json:"transferType,omitempty"`
110+
ContractAddress *eth.Address `json:"contractAddress,omitempty"`
111+
CommunityID *string `json:"communityId,omitempty"`
112+
InteractedContractAddress *eth.Address `json:"interactedContractAddress,omitempty"`
113+
ApprovalSpender *eth.Address `json:"approvalSpender,omitempty"`
116114

117115
IsNew *bool `json:"isNew,omitempty"`
118116

services/wallet/common/const.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ import (
88
ethCommon "github.com/ethereum/go-ethereum/common"
99
)
1010

11-
type MultiTransactionIDType int64
12-
1311
const (
14-
NoMultiTransactionID = MultiTransactionIDType(0)
15-
HexAddressLength = 42
12+
HexAddressLength = 42
1613

1714
StatusDomain = "stateofus.eth"
1815
EthDomain = "eth"

services/wallet/transfer/commands.go

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -367,20 +367,6 @@ func (c *transfersCommand) saveAndConfirmPending(allTransfers []Transfer, blockN
367367
return resErr
368368
}
369369

370-
func externalTransactionOrError(err error, mTID int64) bool {
371-
if err == sql.ErrNoRows {
372-
// External transaction downloaded, ignore it
373-
return true
374-
} else if err != nil {
375-
logutils.ZapLogger().Warn("GetOwnedMultiTransactionID", zap.Error(err))
376-
return true
377-
} else if mTID <= 0 {
378-
// Existing external transaction, ignore it
379-
return true
380-
}
381-
return false
382-
}
383-
384370
func (c *transfersCommand) confirmPendingTransactions(tx *sql.Tx, allTransfers []Transfer) (notifyFunctions []func()) {
385371
notifyFunctions = make([]func(), 0)
386372

@@ -390,15 +376,8 @@ func (c *transfersCommand) confirmPendingTransactions(tx *sql.Tx, allTransfers [
390376
txHash := tr.Receipt.TxHash
391377
txType, err := transactions.GetOwnedPendingStatus(tx, chainID, txHash, tr.Address)
392378
if err == sql.ErrNoRows {
393-
if tr.MultiTransactionID > 0 {
394-
continue
395-
} else {
396-
// Outside transaction, already confirmed by another duplicate or not yet downloaded
397-
existingMTID, err := GetOwnedMultiTransactionID(tx, chainID, txHash, tr.Address)
398-
if externalTransactionOrError(err, existingMTID) {
399-
continue
400-
}
401-
}
379+
// Outside transaction, already confirmed by another duplicate or not yet downloaded
380+
continue
402381
} else if err != nil {
403382
logutils.ZapLogger().Warn("GetOwnedPendingStatus", zap.Error(err))
404383
continue

services/wallet/transfer/database.go

Lines changed: 71 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -372,41 +372,40 @@ func updateOrInsertTransfers(chainID uint64, creator statementCreator, transfers
372372
}
373373

374374
dbFields := transferDBFields{
375-
chainID: chainID,
376-
id: t.ID,
377-
blockHash: t.BlockHash,
378-
blockNumber: t.BlockNumber,
379-
timestamp: t.Timestamp,
380-
address: t.Address,
381-
transaction: t.Transaction,
382-
sender: t.From,
383-
receipt: t.Receipt,
384-
log: t.Log,
385-
transferType: t.Type,
386-
baseGasFees: t.BaseGasFees,
387-
multiTransactionID: t.MultiTransactionID,
388-
receiptStatus: receiptStatus,
389-
receiptType: receiptType,
390-
txHash: txHash,
391-
logIndex: logIndex,
392-
receiptBlockHash: blockHash,
393-
cumulativeGasUsed: cumulativeGasUsed,
394-
contractAddress: contractAddress,
395-
gasUsed: gasUsed,
396-
transactionIndex: transactionIndex,
397-
txType: txType,
398-
txProtected: txProtected,
399-
txGas: txGas,
400-
txGasPrice: txGasPrice,
401-
txGasTipCap: txGasTipCap,
402-
txGasFeeCap: txGasFeeCap,
403-
txValue: txValue,
404-
txNonce: txNonce,
405-
txSize: txSize,
406-
tokenAddress: tokenAddress,
407-
tokenID: tokenID,
408-
txFrom: txFrom,
409-
txTo: txTo,
375+
chainID: chainID,
376+
id: t.ID,
377+
blockHash: t.BlockHash,
378+
blockNumber: t.BlockNumber,
379+
timestamp: t.Timestamp,
380+
address: t.Address,
381+
transaction: t.Transaction,
382+
sender: t.From,
383+
receipt: t.Receipt,
384+
log: t.Log,
385+
transferType: t.Type,
386+
baseGasFees: t.BaseGasFees,
387+
receiptStatus: receiptStatus,
388+
receiptType: receiptType,
389+
txHash: txHash,
390+
logIndex: logIndex,
391+
receiptBlockHash: blockHash,
392+
cumulativeGasUsed: cumulativeGasUsed,
393+
contractAddress: contractAddress,
394+
gasUsed: gasUsed,
395+
transactionIndex: transactionIndex,
396+
txType: txType,
397+
txProtected: txProtected,
398+
txGas: txGas,
399+
txGasPrice: txGasPrice,
400+
txGasTipCap: txGasTipCap,
401+
txGasFeeCap: txGasFeeCap,
402+
txValue: txValue,
403+
txNonce: txNonce,
404+
txSize: txSize,
405+
tokenAddress: tokenAddress,
406+
tokenID: tokenID,
407+
txFrom: txFrom,
408+
txTo: txTo,
410409
}
411410
txsDBFields = append(txsDBFields, dbFields)
412411
}
@@ -415,50 +414,49 @@ func updateOrInsertTransfers(chainID uint64, creator statementCreator, transfers
415414
}
416415

417416
type transferDBFields struct {
418-
chainID uint64
419-
id common.Hash
420-
blockHash common.Hash
421-
blockNumber *big.Int
422-
timestamp uint64
423-
address common.Address
424-
transaction *types.Transaction
425-
sender common.Address
426-
receipt *types.Receipt
427-
log *types.Log
428-
transferType w_common.Type
429-
baseGasFees string
430-
multiTransactionID w_common.MultiTransactionIDType
431-
receiptStatus *uint64
432-
receiptType *uint8
433-
txHash *common.Hash
434-
logIndex *uint
435-
receiptBlockHash *common.Hash
436-
cumulativeGasUsed *uint64
437-
contractAddress *common.Address
438-
gasUsed *uint64
439-
transactionIndex *uint
440-
txType *uint8
441-
txProtected *bool
442-
txGas *uint64
443-
txGasPrice *big.Int
444-
txGasTipCap *big.Int
445-
txGasFeeCap *big.Int
446-
txValue *big.Int
447-
txNonce *uint64
448-
txSize *uint64
449-
tokenAddress *common.Address
450-
tokenID *big.Int
451-
txFrom *common.Address
452-
txTo *common.Address
417+
chainID uint64
418+
id common.Hash
419+
blockHash common.Hash
420+
blockNumber *big.Int
421+
timestamp uint64
422+
address common.Address
423+
transaction *types.Transaction
424+
sender common.Address
425+
receipt *types.Receipt
426+
log *types.Log
427+
transferType w_common.Type
428+
baseGasFees string
429+
receiptStatus *uint64
430+
receiptType *uint8
431+
txHash *common.Hash
432+
logIndex *uint
433+
receiptBlockHash *common.Hash
434+
cumulativeGasUsed *uint64
435+
contractAddress *common.Address
436+
gasUsed *uint64
437+
transactionIndex *uint
438+
txType *uint8
439+
txProtected *bool
440+
txGas *uint64
441+
txGasPrice *big.Int
442+
txGasTipCap *big.Int
443+
txGasFeeCap *big.Int
444+
txValue *big.Int
445+
txNonce *uint64
446+
txSize *uint64
447+
tokenAddress *common.Address
448+
tokenID *big.Int
449+
txFrom *common.Address
450+
txTo *common.Address
453451
}
454452

455453
func updateOrInsertTransfersDBFields(creator statementCreator, transfers []transferDBFields) error {
456454
insert, err := creator.Prepare(`INSERT OR REPLACE INTO transfers
457-
(network_id, hash, blk_hash, blk_number, timestamp, address, tx, sender, receipt, log, type, loaded, base_gas_fee, multi_transaction_id,
455+
(network_id, hash, blk_hash, blk_number, timestamp, address, tx, sender, receipt, log, type, loaded, base_gas_fee,
458456
status, receipt_type, tx_hash, log_index, block_hash, cumulative_gas_used, contract_address, gas_used, tx_index,
459457
tx_type, protected, gas_limit, gas_price_clamped64, gas_tip_cap_clamped64, gas_fee_cap_clamped64, amount_padded128hex, account_nonce, size, token_address, token_id, tx_from_address, tx_to_address)
460458
VALUES
461-
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
459+
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
462460
if err != nil {
463461
return err
464462
}
@@ -469,7 +467,7 @@ func updateOrInsertTransfersDBFields(creator statementCreator, transfers []trans
469467
txGasFeeCap := sqlite.BigIntToClampedInt64(t.txGasFeeCap)
470468
txValue := sqlite.BigIntToPadded128BitsStr(t.txValue)
471469

472-
_, err = insert.Exec(t.chainID, t.id, t.blockHash, (*bigint.SQLBigInt)(t.blockNumber), t.timestamp, t.address, &JSONBlob{t.transaction}, t.sender, &JSONBlob{t.receipt}, &JSONBlob{t.log}, t.transferType, t.baseGasFees, t.multiTransactionID,
470+
_, err = insert.Exec(t.chainID, t.id, t.blockHash, (*bigint.SQLBigInt)(t.blockNumber), t.timestamp, t.address, &JSONBlob{t.transaction}, t.sender, &JSONBlob{t.receipt}, &JSONBlob{t.log}, t.transferType, t.baseGasFees,
473471
t.receiptStatus, t.receiptType, t.txHash, t.logIndex, t.receiptBlockHash, t.cumulativeGasUsed, t.contractAddress, t.gasUsed, t.transactionIndex,
474472
t.txType, t.txProtected, t.txGas, txGasPrice, txGasTipCap, txGasFeeCap, txValue, t.txNonce, t.txSize, t.tokenAddress, (*bigint.SQLBigIntBytes)(t.tokenID), t.txFrom, t.txTo)
475473
if err != nil {
@@ -558,16 +556,6 @@ func markBlocksAsLoaded(chainID uint64, creator statementCreator, address common
558556
return nil
559557
}
560558

561-
// GetOwnedMultiTransactionID returns sql.ErrNoRows if no transaction is found for the given identity
562-
func GetOwnedMultiTransactionID(tx *sql.Tx, chainID w_common.ChainID, hash common.Hash, address common.Address) (mTID int64, err error) {
563-
row := tx.QueryRow(`SELECT COALESCE(multi_transaction_id, 0) FROM transfers WHERE network_id = ? AND tx_hash = ? AND address = ?`, chainID, hash, address)
564-
err = row.Scan(&mTID)
565-
if err != nil {
566-
return 0, err
567-
}
568-
return mTID, nil
569-
}
570-
571559
func (db *Database) GetLatestCollectibleTransfer(address common.Address, id thirdparty.CollectibleUniqueID) (*Transfer, error) {
572560
query := newTransfersQuery().
573561
FilterAddress(address).

services/wallet/transfer/database_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,13 @@ func TestDBSaveTransfers(t *testing.T) {
7272
tx := types.NewTransaction(1, address, nil, 10, big.NewInt(10), nil)
7373
transfers := []Transfer{
7474
{
75-
ID: common.Hash{1},
76-
Type: w_common.EthTransfer,
77-
BlockHash: header.Hash,
78-
BlockNumber: header.Number,
79-
Transaction: tx,
80-
Receipt: types.NewReceipt(nil, false, 100),
81-
Address: address,
82-
MultiTransactionID: 0,
75+
ID: common.Hash{1},
76+
Type: w_common.EthTransfer,
77+
BlockHash: header.Hash,
78+
BlockNumber: header.Number,
79+
Transaction: tx,
80+
Receipt: types.NewReceipt(nil, false, 100),
81+
Address: address,
8382
},
8483
}
8584
require.NoError(t, db.SaveBlocks(777, []*DBHeader{header}))
@@ -156,8 +155,6 @@ func TestGetTransfersForIdentities(t *testing.T) {
156155
require.Equal(t, uint64(trs[3].Timestamp), entries[1].Timestamp)
157156
require.Equal(t, uint64(trs[1].ChainID), entries[0].NetworkID)
158157
require.Equal(t, uint64(trs[3].ChainID), entries[1].NetworkID)
159-
require.Equal(t, w_common.MultiTransactionIDType(0), entries[0].MultiTransactionID)
160-
require.Equal(t, w_common.MultiTransactionIDType(0), entries[1].MultiTransactionID)
161158
}
162159

163160
func TestGetLatestCollectibleTransfer(t *testing.T) {

0 commit comments

Comments
 (0)