payment_identifiers: also match local contacts
This commit is contained in:
@@ -101,6 +101,17 @@ class Contacts(dict, Logger):
|
|||||||
}
|
}
|
||||||
raise AliasNotFoundException("Invalid Bitcoin address or alias", k)
|
raise AliasNotFoundException("Invalid Bitcoin address or alias", k)
|
||||||
|
|
||||||
|
def by_name(self, name):
|
||||||
|
for k in self.keys():
|
||||||
|
_type, addr = self[k]
|
||||||
|
if addr.casefold() == name.casefold():
|
||||||
|
return {
|
||||||
|
'name': addr,
|
||||||
|
'type': _type,
|
||||||
|
'address': k
|
||||||
|
}
|
||||||
|
return None
|
||||||
|
|
||||||
def fetch_openalias(self, config):
|
def fetch_openalias(self, config):
|
||||||
self.alias_info = None
|
self.alias_info = None
|
||||||
alias = config.OPENALIAS_ID
|
alias = config.OPENALIAS_ID
|
||||||
|
|||||||
@@ -380,6 +380,18 @@ class PaymentIdentifier(Logger):
|
|||||||
self._type = PaymentIdentifierType.SPK
|
self._type = PaymentIdentifierType.SPK
|
||||||
self.spk = scriptpubkey
|
self.spk = scriptpubkey
|
||||||
self.set_state(PaymentIdentifierState.AVAILABLE)
|
self.set_state(PaymentIdentifierState.AVAILABLE)
|
||||||
|
elif contact := self.contacts.by_name(text):
|
||||||
|
if contact['type'] == 'address':
|
||||||
|
self._type = PaymentIdentifierType.BIP21
|
||||||
|
self.bip21 = {
|
||||||
|
'address': contact['address'],
|
||||||
|
'label': contact['name']
|
||||||
|
}
|
||||||
|
self.set_state(PaymentIdentifierState.AVAILABLE)
|
||||||
|
elif contact['type'] == 'openalias':
|
||||||
|
self._type = PaymentIdentifierType.EMAILLIKE
|
||||||
|
self.emaillike = contact['address']
|
||||||
|
self.set_state(PaymentIdentifierState.NEED_RESOLVE)
|
||||||
elif re.match(RE_EMAIL, text):
|
elif re.match(RE_EMAIL, text):
|
||||||
self._type = PaymentIdentifierType.EMAILLIKE
|
self._type = PaymentIdentifierType.EMAILLIKE
|
||||||
self.emaillike = text
|
self.emaillike = text
|
||||||
@@ -681,13 +693,14 @@ class PaymentIdentifier(Logger):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
elif self.bip21:
|
elif self.bip21:
|
||||||
recipient = self.bip21.get('address')
|
|
||||||
amount = self.bip21.get('amount')
|
|
||||||
label = self.bip21.get('label')
|
label = self.bip21.get('label')
|
||||||
|
address = self.bip21.get('address')
|
||||||
|
recipient = f'{label} <{address}>' if label else address
|
||||||
|
amount = self.bip21.get('amount')
|
||||||
description = self.bip21.get('message')
|
description = self.bip21.get('message')
|
||||||
# use label as description (not BIP21 compliant)
|
# TODO: use label as description? (not BIP21 compliant)
|
||||||
if label and not description:
|
# if label and not description:
|
||||||
description = label
|
# description = label
|
||||||
|
|
||||||
return FieldsForGUI(recipient=recipient, amount=amount, description=description,
|
return FieldsForGUI(recipient=recipient, amount=amount, description=description,
|
||||||
comment=comment, validated=validated, amount_range=amount_range)
|
comment=comment, validated=validated, amount_range=amount_range)
|
||||||
|
|||||||
Reference in New Issue
Block a user