added 10 outputs check

This commit is contained in:
Serhii 2024-03-10 23:42:58 +02:00
parent 3db22560bc
commit c8e3f61c5c
4 changed files with 14 additions and 2 deletions

View file

@ -31,6 +31,9 @@ class PendingBitcoinTransaction with PendingTransaction {
@override @override
String get feeFormatted => bitcoinAmountToString(amount: fee); String get feeFormatted => bitcoinAmountToString(amount: fee);
@override
int? get outputCount => _tx.outputs.length;
final List<void Function(ElectrumTransactionInfo transaction)> _listeners; final List<void Function(ElectrumTransactionInfo transaction)> _listeners;
@override @override

View file

@ -3,6 +3,7 @@ mixin PendingTransaction {
String get amountFormatted; String get amountFormatted;
String get feeFormatted; String get feeFormatted;
String get hex; String get hex;
int? get outputCount => null;
Future<void> commit(); Future<void> commit();
} }

View file

@ -106,7 +106,7 @@ abstract class ExchangeTradeViewModelBase with Store {
output.setCryptoAmount(trade.amount); output.setCryptoAmount(trade.amount);
if (_provider is ThorChainExchangeProvider) output.memo = trade.memo; if (_provider is ThorChainExchangeProvider) output.memo = trade.memo;
sendViewModel.selectedCryptoCurrency = trade.from; sendViewModel.selectedCryptoCurrency = trade.from;
final pendingTransaction = await sendViewModel.createTransaction(); final pendingTransaction = await sendViewModel.createTransaction(provider: _provider);
if (_provider is ThorChainExchangeProvider) { if (_provider is ThorChainExchangeProvider) {
trade.id = pendingTransaction?.id ?? ''; trade.id = pendingTransaction?.id ?? '';
trades.add(trade); trades.add(trade);

View file

@ -1,6 +1,8 @@
import 'package:cake_wallet/entities/priority_for_wallet_type.dart'; import 'package:cake_wallet/entities/priority_for_wallet_type.dart';
import 'package:cake_wallet/entities/transaction_description.dart'; import 'package:cake_wallet/entities/transaction_description.dart';
import 'package:cake_wallet/ethereum/ethereum.dart'; import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cake_wallet/exchange/provider/exchange_provider.dart';
import 'package:cake_wallet/exchange/provider/thorchain_exchange.provider.dart';
import 'package:cake_wallet/nano/nano.dart'; import 'package:cake_wallet/nano/nano.dart';
import 'package:cake_wallet/core/wallet_change_listener_view_model.dart'; import 'package:cake_wallet/core/wallet_change_listener_view_model.dart';
import 'package:cake_wallet/entities/contact_record.dart'; import 'package:cake_wallet/entities/contact_record.dart';
@ -295,10 +297,16 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
} }
@action @action
Future<PendingTransaction?> createTransaction() async { Future<PendingTransaction?> createTransaction({ExchangeProvider? provider}) async {
try { try {
state = IsExecutingState(); state = IsExecutingState();
pendingTransaction = await wallet.createTransaction(_credentials()); pendingTransaction = await wallet.createTransaction(_credentials());
if (provider is ThorChainExchangeProvider) {
print('Output count: ${pendingTransaction?.outputCount}');
print('provider is ThorChainExchangeProvider and pendingTransaction is ${provider.runtimeType}');
final outputCount = pendingTransaction?.outputCount ?? 0;
if (outputCount > 10) throw Exception("ThorChain does not support more than 10 outputs");
}
state = ExecutedSuccessfullyState(); state = ExecutedSuccessfullyState();
return pendingTransaction; return pendingTransaction;
} catch (e) { } catch (e) {