2020-02-25 09:28:33 +00:00
|
|
|
import 'package:basic_utils/basic_utils.dart';
|
2022-01-14 13:18:03 +00:00
|
|
|
import 'package:cw_core/wallet_type.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2020-02-25 09:28:33 +00:00
|
|
|
|
|
|
|
class OpenaliasRecord {
|
2022-01-18 07:46:13 +00:00
|
|
|
OpenaliasRecord({
|
|
|
|
this.address,
|
|
|
|
this.name,
|
|
|
|
this.description,
|
|
|
|
});
|
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;
|
|
|
|
}
|
|
|
|
|
2022-01-14 13:18:03 +00:00
|
|
|
static Future<OpenaliasRecord> fetchAddressAndName({
|
|
|
|
@required String formattedName,
|
|
|
|
@required String ticker,
|
|
|
|
}) async {
|
2020-02-25 12:45:06 +00:00
|
|
|
String address = formattedName;
|
|
|
|
String name = formattedName;
|
2022-01-18 07:46:13 +00:00
|
|
|
String note = '';
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2020-02-25 12:45:06 +00:00
|
|
|
if (formattedName.contains(".")) {
|
|
|
|
try {
|
2022-01-14 13:18:03 +00:00
|
|
|
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) {
|
|
|
|
for (RRecord element in txtRecord) {
|
|
|
|
String record = element.data;
|
2020-02-25 09:28:33 +00:00
|
|
|
|
2022-01-14 13:18:03 +00:00
|
|
|
if (record.contains("oa1:$ticker") &&
|
|
|
|
record.contains("recipient_address")) {
|
2020-02-25 12:45:06 +00:00
|
|
|
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
|
|
|
|
2022-01-14 13:18:03 +00: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 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
|
|
|
|
2022-01-18 07:46:13 +00:00
|
|
|
final description = dataList
|
|
|
|
.where((item) => (item.contains("tx_description")))
|
|
|
|
.toString()
|
|
|
|
.replaceAll("(", "")
|
|
|
|
.replaceAll(")", "")
|
|
|
|
.trim();
|
|
|
|
|
|
|
|
if (description.isNotEmpty) {
|
|
|
|
note = description.replaceAll("tx_description=", "");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2022-01-18 07:46:13 +00:00
|
|
|
return OpenaliasRecord(address: address, name: name, description: note);
|
2020-02-25 09:28:33 +00:00
|
|
|
}
|
|
|
|
}
|