mirror of
https://github.com/sparrowwallet/drongo.git
synced 2025-11-05 11:56:38 +00:00
improve dns hrn support
This commit is contained in:
parent
a896809286
commit
73acc00ab6
2 changed files with 32 additions and 0 deletions
|
|
@ -4,6 +4,9 @@ import com.sparrowwallet.drongo.uri.BitcoinURI;
|
|||
import org.xbill.DNS.*;
|
||||
import org.xbill.DNS.Record;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.sparrowwallet.drongo.dns.RecordUtils.fromWire;
|
||||
|
||||
public record DnsPayment(String hrn, BitcoinURI bitcoinURI, byte[] proofChain) {
|
||||
|
|
@ -33,4 +36,23 @@ public record DnsPayment(String hrn, BitcoinURI bitcoinURI, byte[] proofChain) {
|
|||
public boolean hasSilentPaymentAddress() {
|
||||
return bitcoinURI.getSilentPaymentAddress() != null;
|
||||
}
|
||||
|
||||
public static Optional<String> getHrn(String value) {
|
||||
String hrn = value;
|
||||
if(value.endsWith(".")) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
if(hrn.startsWith("₿")) {
|
||||
hrn = hrn.substring(1);
|
||||
}
|
||||
|
||||
String[] addressParts = hrn.split("@");
|
||||
if(addressParts.length == 2 && addressParts[1].indexOf('.') > -1 && addressParts[1].substring(addressParts[1].indexOf('.') + 1).length() > 1 &&
|
||||
StandardCharsets.US_ASCII.newEncoder().canEncode(hrn)) {
|
||||
return Optional.of(hrn);
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,16 @@ public class DnsPaymentCache {
|
|||
}
|
||||
}
|
||||
|
||||
public static DnsPayment getDnsPayment(String hrn) {
|
||||
for(DnsPayment dnsPayment : dnsPayments.asMap().values()) {
|
||||
if(dnsPayment.hrn().equals(hrn)) {
|
||||
return dnsPayment;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void putDnsPayment(Address address, DnsPayment dnsPayment) {
|
||||
dnsPayments.put(new DnsAddress(address), dnsPayment);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue