Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: monsterer on November 10, 2013, 01:20:51 PM



Title: Replicate listunspent for multi-sig outputs
Post by: monsterer on November 10, 2013, 01:20:51 PM
Hi guys,

Can you confirm if this method is valid to replicate the functionality of bitcoind's listunspent command (use case is multi-sig address outputs):

Assumption: unspent outputs are transaction outputs which do not appear as transaction inputs.

* getblock
{
   iterate through all txs
   {
      * getrawtransaction
      {
          add each output to a set (index txid + N) named txouts
          add each input to a set (index txid + vout) named txins
      }
   }
}

iterate through all txouts
{
   if txout is not in set txins, add to new set unspent
}

unspent should be the set of all unspent outputs?

Cheers, Paul.


Title: Re: Replicate listunspent for multi-sig outputs
Post by: monsterer on November 12, 2013, 01:34:45 PM
anyone?


Title: Re: Replicate listunspent for multi-sig outputs
Post by: dudeami on November 12, 2013, 01:57:01 PM
If you go through the whole blockchain and record every transaction as you plan, you'll probably run into some sort of memory issue. You do have the right approach, though something like this would save you some memory (using JS in a psuedocode kinda way :p):

Code:
var utxos = {}; // Make an object/list

getblock {
    foreach block.tx {
        getrawtransaction {
            foreach tx.vin {
                if (utxos[vin.txid+':'+vin.vout])
                    unset utxos[vin.txid+':'+vin.vout];
            }
            foreach tx.vout {
                utxos[tx.txid+':'+vout.n] = vout; // Note that the vout object does NOT contain the TX ID
            }
        }
    }
}

So basically, you are only storing the transactions that are unspent. Note this approach may be inaccurate due to doublespends and the like.


Title: Re: Replicate listunspent for multi-sig outputs
Post by: monsterer on November 15, 2013, 10:38:21 AM
Thanks, I appreciate your reply :)