bitcoin-ruby 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.travis.yml +2 -2
  4. data/COPYING +1 -1
  5. data/Gemfile +5 -11
  6. data/README.rdoc +11 -5
  7. data/Rakefile +5 -0
  8. data/bin/bitcoin_node +11 -29
  9. data/bin/bitcoin_node_cli +81 -0
  10. data/bin/bitcoin_wallet +9 -6
  11. data/doc/NODE.rdoc +79 -26
  12. data/examples/bbe_verify_tx.rb +1 -1
  13. data/examples/index_nhash.rb +24 -0
  14. data/examples/reindex_p2sh_addrs.rb +44 -0
  15. data/lib/bitcoin.rb +135 -20
  16. data/lib/bitcoin/builder.rb +233 -63
  17. data/lib/bitcoin/key.rb +89 -16
  18. data/lib/bitcoin/litecoin.rb +13 -11
  19. data/lib/bitcoin/namecoin.rb +5 -4
  20. data/lib/bitcoin/network/command_client.rb +23 -13
  21. data/lib/bitcoin/network/command_handler.rb +336 -131
  22. data/lib/bitcoin/network/connection_handler.rb +14 -13
  23. data/lib/bitcoin/network/node.rb +61 -20
  24. data/lib/bitcoin/protocol.rb +5 -1
  25. data/lib/bitcoin/protocol/block.rb +15 -3
  26. data/lib/bitcoin/protocol/parser.rb +3 -3
  27. data/lib/bitcoin/protocol/tx.rb +82 -20
  28. data/lib/bitcoin/protocol/txin.rb +7 -0
  29. data/lib/bitcoin/protocol/txout.rb +12 -9
  30. data/lib/bitcoin/script.rb +329 -75
  31. data/lib/bitcoin/storage/dummy/dummy_store.rb +23 -4
  32. data/lib/bitcoin/storage/models.rb +6 -11
  33. data/lib/bitcoin/storage/sequel/migrations/005_change_tx_hash_to_bytea.rb +14 -0
  34. data/lib/bitcoin/storage/sequel/migrations/006_add_tx_nhash.rb +31 -0
  35. data/lib/bitcoin/storage/sequel/migrations/007_add_prev_out_index_index.rb +16 -0
  36. data/lib/bitcoin/storage/sequel/migrations/008_add_txin_p2sh_type.rb +31 -0
  37. data/lib/bitcoin/storage/sequel/migrations/009_add_addrs_type.rb +56 -0
  38. data/lib/bitcoin/storage/sequel/sequel_store.rb +168 -70
  39. data/lib/bitcoin/storage/storage.rb +161 -97
  40. data/lib/bitcoin/storage/utxo/migrations/002_utxo.rb +1 -1
  41. data/lib/bitcoin/storage/utxo/migrations/004_add_addrs_type.rb +14 -0
  42. data/lib/bitcoin/storage/utxo/utxo_store.rb +25 -12
  43. data/lib/bitcoin/validation.rb +87 -56
  44. data/lib/bitcoin/version.rb +1 -1
  45. data/spec/bitcoin/bitcoin_spec.rb +38 -0
  46. data/spec/bitcoin/builder_spec.rb +177 -0
  47. data/spec/bitcoin/fixtures/litecoin-tx-f5aa30f574e3b6f1a3d99c07a6356ba812aabb9661e1d5f71edff828cbd5c996.json +259 -0
  48. data/spec/bitcoin/fixtures/rawblock-testnet-265322.bin +0 -0
  49. data/spec/bitcoin/fixtures/tx-0295028ef826b2a188409cb905b631faebb9bb3cdf14510571c5f4bd8591338f.json +64 -0
  50. data/spec/bitcoin/fixtures/tx-03339a725007a279484fb6f5361f522dd1cf4d0923d30e6b973290dba4275f92.json +64 -0
  51. data/spec/bitcoin/fixtures/tx-0ce7e5238fbdb6c086cf1b384b21b827e91cc23f360417265874a5a0d86ce367.json +64 -0
  52. data/spec/bitcoin/fixtures/tx-0ef34c49f630aea17df0080728b0fc67bf5f87fbda936934a4b11b4a69d7821e.json +64 -0
  53. data/spec/bitcoin/fixtures/tx-1129d2a8bd5bb3a81e54dc96a90f1f6b2544575748caa17243470935c5dd91b7.json +28 -0
  54. data/spec/bitcoin/fixtures/tx-19aa42fee0fa57c45d3b16488198b27caaacc4ff5794510d0c17f173f05587ff.json +23 -0
  55. data/spec/bitcoin/fixtures/tx-1a4f3b9dc4494aeedeb39f30dd37e60541b2abe3ed4977992017cc0ad4f44956.json +64 -0
  56. data/spec/bitcoin/fixtures/tx-1f9191dcf2b1844ca28c6ef4b969e1d5fab70a5e3c56b7007949e55851cb0c4f.json +64 -0
  57. data/spec/bitcoin/fixtures/tx-22cd5fef23684d7b304e119bedffde6f54538d3d54a5bfa237e20dc2d9b4b5ad.json +64 -0
  58. data/spec/bitcoin/fixtures/tx-2958fb00b4fd6fe0353503b886eb9a193d502f4fd5fc042d5e03216ba918bbd6.json +64 -0
  59. data/spec/bitcoin/fixtures/tx-29f277145749ad6efbed3ae6ce301f8d33c585ec26b7c044ad93c2f866e9e942.json +64 -0
  60. data/spec/bitcoin/fixtures/tx-2c5e5376c20e9cc78d0fb771730e5d840cc2096eff0ef045b599fe92475ace1c.json +28 -0
  61. data/spec/bitcoin/fixtures/tx-2c63aa814701cef5dbd4bbaddab3fea9117028f2434dddcdab8339141e9b14d1.json +30 -0
  62. data/spec/bitcoin/fixtures/tx-326882a7f22b5191f1a0cc9962ca4b878cd969cf3b3a70887aece4d801a0ba5e.json +23 -0
  63. data/spec/bitcoin/fixtures/tx-345bed8785c3282a264ffb0dbee61cde54854f10e16f1b3e75b7f2d9f62946f2.json +64 -0
  64. data/spec/bitcoin/fixtures/tx-39ba7440b7103557560cc8ce258009936796485aaf8b478e66ab4cb97c66e31b.json +32 -0
  65. data/spec/bitcoin/fixtures/tx-3a04d57a833367f1655cc5ec3beb587888ef4977a86caa8c8ad4ba7cc717eae7.json +64 -0
  66. data/spec/bitcoin/fixtures/tx-4142ee4877eb116abf955a7ec6ef2dc38133b793df762b76d75e3d7d4d8badc9.json +38 -0
  67. data/spec/bitcoin/fixtures/tx-46224764c7870f95b58f155bce1e38d4da8e99d42dbb632d0dd7c07e092ee5aa.json +23 -0
  68. data/spec/bitcoin/fixtures/tx-5df1375ffe61ac35ca178ebb0cab9ea26dedbd0e96005dfcee7e379fa513232f.json +30 -0
  69. data/spec/bitcoin/fixtures/tx-62d9a565bd7b5344c5352e3e9e5f40fa4bbd467fa19c87357216ec8777ba1cce.json +64 -0
  70. data/spec/bitcoin/fixtures/tx-6327783a064d4e350c454ad5cd90201aedf65b1fc524e73709c52f0163739190.json +23 -0
  71. data/spec/bitcoin/fixtures/tx-6606c366a487bff9e412d0b6c09c14916319932db5954bf5d8719f43f828a3ba.json +27 -0
  72. data/spec/bitcoin/fixtures/tx-6aaf18b9f1283b939d8e5d40ff5f8a435229f4178372659cc3a0bce4e262bf78.json +28 -0
  73. data/spec/bitcoin/fixtures/tx-6b48bba6f6d2286d7ec0883c0fc3085955090813a4c94980466611c798b868cc.json +64 -0
  74. data/spec/bitcoin/fixtures/tx-70cfbc6690f9ab46712db44e3079ac227962b2771a9341d4233d898b521619ef.json +40 -0
  75. data/spec/bitcoin/fixtures/tx-7a1a9db42f065f75110fcdb1bc415549c8ef7670417ba1d35a67f1b8adc562c1.json +64 -0
  76. data/spec/bitcoin/fixtures/tx-9a768fc7d0c4bdc86e25154357ef7c0063ca21310e5740a2f12f90b7455184a7.json +64 -0
  77. data/spec/bitcoin/fixtures/tx-9cad8d523a0694f2509d092c39cebc8046adae62b4e4297102d568191d9478d8.json +64 -0
  78. data/spec/bitcoin/fixtures/tx-9e052eb694bd7e15906433f064dff0161a12fd325c1124537766377004023c6f.json +64 -0
  79. data/spec/bitcoin/fixtures/tx-a955032f4d6b0c9bfe8cad8f00a8933790b9c1dc28c82e0f48e75b35da0e4944.json +23 -0
  80. data/spec/bitcoin/fixtures/tx-aab7ef280abbb9cc6fbaf524d2645c3daf4fcca2b3f53370e618d9cedf65f1f8.json +23 -0
  81. data/spec/bitcoin/fixtures/tx-ab9805c6d57d7070d9a42c5176e47bb705023e6b67249fb6760880548298e742.json +27 -0
  82. data/spec/bitcoin/fixtures/tx-ad4bcf3241e5d2ad140564e20db3567d41594cf4c2012433fe46a2b70e0d87b8.json +64 -0
  83. data/spec/bitcoin/fixtures/tx-b5b598de91787439afd5938116654e0b16b7a0d0f82742ba37564219c5afcbf9.json +27 -0
  84. data/spec/bitcoin/fixtures/tx-b8fd633e7713a43d5ac87266adc78444669b987a56b3a65fb92d58c2c4b0e84d.json +28 -0
  85. data/spec/bitcoin/fixtures/tx-bbca0628c42cb8bf7c3f4b2ad688fa56da5308dd2a10255da89fb1f46e6e413d.json +36 -0
  86. data/spec/bitcoin/fixtures/tx-bc7fd132fcf817918334822ee6d9bd95c889099c96e07ca2c1eb2cc70db63224.json +23 -0
  87. data/spec/bitcoin/fixtures/tx-c192b74844e4837a34c4a5a97b438f1c111405b01b99e2d12b7c96d07fc74c04.json +28 -0
  88. data/spec/bitcoin/fixtures/tx-e335562f7e297aadeed88e5954bc4eeb8dc00b31d829eedb232e39d672b0c009.json +406 -0
  89. data/spec/bitcoin/fixtures/tx-eb3b82c0884e3efa6d8b0be55b4915eb20be124c9766245bcc7f34fdac32bccb.json +35 -0
  90. data/spec/bitcoin/fixtures/tx-fee1b9b85531c8fb6cd7831f83490c7f2aa768b6eefe29854ef5e89ce7b9ecb1.json +64 -0
  91. data/spec/bitcoin/fixtures/txscript-invalid-too-many-sigops-followed-by-invalid-pushdata.bin +1 -0
  92. data/spec/bitcoin/helpers/fake_blockchain.rb +183 -0
  93. data/spec/bitcoin/key_spec.rb +79 -8
  94. data/spec/bitcoin/namecoin_spec.rb +1 -1
  95. data/spec/bitcoin/node/command_api_spec.rb +373 -86
  96. data/spec/bitcoin/performance/storage_spec.rb +41 -0
  97. data/spec/bitcoin/protocol/addr_spec.rb +7 -5
  98. data/spec/bitcoin/protocol/aux_pow_spec.rb +1 -0
  99. data/spec/bitcoin/protocol/block_spec.rb +6 -0
  100. data/spec/bitcoin/protocol/tx_spec.rb +184 -1
  101. data/spec/bitcoin/protocol/txin_spec.rb +27 -0
  102. data/spec/bitcoin/protocol/txout_spec.rb +27 -0
  103. data/spec/bitcoin/script/opcodes_spec.rb +74 -3
  104. data/spec/bitcoin/script/script_spec.rb +271 -0
  105. data/spec/bitcoin/spec_helper.rb +34 -6
  106. data/spec/bitcoin/storage/models_spec.rb +104 -0
  107. data/spec/bitcoin/storage/reorg_spec.rb +42 -11
  108. data/spec/bitcoin/storage/storage_spec.rb +58 -15
  109. data/spec/bitcoin/storage/validation_spec.rb +44 -14
  110. data/spec/bitcoin/wallet/keygenerator_spec.rb +6 -3
  111. data/spec/bitcoin/wallet/keystore_spec.rb +3 -3
  112. data/spec/bitcoin/wallet/wallet_spec.rb +87 -89
  113. metadata +117 -11
@@ -0,0 +1,35 @@
1
+ {
2
+ "hash": "eb3b82c0884e3efa6d8b0be55b4915eb20be124c9766245bcc7f34fdac32bccb",
3
+ "ver": 1,
4
+ "vin_sz": 2,
5
+ "vout_sz": 2,
6
+ "lock_time": 0,
7
+ "size": 376,
8
+ "in": [
9
+ {
10
+ "prev_out": {
11
+ "hash": "b8fd633e7713a43d5ac87266adc78444669b987a56b3a65fb92d58c2c4b0e84d",
12
+ "n": 0
13
+ },
14
+ "scriptSig": "304502205b282fbc9b064f3bc823a23edcc0048cbb174754e7aa742e3c9f483ebe02911c022100e4b0b3a117d36cab5a67404dddbf43db7bea3c1530e0fe128ebc15621bd69a3b01 035aa98d5f77cd9a2d88710e6fc66212aff820026f0dad8f32d1f7ce87457dde50"
15
+ },
16
+ {
17
+ "prev_out": {
18
+ "hash": "b8fd633e7713a43d5ac87266adc78444669b987a56b3a65fb92d58c2c4b0e84d",
19
+ "n": 1
20
+ },
21
+ "scriptSig": "0 30440220276d6dad3defa37b5f81add3992d510d2f44a317fd85e04f93a1e2daea64660202200f862a0da684249322ceb8ed842fb8c859c0cb94c81e1c5308b4868157a428ee01 OP_CODESEPARATOR 1 0232abdc893e7f0631364d7fd01cb33d24da45329a00357b3a7886211ab414d55a 1 OP_CHECKMULTISIG"
22
+ }
23
+ ],
24
+ "out": [
25
+ {
26
+ "value": "0.01900000",
27
+ "scriptPubKey": "OP_DUP OP_HASH160 380cb3c594de4e7e9b8e18db182987bebb5a4f70 OP_EQUALVERIFY OP_CHECKSIG"
28
+ },
29
+ {
30
+ "value": "0.03000000",
31
+ "scriptPubKey": "2a9bc5447d664c1d0141392a842d23dba45c4f13 OP_NOP2 OP_DROP"
32
+ }
33
+ ],
34
+ "nid": "d268093bef26d5ca68edd23ed020f46dd3c1abf068964327726463f2f8e001ee"
35
+ }
@@ -0,0 +1,64 @@
1
+ {
2
+ "hash": "fee1b9b85531c8fb6cd7831f83490c7f2aa768b6eefe29854ef5e89ce7b9ecb1",
3
+ "ver": 1,
4
+ "vin_sz": 1,
5
+ "vout_sz": 11,
6
+ "lock_time": 0,
7
+ "size": 357,
8
+ "in": [
9
+ {
10
+ "prev_out": {
11
+ "hash": "5619cf0ae79039401fffe9193b7de5f6236cb78ced2d17d66b0f1f6c970a3022",
12
+ "n": 5
13
+ },
14
+ "scriptSig": "3046022100b6ee15095f496a52583eaaa913f6f72e6a9340d24ada3d717cbb9752afeabeb302210089740020ee62983e68177dbbb0debaeb58a904e6f46e007ed28992931665450701 0431facc67afecd5bf3aa2e81805d1aef2912bb203e70e29dedf5d2cac3a943317e9e8eb8f329791f1b81dc15f0f44a85afb2e0bfd74d490bd059d86bb3dbb5775"
15
+ }
16
+ ],
17
+ "out": [
18
+ {
19
+ "value": "0.07100000",
20
+ "scriptPubKey": "feffffff80 OP_EQUAL"
21
+ },
22
+ {
23
+ "value": "0.04100000",
24
+ "scriptPubKey": "OP_DUP 1 OP_ADD 1 OP_EQUALVERIFY 0 OP_EQUAL"
25
+ },
26
+ {
27
+ "value": "0.02100000",
28
+ "scriptPubKey": "OP_EQUAL"
29
+ },
30
+ {
31
+ "value": "0.01100000",
32
+ "scriptPubKey": "0 OP_PICK 0:1:14 OP_EQUALVERIFY OP_DEPTH 3 OP_EQUAL"
33
+ },
34
+ {
35
+ "value": "0.06100000",
36
+ "scriptPubKey": "90 OP_NEGATE OP_EQUAL"
37
+ },
38
+ {
39
+ "value": "0.03100000",
40
+ "scriptPubKey": "OP_NOT"
41
+ },
42
+ {
43
+ "value": "0.10100000",
44
+ "scriptPubKey": "OP_SIZE 3 OP_EQUAL"
45
+ },
46
+ {
47
+ "value": "4.30550000",
48
+ "scriptPubKey": "OP_DUP OP_HASH160 90d66e5f44e597006a8f65767c7e1cf78fe56218 OP_EQUALVERIFY OP_CHECKSIG"
49
+ },
50
+ {
51
+ "value": "0.08100000",
52
+ "scriptPubKey": "OP_TUCK OP_DEPTH 3 OP_EQUALVERIFY OP_SWAP OP_2DROP"
53
+ },
54
+ {
55
+ "value": "0.09100000",
56
+ "scriptPubKey": "OP_NOP"
57
+ },
58
+ {
59
+ "value": "0.05100000",
60
+ "scriptPubKey": "OP_IF 1 OP_ELSE OP_ENDIF"
61
+ }
62
+ ],
63
+ "nid": "d408e9c5639a542bd31f9a24a64d1cd38dc6db3cb222a7ae55874ca4b97bd85e"
64
+ }
@@ -0,0 +1 @@
1
+ ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������N��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
@@ -0,0 +1,183 @@
1
+ require_relative '../spec_helper'
2
+ require 'fileutils'
3
+
4
+ Bitcoin::NETWORKS[:fake] = {
5
+ :project => :bitcoin,
6
+ :no_difficulty => true,
7
+ :magic_head => "fake",
8
+ :address_version => "00",
9
+ :p2sh_version => "05",
10
+ :privkey_version => "80",
11
+ :default_port => 78333,
12
+ :coinbase_maturity => 0,
13
+ :protocol_version => 70001,
14
+ :max_money => 21_000_000 * 100_000_000,
15
+ :dns_seeds => [],
16
+ :genesis_hash => "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943",
17
+ :proof_of_work_limit => 553713663,
18
+ :alert_pubkeys => [],
19
+ :known_nodes => [],
20
+ :checkpoints => {},
21
+ :min_tx_fee => 10_000,
22
+ :min_relay_tx_fee => 10_000,
23
+ }
24
+
25
+
26
+
27
+ # Small utility to generate fake blocks mostly to be able to test performance
28
+ # They are full from the start, so that we don't have to import 100K blocks to check
29
+ # how performance looks when storing or validating 1K transactions
30
+ class FakeBlockchain
31
+
32
+ # Initialize fake blockchain and generate +num_blocks+ starting blocks with given
33
+ # +opts+ (see #generate).
34
+ def initialize(num = 50, opts = {})
35
+ Bitcoin.network = :fake
36
+ if File.exist? block_path(0)
37
+ genesis = Bitcoin::P::Block.new File.read block_path 0
38
+ Bitcoin.network[:genesis_hash] = genesis.hash
39
+ else
40
+ STDERR.puts "\nFake blockchain not present, generating (go take a nap)..."
41
+ depth = 0
42
+ FileUtils.mkdir_p fixtures_path "fake_chain"
43
+ generate(num, opts) do |blk|
44
+ File.open(block_path(depth),'w') {|f| f.write blk.to_payload }
45
+ depth += 1
46
+ end
47
+ end
48
+ end
49
+
50
+ # Generate fake blockchain with +num+ number of blocks
51
+ # Blocks are provided as an argument to the block given to the method
52
+ # fake_chain.generate(5) {|b| save_block(b) }
53
+ def generate(num = 50, opts = {})
54
+ srand 1337
55
+
56
+ default_opts = {
57
+ block_size: 950_000, # minimum block size
58
+ num_keys: 1000, # number of different keys being used
59
+ genesis_timestamp: Time.new(2009).to_i,
60
+ verbose: true, # print out debug information
61
+ }
62
+
63
+ opts = default_opts.merge(opts)
64
+
65
+ to_spend = [] # table of outputs that we can spend
66
+ lost_count = 0 # keeping track of lost coins
67
+ keys = Array.new(opts[:num_keys]) { Bitcoin::Key.generate }
68
+ timestamp = opts[:genesis_timestamp]
69
+
70
+ genesis = Bitcoin::Builder.build_block do |blk|
71
+ blk.time timestamp
72
+ blk.prev_block "00"*32
73
+ blk.tx do |t|
74
+ t.input {|i| i.coinbase }
75
+ t.output {|o| o.value 50*Bitcoin::COIN; o.script {|s| s.recipient keys[0].addr } }
76
+ end
77
+ end
78
+ Bitcoin.network[:genesis_hash] = genesis.hash
79
+ yield(genesis)
80
+
81
+ to_spend << {tx: genesis.tx[0], tx_idx: 0, key: keys[0], value: 50e8}
82
+
83
+ prev_block = genesis
84
+
85
+
86
+ num.times do |blk_i|
87
+
88
+ timestamp += 600
89
+ t0 = Time.now
90
+
91
+ block = Bitcoin::Builder.build_block do |blk|
92
+ blk.time timestamp
93
+ blk.prev_block prev_block.hash
94
+ key0 = keys.sample
95
+ tx0 = blk.tx do |t|
96
+ t.input {|i| i.coinbase }
97
+ t.output {|o| o.value 50e8; o.script {|s| s.recipient key0.addr } }
98
+ end
99
+
100
+ # We "lose" some coins, that is we decide never to spend some outputs
101
+ # It's to keep utxo growing without making block generation time growing
102
+ lost_count += to_spend.size
103
+ to_spend = to_spend.reject.with_index {|x,i| i==0 ? false : (((to_spend.size - i) / to_spend.size.to_f)**2 * rand > rand*0.2) }
104
+ lost_count -= to_spend.size
105
+
106
+ # many txs vs many tx outputs in given block
107
+ many_outputs_prob = 0.5 * (rand ** 3)
108
+
109
+ total_tx_size = 0
110
+
111
+ # generate tranasctions
112
+ loop do
113
+ # we want utxo to keep growing so we use many inputs only with some small probability
114
+ ins = to_spend[(rand(to_spend.size)).to_i..-1].sample(rand < 0.01 ? (rand(50) + 1) : 1)
115
+ total = ins.map{|i| i[:value]}.inject(:+)
116
+ next if total < 20_000
117
+
118
+ new_outs = []
119
+
120
+ tx = blk.tx do |t|
121
+
122
+ # generate inputs
123
+ ins.map do |input|
124
+ t.input do |i|
125
+ i.prev_out input[:tx]
126
+ i.prev_out_index input[:tx_idx]
127
+ i.signature_key input[:key]
128
+ end
129
+ end
130
+ # remove outputs that we just used
131
+ ins.each {|i| to_spend.delete i}
132
+
133
+ fee = 10_000
134
+ # helper to split value randomly in a half
135
+ half_split = ->(v) { split = [rand, 0.1].max; [v*split, v*(1-split)] }
136
+ # helper to split value randomly to many pieces
137
+ value_split = ->(v, depth=0) {(depth < 10 && rand > 0.2) ? half_split[v].map{|x| value_split[x, depth+1]} : [v] }
138
+
139
+ if rand < many_outputs_prob
140
+ # every now and then there are many outptus
141
+ out_values = value_split[total-fee].flatten.map {|x| x.round(8)}
142
+ out_values.each.with_index do |v,i|
143
+ key = keys.sample
144
+ t.output {|o| o.value v; o.script {|s| s.recipient key.addr }}
145
+ new_outs << {tx_idx: i, key: key, value: v}
146
+ end
147
+ else
148
+ # most txs seem to have 2 outputs
149
+ k1 = keys.sample
150
+ k2 = keys.sample
151
+ v1, v2 = half_split[total-fee]
152
+ t.output {|o| o.value v1; o.script {|s| s.recipient k1.addr }}
153
+ t.output {|o| o.value v2; o.script {|s| s.recipient k2.addr }}
154
+ new_outs << {tx_idx: 0, key: k1, value: v2}
155
+ new_outs << {tx_idx: 1, key: k2, value: v2}
156
+ end
157
+ end
158
+
159
+ new_outs.each {|o| to_spend << {tx: tx}.merge(o) } # fun fact: the opposite merge is way slower
160
+
161
+ total_tx_size += tx.to_payload.size
162
+ break if total_tx_size > opts[:block_size]
163
+ end
164
+
165
+ # coinbase
166
+ to_spend << {tx: tx0, tx_idx: 0, key: key0, value: 50e8}
167
+ end
168
+ puts "depth #{blk_i+1}/#{num} \t txcount: #{block.tx.size} \t size: #{block.to_payload.size} \t utxo count: #{to_spend.size + lost_count} (#{to_spend.size}) \t ttg: #{'%.2f' % (Time.now - t0)}s" if opts[:verbose]
169
+ yield(block)
170
+ prev_block = block
171
+ end
172
+ true
173
+ end
174
+
175
+ def block(depth)
176
+ Bitcoin::Protocol::Block.new File.read block_path depth
177
+ end
178
+
179
+ def block_path(depth)
180
+ fixtures_path "fake_chain/#{depth}.blk"
181
+ end
182
+
183
+ end
@@ -8,21 +8,42 @@ describe "Bitcoin::Key" do
8
8
  Bitcoin.network = :bitcoin
9
9
  @key_data = {
10
10
  :priv => "2ebd3738f59ae4fd408d717bf325b4cb979a409b0153f6d3b4b91cdfe046fb1e",
11
- :pub => "045fcb2fb2802b024f371cc22bc392268cc579e47e7936e0d1f05064e6e1103b8a81954eb6d3d33b8b6e73e9269013e843e83919f7ce4039bb046517a0cad5a3b1" }
12
- @key = Bitcoin::Key.new(@key_data[:priv], @key_data[:pub])
11
+ :pub => "035fcb2fb2802b024f371cc22bc392268cc579e47e7936e0d1f05064e6e1103b8a" }
12
+ @key = Bitcoin::Key.new(@key_data[:priv], @key_data[:pub], false)
13
13
  end
14
14
 
15
15
  it "should generate a key" do
16
16
  k = Bitcoin::Key.generate
17
17
  k.priv.size.should == 64
18
+ k.pub.size.should == 66
19
+ k.compressed.should == true
20
+
21
+ k = Bitcoin::Key.generate(compressed: true)
22
+ k.priv.size.should == 64
23
+ k.pub.size.should == 66
24
+ k.compressed.should == true
25
+
26
+ k = Bitcoin::Key.generate(true)
27
+ k.priv.size.should == 64
28
+ k.pub.size.should == 66
29
+ k.compressed.should == true
30
+
31
+ k = Bitcoin::Key.generate(compressed: false)
32
+ k.priv.size.should == 64
18
33
  k.pub.size.should == 130
19
- #p k.priv, k.pub
34
+ k.compressed.should == false
35
+
36
+ k = Bitcoin::Key.generate(false)
37
+ k.priv.size.should == 64
38
+ k.pub.size.should == 130
39
+ k.compressed.should == false
20
40
  end
21
41
 
22
42
  it "should create empty key" do
23
43
  k = Bitcoin::Key.new
24
44
  k.priv.should == nil
25
45
  k.pub.should == nil
46
+ k.compressed.should == true
26
47
  end
27
48
 
28
49
  it "should create key from priv + pub" do
@@ -56,6 +77,8 @@ describe "Bitcoin::Key" do
56
77
  end
57
78
 
58
79
  it "should get addr" do
80
+ @key.addr.should == "19CyxBz6CUBogxTdSXUrbRHo7T7eLCMgbr"
81
+ @key.instance_eval { @pubkey_compressed = false }
59
82
  @key.addr.should == "1JbYZRKyysprVjSSBobs8LX6QVjzsscQNU"
60
83
  end
61
84
 
@@ -63,12 +86,18 @@ describe "Bitcoin::Key" do
63
86
  @key.sign("foobar").size.should >= 69
64
87
  end
65
88
 
66
- it "should verify signature" do
89
+ it "should verify signature using public key" do
67
90
  sig = @key.sign("foobar")
68
91
  key = Bitcoin::Key.new(nil, @key.pub)
69
92
  key.verify("foobar", sig).should == true
70
93
  end
71
94
 
95
+ it "should verify signature using private key" do
96
+ sig = @key.sign("foobar")
97
+ key = Bitcoin::Key.new(@key.priv)
98
+ key.verify("foobar", sig).should == true
99
+ end
100
+
72
101
  it "recovers public keys from compact signatures" do
73
102
  tests = [
74
103
  # normal
@@ -103,10 +132,10 @@ describe "Bitcoin::Key" do
103
132
 
104
133
  it "should export private key in base58 format" do
105
134
  Bitcoin.network = :bitcoin
106
- str = Bitcoin::Key.new("e9873d79c6d87dc0fb6a5778633389f4453213303da61f20bd67fc233aa33262").to_base58
135
+ str = Bitcoin::Key.new("e9873d79c6d87dc0fb6a5778633389f4453213303da61f20bd67fc233aa33262", nil, false).to_base58
107
136
  str.should == "5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF"
108
137
  Bitcoin.network = :testnet
109
- str = Bitcoin::Key.new("d21fa2c7ad710ffcd9bcc22a9f96357bda1a2521ca7181dd610140ecea2cecd8").to_base58
138
+ str = Bitcoin::Key.new("d21fa2c7ad710ffcd9bcc22a9f96357bda1a2521ca7181dd610140ecea2cecd8", nil, false).to_base58
110
139
  str.should == "93BTVFoqffueSaC5fqjLjLyn29S41JzvAZm2hC35SYMoYDXT1bY"
111
140
  Bitcoin.network = :bitcoin
112
141
  end
@@ -130,13 +159,15 @@ describe "Bitcoin::Key" do
130
159
  Bitcoin.network = :testnet3
131
160
  Bitcoin::Key.new("e3ff5d7e592669d0c1714f1496b260815edd0c3a00186e896dc7f36ede914dd2",
132
161
  nil, true).to_base58.should == "cVDu6aXUWHTM2vpztZW14BMnKkCcd5th6177VnCsa8XozoMyp73C"
133
- Bitcoin.network = :bitcoin end
162
+ Bitcoin.network = :bitcoin
163
+ end
134
164
 
135
165
  it "should import private key in compressed base58 format" do
136
166
  Bitcoin.network = :bitcoin
137
167
  key = Bitcoin::Key.from_base58("L2LusdhGSagfUVvNWrUuPDygn5mdAhxUDEANfABvBj36Twn1mKgQ")
138
168
  key.priv.should == "98e4483a197fb686fe9afb51389f329aabc67964b1d0e0a5340c962a0d63c44a"
139
169
  key.pub.should == "02e054ee811165ac294c992ff410067db6491228725fe09db2a415493c897973a8"
170
+ key.compressed.should == true
140
171
  key.addr.should == "1C7Ni4zuV3zfLs8T1S7s29wNAtRoDHHnpw"
141
172
  Bitcoin.network = :testnet3
142
173
  key = Bitcoin::Key.from_base58("cVDu6aXUWHTM2vpztZW14BMnKkCcd5th6177VnCsa8XozoMyp73C")
@@ -146,7 +177,7 @@ describe "Bitcoin::Key" do
146
177
  Bitcoin.network = :bitcoin
147
178
  end
148
179
 
149
- it "should hanlde compressed and uncompressed pubkeys" do
180
+ it "should handle compressed and uncompressed pubkeys" do
150
181
  compressed = "0351efb6e91a31221652105d032a2508275f374cea63939ad72f1b1e02f477da78"
151
182
  uncompressed = "0451efb6e91a31221652105d032a2508275f374cea63939ad72f1b1e02f477da787f71a2e8ac5aacedab47904d4bd42f636429e9ce069ebcb99f675aad31306a53"
152
183
  Bitcoin::Key.new(nil, compressed).compressed.should == true
@@ -181,6 +212,46 @@ describe "Bitcoin::Key" do
181
212
  k.compressed.should == false
182
213
  end
183
214
 
215
+ it "should handle private key in bip38 (non-ec-multiply) format" do
216
+ k = Bitcoin::Key.from_base58("5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR")
217
+ k.to_bip38("TestingOneTwoThree").should == "6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg"
218
+
219
+ k = Bitcoin::Key.from_bip38("6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg", "TestingOneTwoThree")
220
+ k.to_base58.should == "5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR"
221
+
222
+ k = Bitcoin::Key.from_base58("5HtasZ6ofTHP6HCwTqTkLDuLQisYPah7aUnSKfC7h4hMUVw2gi5")
223
+ k.to_bip38("Satoshi").should == "6PRNFFkZc2NZ6dJqFfhRoFNMR9Lnyj7dYGrzdgXXVMXcxoKTePPX1dWByq"
224
+
225
+ k = Bitcoin::Key.from_bip38("6PRNFFkZc2NZ6dJqFfhRoFNMR9Lnyj7dYGrzdgXXVMXcxoKTePPX1dWByq", "Satoshi")
226
+ k.to_base58.should == "5HtasZ6ofTHP6HCwTqTkLDuLQisYPah7aUnSKfC7h4hMUVw2gi5"
227
+
228
+ k = Bitcoin::Key.from_base58("L44B5gGEpqEDRS9vVPz7QT35jcBG2r3CZwSwQ4fCewXAhAhqGVpP")
229
+ k.to_bip38("TestingOneTwoThree").should == "6PYNKZ1EAgYgmQfmNVamxyXVWHzK5s6DGhwP4J5o44cvXdoY7sRzhtpUeo"
230
+
231
+ k = Bitcoin::Key.from_bip38("6PYNKZ1EAgYgmQfmNVamxyXVWHzK5s6DGhwP4J5o44cvXdoY7sRzhtpUeo", "TestingOneTwoThree")
232
+ k.to_base58.should == "L44B5gGEpqEDRS9vVPz7QT35jcBG2r3CZwSwQ4fCewXAhAhqGVpP"
233
+
234
+ k = Bitcoin::Key.from_base58("KwYgW8gcxj1JWJXhPSu4Fqwzfhp5Yfi42mdYmMa4XqK7NJxXUSK7")
235
+ k.to_bip38("Satoshi").should == "6PYLtMnXvfG3oJde97zRyLYFZCYizPU5T3LwgdYJz1fRhh16bU7u6PPmY7"
236
+
237
+ k = Bitcoin::Key.from_bip38("6PYLtMnXvfG3oJde97zRyLYFZCYizPU5T3LwgdYJz1fRhh16bU7u6PPmY7", "Satoshi")
238
+ k.to_base58.should == "KwYgW8gcxj1JWJXhPSu4Fqwzfhp5Yfi42mdYmMa4XqK7NJxXUSK7"
239
+ end
240
+
241
+ it "should generate private key from warp format" do
242
+ k = Bitcoin::Key.from_warp("ER8FT+HFjk0", "7DpniYifN6c")
243
+ k.addr.should == "1J32CmwScqhwnNQ77cKv9q41JGwoZe2JYQ"
244
+ k.to_base58.should == "5JfEekYcaAexqcigtFAy4h2ZAY95vjKCvS1khAkSG8ATo1veQAD"
245
+
246
+ k = Bitcoin::Key.from_warp("YqIDBApDYME", "G34HqIgjrIc")
247
+ k.addr.should == "19aKBeXe2mi4NbQRpYUrCLZtRDHDUs9J7J"
248
+ k.to_base58.should == "5KUJA5iZ2zS7AXkU2S8BiBVY3xj6F8GspLfWWqL9V7CajXumBQV"
249
+
250
+ k = Bitcoin::Key.from_warp("FPdAxCygMJg", "X+qaSwhUYXw")
251
+ k.addr.should == "14Pqeo9XNRxjtKFFYd6TvRrJuZxVpciS81"
252
+ k.to_base58.should == "5JBAonQ4iGKFJxENExZghDtAS6YB8BsCw5mwpHSvZvP3Q2UxmT1"
253
+ end
254
+
184
255
  end
185
256
 
186
257
  begin
@@ -89,7 +89,7 @@ describe 'Bitcoin::Namecoin' do
89
89
 
90
90
  before do
91
91
  Bitcoin.network = :namecoin
92
- class Bitcoin::Validation::Block; def difficulty; true; end; end
92
+ Bitcoin.network[:no_difficulty] = true
93
93
  class Bitcoin::Validation::Block; def min_timestamp; true; end; end
94
94
  Bitcoin.network[:proof_of_work_limit] = Bitcoin.encode_compact_bits("ff"*32)
95
95
  [:name_new, :name_firstupdate, :name_update].each {|type|