1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2024-11-30 03:48:31 +00:00
Commit Graph

68 Commits

Author SHA1 Message Date
Will Binns
06b8fe01cc
Merge branch 'develop' into patch-1 2021-03-10 08:16:25 +01:00
Will Binns
39d663ed30
ch04: Fix 'key-to-address-ecc-example'
The 'pybitcointools' library is deprecated. Vitalik mentions using the
fork from 'primal100'. This updates the code sample which is currently
broken, to use the Python package for that fork.

Runs all good now.
2021-03-08 15:59:01 +01:00
drakos
6b041e5341
Fix for Private Key (WIF-Compressed)
When testing with a `private_key = '0000000000000000000000000000000000000000000000000000000000000001'` instead of `private_key = bitcoin.random_key()`,
the generated Private Key (WIF-Compressed) is wrong `5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsrefhvB5QZ`, it should be `KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn`. As it turns out, the proper way to get the correct compressed WIF is to pass `'wif_compressed'` and not `'wif'` to the `bitcoin.encode_privkey` function, as pointed out in the Main.py from the bitcoin python package.

```
def encode_privkey(priv, formt, vbyte=0):
    if not isinstance(priv, int_types):
        return encode_privkey(decode_privkey(priv), formt, vbyte)
    if formt == 'decimal': return priv
    elif formt == 'bin': return encode(priv, 256, 32)
    elif formt == 'bin_compressed': return encode(priv, 256, 32)+b'\x01'
    elif formt == 'hex': return encode(priv, 16, 64)
    elif formt == 'hex_compressed': return encode(priv, 16, 64)+'01'
    elif formt == 'wif':
        return bin_to_b58check(encode(priv, 256, 32), 128+int(vbyte))
    elif formt == 'wif_compressed':
        return bin_to_b58check(encode(priv, 256, 32)+b'\x01', 128+int(vbyte))
    else: raise Exception("Invalid format!")
```

The fix can be done in a couple ways:

`bitcoin.encode_privkey(bitcoin.decode_privkey(compressed_private_key, 'hex'), 'wif')` -> 5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsrefhvB5QZ (WRONG)

`bitcoin.encode_privkey(bitcoin.decode_privkey(compressed_private_key, 'hex'), 'wif_compressed')` -> KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU9FMLM39zT (WRONG)

`bitcoin.encode_privkey(bitcoin.decode_privkey(compressed_private_key, 'hex_compressed'), 'wif_compressed')` -> KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn (CORRECT)

`bitcoin.encode_privkey(bitcoin.decode_privkey(private_key, 'hex'), 'wif_compressed')` -> KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn (CORRECT)
2021-02-27 23:37:29 -05:00
Hennadii Stepanov
5d50a93ee6
ch10: Align target description with the actual implementation
See: 43f3ada27b/src/pow.cpp (L86-L88)
2021-01-19 15:10:02 +02:00
Fan
c6fa743597
Update key-to-address-ecc-example.py
If line#24 use 'wif_compressed', it will produce a wrong Key (WIF-Compressed) started with 2.

So there should be 'wif', unless :
wif_compressed_private_key = bitcoin.encode_privkey(
    bitcoin.decode_privkey(private_key, 'hex'), 'wif_compressed')
This is also right. 
However, use the 'compressed_private_key' and 'wif_compressed' is wrong.
2019-12-04 11:39:59 +08:00
Will Binns
cec55847b0
Merge pull request #616 from terzim/patch-2
Update ec-math.py
2019-10-04 21:41:25 +02:00
Will Binns
ecbde7c77c
Merge pull request #568 from theStack/maxmoney_unusedvar
max_money.py: use variable start_block_reward (eliminate magic number)
2019-05-09 19:55:45 +00:00
Will Binns
ee6131abf0
Merge pull request #531 from koshikraj/code-fix
fixed hashlib library error for python3
2019-05-08 20:26:45 +00:00
Massimiliano Terzi
9e2817f50a
Update ec-math.py
python 3, no need for decoding/encoding
2019-01-01 16:58:31 +00:00
theStack
24fd7bd79b max_money.py: use variable start_block_reward (eliminate magic number) 2018-05-19 09:10:18 -04:00
Arthur O'Dwyer
9504d804e0 Stop using numeric_limits for the constant "255", and fix a bug.
The bug is that `x % 255` is not quite the same thing as `x % 256`;
but `x & 255` is.

The stylistic issue is that `numeric_limits<uint8_t>::max()` is a
very verbose way of spelling `255`.
2018-03-25 20:17:35 -07:00
koshikraj
d70a0f91f2 fixed hashlib library error for python3 2018-03-16 20:32:21 +05:30
Andreas M. Antonopoulos
7ed95b283b Errata 166266 2018-03-14 10:23:46 -06:00
MaloneGod
b01acc076b
correct an error line 24 'wif' to 'wif_compressed' 2018-02-08 20:42:50 +08:00
cclauss
ecd13d3523 whitespace fixes to placate flake8 2018-02-03 01:33:46 +01:00
Andreas M. Antonopoulos
b7d97a5e80
Use of print function from Python 3 requires () 2018-02-02 16:29:36 -06:00
Andreas M. Antonopoulos
9dacbb40e3 Merge remote-tracking branch 'github/develop' into second_edition 2018-02-02 15:08:14 -06:00
Andreas M. Antonopoulos
cbc23caf8a
Merge pull request #431 from cjjojoba/cjjojoba-patch-1
Update ec-math.py
2018-02-02 12:35:19 -08:00
ZhaoChunsheng
5460eb7a8d
Update key-to-address-ecc-example.py
The code is very possible to miss a leading '0'.
E.g:
Private Key (hex) is: 57c003d31cca32f79a22e70334fff37875617e89c04d2746b5efc22067ccb8fd
Before: Compressed Public Key (hex) is: 03 8f0de2360796ae0fe17f1a2b0be30af6fb45eccc4a1c7afb5ebea21d041b6e0
After: Compressed Public Key (hex) is: 03 08f0de2360796ae0fe17f1a2b0be30af6fb45eccc4a1c7afb5ebea21d041b6e0

The bug is in the pybitcointools, but it is not updated, we can only repair it ourselves.
2018-01-27 21:56:25 +08:00
Cihat Imamoglu
fc84c40e8b
Update ec-math.py
* Add a missing word "number"
* Convert `& 1` into `% 2 == 0` for clarity
2017-12-10 14:44:04 +00:00
Manjeet Singh Bhatia
22e17ffd3c
Update hash_example.py
As input and hash are inbuilt functions, so I'd suggest using other names for variables.
here is output from python interpreter.

>>> hash
<built-in function hash>
>>> input
<built-in function input>
2017-12-09 22:05:50 -08:00
Will Binns
d5e2316438
Merge pull request #372 from cclauss/patch-3
from __future__ import print_function
2017-11-18 07:39:50 -06:00
MarcoFalke
fa6ee0557e Rework ch03 for most recent version of Bitcoin Core 2017-10-19 22:35:15 +02:00
cclauss
b8a0cddb9f from __future__ import print_function 2017-09-06 07:23:23 +02:00
cclauss
a47fa095cf from __future__ import print_function
`from __future__ import print_function` to bring the print function from Python 3 into Python 2.6 and 2.7.

Properly deals with comma separated values in print() function.
2017-09-06 06:44:52 +02:00
Will Binns
64f851da26 Merge pull request #367 from cclauss/patch-3
Trailing L not needed in Py2 & Syntax Error in Py3
2017-09-05 20:28:22 -06:00
cclauss
14138a859f Trailing L not needed in Py2 & Syntax Error in Py3
Also print() function, ternary if, avoid backslashes.
2017-08-24 19:07:00 +02:00
cclauss
df302e9fe5 long() and print() for Python 3 2017-08-24 18:44:48 +02:00
cclauss
35fef9a94f long(), print(), xrange() for Python 3
Also remove trailing whitespace
2017-08-24 18:37:02 +02:00
cclauss
3c0b24edd7 print() function for Python 3 2017-08-24 18:29:06 +02:00
cclauss
cb1053f905 print() function for Python 3
Also ternary if
2017-08-24 18:27:27 +02:00
cclauss
bdc3743e30 print() and range() for Python 3 2017-08-24 18:22:28 +02:00
cclauss
06ecaf9168 print() function for Python 3 2017-08-24 18:20:22 +02:00
cclauss
5f3a3d4469 print() function for Python 3 2017-08-24 18:14:02 +02:00
cclauss
f396920189 from __future__ import print_function
Support print('xyz', end='') on Python 2
2017-07-23 10:21:30 +02:00
Andreas M. Antonopoulos
d930042fc6 code fixes to update to libbitcoin v3 2017-07-18 12:07:31 +08:00
Andreas M. Antonopoulos
97496a50fb fixes to code example 2017-07-18 11:37:12 +08:00
Nick Adams
c05329d9cf PR edits through Ch 5 2017-05-09 16:16:06 -04:00
Andreas M. Antonopoulos
611f6514a2 Updated BIP appendix 2017-04-23 13:07:48 +02:00
Andreas M. Antonopoulos
572667c69c Merge pull request #177 from kristjanr/develop
Fix unorderable types error&make code more uniform
2016-12-16 16:37:05 +02:00
Andreas M. Antonopoulos
54de3ac14d transaction fees 2016-12-12 15:00:27 +02:00
Will Binns
3e863bcf9c
code/satoshi-words: save_script, use const. 2016-10-16 12:10:05 -06:00
Andreas M. Antonopoulos
4d15f0aad3 ch03 rpc API, code examples, libraries 2016-02-04 20:52:15 -06:00
Kristjan Roosild
980363b6e1 Fix unorderable types error&make code more uniform 2015-07-29 15:07:36 +03:00
Andreas M. Antonopoulos
6040e26579 Addressing errata 152498 2015-03-03 11:57:53 -05:00
Andreas M. Antonopoulos
b841235043 Addressing errate 151301 2015-02-23 18:09:27 -05:00
Andreas M. Antonopoulos
3a7b435d85 removed time module as it is no longer used in this example 2015-02-23 17:54:19 -05:00
Andreas M. Antonopoulos
cd210e356a Addressing errata 151300 2015-02-23 17:53:30 -05:00
Amir Taaki
e827ff5c86 delete uneeded code, replace with bc::hash_literal as per William Swanson (s_tec)'s comment. 2015-01-21 22:29:43 +01:00
Amir Taaki
d44f6aaf92 switch to decode_base16() per William Swanson (s_tec)'s comment. 2015-01-21 22:26:26 +01:00