bitcoin-ruby 0.0.18 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +8 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +46 -0
  5. data/.travis.yml +5 -1
  6. data/Gemfile +11 -9
  7. data/Gemfile.lock +64 -12
  8. data/README.rdoc +17 -4
  9. data/Rakefile +58 -83
  10. data/bitcoin-ruby.gemspec +5 -2
  11. data/lib/bitcoin.rb +31 -14
  12. data/lib/bitcoin/bech32.rb +126 -132
  13. data/lib/bitcoin/bloom_filter.rb +24 -21
  14. data/lib/bitcoin/builder.rb +168 -126
  15. data/lib/bitcoin/connection.rb +21 -24
  16. data/lib/bitcoin/contracthash.rb +20 -24
  17. data/lib/bitcoin/dogecoin.rb +79 -77
  18. data/lib/bitcoin/electrum/mnemonic.rb +28 -25
  19. data/lib/bitcoin/ext_key.rb +3 -3
  20. data/lib/bitcoin/ffi/bitcoinconsensus.rb +17 -13
  21. data/lib/bitcoin/ffi/openssl.rb +355 -338
  22. data/lib/bitcoin/ffi/secp256k1.rb +97 -64
  23. data/lib/bitcoin/protocol.rb +6 -3
  24. data/lib/bitcoin/protocol/address.rb +15 -13
  25. data/lib/bitcoin/protocol/aux_pow.rb +12 -15
  26. data/lib/bitcoin/protocol/block.rb +102 -76
  27. data/lib/bitcoin/protocol/handler.rb +2 -4
  28. data/lib/bitcoin/protocol/parser.rb +108 -92
  29. data/lib/bitcoin/protocol/partial_merkle_tree.rb +59 -47
  30. data/lib/bitcoin/protocol/reject.rb +26 -28
  31. data/lib/bitcoin/protocol/script_witness.rb +3 -8
  32. data/lib/bitcoin/protocol/tx.rb +250 -137
  33. data/lib/bitcoin/protocol/txin.rb +44 -38
  34. data/lib/bitcoin/protocol/txout.rb +27 -20
  35. data/lib/bitcoin/protocol/version.rb +47 -34
  36. data/lib/bitcoin/script.rb +18 -17
  37. data/lib/bitcoin/trezor/mnemonic.rb +113 -98
  38. data/lib/bitcoin/version.rb +1 -1
  39. data/spec/examples.txt +399 -0
  40. data/spec/{bitcoin/fixtures → fixtures}/000000000000056b1a3d84a1e2b33cde8915a4b61c0cae14fca6d3e1490b4f98.json +0 -0
  41. data/spec/{bitcoin/fixtures → fixtures}/03d7e1fa4d5fefa169431f24f7798552861b255cd55d377066fedcd088fb0e99.json +0 -0
  42. data/spec/{bitcoin/fixtures → fixtures}/0961c660358478829505e16a1f028757e54b5bbf9758341a7546573738f31429.json +0 -0
  43. data/spec/{bitcoin/fixtures → fixtures}/0f24294a1d23efbb49c1765cf443fba7930702752aba6d765870082fe4f13cae.json +0 -0
  44. data/spec/{bitcoin/fixtures → fixtures}/156e6e1b84c5c3bd3a0927b25e4119fadce6e6d5186f363317511d1d680fae9a.json +0 -0
  45. data/spec/{bitcoin/fixtures → fixtures}/23b397edccd3740a74adb603c9756370fafcde9bcc4483eb271ecad09a94dd63.json +0 -0
  46. data/spec/{bitcoin/fixtures → fixtures}/315ac7d4c26d69668129cc352851d9389b4a6868f1509c6c8b66bead11e2619f.json +0 -0
  47. data/spec/{bitcoin/fixtures → fixtures}/35e2001b428891fefa0bfb73167c7360669d3cbd7b3aa78e7cad125ddfc51131.json +0 -0
  48. data/spec/{bitcoin/fixtures → fixtures}/3a17dace09ffb919ed627a93f1873220f4c975c1248558b18d16bce25d38c4b7.json +0 -0
  49. data/spec/{bitcoin/fixtures → fixtures}/3e58b7eed0fdb599019af08578effea25c8666bbe8e200845453cacce6314477.json +0 -0
  50. data/spec/{bitcoin/fixtures → fixtures}/514c46f0b61714092f15c8dfcb576c9f79b3f959989b98de3944b19d98832b58.json +0 -0
  51. data/spec/{bitcoin/fixtures → fixtures}/51bf528ecf3c161e7c021224197dbe84f9a8564212f6207baa014c01a1668e1e.json +0 -0
  52. data/spec/{bitcoin/fixtures → fixtures}/60a20bd93aa49ab4b28d514ec10b06e1829ce6818ec06cd3aabd013ebcdc4bb1.json +0 -0
  53. data/spec/{bitcoin/fixtures → fixtures}/69216b8aaa35b76d6613e5f527f4858640d986e1046238583bdad79b35e938dc.json +0 -0
  54. data/spec/{bitcoin/fixtures → fixtures}/7208e5edf525f04e705fb3390194e316205b8f995c8c9fcd8c6093abe04fa27d.json +0 -0
  55. data/spec/{bitcoin/fixtures → fixtures}/761d8c5210fdfd505f6dff38f740ae3728eb93d7d0971fb433f685d40a4c04f6.json +0 -0
  56. data/spec/{bitcoin/fixtures → fixtures}/8d0b238a06b5a70be75d543902d02d7a514d68d3252a949a513865ac3538874c.json +0 -0
  57. data/spec/{bitcoin/fixtures → fixtures}/aea682d68a3ea5e3583e088dcbd699a5d44d4b083f02ad0aaf2598fe1fa4dfd4.json +0 -0
  58. data/spec/{bitcoin/fixtures → fixtures}/base58_keys_invalid.json +0 -0
  59. data/spec/{bitcoin/fixtures → fixtures}/base58_keys_valid.json +0 -0
  60. data/spec/{bitcoin/fixtures → fixtures}/bc179baab547b7d7c1d5d8d6f8b0cc6318eaa4b0dd0a093ad6ac7f5a1cb6b3ba.json +0 -0
  61. data/spec/{bitcoin/fixtures → fixtures}/bd1715f1abfdc62bea3f605bdb461b3ba1f2cca6ec0d73a18a548b7717ca8531.json +0 -0
  62. data/spec/{bitcoin/fixtures → fixtures}/block-testnet-0000000000ac85bb2530a05a4214a387e6be02b22d3348abc5e7a5d9c4ce8dab.bin +0 -0
  63. data/spec/{bitcoin/fixtures → fixtures}/cd874fa8cb0e2ec2d385735d5e1fd482c4fe648533efb4c50ee53bda58e15ae2.json +0 -0
  64. data/spec/{bitcoin/fixtures → fixtures}/ce5fad9b4ef094d8f4937b0707edaf0a6e6ceeaf67d5edbfd51f660eac8f398b.json +0 -0
  65. data/spec/{bitcoin/fixtures → fixtures}/coinbase-toshi.json +0 -0
  66. data/spec/{bitcoin/fixtures → fixtures}/coinbase.json +0 -0
  67. data/spec/{bitcoin/fixtures → fixtures}/dogecoin-block-60323982f9c5ff1b5a954eac9dc1269352835f47c2c5222691d80f0d50dcf053.bin +0 -0
  68. data/spec/{bitcoin/fixtures → fixtures}/f003f0c1193019db2497a675fd05d9f2edddf9b67c59e677c48d3dbd4ed5f00b.json +0 -0
  69. data/spec/{bitcoin/fixtures → fixtures}/filteredblock-0.bin +0 -0
  70. data/spec/{bitcoin/fixtures → fixtures}/litecoin-block-80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f.bin +0 -0
  71. data/spec/{bitcoin/fixtures → fixtures}/litecoin-block-80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f.json +0 -0
  72. data/spec/{bitcoin/fixtures → fixtures}/litecoin-genesis-block-12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2.bin +0 -0
  73. data/spec/{bitcoin/fixtures → fixtures}/litecoin-genesis-block-12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2.json +0 -0
  74. data/spec/{bitcoin/fixtures → fixtures}/litecoin-tx-f5aa30f574e3b6f1a3d99c07a6356ba812aabb9661e1d5f71edff828cbd5c996.json +0 -0
  75. data/spec/{bitcoin/fixtures → fixtures}/rawblock-0.bin +0 -0
  76. data/spec/{bitcoin/fixtures → fixtures}/rawblock-0.json +0 -0
  77. data/spec/{bitcoin/fixtures → fixtures}/rawblock-1.bin +0 -0
  78. data/spec/{bitcoin/fixtures → fixtures}/rawblock-1.json +0 -0
  79. data/spec/{bitcoin/fixtures → fixtures}/rawblock-131025.bin +0 -0
  80. data/spec/{bitcoin/fixtures → fixtures}/rawblock-131025.json +0 -0
  81. data/spec/{bitcoin/fixtures → fixtures}/rawblock-170.bin +0 -0
  82. data/spec/{bitcoin/fixtures → fixtures}/rawblock-9.bin +0 -0
  83. data/spec/{bitcoin/fixtures → fixtures}/rawblock-auxpow.bin +0 -0
  84. data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-1151351.bin +0 -0
  85. data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-26478.bin +0 -0
  86. data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-26478.json +0 -0
  87. data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-265322.bin +0 -0
  88. data/spec/{bitcoin/fixtures → fixtures}/rawtx-01-toshi.json +0 -0
  89. data/spec/{bitcoin/fixtures → fixtures}/rawtx-01.bin +0 -0
  90. data/spec/{bitcoin/fixtures → fixtures}/rawtx-01.json +0 -0
  91. data/spec/{bitcoin/fixtures → fixtures}/rawtx-02-toshi.json +0 -0
  92. data/spec/{bitcoin/fixtures → fixtures}/rawtx-02.bin +0 -0
  93. data/spec/{bitcoin/fixtures → fixtures}/rawtx-02.json +0 -0
  94. data/spec/{bitcoin/fixtures → fixtures}/rawtx-03-toshi.json +0 -0
  95. data/spec/{bitcoin/fixtures → fixtures}/rawtx-03.bin +0 -0
  96. data/spec/{bitcoin/fixtures → fixtures}/rawtx-03.json +0 -0
  97. data/spec/{bitcoin/fixtures → fixtures}/rawtx-04.json +0 -0
  98. data/spec/{bitcoin/fixtures → fixtures}/rawtx-0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9.bin +0 -0
  99. data/spec/{bitcoin/fixtures → fixtures}/rawtx-05.json +0 -0
  100. data/spec/{bitcoin/fixtures → fixtures}/rawtx-14be6fff8c6014f7c9493b4a6e4a741699173f39d74431b6b844fcb41ebb9984.bin +0 -0
  101. data/spec/{bitcoin/fixtures → fixtures}/rawtx-2f4a2717ec8c9f077a87dde6cbe0274d5238793a3f3f492b63c744837285e58a.bin +0 -0
  102. data/spec/{bitcoin/fixtures → fixtures}/rawtx-2f4a2717ec8c9f077a87dde6cbe0274d5238793a3f3f492b63c744837285e58a.json +0 -0
  103. data/spec/{bitcoin/fixtures → fixtures}/rawtx-406b2b06bcd34d3c8733e6b79f7a394c8a431fbf4ff5ac705c93f4076bb77602.json +0 -0
  104. data/spec/{bitcoin/fixtures → fixtures}/rawtx-52250a162c7d03d2e1fbc5ebd1801a88612463314b55102171c5b5d817d2d7b2.bin +0 -0
  105. data/spec/{bitcoin/fixtures → fixtures}/rawtx-b5d4e8883533f99e5903ea2cf001a133a322fa6b1370b18a16c57c946a40823d.bin +0 -0
  106. data/spec/{bitcoin/fixtures → fixtures}/rawtx-ba1ff5cd66713133c062a871a8adab92416f1e38d17786b2bf56ac5f6ffdfdf5.json +0 -0
  107. data/spec/{bitcoin/fixtures → fixtures}/rawtx-c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73.json +0 -0
  108. data/spec/{bitcoin/fixtures → fixtures}/rawtx-de35d060663750b3975b7997bde7fb76307cec5b270d12fcd9c4ad98b279c28c.json +0 -0
  109. data/spec/{bitcoin/fixtures → fixtures}/rawtx-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16.bin +0 -0
  110. data/spec/{bitcoin/fixtures → fixtures}/rawtx-p2wpkh.bin +0 -0
  111. data/spec/{bitcoin/fixtures → fixtures}/rawtx-p2wpkh.json +0 -0
  112. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-04fdc38d6722ab4b12d79113fc4b2896bdcc5169710690ee4e78541b98e467b4.bin +0 -0
  113. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-0b294c7d11dd21bcccb8393e6744fed7d4d1981a08c00e3e88838cc421f33c9f.bin +0 -0
  114. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-3bc52ac063291ad92d95ddda5fd776a342083b95607ad32ed8bc6f8f7d30449e.bin +0 -0
  115. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-6f0bbdd4e71a8af4305018d738184df32dbb6f27284fdebd5b56d16947f7c181.bin +0 -0
  116. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-a220adf1902c46a39db25a24bc4178b6a88440f977a7e2cabfdd8b5c1dd35cfb.json +0 -0
  117. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-a7c9b06e275e8674cc19a5f7d3e557c72c6d93576e635b33212dbe08ab7cdb60.bin +0 -0
  118. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f.bin +0 -0
  119. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f.json +0 -0
  120. data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-f80acbd2f594d04ddb0e1cacba662132104909157dff526935a3c88abe9201a5.bin +0 -0
  121. data/spec/{bitcoin/fixtures → fixtures}/script_tests.json +0 -0
  122. data/spec/{bitcoin/fixtures → fixtures}/sighash.json +0 -0
  123. data/spec/{bitcoin/fixtures → fixtures}/tx-0295028ef826b2a188409cb905b631faebb9bb3cdf14510571c5f4bd8591338f.json +0 -0
  124. data/spec/{bitcoin/fixtures → fixtures}/tx-03339a725007a279484fb6f5361f522dd1cf4d0923d30e6b973290dba4275f92.json +0 -0
  125. data/spec/{bitcoin/fixtures → fixtures}/tx-0a6a357e2f7796444e02638749d9611c008b253fb55f5dc88b739b230ed0c4c3.json +0 -0
  126. data/spec/{bitcoin/fixtures → fixtures}/tx-0ce7e5238fbdb6c086cf1b384b21b827e91cc23f360417265874a5a0d86ce367.json +0 -0
  127. data/spec/{bitcoin/fixtures → fixtures}/tx-0ef34c49f630aea17df0080728b0fc67bf5f87fbda936934a4b11b4a69d7821e.json +0 -0
  128. data/spec/{bitcoin/fixtures → fixtures}/tx-1129d2a8bd5bb3a81e54dc96a90f1f6b2544575748caa17243470935c5dd91b7.json +0 -0
  129. data/spec/{bitcoin/fixtures → fixtures}/tx-19aa42fee0fa57c45d3b16488198b27caaacc4ff5794510d0c17f173f05587ff.json +0 -0
  130. data/spec/{bitcoin/fixtures → fixtures}/tx-1a4f3b9dc4494aeedeb39f30dd37e60541b2abe3ed4977992017cc0ad4f44956.json +0 -0
  131. data/spec/{bitcoin/fixtures → fixtures}/tx-1f9191dcf2b1844ca28c6ef4b969e1d5fab70a5e3c56b7007949e55851cb0c4f.json +0 -0
  132. data/spec/{bitcoin/fixtures → fixtures}/tx-22cd5fef23684d7b304e119bedffde6f54538d3d54a5bfa237e20dc2d9b4b5ad.json +0 -0
  133. data/spec/{bitcoin/fixtures → fixtures}/tx-28204cad1d7fc1d199e8ef4fa22f182de6258a3eaafe1bbe56ebdcacd3069a5f.json +0 -0
  134. data/spec/{bitcoin/fixtures → fixtures}/tx-2958fb00b4fd6fe0353503b886eb9a193d502f4fd5fc042d5e03216ba918bbd6.json +0 -0
  135. data/spec/{bitcoin/fixtures → fixtures}/tx-29f277145749ad6efbed3ae6ce301f8d33c585ec26b7c044ad93c2f866e9e942.json +0 -0
  136. data/spec/{bitcoin/fixtures → fixtures}/tx-2c5e5376c20e9cc78d0fb771730e5d840cc2096eff0ef045b599fe92475ace1c.json +0 -0
  137. data/spec/{bitcoin/fixtures → fixtures}/tx-2c63aa814701cef5dbd4bbaddab3fea9117028f2434dddcdab8339141e9b14d1.json +0 -0
  138. data/spec/{bitcoin/fixtures → fixtures}/tx-313897799b1e37e9ecae15010e56156dddde4e683c96b0e713af95272c38aee0.json +0 -0
  139. data/spec/{bitcoin/fixtures → fixtures}/tx-326882a7f22b5191f1a0cc9962ca4b878cd969cf3b3a70887aece4d801a0ba5e.json +0 -0
  140. data/spec/{bitcoin/fixtures → fixtures}/tx-345bed8785c3282a264ffb0dbee61cde54854f10e16f1b3e75b7f2d9f62946f2.json +0 -0
  141. data/spec/{bitcoin/fixtures → fixtures}/tx-39ba7440b7103557560cc8ce258009936796485aaf8b478e66ab4cb97c66e31b.json +0 -0
  142. data/spec/{bitcoin/fixtures → fixtures}/tx-3a04d57a833367f1655cc5ec3beb587888ef4977a86caa8c8ad4ba7cc717eae7.json +0 -0
  143. data/spec/{bitcoin/fixtures → fixtures}/tx-3da75972766f0ad13319b0b461fd16823a731e44f6e9de4eb3c52d6a6fb6c8ae.json +0 -0
  144. data/spec/{bitcoin/fixtures → fixtures}/tx-4142ee4877eb116abf955a7ec6ef2dc38133b793df762b76d75e3d7d4d8badc9.json +0 -0
  145. data/spec/{bitcoin/fixtures → fixtures}/tx-44b833074e671120ba33106877b49e86ece510824b9af477a3853972bcd8d06a.json +0 -0
  146. data/spec/{bitcoin/fixtures → fixtures}/tx-46224764c7870f95b58f155bce1e38d4da8e99d42dbb632d0dd7c07e092ee5aa.json +0 -0
  147. data/spec/{bitcoin/fixtures → fixtures}/tx-5df1375ffe61ac35ca178ebb0cab9ea26dedbd0e96005dfcee7e379fa513232f.json +0 -0
  148. data/spec/{bitcoin/fixtures → fixtures}/tx-62d9a565bd7b5344c5352e3e9e5f40fa4bbd467fa19c87357216ec8777ba1cce.json +0 -0
  149. data/spec/{bitcoin/fixtures → fixtures}/tx-6327783a064d4e350c454ad5cd90201aedf65b1fc524e73709c52f0163739190.json +0 -0
  150. data/spec/{bitcoin/fixtures → fixtures}/tx-6606c366a487bff9e412d0b6c09c14916319932db5954bf5d8719f43f828a3ba.json +0 -0
  151. data/spec/{bitcoin/fixtures → fixtures}/tx-6aaf18b9f1283b939d8e5d40ff5f8a435229f4178372659cc3a0bce4e262bf78.json +0 -0
  152. data/spec/{bitcoin/fixtures → fixtures}/tx-6b48bba6f6d2286d7ec0883c0fc3085955090813a4c94980466611c798b868cc.json +0 -0
  153. data/spec/{bitcoin/fixtures → fixtures}/tx-70cfbc6690f9ab46712db44e3079ac227962b2771a9341d4233d898b521619ef.json +0 -0
  154. data/spec/{bitcoin/fixtures → fixtures}/tx-7a1a9db42f065f75110fcdb1bc415549c8ef7670417ba1d35a67f1b8adc562c1.json +0 -0
  155. data/spec/{bitcoin/fixtures → fixtures}/tx-9a768fc7d0c4bdc86e25154357ef7c0063ca21310e5740a2f12f90b7455184a7.json +0 -0
  156. data/spec/{bitcoin/fixtures → fixtures}/tx-9cad8d523a0694f2509d092c39cebc8046adae62b4e4297102d568191d9478d8.json +0 -0
  157. data/spec/{bitcoin/fixtures → fixtures}/tx-9e052eb694bd7e15906433f064dff0161a12fd325c1124537766377004023c6f.json +0 -0
  158. data/spec/{bitcoin/fixtures → fixtures}/tx-9fb65b7304aaa77ac9580823c2c06b259cc42591e5cce66d76a81b6f51cc5c28.json +0 -0
  159. data/spec/{bitcoin/fixtures → fixtures}/tx-a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954.json +0 -0
  160. data/spec/{bitcoin/fixtures → fixtures}/tx-a955032f4d6b0c9bfe8cad8f00a8933790b9c1dc28c82e0f48e75b35da0e4944.json +0 -0
  161. data/spec/{bitcoin/fixtures → fixtures}/tx-aab7ef280abbb9cc6fbaf524d2645c3daf4fcca2b3f53370e618d9cedf65f1f8.json +0 -0
  162. data/spec/{bitcoin/fixtures → fixtures}/tx-ab9805c6d57d7070d9a42c5176e47bb705023e6b67249fb6760880548298e742.json +0 -0
  163. data/spec/{bitcoin/fixtures → fixtures}/tx-ad4bcf3241e5d2ad140564e20db3567d41594cf4c2012433fe46a2b70e0d87b8.json +0 -0
  164. data/spec/{bitcoin/fixtures → fixtures}/tx-b5b598de91787439afd5938116654e0b16b7a0d0f82742ba37564219c5afcbf9.json +0 -0
  165. data/spec/{bitcoin/fixtures → fixtures}/tx-b8fd633e7713a43d5ac87266adc78444669b987a56b3a65fb92d58c2c4b0e84d.json +0 -0
  166. data/spec/{bitcoin/fixtures → fixtures}/tx-bbca0628c42cb8bf7c3f4b2ad688fa56da5308dd2a10255da89fb1f46e6e413d.json +0 -0
  167. data/spec/{bitcoin/fixtures → fixtures}/tx-bc7fd132fcf817918334822ee6d9bd95c889099c96e07ca2c1eb2cc70db63224.json +0 -0
  168. data/spec/{bitcoin/fixtures → fixtures}/tx-c192b74844e4837a34c4a5a97b438f1c111405b01b99e2d12b7c96d07fc74c04.json +0 -0
  169. data/spec/{bitcoin/fixtures → fixtures}/tx-d3d77d63709e47d9ef58f0b557800115a6b676c6a423012fbb96f45d8fcef830.json +0 -0
  170. data/spec/{bitcoin/fixtures → fixtures}/tx-e335562f7e297aadeed88e5954bc4eeb8dc00b31d829eedb232e39d672b0c009.json +0 -0
  171. data/spec/{bitcoin/fixtures → fixtures}/tx-eb3b82c0884e3efa6d8b0be55b4915eb20be124c9766245bcc7f34fdac32bccb.json +0 -0
  172. data/spec/{bitcoin/fixtures → fixtures}/tx-fee1b9b85531c8fb6cd7831f83490c7f2aa768b6eefe29854ef5e89ce7b9ecb1.json +0 -0
  173. data/spec/{bitcoin/fixtures → fixtures}/txscript-invalid-too-many-sigops-followed-by-invalid-pushdata.bin +0 -0
  174. data/spec/helpers/block_helpers.rb +58 -0
  175. data/spec/helpers/fixture_helpers.rb +20 -0
  176. data/spec/helpers/library_helpers.rb +15 -0
  177. data/spec/spec_helper.rb +109 -0
  178. data/spec/unit/bitcoin/bech32_spec.rb +187 -0
  179. data/spec/unit/bitcoin/bitcoin_spec.rb +1079 -0
  180. data/spec/unit/bitcoin/bloom_filter_spec.rb +33 -0
  181. data/spec/unit/bitcoin/builder_spec.rb +559 -0
  182. data/spec/unit/bitcoin/contracthash_spec.rb +52 -0
  183. data/spec/unit/bitcoin/ext_key_spec.rb +281 -0
  184. data/spec/unit/bitcoin/key_spec.rb +457 -0
  185. data/spec/unit/bitcoin/network_spec.rb +71 -0
  186. data/spec/unit/bitcoin/protocol/addr_spec.rb +90 -0
  187. data/spec/unit/bitcoin/protocol/aux_pow_spec.rb +45 -0
  188. data/spec/unit/bitcoin/protocol/bip143_spec.rb +334 -0
  189. data/spec/unit/bitcoin/protocol/block_spec.rb +280 -0
  190. data/spec/unit/bitcoin/protocol/getblocks_spec.rb +44 -0
  191. data/spec/unit/bitcoin/protocol/inv_spec.rb +166 -0
  192. data/spec/unit/bitcoin/protocol/notfound_spec.rb +44 -0
  193. data/spec/unit/bitcoin/protocol/parser_spec.rb +69 -0
  194. data/spec/unit/bitcoin/protocol/partial_merkle_tree_spec.rb +47 -0
  195. data/spec/unit/bitcoin/protocol/ping_spec.rb +62 -0
  196. data/spec/unit/bitcoin/protocol/tx_spec.rb +1515 -0
  197. data/spec/unit/bitcoin/protocol/txin_spec.rb +47 -0
  198. data/spec/unit/bitcoin/protocol/txout_spec.rb +36 -0
  199. data/spec/unit/bitcoin/protocol/version_spec.rb +121 -0
  200. data/spec/unit/bitcoin/script/opcodes_spec.rb +864 -0
  201. data/spec/unit/bitcoin/script/script_spec.rb +1610 -0
  202. data/spec/unit/bitcoin/secp256k1_spec.rb +138 -0
  203. data/spec/unit/bitcoin/trezor/mnemonic_spec.rb +193 -0
  204. data/spec/unit/integrations/dogecoin_spec.rb +215 -0
  205. metadata +381 -372
  206. data/lib/bitcoin/logger.rb +0 -86
  207. data/lib/bitcoin/protocol/alert.rb +0 -46
  208. data/spec/bitcoin/bech32_spec.rb +0 -160
  209. data/spec/bitcoin/bitcoin_spec.rb +0 -666
  210. data/spec/bitcoin/bloom_filter_spec.rb +0 -23
  211. data/spec/bitcoin/builder_spec.rb +0 -375
  212. data/spec/bitcoin/contracthash_spec.rb +0 -45
  213. data/spec/bitcoin/dogecoin_spec.rb +0 -176
  214. data/spec/bitcoin/ext_key_spec.rb +0 -180
  215. data/spec/bitcoin/ffi_openssl.rb +0 -45
  216. data/spec/bitcoin/fixtures/rawblock-170.json +0 -68
  217. data/spec/bitcoin/fixtures/rawblock-9.json +0 -39
  218. data/spec/bitcoin/fixtures/reorg/blk_0_to_4.dat +0 -0
  219. data/spec/bitcoin/fixtures/reorg/blk_3A.dat +0 -0
  220. data/spec/bitcoin/fixtures/reorg/blk_4A.dat +0 -0
  221. data/spec/bitcoin/fixtures/reorg/blk_5A.dat +0 -0
  222. data/spec/bitcoin/fixtures/testnet/block_0.bin +0 -0
  223. data/spec/bitcoin/fixtures/testnet/block_1.bin +0 -0
  224. data/spec/bitcoin/fixtures/testnet/block_2.bin +0 -0
  225. data/spec/bitcoin/fixtures/testnet/block_3.bin +0 -0
  226. data/spec/bitcoin/fixtures/testnet/block_4.bin +0 -0
  227. data/spec/bitcoin/fixtures/testnet/block_5.bin +0 -0
  228. data/spec/bitcoin/fixtures/txdp-1.txt +0 -32
  229. data/spec/bitcoin/fixtures/txdp-2-signed.txt +0 -19
  230. data/spec/bitcoin/fixtures/txdp-2-unsigned.txt +0 -14
  231. data/spec/bitcoin/helpers/fake_blockchain.rb +0 -183
  232. data/spec/bitcoin/key_spec.rb +0 -326
  233. data/spec/bitcoin/network_spec.rb +0 -50
  234. data/spec/bitcoin/performance/storage_spec.rb +0 -41
  235. data/spec/bitcoin/protocol/addr_spec.rb +0 -82
  236. data/spec/bitcoin/protocol/alert_spec.rb +0 -22
  237. data/spec/bitcoin/protocol/aux_pow_spec.rb +0 -45
  238. data/spec/bitcoin/protocol/bip143_spec.rb +0 -116
  239. data/spec/bitcoin/protocol/block_spec.rb +0 -208
  240. data/spec/bitcoin/protocol/getblocks_spec.rb +0 -32
  241. data/spec/bitcoin/protocol/inv_spec.rb +0 -134
  242. data/spec/bitcoin/protocol/notfound_spec.rb +0 -31
  243. data/spec/bitcoin/protocol/parser_spec.rb +0 -50
  244. data/spec/bitcoin/protocol/partial_merkle_tree_spec.rb +0 -38
  245. data/spec/bitcoin/protocol/ping_spec.rb +0 -51
  246. data/spec/bitcoin/protocol/reject.rb +0 -17
  247. data/spec/bitcoin/protocol/tx_spec.rb +0 -894
  248. data/spec/bitcoin/protocol/txin_spec.rb +0 -45
  249. data/spec/bitcoin/protocol/txout_spec.rb +0 -33
  250. data/spec/bitcoin/protocol/version_spec.rb +0 -110
  251. data/spec/bitcoin/script/opcodes_spec.rb +0 -773
  252. data/spec/bitcoin/script/script_spec.rb +0 -977
  253. data/spec/bitcoin/secp256k1_spec.rb +0 -78
  254. data/spec/bitcoin/spec_helper.rb +0 -108
  255. data/spec/bitcoin/trezor/mnemonic_spec.rb +0 -161
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b4f48a8cb6fda24adfe21240efb4da2f74d9528d
4
- data.tar.gz: fe92c36e2756b66f9f676e7082ef8a7aac56fd44
2
+ SHA256:
3
+ metadata.gz: 69dc67ff7d6860767e626c22efabed33b86541022b4b490916b061a9b395b210
4
+ data.tar.gz: 5aa94333b2635f7f3d7e6e6f7fdf4476938edc448924cafdc3c8553b1f572933
5
5
  SHA512:
6
- metadata.gz: ead4745327db1385e88ef610de2518d692281f0750c767e8a08216328aaa198218e67420c4f96ee35df5393aa70b19dfc58aba2612fb840555ff3bcfcdabbf9a
7
- data.tar.gz: 8bc95d49dcda8806d2e850e4060510518bf92c210f75a894f46646e4ec10368a957581cbadd859a814a4cdaa3f5ada1d120c5b2d96a93f0ccbd30d8060597bef
6
+ metadata.gz: 33c7835ce224e0c6566baa10253b42c7e71ec46ce977c760a6eeef6b89c160e5aa1cd2a3a7b0ba06269e0d8de7acb8989b271a32b30e6b972ecf59488cf8dd2c
7
+ data.tar.gz: 77518c65ef050ac247ddb677da8c0725eacc49bd146c24a9805217efbef3124f7edf199535c924749c374b5b55443ab1cb94e4fab48e9046bfd21a2dc1b276e7
data/.gitignore CHANGED
@@ -14,3 +14,11 @@ spec/bitcoin/fixtures/fake_chain
14
14
  .rbx/
15
15
  /vendor
16
16
  .ruby-version
17
+
18
+ # rspec
19
+ spec-rspec/examples.txt
20
+
21
+ # emacs
22
+ *~
23
+ \#*\#
24
+ .\#*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,46 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'Gemfile'
4
+
5
+ Metrics/AbcSize:
6
+ Max: 100
7
+
8
+ Metrics/BlockLength:
9
+ Max: 50
10
+ Exclude:
11
+ - 'spec/**/*'
12
+ - 'db/migrations/**/*'
13
+ - 'tasks/**/*'
14
+
15
+ Metrics/ClassLength:
16
+ Max: 500
17
+
18
+ Metrics/CyclomaticComplexity:
19
+ Max: 10
20
+
21
+ Metrics/LineLength:
22
+ Max: 100
23
+
24
+ Metrics/MethodLength:
25
+ Max: 80
26
+
27
+ Metrics/ModuleLength:
28
+ Max: 500
29
+
30
+ Metrics/PerceivedComplexity:
31
+ Max: 10
32
+
33
+ Naming/UncommunicativeMethodParamName:
34
+ Enabled: False
35
+
36
+ Style/FrozenStringLiteralComment:
37
+ Enabled: False
38
+
39
+ Style/NumericPredicate:
40
+ Enabled: false
41
+
42
+ Style/SafeNavigation:
43
+ Enabled: false
44
+
45
+ Style/UnpackFirst:
46
+ Enabled: false
@@ -3,4 +3,8 @@ rvm:
3
3
  - 2.2.9
4
4
  - 2.3.6
5
5
  - 2.4.3
6
- - 2.5.0
6
+ - 2.5.1
7
+ script:
8
+ - bundle exec rake build_libsecp256k1
9
+ - bundle exec rake rspec
10
+ - bundle exec rake coin_spec[dogecoin]
data/Gemfile CHANGED
@@ -1,15 +1,17 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in bitcoin-ruby.gemspec
4
3
  gemspec
5
4
 
6
- group :development do
7
- gem 'eventmachine'
8
- gem 'ffi'
9
- gem 'scrypt'
10
- gem 'minitest'
5
+ group :test do
6
+ gem 'rake', '~> 12.3.1'
7
+ gem 'bacon', '~> 1.2.0'
8
+ gem 'rspec', '~> 3.7.0'
9
+ gem 'rubocop', '~> 0.58.2'
10
+ gem 'simplecov', '~> 0.16.1'
11
+ gem 'minitest', '~> 5.11.3'
12
+ end
11
13
 
12
- gem "rake", ">= 0.8.0"
13
- gem 'bacon', '>= 1.2.0'
14
- #gem 'simplecov', require: false
14
+ group :development do
15
+ gem 'pry', '~> 0.11.3'
16
+ gem 'pry-byebug', '~> 3.6.0'
15
17
  end
@@ -1,33 +1,85 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bitcoin-ruby (0.0.18)
4
+ bitcoin-ruby (0.0.19)
5
+ eventmachine
6
+ ffi
7
+ scrypt
5
8
 
6
9
  GEM
7
10
  remote: https://rubygems.org/
8
11
  specs:
12
+ ast (2.4.0)
9
13
  bacon (1.2.0)
10
- eventmachine (1.2.3)
11
- ffi (1.9.18)
14
+ byebug (10.0.2)
15
+ coderay (1.1.2)
16
+ diff-lcs (1.3)
17
+ docile (1.3.1)
18
+ eventmachine (1.2.7)
19
+ ffi (1.9.25)
12
20
  ffi-compiler (1.0.1)
13
21
  ffi (>= 1.0.0)
14
22
  rake
15
- minitest (5.10.2)
16
- rake (12.0.0)
23
+ jaro_winkler (1.5.1)
24
+ json (2.1.0)
25
+ method_source (0.9.0)
26
+ minitest (5.11.3)
27
+ parallel (1.12.1)
28
+ parser (2.5.1.2)
29
+ ast (~> 2.4.0)
30
+ powerpack (0.1.2)
31
+ pry (0.11.3)
32
+ coderay (~> 1.1.0)
33
+ method_source (~> 0.9.0)
34
+ pry-byebug (3.6.0)
35
+ byebug (~> 10.0)
36
+ pry (~> 0.10)
37
+ rainbow (3.0.0)
38
+ rake (12.3.1)
39
+ rspec (3.7.0)
40
+ rspec-core (~> 3.7.0)
41
+ rspec-expectations (~> 3.7.0)
42
+ rspec-mocks (~> 3.7.0)
43
+ rspec-core (3.7.1)
44
+ rspec-support (~> 3.7.0)
45
+ rspec-expectations (3.7.0)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.7.0)
48
+ rspec-mocks (3.7.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.7.0)
51
+ rspec-support (3.7.1)
52
+ rubocop (0.58.2)
53
+ jaro_winkler (~> 1.5.1)
54
+ parallel (~> 1.10)
55
+ parser (>= 2.5, != 2.5.1.1)
56
+ powerpack (~> 0.1)
57
+ rainbow (>= 2.2.2, < 4.0)
58
+ ruby-progressbar (~> 1.7)
59
+ unicode-display_width (~> 1.0, >= 1.0.1)
60
+ ruby-progressbar (1.9.0)
17
61
  scrypt (3.0.5)
18
62
  ffi-compiler (>= 1.0, < 2.0)
63
+ simplecov (0.16.1)
64
+ docile (~> 1.1)
65
+ json (>= 1.8, < 3)
66
+ simplecov-html (~> 0.10.0)
67
+ simplecov-html (0.10.2)
68
+ unicode-display_width (1.4.0)
19
69
 
20
70
  PLATFORMS
21
71
  ruby
22
72
 
23
73
  DEPENDENCIES
24
- bacon (>= 1.2.0)
74
+ bacon (~> 1.2.0)
25
75
  bitcoin-ruby!
26
- eventmachine
27
- ffi
28
- minitest
29
- rake (>= 0.8.0)
30
- scrypt
76
+ minitest (~> 5.11.3)
77
+ pry (~> 0.11.3)
78
+ pry-byebug (~> 3.6.0)
79
+ rake (~> 12.3.1)
80
+ rspec (~> 3.7.0)
81
+ rubocop (~> 0.58.2)
82
+ simplecov (~> 0.16.1)
31
83
 
32
84
  BUNDLED WITH
33
- 1.14.6
85
+ 1.17.3
@@ -29,7 +29,7 @@ Note that some aspects of the library (such as networking, storage, etc.) need
29
29
  additional dependencies which are not specified in the gemspec. The core requirements are
30
30
  intentionally kept to a minimum, so nobody has to install unneeded dependencies.
31
31
 
32
- * +bacon+ to run the specs
32
+ * +rspec+ to run the specs
33
33
  * +scrypt+ to use a much faster scrypt hash implementation for Litecoin
34
34
 
35
35
  If you would like to install using Bundler, put it in your Gemfile and run bundle install
@@ -169,16 +169,29 @@ The specs are also a good place to see how something works.
169
169
 
170
170
  == Specs
171
171
 
172
- The specs can be run with
172
+ Specs require libsecp256k1 in order to be fully run. Therefore, the first step
173
+ in running the specs is to build this library if you haven't already:
173
174
 
174
- rake bacon
175
+ rake build_libsecp256k1
176
+
177
+ The majority of specs can be run with
178
+
179
+ rake rspec
175
180
 
176
181
  or, if you want to run a single spec
177
182
 
178
- ruby spec/bitcoin/bitcoin_spec.rb
183
+ bundle exec rspec spec/bitcoin/bitcoin_spec.rb
179
184
 
180
185
  If you make changes to the code or add functionality, please also add specs.
181
186
 
187
+ To run specs for changes that monkey patch significant functionality, you
188
+ should run the specs individually. For example, to run the Dogecoin specs:
189
+
190
+ rake coin_spec[dogecoin]
191
+
192
+ If support is added for any new coins a corresponding coin spec should also be
193
+ added to test specific functionality of that coin.
194
+
182
195
  == Development
183
196
 
184
197
  Any help or feedback is greatly appreciated! From getting knee-deep into elliptic-curve acrobatics,
data/Rakefile CHANGED
@@ -1,98 +1,66 @@
1
- begin
2
- require 'bundler/gem_tasks'
3
- rescue LoadError
4
- end
5
-
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
6
3
 
7
- PROJECT_SPECS = ( FileList['spec/bitcoin/bitcoin_spec.rb'] +
8
- FileList['spec/bitcoin/protocol/*_spec.rb'] +
9
- FileList['spec/bitcoin/script/*_spec.rb'] +
10
- FileList['spec/bitcoin/trezor/*_spec.rb'] +
11
- FileList['spec/bitcoin/*_spec.rb'] ).uniq
4
+ # libsecp256k1 repository URL
5
+ LIBSECP256K1_REPO = 'https://github.com/bitcoin-core/secp256k1/'.freeze
6
+ # Folder into which libsecp256k1 repository is cloned
7
+ LIBSECP256K1_PATH = 'secp256k1'.freeze
12
8
 
13
9
  RUBY = 'ruby' unless defined?(RUBY)
14
10
 
15
- task :default => :bacon
16
- #
17
- # test runner
11
+ # Attempts to configure the path to libsecp256k1.
18
12
  #
19
- desc 'Run all bacon specs with pretty output'
20
- task :bacon do
21
- require 'open3'
22
- require 'scanf'
23
- require 'matrix'
24
-
25
- specs = PROJECT_SPECS
26
- unless ENV["SECP256K1_LIB_PATH"]
27
- # skip when missing secp256k1 shared lib
28
- specs.delete_if{|i| ['secp256k1_spec.rb', 'bip143_spec.rb'].include?(File.basename(i))}
13
+ # @return [Bool] true if the library was found and configured, false otherwise.
14
+ def configure_libsecp256k1
15
+ return true if ENV["SECP256K1_LIB_PATH"]
16
+
17
+ if File.exist?('secp256k1.so')
18
+ ENV['SECP256K1_LIB_PATH'] = File.join(Dir.pwd, 'secp256k1.so')
19
+ return true
29
20
  end
30
21
 
31
- # E.g. SPEC=specs/bitcoin/script/ to run script-related specs only.
32
- if spec_mask = ENV["SPEC"]
33
- specs.delete_if{|s| !s[spec_mask] }
22
+ false
23
+ end
24
+
25
+ task :default => :rspec
26
+
27
+ RSpec::Core::RakeTask.new(:rspec) do |t|
28
+ t.rspec_opts = '--exclude spec/unit/integrations/*'
29
+ end
30
+
31
+ RSpec::Core::RakeTask.new(:coin_spec, :coin) do |t, args|
32
+ t.rspec_opts = "--pattern spec/unit/integrations/#{args[:coin]}_spec.rb"
33
+ end
34
+
35
+ desc 'Compiles the libsecp256k1 library'
36
+ task :build_libsecp256k1, [:force] do |_, args|
37
+ # Commit hash for libsecp256k1 from May 31, 2018.
38
+ COMMIT_HASH = '1e6f1f5ad5e7f1e3ef79313ec02023902bf8175c'.freeze
39
+
40
+ force = args[:force]
41
+
42
+ if Dir.exists?(LIBSECP256K1_PATH) && !force
43
+ puts "ERROR: Folder #{LIBSECP256K1_PATH} already exists, run with " \
44
+ "[force:true] to force cloning and building anyways."
45
+ exit 1
34
46
  end
35
47
 
36
- some_failed = false
37
- specs_size = specs.size
38
- len = specs.map{|s| s.size }.sort.last
39
- total_tests = total_assertions = total_failures = total_errors = 0
40
- totals = Vector[0, 0, 0, 0]
41
-
42
- red, yellow, green = "\e[31m%s\e[0m", "\e[33m%s\e[0m", "\e[32m%s\e[0m"
43
- left_format = "%4d/%d: %-#{len + 11}s"
44
- spec_format = "%d specifications (%d requirements), %d failures, %d errors"
45
-
46
- specs.each_with_index do |spec, idx|
47
- print(left_format % [idx + 1, specs_size, spec])
48
-
49
- Open3.popen3(RUBY, spec) do |sin, sout, serr|
50
- out = sout.read.strip
51
- err = serr.read.strip
52
-
53
- # this is conventional, see spec/innate/state/fiber.rb for usage
54
- if out =~ /^Bacon::Error: (needed .*)/
55
- puts(yellow % ("%6s %s" % ['', $1]))
56
- else
57
- total = nil
58
-
59
- out.each_line do |line|
60
- scanned = line.scanf(spec_format)
61
-
62
- next unless scanned.size == 4
63
-
64
- total = Vector[*scanned]
65
- break
66
- end
67
-
68
- if total
69
- totals += total
70
- tests, assertions, failures, errors = total_array = total.to_a
71
-
72
- if tests > 0 && failures + errors == 0
73
- puts((green % "%6d passed") % tests)
74
- else
75
- some_failed = true
76
- puts(red % " failed")
77
- puts out unless out.empty?
78
- puts err unless err.empty?
79
- end
80
- else
81
- some_failed = true
82
- puts(red % " failed")
83
- puts out unless out.empty?
84
- puts err unless err.empty?
85
- end
86
- end
87
- end
48
+ sh "rm -rf #{LIBSECP256K1_PATH}"
49
+ sh "git clone #{LIBSECP256K1_REPO}"
50
+ Dir.chdir(LIBSECP256K1_PATH) do
51
+ sh "git checkout #{COMMIT_HASH}"
52
+ sh './autogen.sh'
53
+ sh './configure --enable-module-recovery --with-pic'
54
+ sh 'make libsecp256k1.la'
88
55
  end
89
56
 
90
- total_color = some_failed ? red : green
91
- puts(total_color % (spec_format % totals.to_a))
92
- exit 1 if some_failed
57
+ libfile = 'libsecp256k1.so.0.0.0'
58
+ # Handle macOS libraries being different from Linux libraries
59
+ libfile = 'libsecp256k1.0.dylib' unless RUBY_PLATFORM.match(/darwin/).nil?
60
+ sh "cp #{LIBSECP256K1_PATH}/.libs/#{libfile} secp256k1.so"
61
+ sh "rm -rf #{LIBSECP256K1_PATH}"
93
62
  end
94
63
 
95
-
96
64
  desc 'Generate RDoc documentation'
97
65
  task :rdoc do
98
66
  `rm -rf rdoc`
@@ -101,12 +69,19 @@ end
101
69
 
102
70
  desc 'Generate test coverage report'
103
71
  task :coverage do
72
+ if !configure_libsecp256k1
73
+ puts 'ERROR: Skipping code coverage tests since required library '\
74
+ 'libsecp256k1 was not found. Run `rake build_libsecp256k1` to build.'
75
+ exit 1
76
+ end
77
+
104
78
  begin
105
79
  require 'simplecov'
106
80
  rescue LoadError
107
81
  puts "Simplecov not found. Run `gem install simplecov` to install it."
108
82
  exit
109
83
  end
110
- sh "bacon", *PROJECT_SPECS
84
+
85
+ Rake::Task['rspec'].invoke
111
86
  system('open coverage/index.html') if RUBY_PLATFORM.include? 'darwin'
112
87
  end
@@ -19,6 +19,9 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.required_rubygems_version = ">= 1.3.6"
23
- #s.add_development_dependency "bacon"
22
+ s.required_rubygems_version = ">= 2.6.13"
23
+
24
+ s.add_runtime_dependency 'ffi'
25
+ s.add_runtime_dependency 'scrypt' # required by Litecoin
26
+ s.add_runtime_dependency 'eventmachine' # required for connection code
24
27
  end
@@ -7,6 +7,20 @@ require 'openssl'
7
7
  require 'securerandom'
8
8
 
9
9
  module Bitcoin
10
+ # Determine the integer class to use. In older versions of ruby (< 2.4.0) the
11
+ # integer class is called Fixnum. In newer version (>= 2.4.0) Fixnum was
12
+ # deprecated in favor of a unification of Fixnum and BigInteger named Integer.
13
+ # Since this project strivers for backwards-compatability, we determine the
14
+ # appropriate class to use at initialization.
15
+ #
16
+ # This avoids annoying deprecation warnings on newer versions for ourselves
17
+ # and library consumers.
18
+ Integer =
19
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.0')
20
+ Integer
21
+ else
22
+ Fixnum
23
+ end
10
24
 
11
25
  autoload :Bech32, 'bitcoin/bech32'
12
26
  autoload :Connection, 'bitcoin/connection'
@@ -14,7 +28,6 @@ module Bitcoin
14
28
  autoload :P, 'bitcoin/protocol'
15
29
  autoload :Script, 'bitcoin/script'
16
30
  autoload :VERSION, 'bitcoin/version'
17
- autoload :Logger, 'bitcoin/logger'
18
31
  autoload :Key, 'bitcoin/key'
19
32
  autoload :ExtKey, 'bitcoin/ext_key'
20
33
  autoload :ExtPubkey, 'bitcoin/ext_key'
@@ -34,6 +47,7 @@ module Bitcoin
34
47
  module Util
35
48
 
36
49
  def address_version; Bitcoin.network[:address_version]; end
50
+ def version_bytes; address_version.size / 2; end
37
51
  def p2sh_version; Bitcoin.network[:p2sh_version]; end
38
52
 
39
53
  # hash160 is a 20 bytes (160bits) rmd610-sha256 hexdigest.
@@ -52,7 +66,7 @@ module Bitcoin
52
66
  def base58_checksum?(base58)
53
67
  hex = decode_base58(base58) rescue nil
54
68
  return false unless hex
55
- checksum( hex[0...42] ) == hex[-8..-1]
69
+ checksum(hex[0...(version_bytes + 20) * 2]) == hex[-8..-1]
56
70
  end
57
71
  alias :address_checksum? :base58_checksum?
58
72
 
@@ -68,6 +82,11 @@ module Bitcoin
68
82
  true
69
83
  rescue OpenSSL::PKey::EC::Point::Error
70
84
  false
85
+ rescue OpenSSL::BNError
86
+ # Occasionally, a malformed value will fail hex decoding completely and
87
+ # instead of raising an `OpenSSL::PKey::EC::Point::Error` will raise this
88
+ # error. We capture this failure mode here as well.
89
+ false
71
90
  end
72
91
 
73
92
  # get hash160 for given +address+. returns nil if address is invalid.
@@ -77,7 +96,9 @@ module Bitcoin
77
96
  _, witness_program_hex = decode_segwit_address(address)
78
97
  witness_program_hex
79
98
  when :hash160, :p2sh
80
- decode_base58(address)[2...42]
99
+ start_idx = version_bytes * 2
100
+ stop_idx = start_idx + 40 # 20 bytes (2 chars per byte)
101
+ decode_base58(address)[start_idx...stop_idx]
81
102
  end
82
103
  end
83
104
 
@@ -98,14 +119,16 @@ module Bitcoin
98
119
  end
99
120
 
100
121
  hex = decode_base58(address) rescue nil
101
- if hex && hex.bytesize == 50 && address_checksum?(address)
122
+
123
+ target_size = (version_bytes + 20 + 4) * 2 # version_bytes + 20 bytes hash + 4 bytes checksum
124
+ if hex && hex.bytesize == target_size && address_checksum?(address)
102
125
  # Litecoin updates the P2SH version byte, and this method should recognize both.
103
126
  p2sh_versions = [p2sh_version]
104
127
  if Bitcoin.network[:legacy_p2sh_versions]
105
128
  p2sh_versions += Bitcoin.network[:legacy_p2sh_versions]
106
129
  end
107
130
 
108
- case hex[0...2]
131
+ case hex[0...(version_bytes * 2)]
109
132
  when address_version
110
133
  return :hash160
111
134
  when *p2sh_versions
@@ -255,7 +278,7 @@ module Bitcoin
255
278
 
256
279
  def decode_target(target_bits)
257
280
  case target_bits
258
- when Fixnum
281
+ when Bitcoin::Integer
259
282
  [ decode_compact_bits(target_bits).to_i(16), target_bits ]
260
283
  when String
261
284
  [ target_bits.to_i(16), encode_compact_bits(target_bits) ]
@@ -561,11 +584,11 @@ module Bitcoin
561
584
  end
562
585
 
563
586
  def self.network_name
564
- @network
587
+ @network ||= nil
565
588
  end
566
589
 
567
590
  def self.network_project
568
- @network_project
591
+ @network_project ||= nil
569
592
  end
570
593
 
571
594
  def self.network=(name)
@@ -653,7 +676,6 @@ module Bitcoin
653
676
  ],
654
677
  genesis_hash: "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
655
678
  proof_of_work_limit: 0x1d00ffff,
656
- alert_pubkeys: ["04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284"],
657
679
  known_nodes: [
658
680
  'relay.eligius.st',
659
681
  'mining.bitcoin.cz',
@@ -692,7 +714,6 @@ module Bitcoin
692
714
  dns_seeds: [ ],
693
715
  genesis_hash: "00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008",
694
716
  proof_of_work_limit: 0x1d07fff8,
695
- alert_pubkeys: ["04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a"],
696
717
  known_nodes: [],
697
718
  checkpoints: {},
698
719
  })
@@ -757,7 +778,6 @@ module Bitcoin
757
778
  ],
758
779
  genesis_hash: "12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2",
759
780
  proof_of_work_limit: 0x1e0fffff,
760
- alert_pubkeys: ["040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9"],
761
781
  known_nodes: [],
762
782
  checkpoints: {
763
783
  1 => "80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f",
@@ -797,7 +817,6 @@ module Bitcoin
797
817
  "dnsseed-testnet.thrasher.io",
798
818
  ],
799
819
  genesis_hash: "4966625a4b2851d9fdee139e56211a0d88575f59ed816ff5e6a63deb4e3e29a0",
800
- alert_pubkeys: ["04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a"],
801
820
  known_nodes: [],
802
821
  checkpoints: {
803
822
  546 => "bf434a4c665307f52a041ee40faa7bf56284c5f3b5d11bf6182aba537961f86c",
@@ -836,7 +855,6 @@ module Bitcoin
836
855
  ],
837
856
  genesis_hash: "1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691",
838
857
  proof_of_work_limit: 0x1e0fffff,
839
- alert_pubkeys: [],
840
858
  known_nodes: [
841
859
  "daemons.chain.so",
842
860
  "bootstrap.chain.so",
@@ -894,7 +912,6 @@ module Bitcoin
894
912
  ],
895
913
  genesis_hash: "bb0a78264637406b6360aad926284d544d7049f45189db5664f3c4d07350559e",
896
914
  proof_of_work_limit: 0x1e0fffff,
897
- alert_pubkeys: [],
898
915
  known_nodes: [
899
916
  "localhost",
900
917
  "testnets.chain.so",