def get_owned_ids(self, owner): """Retrieve a list of `txid`s that can be used as inputs. Args: owner (str): base58 encoded public key. Returns: :obj:`list` of TransactionLink: list of `txid`s and `cid`s pointing to another transaction's condition """ # get all transactions in which owner is in the `owners_after` list response = self.connection.run( r.table('bigchain', read_mode=self.read_mode).concat_map( lambda doc: doc['block']['transactions']).filter( lambda tx: tx['transaction']['conditions'].contains( lambda c: c['owners_after'].contains(owner)))) owned = [] for tx in response: # disregard transactions from invalid blocks validity = self.get_blocks_status_containing_tx(tx['id']) if Bigchain.BLOCK_VALID not in validity.values(): if Bigchain.BLOCK_UNDECIDED not in validity.values(): continue # NOTE: It's OK to not serialize the transaction here, as we do not # use it after the execution of this function. # 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 index, cond in enumerate(tx['transaction']['conditions']): # for simple signature conditions there are no subfulfillments # check if the owner is in the condition `owners_after` if len(cond['owners_after']) == 1: if cond['condition']['details']['public_key'] == owner: tx_link = TransactionLink(tx['id'], index) else: # for transactions with multiple `owners_after` there will be several subfulfillments nested # in the condition. We need to iterate the subfulfillments to make sure there is a # subfulfillment for `owner` if util.condition_details_has_owner( cond['condition']['details'], owner): tx_link = TransactionLink(tx['id'], index) # check if input was already spent if not self.get_spent(tx_link.txid, tx_link.cid): owned.append(tx_link) return owned
def get_owned_ids(self, owner): """Retrieve a list of `txids` that can we used has inputs. Args: owner (str): base58 encoded public key. Returns: 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'] .contains(lambda c: c['new_owners'] .contains(owner))) \ .run(self.conn) owned = [] for tx in response: # disregard transactions from invalid blocks validity = self.get_blocks_status_containing_tx(tx['id']) if Bigchain.BLOCK_VALID not in validity.values(): if Bigchain.BLOCK_UNDECIDED not in validity.values(): continue # 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` if util.condition_details_has_owner( condition['condition']['details'], owner): tx_input = {'txid': tx['id'], 'cid': condition['cid']} # check if input was already spent if not self.get_spent(tx_input): owned.append(tx_input) return owned
def get_owned_ids(self, owner): """Retrieve a list of `txids` that can we used has inputs. Args: owner (str): base58 encoded public key. Returns: 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'] .contains(lambda c: c['new_owners'] .contains(owner))) \ .run(self.conn) owned = [] for tx in response: # disregard transactions from invalid blocks validity = self.get_blocks_status_containing_tx(tx['id']) if Bigchain.BLOCK_VALID not in validity.values(): if Bigchain.BLOCK_UNDECIDED not in validity.values(): continue # 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` if util.condition_details_has_owner(condition['condition']['details'], owner): tx_input = {'txid': tx['id'], 'cid': condition['cid']} # check if input was already spent if not self.get_spent(tx_input): owned.append(tx_input) return owned
def get_owned_ids(self, owner): """Retrieve a list of ``txid`` s that can be used as inputs. Args: owner (str): base58 encoded public key. Returns: :obj:`list` of TransactionLink: list of ``txid`` s and ``cid`` s pointing to another transaction's condition """ # get all transactions in which owner is in the `owners_after` list response = backend.query.get_owned_ids(self.connection, owner) owned = [] for tx in response: # disregard transactions from invalid blocks validity = self.get_blocks_status_containing_tx(tx['id']) if Bigchain.BLOCK_VALID not in validity.values(): if Bigchain.BLOCK_UNDECIDED not in validity.values(): continue # NOTE: It's OK to not serialize the transaction here, as we do not # use it after the execution of this function. # 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 index, cond in enumerate(tx['conditions']): # for simple signature conditions there are no subfulfillments # check if the owner is in the condition `owners_after` if len(cond['owners_after']) == 1: if cond['condition']['details']['public_key'] == owner: tx_link = TransactionLink(tx['id'], index) else: # for transactions with multiple `owners_after` there will be several subfulfillments nested # in the condition. We need to iterate the subfulfillments to make sure there is a # subfulfillment for `owner` if util.condition_details_has_owner(cond['condition']['details'], owner): tx_link = TransactionLink(tx['id'], index) # check if input was already spent if not self.get_spent(tx_link.txid, tx_link.cid): owned.append(tx_link) return owned