mirror of
https://github.com/planetmint/planetmint.git
synced 2025-03-30 15:08:31 +00:00
added get_outputs_by_owner query and adjusted dataaccessor
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
826c803798
commit
9cf743f42c
@ -447,6 +447,11 @@ def get_outputs_by_tx_id(connection, tx_id: str) -> list[Output]:
|
||||
"""Retrieve outputs for a transaction by its id"""
|
||||
raise NotImplementedError
|
||||
|
||||
@singledispatch
|
||||
def get_outputs_by_owner(connection, public_key: str, table: str) -> list[Output]:
|
||||
"""Retrieve an owners outputs by public key"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_metadata(conn, transaction_ids):
|
||||
|
@ -193,7 +193,7 @@ function init()
|
||||
{ field = 'output_index', type = 'unsigned' }
|
||||
}
|
||||
})
|
||||
utxos:create_index('utxo_by_public_keys', {
|
||||
utxos:create_index('public_keys', {
|
||||
if_not_exists = true,
|
||||
unique = false,
|
||||
parts = {{field = 'public_keys[*]', type = 'string' }}
|
||||
|
@ -507,3 +507,10 @@ def get_latest_abci_chain(connection) -> Union[dict, None]:
|
||||
return None
|
||||
_chain = sorted(_all_chains, key=itemgetter(1), reverse=True)[0]
|
||||
return {"chain_id": _chain[0], "height": _chain[1], "is_synced": _chain[2]}
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
@catch_db_exception
|
||||
def get_outputs_by_owner(connection, public_key: str, table=TARANT_TABLE_OUTPUT) -> list[Output]:
|
||||
outputs = connection.connect().select(table, public_key, index="public_keys")
|
||||
return [Output.from_tuple(output) for output in outputs]
|
@ -80,14 +80,18 @@ class DataAccessor:
|
||||
:obj:`list` of TransactionLink: list of ``txid`` s and ``output`` s
|
||||
pointing to another transaction's condition
|
||||
"""
|
||||
# TODO: adjust for new utxo handling, query and return outputs based on spent
|
||||
outputs = self.fastquery.get_outputs_by_public_key(owner)
|
||||
outputs = backend.query.get_outputs_by_owner(self.connection, owner)
|
||||
unspent_outputs = backend.query.get_outputs_by_owner(self.connection, owner, TARANT_TABLE_UTXOS)
|
||||
if spent is None:
|
||||
return outputs
|
||||
elif spent is True:
|
||||
return self.fastquery.filter_unspent_outputs(outputs)
|
||||
spent_outputs = []
|
||||
for output in outputs:
|
||||
if not any(utxo.transaction_id == output.transaction_id and utxo.index == output.index for utxo in unspent_outputs):
|
||||
spent_outputs.append(output)
|
||||
return unspent_outputs
|
||||
elif spent is False:
|
||||
return self.fastquery.filter_spent_outputs(outputs)
|
||||
return unspent_outputs
|
||||
|
||||
def store_block(self, block):
|
||||
"""Create a new block."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user