4

I find myself a victim of either my poor googling skills, or the lack of detail in the bitcoind docs.

I have a walletNotify script running on a full node that whenever a transaction to / from my wallet arrives, performs a getRawTransaction(txid, 1) on the passed transaction ID.

Now, if any of my addresses appears inside the vout array, I know that that transaction is a deposit. What I'd like to verify, is that I can indeed spend those bitcoins.

I read about non-standard transactions (specifically, unspendable transactions) and kinda panicked, so my questions are:

  1. Does bitcoind perform any sort of verification on the "spendability" of the arriving bitcoins?
  2. Is there any easy way of verifying this myself? is there any not-necessarily-easy way?

Thank you very much in advance!

2 Answers 2

1

Bitcoind only scrapes the blockchain for a few transaction types: Pay-to-pubkey, pay-to-pubkey-hash, and pay-to-script-hash. If you check https://en.bitcoin.it/wiki/Script you'll see many more script operators that can be used, so the protocol isn't just those three script types.

Since the scripts have a very definite form, your client will look for the cases where the payments are to address YOU own instead of others.

OP_DUP OP_HASH160 <20 byte hash> OP_EQUALVERIFY OP_CHECKSIG

If bitcoins were sent to this script but with other script operations at the end, your node wouldn't report them as spendable.

  1. Verifying this yourself is easy if you already have a working and completely correct script interpreter. You could look for non-standard outputs, since they do get mined on occasion.

However, reproducing bitcoind's script interpreter, with bug-for-bug compatibility is tricky. Certain clients have been forked from the blockchain by not following every quirk in the reference implementation.

But if you have this, you could write your own node if you liked. Listen for new blocks from the network, or just from bitcoind. Use your script interpreter to ensure that transactions in new blocks are valid, are correctly signed, and so on. Once you're confident the blockchain you end up with is correct, you can parse for the cases that bitcoind ignores and spend them if you can.

2
  • Hi! sorry for the delay. So what you mean is that I won't even get notified when one such nonstandard transaction arrives? or that they won't appear among my UTXOs? Having a working (bug-for-bug) script interpreter is not even not-necessarily-easy :P
    – mpr
    Commented Dec 15, 2014 at 20:04
  • No, your node wouldn't be able to identify it as having anything to do with your wallet. Depending on your use case, maybe you could use txindex=1, and the blocknotify callback? It would trigger a script, passing the block hash as an argument. Decode every raw transaction (why you need txindex), look for outputs whose scripts match what you want, and build your redeem transaction then?
    – karimkorun
    Commented Dec 17, 2014 at 2:03
0

Don't worry about unspendable outputs too much, those are mainly a way to store a little bit of extra data in the blockchain, or to destroy bitcoins. If someone sent you a transaction that had one unspendable TX output, that wouldn't be bad, as long as the actual coins it was sending took place in the other TX outputs.

  1. Does bitcoind perform any sort of verification on the "spendability" of the arriving bitcoins?

Yes, it needs to in order to determine your wallet balance. For example, if I send to a 2 of 3 multisig address that I only have one of the keys for, the bitcoind client will not register that into your balance, but if I have 2 out of the 3 addresses then it will include transactions to that address in my balance.

  1. Is there any easy way of verifying this myself? is there any not-necessarily-easy way?

There is an easy way! If your balance changes, then you received coins. If you're trying to do a watch-only address, where you're trying to look for changes to an 'address balance' (for lack of a better term) of an address that you don't have the private key for, then then you might try getting the scriptPubKeys hex, which should match exactly with the scriptPubKey you expect.

9
  • Thanks for answering! But I'm interested in knowing what would happen if someone would send me, say, 1BTC with a script such that I may never spend such a coin... does bitcoind process the script in order to update the balance? any script whatsoever? even nonstandard ones? (multisig scripts are kinda-standard-scripts in this respect)
    – mpr
    Commented Oct 28, 2014 at 1:15
  • Well, it does make sure it can spend them so that it can add them to your balance, but it only knows how to spend standard transactions. What kind of a transaction are you thinking of that would credit your address but not be a standard transaction?
    – morsecoder
    Commented Oct 28, 2014 at 1:17
  • Well, either of: en.bitcoin.it/wiki/…, en.bitcoin.it/wiki/Script#Anyone-Can-Spend_Outputs, or en.bitcoin.it/wiki/Script#Transaction_puzzle would be problematic :P Now, I'm not saying someone will merrily throw their coins away just to try to annoy me, but it's better to be safe than sorry :)
    – mpr
    Commented Oct 28, 2014 at 1:57
  • Agreed, better safe than sorry. Those are not standard transaction, so they won't register to your balance. I think your solution is to just see when your balance changes.
    – morsecoder
    Commented Oct 28, 2014 at 2:34
  • Hmm, what if I have many transactions at the same time? Checking for balance changes sounds like it could mistakenly mark a transaction a received when many are happening concurrently.
    – mpr
    Commented Oct 28, 2014 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.