fix(wallet) fix reading amount for pending transactions
The reading of the amount for pending transactions was done in the same way as for transfers table. However, the transfers table has a string hex representation of the amount, while the pending transactions table has a binary representation of the amount (*big.Int). This was triggering the not int warning and value was missing. Updates status-desktop #12120
This commit is contained in:
parent
241595a871
commit
21e6914a3c
|
@ -488,6 +488,7 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
|
|||
var tokenAddress, contractAddress *eth.Address
|
||||
var aggregatedStatus int
|
||||
var dbTrAmount sql.NullString
|
||||
dbPTrAmount := new(big.Int)
|
||||
var dbMtFromAmount, dbMtToAmount, contractType sql.NullString
|
||||
var tokenCode, fromTokenCode, toTokenCode sql.NullString
|
||||
var methodHash sql.NullString
|
||||
|
@ -495,7 +496,7 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
|
|||
var communityMintEventDB sql.NullBool
|
||||
var communityMintEvent bool
|
||||
err := rows.Scan(&transferHash, &pendingHash, &chainID, &multiTxID, ×tamp, &dbMtType, &dbTrType, &fromAddress,
|
||||
&toAddressDB, &ownerAddressDB, &dbTrAmount, &dbMtFromAmount, &dbMtToAmount, &aggregatedStatus, &aggregatedCount,
|
||||
&toAddressDB, &ownerAddressDB, &dbTrAmount, (*bigint.SQLBigIntBytes)(dbPTrAmount), &dbMtFromAmount, &dbMtToAmount, &aggregatedStatus, &aggregatedCount,
|
||||
&tokenAddress, &dbTokenID, &tokenCode, &fromTokenCode, &toTokenCode, &outChainIDDB, &inChainIDDB, &contractType,
|
||||
&contractAddressDB, &methodHash, &communityMintEventDB)
|
||||
if err != nil {
|
||||
|
@ -556,7 +557,7 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
|
|||
activityType, _ := getActivityType(dbTrType)
|
||||
|
||||
ownerAddress := eth.BytesToAddress(ownerAddressDB)
|
||||
inAmount, outAmount := getTrInAndOutAmounts(activityType, dbTrAmount)
|
||||
inAmount, outAmount := getTrInAndOutAmounts(activityType, dbTrAmount, dbPTrAmount)
|
||||
|
||||
// Extract tokens and chains
|
||||
var involvedToken *Token
|
||||
|
@ -596,7 +597,7 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
|
|||
// Extract activity type: SendAT/ReceiveAT
|
||||
activityType, _ := getActivityType(dbTrType)
|
||||
|
||||
inAmount, outAmount := getTrInAndOutAmounts(activityType, dbTrAmount)
|
||||
inAmount, outAmount := getTrInAndOutAmounts(activityType, dbTrAmount, dbPTrAmount)
|
||||
|
||||
outChainID = new(common.ChainID)
|
||||
*outChainID = common.ChainID(chainID.Int64)
|
||||
|
@ -674,32 +675,40 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
|
|||
return entries, nil
|
||||
}
|
||||
|
||||
func getTrInAndOutAmounts(activityType Type, trAmount sql.NullString) (inAmount *hexutil.Big, outAmount *hexutil.Big) {
|
||||
func getTrInAndOutAmounts(activityType Type, trAmount sql.NullString, pTrAmount *big.Int) (inAmount *hexutil.Big, outAmount *hexutil.Big) {
|
||||
var amount *big.Int
|
||||
ok := false
|
||||
if trAmount.Valid {
|
||||
amount, ok := new(big.Int).SetString(trAmount.String, 16)
|
||||
if ok {
|
||||
switch activityType {
|
||||
case ContractDeploymentAT:
|
||||
fallthrough
|
||||
case SendAT:
|
||||
inAmount = (*hexutil.Big)(big.NewInt(0))
|
||||
outAmount = (*hexutil.Big)(amount)
|
||||
return
|
||||
case MintAT:
|
||||
fallthrough
|
||||
case ReceiveAT:
|
||||
inAmount = (*hexutil.Big)(amount)
|
||||
outAmount = (*hexutil.Big)(big.NewInt(0))
|
||||
return
|
||||
default:
|
||||
log.Warn(fmt.Sprintf("unexpected activity type %d", activityType))
|
||||
}
|
||||
} else {
|
||||
log.Warn(fmt.Sprintf("could not parse amount %s", trAmount.String))
|
||||
}
|
||||
amount, ok = new(big.Int).SetString(trAmount.String, 16)
|
||||
} else if pTrAmount != nil {
|
||||
// Process pending transaction value
|
||||
amount = pTrAmount
|
||||
ok = true
|
||||
} else {
|
||||
log.Warn(fmt.Sprintf("invalid transaction amount for type %d", activityType))
|
||||
}
|
||||
|
||||
if ok {
|
||||
switch activityType {
|
||||
case ContractDeploymentAT:
|
||||
fallthrough
|
||||
case SendAT:
|
||||
inAmount = (*hexutil.Big)(big.NewInt(0))
|
||||
outAmount = (*hexutil.Big)(amount)
|
||||
return
|
||||
case MintAT:
|
||||
fallthrough
|
||||
case ReceiveAT:
|
||||
inAmount = (*hexutil.Big)(amount)
|
||||
outAmount = (*hexutil.Big)(big.NewInt(0))
|
||||
return
|
||||
default:
|
||||
log.Warn(fmt.Sprintf("unexpected activity type %d", activityType))
|
||||
}
|
||||
} else {
|
||||
log.Warn(fmt.Sprintf("could not parse amount %s", trAmount.String))
|
||||
}
|
||||
|
||||
inAmount = (*hexutil.Big)(big.NewInt(0))
|
||||
outAmount = (*hexutil.Big)(big.NewInt(0))
|
||||
return
|
||||
|
|
|
@ -180,6 +180,7 @@ SELECT
|
|||
transfers.tx_to_address AS to_address,
|
||||
transfers.address AS owner_address,
|
||||
transfers.amount_padded128hex AS tr_amount,
|
||||
NULL AS ptr_amount,
|
||||
NULL AS mt_from_amount,
|
||||
NULL AS mt_to_amount,
|
||||
CASE
|
||||
|
@ -365,7 +366,8 @@ SELECT
|
|||
pending_transactions.from_address AS from_address,
|
||||
pending_transactions.to_address AS to_address,
|
||||
NULL AS owner_address,
|
||||
pending_transactions.value AS tr_amount,
|
||||
NULL AS tr_amount,
|
||||
pending_transactions.value AS ptr_amount,
|
||||
NULL AS mt_from_amount,
|
||||
NULL AS mt_to_amount,
|
||||
statusPending AS agg_status,
|
||||
|
@ -442,6 +444,7 @@ SELECT
|
|||
multi_transactions.to_address AS to_address,
|
||||
multi_transactions.from_address AS owner_address,
|
||||
NULL AS tr_amount,
|
||||
NULL AS ptr_amount,
|
||||
multi_transactions.from_amount AS mt_from_amount,
|
||||
multi_transactions.to_amount AS mt_to_amount,
|
||||
CASE
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
|
||||
"github.com/status-im/status-go/services/wallet/bigint"
|
||||
"github.com/status-im/status-go/services/wallet/common"
|
||||
"github.com/status-im/status-go/services/wallet/testutils"
|
||||
"github.com/status-im/status-go/services/wallet/token"
|
||||
|
@ -348,7 +349,7 @@ func InsertTestPendingTransaction(tb testing.TB, db *sql.DB, tr *TestTransfer) {
|
|||
INSERT INTO pending_transactions (network_id, hash, timestamp, from_address, to_address,
|
||||
symbol, gas_price, gas_limit, value, data, type, additional_data, multi_transaction_id
|
||||
) VALUES (?, ?, ?, ?, ?, 'ETH', 0, 0, ?, '', 'eth', '', ?)`,
|
||||
tr.ChainID, tr.Hash, tr.Timestamp, tr.From, tr.To, tr.Value, tr.MultiTransactionID)
|
||||
tr.ChainID, tr.Hash, tr.Timestamp, tr.From, tr.To, (*bigint.SQLBigIntBytes)(big.NewInt(tr.Value)), tr.MultiTransactionID)
|
||||
require.NoError(tb, err)
|
||||
}
|
||||
|
||||
|
|
|
@ -61,15 +61,17 @@ func GenerateTestPendingTransactions(count int) []PendingTransaction {
|
|||
|
||||
txs := make([]PendingTransaction, count)
|
||||
for i := 0; i < count; i++ {
|
||||
// Avoid generating zero values hash and addresses
|
||||
seed := i + 1
|
||||
txs[i] = PendingTransaction{
|
||||
Hash: eth.Hash{byte(i)},
|
||||
From: eth.Address{byte(i)},
|
||||
To: eth.Address{byte(i * 2)},
|
||||
Hash: eth.Hash{byte(seed)},
|
||||
From: eth.Address{byte(seed)},
|
||||
To: eth.Address{byte(seed * 2)},
|
||||
Type: RegisterENS,
|
||||
AdditionalData: "someuser.stateofus.eth",
|
||||
Value: bigint.BigInt{Int: big.NewInt(int64(i))},
|
||||
Value: bigint.BigInt{Int: big.NewInt(int64(seed))},
|
||||
GasLimit: bigint.BigInt{Int: big.NewInt(21000)},
|
||||
GasPrice: bigint.BigInt{Int: big.NewInt(int64(i))},
|
||||
GasPrice: bigint.BigInt{Int: big.NewInt(int64(seed))},
|
||||
ChainID: 777,
|
||||
Status: new(TxStatus),
|
||||
AutoDelete: new(bool),
|
||||
|
|
Loading…
Reference in New Issue