monacoin-ruby 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +5 -0
  4. data/COPYING +18 -0
  5. data/Gemfile +15 -0
  6. data/Gemfile.lock +33 -0
  7. data/README.rdoc +210 -0
  8. data/Rakefile +112 -0
  9. data/bin/monacoin_shell +12 -0
  10. data/bitcoin-ruby.gemspec +23 -0
  11. data/examples/bbe_verify_tx.rb +60 -0
  12. data/examples/concept-blockchain-pow.rb +151 -0
  13. data/examples/connect.rb +36 -0
  14. data/examples/generate_tx.rb +34 -0
  15. data/examples/simple_network_monitor_and_util.rb +195 -0
  16. data/spec/bitcoin/bitcoin_spec.rb +598 -0
  17. data/spec/bitcoin/bloom_filter_spec.rb +23 -0
  18. data/spec/bitcoin/builder_spec.rb +342 -0
  19. data/spec/bitcoin/contracthash_spec.rb +45 -0
  20. data/spec/bitcoin/dogecoin_spec.rb +176 -0
  21. data/spec/bitcoin/ext_key_spec.rb +180 -0
  22. data/spec/bitcoin/ffi_openssl.rb +45 -0
  23. data/spec/bitcoin/fixtures/000000000000056b1a3d84a1e2b33cde8915a4b61c0cae14fca6d3e1490b4f98.json +3697 -0
  24. data/spec/bitcoin/fixtures/03d7e1fa4d5fefa169431f24f7798552861b255cd55d377066fedcd088fb0e99.json +23 -0
  25. data/spec/bitcoin/fixtures/0961c660358478829505e16a1f028757e54b5bbf9758341a7546573738f31429.json +24 -0
  26. data/spec/bitcoin/fixtures/0f24294a1d23efbb49c1765cf443fba7930702752aba6d765870082fe4f13cae.json +37 -0
  27. data/spec/bitcoin/fixtures/156e6e1b84c5c3bd3a0927b25e4119fadce6e6d5186f363317511d1d680fae9a.json +24 -0
  28. data/spec/bitcoin/fixtures/23b397edccd3740a74adb603c9756370fafcde9bcc4483eb271ecad09a94dd63.json +23 -0
  29. data/spec/bitcoin/fixtures/315ac7d4c26d69668129cc352851d9389b4a6868f1509c6c8b66bead11e2619f.json +31 -0
  30. data/spec/bitcoin/fixtures/35e2001b428891fefa0bfb73167c7360669d3cbd7b3aa78e7cad125ddfc51131.json +27 -0
  31. data/spec/bitcoin/fixtures/3a17dace09ffb919ed627a93f1873220f4c975c1248558b18d16bce25d38c4b7.json +72 -0
  32. data/spec/bitcoin/fixtures/3e58b7eed0fdb599019af08578effea25c8666bbe8e200845453cacce6314477.json +27 -0
  33. data/spec/bitcoin/fixtures/514c46f0b61714092f15c8dfcb576c9f79b3f959989b98de3944b19d98832b58.json +24 -0
  34. data/spec/bitcoin/fixtures/51bf528ecf3c161e7c021224197dbe84f9a8564212f6207baa014c01a1668e1e.json +30 -0
  35. data/spec/bitcoin/fixtures/60a20bd93aa49ab4b28d514ec10b06e1829ce6818ec06cd3aabd013ebcdc4bb1.json +45 -0
  36. data/spec/bitcoin/fixtures/69216b8aaa35b76d6613e5f527f4858640d986e1046238583bdad79b35e938dc.json +28 -0
  37. data/spec/bitcoin/fixtures/7208e5edf525f04e705fb3390194e316205b8f995c8c9fcd8c6093abe04fa27d.json +27 -0
  38. data/spec/bitcoin/fixtures/761d8c5210fdfd505f6dff38f740ae3728eb93d7d0971fb433f685d40a4c04f6.json +27 -0
  39. data/spec/bitcoin/fixtures/8d0b238a06b5a70be75d543902d02d7a514d68d3252a949a513865ac3538874c.json +24 -0
  40. data/spec/bitcoin/fixtures/aea682d68a3ea5e3583e088dcbd699a5d44d4b083f02ad0aaf2598fe1fa4dfd4.json +27 -0
  41. data/spec/bitcoin/fixtures/bc179baab547b7d7c1d5d8d6f8b0cc6318eaa4b0dd0a093ad6ac7f5a1cb6b3ba.json +34 -0
  42. data/spec/bitcoin/fixtures/bd1715f1abfdc62bea3f605bdb461b3ba1f2cca6ec0d73a18a548b7717ca8531.json +34 -0
  43. data/spec/bitcoin/fixtures/block-testnet-0000000000ac85bb2530a05a4214a387e6be02b22d3348abc5e7a5d9c4ce8dab.bin +0 -0
  44. data/spec/bitcoin/fixtures/cd874fa8cb0e2ec2d385735d5e1fd482c4fe648533efb4c50ee53bda58e15ae2.json +24 -0
  45. data/spec/bitcoin/fixtures/ce5fad9b4ef094d8f4937b0707edaf0a6e6ceeaf67d5edbfd51f660eac8f398b.json +41 -0
  46. data/spec/bitcoin/fixtures/coinbase-toshi.json +33 -0
  47. data/spec/bitcoin/fixtures/coinbase.json +24 -0
  48. data/spec/bitcoin/fixtures/dogecoin-block-60323982f9c5ff1b5a954eac9dc1269352835f47c2c5222691d80f0d50dcf053.bin +0 -0
  49. data/spec/bitcoin/fixtures/f003f0c1193019db2497a675fd05d9f2edddf9b67c59e677c48d3dbd4ed5f00b.json +23 -0
  50. data/spec/bitcoin/fixtures/filteredblock-0.bin +0 -0
  51. data/spec/bitcoin/fixtures/litecoin-block-80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f.bin +0 -0
  52. data/spec/bitcoin/fixtures/litecoin-block-80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f.json +39 -0
  53. data/spec/bitcoin/fixtures/litecoin-genesis-block-12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2.bin +0 -0
  54. data/spec/bitcoin/fixtures/litecoin-genesis-block-12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2.json +39 -0
  55. data/spec/bitcoin/fixtures/litecoin-tx-f5aa30f574e3b6f1a3d99c07a6356ba812aabb9661e1d5f71edff828cbd5c996.json +259 -0
  56. data/spec/bitcoin/fixtures/rawblock-0.bin +0 -0
  57. data/spec/bitcoin/fixtures/rawblock-0.json +39 -0
  58. data/spec/bitcoin/fixtures/rawblock-1.bin +0 -0
  59. data/spec/bitcoin/fixtures/rawblock-1.json +39 -0
  60. data/spec/bitcoin/fixtures/rawblock-131025.bin +0 -0
  61. data/spec/bitcoin/fixtures/rawblock-131025.json +5063 -0
  62. data/spec/bitcoin/fixtures/rawblock-170.bin +0 -0
  63. data/spec/bitcoin/fixtures/rawblock-170.json +68 -0
  64. data/spec/bitcoin/fixtures/rawblock-9.bin +0 -0
  65. data/spec/bitcoin/fixtures/rawblock-9.json +39 -0
  66. data/spec/bitcoin/fixtures/rawblock-auxpow.bin +0 -0
  67. data/spec/bitcoin/fixtures/rawblock-testnet-1151351.bin +0 -0
  68. data/spec/bitcoin/fixtures/rawblock-testnet-26478.bin +0 -0
  69. data/spec/bitcoin/fixtures/rawblock-testnet-26478.json +64 -0
  70. data/spec/bitcoin/fixtures/rawblock-testnet-265322.bin +0 -0
  71. data/spec/bitcoin/fixtures/rawtx-01-toshi.json +46 -0
  72. data/spec/bitcoin/fixtures/rawtx-01.bin +0 -0
  73. data/spec/bitcoin/fixtures/rawtx-01.json +27 -0
  74. data/spec/bitcoin/fixtures/rawtx-02-toshi.json +46 -0
  75. data/spec/bitcoin/fixtures/rawtx-02.bin +0 -0
  76. data/spec/bitcoin/fixtures/rawtx-02.json +27 -0
  77. data/spec/bitcoin/fixtures/rawtx-03-toshi.json +73 -0
  78. data/spec/bitcoin/fixtures/rawtx-03.bin +0 -0
  79. data/spec/bitcoin/fixtures/rawtx-03.json +48 -0
  80. data/spec/bitcoin/fixtures/rawtx-04.json +27 -0
  81. data/spec/bitcoin/fixtures/rawtx-0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9.bin +0 -0
  82. data/spec/bitcoin/fixtures/rawtx-05.json +23 -0
  83. data/spec/bitcoin/fixtures/rawtx-14be6fff8c6014f7c9493b4a6e4a741699173f39d74431b6b844fcb41ebb9984.bin +0 -0
  84. data/spec/bitcoin/fixtures/rawtx-2f4a2717ec8c9f077a87dde6cbe0274d5238793a3f3f492b63c744837285e58a.bin +0 -0
  85. data/spec/bitcoin/fixtures/rawtx-2f4a2717ec8c9f077a87dde6cbe0274d5238793a3f3f492b63c744837285e58a.json +27 -0
  86. data/spec/bitcoin/fixtures/rawtx-406b2b06bcd34d3c8733e6b79f7a394c8a431fbf4ff5ac705c93f4076bb77602.json +23 -0
  87. data/spec/bitcoin/fixtures/rawtx-52250a162c7d03d2e1fbc5ebd1801a88612463314b55102171c5b5d817d2d7b2.bin +0 -0
  88. data/spec/bitcoin/fixtures/rawtx-b5d4e8883533f99e5903ea2cf001a133a322fa6b1370b18a16c57c946a40823d.bin +0 -0
  89. data/spec/bitcoin/fixtures/rawtx-ba1ff5cd66713133c062a871a8adab92416f1e38d17786b2bf56ac5f6ffdfdf5.json +37 -0
  90. data/spec/bitcoin/fixtures/rawtx-c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73.json +24 -0
  91. data/spec/bitcoin/fixtures/rawtx-de35d060663750b3975b7997bde7fb76307cec5b270d12fcd9c4ad98b279c28c.json +23 -0
  92. data/spec/bitcoin/fixtures/rawtx-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16.bin +0 -0
  93. data/spec/bitcoin/fixtures/rawtx-p2wpkh.bin +0 -0
  94. data/spec/bitcoin/fixtures/rawtx-p2wpkh.json +67 -0
  95. data/spec/bitcoin/fixtures/rawtx-testnet-04fdc38d6722ab4b12d79113fc4b2896bdcc5169710690ee4e78541b98e467b4.bin +0 -0
  96. data/spec/bitcoin/fixtures/rawtx-testnet-0b294c7d11dd21bcccb8393e6744fed7d4d1981a08c00e3e88838cc421f33c9f.bin +0 -0
  97. data/spec/bitcoin/fixtures/rawtx-testnet-3bc52ac063291ad92d95ddda5fd776a342083b95607ad32ed8bc6f8f7d30449e.bin +0 -0
  98. data/spec/bitcoin/fixtures/rawtx-testnet-6f0bbdd4e71a8af4305018d738184df32dbb6f27284fdebd5b56d16947f7c181.bin +0 -0
  99. data/spec/bitcoin/fixtures/rawtx-testnet-a220adf1902c46a39db25a24bc4178b6a88440f977a7e2cabfdd8b5c1dd35cfb.json +27 -0
  100. data/spec/bitcoin/fixtures/rawtx-testnet-a7c9b06e275e8674cc19a5f7d3e557c72c6d93576e635b33212dbe08ab7cdb60.bin +0 -0
  101. data/spec/bitcoin/fixtures/rawtx-testnet-e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f.bin +0 -0
  102. data/spec/bitcoin/fixtures/rawtx-testnet-e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f.json +41 -0
  103. data/spec/bitcoin/fixtures/rawtx-testnet-f80acbd2f594d04ddb0e1cacba662132104909157dff526935a3c88abe9201a5.bin +0 -0
  104. data/spec/bitcoin/fixtures/reorg/blk_0_to_4.dat +0 -0
  105. data/spec/bitcoin/fixtures/reorg/blk_3A.dat +0 -0
  106. data/spec/bitcoin/fixtures/reorg/blk_4A.dat +0 -0
  107. data/spec/bitcoin/fixtures/reorg/blk_5A.dat +0 -0
  108. data/spec/bitcoin/fixtures/script_tests.json +1947 -0
  109. data/spec/bitcoin/fixtures/sighash.json +1004 -0
  110. data/spec/bitcoin/fixtures/testnet/block_0.bin +0 -0
  111. data/spec/bitcoin/fixtures/testnet/block_1.bin +0 -0
  112. data/spec/bitcoin/fixtures/testnet/block_2.bin +0 -0
  113. data/spec/bitcoin/fixtures/testnet/block_3.bin +0 -0
  114. data/spec/bitcoin/fixtures/testnet/block_4.bin +0 -0
  115. data/spec/bitcoin/fixtures/testnet/block_5.bin +0 -0
  116. data/spec/bitcoin/fixtures/tx-0295028ef826b2a188409cb905b631faebb9bb3cdf14510571c5f4bd8591338f.json +64 -0
  117. data/spec/bitcoin/fixtures/tx-03339a725007a279484fb6f5361f522dd1cf4d0923d30e6b973290dba4275f92.json +64 -0
  118. data/spec/bitcoin/fixtures/tx-0a6a357e2f7796444e02638749d9611c008b253fb55f5dc88b739b230ed0c4c3.json +139 -0
  119. data/spec/bitcoin/fixtures/tx-0ce7e5238fbdb6c086cf1b384b21b827e91cc23f360417265874a5a0d86ce367.json +64 -0
  120. data/spec/bitcoin/fixtures/tx-0ef34c49f630aea17df0080728b0fc67bf5f87fbda936934a4b11b4a69d7821e.json +64 -0
  121. data/spec/bitcoin/fixtures/tx-1129d2a8bd5bb3a81e54dc96a90f1f6b2544575748caa17243470935c5dd91b7.json +28 -0
  122. data/spec/bitcoin/fixtures/tx-19aa42fee0fa57c45d3b16488198b27caaacc4ff5794510d0c17f173f05587ff.json +23 -0
  123. data/spec/bitcoin/fixtures/tx-1a4f3b9dc4494aeedeb39f30dd37e60541b2abe3ed4977992017cc0ad4f44956.json +64 -0
  124. data/spec/bitcoin/fixtures/tx-1f9191dcf2b1844ca28c6ef4b969e1d5fab70a5e3c56b7007949e55851cb0c4f.json +64 -0
  125. data/spec/bitcoin/fixtures/tx-22cd5fef23684d7b304e119bedffde6f54538d3d54a5bfa237e20dc2d9b4b5ad.json +64 -0
  126. data/spec/bitcoin/fixtures/tx-28204cad1d7fc1d199e8ef4fa22f182de6258a3eaafe1bbe56ebdcacd3069a5f.json +34 -0
  127. data/spec/bitcoin/fixtures/tx-2958fb00b4fd6fe0353503b886eb9a193d502f4fd5fc042d5e03216ba918bbd6.json +64 -0
  128. data/spec/bitcoin/fixtures/tx-29f277145749ad6efbed3ae6ce301f8d33c585ec26b7c044ad93c2f866e9e942.json +64 -0
  129. data/spec/bitcoin/fixtures/tx-2c5e5376c20e9cc78d0fb771730e5d840cc2096eff0ef045b599fe92475ace1c.json +28 -0
  130. data/spec/bitcoin/fixtures/tx-2c63aa814701cef5dbd4bbaddab3fea9117028f2434dddcdab8339141e9b14d1.json +30 -0
  131. data/spec/bitcoin/fixtures/tx-313897799b1e37e9ecae15010e56156dddde4e683c96b0e713af95272c38aee0.json +30 -0
  132. data/spec/bitcoin/fixtures/tx-326882a7f22b5191f1a0cc9962ca4b878cd969cf3b3a70887aece4d801a0ba5e.json +23 -0
  133. data/spec/bitcoin/fixtures/tx-345bed8785c3282a264ffb0dbee61cde54854f10e16f1b3e75b7f2d9f62946f2.json +64 -0
  134. data/spec/bitcoin/fixtures/tx-39ba7440b7103557560cc8ce258009936796485aaf8b478e66ab4cb97c66e31b.json +32 -0
  135. data/spec/bitcoin/fixtures/tx-3a04d57a833367f1655cc5ec3beb587888ef4977a86caa8c8ad4ba7cc717eae7.json +64 -0
  136. data/spec/bitcoin/fixtures/tx-3da75972766f0ad13319b0b461fd16823a731e44f6e9de4eb3c52d6a6fb6c8ae.json +23 -0
  137. data/spec/bitcoin/fixtures/tx-4142ee4877eb116abf955a7ec6ef2dc38133b793df762b76d75e3d7d4d8badc9.json +38 -0
  138. data/spec/bitcoin/fixtures/tx-44b833074e671120ba33106877b49e86ece510824b9af477a3853972bcd8d06a.json +30 -0
  139. data/spec/bitcoin/fixtures/tx-46224764c7870f95b58f155bce1e38d4da8e99d42dbb632d0dd7c07e092ee5aa.json +23 -0
  140. data/spec/bitcoin/fixtures/tx-5df1375ffe61ac35ca178ebb0cab9ea26dedbd0e96005dfcee7e379fa513232f.json +30 -0
  141. data/spec/bitcoin/fixtures/tx-62d9a565bd7b5344c5352e3e9e5f40fa4bbd467fa19c87357216ec8777ba1cce.json +64 -0
  142. data/spec/bitcoin/fixtures/tx-6327783a064d4e350c454ad5cd90201aedf65b1fc524e73709c52f0163739190.json +23 -0
  143. data/spec/bitcoin/fixtures/tx-6606c366a487bff9e412d0b6c09c14916319932db5954bf5d8719f43f828a3ba.json +27 -0
  144. data/spec/bitcoin/fixtures/tx-6aaf18b9f1283b939d8e5d40ff5f8a435229f4178372659cc3a0bce4e262bf78.json +28 -0
  145. data/spec/bitcoin/fixtures/tx-6b48bba6f6d2286d7ec0883c0fc3085955090813a4c94980466611c798b868cc.json +64 -0
  146. data/spec/bitcoin/fixtures/tx-70cfbc6690f9ab46712db44e3079ac227962b2771a9341d4233d898b521619ef.json +40 -0
  147. data/spec/bitcoin/fixtures/tx-7a1a9db42f065f75110fcdb1bc415549c8ef7670417ba1d35a67f1b8adc562c1.json +64 -0
  148. data/spec/bitcoin/fixtures/tx-9a768fc7d0c4bdc86e25154357ef7c0063ca21310e5740a2f12f90b7455184a7.json +64 -0
  149. data/spec/bitcoin/fixtures/tx-9cad8d523a0694f2509d092c39cebc8046adae62b4e4297102d568191d9478d8.json +64 -0
  150. data/spec/bitcoin/fixtures/tx-9e052eb694bd7e15906433f064dff0161a12fd325c1124537766377004023c6f.json +64 -0
  151. data/spec/bitcoin/fixtures/tx-9fb65b7304aaa77ac9580823c2c06b259cc42591e5cce66d76a81b6f51cc5c28.json +23 -0
  152. data/spec/bitcoin/fixtures/tx-a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954.json +30 -0
  153. data/spec/bitcoin/fixtures/tx-a955032f4d6b0c9bfe8cad8f00a8933790b9c1dc28c82e0f48e75b35da0e4944.json +23 -0
  154. data/spec/bitcoin/fixtures/tx-aab7ef280abbb9cc6fbaf524d2645c3daf4fcca2b3f53370e618d9cedf65f1f8.json +23 -0
  155. data/spec/bitcoin/fixtures/tx-ab9805c6d57d7070d9a42c5176e47bb705023e6b67249fb6760880548298e742.json +27 -0
  156. data/spec/bitcoin/fixtures/tx-ad4bcf3241e5d2ad140564e20db3567d41594cf4c2012433fe46a2b70e0d87b8.json +64 -0
  157. data/spec/bitcoin/fixtures/tx-b5b598de91787439afd5938116654e0b16b7a0d0f82742ba37564219c5afcbf9.json +27 -0
  158. data/spec/bitcoin/fixtures/tx-b8fd633e7713a43d5ac87266adc78444669b987a56b3a65fb92d58c2c4b0e84d.json +28 -0
  159. data/spec/bitcoin/fixtures/tx-bbca0628c42cb8bf7c3f4b2ad688fa56da5308dd2a10255da89fb1f46e6e413d.json +36 -0
  160. data/spec/bitcoin/fixtures/tx-bc7fd132fcf817918334822ee6d9bd95c889099c96e07ca2c1eb2cc70db63224.json +23 -0
  161. data/spec/bitcoin/fixtures/tx-c192b74844e4837a34c4a5a97b438f1c111405b01b99e2d12b7c96d07fc74c04.json +28 -0
  162. data/spec/bitcoin/fixtures/tx-d3d77d63709e47d9ef58f0b557800115a6b676c6a423012fbb96f45d8fcef830.json +28 -0
  163. data/spec/bitcoin/fixtures/tx-e335562f7e297aadeed88e5954bc4eeb8dc00b31d829eedb232e39d672b0c009.json +406 -0
  164. data/spec/bitcoin/fixtures/tx-eb3b82c0884e3efa6d8b0be55b4915eb20be124c9766245bcc7f34fdac32bccb.json +35 -0
  165. data/spec/bitcoin/fixtures/tx-fee1b9b85531c8fb6cd7831f83490c7f2aa768b6eefe29854ef5e89ce7b9ecb1.json +64 -0
  166. data/spec/bitcoin/fixtures/txdp-1.txt +32 -0
  167. data/spec/bitcoin/fixtures/txdp-2-signed.txt +19 -0
  168. data/spec/bitcoin/fixtures/txdp-2-unsigned.txt +14 -0
  169. data/spec/bitcoin/fixtures/txscript-invalid-too-many-sigops-followed-by-invalid-pushdata.bin +1 -0
  170. data/spec/bitcoin/helpers/fake_blockchain.rb +183 -0
  171. data/spec/bitcoin/key_spec.rb +326 -0
  172. data/spec/bitcoin/network_spec.rb +50 -0
  173. data/spec/bitcoin/performance/storage_spec.rb +41 -0
  174. data/spec/bitcoin/protocol/addr_spec.rb +82 -0
  175. data/spec/bitcoin/protocol/alert_spec.rb +22 -0
  176. data/spec/bitcoin/protocol/aux_pow_spec.rb +45 -0
  177. data/spec/bitcoin/protocol/bip143_spec.rb +116 -0
  178. data/spec/bitcoin/protocol/block_spec.rb +208 -0
  179. data/spec/bitcoin/protocol/getblocks_spec.rb +32 -0
  180. data/spec/bitcoin/protocol/inv_spec.rb +134 -0
  181. data/spec/bitcoin/protocol/notfound_spec.rb +31 -0
  182. data/spec/bitcoin/protocol/parser_spec.rb +50 -0
  183. data/spec/bitcoin/protocol/partial_merkle_tree_spec.rb +38 -0
  184. data/spec/bitcoin/protocol/ping_spec.rb +51 -0
  185. data/spec/bitcoin/protocol/reject.rb +17 -0
  186. data/spec/bitcoin/protocol/tx_spec.rb +894 -0
  187. data/spec/bitcoin/protocol/txin_spec.rb +45 -0
  188. data/spec/bitcoin/protocol/txout_spec.rb +27 -0
  189. data/spec/bitcoin/protocol/version_spec.rb +110 -0
  190. data/spec/bitcoin/script/opcodes_spec.rb +773 -0
  191. data/spec/bitcoin/script/script_spec.rb +971 -0
  192. data/spec/bitcoin/secp256k1_spec.rb +78 -0
  193. data/spec/bitcoin/spec_helper.rb +108 -0
  194. data/spec/bitcoin/trezor/mnemonic_spec.rb +161 -0
  195. metadata +237 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 402c242d2512162b5169de6a9a42d60ef0eee0c86f7fe7609438b3f25d8b9e28
4
+ data.tar.gz: 977043c3719fe54dd9338cca69ebfbb2e9c3d49394852a2cb86e3458b6f7a212
5
+ SHA512:
6
+ metadata.gz: 2b40e18d59c045a8e775eccf6d2f54beeb355db7dda2b45d1809d24d5e6c03b3c7232567df6d090fc6846d92b604b2b73b038a9d0f37115c08fbe65d750551b0
7
+ data.tar.gz: 96121a28ffc81b450e64cd6c090b5b95bbad96ea7456d3eff54a6460189fc62ee9afabdd7c7e8c4071166f29981e8e7ac173afdcd9868b4530ad9175132a81e7
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ .bundle
3
+ pkg/*
4
+ *.swp
5
+ .rvmrc
6
+ *.DS_Store
7
+ tmp/
8
+ log/
9
+ rdoc/
10
+ coverage/
11
+ spec/bitcoin/fixtures/fake_chain
12
+ *.conf
13
+ *.db
14
+ .rbx/
15
+ /vendor
16
+ .ruby-version
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ - 2.3.2
5
+ - 2.4.1
data/COPYING ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2018 Julian Langschaedel <meta.rb@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bitcoin-ruby.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'eventmachine'
8
+ gem 'ffi'
9
+ gem 'scrypt'
10
+ gem 'minitest'
11
+
12
+ gem "rake", ">= 0.8.0"
13
+ gem 'bacon', '>= 1.2.0'
14
+ #gem 'simplecov', require: false
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ monacoin-ruby (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ bacon (1.2.0)
10
+ eventmachine (1.2.5)
11
+ ffi (1.9.18)
12
+ ffi-compiler (1.0.1)
13
+ ffi (>= 1.0.0)
14
+ rake
15
+ minitest (5.11.1)
16
+ rake (12.3.0)
17
+ scrypt (3.0.5)
18
+ ffi-compiler (>= 1.0, < 2.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bacon (>= 1.2.0)
25
+ eventmachine
26
+ ffi
27
+ minitest
28
+ monacoin-ruby!
29
+ rake (>= 0.8.0)
30
+ scrypt
31
+
32
+ BUNDLED WITH
33
+ 1.16.1
data/README.rdoc ADDED
@@ -0,0 +1,210 @@
1
+ = Bitcoin-ruby {<img src="https://api.travis-ci.org/lian/bitcoin-ruby.svg?branch=master" />}[http://travis-ci.org/lian/bitcoin-ruby] {<img src="http://inch-ci.org/github/lian/bitcoin-ruby.svg?branch=master" alt="Inline docs" />}[http://inch-ci.org/github/lian/bitcoin-ruby] {<img src="https://tip4commit.com/projects/108.svg" alt="tip for next commit" />}[https://tip4commit.com/github/lian/bitcoin-ruby]
2
+
3
+ This is a ruby library for interacting with the bitcoin protocol/network.
4
+
5
+ Some of the main features are:
6
+
7
+ * Bitcoin::Util provides the basic bitcoin utility functions for base58, ECC, etc.
8
+ * Bitcoin::Protocol can parse/create all protocol messages
9
+ * Bitcoin::Script implementation, create/run scripts and verify signatures
10
+ * Bitcoin::Key provides a high-level API for creating and handling keys/addresses
11
+ * Bitcoin::Builder provides a high-level API for creating transactions (and blocks)
12
+ * Bitcoin::Litecoin implements all the litecoin-specific differences
13
+
14
+ == Related Projects
15
+
16
+ * toshi[https://github.com/coinbase/toshi]
17
+ * bitcoin-ruby-blockchain[http://github.com/mhanne/bitcoin-ruby-blockchain]
18
+ * bitcoin-ruby-node[http://github.com/mhanne/bitcoin-ruby-node]
19
+ * bitcoin-ruby-wallet[http://github.com/mhanne/bitcoin-ruby-wallet]
20
+ * bitcoin-ruby-gui[http://github.com/mhanne/bitcoin-ruby-gui]
21
+ * namecoin-ruby[http://github.com/mhanne/namecoin-ruby]
22
+
23
+ == Compatible with...
24
+
25
+ * ruby 1.9.3
26
+ * ruby 2.0.0
27
+ * ruby 2.1.2
28
+ * ruby 2.2.0
29
+ * ruby 2.2.2
30
+
31
+ == Installation
32
+
33
+ We assume you already have a ruby 1.9 or 2.0 compatible interpreter and rubygems environment.
34
+
35
+ git clone https://github.com/lian/bitcoin-ruby.git; cd bitcoin-ruby
36
+
37
+ if you want to have it available system-wide, just build the gem and install it:
38
+
39
+ gem build bitcoin-ruby.gemspec && gem install bitcoin-ruby-0.0.11.gem
40
+
41
+ Note that some aspects of the library (such as networking, storage, etc.) need
42
+ additional dependencies which are not specified in the gemspec. The core requirements are
43
+ intentionally kept to a minimum, so nobody has to install unneeded dependencies.
44
+
45
+ * +bacon+ to run the specs
46
+ * +scrypt+ to use a much faster scrypt hash implementation for Litecoin
47
+
48
+ If you would like to install using Bundler, put it in your Gemfile and run bundle install
49
+ gem 'bitcoin-ruby', git: 'https://github.com/lian/bitcoin-ruby', branch: 'master', require: 'bitcoin'
50
+
51
+ == Library Usage
52
+
53
+ There are different aspects to the library which can be used separately or in combination.
54
+ Here are some ideas of what you could do. There are also some demo scripts in examples/,
55
+ see EXAMPLES.
56
+
57
+ === Keys/Addresses
58
+
59
+ Generate a Bitcoin::Key
60
+
61
+ key = Bitcoin::generate_key
62
+ key #=> [<privkey>, <pubkey>]
63
+
64
+ Get the address from a public key
65
+
66
+ address = Bitcoin::pubkey_to_address(key[1])
67
+ address #=> <bitcoin address>
68
+
69
+ Check if an address is valid
70
+
71
+ Bitcoin::valid_address?(address) #=> true
72
+
73
+
74
+ === Blocks / Transactions parsing
75
+
76
+ Parse a Bitcoin::Protocol::Block
77
+
78
+ raw_block = File.open('spec/bitcoin/fixtures/rawblock-0.bin', 'rb') {|f| f.read}
79
+ blk = Bitcoin::Protocol::Block.new(raw_block)
80
+ blk.hash #=> 00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048
81
+ blk.tx.count #=> 1
82
+ blk.to_hash #=> ...
83
+ Bitcoin::Protocol::Block.from_json( blk.to_json )
84
+
85
+ Parse a Bitcoin::Protocol::Tx
86
+
87
+ raw_tx = File.open('spec/bitcoin/fixtures/rawtx-01.bin', 'rb') {|f| f.read}
88
+ tx = Bitcoin::Protocol::Tx.new(raw_tx)
89
+ tx.hash #=> 6e9dd16625b62cfcd4bf02edb89ca1f5a8c30c4b1601507090fb28e59f2d02b4
90
+ tx.in.size #=> 1
91
+ tx.out.size #=> 2
92
+ tx.to_hash #=> ...
93
+ Bitcoin::Protocol::Tx.from_json( tx.to_json )
94
+
95
+ Bitcoin::Script.new(tx.out[0].pk_script).to_string
96
+ #=> "OP_DUP OP_HASH160 b2e21c1db922e3bdc529de7b38b4c401399e9afd OP_EQUALVERIFY OP_CHECKSIG"
97
+
98
+ === Transaction verification / Scripts
99
+
100
+ Get the matching transactions (in this example tx1 is the spending transaction)
101
+
102
+ rawtx1 = File.open("spec/bitcoin/fixtures/rawtx-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16.bin", 'rb') {|f| f.read}
103
+ rawtx2 = File.open("spec/bitcoin/fixtures/rawtx-0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9.bin", 'rb') {|f| f.read}
104
+ tx1 = Bitcoin::Protocol::Tx.new(rawtx1)
105
+ tx2 = Bitcoin::Protocol::Tx.new(rawtx2)
106
+
107
+ Then simply ask the transaction to verify an input
108
+
109
+ tx1.verify_input_signature(0, tx2) #=> true
110
+
111
+ === Scripts
112
+
113
+ If you want to control the Bitcoin::Script yourself, you can do so
114
+
115
+ txin = tx1.in.first
116
+ txout = tx2.out[txin.prev_out_index]
117
+ script = Bitcoin::Script.new(txin.script_sig + txout.pk_script)
118
+
119
+ result = script.run do |pubkey, sig, hash_type|
120
+ hash = tx1.signature_hash_for_input(0, nil, txout.pk_script)
121
+ Bitcoin.verify_signature(hash, sig, pubkey.unpack("H*")[0])
122
+ end
123
+ result #=> true
124
+
125
+ === Create Transactions
126
+
127
+ You need to know the previous output you want to spend (tx hash and output index),
128
+ as well as the private key for the address required to sign for it.
129
+
130
+ # use testnet so you don't accidentally blow your whole money!
131
+ Bitcoin.network = :testnet3
132
+
133
+ # make the DSL methods available in your scope
134
+ include Bitcoin::Builder
135
+
136
+ # the previous transaction that has an output to your address
137
+ prev_hash = "6c44b284c20fa22bd69c57a9dbff91fb71deddc8c54fb2f5aa41fc78c96c1ad1"
138
+
139
+ # the number of the output you want to use
140
+ prev_out_index = 0
141
+
142
+ # fetch the tx from whereever you like and parse it
143
+ prev_tx = Bitcoin::P::Tx.from_json(open("http://test.webbtc.com/tx/#{prev_hash}.json"))
144
+
145
+ # the key needed to sign an input that spends the previous output
146
+ key = Bitcoin::Key.from_base58("92ZRu28m2GHSKaaF2W7RswJ2iJYpTzVhBaN6ZLs7TENCs4b7ML8")
147
+
148
+ # create a new transaction (and sign the inputs)
149
+ new_tx = build_tx do |t|
150
+
151
+ # add the input you picked out earlier
152
+ t.input do |i|
153
+ i.prev_out prev_tx
154
+ i.prev_out_index prev_out_index
155
+ i.signature_key key
156
+ end
157
+
158
+ # add an output that sends some bitcoins to another address
159
+ t.output do |o|
160
+ o.value 50000000 # 0.5 BTC in satoshis
161
+ o.script {|s| s.recipient "mugwYJ1sKyr8EDDgXtoh8sdDQuNWKYNf88" }
162
+ end
163
+
164
+ # add another output spending the remaining amount back to yourself
165
+ # if you want to pay a tx fee, reduce the value of this output accordingly
166
+ # if you want to keep your financial history private, use a different address
167
+ t.output do |o|
168
+ o.value 49000000 # 0.49 BTC, leave 0.01 BTC as fee
169
+ o.script {|s| s.recipient key.addr }
170
+ end
171
+
172
+ end
173
+
174
+ # examine your transaction. you can relay it through http://test.webbtc.com/relay_tx
175
+ # that will also give you a hint on the error if something goes wrong
176
+ puts new_tx.to_json
177
+
178
+ == Documentation
179
+
180
+ Always trying to improve, any help appreciated! If anything is unclear to you, let us know!
181
+
182
+ Documentation is generated using yardoc:
183
+
184
+ rake doc
185
+
186
+ The specs are also a good place to see how something works.
187
+
188
+ == Specs
189
+
190
+ The specs can be run with
191
+
192
+ rake bacon
193
+
194
+ or, if you want to run a single spec
195
+
196
+ ruby spec/bitcoin/bitcoin_spec.rb
197
+
198
+ If you make changes to the code or add functionality, please also add specs.
199
+
200
+ == Development
201
+
202
+ Any help or feedback is greatly appreciated! From getting knee-deep into elliptic-curve acrobatics,
203
+ to cleaning up high-level naming conventions, there is something for everyone to do.
204
+ Even if you are completely lost, just pointing out what is unclear helps a lot!
205
+
206
+ If you are curious or like to participate in development, drop by \#bitcoin-ruby on irc.freenode.net!
207
+
208
+ == License
209
+
210
+ Available here: [link:COPYING]
data/Rakefile ADDED
@@ -0,0 +1,112 @@
1
+ begin
2
+ require 'bundler/gem_tasks'
3
+ rescue LoadError
4
+ end
5
+
6
+
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
12
+
13
+ RUBY = 'ruby' unless defined?(RUBY)
14
+
15
+ task :default => :bacon
16
+ #
17
+ # test runner
18
+ #
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))}
29
+ end
30
+
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] }
34
+ end
35
+
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
88
+ end
89
+
90
+ total_color = some_failed ? red : green
91
+ puts(total_color % (spec_format % totals.to_a))
92
+ exit 1 if some_failed
93
+ end
94
+
95
+
96
+ desc 'Generate RDoc documentation'
97
+ task :rdoc do
98
+ `rm -rf rdoc`
99
+ system("rdoc -a -A -H -t 'bitcoin-ruby RDoc' -W 'https://github.com/mhanne/bitcoin-ruby/tree/master/%s' -o rdoc -m README.rdoc examples/ doc/ lib/ README.rdoc COPYING")
100
+ end
101
+
102
+ desc 'Generate test coverage report'
103
+ task :coverage do
104
+ begin
105
+ require 'simplecov'
106
+ rescue LoadError
107
+ puts "Simplecov not found. Run `gem install simplecov` to install it."
108
+ exit
109
+ end
110
+ sh "bacon", *PROJECT_SPECS
111
+ system('open coverage/index.html') if RUBY_PLATFORM.include? 'darwin'
112
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift( File.expand_path("../../lib", __FILE__) )
3
+ require 'bitcoin'
4
+
5
+ include Bitcoin
6
+ include Bitcoin::Util
7
+
8
+ Bitcoin.network = ARGV.shift || :monacoin
9
+
10
+ require 'irb'
11
+ require 'irb/completion'
12
+ IRB.start
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bitcoin/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "monacoin-ruby"
7
+ s.version = Bitcoin::VERSION
8
+ s.authors = ["lian wrote original files, Tkobayashi added"]
9
+ s.email = ["dev.koba@gmail.com"]
10
+ s.summary = %q{append monacoin utils and protocol to bitcoin-ruby)}
11
+ s.description = %q{This is a ruby library for interacting with the bitcoin(monacoin) protocol/network}
12
+ s.homepage = "https://github.com/crypto-team/mona-bitcoin-ruby"
13
+
14
+ s.rubyforge_project = "bitcoin-ruby-mona"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.required_rubygems_version = ">= 1.3.6"
22
+ #s.add_development_dependency "bacon"
23
+ end