fix #1181
This commit is contained in:
@@ -462,39 +462,45 @@ class Abstract_Wallet(object):
|
|||||||
fee = v_out - v_in
|
fee = v_out - v_in
|
||||||
return is_relevant, is_send, v, fee
|
return is_relevant, is_send, v, fee
|
||||||
|
|
||||||
def get_addr_utxo(self, address):
|
def get_addr_io(self, address):
|
||||||
h = self.history.get(address, [])
|
h = self.history.get(address, [])
|
||||||
coins = {}
|
received = {}
|
||||||
|
sent = {}
|
||||||
for tx_hash, height in h:
|
for tx_hash, height in h:
|
||||||
l = self.txo.get(tx_hash, {}).get(address, [])
|
l = self.txo.get(tx_hash, {}).get(address, [])
|
||||||
for n, v, is_cb in l:
|
for n, v, is_cb in l:
|
||||||
coins[tx_hash + ':%d'%n] = (height, v, is_cb)
|
received[tx_hash + ':%d'%n] = (height, v, is_cb)
|
||||||
for tx_hash, height in h:
|
for tx_hash, height in h:
|
||||||
l = self.txi.get(tx_hash, {}).get(address, [])
|
l = self.txi.get(tx_hash, {}).get(address, [])
|
||||||
for txi, v in l:
|
for txi, v in l:
|
||||||
coins.pop(txi)
|
sent[txi] = height
|
||||||
|
return received, sent
|
||||||
|
|
||||||
|
def get_addr_utxo(self, address):
|
||||||
|
coins, spent = self.get_addr_io(address)
|
||||||
|
for txi in spent:
|
||||||
|
coins.pop(txi)
|
||||||
return coins.items()
|
return coins.items()
|
||||||
|
|
||||||
#return the total amount ever received by an address
|
# return the total amount ever received by an address
|
||||||
def get_addr_received(self, address):
|
def get_addr_received(self, address):
|
||||||
h = self.history.get(address, [])
|
received, sent = self.get_addr_io(address)
|
||||||
received = 0
|
return sum([v for height, v, is_cb in received.values()])
|
||||||
for tx_hash, height in h:
|
|
||||||
l = self.txo.get(tx_hash, {}).get(address, [])
|
|
||||||
for n, v, is_cb in l:
|
|
||||||
received += v
|
|
||||||
return received
|
|
||||||
|
|
||||||
|
# return the confirmed balance and pending (unconfirmed) balance change of a bitcoin address
|
||||||
def get_addr_balance(self, address):
|
def get_addr_balance(self, address):
|
||||||
"returns the confirmed balance and pending (unconfirmed) balance change of a bitcoin address"
|
received, sent = self.get_addr_io(address)
|
||||||
coins = self.get_addr_utxo(address)
|
|
||||||
c = u = 0
|
c = u = 0
|
||||||
for txo, v in coins:
|
for txo, (tx_height, v, is_cb) in received.items():
|
||||||
tx_height, v, is_cb = v
|
|
||||||
if tx_height > 0:
|
if tx_height > 0:
|
||||||
c += v
|
c += v
|
||||||
else:
|
else:
|
||||||
u += v
|
u += v
|
||||||
|
if txo in sent:
|
||||||
|
if sent[txo] > 0:
|
||||||
|
c -= v
|
||||||
|
else:
|
||||||
|
u -= v
|
||||||
return c, u
|
return c, u
|
||||||
|
|
||||||
|
|
||||||
@@ -525,17 +531,6 @@ class Abstract_Wallet(object):
|
|||||||
coins = coins[1:] + [ coins[0] ]
|
coins = coins[1:] + [ coins[0] ]
|
||||||
return [value for height, value in coins]
|
return [value for height, value in coins]
|
||||||
|
|
||||||
def get_addr_balance2(self, address):
|
|
||||||
"returns the confirmed balance and pending (unconfirmed) balance change of a bitcoin address"
|
|
||||||
coins = self.get_addr_utxo(address)
|
|
||||||
c = u = 0
|
|
||||||
for txo, v, height in coins:
|
|
||||||
if height > 0:
|
|
||||||
c += v
|
|
||||||
else:
|
|
||||||
u += v
|
|
||||||
return c, u
|
|
||||||
|
|
||||||
def get_account_name(self, k):
|
def get_account_name(self, k):
|
||||||
return self.labels.get(k, self.accounts[k].get_name(k))
|
return self.labels.get(k, self.accounts[k].get_name(k))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user