mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-09 12:29:31 +00:00
update logic for Crypto address resolving
update resolving of crypto wallet addresses by using of OpenAlias in way to pick right wallet address based on current wallet type
This commit is contained in:
parent
1a0d33ee31
commit
ac8ef0c946
2 changed files with 42 additions and 31 deletions
|
@ -1,7 +1,8 @@
|
||||||
import 'package:basic_utils/basic_utils.dart';
|
import 'package:basic_utils/basic_utils.dart';
|
||||||
|
import 'package:cw_core/wallet_type.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class OpenaliasRecord {
|
class OpenaliasRecord {
|
||||||
|
|
||||||
OpenaliasRecord({this.address, this.name});
|
OpenaliasRecord({this.address, this.name});
|
||||||
|
|
||||||
final String name;
|
final String name;
|
||||||
|
@ -17,30 +18,43 @@ class OpenaliasRecord {
|
||||||
return formattedName;
|
return formattedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<OpenaliasRecord> fetchAddressAndName(String formattedName) async {
|
static Future<OpenaliasRecord> fetchAddressAndName({
|
||||||
|
@required String formattedName,
|
||||||
|
@required String ticker,
|
||||||
|
}) async {
|
||||||
String address = formattedName;
|
String address = formattedName;
|
||||||
String name = formattedName;
|
String name = formattedName;
|
||||||
|
|
||||||
if (formattedName.contains(".")) {
|
if (formattedName.contains(".")) {
|
||||||
try {
|
try {
|
||||||
final txtRecord = await DnsUtils.lookupRecord(formattedName, RRecordType.TXT, dnssec: true);
|
final txtRecord = await DnsUtils.lookupRecord(
|
||||||
|
formattedName, RRecordType.TXT,
|
||||||
|
dnssec: true);
|
||||||
|
|
||||||
if (txtRecord != null) {
|
if (txtRecord != null) {
|
||||||
|
|
||||||
for (RRecord element in txtRecord) {
|
for (RRecord element in txtRecord) {
|
||||||
String record = element.data;
|
String record = element.data;
|
||||||
|
|
||||||
if (record.contains("oa1:xmr") && record.contains("recipient_address")) {
|
if (record.contains("oa1:$ticker") &&
|
||||||
|
record.contains("recipient_address")) {
|
||||||
record = record.replaceAll('\"', "");
|
record = record.replaceAll('\"', "");
|
||||||
|
|
||||||
final dataList = record.split(";");
|
final dataList = record.split(";");
|
||||||
|
|
||||||
address = dataList.where((item) => (item.contains("recipient_address")))
|
address = dataList
|
||||||
.toString().replaceAll("oa1:xmr recipient_address=", "")
|
.where((item) => (item.contains("recipient_address")))
|
||||||
.replaceAll("(", "").replaceAll(")", "").trim();
|
.toString()
|
||||||
|
.replaceAll("oa1:$ticker recipient_address=", "")
|
||||||
|
.replaceAll("(", "")
|
||||||
|
.replaceAll(")", "")
|
||||||
|
.trim();
|
||||||
|
|
||||||
final recipientName = dataList.where((item) => (item.contains("recipient_name"))).toString()
|
final recipientName = dataList
|
||||||
.replaceAll("(", "").replaceAll(")", "").trim();
|
.where((item) => (item.contains("recipient_name")))
|
||||||
|
.toString()
|
||||||
|
.replaceAll("(", "")
|
||||||
|
.replaceAll(")", "")
|
||||||
|
.trim();
|
||||||
|
|
||||||
if (recipientName.isNotEmpty) {
|
if (recipientName.isNotEmpty) {
|
||||||
name = recipientName.replaceAll("recipient_name=", "");
|
name = recipientName.replaceAll("recipient_name=", "");
|
||||||
|
@ -57,6 +71,4 @@ class OpenaliasRecord {
|
||||||
|
|
||||||
return OpenaliasRecord(address: address, name: name);
|
return OpenaliasRecord(address: address, name: name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,18 +2,20 @@ import 'package:cake_wallet/entities/openalias_record.dart';
|
||||||
import 'package:cake_wallet/entities/parsed_address.dart';
|
import 'package:cake_wallet/entities/parsed_address.dart';
|
||||||
import 'package:cake_wallet/entities/unstoppable_domain_address.dart';
|
import 'package:cake_wallet/entities/unstoppable_domain_address.dart';
|
||||||
import 'package:cake_wallet/store/yat/yat_store.dart';
|
import 'package:cake_wallet/store/yat/yat_store.dart';
|
||||||
|
import 'package:cw_core/wallet_type.dart';
|
||||||
|
|
||||||
const unstoppableDomains = [
|
const unstoppableDomains = [
|
||||||
'crypto',
|
'crypto',
|
||||||
'zil',
|
'zil',
|
||||||
'x',
|
'x',
|
||||||
'coin',
|
'coin',
|
||||||
'wallet',
|
'wallet',
|
||||||
'bitcoin',
|
'bitcoin',
|
||||||
'888',
|
'888',
|
||||||
'nft',
|
'nft',
|
||||||
'dao',
|
'dao',
|
||||||
'blockchain'];
|
'blockchain'
|
||||||
|
];
|
||||||
|
|
||||||
Future<ParsedAddress> parseAddressFromDomain(
|
Future<ParsedAddress> parseAddressFromDomain(
|
||||||
String domain, String ticker) async {
|
String domain, String ticker) async {
|
||||||
|
@ -28,22 +30,18 @@ Future<ParsedAddress> parseAddressFromDomain(
|
||||||
|
|
||||||
if (addresses?.isEmpty ?? true) {
|
if (addresses?.isEmpty ?? true) {
|
||||||
return ParsedAddress(
|
return ParsedAddress(
|
||||||
addresses: [domain],
|
addresses: [domain], parseFrom: ParseFrom.yatRecord);
|
||||||
parseFrom: ParseFrom.yatRecord);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ParsedAddress(
|
return ParsedAddress(
|
||||||
addresses: addresses,
|
addresses: addresses, name: domain, parseFrom: ParseFrom.yatRecord);
|
||||||
name: domain,
|
|
||||||
parseFrom: ParseFrom.yatRecord);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return ParsedAddress(addresses: [domain]);
|
return ParsedAddress(addresses: [domain]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unstoppableDomains.any((domain) => name.contains(domain))) {
|
if (unstoppableDomains.any((domain) => name.contains(domain))) {
|
||||||
final address =
|
final address = await fetchUnstoppableDomainAddress(domain, ticker);
|
||||||
await fetchUnstoppableDomainAddress(domain, ticker);
|
|
||||||
|
|
||||||
if (address?.isEmpty ?? true) {
|
if (address?.isEmpty ?? true) {
|
||||||
return ParsedAddress(addresses: [domain]);
|
return ParsedAddress(addresses: [domain]);
|
||||||
|
@ -55,7 +53,8 @@ Future<ParsedAddress> parseAddressFromDomain(
|
||||||
parseFrom: ParseFrom.unstoppableDomains);
|
parseFrom: ParseFrom.unstoppableDomains);
|
||||||
}
|
}
|
||||||
|
|
||||||
final record = await OpenaliasRecord.fetchAddressAndName(formattedName);
|
final record = await OpenaliasRecord.fetchAddressAndName(
|
||||||
|
formattedName: formattedName, ticker: ticker);
|
||||||
|
|
||||||
if (record == null || record.address.contains(formattedName)) {
|
if (record == null || record.address.contains(formattedName)) {
|
||||||
return ParsedAddress(addresses: [domain]);
|
return ParsedAddress(addresses: [domain]);
|
||||||
|
@ -70,4 +69,4 @@ Future<ParsedAddress> parseAddressFromDomain(
|
||||||
}
|
}
|
||||||
|
|
||||||
return ParsedAddress(addresses: [domain]);
|
return ParsedAddress(addresses: [domain]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue