Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions bitgo/bitgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from pycoin.tx import Spendable

from pycoin.tx.pay_to.ScriptMultisig import ScriptMultisig
from pycoin.tx.pay_to import SolvingError
from pycoin.tx.exceptions import SolvingError
from pycoin.tx.script import tools
from pycoin.tx.script.check_signature import parse_signature_blob
from pycoin import ecdsa
Expand Down Expand Up @@ -291,6 +291,7 @@ def send(self, wallet_id, passcode, address, amount, message='', fee=None, fan_u
"""
MINIMAL_FEE = 20000
MINIMAL_SPLIT = 10000000
MIN_UNSPENTS_FAN = 5

wallet = self.get_wallet(wallet_id)
if not wallet['spendingAccount']:
Expand Down Expand Up @@ -333,9 +334,11 @@ def send(self, wallet_id, passcode, address, amount, message='', fee=None, fan_u
cipher = sjcl.SJCL()
xprv = cipher.decrypt(data, passcode)

unspents = self.get_unspents(wallet_id)
unspents = self.get_unspents(wallet_id)['unspents']
order_unspents = sorted(unspents, key=lambda k: k['confirmations'], reverse=True)

total_value = 0
for d in unspents['unspents'][::-1]:
for d in order_unspents:
path = keychain_path + d['chainPath']
chain_paths.append(path)
p2sh.append(h2b(d["redeemScript"]))
Expand All @@ -349,7 +352,7 @@ def send(self, wallet_id, passcode, address, amount, message='', fee=None, fan_u
break

# make many outputs?
if len(unspents['unspents']) < 5 and (total_value > (amount + MINIMAL_SPLIT)) and fan_unspend > 0:
if len(order_unspents) < MIN_UNSPENTS_FAN and (total_value > (amount + MINIMAL_SPLIT)) and fan_unspend > 0:
fee = self.calculate_fee(len(spendables), fan_unspend)
value = (total_value - amount - fee) / fan_unspend
for i in range(fan_unspend):
Expand Down