Skip to content

Commit 7b7eaa8

Browse files
committed
allow send to cardano enterprise addresses
1 parent 1f44387 commit 7b7eaa8

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

lib/wallets/crypto_currency/coins/cardano.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import 'package:blockchain_utils/bip/address/ada/ada.dart';
2+
import 'package:on_chain/ada/ada.dart';
3+
14
import '../../../models/isar/models/blockchain_data/address.dart';
25
import '../../../models/node_model.dart';
36
import '../../../utilities/default_nodes.dart';
@@ -123,7 +126,18 @@ class Cardano extends Bip39Currency {
123126
bool validateAddress(String address) {
124127
switch (network) {
125128
case CryptoCurrencyNetwork.main:
126-
return RegExp(r"^addr1[0-9a-zA-Z]{98}$").hasMatch(address);
129+
try {
130+
final adaAddress = ADAAddress.fromAddress(
131+
address,
132+
network: ADANetwork.mainnet,
133+
);
134+
135+
return (adaAddress is ADABaseAddress ||
136+
adaAddress is ADAEnterpriseAddress);
137+
} catch (_) {
138+
return false;
139+
}
140+
127141
default:
128142
throw Exception("Unsupported network: $network");
129143
}

lib/wallets/wallet/impl/cardano_wallet.dart

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,17 @@ class CardanoWallet extends Bip39Wallet<Cardano> {
202202
address: ADABaseAddress((await getCurrentReceivingAddress())!.value),
203203
amount: Value(coin: totalBalance - (txData.amount!.raw)),
204204
);
205+
206+
final outputAddress = ADAAddress.fromAddress(
207+
txData.recipients!.first.address,
208+
);
209+
if (!(outputAddress is ADABaseAddress ||
210+
outputAddress is ADAEnterpriseAddress)) {
211+
throw Exception(
212+
"Address of type ${outputAddress.runtimeType} currently not supported.",
213+
);
214+
}
215+
205216
final body = TransactionBody(
206217
inputs:
207218
listOfUtxosToBeUsed
@@ -215,7 +226,7 @@ class CardanoWallet extends Bip39Wallet<Cardano> {
215226
outputs: [
216227
change,
217228
TransactionOutput(
218-
address: ADABaseAddress(txData.recipients!.first.address),
229+
address: outputAddress,
219230
amount: Value(coin: txData.amount!.raw - exampleFee),
220231
),
221232
],
@@ -323,19 +334,30 @@ class CardanoWallet extends Bip39Wallet<Cardano> {
323334
coin: totalUtxoAmount - (txData.amount!.raw + txData.fee!.raw),
324335
),
325336
);
337+
338+
final outputAddress = ADAAddress.fromAddress(
339+
txData.recipients!.first.address,
340+
);
341+
if (!(outputAddress is ADABaseAddress ||
342+
outputAddress is ADAEnterpriseAddress)) {
343+
throw Exception(
344+
"Address of type ${outputAddress.runtimeType} currently not supported.",
345+
);
346+
}
347+
326348
List<TransactionOutput> outputs = [];
327349
if (totalBalance == (txData.amount!.raw + txData.fee!.raw)) {
328350
outputs = [
329351
TransactionOutput(
330-
address: ADABaseAddress(txData.recipients!.first.address),
352+
address: outputAddress,
331353
amount: Value(coin: txData.amount!.raw),
332354
),
333355
];
334356
} else {
335357
outputs = [
336358
change,
337359
TransactionOutput(
338-
address: ADABaseAddress(txData.recipients!.first.address),
360+
address: outputAddress,
339361
amount: Value(coin: txData.amount!.raw),
340362
),
341363
];

0 commit comments

Comments
 (0)