diff --git a/BlockchainSdk/Blockchains/Ethereum/EthereumStakeKitTransactionHelper.swift b/BlockchainSdk/Blockchains/Ethereum/EthereumStakeKitTransactionHelper.swift index 62e71a6c9..3486be9d9 100644 --- a/BlockchainSdk/Blockchains/Ethereum/EthereumStakeKitTransactionHelper.swift +++ b/BlockchainSdk/Blockchains/Ethereum/EthereumStakeKitTransactionHelper.swift @@ -11,13 +11,17 @@ import WalletCore import BigInt struct EthereumStakeKitTransactionHelper { + private let transactionBuilder: EthereumTransactionBuilder + + init(transactionBuilder: EthereumTransactionBuilder) { + self.transactionBuilder = transactionBuilder + } + func prepareForSign( - _ stakingTransaction: StakeKitTransaction, - transactionBuilder: EthereumTransactionBuilder + _ stakingTransaction: StakeKitTransaction ) throws -> Data { let input = try buildSigningInput( - stakingTransaction: stakingTransaction, - transactionBuilder: transactionBuilder + stakingTransaction: stakingTransaction ) let preSigningOutput = try transactionBuilder.buildTxCompilerPreSigningOutput(input: input) return preSigningOutput.dataHash @@ -25,20 +29,17 @@ struct EthereumStakeKitTransactionHelper { func prepareForSend( stakingTransaction: StakeKitTransaction, - transactionBuilder: EthereumTransactionBuilder, signatureInfo: SignatureInfo ) throws -> Data { let input = try buildSigningInput( - stakingTransaction: stakingTransaction, - transactionBuilder: transactionBuilder + stakingTransaction: stakingTransaction ) let output = try transactionBuilder.buildSigningOutput(input: input, signatureInfo: signatureInfo) return output.encoded } private func buildSigningInput( - stakingTransaction: StakeKitTransaction, - transactionBuilder: EthereumTransactionBuilder + stakingTransaction: StakeKitTransaction ) throws -> EthereumSigningInput { let compiledTransactionData = Data(hex: stakingTransaction.unsignedData) let compiledTransaction = try JSONDecoder().decode( diff --git a/BlockchainSdk/Blockchains/Ethereum/EthereumTransactionBuilder.swift b/BlockchainSdk/Blockchains/Ethereum/EthereumTransactionBuilder.swift index 0950398c9..420c8759f 100644 --- a/BlockchainSdk/Blockchains/Ethereum/EthereumTransactionBuilder.swift +++ b/BlockchainSdk/Blockchains/Ethereum/EthereumTransactionBuilder.swift @@ -30,7 +30,7 @@ class EthereumTransactionBuilder { let input = try buildSigningInput(transaction: transaction) let output = try buildSigningOutput(input: input, signatureInfo: signatureInfo) return output.encoded - } + } func buildDummyTransactionForL1(destination: String, value: String?, data: Data?, fee: Fee) throws -> Data { let valueData = BigUInt(Data(hex: value ?? "0x0")) diff --git a/BlockchainSdk/Blockchains/Ethereum/EthereumWalletManager.swift b/BlockchainSdk/Blockchains/Ethereum/EthereumWalletManager.swift index fa41a30e7..36194e422 100644 --- a/BlockchainSdk/Blockchains/Ethereum/EthereumWalletManager.swift +++ b/BlockchainSdk/Blockchains/Ethereum/EthereumWalletManager.swift @@ -410,28 +410,9 @@ extension EthereumWalletManager: StakeKitTransactionSender { transaction: StakeKitTransaction, signer: any TransactionSigner ) -> AnyPublisher { - signStakeKit(transaction, signer: signer) - .withWeakCaptureOf(self) - .flatMap { walletManager, rawTransaction in - walletManager.networkService.send(transaction: rawTransaction) - .mapSendError(tx: rawTransaction) - } - .withWeakCaptureOf(self) - .tryMap { walletManager, hash in - let mapper = PendingTransactionRecordMapper() - let record = mapper.mapToPendingTransactionRecord(stakeKitTransaction: transaction, hash: hash) - walletManager.wallet.addPendingTransaction(record) - - return TransactionSendResult(hash: hash) - } - .eraseSendError() - .eraseToAnyPublisher() - } - - func signStakeKit(_ transaction: StakeKitTransaction, signer: TransactionSigner) -> AnyPublisher { - let helper = EthereumStakeKitTransactionHelper() + let helper = EthereumStakeKitTransactionHelper(transactionBuilder: txBuilder) return Result { - try helper.prepareForSign(transaction, transactionBuilder: txBuilder) + try helper.prepareForSign(transaction) } .publisher .withWeakCaptureOf(self) @@ -442,13 +423,26 @@ extension EthereumWalletManager: StakeKitTransactionSender { .tryMap { walletManager, signatureInfo -> String in try helper.prepareForSend( stakingTransaction: transaction, - transactionBuilder: walletManager.txBuilder, signatureInfo: signatureInfo ) .hexString .lowercased() .addHexPrefix() } + .withWeakCaptureOf(self) + .flatMap { walletManager, rawTransaction in + walletManager.networkService.send(transaction: rawTransaction) + .mapSendError(tx: rawTransaction) + } + .withWeakCaptureOf(self) + .tryMap { walletManager, hash in + let mapper = PendingTransactionRecordMapper() + let record = mapper.mapToPendingTransactionRecord(stakeKitTransaction: transaction, hash: hash) + walletManager.wallet.addPendingTransaction(record) + + return TransactionSendResult(hash: hash) + } + .eraseSendError() .eraseToAnyPublisher() } }