2

I WENT through the tutorial for pybitcointools using the command line. At the last line I am to pushtx(tx3) and Yet I keep getting this error :

raise Exception(p)
Exception: An outpoint is already spent in [37275258, 92842599]

THIS is the list of commands written :

from bitcoin import * 
>>> priv = sha256('some big long brainwallet password')
>>> priv 
'57c617d9b4e1f7af6ec97ca2ff57e94a28279a7eedd4d12a99fa11170e94f5a4'
>>> pub = privtopub(priv)
>>> pub 
'0420f34c2786b4bae593e22596631b025f3ff46e200fc1d4b52ef49bbdc2ed00b26c584b7e32523fb01be2294a1f8a5eb0cf71a203cc034ced46ea92a8df16c6e9'
>>> addr = pubtoaddr(pub)
>>> addr 
'1CQLd3bhw4EzaURHbKCwM5YZbUQfA4ReY6'
>>> h = history(addr)
>>> h
[{'output': u'4cc806bb04f730c445c60b3e0f4f44b54769a1c196ca37d8d4002135e4abd171:1', 'block_height': 262537, 'spend': u'772bebdf445d719d90d52a3029d27e90aa8f26eca8d431fc77cc487c377a89c4:1', 'value': 50000, 'address': u'1CQLd3bhw4EzaURHbKCwM5YZbUQfA4ReY6'}, {'output': u'b0aad2e5184099b20d53100a678e9bec2eab1b0710fb06930f333387492a82b3:0', 'block_height': 363957, 'spend': u'05551814576ba084a0736abd8df411061c5ea7e4ae72d334317f5504f6b331d6:0', 'value': 500000, 'address': u'1CQLd3bhw4EzaURHbKCwM5YZbUQfA4ReY6'}, {'output': u'97f7c7d8ac85e40c255f8a763b6cd9a68f3a94d2e93e8bfa08f977b92e55465e:0', 'block_height': 262537, 'spend': u'772bebdf445d719d90d52a3029d27e90aa8f26eca8d431fc77cc487c377a89c4:0', 'value': 50000, 'address': u'1CQLd3bhw4EzaURHbKCwM5YZbUQfA4ReY6'}]
>>> outs = [{'value': 9000, 'address': '16iw1MQ1sy1DtRPYw3ao1bCamoyBJtRB4t'}]
>>> tx = mktx(h,outs)
>>> tx 
'010000000371d1abe4352100d4d837ca96c1a16947b5444f0f3e0bc645c430f704bb06c84c0100000000ffffffffb3822a498733330f9306fb10071bab2eec9b8e670a10530db2994018e5d2aab00000000000ffffffff5e46552eb977f908fa8b3ee9d2943a8fa6d96c3b768a5f250ce485acd8c7f7970000000000ffffffff0128230000000000001976a9143ec6c3ed8dfc3ceabcc1cbdb0c5aef4e2d02873c88ac00000000'
>>> tx2 = sign(tx,0,priv)
>>> tx2
'010000000371d1abe4352100d4d837ca96c1a16947b5444f0f3e0bc645c430f704bb06c84c010000008a47304402207422fc91d125a40ce5a4f0e105554ade35dc89f59da1b62dfff75f66cd25f87e022072cea64cb10866042339c1ae8ea6d81478867f541086b07837774e2df652630a01410420f34c2786b4bae593e22596631b025f3ff46e200fc1d4b52ef49bbdc2ed00b26c584b7e32523fb01be2294a1f8a5eb0cf71a203cc034ced46ea92a8df16c6e9ffffffffb3822a498733330f9306fb10071bab2eec9b8e670a10530db2994018e5d2aab00000000000ffffffff5e46552eb977f908fa8b3ee9d2943a8fa6d96c3b768a5f250ce485acd8c7f7970000000000ffffffff0128230000000000001976a9143ec6c3ed8dfc3ceabcc1cbdb0c5aef4e2d02873c88ac00000000'
>>> tx3 = sign(tx2,1,priv)
>>> tx3
'010000000371d1abe4352100d4d837ca96c1a16947b5444f0f3e0bc645c430f704bb06c84c010000008a47304402207422fc91d125a40ce5a4f0e105554ade35dc89f59da1b62dfff75f66cd25f87e022072cea64cb10866042339c1ae8ea6d81478867f541086b07837774e2df652630a01410420f34c2786b4bae593e22596631b025f3ff46e200fc1d4b52ef49bbdc2ed00b26c584b7e32523fb01be2294a1f8a5eb0cf71a203cc034ced46ea92a8df16c6e9ffffffffb3822a498733330f9306fb10071bab2eec9b8e670a10530db2994018e5d2aab0000000008a47304402206aa501a97b3b9754d2cf3b702dcd9733a8a3156321569d8fb97b175f411211a80220442f426c7121a68b9476dc1df31ef71d70eb1bf3777cb38ce83b35882765518701410420f34c2786b4bae593e22596631b025f3ff46e200fc1d4b52ef49bbdc2ed00b26c584b7e32523fb01be2294a1f8a5eb0cf71a203cc034ced46ea92a8df16c6e9ffffffff5e46552eb977f908fa8b3ee9d2943a8fa6d96c3b768a5f250ce485acd8c7f7970000000000ffffffff0128230000000000001976a9143ec6c3ed8dfc3ceabcc1cbdb0c5aef4e2d02873c88ac00000000'

>>> pushtx(tx3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/bitcoin/bci.py", line 304, in pushtx
    return f(*args)
  File "/usr/local/lib/python2.7/site-packages/bitcoin/bci.py", line 259, in bci_pushtx
    return make_request('https://blockchain.info/pushtx', 'tx='+tx)
  File "/usr/local/lib/python2.7/site-packages/bitcoin/bci.py", line 23, in make_request
    raise Exception(p)
Exception: An outpoint is already spent in [37275258, 92842599]

I am not sure what I am doing wrong.

Your help is much appreciated. Cheers

1

There are two problems with the transaction you're creating.

UTXOs

The history() call retrieves all transaction outputs (TXOs) that have been "received" by the specified bitcoin address. This includes both unspent and spent TXOs. If you look at the received transactions for this address (the three where this address is listed on the right), you see that each one is marked with an (S), meaning that all three have been spent.

Likewise, if you look at the contents of the h variable, each TXO object includes a spend key, which also indicates that each has already been spent. Your transaction is a double-spend attempt, which is why it was rejected.

You'll probably want to filter out those already-spent TXOs to create a list of unspent TXOs (UTXOs):

utxos = filter(lambda txo: 'spend' not in txo, h)

or you can call unspent() instead of history().

(Of course, in this example utxos is now empty because there are no UTXOs.)

Signatures

The second issue is that your TX includes three inputs, but you only sign the first two. You'll probably want something like:

for i in range(len(utxos)):
    tx = sign(tx, i, priv)

or simply:

tx = signall(tx, priv)

As an aside, hopefully you do realize that you've posted your private key on a public forum? Had those TXOs not yet been spent, they probably would have been taken by now.... edit: I just noticed that the private key came straight from pybitcointools docs, so nevermind....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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