fix(wallet): properly parse multitransaction amounts
This commit is contained in:
parent
ad9ad4026b
commit
60b160997c
|
@ -476,14 +476,18 @@ func getTrInAndOutAmounts(activityType Type, trAmount sql.NullString) (inAmount
|
||||||
|
|
||||||
func getMtInAndOutAmounts(dbFromAmount sql.NullString, dbToAmount sql.NullString) (inAmount *hexutil.Big, outAmount *hexutil.Big) {
|
func getMtInAndOutAmounts(dbFromAmount sql.NullString, dbToAmount sql.NullString) (inAmount *hexutil.Big, outAmount *hexutil.Big) {
|
||||||
if dbFromAmount.Valid && dbToAmount.Valid {
|
if dbFromAmount.Valid && dbToAmount.Valid {
|
||||||
fromAmount, frOk := new(big.Int).SetString(dbFromAmount.String, 16)
|
fromHexStr := dbFromAmount.String
|
||||||
toAmount, toOk := new(big.Int).SetString(dbToAmount.String, 16)
|
toHexStr := dbToAmount.String
|
||||||
if frOk && toOk {
|
if len(fromHexStr) > 2 && len(toHexStr) > 2 {
|
||||||
inAmount = (*hexutil.Big)(toAmount)
|
fromAmount, frOk := new(big.Int).SetString(dbFromAmount.String[2:], 16)
|
||||||
outAmount = (*hexutil.Big)(fromAmount)
|
toAmount, toOk := new(big.Int).SetString(dbToAmount.String[2:], 16)
|
||||||
return
|
if frOk && toOk {
|
||||||
|
inAmount = (*hexutil.Big)(toAmount)
|
||||||
|
outAmount = (*hexutil.Big)(fromAmount)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.Warn(fmt.Sprintf("could not parse amounts %s %s", dbFromAmount.String, dbToAmount.String))
|
log.Warn(fmt.Sprintf("could not parse amounts %s %s", fromHexStr, toHexStr))
|
||||||
} else {
|
} else {
|
||||||
log.Warn("invalid transaction amounts")
|
log.Warn("invalid transaction amounts")
|
||||||
}
|
}
|
||||||
|
@ -613,6 +617,7 @@ func getActivityEntries(ctx context.Context, db *sql.DB, addresses []eth.Address
|
||||||
} else if multiTxID.Valid {
|
} else if multiTxID.Valid {
|
||||||
mtInAmount, mtOutAmount := getMtInAndOutAmounts(dbMtFromAmount, dbMtToAmount)
|
mtInAmount, mtOutAmount := getMtInAndOutAmounts(dbMtFromAmount, dbMtToAmount)
|
||||||
activityType := multiTransactionTypeToActivityType(transfer.MultiTransactionType(dbMtType.Byte))
|
activityType := multiTransactionTypeToActivityType(transfer.MultiTransactionType(dbMtType.Byte))
|
||||||
|
fmt.Println("getMtInAndOutAmounts", multiTxID.Int64, activityType, mtInAmount, mtOutAmount)
|
||||||
entry = NewActivityEntryWithMultiTransaction(transfer.MultiTransactionIDType(multiTxID.Int64),
|
entry = NewActivityEntryWithMultiTransaction(transfer.MultiTransactionIDType(multiTxID.Int64),
|
||||||
timestamp, activityType, activityStatus, mtInAmount, mtOutAmount)
|
timestamp, activityType, activityStatus, mtInAmount, mtOutAmount)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,10 +3,12 @@ package transfer
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
eth_common "github.com/ethereum/go-ethereum/common"
|
eth_common "github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/status-im/status-go/services/wallet/common"
|
"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/testutils"
|
||||||
"github.com/status-im/status-go/sqlite"
|
"github.com/status-im/status-go/sqlite"
|
||||||
|
@ -72,6 +74,7 @@ func GenerateTestSendMultiTransaction(tr TestTransfer) TestMultiTransaction {
|
||||||
FromToken: tr.Token,
|
FromToken: tr.Token,
|
||||||
ToToken: tr.Token,
|
ToToken: tr.Token,
|
||||||
FromAmount: tr.Value,
|
FromAmount: tr.Value,
|
||||||
|
ToAmount: 0,
|
||||||
Timestamp: tr.Timestamp,
|
Timestamp: tr.Timestamp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,10 +155,13 @@ func InsertTestMultiTransaction(t *testing.T, db *sql.DB, tr *TestMultiTransacti
|
||||||
if tr.ToToken == "" {
|
if tr.ToToken == "" {
|
||||||
toTokenType = testutils.EthSymbol
|
toTokenType = testutils.EthSymbol
|
||||||
}
|
}
|
||||||
|
fromAmount := (*hexutil.Big)(big.NewInt(tr.FromAmount))
|
||||||
|
toAmount := (*hexutil.Big)(big.NewInt(tr.ToAmount))
|
||||||
|
|
||||||
result, err := db.Exec(`
|
result, err := db.Exec(`
|
||||||
INSERT INTO multi_transactions (from_address, from_asset, from_amount, to_address, to_asset, to_amount, type, timestamp
|
INSERT INTO multi_transactions (from_address, from_asset, from_amount, to_address, to_asset, to_amount, type, timestamp
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||||
tr.FromAddress, fromTokenType, tr.FromAmount, tr.ToAddress, toTokenType, tr.ToAmount, tr.MultiTransactionType, tr.Timestamp)
|
tr.FromAddress, fromTokenType, fromAmount.String(), tr.ToAddress, toTokenType, toAmount.String(), tr.MultiTransactionType, tr.Timestamp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
rowID, err := result.LastInsertId()
|
rowID, err := result.LastInsertId()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
Loading…
Reference in New Issue