kaspanet/rusty-kaspa

Support determining return addresses for a given UTXO

Opened this issue · 1 comments

Given a new UTXO, support a way to determine the UTXOs that were spent in order to create that UTXO. This is relevant for instance for determining return addresses for a UTXO.

Scenario

  • A client follows the utxo-change events on a specific address he is interested in tracking payments to
  • A utxo arrives (as a result of a newly accepted transaction), the client wants to know what is the sending address

Challenge

The utxo outpoint id can be used to get the recent tx which created it (pending txindex pr #401), but that tx only holds the outpoints of the utxos it spent (which do not include the script-public-key/address info). The full utxo was recently known by the node, but this info seems supposedly lost. Note that the original tx might be old and thus pruned.

Solution

In order to be able to reorg the virtual chain, the node saves a full utxo diff from each chain block to its selected parent block. This means that daa score of the new utxo entry can be used to binary search chain blocks in that area and find the spent utxos contained in their persisted utxo diff structure

As discussed with @aspect this needs to return only a single return address - the first one in the inputs. So response can just be Option<Address>