fix_: Add pending tx for collectibles

This commit is contained in:
Emil Sawicki 2024-07-08 11:02:06 +02:00 committed by Andrea Maria Piana
parent 58a3cc1127
commit 094d26dc66
8 changed files with 86 additions and 31 deletions

View File

@ -557,7 +557,7 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
} else if trType.Byte == toTrType { } else if trType.Byte == toTrType {
at := ReceiveAT at := ReceiveAT
if fromAddress == ZeroAddress && transferType != nil { if fromAddress == ZeroAddress && transferType != nil {
if *transferType == TransferTypeErc721 || (*transferType == TransferTypeErc20 && methodHash.Valid && (communityMintEvent || sliceContains(inputDataMethods, methodHash.String))) { if *transferType == TransferTypeErc721 || *transferType == TransferTypeErc1155 || (*transferType == TransferTypeErc20 && methodHash.Valid && (communityMintEvent || sliceContains(inputDataMethods, methodHash.String))) {
at = MintAT at = MintAT
} }
} }
@ -776,6 +776,8 @@ func contractTypeFromDBType(dbType string) (transferType *TransferType) {
*transferType = TransferTypeErc20 *transferType = TransferTypeErc20
case common.Erc721Transfer: case common.Erc721Transfer:
*transferType = TransferTypeErc721 *transferType = TransferTypeErc721
case common.Erc1155Transfer:
*transferType = TransferTypeErc1155
default: default:
return nil return nil
} }

View File

@ -344,9 +344,10 @@ func (s *CelerBridgeProcessor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, s
return nil, statusErrors.CreateErrorResponseFromError(err) return nil, statusErrors.CreateErrorResponseFromError(err)
} }
var tx *ethTypes.Transaction
txOpts := sendArgs.CbridgeTx.ToTransactOpts(signerFn) txOpts := sendArgs.CbridgeTx.ToTransactOpts(signerFn)
if token.IsNative() { if token.IsNative() {
return contract.SendNative( tx, err = contract.SendNative(
txOpts, txOpts,
sendArgs.CbridgeTx.Recipient, sendArgs.CbridgeTx.Recipient,
(*big.Int)(sendArgs.CbridgeTx.Amount), (*big.Int)(sendArgs.CbridgeTx.Amount),
@ -354,17 +355,25 @@ func (s *CelerBridgeProcessor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, s
uint64(time.Now().UnixMilli()), uint64(time.Now().UnixMilli()),
maxSlippage, maxSlippage,
) )
} else {
tx, err = contract.Send(
txOpts,
sendArgs.CbridgeTx.Recipient,
token.Address,
(*big.Int)(sendArgs.CbridgeTx.Amount),
sendArgs.CbridgeTx.ChainID,
uint64(time.Now().UnixMilli()),
maxSlippage,
)
} }
if err != nil {
return contract.Send( return tx, statusErrors.CreateErrorResponseFromError(err)
txOpts, }
sendArgs.CbridgeTx.Recipient, err = s.transactor.StoreAndTrackPendingTx(txOpts.From, sendArgs.CbridgeTx.Symbol, sendArgs.ChainID, sendArgs.CbridgeTx.MultiTransactionID, tx)
token.Address, if err != nil {
(*big.Int)(sendArgs.CbridgeTx.Amount), return tx, statusErrors.CreateErrorResponseFromError(err)
sendArgs.CbridgeTx.ChainID, }
uint64(time.Now().UnixMilli()), return tx, nil
maxSlippage,
)
} }
func (s *CelerBridgeProcessor) Send(sendArgs *MultipathProcessorTxArgs, verifiedAccount *account.SelectedExtKey) (types.Hash, error) { func (s *CelerBridgeProcessor) Send(sendArgs *MultipathProcessorTxArgs, verifiedAccount *account.SelectedExtKey) (types.Hash, error) {

View File

@ -341,18 +341,26 @@ func (h *HopBridgeProcessor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, sig
switch contractType { switch contractType {
case hop.CctpL1Bridge: case hop.CctpL1Bridge:
return h.sendCctpL1BridgeTx(contractAddress, ethClient, sendArgs.HopTx.ChainID, sendArgs.HopTx.Recipient, txOpts, bonderFee) tx, err = h.sendCctpL1BridgeTx(contractAddress, ethClient, sendArgs.HopTx.ChainID, sendArgs.HopTx.Recipient, txOpts, bonderFee)
case hop.L1Bridge: case hop.L1Bridge:
return h.sendL1BridgeTx(contractAddress, ethClient, sendArgs.HopTx.ChainID, sendArgs.HopTx.Recipient, txOpts, token, bonderFee) tx, err = h.sendL1BridgeTx(contractAddress, ethClient, sendArgs.HopTx.ChainID, sendArgs.HopTx.Recipient, txOpts, token, bonderFee)
case hop.L2AmmWrapper: case hop.L2AmmWrapper:
return h.sendL2AmmWrapperTx(contractAddress, ethClient, sendArgs.HopTx.ChainID, sendArgs.HopTx.Recipient, txOpts, bonderFee) tx, err = h.sendL2AmmWrapperTx(contractAddress, ethClient, sendArgs.HopTx.ChainID, sendArgs.HopTx.Recipient, txOpts, bonderFee)
case hop.CctpL2Bridge: case hop.CctpL2Bridge:
return h.sendCctpL2BridgeTx(contractAddress, ethClient, sendArgs.HopTx.ChainID, sendArgs.HopTx.Recipient, txOpts, bonderFee) tx, err = h.sendCctpL2BridgeTx(contractAddress, ethClient, sendArgs.HopTx.ChainID, sendArgs.HopTx.Recipient, txOpts, bonderFee)
case hop.L2Bridge: case hop.L2Bridge:
return h.sendL2BridgeTx(contractAddress, ethClient, sendArgs.HopTx.ChainID, sendArgs.HopTx.Recipient, txOpts, bonderFee) tx, err = h.sendL2BridgeTx(contractAddress, ethClient, sendArgs.HopTx.ChainID, sendArgs.HopTx.Recipient, txOpts, bonderFee)
default:
return tx, ErrContractTypeNotSupported
} }
if err != nil {
return tx, ErrContractTypeNotSupported return tx, statusErrors.CreateErrorResponseFromError(err)
}
err = h.transactor.StoreAndTrackPendingTx(txOpts.From, sendArgs.HopTx.Symbol, sendArgs.ChainID, sendArgs.HopTx.MultiTransactionID, tx)
if err != nil {
return tx, statusErrors.CreateErrorResponseFromError(err)
}
return tx, nil
} }
func (h *HopBridgeProcessor) Send(sendArgs *MultipathProcessorTxArgs, verifiedAccount *account.SelectedExtKey) (hash types.Hash, err error) { func (h *HopBridgeProcessor) Send(sendArgs *MultipathProcessorTxArgs, verifiedAccount *account.SelectedExtKey) (hash types.Hash, err error) {

View File

@ -151,8 +151,9 @@ func (s *ERC1155Processor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, signe
argNonce := hexutil.Uint64(nonce) argNonce := hexutil.Uint64(nonce)
sendArgs.ERC1155TransferTx.Nonce = &argNonce sendArgs.ERC1155TransferTx.Nonce = &argNonce
txOpts := sendArgs.ERC1155TransferTx.ToTransactOpts(signerFn) txOpts := sendArgs.ERC1155TransferTx.ToTransactOpts(signerFn)
from := common.Address(sendArgs.ERC1155TransferTx.From)
tx, err = contract.SafeTransferFrom( tx, err = contract.SafeTransferFrom(
txOpts, common.Address(sendArgs.ERC1155TransferTx.From), txOpts, from,
sendArgs.ERC1155TransferTx.Recipient, sendArgs.ERC1155TransferTx.Recipient,
sendArgs.ERC1155TransferTx.TokenID.ToInt(), sendArgs.ERC1155TransferTx.TokenID.ToInt(),
sendArgs.ERC1155TransferTx.Amount.ToInt(), sendArgs.ERC1155TransferTx.Amount.ToInt(),
@ -161,7 +162,10 @@ func (s *ERC1155Processor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, signe
if err != nil { if err != nil {
return tx, statusErrors.CreateErrorResponseFromError(err) return tx, statusErrors.CreateErrorResponseFromError(err)
} }
err = s.transactor.StoreAndTrackPendingTx(from, sendArgs.ERC1155TransferTx.Symbol, sendArgs.ChainID, sendArgs.ERC1155TransferTx.MultiTransactionID, tx)
if err != nil {
return tx, statusErrors.CreateErrorResponseFromError(err)
}
return tx, nil return tx, nil
} }

View File

@ -148,13 +148,17 @@ func (s *ERC721Processor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, signer
argNonce := hexutil.Uint64(nonce) argNonce := hexutil.Uint64(nonce)
sendArgs.ERC721TransferTx.Nonce = &argNonce sendArgs.ERC721TransferTx.Nonce = &argNonce
txOpts := sendArgs.ERC721TransferTx.ToTransactOpts(signerFn) txOpts := sendArgs.ERC721TransferTx.ToTransactOpts(signerFn)
from := common.Address(sendArgs.ERC721TransferTx.From)
tx, err = contract.SafeTransferFrom(txOpts, common.Address(sendArgs.ERC721TransferTx.From), tx, err = contract.SafeTransferFrom(txOpts, from,
sendArgs.ERC721TransferTx.Recipient, sendArgs.ERC721TransferTx.Recipient,
sendArgs.ERC721TransferTx.TokenID.ToInt()) sendArgs.ERC721TransferTx.TokenID.ToInt())
if err != nil { if err != nil {
return tx, statusErrors.CreateErrorResponseFromError(err) return tx, statusErrors.CreateErrorResponseFromError(err)
} }
err = s.transactor.StoreAndTrackPendingTx(from, sendArgs.ERC721TransferTx.Symbol, sendArgs.ChainID, sendArgs.ERC721TransferTx.MultiTransactionID, tx)
if err != nil {
return tx, statusErrors.CreateErrorResponseFromError(err)
}
return tx, nil return tx, nil
} }

View File

@ -162,6 +162,20 @@ func (mr *MockTransactorIfaceMockRecorder) SendTransactionWithSignature(from, sy
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendTransactionWithSignature", reflect.TypeOf((*MockTransactorIface)(nil).SendTransactionWithSignature), from, symbol, multiTransactionID, tx) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendTransactionWithSignature", reflect.TypeOf((*MockTransactorIface)(nil).SendTransactionWithSignature), from, symbol, multiTransactionID, tx)
} }
// StoreAndTrackPendingTx mocks base method.
func (m *MockTransactorIface) StoreAndTrackPendingTx(from common.Address, symbol string, chainID uint64, multiTransactionID common0.MultiTransactionIDType, tx *types.Transaction) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "StoreAndTrackPendingTx", from, symbol, chainID, multiTransactionID, tx)
ret0, _ := ret[0].(error)
return ret0
}
// StoreAndTrackPendingTx indicates an expected call of StoreAndTrackPendingTx.
func (mr *MockTransactorIfaceMockRecorder) StoreAndTrackPendingTx(from, symbol, chainID, multiTransactionID, tx interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StoreAndTrackPendingTx", reflect.TypeOf((*MockTransactorIface)(nil).StoreAndTrackPendingTx), from, symbol, chainID, multiTransactionID, tx)
}
// ValidateAndBuildTransaction mocks base method. // ValidateAndBuildTransaction mocks base method.
func (m *MockTransactorIface) ValidateAndBuildTransaction(chainID uint64, sendArgs transactions.SendTxArgs) (*types.Transaction, error) { func (m *MockTransactorIface) ValidateAndBuildTransaction(chainID uint64, sendArgs transactions.SendTxArgs) (*types.Transaction, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()

View File

@ -55,6 +55,7 @@ type TransactorIface interface {
SendRawTransaction(chainID uint64, rawTx string) error SendRawTransaction(chainID uint64, rawTx string) error
BuildTransactionWithSignature(chainID uint64, args SendTxArgs, sig []byte) (*gethtypes.Transaction, error) BuildTransactionWithSignature(chainID uint64, args SendTxArgs, sig []byte) (*gethtypes.Transaction, error)
SendTransactionWithSignature(from common.Address, symbol string, multiTransactionID wallet_common.MultiTransactionIDType, tx *gethtypes.Transaction) (hash types.Hash, err error) SendTransactionWithSignature(from common.Address, symbol string, multiTransactionID wallet_common.MultiTransactionIDType, tx *gethtypes.Transaction) (hash types.Hash, err error)
StoreAndTrackPendingTx(from common.Address, symbol string, chainID uint64, multiTransactionID wallet_common.MultiTransactionIDType, tx *gethtypes.Transaction) error
} }
// Transactor validates, signs transactions. // Transactor validates, signs transactions.
@ -202,6 +203,15 @@ func createPendingTransaction(from common.Address, symbol string, chainID uint64
return return
} }
func (t *Transactor) StoreAndTrackPendingTx(from common.Address, symbol string, chainID uint64, multiTransactionID wallet_common.MultiTransactionIDType, tx *gethtypes.Transaction) error {
if t.pendingTracker == nil {
return nil
}
pTx := createPendingTransaction(from, symbol, chainID, multiTransactionID, tx)
return t.pendingTracker.StoreAndTrackPendingTx(pTx)
}
func (t *Transactor) sendTransaction(rpcWrapper *rpcWrapper, from common.Address, symbol string, func (t *Transactor) sendTransaction(rpcWrapper *rpcWrapper, from common.Address, symbol string,
multiTransactionID wallet_common.MultiTransactionIDType, tx *gethtypes.Transaction) (hash types.Hash, err error) { multiTransactionID wallet_common.MultiTransactionIDType, tx *gethtypes.Transaction) (hash types.Hash, err error) {
ctx, cancel := context.WithTimeout(context.Background(), t.rpcCallTimeout) ctx, cancel := context.WithTimeout(context.Background(), t.rpcCallTimeout)
@ -211,14 +221,9 @@ func (t *Transactor) sendTransaction(rpcWrapper *rpcWrapper, from common.Address
return hash, err return hash, err
} }
if t.pendingTracker != nil { err = t.StoreAndTrackPendingTx(from, symbol, rpcWrapper.chainID, multiTransactionID, tx)
if err != nil {
tx := createPendingTransaction(from, symbol, rpcWrapper.chainID, multiTransactionID, tx) return hash, err
err := t.pendingTracker.StoreAndTrackPendingTx(tx)
if err != nil {
return hash, err
}
} }
return types.Hash(tx.Hash()), nil return types.Hash(tx.Hash()), nil

View File

@ -23,6 +23,7 @@ import (
"github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/params" "github.com/status-im/status-go/params"
"github.com/status-im/status-go/rpc" "github.com/status-im/status-go/rpc"
wallet_common "github.com/status-im/status-go/services/wallet/common"
"github.com/status-im/status-go/sqlite" "github.com/status-im/status-go/sqlite"
"github.com/status-im/status-go/t/utils" "github.com/status-im/status-go/t/utils"
"github.com/status-im/status-go/transactions/fake" "github.com/status-im/status-go/transactions/fake"
@ -371,3 +372,11 @@ func (s *TransactorSuite) TestHashTransaction() {
s.NotEqual(common.Hash{}, hash) s.NotEqual(common.Hash{}, hash)
} }
func (s *TransactorSuite) TestStoreAndTrackPendingTx() {
s.Nil(s.manager.pendingTracker)
// Empty tracker doesn't produce error
err := s.manager.StoreAndTrackPendingTx(common.Address{}, "", 0, wallet_common.MultiTransactionIDType(0), nil)
s.NoError(err)
}