diff --git a/api/backend.go b/api/backend.go index f7dbeaf68..53486502f 100644 --- a/api/backend.go +++ b/api/backend.go @@ -12,7 +12,7 @@ import ( "github.com/status-im/status-go/params" "github.com/status-im/status-go/services/personal" "github.com/status-im/status-go/services/typeddata" - "github.com/status-im/status-go/transactions" + "github.com/status-im/status-go/services/wallet/wallettypes" ) // StatusBackend defines the contract for the Status.im service @@ -39,13 +39,13 @@ type StatusBackend interface { CallPrivateRPC(inputJSON string) (string, error) CallRPC(inputJSON string) (string, error) - HashTransaction(sendArgs transactions.SendTxArgs) (transactions.SendTxArgs, types.Hash, error) + HashTransaction(sendArgs wallettypes.SendTxArgs) (wallettypes.SendTxArgs, types.Hash, error) HashTypedData(typed typeddata.TypedData) (types.Hash, error) HashTypedDataV4(typed signercore.TypedData) (types.Hash, error) ResetChainData() error - SendTransaction(sendArgs transactions.SendTxArgs, password string) (hash types.Hash, err error) - SendTransactionWithChainID(chainID uint64, sendArgs transactions.SendTxArgs, password string) (hash types.Hash, err error) - SendTransactionWithSignature(sendArgs transactions.SendTxArgs, sig []byte) (hash types.Hash, err error) + SendTransaction(sendArgs wallettypes.SendTxArgs, password string) (hash types.Hash, err error) + SendTransactionWithChainID(chainID uint64, sendArgs wallettypes.SendTxArgs, password string) (hash types.Hash, err error) + SendTransactionWithSignature(sendArgs wallettypes.SendTxArgs, sig []byte) (hash types.Hash, err error) SignHash(hexEncodedHash string) (string, error) SignMessage(rpcParams personal.SignParams) (types.HexBytes, error) SignTypedData(typed typeddata.TypedData, address string, password string) (types.HexBytes, error) diff --git a/api/backend_test.go b/api/backend_test.go index b2ca19a1e..c3cfb7007 100644 --- a/api/backend_test.go +++ b/api/backend_test.go @@ -37,11 +37,11 @@ import ( "github.com/status-im/status-go/services/typeddata" "github.com/status-im/status-go/services/wallet" walletservice "github.com/status-im/status-go/services/wallet" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/signal" "github.com/status-im/status-go/sqlite" "github.com/status-im/status-go/t/helpers" "github.com/status-im/status-go/t/utils" - "github.com/status-im/status-go/transactions" "github.com/status-im/status-go/walletdatabase" ) @@ -603,7 +603,7 @@ func TestBackendGetVerifiedAccount(t *testing.T) { require.NoError(t, err) address := gethcrypto.PubkeyToAddress(pkey.PublicKey) key, err := backend.getVerifiedWalletAccount(address.String(), password) - require.EqualError(t, err, transactions.ErrAccountDoesntExist.Error()) + require.EqualError(t, err, wallettypes.ErrAccountDoesntExist.Error()) require.Nil(t, key) }) diff --git a/api/geth_backend.go b/api/geth_backend.go index 81dbc16c5..77acd2627 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -55,6 +55,7 @@ import ( "github.com/status-im/status-go/services/personal" "github.com/status-im/status-go/services/typeddata" "github.com/status-im/status-go/services/wallet" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/signal" "github.com/status-im/status-go/sqlite" "github.com/status-im/status-go/transactions" @@ -2267,7 +2268,7 @@ func (b *GethStatusBackend) CallPrivateRPC(inputJSON string) (string, error) { } // SendTransaction creates a new transaction and waits until it's complete. -func (b *GethStatusBackend) SendTransaction(sendArgs transactions.SendTxArgs, password string) (hash types.Hash, err error) { +func (b *GethStatusBackend) SendTransaction(sendArgs wallettypes.SendTxArgs, password string) (hash types.Hash, err error) { verifiedAccount, err := b.getVerifiedWalletAccount(sendArgs.From.String(), password) if err != nil { return hash, err @@ -2277,7 +2278,7 @@ func (b *GethStatusBackend) SendTransaction(sendArgs transactions.SendTxArgs, pa return hash, err } -func (b *GethStatusBackend) SendTransactionWithChainID(chainID uint64, sendArgs transactions.SendTxArgs, password string) (hash types.Hash, err error) { +func (b *GethStatusBackend) SendTransactionWithChainID(chainID uint64, sendArgs wallettypes.SendTxArgs, password string) (hash types.Hash, err error) { verifiedAccount, err := b.getVerifiedWalletAccount(sendArgs.From.String(), password) if err != nil { return hash, err @@ -2287,7 +2288,7 @@ func (b *GethStatusBackend) SendTransactionWithChainID(chainID uint64, sendArgs return hash, err } -func (b *GethStatusBackend) SendTransactionWithSignature(sendArgs transactions.SendTxArgs, sig []byte) (hash types.Hash, err error) { +func (b *GethStatusBackend) SendTransactionWithSignature(sendArgs wallettypes.SendTxArgs, sig []byte) (hash types.Hash, err error) { txWithSignature, err := b.transactor.BuildTransactionWithSignature(b.transactor.NetworkID(), sendArgs, sig) if err != nil { return hash, err @@ -2297,7 +2298,7 @@ func (b *GethStatusBackend) SendTransactionWithSignature(sendArgs transactions.S } // HashTransaction validate the transaction and returns new sendArgs and the transaction hash. -func (b *GethStatusBackend) HashTransaction(sendArgs transactions.SendTxArgs) (transactions.SendTxArgs, types.Hash, error) { +func (b *GethStatusBackend) HashTransaction(sendArgs wallettypes.SendTxArgs) (wallettypes.SendTxArgs, types.Hash, error) { return b.transactor.HashTransaction(sendArgs) } @@ -2379,8 +2380,8 @@ func (b *GethStatusBackend) getVerifiedWalletAccount(address, password string) ( } if !exists { - b.logger.Error("failed to get a selected account", zap.Error(transactions.ErrInvalidTxSender)) - return nil, transactions.ErrAccountDoesntExist + b.logger.Error("failed to get a selected account", zap.Error(wallettypes.ErrInvalidTxSender)) + return nil, wallettypes.ErrAccountDoesntExist } key, err := b.accountManager.VerifyAccountPassword(config.KeyStoreDir, address, password) diff --git a/mobile/response.go b/mobile/response.go index 0ad05a610..e75fd0808 100644 --- a/mobile/response.go +++ b/mobile/response.go @@ -5,7 +5,7 @@ import ( "github.com/status-im/status-go/account" "github.com/status-im/status-go/eth-node/keystore" - "github.com/status-im/status-go/transactions" + "github.com/status-im/status-go/services/wallet/wallettypes" ) const ( @@ -20,9 +20,9 @@ const ( ) var errToCodeMap = map[error]int{ - account.ErrNoAccountSelected: codeErrNoAccountSelected, - transactions.ErrInvalidTxSender: codeErrInvalidTxSender, - keystore.ErrDecrypt: codeErrDecrypt, + account.ErrNoAccountSelected: codeErrNoAccountSelected, + wallettypes.ErrInvalidTxSender: codeErrInvalidTxSender, + keystore.ErrDecrypt: codeErrDecrypt, } type jsonrpcSuccessfulResponse struct { diff --git a/mobile/status.go b/mobile/status.go index 3b431d8dc..eadd7ce66 100644 --- a/mobile/status.go +++ b/mobile/status.go @@ -46,8 +46,8 @@ import ( "github.com/status-im/status-go/server/pairing/preflight" "github.com/status-im/status-go/services/personal" "github.com/status-im/status-go/services/typeddata" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/signal" - "github.com/status-im/status-go/transactions" "github.com/status-im/status-go/mobile/callog" ) @@ -848,7 +848,7 @@ func SendTransactionWithChainID(chainID int, txArgsJSON, password string) string // sendTransactionWithChainID converts RPC args and calls backend.SendTransactionWithChainID. func sendTransactionWithChainID(chainID int, txArgsJSON, password string) string { - var params transactions.SendTxArgs + var params wallettypes.SendTxArgs err := json.Unmarshal([]byte(txArgsJSON), ¶ms) if err != nil { return prepareJSONResponseWithCode(nil, err, codeFailedParseParams) @@ -869,7 +869,7 @@ func SendTransaction(txArgsJSON, password string) string { // sendTransaction converts RPC args and calls backend.SendTransaction. // Deprecated: Use sendTransactionV2 instead. func sendTransaction(txArgsJSON, password string) string { - var params transactions.SendTxArgs + var params wallettypes.SendTxArgs err := json.Unmarshal([]byte(txArgsJSON), ¶ms) if err != nil { return prepareJSONResponseWithCode(nil, err, codeFailedParseParams) @@ -911,7 +911,7 @@ func SendTransactionWithSignature(txArgsJSON, sigString string) string { // sendTransactionWithSignature converts RPC args and calls backend.SendTransactionWithSignature func sendTransactionWithSignature(txArgsJSON, sigString string) string { - var params transactions.SendTxArgs + var params wallettypes.SendTxArgs err := json.Unmarshal([]byte(txArgsJSON), ¶ms) if err != nil { return prepareJSONResponseWithCode(nil, err, codeFailedParseParams) @@ -936,7 +936,7 @@ func HashTransaction(txArgsJSON string) string { // hashTransaction validate the transaction and returns new txArgs and the transaction hash. func hashTransaction(txArgsJSON string) string { - var params transactions.SendTxArgs + var params wallettypes.SendTxArgs err := json.Unmarshal([]byte(txArgsJSON), ¶ms) if err != nil { return prepareJSONResponseWithCode(nil, err, codeFailedParseParams) @@ -949,8 +949,8 @@ func hashTransaction(txArgsJSON string) string { } result := struct { - Transaction transactions.SendTxArgs `json:"transaction"` - Hash types.Hash `json:"hash"` + Transaction wallettypes.SendTxArgs `json:"transaction"` + Hash types.Hash `json:"hash"` }{ Transaction: newTxArgs, Hash: hash, diff --git a/protocol/communities/manager.go b/protocol/communities/manager.go index 56b179f0a..be5a5b659 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -43,8 +43,8 @@ import ( walletcommon "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/services/wallet/thirdparty" "github.com/status-im/status-go/services/wallet/token" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/signal" - "github.com/status-im/status-go/transactions" ) type Publisher interface { @@ -266,7 +266,7 @@ type AssetContractData struct { type CommunityTokensServiceInterface interface { GetCollectibleContractData(chainID uint64, contractAddress string) (*CollectibleContractData, error) - SetSignerPubKey(ctx context.Context, chainID uint64, contractAddress string, txArgs transactions.SendTxArgs, password string, newSignerPubKey string) (string, error) + SetSignerPubKey(ctx context.Context, chainID uint64, contractAddress string, txArgs wallettypes.SendTxArgs, password string, newSignerPubKey string) (string, error) GetAssetContractData(chainID uint64, contractAddress string) (*AssetContractData, error) SafeGetSignerPubKey(ctx context.Context, chainID uint64, communityID string) (string, error) DeploymentSignatureDigest(chainID uint64, addressFrom string, communityID string) ([]byte, error) diff --git a/protocol/communities_messenger_helpers_test.go b/protocol/communities_messenger_helpers_test.go index ba1adf181..6fd49c382 100644 --- a/protocol/communities_messenger_helpers_test.go +++ b/protocol/communities_messenger_helpers_test.go @@ -30,7 +30,7 @@ import ( walletCommon "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/services/wallet/thirdparty" walletToken "github.com/status-im/status-go/services/wallet/token" - "github.com/status-im/status-go/transactions" + "github.com/status-im/status-go/services/wallet/wallettypes" ) type AccountManagerMock struct { @@ -201,7 +201,7 @@ func (c *CollectiblesServiceMock) SetSignerPubkeyForCommunity(communityID []byte c.Signers[types.EncodeHex(communityID)] = signerPubKey } -func (c *CollectiblesServiceMock) SetSignerPubKey(ctx context.Context, chainID uint64, contractAddress string, txArgs transactions.SendTxArgs, password string, newSignerPubKey string) (string, error) { +func (c *CollectiblesServiceMock) SetSignerPubKey(ctx context.Context, chainID uint64, contractAddress string, txArgs wallettypes.SendTxArgs, password string, newSignerPubKey string) (string, error) { return "", nil } diff --git a/protocol/requests/send_transaction.go b/protocol/requests/send_transaction.go index a28b3a166..f6b706b0f 100644 --- a/protocol/requests/send_transaction.go +++ b/protocol/requests/send_transaction.go @@ -3,13 +3,13 @@ package requests import ( "gopkg.in/go-playground/validator.v9" - "github.com/status-im/status-go/transactions" + "github.com/status-im/status-go/services/wallet/wallettypes" ) // SendTransaction represents a request to send a transaction. type SendTransaction struct { - TxArgs transactions.SendTxArgs `json:"txArgs"` - Password string `json:"password" validate:"required"` + TxArgs wallettypes.SendTxArgs `json:"txArgs"` + Password string `json:"password" validate:"required"` } // Validate checks the fields of SendTransaction to ensure they meet the requirements. diff --git a/services/communitytokens/api.go b/services/communitytokens/api.go index 1eb73adb1..7f6c3c6e0 100644 --- a/services/communitytokens/api.go +++ b/services/communitytokens/api.go @@ -25,6 +25,7 @@ import ( "github.com/status-im/status-go/services/utils" "github.com/status-im/status-go/services/wallet/bigint" wcommon "github.com/status-im/status-go/services/wallet/common" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/transactions" ) @@ -101,7 +102,7 @@ func (d *DeploymentParameters) Validate(isAsset bool) error { return nil } -func (api *API) DeployCollectibles(ctx context.Context, chainID uint64, deploymentParameters DeploymentParameters, txArgs transactions.SendTxArgs, password string) (DeploymentDetails, error) { +func (api *API) DeployCollectibles(ctx context.Context, chainID uint64, deploymentParameters DeploymentParameters, txArgs wallettypes.SendTxArgs, password string) (DeploymentDetails, error) { err := deploymentParameters.Validate(false) if err != nil { return DeploymentDetails{}, err @@ -180,7 +181,7 @@ func prepareDeploymentSignatureStruct(signature string, communityID string, addr func (api *API) DeployOwnerToken(ctx context.Context, chainID uint64, ownerTokenParameters DeploymentParameters, masterTokenParameters DeploymentParameters, - signerPubKey string, txArgs transactions.SendTxArgs, password string) (DeploymentDetails, error) { + signerPubKey string, txArgs wallettypes.SendTxArgs, password string) (DeploymentDetails, error) { err := ownerTokenParameters.Validate(false) if err != nil { return DeploymentDetails{}, err @@ -272,7 +273,7 @@ func (api *API) ReTrackOwnerTokenDeploymentTransaction(ctx context.Context, chai return api.s.ReTrackOwnerTokenDeploymentTransaction(ctx, chainID, contractAddress) } -func (api *API) DeployAssets(ctx context.Context, chainID uint64, deploymentParameters DeploymentParameters, txArgs transactions.SendTxArgs, password string) (DeploymentDetails, error) { +func (api *API) DeployAssets(ctx context.Context, chainID uint64, deploymentParameters DeploymentParameters, txArgs wallettypes.SendTxArgs, password string) (DeploymentDetails, error) { err := deploymentParameters.Validate(true) if err != nil { @@ -376,7 +377,7 @@ func (api *API) NewAssetsInstance(chainID uint64, contractAddress string) (*asse } // Universal minting function for every type of token. -func (api *API) MintTokens(ctx context.Context, chainID uint64, contractAddress string, txArgs transactions.SendTxArgs, password string, walletAddresses []string, amount *bigint.BigInt) (string, error) { +func (api *API) MintTokens(ctx context.Context, chainID uint64, contractAddress string, txArgs wallettypes.SendTxArgs, password string, walletAddresses []string, amount *bigint.BigInt) (string, error) { err := api.s.ValidateWalletsAndAmounts(walletAddresses, amount) if err != nil { @@ -439,7 +440,7 @@ func (api *API) RemoteDestructedAmount(ctx context.Context, chainID uint64, cont } // This is only ERC721 function -func (api *API) RemoteBurn(ctx context.Context, chainID uint64, contractAddress string, txArgs transactions.SendTxArgs, password string, tokenIds []*bigint.BigInt, additionalData string) (string, error) { +func (api *API) RemoteBurn(ctx context.Context, chainID uint64, contractAddress string, txArgs wallettypes.SendTxArgs, password string, tokenIds []*bigint.BigInt, additionalData string) (string, error) { err := api.s.validateTokens(tokenIds) if err != nil { return "", err @@ -491,7 +492,7 @@ func (api *API) RemainingSupply(ctx context.Context, chainID uint64, contractAdd return api.s.remainingSupply(ctx, chainID, contractAddress) } -func (api *API) Burn(ctx context.Context, chainID uint64, contractAddress string, txArgs transactions.SendTxArgs, password string, burnAmount *bigint.BigInt) (string, error) { +func (api *API) Burn(ctx context.Context, chainID uint64, contractAddress string, txArgs wallettypes.SendTxArgs, password string, burnAmount *bigint.BigInt) (string, error) { err := api.s.validateBurnAmount(ctx, burnAmount, chainID, contractAddress) if err != nil { return "", err @@ -546,7 +547,7 @@ func (api *API) SafeGetOwnerTokenAddress(ctx context.Context, chainID uint64, co return api.s.SafeGetOwnerTokenAddress(ctx, chainID, communityID) } -func (api *API) SetSignerPubKey(ctx context.Context, chainID uint64, contractAddress string, txArgs transactions.SendTxArgs, password string, newSignerPubKey string) (string, error) { +func (api *API) SetSignerPubKey(ctx context.Context, chainID uint64, contractAddress string, txArgs wallettypes.SendTxArgs, password string, newSignerPubKey string) (string, error) { return api.s.SetSignerPubKey(ctx, chainID, contractAddress, txArgs, password, newSignerPubKey) } diff --git a/services/communitytokens/estimations.go b/services/communitytokens/estimations.go index bb7fd0ef6..808d9acbd 100644 --- a/services/communitytokens/estimations.go +++ b/services/communitytokens/estimations.go @@ -21,7 +21,7 @@ import ( "github.com/status-im/status-go/protocol/protobuf" "github.com/status-im/status-go/services/wallet/bigint" "github.com/status-im/status-go/services/wallet/router/fees" - "github.com/status-im/status-go/transactions" + "github.com/status-im/status-go/services/wallet/wallettypes" ) type CommunityTokenFees struct { @@ -375,8 +375,8 @@ func (s *Service) prepareCommunityTokenFees(ctx context.Context, from common.Add }, nil } -func (s *Service) suggestedFeesToSendTxArgs(from common.Address, to *common.Address, gas uint64, suggestedFees *fees.SuggestedFeesGwei) transactions.SendTxArgs { - sendArgs := transactions.SendTxArgs{} +func (s *Service) suggestedFeesToSendTxArgs(from common.Address, to *common.Address, gas uint64, suggestedFees *fees.SuggestedFeesGwei) wallettypes.SendTxArgs { + sendArgs := wallettypes.SendTxArgs{} sendArgs.From = types.Address(from) sendArgs.To = (*types.Address)(to) sendArgs.Gas = (*hexutil.Uint64)(&gas) @@ -389,7 +389,7 @@ func (s *Service) suggestedFeesToSendTxArgs(from common.Address, to *common.Addr return sendArgs } -func (s *Service) estimateL1Fee(ctx context.Context, chainID uint64, sendArgs transactions.SendTxArgs) (uint64, error) { +func (s *Service) estimateL1Fee(ctx context.Context, chainID uint64, sendArgs wallettypes.SendTxArgs) (uint64, error) { transaction, _, err := s.transactor.ValidateAndBuildTransaction(chainID, sendArgs, -1) if err != nil { return 0, err diff --git a/services/communitytokens/service.go b/services/communitytokens/service.go index a1a8930d3..8b339e4ce 100644 --- a/services/communitytokens/service.go +++ b/services/communitytokens/service.go @@ -35,6 +35,7 @@ import ( wcommon "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/services/wallet/router/fees" "github.com/status-im/status-go/services/wallet/walletevent" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/signal" "github.com/status-im/status-go/transactions" ) @@ -501,7 +502,7 @@ func (s *Service) ProcessCommunityTokenAction(message *protobuf.CommunityTokenAc return nil } -func (s *Service) SetSignerPubKey(ctx context.Context, chainID uint64, contractAddress string, txArgs transactions.SendTxArgs, password string, newSignerPubKey string) (string, error) { +func (s *Service) SetSignerPubKey(ctx context.Context, chainID uint64, contractAddress string, txArgs wallettypes.SendTxArgs, password string, newSignerPubKey string) (string, error) { if len(newSignerPubKey) <= 0 { return "", fmt.Errorf("signerPubKey is empty") diff --git a/services/connector/commands/client_handler.go b/services/connector/commands/client_handler.go index a1334d5df..0b361a0c1 100644 --- a/services/connector/commands/client_handler.go +++ b/services/connector/commands/client_handler.go @@ -11,8 +11,8 @@ import ( "github.com/status-im/status-go/eth-node/types" persistence "github.com/status-im/status-go/services/connector/database" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/signal" - "github.com/status-im/status-go/transactions" ) var ( @@ -148,7 +148,7 @@ func (c *ClientSideHandler) RecallDAppPermissions(args RecallDAppPermissionsArgs return nil } -func (c *ClientSideHandler) RequestSendTransaction(dApp signal.ConnectorDApp, chainID uint64, txArgs *transactions.SendTxArgs) (types.Hash, error) { +func (c *ClientSideHandler) RequestSendTransaction(dApp signal.ConnectorDApp, chainID uint64, txArgs *wallettypes.SendTxArgs) (types.Hash, error) { if !c.setRequestRunning() { return types.Hash{}, ErrAnotherConnectorOperationIsAwaitingFor } diff --git a/services/connector/commands/rpc_traits.go b/services/connector/commands/rpc_traits.go index 0a680021f..4ef262923 100644 --- a/services/connector/commands/rpc_traits.go +++ b/services/connector/commands/rpc_traits.go @@ -8,8 +8,8 @@ import ( "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/params" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/signal" - "github.com/status-im/status-go/transactions" ) const ( @@ -75,7 +75,7 @@ type ClientSideHandlerInterface interface { RequestAccountsRejected(args RejectedArgs) error RecallDAppPermissions(args RecallDAppPermissionsArgs) error - RequestSendTransaction(dApp signal.ConnectorDApp, chainID uint64, txArgs *transactions.SendTxArgs) (types.Hash, error) + RequestSendTransaction(dApp signal.ConnectorDApp, chainID uint64, txArgs *wallettypes.SendTxArgs) (types.Hash, error) SendTransactionAccepted(args SendTransactionAcceptedArgs) error SendTransactionRejected(args RejectedArgs) error diff --git a/services/connector/commands/send_transaction.go b/services/connector/commands/send_transaction.go index 332da2a8a..a04692d87 100644 --- a/services/connector/commands/send_transaction.go +++ b/services/connector/commands/send_transaction.go @@ -13,8 +13,8 @@ import ( "github.com/status-im/status-go/rpc" persistence "github.com/status-im/status-go/services/connector/database" "github.com/status-im/status-go/services/wallet/router/fees" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/signal" - "github.com/status-im/status-go/transactions" ) var ( @@ -29,7 +29,7 @@ type SendTransactionCommand struct { ClientHandler ClientSideHandlerInterface } -func (r *RPCRequest) getSendTransactionParams() (*transactions.SendTxArgs, error) { +func (r *RPCRequest) getSendTransactionParams() (*wallettypes.SendTxArgs, error) { if r.Params == nil || len(r.Params) == 0 { return nil, ErrEmptyRPCParams } @@ -44,7 +44,7 @@ func (r *RPCRequest) getSendTransactionParams() (*transactions.SendTxArgs, error return nil, fmt.Errorf("error marshalling first transaction param: %v", err) } - var sendTxArgs transactions.SendTxArgs + var sendTxArgs wallettypes.SendTxArgs err = json.Unmarshal(paramBytes, &sendTxArgs) if err != nil { return nil, fmt.Errorf("error unmarshalling first transaction param to SendTxArgs: %v", err) diff --git a/services/connector/commands/send_transaction_test.go b/services/connector/commands/send_transaction_test.go index 356448884..14da43d09 100644 --- a/services/connector/commands/send_transaction_test.go +++ b/services/connector/commands/send_transaction_test.go @@ -13,12 +13,12 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/status-im/status-go/eth-node/types" mock_client "github.com/status-im/status-go/rpc/chain/mock/client" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/signal" - "github.com/status-im/status-go/transactions" ) func prepareSendTransactionRequest(dApp signal.ConnectorDApp, from types.Address) (RPCRequest, error) { - sendArgs := transactions.SendTxArgs{ + sendArgs := wallettypes.SendTxArgs{ From: from, To: &types.Address{0x02}, Value: &hexutil.Big{}, diff --git a/services/ens/api.go b/services/ens/api.go index 864bff819..52f67bc11 100644 --- a/services/ens/api.go +++ b/services/ens/api.go @@ -32,6 +32,7 @@ import ( "github.com/status-im/status-go/services/ens/ensresolver" "github.com/status-im/status-go/services/utils" wcommon "github.com/status-im/status-go/services/wallet/common" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/transactions" ) @@ -147,7 +148,7 @@ func (api *API) Price(ctx context.Context, chainID uint64) (string, error) { // Deprecated: `Release` was used before introducing a new, uniform, sending flow that uses router. // Releasing ens username should start from calling `wallet_getSuggestedRoutesAsync` // TODO: remove once mobile switches to a new sending flow. -func (api *API) Release(ctx context.Context, chainID uint64, txArgs transactions.SendTxArgs, password string, username string) (string, error) { +func (api *API) Release(ctx context.Context, chainID uint64, txArgs wallettypes.SendTxArgs, password string, username string) (string, error) { registryAddr, err := api.ensResolver.GetRegistrarAddress(ctx, chainID) if err != nil { return "", err @@ -185,7 +186,7 @@ func (api *API) Release(ctx context.Context, chainID uint64, txArgs transactions // Deprecated: `ReleasePrepareTxCallMsg` was used before introducing a new, uniform, sending flow that uses router. // Releasing ens username should start from calling `wallet_getSuggestedRoutesAsync` // TODO: remove once mobile switches to a new sending flow. -func (api *API) ReleasePrepareTxCallMsg(ctx context.Context, chainID uint64, txArgs transactions.SendTxArgs, username string) (ethereum.CallMsg, error) { +func (api *API) ReleasePrepareTxCallMsg(ctx context.Context, chainID uint64, txArgs wallettypes.SendTxArgs, username string) (ethereum.CallMsg, error) { registrarABI, err := abi.JSON(strings.NewReader(registrar.UsernameRegistrarABI)) if err != nil { return ethereum.CallMsg{}, err @@ -208,10 +209,7 @@ func (api *API) ReleasePrepareTxCallMsg(ctx context.Context, chainID uint64, txA }, nil } -// Deprecated: `ReleasePrepareTx` was used before introducing a new, uniform, sending flow that uses router. -// Releasing ens username should start from calling `wallet_getSuggestedRoutesAsync` -// TODO: remove once mobile switches to a new sending flow. -func (api *API) ReleasePrepareTx(ctx context.Context, chainID uint64, txArgs transactions.SendTxArgs, username string) (interface{}, error) { +func (api *API) ReleasePrepareTx(ctx context.Context, chainID uint64, txArgs wallettypes.SendTxArgs, username string) (interface{}, error) { callMsg, err := api.ReleasePrepareTxCallMsg(ctx, chainID, txArgs, username) if err != nil { return nil, err @@ -223,7 +221,7 @@ func (api *API) ReleasePrepareTx(ctx context.Context, chainID uint64, txArgs tra // Deprecated: `ReleaseEstimate` was used before introducing a new, uniform, sending flow that uses router. // Releasing ens username should start from calling `wallet_getSuggestedRoutesAsync` // TODO: remove once mobile switches to a new sending flow. -func (api *API) ReleaseEstimate(ctx context.Context, chainID uint64, txArgs transactions.SendTxArgs, username string) (uint64, error) { +func (api *API) ReleaseEstimate(ctx context.Context, chainID uint64, txArgs wallettypes.SendTxArgs, username string) (uint64, error) { callMsg, err := api.ReleasePrepareTxCallMsg(ctx, chainID, txArgs, username) if err != nil { return 0, err @@ -235,7 +233,7 @@ func (api *API) ReleaseEstimate(ctx context.Context, chainID uint64, txArgs tran // Deprecated: `Register` was used before introducing a new, uniform, sending flow that uses router. // Releasing ens username should start from calling `wallet_getSuggestedRoutesAsync` // TODO: remove once mobile switches to a new sending flow. -func (api *API) Register(ctx context.Context, chainID uint64, txArgs transactions.SendTxArgs, password string, username string, pubkey string) (string, error) { +func (api *API) Register(ctx context.Context, chainID uint64, txArgs wallettypes.SendTxArgs, password string, username string, pubkey string) (string, error) { registryAddr, err := api.ensResolver.GetRegistrarAddress(ctx, chainID) if err != nil { return "", err @@ -273,7 +271,7 @@ func (api *API) Register(ctx context.Context, chainID uint64, txArgs transaction // Deprecated: `RegisterPrepareTxCallMsg` was used before introducing a new, uniform, sending flow that uses router. // Releasing ens username should start from calling `wallet_getSuggestedRoutesAsync` // TODO: remove once mobile switches to a new sending flow. -func (api *API) RegisterPrepareTxCallMsg(ctx context.Context, chainID uint64, txArgs transactions.SendTxArgs, username string, pubkey string) (ethereum.CallMsg, error) { +func (api *API) RegisterPrepareTxCallMsg(ctx context.Context, chainID uint64, txArgs wallettypes.SendTxArgs, username string, pubkey string) (ethereum.CallMsg, error) { priceHex, err := api.Price(ctx, chainID) if err != nil { return ethereum.CallMsg{}, err @@ -322,7 +320,7 @@ func (api *API) RegisterPrepareTxCallMsg(ctx context.Context, chainID uint64, tx // Deprecated: `RegisterPrepareTx` was used before introducing a new, uniform, sending flow that uses router. // Releasing ens username should start from calling `wallet_getSuggestedRoutesAsync` // TODO: remove once mobile switches to a new sending flow. -func (api *API) RegisterPrepareTx(ctx context.Context, chainID uint64, txArgs transactions.SendTxArgs, username string, pubkey string) (interface{}, error) { +func (api *API) RegisterPrepareTx(ctx context.Context, chainID uint64, txArgs wallettypes.SendTxArgs, username string, pubkey string) (interface{}, error) { callMsg, err := api.RegisterPrepareTxCallMsg(ctx, chainID, txArgs, username, pubkey) if err != nil { return nil, err @@ -334,7 +332,7 @@ func (api *API) RegisterPrepareTx(ctx context.Context, chainID uint64, txArgs tr // Deprecated: `RegisterEstimate` was used before introducing a new, uniform, sending flow that uses router. // Releasing ens username should start from calling `wallet_getSuggestedRoutesAsync` // TODO: remove once mobile switches to a new sending flow. -func (api *API) RegisterEstimate(ctx context.Context, chainID uint64, txArgs transactions.SendTxArgs, username string, pubkey string) (uint64, error) { +func (api *API) RegisterEstimate(ctx context.Context, chainID uint64, txArgs wallettypes.SendTxArgs, username string, pubkey string) (uint64, error) { callMsg, err := api.RegisterPrepareTxCallMsg(ctx, chainID, txArgs, username, pubkey) if err != nil { return 0, err @@ -346,7 +344,7 @@ func (api *API) RegisterEstimate(ctx context.Context, chainID uint64, txArgs tra // Deprecated: `SetPubKey` was used before introducing a new, uniform, sending flow that uses router. // Releasing ens username should start from calling `wallet_getSuggestedRoutesAsync` // TODO: remove once mobile switches to a new sending flow. -func (api *API) SetPubKey(ctx context.Context, chainID uint64, txArgs transactions.SendTxArgs, password string, username string, pubkey string) (string, error) { +func (api *API) SetPubKey(ctx context.Context, chainID uint64, txArgs wallettypes.SendTxArgs, password string, username string, pubkey string) (string, error) { resolverAddress, err := api.Resolver(ctx, chainID, username) if err != nil { return "", err @@ -384,7 +382,7 @@ func (api *API) SetPubKey(ctx context.Context, chainID uint64, txArgs transactio // Deprecated: `SetPubKeyPrepareTxCallMsg` was used before introducing a new, uniform, sending flow that uses router. // Releasing ens username should start from calling `wallet_getSuggestedRoutesAsync` // TODO: remove once mobile switches to a new sending flow. -func (api *API) SetPubKeyPrepareTxCallMsg(ctx context.Context, chainID uint64, txArgs transactions.SendTxArgs, username string, pubkey string) (ethereum.CallMsg, error) { +func (api *API) SetPubKeyPrepareTxCallMsg(ctx context.Context, chainID uint64, txArgs wallettypes.SendTxArgs, username string, pubkey string) (ethereum.CallMsg, error) { err := wcommon.ValidateENSUsername(username) if err != nil { return ethereum.CallMsg{}, err @@ -417,7 +415,7 @@ func (api *API) SetPubKeyPrepareTxCallMsg(ctx context.Context, chainID uint64, t // Deprecated: `SetPubKeyPrepareTx` was used before introducing a new, uniform, sending flow that uses router. // Releasing ens username should start from calling `wallet_getSuggestedRoutesAsync` // TODO: remove once mobile switches to a new sending flow. -func (api *API) SetPubKeyPrepareTx(ctx context.Context, chainID uint64, txArgs transactions.SendTxArgs, username string, pubkey string) (interface{}, error) { +func (api *API) SetPubKeyPrepareTx(ctx context.Context, chainID uint64, txArgs wallettypes.SendTxArgs, username string, pubkey string) (interface{}, error) { callMsg, err := api.SetPubKeyPrepareTxCallMsg(ctx, chainID, txArgs, username, pubkey) if err != nil { return nil, err @@ -429,7 +427,7 @@ func (api *API) SetPubKeyPrepareTx(ctx context.Context, chainID uint64, txArgs t // Deprecated: `SetPubKeyEstimate` was used before introducing a new, uniform, sending flow that uses router. // Releasing ens username should start from calling `wallet_getSuggestedRoutesAsync` // TODO: remove once mobile switches to a new sending flow. -func (api *API) SetPubKeyEstimate(ctx context.Context, chainID uint64, txArgs transactions.SendTxArgs, username string, pubkey string) (uint64, error) { +func (api *API) SetPubKeyEstimate(ctx context.Context, chainID uint64, txArgs wallettypes.SendTxArgs, username string, pubkey string) (uint64, error) { callMsg, err := api.SetPubKeyPrepareTxCallMsg(ctx, chainID, txArgs, username, pubkey) if err != nil { return 0, err diff --git a/services/ens/ensresolver/resolver.go b/services/ens/ensresolver/resolver.go index cdd4069bb..ff0a64284 100644 --- a/services/ens/ensresolver/resolver.go +++ b/services/ens/ensresolver/resolver.go @@ -22,7 +22,7 @@ import ( "github.com/status-im/status-go/logutils" "github.com/status-im/status-go/rpc" walletCommon "github.com/status-im/status-go/services/wallet/common" - "github.com/status-im/status-go/transactions" + "github.com/status-im/status-go/services/wallet/wallettypes" ) func NewEnsResolver(rpcClient *rpc.Client) *EnsResolver { @@ -270,7 +270,7 @@ func (e *EnsResolver) Price(ctx context.Context, chainID uint64) (string, error) return fmt.Sprintf("%x", price), nil } -func (e *EnsResolver) Release(ctx context.Context, chainID uint64, registryAddress common.Address, txArgs transactions.SendTxArgs, username string, signFn bind.SignerFn) (*types.Transaction, error) { +func (e *EnsResolver) Release(ctx context.Context, chainID uint64, registryAddress common.Address, txArgs wallettypes.SendTxArgs, username string, signFn bind.SignerFn) (*types.Transaction, error) { registrar, err := e.contractMaker.NewUsernameRegistrar(chainID, registryAddress) if err != nil { return nil, err @@ -293,7 +293,7 @@ func (e *EnsResolver) ReleaseEstimate(ctx context.Context, chainID uint64, callM return estimate + 1000, nil } -func (e *EnsResolver) Register(ctx context.Context, chainID uint64, registryAddress common.Address, txArgs transactions.SendTxArgs, username string, pubkey string, signFn bind.SignerFn) (*types.Transaction, error) { +func (e *EnsResolver) Register(ctx context.Context, chainID uint64, registryAddress common.Address, txArgs wallettypes.SendTxArgs, username string, pubkey string, signFn bind.SignerFn) (*types.Transaction, error) { snt, err := e.contractMaker.NewSNT(chainID) if err != nil { return nil, err @@ -339,7 +339,7 @@ func (e *EnsResolver) RegisterEstimate(ctx context.Context, chainID uint64, call return estimate + 1000, nil } -func (e *EnsResolver) SetPubKey(ctx context.Context, chainID uint64, resolverAddress *common.Address, txArgs transactions.SendTxArgs, username string, pubkey string, signFn bind.SignerFn) (*types.Transaction, error) { +func (e *EnsResolver) SetPubKey(ctx context.Context, chainID uint64, resolverAddress *common.Address, txArgs wallettypes.SendTxArgs, username string, pubkey string, signFn bind.SignerFn) (*types.Transaction, error) { err := walletCommon.ValidateENSUsername(username) if err != nil { return nil, err diff --git a/services/wallet/api.go b/services/wallet/api.go index 6e7abfb07..45d29ccc3 100644 --- a/services/wallet/api.go +++ b/services/wallet/api.go @@ -39,6 +39,7 @@ import ( "github.com/status-im/status-go/services/wallet/token" "github.com/status-im/status-go/services/wallet/transfer" "github.com/status-im/status-go/services/wallet/walletconnect" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/transactions" ) @@ -660,7 +661,7 @@ func (api *API) SignMessage(ctx context.Context, message types.HexBytes, address func (api *API) BuildTransaction(ctx context.Context, chainID uint64, sendTxArgsJSON string) (response *transfer.TxResponse, err error) { logutils.ZapLogger().Debug("[WalletAPI::BuildTransaction]", zap.Uint64("chainID", chainID), zap.String("sendTxArgsJSON", sendTxArgsJSON)) - var params transactions.SendTxArgs + var params wallettypes.SendTxArgs err = json.Unmarshal([]byte(sendTxArgsJSON), ¶ms) if err != nil { return nil, err @@ -676,7 +677,7 @@ func (api *API) BuildRawTransaction(ctx context.Context, chainID uint64, sendTxA return nil, err } - var params transactions.SendTxArgs + var params wallettypes.SendTxArgs err = json.Unmarshal([]byte(sendTxArgsJSON), ¶ms) if err != nil { return nil, err @@ -698,7 +699,7 @@ func (api *API) SendTransactionWithSignature(ctx context.Context, chainID uint64 return hash, err } - var params transactions.SendTxArgs + var params wallettypes.SendTxArgs err = json.Unmarshal([]byte(sendTxArgsJSON), ¶ms) if err != nil { return hash, err @@ -912,8 +913,8 @@ func (api *API) getVerifiedWalletAccount(address, password string) (*account.Sel } if !exists { - logutils.ZapLogger().Error("failed to get a selected account", zap.Error(transactions.ErrInvalidTxSender)) - return nil, transactions.ErrAccountDoesntExist + logutils.ZapLogger().Error("failed to get a selected account", zap.Error(wallettypes.ErrInvalidTxSender)) + return nil, wallettypes.ErrAccountDoesntExist } keyStoreDir := api.s.Config().KeyStoreDir diff --git a/services/wallet/responses/router_transactions.go b/services/wallet/responses/router_transactions.go index bbc87b194..03a315915 100644 --- a/services/wallet/responses/router_transactions.go +++ b/services/wallet/responses/router_transactions.go @@ -3,7 +3,7 @@ package responses import ( "github.com/status-im/status-go/errors" "github.com/status-im/status-go/eth-node/types" - "github.com/status-im/status-go/transactions" + "github.com/status-im/status-go/services/wallet/wallettypes" ) type SendDetails struct { @@ -54,7 +54,7 @@ type RouterSentTransactions struct { SentTransactions []*RouterSentTransaction `json:"sentTransactions"` } -func NewRouterSentTransaction(sendArgs *transactions.SendTxArgs, hash types.Hash, approvalTx bool) *RouterSentTransaction { +func NewRouterSentTransaction(sendArgs *wallettypes.SendTxArgs, hash types.Hash, approvalTx bool) *RouterSentTransaction { addr := types.Address{} if sendArgs.To != nil { addr = *sendArgs.To diff --git a/services/wallet/router/pathprocessor/multipath_processor.go b/services/wallet/router/pathprocessor/multipath_processor.go index a80f8d91c..09557a375 100644 --- a/services/wallet/router/pathprocessor/multipath_processor.go +++ b/services/wallet/router/pathprocessor/multipath_processor.go @@ -5,13 +5,13 @@ import ( "github.com/status-im/status-go/eth-node/types" walletCommon "github.com/status-im/status-go/services/wallet/common" - "github.com/status-im/status-go/transactions" + "github.com/status-im/status-go/services/wallet/wallettypes" ) type MultipathProcessorTxArgs struct { Name string `json:"bridgeName"` ChainID uint64 - TransferTx *transactions.SendTxArgs + TransferTx *wallettypes.SendTxArgs HopTx *HopBridgeTxArgs CbridgeTx *CelerBridgeTxArgs ERC721TransferTx *ERC721TxArgs diff --git a/services/wallet/router/pathprocessor/processor.go b/services/wallet/router/pathprocessor/processor.go index 4f188019f..084064c18 100644 --- a/services/wallet/router/pathprocessor/processor.go +++ b/services/wallet/router/pathprocessor/processor.go @@ -13,7 +13,7 @@ import ( "github.com/status-im/status-go/params" "github.com/status-im/status-go/services/wallet/requests" "github.com/status-im/status-go/services/wallet/token" - "github.com/status-im/status-go/transactions" + "github.com/status-im/status-go/services/wallet/wallettypes" ) type PathProcessor interface { @@ -36,7 +36,7 @@ type PathProcessor interface { // BuildTransaction builds the transaction based on MultipathProcessorTxArgs, returns the transaction and the used nonce (lastUsedNonce is -1 if it's the first tx) BuildTransaction(sendArgs *MultipathProcessorTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) // BuildTransactionV2 builds the transaction based on SendTxArgs, returns the transaction and the used nonce (lastUsedNonce is -1 if it's the first tx) - BuildTransactionV2(sendArgs *transactions.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) + BuildTransactionV2(sendArgs *wallettypes.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) } type PathProcessorClearable interface { diff --git a/services/wallet/router/pathprocessor/processor_bridge_celar.go b/services/wallet/router/pathprocessor/processor_bridge_celar.go index df835e5d0..cf1871710 100644 --- a/services/wallet/router/pathprocessor/processor_bridge_celar.go +++ b/services/wallet/router/pathprocessor/processor_bridge_celar.go @@ -27,6 +27,7 @@ import ( "github.com/status-im/status-go/services/wallet/router/pathprocessor/cbridge" "github.com/status-im/status-go/services/wallet/thirdparty" "github.com/status-im/status-go/services/wallet/token" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/transactions" ) @@ -38,7 +39,7 @@ const ( ) type CelerBridgeTxArgs struct { - transactions.SendTxArgs + wallettypes.SendTxArgs ChainID uint64 `json:"chainId"` Symbol string `json:"symbol"` Recipient common.Address `json:"recipient"` @@ -365,7 +366,7 @@ func (s *CelerBridgeProcessor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, s return tx, nil } -func (s *CelerBridgeProcessor) sendOrBuildV2(sendArgs *transactions.SendTxArgs, signerFn bind.SignerFn, lastUsedNonce int64) (*ethTypes.Transaction, error) { +func (s *CelerBridgeProcessor) sendOrBuildV2(sendArgs *wallettypes.SendTxArgs, signerFn bind.SignerFn, lastUsedNonce int64) (*ethTypes.Transaction, error) { fromChain := s.rpcClient.NetworkManager.Find(sendArgs.FromChainID) if fromChain == nil { return nil, ErrNetworkNotFound @@ -441,7 +442,7 @@ func (s *CelerBridgeProcessor) BuildTransaction(sendArgs *MultipathProcessorTxAr return tx, tx.Nonce(), err } -func (s *CelerBridgeProcessor) BuildTransactionV2(sendArgs *transactions.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { +func (s *CelerBridgeProcessor) BuildTransactionV2(sendArgs *wallettypes.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { tx, err := s.sendOrBuildV2(sendArgs, nil, lastUsedNonce) if err != nil { return nil, 0, createBridgeCellerErrorResponse(err) diff --git a/services/wallet/router/pathprocessor/processor_bridge_hop.go b/services/wallet/router/pathprocessor/processor_bridge_hop.go index 328261cc4..e86d39117 100644 --- a/services/wallet/router/pathprocessor/processor_bridge_hop.go +++ b/services/wallet/router/pathprocessor/processor_bridge_hop.go @@ -35,11 +35,12 @@ import ( walletCommon "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/services/wallet/thirdparty" "github.com/status-im/status-go/services/wallet/token" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/transactions" ) type HopBridgeTxArgs struct { - transactions.SendTxArgs + wallettypes.SendTxArgs ChainID uint64 `json:"chainId"` ChainIDTo uint64 `json:"chainIdTo"` Symbol string `json:"symbol"` @@ -350,7 +351,7 @@ func (h *HopBridgeProcessor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, sig return tx, nil } -func (h *HopBridgeProcessor) sendOrBuildV2(sendArgs *transactions.SendTxArgs, signerFn bind.SignerFn, lastUsedNonce int64) (tx *ethTypes.Transaction, err error) { +func (h *HopBridgeProcessor) sendOrBuildV2(sendArgs *wallettypes.SendTxArgs, signerFn bind.SignerFn, lastUsedNonce int64) (tx *ethTypes.Transaction, err error) { fromChain := h.networkManager.Find(sendArgs.FromChainID) if fromChain == nil { return tx, fmt.Errorf("ChainID not supported %d", sendArgs.FromChainID) @@ -433,7 +434,7 @@ func (h *HopBridgeProcessor) BuildTransaction(sendArgs *MultipathProcessorTxArgs return tx, tx.Nonce(), createBridgeHopErrorResponse(err) } -func (h *HopBridgeProcessor) BuildTransactionV2(sendArgs *transactions.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { +func (h *HopBridgeProcessor) BuildTransactionV2(sendArgs *wallettypes.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { tx, err := h.sendOrBuildV2(sendArgs, nil, lastUsedNonce) if err != nil { return nil, 0, createBridgeHopErrorResponse(err) diff --git a/services/wallet/router/pathprocessor/processor_ens_public_key.go b/services/wallet/router/pathprocessor/processor_ens_public_key.go index 4017cde91..f513b230f 100644 --- a/services/wallet/router/pathprocessor/processor_ens_public_key.go +++ b/services/wallet/router/pathprocessor/processor_ens_public_key.go @@ -16,6 +16,7 @@ import ( "github.com/status-im/status-go/rpc" "github.com/status-im/status-go/services/ens/ensresolver" walletCommon "github.com/status-im/status-go/services/wallet/common" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/transactions" ) @@ -111,7 +112,7 @@ func (s *ENSPublicKeyProcessor) BuildTransaction(sendArgs *MultipathProcessorTxA return s.transactor.ValidateAndBuildTransaction(sendArgs.ChainID, *sendArgs.TransferTx, lastUsedNonce) } -func (s *ENSPublicKeyProcessor) BuildTransactionV2(sendArgs *transactions.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { +func (s *ENSPublicKeyProcessor) BuildTransactionV2(sendArgs *wallettypes.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { return s.transactor.ValidateAndBuildTransaction(sendArgs.FromChainID, *sendArgs, lastUsedNonce) } diff --git a/services/wallet/router/pathprocessor/processor_ens_register.go b/services/wallet/router/pathprocessor/processor_ens_register.go index 5df64a17c..9a2b8ae34 100644 --- a/services/wallet/router/pathprocessor/processor_ens_register.go +++ b/services/wallet/router/pathprocessor/processor_ens_register.go @@ -18,6 +18,7 @@ import ( "github.com/status-im/status-go/rpc" "github.com/status-im/status-go/services/ens/ensresolver" walletCommon "github.com/status-im/status-go/services/wallet/common" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/transactions" ) @@ -147,7 +148,7 @@ func (s *ENSRegisterProcessor) BuildTransaction(sendArgs *MultipathProcessorTxAr return s.transactor.ValidateAndBuildTransaction(sendArgs.ChainID, *sendArgs.TransferTx, lastUsedNonce) } -func (s *ENSRegisterProcessor) BuildTransactionV2(sendArgs *transactions.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { +func (s *ENSRegisterProcessor) BuildTransactionV2(sendArgs *wallettypes.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { return s.transactor.ValidateAndBuildTransaction(sendArgs.FromChainID, *sendArgs, lastUsedNonce) } diff --git a/services/wallet/router/pathprocessor/processor_ens_release.go b/services/wallet/router/pathprocessor/processor_ens_release.go index 51731459d..88bdc2603 100644 --- a/services/wallet/router/pathprocessor/processor_ens_release.go +++ b/services/wallet/router/pathprocessor/processor_ens_release.go @@ -16,6 +16,7 @@ import ( "github.com/status-im/status-go/rpc" "github.com/status-im/status-go/services/ens/ensresolver" walletCommon "github.com/status-im/status-go/services/wallet/common" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/transactions" ) @@ -111,7 +112,7 @@ func (s *ENSReleaseProcessor) BuildTransaction(sendArgs *MultipathProcessorTxArg return s.transactor.ValidateAndBuildTransaction(sendArgs.ChainID, *sendArgs.TransferTx, lastUsedNonce) } -func (s *ENSReleaseProcessor) BuildTransactionV2(sendArgs *transactions.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { +func (s *ENSReleaseProcessor) BuildTransactionV2(sendArgs *wallettypes.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { return s.transactor.ValidateAndBuildTransaction(sendArgs.FromChainID, *sendArgs, lastUsedNonce) } diff --git a/services/wallet/router/pathprocessor/processor_erc1155.go b/services/wallet/router/pathprocessor/processor_erc1155.go index 91014d7cd..912b1f3b4 100644 --- a/services/wallet/router/pathprocessor/processor_erc1155.go +++ b/services/wallet/router/pathprocessor/processor_erc1155.go @@ -16,11 +16,12 @@ import ( "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/rpc" walletCommon "github.com/status-im/status-go/services/wallet/common" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/transactions" ) type ERC1155TxArgs struct { - transactions.SendTxArgs + wallettypes.SendTxArgs TokenID *hexutil.Big `json:"tokenId"` Recipient common.Address `json:"recipient"` Amount *hexutil.Big `json:"amount"` @@ -164,7 +165,7 @@ func (s *ERC1155Processor) BuildTransaction(sendArgs *MultipathProcessorTxArgs, return tx, tx.Nonce(), err } -func (s *ERC1155Processor) BuildTransactionV2(sendArgs *transactions.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { +func (s *ERC1155Processor) BuildTransactionV2(sendArgs *wallettypes.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { return s.transactor.ValidateAndBuildTransaction(sendArgs.FromChainID, *sendArgs, lastUsedNonce) } diff --git a/services/wallet/router/pathprocessor/processor_erc721.go b/services/wallet/router/pathprocessor/processor_erc721.go index eb9585963..2cc9c8114 100644 --- a/services/wallet/router/pathprocessor/processor_erc721.go +++ b/services/wallet/router/pathprocessor/processor_erc721.go @@ -19,6 +19,7 @@ import ( "github.com/status-im/status-go/rpc" walletCommon "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/services/wallet/token" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/transactions" ) @@ -28,7 +29,7 @@ const ( ) type ERC721TxArgs struct { - transactions.SendTxArgs + wallettypes.SendTxArgs TokenID *hexutil.Big `json:"tokenId"` Recipient common.Address `json:"recipient"` } @@ -222,7 +223,7 @@ func (s *ERC721Processor) BuildTransaction(sendArgs *MultipathProcessorTxArgs, l return tx, tx.Nonce(), err } -func (s *ERC721Processor) BuildTransactionV2(sendArgs *transactions.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { +func (s *ERC721Processor) BuildTransactionV2(sendArgs *wallettypes.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { return s.transactor.ValidateAndBuildTransaction(sendArgs.FromChainID, *sendArgs, lastUsedNonce) } diff --git a/services/wallet/router/pathprocessor/processor_stickers_buy.go b/services/wallet/router/pathprocessor/processor_stickers_buy.go index 1b1d93ad5..ed222a3bc 100644 --- a/services/wallet/router/pathprocessor/processor_stickers_buy.go +++ b/services/wallet/router/pathprocessor/processor_stickers_buy.go @@ -17,6 +17,7 @@ import ( "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/rpc" walletCommon "github.com/status-im/status-go/services/wallet/common" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/transactions" ) @@ -136,7 +137,7 @@ func (s *StickersBuyProcessor) BuildTransaction(sendArgs *MultipathProcessorTxAr return s.transactor.ValidateAndBuildTransaction(sendArgs.ChainID, *sendArgs.TransferTx, lastUsedNonce) } -func (s *StickersBuyProcessor) BuildTransactionV2(sendArgs *transactions.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { +func (s *StickersBuyProcessor) BuildTransactionV2(sendArgs *wallettypes.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { return s.transactor.ValidateAndBuildTransaction(sendArgs.FromChainID, *sendArgs, lastUsedNonce) } diff --git a/services/wallet/router/pathprocessor/processor_swap_paraswap.go b/services/wallet/router/pathprocessor/processor_swap_paraswap.go index b0f6234d4..691a9fc8f 100644 --- a/services/wallet/router/pathprocessor/processor_swap_paraswap.go +++ b/services/wallet/router/pathprocessor/processor_swap_paraswap.go @@ -15,11 +15,12 @@ import ( walletCommon "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/services/wallet/thirdparty/paraswap" walletToken "github.com/status-im/status-go/services/wallet/token" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/transactions" ) type SwapParaswapTxArgs struct { - transactions.SendTxArgs + wallettypes.SendTxArgs ChainID uint64 `json:"chainId"` ChainIDTo uint64 `json:"chainIdTo"` TokenIDFrom string `json:"tokenIdFrom"` @@ -255,7 +256,7 @@ func (s *SwapParaswapProcessor) prepareTransaction(sendArgs *MultipathProcessorT return nil } -func (s *SwapParaswapProcessor) prepareTransactionV2(sendArgs *transactions.SendTxArgs) error { +func (s *SwapParaswapProcessor) prepareTransactionV2(sendArgs *wallettypes.SendTxArgs) error { slippageBP := uint(sendArgs.SlippagePercentage * 100) // convert to basis points key := makeKey(sendArgs.FromChainID, sendArgs.ToChainID, sendArgs.FromTokenID, sendArgs.ToTokenID, sendArgs.ValueIn.ToInt()) @@ -308,7 +309,7 @@ func (s *SwapParaswapProcessor) BuildTransaction(sendArgs *MultipathProcessorTxA return s.transactor.ValidateAndBuildTransaction(sendArgs.ChainID, sendArgs.SwapTx.SendTxArgs, lastUsedNonce) } -func (s *SwapParaswapProcessor) BuildTransactionV2(sendArgs *transactions.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { +func (s *SwapParaswapProcessor) BuildTransactionV2(sendArgs *wallettypes.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { err := s.prepareTransactionV2(sendArgs) if err != nil { return nil, 0, createSwapParaswapErrorResponse(err) diff --git a/services/wallet/router/pathprocessor/processor_transfer.go b/services/wallet/router/pathprocessor/processor_transfer.go index 07521fcf4..52583efbd 100644 --- a/services/wallet/router/pathprocessor/processor_transfer.go +++ b/services/wallet/router/pathprocessor/processor_transfer.go @@ -14,6 +14,7 @@ import ( "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/rpc" walletCommon "github.com/status-im/status-go/services/wallet/common" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/transactions" ) @@ -122,7 +123,7 @@ func (s *TransferProcessor) BuildTransaction(sendArgs *MultipathProcessorTxArgs, return s.transactor.ValidateAndBuildTransaction(sendArgs.ChainID, *sendArgs.TransferTx, lastUsedNonce) } -func (s *TransferProcessor) BuildTransactionV2(sendArgs *transactions.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { +func (s *TransferProcessor) BuildTransactionV2(sendArgs *wallettypes.SendTxArgs, lastUsedNonce int64) (*ethTypes.Transaction, uint64, error) { return s.transactor.ValidateAndBuildTransaction(sendArgs.FromChainID, *sendArgs, lastUsedNonce) } diff --git a/services/wallet/transfer/transaction_manager.go b/services/wallet/transfer/transaction_manager.go index cb54bfb3f..273e03c05 100644 --- a/services/wallet/transfer/transaction_manager.go +++ b/services/wallet/transfer/transaction_manager.go @@ -18,6 +18,7 @@ import ( wallet_common "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/services/wallet/router/pathprocessor" "github.com/status-im/status-go/services/wallet/router/routes" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/transactions" ) @@ -30,7 +31,7 @@ type TransactionDescription struct { } type TransactionData struct { - TxArgs *transactions.SendTxArgs + TxArgs *wallettypes.SendTxArgs Tx *ethTypes.Transaction HashToSign types.Hash Signature []byte @@ -153,15 +154,15 @@ type TransactionIdentity struct { } type TxResponse struct { - KeyUID string `json:"keyUid,omitempty"` - Address types.Address `json:"address,omitempty"` - AddressPath string `json:"addressPath,omitempty"` - SignOnKeycard bool `json:"signOnKeycard,omitempty"` - ChainID uint64 `json:"chainId,omitempty"` - MessageToSign interface{} `json:"messageToSign,omitempty"` - TxArgs transactions.SendTxArgs `json:"txArgs,omitempty"` - RawTx string `json:"rawTx,omitempty"` - TxHash common.Hash `json:"txHash,omitempty"` + KeyUID string `json:"keyUid,omitempty"` + Address types.Address `json:"address,omitempty"` + AddressPath string `json:"addressPath,omitempty"` + SignOnKeycard bool `json:"signOnKeycard,omitempty"` + ChainID uint64 `json:"chainId,omitempty"` + MessageToSign interface{} `json:"messageToSign,omitempty"` + TxArgs wallettypes.SendTxArgs `json:"txArgs,omitempty"` + RawTx string `json:"rawTx,omitempty"` + TxHash common.Hash `json:"txHash,omitempty"` } func NewMultiTransaction(timestamp uint64, fromNetworkID, toNetworkID uint64, fromTxHash, toTxHash common.Hash, fromAddress, toAddress common.Address, fromAsset, toAsset string, fromAmount, toAmount *hexutil.Big, txType MultiTransactionType, crossTxID string) *MultiTransaction { @@ -197,7 +198,7 @@ func (tm *TransactionManager) SignMessage(message types.HexBytes, account *types return types.EncodeHex(signature), err } -func (tm *TransactionManager) BuildTransaction(chainID uint64, sendArgs transactions.SendTxArgs) (response *TxResponse, err error) { +func (tm *TransactionManager) BuildTransaction(chainID uint64, sendArgs wallettypes.SendTxArgs) (response *TxResponse, err error) { account, err := tm.accountsDB.GetAccountByAddress(sendArgs.From) if err != nil { return nil, fmt.Errorf("failed to resolve account: %w", err) @@ -255,7 +256,7 @@ func (tm *TransactionManager) BuildTransaction(chainID uint64, sendArgs transact }, nil } -func (tm *TransactionManager) BuildRawTransaction(chainID uint64, sendArgs transactions.SendTxArgs, signature []byte) (response *TxResponse, err error) { +func (tm *TransactionManager) BuildRawTransaction(chainID uint64, sendArgs wallettypes.SendTxArgs, signature []byte) (response *TxResponse, err error) { tx, err := tm.transactor.BuildTransactionWithSignature(chainID, sendArgs, signature) if err != nil { return nil, err @@ -274,7 +275,7 @@ func (tm *TransactionManager) BuildRawTransaction(chainID uint64, sendArgs trans }, nil } -func (tm *TransactionManager) SendTransactionWithSignature(chainID uint64, sendArgs transactions.SendTxArgs, signature []byte) (hash types.Hash, err error) { +func (tm *TransactionManager) SendTransactionWithSignature(chainID uint64, sendArgs wallettypes.SendTxArgs, signature []byte) (hash types.Hash, err error) { txWithSignature, err := tm.transactor.BuildTransactionWithSignature(chainID, sendArgs, signature) if err != nil { return hash, err diff --git a/services/wallet/transfer/transaction_manager_multitransaction_test.go b/services/wallet/transfer/transaction_manager_multitransaction_test.go index ac5b34438..72d365529 100644 --- a/services/wallet/transfer/transaction_manager_multitransaction_test.go +++ b/services/wallet/transfer/transaction_manager_multitransaction_test.go @@ -22,14 +22,15 @@ import ( "github.com/status-im/status-go/services/wallet/router/pathprocessor" mock_pathprocessor "github.com/status-im/status-go/services/wallet/router/pathprocessor/mock" "github.com/status-im/status-go/services/wallet/walletevent" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/t/helpers" "github.com/status-im/status-go/transactions" mock_transactor "github.com/status-im/status-go/transactions/mock" "github.com/status-im/status-go/walletdatabase" ) -func deepCopy(tx *transactions.SendTxArgs) *transactions.SendTxArgs { - return &transactions.SendTxArgs{ +func deepCopy(tx *wallettypes.SendTxArgs) *wallettypes.SendTxArgs { + return &wallettypes.SendTxArgs{ From: tx.From, To: tx.To, Value: tx.Value, @@ -87,7 +88,7 @@ func setupTransactionData(_ *testing.T, transactor transactions.TransactorIface) { ChainID: 1, Name: transferBridge.Name(), - TransferTx: &transactions.SendTxArgs{ + TransferTx: &wallettypes.SendTxArgs{ From: types.Address(ethTransfer.From), To: (*types.Address)(ðTransfer.To), Value: (*hexutil.Big)(big.NewInt(ethTransfer.Value / 3)), @@ -99,7 +100,7 @@ func setupTransactionData(_ *testing.T, transactor transactions.TransactorIface) { ChainID: 420, Name: transferBridge.Name(), - TransferTx: &transactions.SendTxArgs{ + TransferTx: &wallettypes.SendTxArgs{ From: types.Address(ethTransfer.From), To: (*types.Address)(ðTransfer.To), Value: (*hexutil.Big)(big.NewInt(ethTransfer.Value * 2 / 3)), @@ -137,7 +138,7 @@ func setupApproveTransactionData(_ *testing.T, transactor transactions.Transacto { //ChainID: 1, // This will be set by transaction manager Name: transferBridge.Name(), - TransferTx: &transactions.SendTxArgs{ + TransferTx: &wallettypes.SendTxArgs{ From: types.Address(tokenTransfer.From), To: (*types.Address)(&tokenTransfer.To), Value: (*hexutil.Big)(big.NewInt(tokenTransfer.Value)), @@ -203,9 +204,9 @@ func TestSendTransactionsETHFailOnBridge(t *testing.T) { transferBridge.EXPECT().Name().Return(data[0].Name).AnyTimes() bridges[transferBridge.Name()] = transferBridge - expectedErr := transactions.ErrInvalidTxSender // Any error to verify + expectedErr := wallettypes.ErrInvalidTxSender // Any error to verify // In case of bridge error, verify that the error is returned - transferBridge.EXPECT().Send(gomock.Any(), int64(-1), gomock.Any()).Return(types.Hash{}, uint64(0), transactions.ErrInvalidTxSender) + transferBridge.EXPECT().Send(gomock.Any(), int64(-1), gomock.Any()).Return(types.Hash{}, uint64(0), wallettypes.ErrInvalidTxSender) // Call the SendTransactions method _, err := tm.SendTransactions(context.Background(), multiTransaction, data, bridges, account) @@ -219,7 +220,7 @@ func TestSendTransactionsETHFailOnTransactor(t *testing.T) { // Verify that the SendTransactionWithChainID method is called for each transaction with proper arguments // Return values are not checked, because they must be checked in Transactor tests. Only error propagation matters here - expectedErr := transactions.ErrInvalidTxSender // Any error to verify + expectedErr := wallettypes.ErrInvalidTxSender // Any error to verify transactor.EXPECT().SendTransactionWithChainID(expectedData[0].ChainID, *(expectedData[0].TransferTx), int64(-1), account).Return(types.Hash{}, uint64(0), nil) transactor.EXPECT().SendTransactionWithChainID(expectedData[1].ChainID, *(expectedData[1].TransferTx), int64(-1), account).Return(types.Hash{}, uint64(0), expectedErr) diff --git a/services/wallet/transfer/transaction_manager_route.go b/services/wallet/transfer/transaction_manager_route.go index c2f88d80b..94ec63755 100644 --- a/services/wallet/transfer/transaction_manager_route.go +++ b/services/wallet/transfer/transaction_manager_route.go @@ -17,7 +17,7 @@ import ( "github.com/status-im/status-go/services/wallet/responses" "github.com/status-im/status-go/services/wallet/router/pathprocessor" "github.com/status-im/status-go/services/wallet/router/routes" - "github.com/status-im/status-go/transactions" + "github.com/status-im/status-go/services/wallet/wallettypes" ) type BuildRouteExtraParams struct { @@ -89,8 +89,8 @@ func buildApprovalTxForPath(transactor transactions.TransactorIface, path *route } addrTo := types.Address(path.FromToken.Address) - approavalSendArgs := &transactions.SendTxArgs{ - Version: transactions.SendTxArgsVersion1, + approavalSendArgs := &wallettypes.SendTxArgs{ + Version: wallettypes.SendTxArgsVersion1, // tx fields From: types.Address(addressFrom), @@ -151,8 +151,8 @@ func buildTxForPath(transactor transactions.TransactorIface, path *routes.Path, } addrTo := types.Address(params.AddressTo) - sendArgs := &transactions.SendTxArgs{ - Version: transactions.SendTxArgsVersion1, + sendArgs := &wallettypes.SendTxArgs{ + Version: wallettypes.SendTxArgsVersion1, // tx fields From: types.Address(params.AddressFrom), diff --git a/services/wallet/transfer/transaction_manager_test.go b/services/wallet/transfer/transaction_manager_test.go index e98b804a5..8705bf7d3 100644 --- a/services/wallet/transfer/transaction_manager_test.go +++ b/services/wallet/transfer/transaction_manager_test.go @@ -17,7 +17,7 @@ import ( "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/multiaccounts/accounts" wallet_common "github.com/status-im/status-go/services/wallet/common" - "github.com/status-im/status-go/transactions" + "github.com/status-im/status-go/services/wallet/wallettypes" mock_transactor "github.com/status-im/status-go/transactions/mock" "github.com/ethereum/go-ethereum/common" @@ -268,7 +268,7 @@ func TestBuildTransaction(t *testing.T) { chainID := uint64(1) nonce := uint64(1) gas := uint64(21000) - sendArgs := transactions.SendTxArgs{ + sendArgs := wallettypes.SendTxArgs{ From: types.Address{1}, To: &types.Address{2}, Value: (*hexutil.Big)(big.NewInt(123)), @@ -309,7 +309,7 @@ func TestBuildTransaction_AccountNotFound(t *testing.T) { chainID := uint64(1) nonce := uint64(1) gas := uint64(21000) - sendArgs := transactions.SendTxArgs{ + sendArgs := wallettypes.SendTxArgs{ From: types.Address{2}, To: &types.Address{2}, Value: (*hexutil.Big)(big.NewInt(123)), @@ -328,7 +328,7 @@ func TestBuildTransaction_InvalidSendTxArgs(t *testing.T) { manager, transactor := setupTestSuite(t) chainID := uint64(1) - sendArgs := transactions.SendTxArgs{ + sendArgs := wallettypes.SendTxArgs{ From: types.Address{1}, To: &types.Address{2}, } @@ -346,7 +346,7 @@ func TestBuildRawTransaction(t *testing.T) { chainID := uint64(1) nonce := uint64(1) gas := uint64(21000) - sendArgs := transactions.SendTxArgs{ + sendArgs := wallettypes.SendTxArgs{ From: types.Address{1}, To: &types.Address{2}, Value: (*hexutil.Big)(big.NewInt(123)), diff --git a/transactions/types.go b/services/wallet/wallettypes/types.go similarity index 99% rename from transactions/types.go rename to services/wallet/wallettypes/types.go index 7c3dbca77..3dfee41fb 100644 --- a/transactions/types.go +++ b/services/wallet/wallettypes/types.go @@ -1,4 +1,4 @@ -package transactions +package wallettypes import ( "bytes" diff --git a/transactions/types_test.go b/services/wallet/wallettypes/types_test.go similarity index 98% rename from transactions/types_test.go rename to services/wallet/wallettypes/types_test.go index 6114cdc16..836534710 100644 --- a/transactions/types_test.go +++ b/services/wallet/wallettypes/types_test.go @@ -1,4 +1,4 @@ -package transactions +package wallettypes import ( "testing" diff --git a/services/web3provider/api.go b/services/web3provider/api.go index 929c531bc..fc476aac6 100644 --- a/services/web3provider/api.go +++ b/services/web3provider/api.go @@ -12,7 +12,7 @@ import ( "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/logutils" "github.com/status-im/status-go/services/typeddata" - "github.com/status-im/status-go/transactions" + "github.com/status-im/status-go/services/wallet/wallettypes" ) const Web3SendAsyncReadOnly = "web3-send-async-read-only" @@ -247,8 +247,8 @@ func (api *API) getVerifiedWalletAccount(address, password string) (*account.Sel } if !exists { - logutils.ZapLogger().Error("failed to get a selected account", zap.Error(transactions.ErrInvalidTxSender)) - return nil, transactions.ErrAccountDoesntExist + logutils.ZapLogger().Error("failed to get a selected account", zap.Error(wallettypes.ErrInvalidTxSender)) + return nil, wallettypes.ErrAccountDoesntExist } key, err := api.s.accountsManager.VerifyAccountPassword(api.s.config.KeyStoreDir, address, password) @@ -326,7 +326,7 @@ func (api *API) ProcessWeb3ReadOnlyRequest(request Web3SendAsyncReadOnlyRequest) return nil, err } - var trxArgs transactions.SendTxArgs + var trxArgs wallettypes.SendTxArgs if err := json.Unmarshal(jsonString, &trxArgs); err != nil { return nil, err } diff --git a/services/web3provider/signature.go b/services/web3provider/signature.go index 1a4dd989e..a33363680 100644 --- a/services/web3provider/signature.go +++ b/services/web3provider/signature.go @@ -12,7 +12,7 @@ import ( "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/services/rpcfilters" "github.com/status-im/status-go/services/typeddata" - "github.com/status-im/status-go/transactions" + "github.com/status-im/status-go/services/wallet/wallettypes" ) // signMessage checks the pwd vs the selected account and signs a message @@ -73,7 +73,7 @@ func (api *API) signTypedDataV4(typed signercore.TypedData, address string, pass } // SendTransaction creates a new transaction and waits until it's complete. -func (api *API) sendTransaction(chainID uint64, sendArgs transactions.SendTxArgs, password string, requestType string) (hash types.Hash, err error) { +func (api *API) sendTransaction(chainID uint64, sendArgs wallettypes.SendTxArgs, password string, requestType string) (hash types.Hash, err error) { verifiedAccount, err := api.getVerifiedWalletAccount(sendArgs.From.String(), password) if err != nil { return hash, err diff --git a/transactions/transactor.go b/transactions/transactor.go index 5c3c3d414..aefda2947 100644 --- a/transactions/transactor.go +++ b/transactions/transactor.go @@ -25,6 +25,7 @@ import ( "github.com/status-im/status-go/rpc" "github.com/status-im/status-go/services/wallet/bigint" wallet_common "github.com/status-im/status-go/services/wallet/common" + "github.com/status-im/status-go/services/wallet/wallettypes" ) const ( @@ -52,12 +53,12 @@ func (e *ErrBadNonce) Error() string { type TransactorIface interface { NextNonce(rpcClient rpc.ClientInterface, chainID uint64, from types.Address) (uint64, error) EstimateGas(network *params.Network, from common.Address, to common.Address, value *big.Int, input []byte) (uint64, error) - SendTransaction(sendArgs SendTxArgs, verifiedAccount *account.SelectedExtKey, lastUsedNonce int64) (hash types.Hash, nonce uint64, err error) - SendTransactionWithChainID(chainID uint64, sendArgs SendTxArgs, lastUsedNonce int64, verifiedAccount *account.SelectedExtKey) (hash types.Hash, nonce uint64, err error) - ValidateAndBuildTransaction(chainID uint64, sendArgs SendTxArgs, lastUsedNonce int64) (tx *gethtypes.Transaction, nonce uint64, err error) + SendTransaction(sendArgs wallettypes.SendTxArgs, verifiedAccount *account.SelectedExtKey, lastUsedNonce int64) (hash types.Hash, nonce uint64, err error) + SendTransactionWithChainID(chainID uint64, sendArgs wallettypes.SendTxArgs, lastUsedNonce int64, verifiedAccount *account.SelectedExtKey) (hash types.Hash, nonce uint64, err error) + ValidateAndBuildTransaction(chainID uint64, sendArgs wallettypes.SendTxArgs, lastUsedNonce int64) (tx *gethtypes.Transaction, nonce uint64, err error) AddSignatureToTransaction(chainID uint64, tx *gethtypes.Transaction, sig []byte) (*gethtypes.Transaction, error) SendRawTransaction(chainID uint64, rawTx string) error - BuildTransactionWithSignature(chainID uint64, args SendTxArgs, sig []byte) (*gethtypes.Transaction, error) + BuildTransactionWithSignature(chainID uint64, args wallettypes.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 } @@ -142,18 +143,18 @@ func (t *Transactor) EstimateGas(network *params.Network, from common.Address, t } // SendTransaction is an implementation of eth_sendTransaction. It queues the tx to the sign queue. -func (t *Transactor) SendTransaction(sendArgs SendTxArgs, verifiedAccount *account.SelectedExtKey, lastUsedNonce int64) (hash types.Hash, nonce uint64, err error) { +func (t *Transactor) SendTransaction(sendArgs wallettypes.SendTxArgs, verifiedAccount *account.SelectedExtKey, lastUsedNonce int64) (hash types.Hash, nonce uint64, err error) { hash, nonce, err = t.validateAndPropagate(t.rpcWrapper, verifiedAccount, sendArgs, lastUsedNonce) return } -func (t *Transactor) SendTransactionWithChainID(chainID uint64, sendArgs SendTxArgs, lastUsedNonce int64, verifiedAccount *account.SelectedExtKey) (hash types.Hash, nonce uint64, err error) { +func (t *Transactor) SendTransactionWithChainID(chainID uint64, sendArgs wallettypes.SendTxArgs, lastUsedNonce int64, verifiedAccount *account.SelectedExtKey) (hash types.Hash, nonce uint64, err error) { wrapper := newRPCWrapper(t.rpcWrapper.RPCClient, chainID) hash, nonce, err = t.validateAndPropagate(wrapper, verifiedAccount, sendArgs, lastUsedNonce) return } -func (t *Transactor) ValidateAndBuildTransaction(chainID uint64, sendArgs SendTxArgs, lastUsedNonce int64) (tx *gethtypes.Transaction, nonce uint64, err error) { +func (t *Transactor) ValidateAndBuildTransaction(chainID uint64, sendArgs wallettypes.SendTxArgs, lastUsedNonce int64) (tx *gethtypes.Transaction, nonce uint64, err error) { wrapper := newRPCWrapper(t.rpcWrapper.RPCClient, chainID) tx, err = t.validateAndBuildTransaction(wrapper, sendArgs, lastUsedNonce) if err != nil { @@ -246,9 +247,9 @@ func (t *Transactor) SendTransactionWithSignature(from common.Address, symbol st // BuildTransactionAndSendWithSignature receive a transaction and a signature, serialize them together // It's different from eth_sendRawTransaction because it receives a signature and not a serialized transaction with signature. // Since the transactions is already signed, we assume it was validated and used the right nonce. -func (t *Transactor) BuildTransactionWithSignature(chainID uint64, args SendTxArgs, sig []byte) (*gethtypes.Transaction, error) { +func (t *Transactor) BuildTransactionWithSignature(chainID uint64, args wallettypes.SendTxArgs, sig []byte) (*gethtypes.Transaction, error) { if !args.Valid() { - return nil, ErrInvalidSendTxArgs + return nil, wallettypes.ErrInvalidSendTxArgs } if len(sig) != ValidSignatureSize { @@ -273,9 +274,9 @@ func (t *Transactor) BuildTransactionWithSignature(chainID uint64, args SendTxAr return txWithSignature, nil } -func (t *Transactor) HashTransaction(args SendTxArgs) (validatedArgs SendTxArgs, hash types.Hash, err error) { +func (t *Transactor) HashTransaction(args wallettypes.SendTxArgs) (validatedArgs wallettypes.SendTxArgs, hash types.Hash, err error) { if !args.Valid() { - return validatedArgs, hash, ErrInvalidSendTxArgs + return validatedArgs, hash, wallettypes.ErrInvalidSendTxArgs } validatedArgs = args @@ -356,21 +357,21 @@ func (t *Transactor) HashTransaction(args SendTxArgs) (validatedArgs SendTxArgs, } // make sure that only account which created the tx can complete it -func (t *Transactor) validateAccount(args SendTxArgs, selectedAccount *account.SelectedExtKey) error { +func (t *Transactor) validateAccount(args wallettypes.SendTxArgs, selectedAccount *account.SelectedExtKey) error { if selectedAccount == nil { return account.ErrNoAccountSelected } if !bytes.Equal(args.From.Bytes(), selectedAccount.Address.Bytes()) { - return ErrInvalidTxSender + return wallettypes.ErrInvalidTxSender } return nil } -func (t *Transactor) validateAndBuildTransaction(rpcWrapper *rpcWrapper, args SendTxArgs, lastUsedNonce int64) (tx *gethtypes.Transaction, err error) { +func (t *Transactor) validateAndBuildTransaction(rpcWrapper *rpcWrapper, args wallettypes.SendTxArgs, lastUsedNonce int64) (tx *gethtypes.Transaction, err error) { if !args.Valid() { - return tx, ErrInvalidSendTxArgs + return tx, wallettypes.ErrInvalidSendTxArgs } var nonce uint64 @@ -445,9 +446,9 @@ func (t *Transactor) validateAndBuildTransaction(rpcWrapper *rpcWrapper, args Se return tx, nil } -func (t *Transactor) validateAndPropagate(rpcWrapper *rpcWrapper, selectedAccount *account.SelectedExtKey, args SendTxArgs, lastUsedNonce int64) (hash types.Hash, nonce uint64, err error) { +func (t *Transactor) validateAndPropagate(rpcWrapper *rpcWrapper, selectedAccount *account.SelectedExtKey, args wallettypes.SendTxArgs, lastUsedNonce int64) (hash types.Hash, nonce uint64, err error) { symbol := args.Symbol - if args.Version == SendTxArgsVersion1 { + if args.Version == wallettypes.SendTxArgsVersion1 { symbol = args.FromTokenID } @@ -470,7 +471,7 @@ func (t *Transactor) validateAndPropagate(rpcWrapper *rpcWrapper, selectedAccoun return hash, tx.Nonce(), err } -func (t *Transactor) buildTransaction(args SendTxArgs) *gethtypes.Transaction { +func (t *Transactor) buildTransaction(args wallettypes.SendTxArgs) *gethtypes.Transaction { var ( nonce uint64 value *big.Int @@ -493,7 +494,7 @@ func (t *Transactor) buildTransaction(args SendTxArgs) *gethtypes.Transaction { return t.buildTransactionWithOverrides(nonce, value, gas, gasPrice, args) } -func (t *Transactor) buildTransactionWithOverrides(nonce uint64, value *big.Int, gas uint64, gasPrice *big.Int, args SendTxArgs) *gethtypes.Transaction { +func (t *Transactor) buildTransactionWithOverrides(nonce uint64, value *big.Int, gas uint64, gasPrice *big.Int, args wallettypes.SendTxArgs) *gethtypes.Transaction { var tx *gethtypes.Transaction if args.To != nil { @@ -548,7 +549,7 @@ func (t *Transactor) buildTransactionWithOverrides(nonce uint64, value *big.Int, return tx } -func (t *Transactor) logNewTx(args SendTxArgs, gas uint64, gasPrice *big.Int, value *big.Int) { +func (t *Transactor) logNewTx(args wallettypes.SendTxArgs, gas uint64, gasPrice *big.Int, value *big.Int) { t.logger.Info("New transaction", zap.Stringer("From", args.From), zap.Stringer("To", args.To), @@ -558,7 +559,7 @@ func (t *Transactor) logNewTx(args SendTxArgs, gas uint64, gasPrice *big.Int, va ) } -func (t *Transactor) logNewContract(args SendTxArgs, gas uint64, gasPrice *big.Int, value *big.Int, nonce uint64) { +func (t *Transactor) logNewContract(args wallettypes.SendTxArgs, gas uint64, gasPrice *big.Int, value *big.Int, nonce uint64) { t.logger.Info("New contract", zap.Stringer("From", args.From), zap.Uint64("Gas", gas), diff --git a/transactions/transactor_test.go b/transactions/transactor_test.go index b6348023d..06481cfaa 100644 --- a/transactions/transactor_test.go +++ b/transactions/transactor_test.go @@ -29,6 +29,7 @@ import ( "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/params" wallet_common "github.com/status-im/status-go/services/wallet/common" + "github.com/status-im/status-go/services/wallet/wallettypes" "github.com/status-im/status-go/sqlite" "github.com/status-im/status-go/t/utils" "github.com/status-im/status-go/transactions/fake" @@ -102,7 +103,7 @@ var ( testNonce = hexutil.Uint64(10) ) -func (s *TransactorSuite) setupTransactionPoolAPI(args SendTxArgs, returnNonce, resultNonce hexutil.Uint64, account *account.SelectedExtKey, txErr error) { +func (s *TransactorSuite) setupTransactionPoolAPI(args wallettypes.SendTxArgs, returnNonce, resultNonce hexutil.Uint64, account *account.SelectedExtKey, txErr error) { // Expect calls to gas functions only if there are no user defined values. // And also set the expected gas and gas price for RLP encoding the expected tx. var usedGas hexutil.Uint64 @@ -129,7 +130,7 @@ func (s *TransactorSuite) setupTransactionPoolAPI(args SendTxArgs, returnNonce, s.txServiceMock.EXPECT().SendRawTransaction(gomock.Any(), data).Return(common.Hash{}, txErr) } -func (s *TransactorSuite) rlpEncodeTx(args SendTxArgs, config *params.NodeConfig, account *account.SelectedExtKey, nonce *hexutil.Uint64, gas hexutil.Uint64, gasPrice *big.Int) hexutil.Bytes { +func (s *TransactorSuite) rlpEncodeTx(args wallettypes.SendTxArgs, config *params.NodeConfig, account *account.SelectedExtKey, nonce *hexutil.Uint64, gas hexutil.Uint64, gasPrice *big.Int) hexutil.Bytes { var txData gethtypes.TxData to := common.Address(*args.To) if args.IsDynamicFeeTx() { @@ -220,7 +221,7 @@ func (s *TransactorSuite) TestGasValues() { for _, testCase := range testCases { s.T().Run(testCase.name, func(t *testing.T) { s.SetupTest() - args := SendTxArgs{ + args := wallettypes.SendTxArgs{ From: account.FromAddress(utils.TestConfig.Account1.WalletAddress), To: account.ToAddress(utils.TestConfig.Account2.WalletAddress), Gas: testCase.gas, @@ -237,7 +238,7 @@ func (s *TransactorSuite) TestGasValues() { } } -func (s *TransactorSuite) setupBuildTransactionMocks(args SendTxArgs, account *account.SelectedExtKey) { +func (s *TransactorSuite) setupBuildTransactionMocks(args wallettypes.SendTxArgs, account *account.SelectedExtKey) { s.txServiceMock.EXPECT().GetTransactionCount(gomock.Any(), gomock.Eq(common.Address(account.Address)), gethrpc.PendingBlockNumber).Return(&testNonce, nil) if !args.IsDynamicFeeTx() && args.GasPrice == nil { @@ -269,7 +270,7 @@ func (s *TransactorSuite) TestBuildAndValidateTransaction() { s.SetupTest() gas := hexutil.Uint64(21000) - args := SendTxArgs{ + args := wallettypes.SendTxArgs{ From: fromAddress, To: toAddress, Gas: &gas, @@ -289,7 +290,7 @@ func (s *TransactorSuite) TestBuildAndValidateTransaction() { s.T().Run("DynamicFeeTransaction with gas estimation", func(t *testing.T) { s.SetupTest() - args := SendTxArgs{ + args := wallettypes.SendTxArgs{ From: fromAddress, To: toAddress, Value: value, @@ -312,7 +313,7 @@ func (s *TransactorSuite) TestBuildAndValidateTransaction() { gas := hexutil.Uint64(21000) gasPrice := (*hexutil.Big)(big.NewInt(10)) - args := SendTxArgs{ + args := wallettypes.SendTxArgs{ From: fromAddress, To: toAddress, Value: value, @@ -330,7 +331,7 @@ func (s *TransactorSuite) TestBuildAndValidateTransaction() { s.T().Run("LegacyTransaction without gas estimation", func(t *testing.T) { s.SetupTest() - args := SendTxArgs{ + args := wallettypes.SendTxArgs{ From: fromAddress, To: toAddress, Value: value, @@ -346,7 +347,7 @@ func (s *TransactorSuite) TestBuildAndValidateTransaction() { } func (s *TransactorSuite) TestArgsValidation() { - args := SendTxArgs{ + args := wallettypes.SendTxArgs{ From: account.FromAddress(utils.TestConfig.Account1.WalletAddress), To: account.ToAddress(utils.TestConfig.Account2.WalletAddress), Data: types.HexBytes([]byte{0x01, 0x02}), @@ -357,11 +358,11 @@ func (s *TransactorSuite) TestArgsValidation() { Address: account.FromAddress(utils.TestConfig.Account1.WalletAddress), } _, _, err := s.manager.SendTransaction(args, selectedAccount, -1) - s.EqualError(err, ErrInvalidSendTxArgs.Error()) + s.EqualError(err, wallettypes.ErrInvalidSendTxArgs.Error()) } func (s *TransactorSuite) TestAccountMismatch() { - args := SendTxArgs{ + args := wallettypes.SendTxArgs{ From: account.FromAddress(utils.TestConfig.Account1.WalletAddress), To: account.ToAddress(utils.TestConfig.Account2.WalletAddress), } @@ -377,7 +378,7 @@ func (s *TransactorSuite) TestAccountMismatch() { Address: account.FromAddress(utils.TestConfig.Account2.WalletAddress), } _, _, err = s.manager.SendTransaction(args, selectedAccount, -1) - s.EqualError(err, ErrInvalidTxSender.Error()) + s.EqualError(err, wallettypes.ErrInvalidTxSender.Error()) } func (s *TransactorSuite) TestSendTransactionWithSignature() { @@ -415,7 +416,7 @@ func (s *TransactorSuite) TestSendTransactionWithSignature() { gasPrice := (*hexutil.Big)(big.NewInt(2000000000)) data := []byte{} chainID := big.NewInt(int64(s.nodeConfig.NetworkID)) - args := SendTxArgs{ + args := wallettypes.SendTxArgs{ From: from, To: &to, Gas: &gas, @@ -464,7 +465,7 @@ func (s *TransactorSuite) TestSendTransactionWithSignature() { } func (s *TransactorSuite) TestSendTransactionWithSignature_InvalidSignature() { - args := SendTxArgs{} + args := wallettypes.SendTxArgs{} _, err := s.manager.BuildTransactionWithSignature(1, args, []byte{}) s.Equal(ErrInvalidSignatureSize, err) } @@ -482,7 +483,7 @@ func (s *TransactorSuite) TestHashTransaction() { gas := hexutil.Uint64(21000) gasPrice := (*hexutil.Big)(big.NewInt(2000000000)) - args := SendTxArgs{ + args := wallettypes.SendTxArgs{ From: from, To: &to, Gas: &gas,