Bitcoin Forum
May 05, 2024, 08:00:20 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Replicate listunspent for multi-sig outputs  (Read 961 times)
monsterer (OP)
Legendary
*
Offline Offline

Activity: 1008
Merit: 1000


View Profile
November 10, 2013, 01:20:51 PM
 #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.
1714896020
Hero Member
*
Offline Offline

Posts: 1714896020

View Profile Personal Message (Offline)

Ignore
1714896020
Reply with quote  #2

1714896020
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714896020
Hero Member
*
Offline Offline

Posts: 1714896020

View Profile Personal Message (Offline)

Ignore
1714896020
Reply with quote  #2

1714896020
Report to moderator
monsterer (OP)
Legendary
*
Offline Offline

Activity: 1008
Merit: 1000


View Profile
November 12, 2013, 01:34:45 PM
 #2

anyone?
dudeami
Full Member
***
Offline Offline

Activity: 126
Merit: 100



View Profile
November 12, 2013, 01:57:01 PM
 #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.

Put your heart on the line, it determines your fate.
BTC: 1DUDEAMiV54PFJFSe5fen3wr1e71unkaGj
monsterer (OP)
Legendary
*
Offline Offline

Activity: 1008
Merit: 1000


View Profile
November 15, 2013, 10:38:21 AM
 #4

Thanks, I appreciate your reply Smiley
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!