From 0766e407fb815e87088fdc54100283085971fd60 Mon Sep 17 00:00:00 2001 From: Antonio ceraso Date: Thu, 3 Mar 2016 10:55:16 -0300 Subject: [PATCH 1/4] tweaks on unspents order --- bitgo/bitgo.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bitgo/bitgo.py b/bitgo/bitgo.py index 5db14cf..4f75a7f 100644 --- a/bitgo/bitgo.py +++ b/bitgo/bitgo.py @@ -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']: @@ -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"])) @@ -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): From 3fb76c8c1b5419c49a6badd42bafe29582e70f8c Mon Sep 17 00:00:00 2001 From: Antonio ceraso Date: Thu, 3 Mar 2016 11:15:33 -0300 Subject: [PATCH 2/4] check for lower fee --- bitgo/bitgo.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bitgo/bitgo.py b/bitgo/bitgo.py index 4f75a7f..fec7283 100644 --- a/bitgo/bitgo.py +++ b/bitgo/bitgo.py @@ -361,6 +361,8 @@ def send(self, wallet_id, passcode, address, amount, message='', fee=None, fan_u # add a change address if fee is None: fee = self.calculate_fee(len(spendables), 2) + elif fee < MINIMAL_FEE: + raise Exception("Fee to low... your fee: %s min fee allowed: %s" % (fee, MINIMAL_FEE)) value = total_value - amount - fee if value > 10000: #avoid dust payables.append((change_address, value)) From 7cca2cec1b38834189266bbdea1b24042bd673b5 Mon Sep 17 00:00:00 2001 From: Antonio ceraso Date: Wed, 15 Jun 2016 18:27:00 -0300 Subject: [PATCH 3/4] fix import --- bitgo/bitgo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitgo/bitgo.py b/bitgo/bitgo.py index fec7283..888d5f2 100644 --- a/bitgo/bitgo.py +++ b/bitgo/bitgo.py @@ -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 From 2c67691de8175c69d67557bfc28e7ed5c3c481d8 Mon Sep 17 00:00:00 2001 From: Antonio ceraso Date: Wed, 15 Jun 2016 18:36:22 -0300 Subject: [PATCH 4/4] tweaks --- bitgo/bitgo.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/bitgo/bitgo.py b/bitgo/bitgo.py index 888d5f2..ca5006e 100644 --- a/bitgo/bitgo.py +++ b/bitgo/bitgo.py @@ -361,8 +361,6 @@ def send(self, wallet_id, passcode, address, amount, message='', fee=None, fan_u # add a change address if fee is None: fee = self.calculate_fee(len(spendables), 2) - elif fee < MINIMAL_FEE: - raise Exception("Fee to low... your fee: %s min fee allowed: %s" % (fee, MINIMAL_FEE)) value = total_value - amount - fee if value > 10000: #avoid dust payables.append((change_address, value))