Skip to content

Commit

Permalink
Merge 9f3c5c6 into 0479f34
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNaif2018 committed Sep 19, 2020
2 parents 0479f34 + 9f3c5c6 commit 52ab4a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def verifymessage(self, address, signature, message):
return bitcoin.verify_message(address, sig, message)

def _mktx(self, outputs, fee=None, change_addr=None, domain=None, nocheck=False,
unsigned=False, password=None, locktime=None, op_return=None, op_return_raw=None):
unsigned=False, password=None, locktime=None, op_return=None, op_return_raw=None, addtransaction=False):
if op_return and op_return_raw:
raise ValueError('Both op_return and op_return_raw cannot be specified together!')
self.nocheck = nocheck
Expand Down Expand Up @@ -540,23 +540,27 @@ def _mktx(self, outputs, fee=None, change_addr=None, domain=None, nocheck=False,
if not unsigned:
run_hook('sign_tx', self.wallet, tx)
self.wallet.sign_transaction(tx, password)
if addtransaction:
self.wallet.add_transaction(tx.txid(), tx)
self.wallet.add_tx_to_history(tx.txid())
self.wallet.save_transactions()
return tx

@command('wp')
def payto(self, destination, amount, fee=None, from_addr=None, change_addr=None, nocheck=False, unsigned=False, password=None, locktime=None,
op_return=None, op_return_raw=None):
op_return=None, op_return_raw=None, addtransaction=False):
"""Create a transaction. """
tx_fee = satoshis(fee)
domain = from_addr.split(',') if from_addr else None
tx = self._mktx([(destination, amount)], tx_fee, change_addr, domain, nocheck, unsigned, password, locktime, op_return, op_return_raw)
tx = self._mktx([(destination, amount)], tx_fee, change_addr, domain, nocheck, unsigned, password, locktime, op_return, op_return_raw, addtransaction=addtransaction)
return tx.as_dict()

@command('wp')
def paytomany(self, outputs, fee=None, from_addr=None, change_addr=None, nocheck=False, unsigned=False, password=None, locktime=None):
def paytomany(self, outputs, fee=None, from_addr=None, change_addr=None, nocheck=False, unsigned=False, password=None, locktime=None, addtransaction=False):
"""Create a multi-output transaction. """
tx_fee = satoshis(fee)
domain = from_addr.split(',') if from_addr else None
tx = self._mktx(outputs, tx_fee, change_addr, domain, nocheck, unsigned, password, locktime)
tx = self._mktx(outputs, tx_fee, change_addr, domain, nocheck, unsigned, password, locktime, addtransaction=addtransaction)
return tx.as_dict()

@command('w')
Expand Down Expand Up @@ -844,6 +848,7 @@ def help(self):
}

command_options = {
'addtransaction': (None, 'Whether transaction is to be used for broadcasting afterwards. Adds transaction to the wallet'),
'balance': ("-b", "Show the balances of listed addresses"),
'change': (None, "Show only change addresses"),
'change_addr': ("-c", "Change address. Default is a spare address, or the source address if it's not in the wallet"),
Expand Down
9 changes: 9 additions & 0 deletions lib/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import threading
from collections import defaultdict
from functools import partial
import itertools

from .i18n import ngettext
from .util import NotEnoughFunds, ExcessiveFee, PrintError, UserCancelled, profiler, format_satoshis, format_time, finalization_print_error, to_string
Expand Down Expand Up @@ -1437,6 +1438,14 @@ def receive_history_callback(self, addr, hist, tx_fees):
if self.network:
self.network.trigger_callback('on_history', self)

def add_tx_to_history(self, txid):
with self.lock:
for addr in itertools.chain(list(self.txi.get(txid, {}).keys()), list(self.txo.get(txid, {}).keys())):
cur_hist = self._history.get(addr, list())
if not any(True for x in cur_hist if x[0] == txid):
cur_hist.append((txid, 0))
self._history[addr] = cur_hist

def get_history(self, domain=None, *, reverse=False):
# get domain
if domain is None:
Expand Down

0 comments on commit 52ab4a2

Please sign in to comment.