CardanoSolutions / ogmios

❇️ A WebSocket JSON/RPC bridge for Cardano
https://ogmios.dev
Mozilla Public License 2.0
304 stars 90 forks source link

Add address & value to the inputs #223

Closed Hathoriel closed 2 years ago

Hathoriel commented 2 years ago

Describe your idea, in simple words.

Add address and value fields to the inputs

Right now we have this interface in the Cardano Ogmios chain sync client

export interface TxIn {
    txId: TxId;
    index: number;
}

I would like to add the address and value:

export interface TxIn {
    txId: TxId;
    index: number;
    address: string;
    value: number;
}

I don't insist on these exact types, but you know my point.

Why is it a good idea?

I need more information about transactions. Right now I don't have these values and if I need to get these details I need to connect to the GraphQL interface, which adds an unnecessary dependency to the system.

Are you willing to work on it yourself?

If it were a simple change I would do it.

KtorZ commented 2 years ago

Hi there!

This is generally not possible because of how the UTxO graph is constructed. Ogmios itself doesn't not store any data; it derives everything from the cardano-node and merely provide a more friendly interface to low-level interfaces offered by the node. The node itself also does not maintain historical data on UTxO. Indeed, as transaction outputs are consumed, they are removed from the UTxO set.

Therefore, it isn't generally possible to resolve the address and value corresponding to any transaction input; and certainly not on historical data. If you're using the chain-sync protocol then it is likely that you would want your application to also keep track of the past seen outputs to allow performing a lookup later on.

Having said that, know that you can query any UTxO by TxIn via the state-query protocol though, this only works for UTxO (that is, previous outputs that haven't been spent yet).

If you need to access historical data, then you will need to query a chain-index; either by constructing the index yourself, or by using some existing tool / service that does this. For example: kupo or scrolls are likely what you're looking for (they are more lightweight alternative to db-sync / graphql).