diff --git a/services/wallet/activity/activity.go b/services/wallet/activity/activity.go index ef80df647..2bcd650d0 100644 --- a/services/wallet/activity/activity.go +++ b/services/wallet/activity/activity.go @@ -557,7 +557,7 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses } else if trType.Byte == toTrType { at := ReceiveAT 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 } } @@ -776,6 +776,8 @@ func contractTypeFromDBType(dbType string) (transferType *TransferType) { *transferType = TransferTypeErc20 case common.Erc721Transfer: *transferType = TransferTypeErc721 + case common.Erc1155Transfer: + *transferType = TransferTypeErc1155 default: return nil } diff --git a/services/wallet/router/pathprocessor/processor_bridge_celar.go b/services/wallet/router/pathprocessor/processor_bridge_celar.go index c3f5c3023..44cc0f217 100644 --- a/services/wallet/router/pathprocessor/processor_bridge_celar.go +++ b/services/wallet/router/pathprocessor/processor_bridge_celar.go @@ -344,9 +344,10 @@ func (s *CelerBridgeProcessor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, s return nil, statusErrors.CreateErrorResponseFromError(err) } + var tx *ethTypes.Transaction txOpts := sendArgs.CbridgeTx.ToTransactOpts(signerFn) if token.IsNative() { - return contract.SendNative( + tx, err = contract.SendNative( txOpts, sendArgs.CbridgeTx.Recipient, (*big.Int)(sendArgs.CbridgeTx.Amount), @@ -354,17 +355,25 @@ func (s *CelerBridgeProcessor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, s uint64(time.Now().UnixMilli()), 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, + ) } - - return 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 tx, statusErrors.CreateErrorResponseFromError(err) + } + err = s.transactor.StoreAndTrackPendingTx(txOpts.From, sendArgs.CbridgeTx.Symbol, sendArgs.ChainID, sendArgs.CbridgeTx.MultiTransactionID, tx) + if err != nil { + return tx, statusErrors.CreateErrorResponseFromError(err) + } + return tx, nil } func (s *CelerBridgeProcessor) Send(sendArgs *MultipathProcessorTxArgs, verifiedAccount *account.SelectedExtKey) (types.Hash, error) { diff --git a/services/wallet/router/pathprocessor/processor_bridge_hop.go b/services/wallet/router/pathprocessor/processor_bridge_hop.go index 7379f0760..1bbdd900e 100644 --- a/services/wallet/router/pathprocessor/processor_bridge_hop.go +++ b/services/wallet/router/pathprocessor/processor_bridge_hop.go @@ -341,18 +341,26 @@ func (h *HopBridgeProcessor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, sig switch contractType { 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: - 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: - 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: - 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: - 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 } - - return tx, ErrContractTypeNotSupported + if err != nil { + 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) { diff --git a/services/wallet/router/pathprocessor/processor_erc1155.go b/services/wallet/router/pathprocessor/processor_erc1155.go index 51e87fa18..66ef0039e 100644 --- a/services/wallet/router/pathprocessor/processor_erc1155.go +++ b/services/wallet/router/pathprocessor/processor_erc1155.go @@ -151,8 +151,9 @@ func (s *ERC1155Processor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, signe argNonce := hexutil.Uint64(nonce) sendArgs.ERC1155TransferTx.Nonce = &argNonce txOpts := sendArgs.ERC1155TransferTx.ToTransactOpts(signerFn) + from := common.Address(sendArgs.ERC1155TransferTx.From) tx, err = contract.SafeTransferFrom( - txOpts, common.Address(sendArgs.ERC1155TransferTx.From), + txOpts, from, sendArgs.ERC1155TransferTx.Recipient, sendArgs.ERC1155TransferTx.TokenID.ToInt(), sendArgs.ERC1155TransferTx.Amount.ToInt(), @@ -161,7 +162,10 @@ func (s *ERC1155Processor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, signe if err != nil { 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 } diff --git a/services/wallet/router/pathprocessor/processor_erc721.go b/services/wallet/router/pathprocessor/processor_erc721.go index 9b861bcec..2c77f21de 100644 --- a/services/wallet/router/pathprocessor/processor_erc721.go +++ b/services/wallet/router/pathprocessor/processor_erc721.go @@ -148,13 +148,17 @@ func (s *ERC721Processor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, signer argNonce := hexutil.Uint64(nonce) sendArgs.ERC721TransferTx.Nonce = &argNonce txOpts := sendArgs.ERC721TransferTx.ToTransactOpts(signerFn) - - tx, err = contract.SafeTransferFrom(txOpts, common.Address(sendArgs.ERC721TransferTx.From), + from := common.Address(sendArgs.ERC721TransferTx.From) + tx, err = contract.SafeTransferFrom(txOpts, from, sendArgs.ERC721TransferTx.Recipient, sendArgs.ERC721TransferTx.TokenID.ToInt()) if err != nil { 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 } diff --git a/transactions/mock_transactor/transactor.go b/transactions/mock_transactor/transactor.go index 27c34d1c5..09982e599 100644 --- a/transactions/mock_transactor/transactor.go +++ b/transactions/mock_transactor/transactor.go @@ -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) } +// 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. func (m *MockTransactorIface) ValidateAndBuildTransaction(chainID uint64, sendArgs transactions.SendTxArgs) (*types.Transaction, error) { m.ctrl.T.Helper() diff --git a/transactions/transactor.go b/transactions/transactor.go index 2efbb8dc3..667ffac4e 100644 --- a/transactions/transactor.go +++ b/transactions/transactor.go @@ -55,6 +55,7 @@ type TransactorIface interface { SendRawTransaction(chainID uint64, rawTx string) 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) + StoreAndTrackPendingTx(from common.Address, symbol string, chainID uint64, multiTransactionID wallet_common.MultiTransactionIDType, tx *gethtypes.Transaction) error } // Transactor validates, signs transactions. @@ -202,6 +203,15 @@ func createPendingTransaction(from common.Address, symbol string, chainID uint64 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, multiTransactionID wallet_common.MultiTransactionIDType, tx *gethtypes.Transaction) (hash types.Hash, err error) { ctx, cancel := context.WithTimeout(context.Background(), t.rpcCallTimeout) @@ -211,14 +221,9 @@ func (t *Transactor) sendTransaction(rpcWrapper *rpcWrapper, from common.Address return hash, err } - if t.pendingTracker != nil { - - tx := createPendingTransaction(from, symbol, rpcWrapper.chainID, multiTransactionID, tx) - - err := t.pendingTracker.StoreAndTrackPendingTx(tx) - if err != nil { - return hash, err - } + err = t.StoreAndTrackPendingTx(from, symbol, rpcWrapper.chainID, multiTransactionID, tx) + if err != nil { + return hash, err } return types.Hash(tx.Hash()), nil diff --git a/transactions/transactor_test.go b/transactions/transactor_test.go index b587aae94..677cea243 100644 --- a/transactions/transactor_test.go +++ b/transactions/transactor_test.go @@ -23,6 +23,7 @@ import ( "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/params" "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/t/utils" "github.com/status-im/status-go/transactions/fake" @@ -371,3 +372,11 @@ func (s *TransactorSuite) TestHashTransaction() { 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) +}