in resdb_driver/transaction.py [0:0]
def get_asset_id(transactions):
"""! Get the asset id from a list of :class:`~.Transactions`.
This is useful when we want to check if the multiple inputs of a
transaction are related to the same asset id.
Args:
@param transactions (:obj:`list` of :class:`~resdb.transaction.Transaction`):
A list of Transactions.
Usually input Transactions that should have a matching
asset ID.
@return ID of the asset.
@exception If the inputs are related to different assets.
"""
if not isinstance(transactions, list):
transactions = [transactions]
# create a set of the transactions' asset ids
asset_ids = {
tx.id if tx.operation == Transaction.CREATE else tx.asset["id"]
for tx in transactions
}
# check that all the transasctions have the same asset id
if len(asset_ids) > 1:
raise AssetIdMismatch(
(
"All inputs of all transactions passed"
" need to have the same asset id"
)
)
return asset_ids.pop()