Giter VIP home page Giter VIP logo

pybitcointools's Introduction

I really don't have time to maintain this library further. If you want to fork it or use it despite lack of maintenance, feel free to clone locally and revert one commit.

This externally-maintained fork looks good though I did not personally write it so can't vouch for security: https://github.com/primal100/pybitcointools

pybitcointools's People

Contributors

cneves avatar coder5876 avatar ethers avatar fcracker79 avatar frewsxcv avatar miwcryptocurrency avatar reiven avatar renelvon avatar rubensayshi avatar steve132 avatar tgerring avatar tinybike avatar vbuterin avatar wizardofozzie avatar ycuv avatar zouppen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pybitcointools's Issues

merkle_prove index out of range

https://github.com/vbuterin/pybitcointools/blob/master/bitcoin/blocks.py#L43 is hitting index out of range

tx = 'fda204502a3345e08afd6af27377c052e77f1fefeaeb31bdd45f1e1237ca5470'
>>> merkle_prove(tx)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "bitcoin/composite.py", line 128, in merkle_prove
  File "bitcoin/blocks.py", line 43, in mk_merkle_proof
IndexError: list index out of range

fda... is the 8th indexed transaction of block 100001

eligius_pushtx fail

show below message:

Trying to send...
NULL
Response = 0Sorry, function disabled. Contact wizkid057 directly if you need a transaction mined.

Testnet history and push

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.

How to validate bip32 xpub keys and bitcoin addresses?

I hope I'm in the right place, as the title suggests I'm looking for a way to check if a string is either a valid bip32 pub key or a valid btc address.

Having a hard time finding a python function that achieves this, is this possible with this library and if so please could you give me a hint ;)

Thank you

Multi-input transaction doubt

Hi everyone,

I have a doubt related to multi-input transactions. Where the transaction is signed, the index of the input to be signed is requested in the function call:

sign(tx, i, private_key)

I don't figure out what it's used for. Is not the whole tx signed (or at least all the inputs and outputs) in order to avoid that any input or output could be modified after signing it?

Thank you.

apply multisig

Hi,
The function apply multisig doesnt seem to work, it returned the Hex with non Hex characters inside....

[bug] non-mandatory-script-verify-flag Error when pushing tx made by pybitcointools

Here is code that reproduces the tx. It is a regtest tx, I could upload my regtest/ directory if required.

import bitcoin as btc

tx_5825 = '0100000005980022ce9350f563cedb70ff576d8b8e0fa8cf9a0ee4760d36e428c91570a812010000006c493046022100adc9b9cab0a2428d1f38d4f922675a9ee3db2c9f85ea070ea484dc79f8d01fa0022100a885fa8753dc31fafbd98896e3cf3e3345b8f3c8acd42b3ff9bee65959c5171c012102107122bb8ade89244937faf7439b4d0f1812384eadec3a35b7903d0660d3d479ffffffffc8e66bf3cdb1f0798f3cc8c5b435b2c6bfced202dd9bfc68f8a82d427f0f2bee050000006b483045022100dd256287ba9f16ff1dfb35423d2af36de016ad6cb869d5415bc01ea400761a90022052245a970da2f9a3ac43ecc1ee84192000558b605d7614c39af10819d13da657012102230beb1b5745e9b9b6dba98f541857831db2aa0580472ee4ce3df05bc441be72ffffffff13a0e0f98ec6a99623ee198fa9ed4b49c03b3900fddebadadc6dc1b79a5fd2ba040000006c493046022100d3e36382c81a8ff454e06c4cb69fe7648ca28ceeb480f8100237953e76e215b9022100b40ea51b19f8015829388570bb776369a016e2311171ed1242ffb6fb069d5cb301210277129b6fe03e7c84f7406048d41e1622a741a2237d2b3edaf46e28cee344b652ffffffff980022ce9350f563cedb70ff576d8b8e0fa8cf9a0ee4760d36e428c91570a812020000006c493046022100fabb8c10886df0c2a2106f32c5731f39e05aec16de809e6d1ae800e8f4019368022100d53d353c5e47956b346fe7d66a81356dc01523149545c3e1b6f47d62bfd8c9b00121023d73a29015b383b3e7a3d3baff9f35fde1d81d2e9accaca3e6bc762f2df11a55ffffffffc8e66bf3cdb1f0798f3cc8c5b435b2c6bfced202dd9bfc68f8a82d427f0f2bee030000006a4730440220381f2849650e9875c65c424faf82631a107d9e5be6cb626a728494cb22b4606f02205c86c445ba20c726ffa4e5376f93c52524459180c9e6ff5d9a7a4f7fe84c8b96012103143a65e23bfc156051863b5c371a338b5f976914d43bfea5313b50438cbed942ffffffff0694123695000000001976a91444e13e5b04431526de0a4945e117583ec899810f88acfa90941b000000001976a91458691d41de22d2b5286039d176baae3d3c785e0f88aceeace61d000000001976a9141422800fb5c930770cddf4c7d6e7fb9fe710561288ac1ddda74c000000001976a914dc8af008230314ce43d56ed9326f047b710ae3fe88ac94123695000000001976a914d09bdcd91a15c9fec88849b7927ac1da501b116e88ac94123695000000001976a914b3c80951bc43b9265c0e27a94b49c5aa8520965788ac00000000'
assert btc.txhash(tx_5825) == '5825c725a2927c4d1d74e6d3676621f6ef6954bf95fe4fe6e0c4e8dd0346c0c6'

tx_12a8 = '0100000005c8e66bf3cdb1f0798f3cc8c5b435b2c6bfced202dd9bfc68f8a82d427f0f2bee000000006b48304502200f9087864888795d2d4ee1c3e049f8a3af633a3dcb2f8ddadf73280add1a3a43022100f48f5f2cb6d0a527dad4cb8df041e517d8198664145ced41592a0f48f9a8f72c01210305405f91840a4de707a4412464b421cd317669fb24ecfe8defea749a8bc2e327ffffffffe7d164b847d2ac9e5e98d66ad2c43e2a3d7e66ae4c55edc9a40824c6dcc9f0b4050000006b48304502203ffc9d25983fe2c56aeaaa34db4143dc796124b2b2c45b12c58b92c910758d70022100ccaf79fd20e503aef81e32610d30980a309a92c48b6a5b2788720fd17dfcb285012102b05b4db8671926c6a15c61bc12afdc1aa8ef37b1cc34d0bbe1d2446c4269ab6affffffff1f0028fd48f21b4b15e9aee450b93492bc1061376787873a06364932104eeb69010000006a47304402204b57ab03dfa628e6dab74ddcf53e9113a94d937323d304301f00513da4f56b65022070ea9dfbc5bed783f7616c73bf1129709f6d1c1a9c4a050a7ac71e5e44a4a8e0012103e950eff043e00a70b1c01ac5a03d4157bae72d129491581688ac65e30e4ba90dffffffff13a0e0f98ec6a99623ee198fa9ed4b49c03b3900fddebadadc6dc1b79a5fd2ba000000006c493046022100c69382b3cda3ad7bffbeda1036765a7f35cf648f1fe40660ca412cf093a4c876022100891010309060e61f0c5c9121c806ed37632dd3a9d7200c41adea0abaf7e2bc9501210286264ae391bf00604324df057023825d2d3025d5e23d222fdba2d3fa9bfabb8fffffffffe7d164b847d2ac9e5e98d66ad2c43e2a3d7e66ae4c55edc9a40824c6dcc9f0b4020000006a47304402200889c1da5a16fd100d199d2eb56cc1da83108304660341168f4bdce2e064dad602203889db9e656d5a41bf794babcfb138238489998f748170fc2bad3043fee77e070121022bb2ebb6899c94a88485027b1bad895992fd140d8014deb41463d4acdc7adc15ffffffff056de6ee1f000000001976a9144ce46664ba73e37d562ec3e76b0c9d9a9d3ec7df88ac15cf6d88000000001976a91444b76e75bb518ef157a81ddd552490534db5019788ac15cf6d88000000001976a914e8b808ce72a372c317e5bc517adc28307a89794f88ac15cf6d88000000001976a9143c72bbcb650c88b3b5ae27802af31fb6ecec4ba688ac9f166f19010000001976a9144232e272e40aabf25abc8579bf8a63913e71095c88ac00000000'
assert btc.txhash(tx_12a8) == '12a87015c928e4360d76e40e9acfa80f8e8b6d57ff70dbce63f55093ce220098'

utxo_privkeys = [
('5825c725a2927c4d1d74e6d3676621f6ef6954bf95fe4fe6e0c4e8dd0346c0c6:4', 'cUAZZEcHoDxTc4wMV2KNRmAAzMZGNPG6sjBcyab1UsdhBmiByLSf'),
('5825c725a2927c4d1d74e6d3676621f6ef6954bf95fe4fe6e0c4e8dd0346c0c6:0', 'cR4cSNZ1uDNrcK7ySiih5yC3YTLYg9ep2qVkgt92ptEjeT9jgmcm'),
('5825c725a2927c4d1d74e6d3676621f6ef6954bf95fe4fe6e0c4e8dd0346c0c6:5', 'cSz44CEnPK8f9un19y9AbPWoh2AwYYzTknMNNwkvXjbtEsW7SMdC'),
('12a87015c928e4360d76e40e9acfa80f8e8b6d57ff70dbce63f55093ce220098:3', 'cV4qW8AZsyTpCRdeaxY7qvAegmC55Peio2eyc2dpkqw5SFQ8fhQk')
]

outputs = \
[{'address': 'myD3VAt8nFUPTH4ppRrjmtvBZFqn734gfz', 'value': 1114147350},
 {'address': 'mvZB2DF1yD99uScKCwPtgCor6egsdiEXrL', 'value': 1114147350},
 {'address': 'mv53HA1roXE36XL7w9n22uogQy3vwWQWNH', 'value': 899696279},
 {'address': 'mwxD3Lw7LZbjyuVdTWFyB7S2dihQqy3WEj', 'value': 1391984503},
 {'address': 'n1CeSEDjUm7AJdAAzfAxdLPN3UCDQBAdK4', 'value': 1103002474},
 {'address': 'mvkKgMi5yXBdUyisqp4jFWffYZ6R3uWEtp', 'value': 1391984503},
 {'address': 'mfZhBrJJFS3YjsUcYncRDDAwcJxqxtBYRe', 'value': 1391984503},
 {'address': 'mjzNa9UDJvtMQZHfjxWHVik2DK9AWYcsMq', 'value': 1391984503}]


inputs = [{'output': up[0]} for up in utxo_privkeys]
tx = btc.mktx(inputs, outputs)

for i, up in enumerate(utxo_privkeys):
    tx = btc.sign(tx, i, up[1])
print tx

def getrawtransaction(txid):
    if txid.startswith('5825'):
        return tx_5825
    elif txid.startswith('12a8'):
        return tx_12a8
    else:
        return None

txd = btc.deserialize(tx)
for index, ins in enumerate(txd['ins']):
    rawtx = getrawtransaction(ins['outpoint']['hash'])
    script = btc.deserialize(rawtx)['outs'][ins['outpoint']['index']]['script']
    scriptPubKey = btc.deserialize_script(ins['script'])
    good = btc.verify_tx_input(tx, index, script, *scriptPubKey)
    print 'checking signature at ' + str(index) + ', Result = ' + str(good)

When run

0100000004c6c04603dde8c4e0e64ffe95bf5469eff6216667d3e6741d4d7c92a225c72558040000006c493046022100e1153d33e20a2203a379883ed8be9d0155b102fe5d26d0b2fd89ba3cfb3ba454022100ce227b56b6b13ff286e37820d2818410da92c7e9cbb5ef10c8e4793a68148a9e01210312a3424c47dd9cc87e50ae0f9993f4811fb84e80fa8b6f2cfedff144a01c94dfffffffffc6c04603dde8c4e0e64ffe95bf5469eff6216667d3e6741d4d7c92a225c72558000000006b483045022100a6c451d63e5124e9df678afdbadbb114c668b7a56746b9f2910a3de43ef5c525022020ffb275a2d822fad5ba172bf00d75402c68917ec28049c4106710baac196dc60121034fbd40b92050b64e7c057fe70bf002974263cc349c3a0916b9957bc8b26a03c8ffffffffc6c04603dde8c4e0e64ffe95bf5469eff6216667d3e6741d4d7c92a225c72558050000006b483045022100cfe66a9d9dc11a4c9e4dc3de29105acf0389c8467ae7117d12a323a25684833c0220053f3710665c91abf75f0fc5cf63898136f71d26d93b182afcdcb18519c048af012103ddaeea8b3d37ad6ab4935f1b23caf4eefbb5640a9fddcf8caa542620d10e82caffffffff980022ce9350f563cedb70ff576d8b8e0fa8cf9a0ee4760d36e428c91570a812030000006a473044021fc91b83d94f954146b0959ec4bdd00a1cd3ae48177aee6563e0a740324ae2d602210098f4519d5374b4eca68581b83b04f28cadd9ef967b7f139159195bec2057663e012103b824e91bbdb70b4672a07045e0b12d5f9ce7735aaac67a96f1a8ff8206394686ffffffff08168a6842000000001976a914c20f1c4f80661e2718d5bbf10a5c0a64b640a8e588ac168a6842000000001976a914a4f557afe46d42da29915bb62a9f53709fa7329088ac9746a035000000001976a9149fa33b8ce8071c4316c08ebdfe666113ce53db2788ac77fff752000000001976a914b448b8a3cd71322584003bfde55c306e46b4f64d88ac6a7bbe41000000001976a914d7ec1ed0cf25ab1d66797bb1c58c76e7284c51d088ac77fff752000000001976a914a711252aac3f5e57500aab8ef52435bb43222d7588ac77fff752000000001976a9140084a321f0a8abbfce767e77e0dcb6c112c5f9a188ac77fff752000000001976a914310ffff9ff4f815b262629982d7f34ae9a31686288ac00000000
checking signature at 0, Result = True
checking signature at 1, Result = True
checking signature at 2, Result = True
checking signature at 3, Result = True

Using sendrawtransaction on bitcoin core console produces this error

64: non-mandatory-script-verify-flag (No error) (code -26)

The relevant line the debug.log

2015-04-25 19:44:39 ERROR: CScriptCheck(): 951a38b33df011e92584deed5e67ce57ab9a0c1dba9e3c4b97fcb1cb4734a0ce:3 VerifySignature failed: Non-canonical DER signature

2 diff addresses from the same HD prvkey

I created a privkey from my HD master key:
mk = bitcoin.bip32_master_key('seed')
prv = bitcoin.bip32_ckd(mk,0)

Which of the below should I use to get the address?

bitcoin.pubkey_to_address(bitcoin.bip32_privtopub(prv))

'1PryoY2TVGno95zueXavej8xetFxxWmwXq'

bitcoin.privkey_to_address(bitcoin.encode_privkey(bitcoin.bip32_extract_key(prv), 'wif'))

'1LbQvv9Xzxmm3RPVgCVhnmyfDR4Tke2GLB'

Wrong MultiSignature Address Generation

This generates the wrong address for multisigniture addresses:

 TestMultisig = mk_multisig_script(["0254236f7d1124fc07600ad3eec5ac47393bf963fbf0608bcce255e685580d16d9","03560cad89031c412ad8619398bd43b3d673cb5bdcdac1afc46449382c6a8e0b2b"],2)

    multisig_address = p2sh_scriptaddr(TestMultisig)

This will Generate : 3Qu1wLEVDda4EjCCgtirUuz5kq6geoaDQW

Although if you check with either pycoin or http://ms-brainwallet.org, it should generate: 33byJBaS5N45RHFcatTSt9ZjiGb6nK4iV3

mktx doesn't work with float values

The code shown in the readme does not work with a float value.

h = history(fromWallet)
jsonTrans = [{'value': 0.1, 'address': intoWallet}]
trans = mktx(h, jsonTrans)

will result in an error on line 73 in main.py : TypeError: string indices must be integers, not float

result = code_string[val % base] + result

how to use new send function

I noticed that there's a new function "send",but i'm confused about it :

%Takes privkey, address, value (satoshis), fee (satoshis)
mksend(to+':'+str(value),privtoaddr(to),fee)
is send need priv key of the address i'll pay?

i replace privtoaddr(to) with address but the osum is wrong.

can you give some example how to use "send"?

Thanks

Blockchain SSL support

Hi
It seems that all calls to the Blockchain API are done via HTTP instead of HTTPS. This is problematic as it allows snooping parties to determine what addresses/transactions we're interested in and potentially own.
Regards,
Vedran

deserialize

What are the last two return values in the returned array from deserialize?

Thanks

How to apply_multisignatures to a tx with more than one input

Hi, i have a rawtransaction with two inputs and two outputs , but i cannot get a fully signed transaction

rawtx = 01000000027952018283a70cd1de352494063ccd252ebb11ab9977ba97682d5587e950ad600000000000ffffffff2581265adfc01d079452bcdf8842deb5fb143c9da9a1888833e2c52d391de0d70000000000ffffffff02c0c62d000000000017a914a4c213e36f42e3f6d21513a42830159ee52912e78740420f000000000017a914c41f74428cc7a0b7420a64af0793a158db93c35d8700000000
sign1 = ['3046022100ff3fa484b39dc5449722668a62a08a3c71c4f8ec8639a8da468534226c75ea600221009682fed1598016582208dfdaec430afee364d8d8355321568ce900a48800e87c01','3046022100d5e151b6c97580d112b9d0b401644fa86d472d681541b0914b5a6ff75692e457022100d5fc829689e8be7b314b6b16ee16afcd91627a4b1fa957838591ad1873a6fb5e01']
sign2 = ['3046022100c68beb2e026fbde6a2dc7e311fb2d9a84b391b02932288002b23d240e00212280221008709e68c5fd4e254609ac883baa6be338a119fc560caa7d5f8676820cb55f27101', '3045022100f686d3830e24119b36cf3627b53df14bcb1971bb7f4ce85c10a599867d4177c70220651c453ccc22ab0f4cf0a08a23761abef1246d750a27caf285fefe92ef9cedba01']
rawtx2 = apply_multisignatures(rawtx, 0, redeem, [sign1[0], sign2[0]])
rawtx3 = apply_multisignatures(rawtx2, 1, redeem, [sign1[1], sign2[1]])

final hash:
'01000000027952018283a70cd1de352494063ccd252ebb11ab9977ba97682d5587e950ad6000000000fd1e0100493046022100ff3fa484b39dc5449722668a62a08a3c71c4f8ec8639a8da468534226c75ea600221009682fed1598016582208dfdaec430afee364d8d8355321568ce900a48800e87c01493046022100c68beb2e026fbde6a2dc7e311fb2d9a84b391b02932288002b23d240e00212280221008709e68c5fd4e254609ac883baa6be338a119fc560caa7d5f8676820cb55f271014c875241045a6430c5b44755a3b7adcc3dd6d542e3ab71e0cf31fc92fbe027368d9c439411016ef6067a548a6235de76117c720ddaf1d776f7869b9df15b61b5f330f1bda441045240868d326f943acd099196bf55cb8800ce10ed5861ba4ae7687ef5d0f9b68544e73a0002c34cce90ce89915c3801eccd12bceb6a801a7a3d8902baf65a0e9252aeffffffff2581265adfc01d079452bcdf8842deb5fb143c9da9a1888833e2c52d391de0d700000000fd1d0100493046022100d5e151b6c97580d112b9d0b401644fa86d472d681541b0914b5a6ff75692e457022100d5fc829689e8be7b314b6b16ee16afcd91627a4b1fa957838591ad1873a6fb5e01483045022100f686d3830e24119b36cf3627b53df14bcb1971bb7f4ce85c10a599867d4177c70220651c453ccc22ab0f4cf0a08a23761abef1246d750a27caf285fefe92ef9cedba014c875241045a6430c5b44755a3b7adcc3dd6d542e3ab71e0cf31fc92fbe027368d9c439411016ef6067a548a6235de76117c720ddaf1d776f7869b9df15b61b5f330f1bda441045240868d326f943acd099196bf55cb8800ce10ed5861ba4ae7687ef5d0f9b68544e73a0002c34cce90ce89915c3801eccd12bceb6a801a7a3d8902baf65a0e9252aeffffffff02c0c62d000000000017a914a4c213e36f42e3f6d21513a42830159ee52912e78740420f000000000017a914c41f74428cc7a0b7420a64af0793a158db93c35d8700000000'

but on rcpclient, if i do a signrawtransaction of that hash, it keeps saying 'complete': False

What i'm doing wrong, or there is any missing step to do this?

Additional information: the address is a 2/2 multisig on tesnet

Thanks

unable to generate valid signature

i tried following "Example usage" and i got different result after line:
tx2 = sign(tx,0,priv)

of course "h = history(addr)" yields different result now, so instead i manually assigned value printed in line below to h

blockchain info api: tx hash

Why does the unspent-function in bci.py reverse the tx_hash from blockchain.info? What's the consequence of not doing that when using the tx_hash to create a raw transaction?

Value of scripthash_byte in script_to_address()

Not sure about this but should we not use 196 instead of 192 for the value of scripthash_byte in script_to_address() ? (https://en.bitcoin.it/wiki/List_of_address_prefixes)

Done some tests to generate a P2SH address and send some coins to this address with Bitcoin Core:

priv1 = sha256('This is a private key 1')
pub1 = privtopub(priv1)
priv2 = sha256('This is a private key 2')
pub2 = privtopub(priv2)
script = mk_multisig_script([pub1, pub2], 2, 2)
multisig_addr = p2sh_scriptaddr(script, 196) # 2N55f5BcsXWZYWLF9S1NBPdjwkmToBcJaYT accepted by bitcoin core
multisig_addr2 = p2sh_scriptaddr(script, 192) # 2LTjF8kRigni3EbgoLL2uT8eoEkS2PbGbMF refused by bitcoin core

the second round of sign() of a transaction doesn't work

The code just follows the example given in the Readme.md:

    h = bitcoin.history(src_addr)
    log.info("history: '{}'.".format(h))
    tx = bitcoin.mktx(h, outs)
    log.info("tx: '{}'.".format(tx))
    tx2 = bitcoin.sign(tx, 0, src_priv)
    log.info("tx2: '{}'.".format(tx2))
    tx3 = bitcoin.sign(tx2, 1, src_priv)
    log.info("tx3: '{}'.".format(tx3))

the second round (generating tx3) would raise an exception (IndexError) shown below:

Traceback (most recent call last):
  File "C:\btc4fun\py\caretaker.py", line 72, in <module>
    ret = main()
  File "C:\btc4fun\py\caretaker.py", line 66, in main
    return v(args)
  File "C:\btc4fun\py\caretaker_cmds.py", line 113, in pay
    b4f.btc.pay(btc_value, dest_addr, (addr, priv))
  File "C:\btc4fun\py\b4f\btc.py", line 63, in pay
    tx3 = bitcoin.sign(tx2, 1, src_priv)
  File "C:\btc4fun\py\external\pybitcointools-2014.06.21\bitcoin\transaction.py"
, line 261, in sign
    signing_tx = signature_form(tx,i,mk_pubkey_script(address))
  File "C:\btc4fun\py\external\pybitcointools-2014.06.21\bitcoin\transaction.py"
, line 104, in signature_form
    return serialize(signature_form(deserialize(tx),i,script,hashcode))
  File "C:\btc4fun\py\external\pybitcointools-2014.06.21\bitcoin\transaction.py"
, line 107, in signature_form
    newtx["ins"][i]["script"] = script
IndexError: list index out of range

So far every function I called (unspent, history, etc.) works perfectly except this one. Is there anything I missed or I did incorrectly?

Multisig script is no longer valid: OP_CHECKMULTISIG(VERIFY) with non-null nulldummy

Hello there.

I'm getting this error:

OP_CHECKMULTISIG(VERIFY) with non-null nulldummy: [48, 68, 2, 32, 62, -19, -78, 21, -25, -76, -2, -88, -75, -49, 60, 104, 53, 80, 23, 111, 40, 39, -109, 27, 35, -48, 86, 21, 80, 60, 37, 72, -112, 99, -98, 0, 2, 32, 29, -73, 28, 4, -31, -10, -61, -3, -85, -109, 10, 67, -116, 63, 58, 43, -44, -72, 54, 48, 81, -107, 54, -95, 5, 66, -30, 95, -16, 20, -4, 51, 1]

With this Counterparty transaction that I am signing. If I understand correctly, some rules changed and some scripts that used to be valid are no longer valid because Bitcoin core implementations are more strict now. See: btcsuite/btcd#131

This is the signed transaction:

0100000001caa1cd766de01294451f1610a0a0136bc9176070f1c22494eb2e28443624aa8e00000000fd5d010047304402203eedb215e7b4fea8b5cf3c683550176f2827931b23d05615503c254890639e0002201db71c04e1f6c3fdab930a438c3f3a2bd4b83630519536a10542e25ff014fc3301483045022100a83b7b516982442700f350bdafa7aa10b91c7930aa05ca20dca82613670292d602207cda3992c1d224cfd0a2bf6b8b6d595e17a9abe1353795879b1e29d5507550cc014cc95241043e12a6cb1c7c156f789110abf8397b714047414b5a32c742f17ccf93ff23bdf3128f946207086bcef012558240cd16182c741123e93ed18327c4cd6ebac668a94104e4168c172283c7dfaa85d2004f763a28bf6d0f1602fc1452ccec62a7c8a66e422af1410fbf24a47355ddc43dfe3491cb1b806574ccd1c434680466dcff926f01410427db4059d24bab05df3f6bcc768fb01bd976b973f93e72cce2dfbfbed5a32056c9040a2c2ea4c10c812a54fed7ff2e6a917dbc843362d398f6ace4000fafa5c653aeffffffff0336150000000000001976a91451bb89eb8fcb138174114315fc8eaf054395c0cc88ac781e00000000000089512103ff58dcadeb5a447162ab629d309c2a28043a3437884b7b280fcfff9baa3119c021024131478633f18da1caec8ee455108b72feb19d70baae9ca86638661e47562bfa410427db4059d24bab05df3f6bcc768fb01bd976b973f93e72cce2dfbfbed5a32056c9040a2c2ea4c10c812a54fed7ff2e6a917dbc843362d398f6ace4000fafa5c653ae9268000000000000c952410427db4059d24bab05df3f6bcc768fb01bd976b973f93e72cce2dfbfbed5a32056c9040a2c2ea4c10c812a54fed7ff2e6a917dbc843362d398f6ace4000fafa5c641043e12a6cb1c7c156f789110abf8397b714047414b5a32c742f17ccf93ff23bdf3128f946207086bcef012558240cd16182c741123e93ed18327c4cd6ebac668a94104e4168c172283c7dfaa85d2004f763a28bf6d0f1602fc1452ccec62a7c8a66e422af1410fbf24a47355ddc43dfe3491cb1b806574ccd1c434680466dcff926f0153ae00000000

More data here:

http://pastebin.com/hYDy1pD3

I can provide more data if needed.

Thanks!

Does function decode_privkey in main.py need a special case for wif format?

Specifically, I made these changes:

    #else:
    # bin_p = b58check_to_bin(priv)
    # if len(bin_p) == 32: return decode(bin_p,256)
    # elif len(bin_p) == 33: return decode(bin_p[:32],256)
    # else: raise Exception("WIF does not represent privkey")
    elif formt == 'wif': return decode(b58check_to_bin(priv),256)
    elif formt == 'wif_compressed': return decode(b58check_to_bin(priv)[:32],256)
    else: raise Exception("Invalid privkey format!")

Is there any reason why there is special handling of 'wif' stuff here? It is identical to stuff in the function get_privkey_format . I would make a normal pull request, but my fork is a translation to Racket Scheme, and I don't want to figure out handling multiple branches and whatnot.

Module name for import seems to be 'bitcoin' not 'pybitcointools'

Running:
2.7.6 |Anaconda 1.9.2 (x86_64)| (default, Jan 10 2014, 11:23:15)
[GCC 4.0.1 (Apple Inc. build 5493)]

from pybitcointools import *
ImportError: No module named pybitcointools
from bitcoin import *
(success)

...might want to edit README.
Thanks VB, such great work

Null exception error

Not sure if this is related to #39 but I am seeing issues intermittently where a null exception is raised.

Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/Users/brianhoffman/Projects/merge/083014/OpenBazaar/node/trust.py", line 103, in get_history
    history = pybitcointools.history(addr)
  File "/Library/Python/2.7/site-packages/pybitcointools/bci.py", line 28, in history
    data = make_request('http://blockchain.info/address/%s?format=json&offset=%s' % (addr,offset))
  File "/Library/Python/2.7/site-packages/pybitcointools/bci.py", line 13, in make_request
    raise Exception(p)
Exception: null

Odd length private keys have issues to be encoded

hash='bf4d66297022d912544810bf956254479957683604243cd13558b3fde26da49'
encode_privkey(hashh,'wif')

returns:

File "test.py", line 475, in b58check_to_bin
assert bin_dbl_sha256(data[:-4])[:4] == data[-4:]
AssertionError

Setting vbyte to 196 in script_to_address results in a mainnet address

def script_to_address(script, vbyte=0):
    if re.match('^[0-9a-fA-F]*$', script):
        script = binascii.unhexlify(script)
    if script[:3] == '\x76\xa9\x14' and script[-2:] == '\x88\xac' and len(script) == 25:
        return bin_to_b58check(script[3:-2], vbyte)  # pubkey hash addresses
    else:
        if vbyte == 111:
            # Testnet
            scripthash_byte = 196
        else:
            scripthash_byte = 5
        # BIP0016 scripthash addresses
        return bin_to_b58check(script[2:-1], scripthash_byte)

The testnet vbyte for P2SH addresses is 196. If you call script_to_address(script, 196), this code sets scripthash_byte to 5 instead. It's avoidable by setting vbyte to 111 instead, but it seems odd to use the P2PKH vbyte for a function that creates a P2SH address. I can make a pull request for this if you'd like, but it's a one-line fix.

Ripemd Module

I think there's something wrong with this module when i want to compile something its raising an exception saying:

line 160, in RMD160Transform
x = struct.unpack('<16L', ''.join([chr(x) for x in block[0:64]]))
TypeError: 'str' does not support the buffer interface

I'm using python 3.4.2 and Windows 7, i think its a cast issue, hope it helps.

signining chokes on unicode strings

Signing transactions represented using unicode strings (standard in python) fails in signature_form:

def signature_form(tx, i, script, hashcode = SIGHASH_ALL):
    i, hashcode = int(i), int(hashcode)
    if isinstance(tx, str):
        return serialize(signature_form(deserialize(tx), i, script, hashcode))
    newtx = copy.deepcopy(tx)

Here, the check if isinstance(tx, str): fails. It should read if isinstance(tx, str) or isinstance(tx, unicode):.

User-side workaround:

signed_raw_tx = pybitcointools.signall(tx.encode('ascii','ignore'), privateKey)

Unicode errors under Python 2.7

UNICODE objects under Python 2.7 causing issues.

deserialize_script on unicode dictionary objects (from bitcoin-rpc) returns no error but completely corrupted data
deserialize on a unicode raw hex tx throws an error in py2specials.decode

Both can be solved by ensuring unicode objects are non-unicode strings ie by using str(unicode_basestring)


lu = rpc.listunspent()

>>>lu[-2]

{u'account': u'',
 u'address': u'2NCgTCaiUHSVKZ6Wwvx74D1Me9gLN1Gw8Rr',
 u'amount': Decimal('0.00940000'),
 u'confirmations': 14839,
 u'redeemScript': u'522103d3ff0a3067aece5817d1c017d8f119422b208d30764fd595747b3a1e7b6cae95210268a35242e5f131f031a25bb0d5
7141c7737b1668ed702bc8c6ec65205d85e8f82102d7c0f0b9eafe5af2c6d68411fd16a9b596a607ea4ae670bad3ffabfd0ee6bd0353ae',
 u'scriptPubKey': u'a914d52fd15aab4e472f198f64b001a8fafa57ca264587',
 u'spendable': True,
 u'txid': u'c1cfe29c3e1ae6fbf2cb7631cb4c9b2e12f31c8038877ca0522ddae67757e3db',
 u'vout': 0}

 redeemScript = u'522103d3ff0a3067aece5817d1c017d8f119422b208d30764fd595747b3a1e7b6cae95210268a35242e5f131f031a25bb0d57141c7737b1668ed702bc8c6ec65205d85e8f82102d7c0f0b9eafe5af2c6d68411fd16a9b596a607ea4ae670bad3ffabfd0ee6bd0353ae'

deserialize_script(lu[-2]['redeemScript'])      # unicode object

[u'22103d3ff0a3067aece5817d1c017d8f119422b208d30764fd595',
 u'47b3a1e7b6cae95210268a35242e5f131f031a25bb0d57141c7737b',
 u'668ed702bc8c6ec65205d85e8f82102d7c0f0b9eafe5af2c6',
 100,
 u'8411fd16a9b596a607ea4ae670bad3ffabfd0ee6bd0353ae']

deserialize_script(str(lu[-2]['redeemScript']))

>>> [2,
 '03d3ff0a3067aece5817d1c017d8f119422b208d30764fd595747b3a1e7b6cae95',
 '0268a35242e5f131f031a25bb0d57141c7737b1668ed702bc8c6ec65205d85e8f8',
 '02d7c0f0b9eafe5af2c6d68411fd16a9b596a607ea4ae670bad3ffabfd0ee6bd03',
 3,
 174]

 testnet_raw_tx = u"01000000019606a46d9a2539051dac55696daea42f61af02a03f287a618d8effb00ec0eff7000000008b4830450221009f2d20c46be10de310b57f8f8583d349d07ae9879344372729749c95715dab4002204418e87634aa723432e83d216d7e50a37140e070e1da72a23663063f1e1298610141045dfb08a474f86ebfb7d2f1786f4d9a9347ac46346229373b892883467c6b624b53a106d9628896fbd5343e0efe3528d934701e1d87caa57475320ff1c6aa4c10ffffffff02802b530b000000001976a91423e01dab3bfd754dd92aa86715322db3e050733b88ac0000000000000000fd37036a4d3303476f206f6e20616e64207772696e67206d79206e65636b0a4c696b65207768656e2061207261672067657473207765740a41206c6974746c65206469736369706c696e650a466f72206d79207065742067656e6975730a4d792068656164206973206c696b65206c6574747563650a476f206f6e2064696720796f7572207468756d627320696e0a492063616e6e6f742073746f7020676976696e670a49276d207468697274792d736f6d657468696e670a53656e7365206f662073656375726974790a4c696b6520706f636b657473206a696e676c696e670a4d69646c696665206372697369730a5375636b20696e67656e756974790a446f776e207468726f756768207468652066616d696c7920747265650a596f7527726520706572666563742c207965732c206974277320747275650a42757420776974686f7574206d6520796f75277265206f6e6c7920796f750a596f7572206d656e737472756174696e672068656172740a49742061696e277420626c656564696e2720656e6f75676820666f722074776f0a497427732061206d69646c696665206372697369732e2e2e0a5768617420616e20696e6865726974616e63650a5468652073616c7420616e6420746865206b6c65656e65780a4d6f726269642073656c6620617474656e74696f6e0a42656e64696e67206d792070696e6b79206261636b0a41206c6974746c65206469736369706c696e650a4120646f6e6f722062792068616269740a41206c6974746c65206469736369706c696e650a52656e7420616e206f70696e696f6e0a53656e7365206f662073656375726974790a486f6c64696e6720626c756e7420696e737472756d656e740a49276d20612070657266656374696f6e6973740a416e642070657266656374206973206120736b696e6e6564206b6e65650a596f7527726520706572666563742c207965732c206974277320747275650a42757420776974686f7574206d6520796f75277265206f6e6c7920796f750a596f7572206d656e737472756174696e672068656172740a49742061696e277420626c656564696e2720656e6f75676820666f722074776f0a497427732061206d69646c696665206372697369732e2e2e00000000"

 deserialize(testnet_raw_tx)    # THROWS py2specials.decode error ("'ascii' codec can't decode byte 0x80 in position 128: ordinal not in range(128)")

 deserialize(str(testnet_raw_tx))   # FINE

base10 encoding/decoding broken

Commit 32c454c (pep8) made a big bug.

code_strings = {
2: '01',
10: '012356789',
16: '0123456789abcdef',

the 4 is missing in base10, causing incorrect encoding and decoding.

bitcoin.decode('444',10)
-111
bitcoin.decode('555',10)
444

can't replicate electrum behaviour

I create seed as

seed = sha256("my 12 word list")[:32]
print electrum_mpk(seed)

And it doesn't match my master public key in electrum gui. I got the sha256[:32] method from random_electrum_seed method.

Testnet Hashing

Is there a way to set the lib to testnet mode?
I need to verify pubkeys to addresses on both test-net and main-net

Transaction rejected; related to signature padding

The following transaction was rejected by electrum servers (and by bitcoind):

raw:
010000000103c2f4abddf4a0bfef650e9d06da76be6ad23ad86520472dfd28794233713824010000008a4730440220004306c38b85e61238e365b11aad9360d1140641b0c58ed4f66246f1adcf8b4a02200899d24c29112df6bd72eac47036d39ad87db15a584067fffe013cb2fb63fe910141049c1436ca66438c26103aad4f660dcb3b6dc78c8288f2456a0015c72dcb507d59ce9aaba3d4e82ef27e6e9d658ca823671f49a856cebaa0ed551a14742d78fa3affffffff0250460000000000001976a914ff6a23760e9648227faf8d16ca20173578eb3ce088ac37320400000000001976a9143397246f1de0bd4cb3af3f353abae9ab9651cffc88ac00000000

deserialized:
{'locktime': 0, 'outs': [{'value': 18000, 'script': '76a914ff6a23760e9648227faf8d16ca20173578eb3ce088ac'}, {'value': 274999, 'script': '76a9143397246f1de0bd4cb3af3f353abae9ab9651cffc88ac'}], 'version': 1, 'ins': [{'script': '4730440220004306c38b85e61238e365b11aad9360d1140641b0c58ed4f66246f1adcf8b4a02200899d24c29112df6bd72eac47036d39ad87db15a584067fffe013cb2fb63fe910141049c1436ca66438c26103aad4f660dcb3b6dc78c8288f2456a0015c72dcb507d59ce9aaba3d4e82ef27e6e9d658ca823671f49a856cebaa0ed551a14742d78fa3a', 'outpoint': {'index': 1, 'hash': '24387133427928fd2d472065d83ad26abe76da069d0e65efbfa0f4ddabf4c203'}, 'sequence': 4294967295}]}

--> Electrum server sent back: [{'id': 1, 'result': "{u'message': u'TX rejected', u'code': -22}"}]

IRC comments from ThomasV after debugging:

ThomasV: it's in bitcoind/src/script.cpp, line 286
ThomasV: tell him the his signature fails here
ThomasV: s/the/that

ThomasV: he needs to remove the 0x00 at the beginning of the signature
ThomasV: (the R value)

So it seems this is indeed a bug and that it will only occur occasionally.

Does get_pubkey_format need all the extra checks?

In get_pubkey_format, you not only check the lengths of the pubkeys, but you also check substrings of the pubkeys. Do you need to do this? You don't do it in get_privkey_format. Also, it looks like the encode functions are correct, so why do you need to check in this function? These questions might not make much sense, but I'm trying to be clear about reasoning behind some parts of the code, because I am trying to translate it to Racket Scheme.

Feature Request: Testnet support

First off, thanks for a great library!

I'd love to have testnet support or perhaps the generic ability to specify address prefixes so that altcoins can be supported.

Tag/branch for a stable version before the pybitcointool->bitcoin rename?

We seem to have some fairly serious breakage in the current master, eg:
#71

...and at some point the name changed from pybitcointool to bitcoin, but pybitcointool is still available in pip.

This makes it a bit confusing to distribute a script using this code and link back to where the dependency is coming from. Would it be possible to add a tag or a branch or something pointing at some reasonably stable commit before the bitcoin->pybitcointool rename?

can't Transaction btc

Hi,I;m just try pybitcointools but when i try to send btc to another address,it failed

I replaced priv = '???' instead sha256('some big long brainwallet password'),but error occoured when the 3rd sign as following:

tx3 = sign(tx2,1,priv)
  File "C:\Python27\lib\site-packages\pybitcointools\transaction.py", line 252, in sign
    signing_tx = signature_form(tx,i,mk_pubkey_script(address))
  File "C:\Python27\lib\site-packages\pybitcointools\transaction.py", line 104, in signature_form
    return serialize(signature_form(deserialize(tx),i,script))
  File "C:\Python27\lib\site-packages\pybitcointools\transaction.py", line 107, in signature_form
    newtx["ins"][i]["script"] = script
IndexError: list index out of range

i'm confused about sign(tx,i,priv),but i think according to the example ,the Index is correct,where's the problem?

The btc address is 1CtpwCtuWh7puJFkvXYMZNWaFD9rdG4YrT

Thanks,

reynolds

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.