mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-07 11:19:25 +00:00
fix: bch address book entry address validation
This commit is contained in:
parent
314f036dbf
commit
99b809ef17
1 changed files with 43 additions and 3 deletions
|
@ -10,11 +10,11 @@
|
||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:bitbox/bitbox.dart' as bitbox;
|
||||||
import 'package:bitcoindart/bitcoindart.dart';
|
import 'package:bitcoindart/bitcoindart.dart';
|
||||||
import 'package:crypto/crypto.dart';
|
import 'package:crypto/crypto.dart';
|
||||||
import 'package:flutter_libepiccash/epic_cash.dart';
|
import 'package:flutter_libepiccash/epic_cash.dart';
|
||||||
import 'package:nanodart/nanodart.dart';
|
import 'package:nanodart/nanodart.dart';
|
||||||
import 'package:stackwallet/services/coins/bitcoincash/bitcoincash_wallet.dart';
|
|
||||||
import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart';
|
import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart';
|
||||||
import 'package:stackwallet/services/coins/ecash/ecash_wallet.dart';
|
import 'package:stackwallet/services/coins/ecash/ecash_wallet.dart';
|
||||||
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
||||||
|
@ -64,7 +64,27 @@ class AddressUtils {
|
||||||
case Coin.litecoin:
|
case Coin.litecoin:
|
||||||
return Address.validateAddress(address, litecoin);
|
return Address.validateAddress(address, litecoin);
|
||||||
case Coin.bitcoincash:
|
case Coin.bitcoincash:
|
||||||
return Address.validateAddress(address, bitcoincash);
|
try {
|
||||||
|
// 0 for bitcoincash: address scheme, 1 for legacy address
|
||||||
|
final format = bitbox.Address.detectFormat(address);
|
||||||
|
|
||||||
|
if (coin == Coin.bitcoincashTestnet) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format == bitbox.Address.formatCashAddr) {
|
||||||
|
String addr = address;
|
||||||
|
if (addr.contains(":")) {
|
||||||
|
addr = addr.split(":").last;
|
||||||
|
}
|
||||||
|
|
||||||
|
return addr.startsWith("q");
|
||||||
|
} else {
|
||||||
|
return address.startsWith("1");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
case Coin.dogecoin:
|
case Coin.dogecoin:
|
||||||
return Address.validateAddress(address, dogecoin);
|
return Address.validateAddress(address, dogecoin);
|
||||||
case Coin.epicCash:
|
case Coin.epicCash:
|
||||||
|
@ -94,7 +114,27 @@ class AddressUtils {
|
||||||
case Coin.litecoinTestNet:
|
case Coin.litecoinTestNet:
|
||||||
return Address.validateAddress(address, litecointestnet);
|
return Address.validateAddress(address, litecointestnet);
|
||||||
case Coin.bitcoincashTestnet:
|
case Coin.bitcoincashTestnet:
|
||||||
return Address.validateAddress(address, bitcoincashtestnet);
|
try {
|
||||||
|
// 0 for bitcoincash: address scheme, 1 for legacy address
|
||||||
|
final format = bitbox.Address.detectFormat(address);
|
||||||
|
|
||||||
|
if (coin == Coin.bitcoincashTestnet) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format == bitbox.Address.formatCashAddr) {
|
||||||
|
String addr = address;
|
||||||
|
if (addr.contains(":")) {
|
||||||
|
addr = addr.split(":").last;
|
||||||
|
}
|
||||||
|
|
||||||
|
return addr.startsWith("q");
|
||||||
|
} else {
|
||||||
|
return address.startsWith("1");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
case Coin.firoTestNet:
|
case Coin.firoTestNet:
|
||||||
return Address.validateAddress(address, firoTestNetwork);
|
return Address.validateAddress(address, firoTestNetwork);
|
||||||
case Coin.dogecoinTestNet:
|
case Coin.dogecoinTestNet:
|
||||||
|
|
Loading…
Reference in a new issue