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