mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
better coments for the get_owned_ids method
This commit is contained in:
parent
665fea7107
commit
131acb8cb7
@ -221,6 +221,7 @@ class Bigchain(object):
|
|||||||
list: list of `txids` currently owned by `owner`
|
list: list of `txids` currently owned by `owner`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# get all transactions in which owner is in the `new_owners` list
|
||||||
response = r.table('bigchain') \
|
response = r.table('bigchain') \
|
||||||
.concat_map(lambda doc: doc['block']['transactions']) \
|
.concat_map(lambda doc: doc['block']['transactions']) \
|
||||||
.filter(lambda tx: tx['transaction']['conditions']
|
.filter(lambda tx: tx['transaction']['conditions']
|
||||||
@ -230,11 +231,18 @@ class Bigchain(object):
|
|||||||
owned = []
|
owned = []
|
||||||
|
|
||||||
for tx in response:
|
for tx in response:
|
||||||
|
# a transaction can contain multiple outputs (conditions) so we need to iterate over all of them
|
||||||
|
# to get a list of outputs available to spend
|
||||||
for condition in tx['transaction']['conditions']:
|
for condition in tx['transaction']['conditions']:
|
||||||
|
# for simple signature conditions there are no subfulfillments
|
||||||
|
# check if the owner is in the condition `new_owners`
|
||||||
if len(condition['new_owners']) == 1:
|
if len(condition['new_owners']) == 1:
|
||||||
if condition['condition']['details']['public_key'] == owner:
|
if condition['condition']['details']['public_key'] == owner:
|
||||||
tx_input = {'txid': tx['id'], 'cid': condition['cid']}
|
tx_input = {'txid': tx['id'], 'cid': condition['cid']}
|
||||||
else:
|
else:
|
||||||
|
# for transactions with multiple `new_owners` there will be several subfulfillments nested
|
||||||
|
# in the condition. We need to iterate the subfulfillments to make sure there is a
|
||||||
|
# subfulfillment for `owner`
|
||||||
for subfulfillment in condition['condition']['details']['subfulfillments']:
|
for subfulfillment in condition['condition']['details']['subfulfillments']:
|
||||||
if subfulfillment['public_key'] == owner:
|
if subfulfillment['public_key'] == owner:
|
||||||
tx_input = {'txid': tx['id'], 'cid': condition['cid']}
|
tx_input = {'txid': tx['id'], 'cid': condition['cid']}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user