2020-02-25 09:28:33 +00:00
|
|
|
import 'package:basic_utils/basic_utils.dart';
|
2024-12-09 18:23:59 +00:00
|
|
|
import 'package:cw_core/utils/print_verbose.dart';
|
2020-02-25 09:28:33 +00:00
|
|
|
|
|
|
|
class OpenaliasRecord {
|
2022-01-18 07:46:13 +00:00
|
|
|
OpenaliasRecord({
|
2022-10-12 17:09:57 +00:00
|
|
|
required this.address,
|
|
|
|
required this.name,
|
|
|
|
required this.description,
|
2022-01-18 07:46:13 +00:00
|
|
|
});
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
final String name;
|
|
|
|
final String address;
|
2022-01-18 07:46:13 +00:00
|
|
|
final String description;
|
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;
|
|
|
|
}
|
|
|
|
|
2023-01-31 19:39:08 +00:00
|
|
|
static Future<List<RRecord>?> lookupOpenAliasRecord(String name) async {
|
|
|
|
try {
|
|
|
|
final txtRecord = await DnsUtils.lookupRecord(name, RRecordType.TXT, dnssec: true);
|
|
|
|
|
|
|
|
return txtRecord;
|
|
|
|
} catch (e) {
|
2024-12-09 18:23:59 +00:00
|
|
|
printV("${e.toString()}");
|
2023-01-31 19:39:08 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static OpenaliasRecord fetchAddressAndName({
|
2022-10-12 17:09:57 +00:00
|
|
|
required String formattedName,
|
|
|
|
required String ticker,
|
2023-01-31 19:39:08 +00:00
|
|
|
required List<RRecord> txtRecord,
|
|
|
|
}) {
|
2023-08-01 12:00:00 +00:00
|
|
|
String address = '';
|
2020-02-25 12:45:06 +00:00
|
|
|
String name = formattedName;
|
2022-01-18 07:46:13 +00:00
|
|
|
String note = '';
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2023-01-31 19:39:08 +00:00
|
|
|
for (RRecord element in txtRecord) {
|
|
|
|
String record = element.data;
|
|
|
|
|
|
|
|
if (record.contains("oa1:$ticker") && record.contains("recipient_address")) {
|
|
|
|
record = record.replaceAll('\"', "");
|
|
|
|
|
|
|
|
final dataList = record.split(";");
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if (recipientName.isNotEmpty) {
|
|
|
|
name = recipientName.replaceAll("recipient_name=", "");
|
2020-02-25 09:28:33 +00:00
|
|
|
}
|
2023-01-31 19:39:08 +00:00
|
|
|
|
|
|
|
final description = dataList
|
|
|
|
.where((item) => (item.contains("tx_description")))
|
|
|
|
.toString()
|
|
|
|
.replaceAll("(", "")
|
|
|
|
.replaceAll(")", "")
|
|
|
|
.trim();
|
|
|
|
|
|
|
|
if (description.isNotEmpty) {
|
|
|
|
note = description.replaceAll("tx_description=", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2020-02-25 09:28:33 +00:00
|
|
|
}
|
2020-02-25 12:45:06 +00:00
|
|
|
|
2020-02-25 09:28:33 +00:00
|
|
|
}
|
2023-01-31 19:39:08 +00:00
|
|
|
return OpenaliasRecord(address: address, name: name, description: note);
|
|
|
|
}
|
2020-02-25 09:28:33 +00:00
|
|
|
}
|