From bf2cc89991bd9111cee6299add68b5ce027b6f6b Mon Sep 17 00:00:00 2001 From: Rodolphe Marques Date: Fri, 8 Apr 2016 14:41:20 +0200 Subject: [PATCH] Updated get owned ids to also return the cid. --- bigchaindb/core.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/bigchaindb/core.py b/bigchaindb/core.py index 413489b5..94679bc0 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -228,17 +228,22 @@ class Bigchain(object): list: list of `txids` currently owned by `owner` """ - response = r.table('bigchain')\ - .concat_map(lambda doc: doc['block']['transactions'])\ - .filter({'transaction': {'new_owner': owner}})\ - .pluck('id')['id']\ - .run(self.conn) + response = r.table('bigchain') \ + .concat_map(lambda doc: doc['block']['transactions']) \ + .filter(lambda tx: tx['transaction']['conditions'] + .contains(lambda c: c['new_owners'] + .contains(owner))) \ + .run(self.conn) owned = [] - # remove all inputs already spent - for tx_input in list(response): - if not self.get_spent(tx_input): - owned.append(tx_input) + for tx in response: + tx_input = {'txid': tx['id']} + for condition in tx['transaction']['conditions']: + if owner in condition['new_owners']: + tx_input.update({'cid': condition['cid']}) + # check if input was already spent + if not self.get_spent(tx_input): + owned.append(tx_input) return owned