mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 17:01:34 +00:00
use contacts in command line
This commit is contained in:
parent
5cd3bfedb6
commit
ee5f499fc1
3 changed files with 35 additions and 43 deletions
|
@ -118,7 +118,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
self.app = gui_object.app
|
self.app = gui_object.app
|
||||||
|
|
||||||
self.invoices = InvoiceStore(self.config)
|
self.invoices = InvoiceStore(self.config)
|
||||||
self.contacts = StoreDict(self.config, 'contacts')
|
self.contacts = util.Contacts(self.config)
|
||||||
|
|
||||||
self.create_status_bar()
|
self.create_status_bar()
|
||||||
self.need_update = threading.Event()
|
self.need_update = threading.Event()
|
||||||
|
|
|
@ -23,9 +23,9 @@ import copy
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
import util
|
||||||
from util import print_msg, format_satoshis, print_stderr
|
from util import print_msg, format_satoshis, print_stderr
|
||||||
from util import StoreDict
|
from bitcoin import is_address, hash_160_to_bc_address, hash_160
|
||||||
from bitcoin import is_valid, hash_160_to_bc_address, hash_160
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import bitcoin
|
import bitcoin
|
||||||
from transaction import Transaction
|
from transaction import Transaction
|
||||||
|
@ -153,10 +153,11 @@ arg_types = {
|
||||||
'num':int,
|
'num':int,
|
||||||
'nbits':int,
|
'nbits':int,
|
||||||
'entropy':long,
|
'entropy':long,
|
||||||
'pubkeys':json.loads,
|
'pubkeys': json.loads,
|
||||||
'inputs': json.loads,
|
'inputs': json.loads,
|
||||||
'outputs':json.loads,
|
'outputs': json.loads,
|
||||||
'tx_fee':lambda x: (Decimal(x) if x is not None else None)
|
'tx_fee': lambda x: Decimal(x) if x is not None else None,
|
||||||
|
'amount': lambda x: Decimal(x) if x!='!' else '!',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -252,6 +253,7 @@ class Commands:
|
||||||
self.network = network
|
self.network = network
|
||||||
self._callback = callback
|
self._callback = callback
|
||||||
self.password = None
|
self.password = None
|
||||||
|
self.contacts = util.Contacts(self.config)
|
||||||
|
|
||||||
def _run(self, method, args, password_getter):
|
def _run(self, method, args, password_getter):
|
||||||
cmd = known_commands[method]
|
cmd = known_commands[method]
|
||||||
|
@ -351,7 +353,7 @@ class Commands:
|
||||||
return [self.wallet.get_private_key(address, self.password) for address in addresses]
|
return [self.wallet.get_private_key(address, self.password) for address in addresses]
|
||||||
|
|
||||||
def validateaddress(self, addr):
|
def validateaddress(self, addr):
|
||||||
isvalid = is_valid(addr)
|
isvalid = is_address(addr)
|
||||||
out = { 'isvalid':isvalid }
|
out = { 'isvalid':isvalid }
|
||||||
if isvalid:
|
if isvalid:
|
||||||
out['address'] = addr
|
out['address'] = addr
|
||||||
|
@ -425,37 +427,13 @@ class Commands:
|
||||||
return bitcoin.verify_message(address, signature, message)
|
return bitcoin.verify_message(address, signature, message)
|
||||||
|
|
||||||
def _mktx(self, outputs, fee=None, change_addr=None, domain=None):
|
def _mktx(self, outputs, fee=None, change_addr=None, domain=None):
|
||||||
for to_address, amount in outputs:
|
change_addr = None if change_addr is None else self.contacts.resolve(change_addr)
|
||||||
if not is_valid(to_address):
|
domain = None if domain is None else map(self.contacts.resolve, domain)
|
||||||
raise Exception("Invalid Bitcoin address", to_address)
|
fee = None if fee is None else int(100000000*Decimal(fee))
|
||||||
|
|
||||||
if change_addr:
|
|
||||||
if not is_valid(change_addr):
|
|
||||||
raise Exception("Invalid Bitcoin address", change_addr)
|
|
||||||
|
|
||||||
if domain is not None:
|
|
||||||
for addr in domain:
|
|
||||||
if not is_valid(addr):
|
|
||||||
raise Exception("invalid Bitcoin address", addr)
|
|
||||||
|
|
||||||
if not self.wallet.is_mine(addr):
|
|
||||||
raise Exception("address not in wallet", addr)
|
|
||||||
|
|
||||||
for k, v in self.wallet.labels.items():
|
|
||||||
if change_addr and v == change_addr:
|
|
||||||
change_addr = k
|
|
||||||
|
|
||||||
if fee is not None:
|
|
||||||
fee = int(100000000*fee)
|
|
||||||
|
|
||||||
final_outputs = []
|
final_outputs = []
|
||||||
for to_address, amount in outputs:
|
for address, amount in outputs:
|
||||||
for k, v in self.wallet.labels.items():
|
address = self.contacts.resolve(address)
|
||||||
if v == to_address:
|
#assert self.wallet.is_mine(address)
|
||||||
to_address = k
|
|
||||||
print_msg("alias", to_address)
|
|
||||||
break
|
|
||||||
|
|
||||||
if amount == '!':
|
if amount == '!':
|
||||||
assert len(outputs) == 1
|
assert len(outputs) == 1
|
||||||
inputs = self.wallet.get_spendable_coins(domain)
|
inputs = self.wallet.get_spendable_coins(domain)
|
||||||
|
@ -468,8 +446,8 @@ class Commands:
|
||||||
fee = self.wallet.estimated_fee(dummy_tx)
|
fee = self.wallet.estimated_fee(dummy_tx)
|
||||||
amount -= fee
|
amount -= fee
|
||||||
else:
|
else:
|
||||||
amount = int(100000000*amount)
|
amount = int(100000000*Decimal(amount))
|
||||||
final_outputs.append(('address', to_address, amount))
|
final_outputs.append(('address', address, amount))
|
||||||
|
|
||||||
return self.wallet.mktx(final_outputs, self.password, fee, change_addr, domain)
|
return self.wallet.mktx(final_outputs, self.password, fee, change_addr, domain)
|
||||||
|
|
||||||
|
@ -528,13 +506,11 @@ class Commands:
|
||||||
self.wallet.set_label(key, label)
|
self.wallet.set_label(key, label)
|
||||||
|
|
||||||
def listcontacts(self):
|
def listcontacts(self):
|
||||||
contacts = StoreDict(self.config, 'contacts')
|
return self.contacts
|
||||||
return contacts
|
|
||||||
|
|
||||||
def searchcontacts(self, query):
|
def searchcontacts(self, query):
|
||||||
contacts = StoreDict(self.config, 'contacts')
|
|
||||||
results = {}
|
results = {}
|
||||||
for key, value in contacts.items():
|
for key, value in self.contacts.items():
|
||||||
if query.lower() in key.lower():
|
if query.lower() in key.lower():
|
||||||
results[key] = value
|
results[key] = value
|
||||||
return results
|
return results
|
||||||
|
|
16
lib/util.py
16
lib/util.py
|
@ -461,3 +461,19 @@ class StoreDict(dict):
|
||||||
if key in self.keys():
|
if key in self.keys():
|
||||||
dict.pop(self, key)
|
dict.pop(self, key)
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
|
||||||
|
import bitcoin
|
||||||
|
|
||||||
|
class Contacts(StoreDict):
|
||||||
|
def __init__(self, config):
|
||||||
|
StoreDict.__init__(self, config, 'contacts')
|
||||||
|
|
||||||
|
def resolve(self, k):
|
||||||
|
if bitcoin.is_address(k):
|
||||||
|
return k
|
||||||
|
if k in self.keys():
|
||||||
|
_type, addr = self[k]
|
||||||
|
return addr
|
||||||
|
raise Exception("invalid Bitcoin address", k)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue