better coments for the get_owned_ids method

This commit is contained in:
Rodolphe Marques 2016-04-26 14:58:36 +02:00
parent 665fea7107
commit 131acb8cb7

View File

@ -221,6 +221,7 @@ class Bigchain(object):
list: list of `txids` currently owned by `owner`
"""
# get all transactions in which owner is in the `new_owners` list
response = r.table('bigchain') \
.concat_map(lambda doc: doc['block']['transactions']) \
.filter(lambda tx: tx['transaction']['conditions']
@ -230,11 +231,18 @@ class Bigchain(object):
owned = []
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 simple signature conditions there are no subfulfillments
# check if the owner is in the condition `new_owners`
if len(condition['new_owners']) == 1:
if condition['condition']['details']['public_key'] == owner:
tx_input = {'txid': tx['id'], 'cid': condition['cid']}
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']:
if subfulfillment['public_key'] == owner:
tx_input = {'txid': tx['id'], 'cid': condition['cid']}