Author

Topic: Replicate listunspent for multi-sig outputs (Read 998 times)

legendary
Activity: 1008
Merit: 1007
November 15, 2013, 05:38:21 AM
#4
Thanks, I appreciate your reply Smiley
full member
Activity: 126
Merit: 100
November 12, 2013, 08:57:01 AM
#3
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.
legendary
Activity: 1008
Merit: 1007
November 12, 2013, 08:34:45 AM
#2
anyone?
legendary
Activity: 1008
Merit: 1007
November 10, 2013, 08:20:51 AM
#1
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.
Jump to: