wallet_balance.py: Prevent edge cases
This commit is contained in:
parent
12fd4bbd1e
commit
bb41e632ca
1 changed files with 7 additions and 2 deletions
|
@ -28,12 +28,17 @@ def create_transactions(node, address, amt, fees):
|
||||||
for utxo in utxos:
|
for utxo in utxos:
|
||||||
inputs.append({"txid": utxo["txid"], "vout": utxo["vout"]})
|
inputs.append({"txid": utxo["txid"], "vout": utxo["vout"]})
|
||||||
ins_total += utxo['amount']
|
ins_total += utxo['amount']
|
||||||
if ins_total + max(fees) > amt:
|
if ins_total >= amt + max(fees):
|
||||||
break
|
break
|
||||||
|
# make sure there was enough utxos
|
||||||
|
assert ins_total >= amt + max(fees)
|
||||||
|
|
||||||
txs = []
|
txs = []
|
||||||
for fee in fees:
|
for fee in fees:
|
||||||
outputs = {address: amt, node.getrawchangeaddress(): ins_total - amt - fee}
|
outputs = {address: amt}
|
||||||
|
# prevent 0 change output
|
||||||
|
if ins_total > amt + fee:
|
||||||
|
outputs[node.getrawchangeaddress()] = ins_total - amt - fee
|
||||||
raw_tx = node.createrawtransaction(inputs, outputs, 0, True)
|
raw_tx = node.createrawtransaction(inputs, outputs, 0, True)
|
||||||
raw_tx = node.signrawtransactionwithwallet(raw_tx)
|
raw_tx = node.signrawtransactionwithwallet(raw_tx)
|
||||||
assert_equal(raw_tx['complete'], True)
|
assert_equal(raw_tx['complete'], True)
|
||||||
|
|
Loading…
Reference in a new issue