2020-02-25 09:28:33 +00:00
|
|
|
import 'package:basic_utils/basic_utils.dart';
|
|
|
|
|
|
|
|
class OpenaliasRecord {
|
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
OpenaliasRecord({this.address, this.name});
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
final String name;
|
|
|
|
final String address;
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
static String formatDomainName(String name) {
|
2020-02-25 09:28:33 +00:00
|
|
|
String formattedName = name;
|
|
|
|
|
|
|
|
if (name.contains("@")) {
|
|
|
|
formattedName = name.replaceAll("@", ".");
|
|
|
|
}
|
|
|
|
|
|
|
|
return formattedName;
|
|
|
|
}
|
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
static Future<OpenaliasRecord> fetchAddressAndName(String formattedName) async {
|
|
|
|
String address = formattedName;
|
|
|
|
String name = formattedName;
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
if (formattedName.contains(".")) {
|
|
|
|
try {
|
|
|
|
final txtRecord = await DnsUtils.lookupRecord(formattedName, RRecordType.TXT, dnssec: true);
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
if (txtRecord != null) {
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
for (RRecord element in txtRecord) {
|
|
|
|
String record = element.data;
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
if (record.contains("oa1:xmr") && record.contains("recipient_address")) {
|
|
|
|
record = record.replaceAll('\"', "");
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
final dataList = record.split(";");
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
address = dataList.where((item) => (item.contains("recipient_address")))
|
|
|
|
.toString().replaceAll("oa1:xmr recipient_address=", "")
|
|
|
|
.replaceAll("(", "").replaceAll(")", "").trim();
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
final recipientName = dataList.where((item) => (item.contains("recipient_name"))).toString()
|
|
|
|
.replaceAll("(", "").replaceAll(")", "").trim();
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
if (recipientName.isNotEmpty) {
|
|
|
|
name = recipientName.replaceAll("recipient_name=", "");
|
|
|
|
}
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-02-25 09:28:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-25 12:45:06 +00:00
|
|
|
} catch (e) {
|
|
|
|
print("${e.toString()}");
|
2020-02-25 09:28:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-25 12:45:06 +00:00
|
|
|
|
|
|
|
return OpenaliasRecord(address: address, name: name);
|
2020-02-25 09:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|