fix tx.get_value()
This commit is contained in:
parent
f07591eb5b
commit
f0671a9ada
@ -805,6 +805,7 @@ class Transaction:
|
|||||||
# return the balance for that tx
|
# return the balance for that tx
|
||||||
is_send = False
|
is_send = False
|
||||||
is_pruned = False
|
is_pruned = False
|
||||||
|
is_partial = False
|
||||||
v_in = v_out = v_out_mine = 0
|
v_in = v_out = v_out_mine = 0
|
||||||
|
|
||||||
for item in self.inputs:
|
for item in self.inputs:
|
||||||
@ -818,7 +819,9 @@ class Transaction:
|
|||||||
else:
|
else:
|
||||||
v_in += value
|
v_in += value
|
||||||
else:
|
else:
|
||||||
is_pruned = True
|
is_partial = True
|
||||||
|
|
||||||
|
if not is_send: is_partial = False
|
||||||
|
|
||||||
for item in self.outputs:
|
for item in self.outputs:
|
||||||
addr, value = item
|
addr, value = item
|
||||||
@ -826,11 +829,7 @@ class Transaction:
|
|||||||
if addr in addresses:
|
if addr in addresses:
|
||||||
v_out_mine += value
|
v_out_mine += value
|
||||||
|
|
||||||
if not is_pruned:
|
if is_pruned:
|
||||||
# all inputs are mine:
|
|
||||||
fee = v_out - v_in
|
|
||||||
v = v_out_mine - v_in
|
|
||||||
else:
|
|
||||||
# some inputs are mine:
|
# some inputs are mine:
|
||||||
fee = None
|
fee = None
|
||||||
if is_send:
|
if is_send:
|
||||||
@ -838,7 +837,18 @@ class Transaction:
|
|||||||
else:
|
else:
|
||||||
# no input is mine
|
# no input is mine
|
||||||
v = v_out_mine
|
v = v_out_mine
|
||||||
|
|
||||||
|
else:
|
||||||
|
v = v_out_mine - v_in
|
||||||
|
|
||||||
|
if is_partial:
|
||||||
|
# some inputs are mine, but not all
|
||||||
|
fee = None
|
||||||
|
is_send = v < 0
|
||||||
|
else:
|
||||||
|
# all inputs are mine
|
||||||
|
fee = v_out - v_in
|
||||||
|
|
||||||
return is_send, v, fee
|
return is_send, v, fee
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user