vbuterin / pybitcointools

SImple, common-sense Bitcoin-themed Python ECC library
1.28k stars 857 forks source link

Testnet history and push #91

Closed sr-gi closed 9 years ago

sr-gi commented 9 years ago

Hi everyone,

I'd like to know if there's any way to history and push transactions to the testnet, or even if it's planned to be a future feature.

Thanks a lot.

wizardofozzie commented 9 years ago

Yes, there is. blockr_fetch(txindex, "testnet") and blockr_push(signedTx, "testnet"). Note the need to use "testnet" as the 2nd parameter

sr-gi commented 9 years ago

Thank you @simcity4242, I've been able to fetch the transaction that I was looking for from the testnet using the blockr_fetchtx, but I'm not sure how to use it in order to build a new transaction.

Is there any kind of howto?

If tried to deserialize the fetched transaction, get the outs and build the transaction like:

bitcoin_address = public_key_to_bc_address(public_key_hex, 'test') prev_tx_hex = blockr_fetchtx('67a480b18f17a9518ebc0dd962f8972163cc73710e0014878c8479a476d1b6bf', 'testnet') prev_tx = deserialize(prev_tx_hex) prev_outs = prev_tx.get('outs')

cs_bt_address = 'mpFECAZYV4dXnK2waQC36AoZsAftv5RAkM' outs = [{'value': 100, 'address': cs_bt_address}] tx = mktx(prev_outs, outs) signedtx = sign(tx, 0, private_key_hex)

blockr_pushtx(signedtx, 'testnet')

But I don't even know if it's the right way.

sr-gi commented 9 years ago

Finally I've figure out how to do it building the prev_tx manually to look like the history method result.

bitcoin_address = public_key_to_bc_address(public_key_hex, 'test') prev_tx = [{'output': u'67a480b18f17a9518ebc0dd962f8972163cc73710e0014878c8479a476d1b6bf:1', 'value': 300000000, 'address': unicode(bitcoin_address)}] cs_bt_address = 'mpFECAZYV4dXnK2waQC36AoZsAftv5RAkM' outs = [{'value': 299990000, 'address': cs_bt_address}] tx = mktx(prev_tx, outs) signed_tx = sign(tx, 0, private_key_hex) blockr_pushtx(signed_tx, 'testnet')

I've got the information of the prev_tx from the blockexplorer. The problem is that I don't know how to do it automatically because I don't know how to fetch the transactions that currently have non redeemed funds (like the history method does for the main network).

Any idea?

Thanks a lot,

sr-gi commented 9 years ago

I've finally figure it out, using blockr_unspent(bitcoin_address, 'testnet').

Thank you for all.

wizardofozzie commented 9 years ago

Sorry mate, I just saw this question. I'll reference some code which can be used to easily make a json object: it's basically mkjson(txin, vout, address, amount) or mkjson(address, amount), ie it checks to see how many *args there are, if 4, then it's input json, and returns accordingly. Conversely, it'll return outputs with 2 vars. Consider asking on bitcoin.stackexchange.com if you need quicker responses in future!

sr-gi commented 9 years ago

No problem @simcity4242.

Thank you for the advice.

PD: The issue could be closed if you want.