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.
- checksums.yaml +5 -5
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/.rubocop.yml +46 -0
- data/.travis.yml +5 -1
- data/Gemfile +11 -9
- data/Gemfile.lock +64 -12
- data/README.rdoc +17 -4
- data/Rakefile +58 -83
- data/bitcoin-ruby.gemspec +5 -2
- data/lib/bitcoin.rb +31 -14
- data/lib/bitcoin/bech32.rb +126 -132
- data/lib/bitcoin/bloom_filter.rb +24 -21
- data/lib/bitcoin/builder.rb +168 -126
- data/lib/bitcoin/connection.rb +21 -24
- data/lib/bitcoin/contracthash.rb +20 -24
- data/lib/bitcoin/dogecoin.rb +79 -77
- data/lib/bitcoin/electrum/mnemonic.rb +28 -25
- data/lib/bitcoin/ext_key.rb +3 -3
- data/lib/bitcoin/ffi/bitcoinconsensus.rb +17 -13
- data/lib/bitcoin/ffi/openssl.rb +355 -338
- data/lib/bitcoin/ffi/secp256k1.rb +97 -64
- data/lib/bitcoin/protocol.rb +6 -3
- data/lib/bitcoin/protocol/address.rb +15 -13
- data/lib/bitcoin/protocol/aux_pow.rb +12 -15
- data/lib/bitcoin/protocol/block.rb +102 -76
- data/lib/bitcoin/protocol/handler.rb +2 -4
- data/lib/bitcoin/protocol/parser.rb +108 -92
- data/lib/bitcoin/protocol/partial_merkle_tree.rb +59 -47
- data/lib/bitcoin/protocol/reject.rb +26 -28
- data/lib/bitcoin/protocol/script_witness.rb +3 -8
- data/lib/bitcoin/protocol/tx.rb +250 -137
- data/lib/bitcoin/protocol/txin.rb +44 -38
- data/lib/bitcoin/protocol/txout.rb +27 -20
- data/lib/bitcoin/protocol/version.rb +47 -34
- data/lib/bitcoin/script.rb +18 -17
- data/lib/bitcoin/trezor/mnemonic.rb +113 -98
- data/lib/bitcoin/version.rb +1 -1
- data/spec/examples.txt +399 -0
- data/spec/{bitcoin/fixtures → fixtures}/000000000000056b1a3d84a1e2b33cde8915a4b61c0cae14fca6d3e1490b4f98.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/03d7e1fa4d5fefa169431f24f7798552861b255cd55d377066fedcd088fb0e99.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/0961c660358478829505e16a1f028757e54b5bbf9758341a7546573738f31429.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/0f24294a1d23efbb49c1765cf443fba7930702752aba6d765870082fe4f13cae.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/156e6e1b84c5c3bd3a0927b25e4119fadce6e6d5186f363317511d1d680fae9a.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/23b397edccd3740a74adb603c9756370fafcde9bcc4483eb271ecad09a94dd63.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/315ac7d4c26d69668129cc352851d9389b4a6868f1509c6c8b66bead11e2619f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/35e2001b428891fefa0bfb73167c7360669d3cbd7b3aa78e7cad125ddfc51131.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/3a17dace09ffb919ed627a93f1873220f4c975c1248558b18d16bce25d38c4b7.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/3e58b7eed0fdb599019af08578effea25c8666bbe8e200845453cacce6314477.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/514c46f0b61714092f15c8dfcb576c9f79b3f959989b98de3944b19d98832b58.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/51bf528ecf3c161e7c021224197dbe84f9a8564212f6207baa014c01a1668e1e.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/60a20bd93aa49ab4b28d514ec10b06e1829ce6818ec06cd3aabd013ebcdc4bb1.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/69216b8aaa35b76d6613e5f527f4858640d986e1046238583bdad79b35e938dc.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/7208e5edf525f04e705fb3390194e316205b8f995c8c9fcd8c6093abe04fa27d.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/761d8c5210fdfd505f6dff38f740ae3728eb93d7d0971fb433f685d40a4c04f6.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/8d0b238a06b5a70be75d543902d02d7a514d68d3252a949a513865ac3538874c.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/aea682d68a3ea5e3583e088dcbd699a5d44d4b083f02ad0aaf2598fe1fa4dfd4.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/base58_keys_invalid.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/base58_keys_valid.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/bc179baab547b7d7c1d5d8d6f8b0cc6318eaa4b0dd0a093ad6ac7f5a1cb6b3ba.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/bd1715f1abfdc62bea3f605bdb461b3ba1f2cca6ec0d73a18a548b7717ca8531.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/block-testnet-0000000000ac85bb2530a05a4214a387e6be02b22d3348abc5e7a5d9c4ce8dab.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/cd874fa8cb0e2ec2d385735d5e1fd482c4fe648533efb4c50ee53bda58e15ae2.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/ce5fad9b4ef094d8f4937b0707edaf0a6e6ceeaf67d5edbfd51f660eac8f398b.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/coinbase-toshi.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/coinbase.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/dogecoin-block-60323982f9c5ff1b5a954eac9dc1269352835f47c2c5222691d80f0d50dcf053.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/f003f0c1193019db2497a675fd05d9f2edddf9b67c59e677c48d3dbd4ed5f00b.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/filteredblock-0.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/litecoin-block-80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/litecoin-block-80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/litecoin-genesis-block-12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/litecoin-genesis-block-12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/litecoin-tx-f5aa30f574e3b6f1a3d99c07a6356ba812aabb9661e1d5f71edff828cbd5c996.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-0.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-0.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-1.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-1.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-131025.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-131025.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-170.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-9.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-auxpow.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-1151351.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-26478.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-26478.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawblock-testnet-265322.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-01-toshi.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-01.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-01.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-02-toshi.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-02.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-02.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-03-toshi.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-03.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-03.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-04.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-05.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-14be6fff8c6014f7c9493b4a6e4a741699173f39d74431b6b844fcb41ebb9984.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-2f4a2717ec8c9f077a87dde6cbe0274d5238793a3f3f492b63c744837285e58a.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-2f4a2717ec8c9f077a87dde6cbe0274d5238793a3f3f492b63c744837285e58a.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-406b2b06bcd34d3c8733e6b79f7a394c8a431fbf4ff5ac705c93f4076bb77602.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-52250a162c7d03d2e1fbc5ebd1801a88612463314b55102171c5b5d817d2d7b2.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-b5d4e8883533f99e5903ea2cf001a133a322fa6b1370b18a16c57c946a40823d.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-ba1ff5cd66713133c062a871a8adab92416f1e38d17786b2bf56ac5f6ffdfdf5.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-de35d060663750b3975b7997bde7fb76307cec5b270d12fcd9c4ad98b279c28c.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-p2wpkh.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-p2wpkh.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-04fdc38d6722ab4b12d79113fc4b2896bdcc5169710690ee4e78541b98e467b4.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-0b294c7d11dd21bcccb8393e6744fed7d4d1981a08c00e3e88838cc421f33c9f.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-3bc52ac063291ad92d95ddda5fd776a342083b95607ad32ed8bc6f8f7d30449e.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-6f0bbdd4e71a8af4305018d738184df32dbb6f27284fdebd5b56d16947f7c181.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-a220adf1902c46a39db25a24bc4178b6a88440f977a7e2cabfdd8b5c1dd35cfb.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-a7c9b06e275e8674cc19a5f7d3e557c72c6d93576e635b33212dbe08ab7cdb60.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/rawtx-testnet-f80acbd2f594d04ddb0e1cacba662132104909157dff526935a3c88abe9201a5.bin +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/script_tests.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/sighash.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-0295028ef826b2a188409cb905b631faebb9bb3cdf14510571c5f4bd8591338f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-03339a725007a279484fb6f5361f522dd1cf4d0923d30e6b973290dba4275f92.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-0a6a357e2f7796444e02638749d9611c008b253fb55f5dc88b739b230ed0c4c3.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-0ce7e5238fbdb6c086cf1b384b21b827e91cc23f360417265874a5a0d86ce367.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-0ef34c49f630aea17df0080728b0fc67bf5f87fbda936934a4b11b4a69d7821e.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-1129d2a8bd5bb3a81e54dc96a90f1f6b2544575748caa17243470935c5dd91b7.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-19aa42fee0fa57c45d3b16488198b27caaacc4ff5794510d0c17f173f05587ff.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-1a4f3b9dc4494aeedeb39f30dd37e60541b2abe3ed4977992017cc0ad4f44956.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-1f9191dcf2b1844ca28c6ef4b969e1d5fab70a5e3c56b7007949e55851cb0c4f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-22cd5fef23684d7b304e119bedffde6f54538d3d54a5bfa237e20dc2d9b4b5ad.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-28204cad1d7fc1d199e8ef4fa22f182de6258a3eaafe1bbe56ebdcacd3069a5f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-2958fb00b4fd6fe0353503b886eb9a193d502f4fd5fc042d5e03216ba918bbd6.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-29f277145749ad6efbed3ae6ce301f8d33c585ec26b7c044ad93c2f866e9e942.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-2c5e5376c20e9cc78d0fb771730e5d840cc2096eff0ef045b599fe92475ace1c.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-2c63aa814701cef5dbd4bbaddab3fea9117028f2434dddcdab8339141e9b14d1.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-313897799b1e37e9ecae15010e56156dddde4e683c96b0e713af95272c38aee0.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-326882a7f22b5191f1a0cc9962ca4b878cd969cf3b3a70887aece4d801a0ba5e.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-345bed8785c3282a264ffb0dbee61cde54854f10e16f1b3e75b7f2d9f62946f2.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-39ba7440b7103557560cc8ce258009936796485aaf8b478e66ab4cb97c66e31b.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-3a04d57a833367f1655cc5ec3beb587888ef4977a86caa8c8ad4ba7cc717eae7.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-3da75972766f0ad13319b0b461fd16823a731e44f6e9de4eb3c52d6a6fb6c8ae.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-4142ee4877eb116abf955a7ec6ef2dc38133b793df762b76d75e3d7d4d8badc9.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-44b833074e671120ba33106877b49e86ece510824b9af477a3853972bcd8d06a.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-46224764c7870f95b58f155bce1e38d4da8e99d42dbb632d0dd7c07e092ee5aa.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-5df1375ffe61ac35ca178ebb0cab9ea26dedbd0e96005dfcee7e379fa513232f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-62d9a565bd7b5344c5352e3e9e5f40fa4bbd467fa19c87357216ec8777ba1cce.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-6327783a064d4e350c454ad5cd90201aedf65b1fc524e73709c52f0163739190.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-6606c366a487bff9e412d0b6c09c14916319932db5954bf5d8719f43f828a3ba.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-6aaf18b9f1283b939d8e5d40ff5f8a435229f4178372659cc3a0bce4e262bf78.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-6b48bba6f6d2286d7ec0883c0fc3085955090813a4c94980466611c798b868cc.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-70cfbc6690f9ab46712db44e3079ac227962b2771a9341d4233d898b521619ef.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-7a1a9db42f065f75110fcdb1bc415549c8ef7670417ba1d35a67f1b8adc562c1.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-9a768fc7d0c4bdc86e25154357ef7c0063ca21310e5740a2f12f90b7455184a7.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-9cad8d523a0694f2509d092c39cebc8046adae62b4e4297102d568191d9478d8.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-9e052eb694bd7e15906433f064dff0161a12fd325c1124537766377004023c6f.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-9fb65b7304aaa77ac9580823c2c06b259cc42591e5cce66d76a81b6f51cc5c28.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-a955032f4d6b0c9bfe8cad8f00a8933790b9c1dc28c82e0f48e75b35da0e4944.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-aab7ef280abbb9cc6fbaf524d2645c3daf4fcca2b3f53370e618d9cedf65f1f8.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-ab9805c6d57d7070d9a42c5176e47bb705023e6b67249fb6760880548298e742.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-ad4bcf3241e5d2ad140564e20db3567d41594cf4c2012433fe46a2b70e0d87b8.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-b5b598de91787439afd5938116654e0b16b7a0d0f82742ba37564219c5afcbf9.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-b8fd633e7713a43d5ac87266adc78444669b987a56b3a65fb92d58c2c4b0e84d.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-bbca0628c42cb8bf7c3f4b2ad688fa56da5308dd2a10255da89fb1f46e6e413d.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-bc7fd132fcf817918334822ee6d9bd95c889099c96e07ca2c1eb2cc70db63224.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-c192b74844e4837a34c4a5a97b438f1c111405b01b99e2d12b7c96d07fc74c04.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-d3d77d63709e47d9ef58f0b557800115a6b676c6a423012fbb96f45d8fcef830.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-e335562f7e297aadeed88e5954bc4eeb8dc00b31d829eedb232e39d672b0c009.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-eb3b82c0884e3efa6d8b0be55b4915eb20be124c9766245bcc7f34fdac32bccb.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/tx-fee1b9b85531c8fb6cd7831f83490c7f2aa768b6eefe29854ef5e89ce7b9ecb1.json +0 -0
- data/spec/{bitcoin/fixtures → fixtures}/txscript-invalid-too-many-sigops-followed-by-invalid-pushdata.bin +0 -0
- data/spec/helpers/block_helpers.rb +58 -0
- data/spec/helpers/fixture_helpers.rb +20 -0
- data/spec/helpers/library_helpers.rb +15 -0
- data/spec/spec_helper.rb +109 -0
- data/spec/unit/bitcoin/bech32_spec.rb +187 -0
- data/spec/unit/bitcoin/bitcoin_spec.rb +1079 -0
- data/spec/unit/bitcoin/bloom_filter_spec.rb +33 -0
- data/spec/unit/bitcoin/builder_spec.rb +559 -0
- data/spec/unit/bitcoin/contracthash_spec.rb +52 -0
- data/spec/unit/bitcoin/ext_key_spec.rb +281 -0
- data/spec/unit/bitcoin/key_spec.rb +457 -0
- data/spec/unit/bitcoin/network_spec.rb +71 -0
- data/spec/unit/bitcoin/protocol/addr_spec.rb +90 -0
- data/spec/unit/bitcoin/protocol/aux_pow_spec.rb +45 -0
- data/spec/unit/bitcoin/protocol/bip143_spec.rb +334 -0
- data/spec/unit/bitcoin/protocol/block_spec.rb +280 -0
- data/spec/unit/bitcoin/protocol/getblocks_spec.rb +44 -0
- data/spec/unit/bitcoin/protocol/inv_spec.rb +166 -0
- data/spec/unit/bitcoin/protocol/notfound_spec.rb +44 -0
- data/spec/unit/bitcoin/protocol/parser_spec.rb +69 -0
- data/spec/unit/bitcoin/protocol/partial_merkle_tree_spec.rb +47 -0
- data/spec/unit/bitcoin/protocol/ping_spec.rb +62 -0
- data/spec/unit/bitcoin/protocol/tx_spec.rb +1515 -0
- data/spec/unit/bitcoin/protocol/txin_spec.rb +47 -0
- data/spec/unit/bitcoin/protocol/txout_spec.rb +36 -0
- data/spec/unit/bitcoin/protocol/version_spec.rb +121 -0
- data/spec/unit/bitcoin/script/opcodes_spec.rb +864 -0
- data/spec/unit/bitcoin/script/script_spec.rb +1610 -0
- data/spec/unit/bitcoin/secp256k1_spec.rb +138 -0
- data/spec/unit/bitcoin/trezor/mnemonic_spec.rb +193 -0
- data/spec/unit/integrations/dogecoin_spec.rb +215 -0
- metadata +381 -372
- data/lib/bitcoin/logger.rb +0 -86
- data/lib/bitcoin/protocol/alert.rb +0 -46
- data/spec/bitcoin/bech32_spec.rb +0 -160
- data/spec/bitcoin/bitcoin_spec.rb +0 -666
- data/spec/bitcoin/bloom_filter_spec.rb +0 -23
- data/spec/bitcoin/builder_spec.rb +0 -375
- data/spec/bitcoin/contracthash_spec.rb +0 -45
- data/spec/bitcoin/dogecoin_spec.rb +0 -176
- data/spec/bitcoin/ext_key_spec.rb +0 -180
- data/spec/bitcoin/ffi_openssl.rb +0 -45
- data/spec/bitcoin/fixtures/rawblock-170.json +0 -68
- data/spec/bitcoin/fixtures/rawblock-9.json +0 -39
- data/spec/bitcoin/fixtures/reorg/blk_0_to_4.dat +0 -0
- data/spec/bitcoin/fixtures/reorg/blk_3A.dat +0 -0
- data/spec/bitcoin/fixtures/reorg/blk_4A.dat +0 -0
- data/spec/bitcoin/fixtures/reorg/blk_5A.dat +0 -0
- data/spec/bitcoin/fixtures/testnet/block_0.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_1.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_2.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_3.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_4.bin +0 -0
- data/spec/bitcoin/fixtures/testnet/block_5.bin +0 -0
- data/spec/bitcoin/fixtures/txdp-1.txt +0 -32
- data/spec/bitcoin/fixtures/txdp-2-signed.txt +0 -19
- data/spec/bitcoin/fixtures/txdp-2-unsigned.txt +0 -14
- data/spec/bitcoin/helpers/fake_blockchain.rb +0 -183
- data/spec/bitcoin/key_spec.rb +0 -326
- data/spec/bitcoin/network_spec.rb +0 -50
- data/spec/bitcoin/performance/storage_spec.rb +0 -41
- data/spec/bitcoin/protocol/addr_spec.rb +0 -82
- data/spec/bitcoin/protocol/alert_spec.rb +0 -22
- data/spec/bitcoin/protocol/aux_pow_spec.rb +0 -45
- data/spec/bitcoin/protocol/bip143_spec.rb +0 -116
- data/spec/bitcoin/protocol/block_spec.rb +0 -208
- data/spec/bitcoin/protocol/getblocks_spec.rb +0 -32
- data/spec/bitcoin/protocol/inv_spec.rb +0 -134
- data/spec/bitcoin/protocol/notfound_spec.rb +0 -31
- data/spec/bitcoin/protocol/parser_spec.rb +0 -50
- data/spec/bitcoin/protocol/partial_merkle_tree_spec.rb +0 -38
- data/spec/bitcoin/protocol/ping_spec.rb +0 -51
- data/spec/bitcoin/protocol/reject.rb +0 -17
- data/spec/bitcoin/protocol/tx_spec.rb +0 -894
- data/spec/bitcoin/protocol/txin_spec.rb +0 -45
- data/spec/bitcoin/protocol/txout_spec.rb +0 -33
- data/spec/bitcoin/protocol/version_spec.rb +0 -110
- data/spec/bitcoin/script/opcodes_spec.rb +0 -773
- data/spec/bitcoin/script/script_spec.rb +0 -977
- data/spec/bitcoin/secp256k1_spec.rb +0 -78
- data/spec/bitcoin/spec_helper.rb +0 -108
- data/spec/bitcoin/trezor/mnemonic_spec.rb +0 -161
@@ -1,180 +0,0 @@
|
|
1
|
-
# encoding: ascii-8bit
|
2
|
-
|
3
|
-
require_relative 'spec_helper'
|
4
|
-
|
5
|
-
# BIP-32 test
|
6
|
-
# https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#Test_Vectors
|
7
|
-
describe Bitcoin::ExtKey do
|
8
|
-
|
9
|
-
describe 'Test Vector 1' do
|
10
|
-
|
11
|
-
before do
|
12
|
-
Bitcoin.network = :bitcoin
|
13
|
-
@master_key = Bitcoin::ExtKey.generate_master('000102030405060708090a0b0c0d0e0f'.htb)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'Chain m' do
|
17
|
-
@master_key.depth.should == 0
|
18
|
-
@master_key.number.should == 0
|
19
|
-
@master_key.fingerprint.should == '3442193e'
|
20
|
-
@master_key.chain_code.bth.should == '873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508'
|
21
|
-
@master_key.priv.should == 'e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35'
|
22
|
-
@master_key.addr.should == '15mKKb2eos1hWa6tisdPwwDC1a5J1y9nma'
|
23
|
-
@master_key.pub.should == '0339a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c2'
|
24
|
-
@master_key.to_base58.should == 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
|
25
|
-
@master_key.ext_pubkey.to_base58.should == 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8'
|
26
|
-
@master_key.ext_pubkey.pub.should == '0339a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c2'
|
27
|
-
@master_key.ext_pubkey.addr.should == '15mKKb2eos1hWa6tisdPwwDC1a5J1y9nma'
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'Chain m/0H' do
|
31
|
-
key = @master_key.derive(2**31)
|
32
|
-
key.depth.should == 1
|
33
|
-
key.fingerprint.should == '5c1bd648'
|
34
|
-
key.chain_code.bth.should == '47fdacbd0f1097043b78c63c20c34ef4ed9a111d980047ad16282c7ae6236141'
|
35
|
-
key.priv_key.priv.should == 'edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea'
|
36
|
-
key.to_base58.should == 'xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7'
|
37
|
-
key.ext_pubkey.to_base58.should == 'xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw'
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'Chain m/0H/1' do
|
41
|
-
key = @master_key.derive(2**31).derive(1)
|
42
|
-
key.depth.should == 2
|
43
|
-
key.fingerprint.should == 'bef5a2f9'
|
44
|
-
key.chain_code.bth.should == '2a7857631386ba23dacac34180dd1983734e444fdbf774041578e9b6adb37c19'
|
45
|
-
key.priv_key.priv.should == '3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368'
|
46
|
-
key.to_base58.should == 'xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs'
|
47
|
-
key.ext_pubkey.to_base58.should == 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ'
|
48
|
-
|
49
|
-
# pubkey derivation
|
50
|
-
ext_pubkey = @master_key.derive(2**31).ext_pubkey.derive(1)
|
51
|
-
ext_pubkey.to_base58.should == 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ'
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'Chain m/0H/1/2H' do
|
55
|
-
key = @master_key.derive(2**31).derive(1).derive(2**31 + 2)
|
56
|
-
key.depth.should == 3
|
57
|
-
key.fingerprint.should == 'ee7ab90c'
|
58
|
-
key.chain_code.bth.should == '04466b9cc8e161e966409ca52986c584f07e9dc81f735db683c3ff6ec7b1503f'
|
59
|
-
key.priv_key.priv.should == 'cbce0d719ecf7431d88e6a89fa1483e02e35092af60c042b1df2ff59fa424dca'
|
60
|
-
key.to_base58.should == 'xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM'
|
61
|
-
key.ext_pubkey.to_base58.should == 'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5'
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'Chain m/0H/1/2H/2' do
|
65
|
-
key = @master_key.derive(2**31).derive(1).derive(2**31 + 2).derive(2)
|
66
|
-
key.depth.should == 4
|
67
|
-
key.fingerprint.should == 'd880d7d8'
|
68
|
-
key.chain_code.bth.should == 'cfb71883f01676f587d023cc53a35bc7f88f724b1f8c2892ac1275ac822a3edd'
|
69
|
-
key.priv_key.priv.should == '0f479245fb19a38a1954c5c7c0ebab2f9bdfd96a17563ef28a6a4b1a2a764ef4'
|
70
|
-
key.to_base58.should == 'xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334'
|
71
|
-
key.ext_pubkey.to_base58.should == 'xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV'
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'Chain m/0H/1/2H/2/1000000000' do
|
75
|
-
key = @master_key.derive(2**31).derive(1).derive(2**31 + 2).derive(2).derive(1000000000)
|
76
|
-
key.depth.should == 5
|
77
|
-
key.fingerprint.should == 'd69aa102'
|
78
|
-
key.chain_code.bth.should == 'c783e67b921d2beb8f6b389cc646d7263b4145701dadd2161548a8b078e65e9e'
|
79
|
-
key.priv_key.priv.should == '471b76e389e528d6de6d816857e012c5455051cad6660850e58372a6c3e6e7c8'
|
80
|
-
key.to_base58.should == 'xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76'
|
81
|
-
key.ext_pubkey.to_base58.should == 'xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy'
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe 'Test Vector 2' do
|
86
|
-
before do
|
87
|
-
Bitcoin.network = :bitcoin
|
88
|
-
@master_key = Bitcoin::ExtKey.generate_master('fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542'.htb)
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'Chain m' do
|
92
|
-
@master_key.depth.should == 0
|
93
|
-
@master_key.number.should == 0
|
94
|
-
@master_key.to_base58.should == 'xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U'
|
95
|
-
@master_key.ext_pubkey.to_base58.should == 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB'
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'Chain m/0' do
|
99
|
-
key = @master_key.derive(0)
|
100
|
-
key.depth.should == 1
|
101
|
-
key.number.should == 0
|
102
|
-
key.to_base58.should == 'xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt'
|
103
|
-
key.ext_pubkey.to_base58.should == 'xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH'
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'Chain m/0/2147483647H' do
|
107
|
-
key = @master_key.derive(0).derive(2**31 + 2147483647)
|
108
|
-
key.depth.should == 2
|
109
|
-
key.number.should == 2**31 + 2147483647
|
110
|
-
key.to_base58.should == 'xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9'
|
111
|
-
key.ext_pubkey.to_base58.should == 'xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a'
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'Chain m/0/2147483647H/1' do
|
115
|
-
key = @master_key.derive(0).derive(2**31 + 2147483647).derive(1)
|
116
|
-
key.depth.should == 3
|
117
|
-
key.number.should == 1
|
118
|
-
key.to_base58.should == 'xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef'
|
119
|
-
key.ext_pubkey.to_base58.should == 'xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon'
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'Chain m/0/2147483647H/1/2147483646H' do
|
123
|
-
key = @master_key.derive(0).derive(2**31 + 2147483647).derive(1).derive(2**31 + 2147483646)
|
124
|
-
key.depth.should == 4
|
125
|
-
key.number.should == 2**31 + 2147483646
|
126
|
-
key.to_base58.should == 'xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc'
|
127
|
-
key.ext_pubkey.to_base58.should == 'xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL'
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'Chain m/0/2147483647H/1/2147483646H/2' do
|
131
|
-
key = @master_key.derive(0).derive(2**31 + 2147483647).derive(1).derive(2**31 + 2147483646).derive(2)
|
132
|
-
key.depth.should == 5
|
133
|
-
key.number.should == 2
|
134
|
-
key.to_base58.should == 'xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j'
|
135
|
-
key.ext_pubkey.to_base58.should == 'xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt'
|
136
|
-
ext_pubkey = @master_key.derive(0).derive(2**31 + 2147483647).derive(1).derive(2**31 + 2147483646).ext_pubkey.derive(2)
|
137
|
-
ext_pubkey.to_base58.should == 'xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt'
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
141
|
-
|
142
|
-
describe 'import from base58 address' do
|
143
|
-
|
144
|
-
it 'import private key' do
|
145
|
-
# normal key
|
146
|
-
key = Bitcoin::ExtKey.from_base58('xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs')
|
147
|
-
key.depth.should == 2
|
148
|
-
key.number.should == 1
|
149
|
-
key.chain_code.bth.should == '2a7857631386ba23dacac34180dd1983734e444fdbf774041578e9b6adb37c19'
|
150
|
-
key.priv_key.priv.should == '3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368'
|
151
|
-
key.ext_pubkey.to_base58.should == 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ'
|
152
|
-
|
153
|
-
# hardended key
|
154
|
-
key = Bitcoin::ExtKey.from_base58('xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM')
|
155
|
-
key.depth.should == 3
|
156
|
-
key.number.should == 2**31 + 2
|
157
|
-
key.fingerprint.should == 'ee7ab90c'
|
158
|
-
key.chain_code.bth.should == '04466b9cc8e161e966409ca52986c584f07e9dc81f735db683c3ff6ec7b1503f'
|
159
|
-
key.priv_key.priv.should == 'cbce0d719ecf7431d88e6a89fa1483e02e35092af60c042b1df2ff59fa424dca'
|
160
|
-
key.to_base58.should == 'xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM'
|
161
|
-
key.ext_pubkey.to_base58.should == 'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5'
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'import public key' do
|
165
|
-
# normal key
|
166
|
-
key = Bitcoin::ExtPubkey.from_base58('xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ')
|
167
|
-
key.depth.should == 2
|
168
|
-
key.number.should == 1
|
169
|
-
key.chain_code.bth.should == '2a7857631386ba23dacac34180dd1983734e444fdbf774041578e9b6adb37c19'
|
170
|
-
key.to_base58.should == 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ'
|
171
|
-
|
172
|
-
# hardended key
|
173
|
-
key = Bitcoin::ExtPubkey.from_base58('xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5')
|
174
|
-
key.depth.should == 3
|
175
|
-
key.number.should == 2**31 + 2
|
176
|
-
key.fingerprint.should == 'ee7ab90c'
|
177
|
-
key.chain_code.bth.should == '04466b9cc8e161e966409ca52986c584f07e9dc81f735db683c3ff6ec7b1503f'
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
data/spec/bitcoin/ffi_openssl.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# encoding: ascii-8bit
|
2
|
-
|
3
|
-
require_relative 'spec_helper.rb'
|
4
|
-
require 'bitcoin'
|
5
|
-
|
6
|
-
|
7
|
-
describe 'Bitcoin FFI OpenSSL Helpers' do
|
8
|
-
it 'should convert high-S DER signatures to low-S equivalents' do
|
9
|
-
Bitcoin.network = 'testnet'
|
10
|
-
|
11
|
-
tx_in = Bitcoin::Protocol::Tx.new( fixtures_file('rawtx-testnet-6f0bbdd4e71a8af4305018d738184df32dbb6f27284fdebd5b56d16947f7c181.bin') )
|
12
|
-
tx_out = Bitcoin::Protocol::Tx.new( fixtures_file('rawtx-testnet-a7c9b06e275e8674cc19a5f7d3e557c72c6d93576e635b33212dbe08ab7cdb60.bin') )
|
13
|
-
original_hash = tx_out.hash
|
14
|
-
tx_out.verify_input_signature(0, tx_in).should == true
|
15
|
-
script_sig = Bitcoin::Script.new(tx_out.in[0].script_sig)
|
16
|
-
sig = script_sig.chunks[0]
|
17
|
-
pubkey = script_sig.chunks[1]
|
18
|
-
Bitcoin::Script::is_low_der_signature?(sig).should == false
|
19
|
-
|
20
|
-
sig = Bitcoin::OpenSSL_EC.signature_to_low_s(sig)
|
21
|
-
Bitcoin::Script::is_low_der_signature?(sig).should == true
|
22
|
-
|
23
|
-
tx_out.in[0].script_sig = Bitcoin::Script.to_signature_pubkey_script(sig, pubkey)
|
24
|
-
tx_out.verify_input_signature(0, tx_in).should == true
|
25
|
-
|
26
|
-
# Repack the transaction to force hash update
|
27
|
-
tx_out = Bitcoin::Protocol::Tx.new( tx_out.to_payload )
|
28
|
-
original_hash.should != tx_out.hash
|
29
|
-
|
30
|
-
Bitcoin.network = 'bitcoin'
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'Bitcoin::OpenSSL_EC.repack_der_signature' do
|
34
|
-
s = "304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d09"
|
35
|
-
ns = Bitcoin::OpenSSL_EC.repack_der_signature([s].pack("H*")).unpack("H*")[0]
|
36
|
-
ns.should == s
|
37
|
-
|
38
|
-
[
|
39
|
-
"304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860",
|
40
|
-
"304402204e45e16932",
|
41
|
-
"304402204",
|
42
|
-
"3044",
|
43
|
-
].all?{|s| Bitcoin::OpenSSL_EC.repack_der_signature([s].pack("H*")) == false }.should == true
|
44
|
-
end
|
45
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"hash":"00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee",
|
3
|
-
"ver":1,
|
4
|
-
"prev_block":"000000002a22cfee1f2c846adbd12b3e183d4f97683f85dad08a79780a84bd55",
|
5
|
-
"mrkl_root":"7dac2c5666815c17a3b36427de37bb9d2e2c5ccec3f8633eb91a4205cb4c10ff",
|
6
|
-
"time":1231731025,
|
7
|
-
"bits":486604799,
|
8
|
-
"nonce":1889418792,
|
9
|
-
"n_tx":2,
|
10
|
-
"size":490,
|
11
|
-
"tx":[
|
12
|
-
{
|
13
|
-
"hash":"b1fea52486ce0c62bb442b530a3f0132b826c74e473d1f2c220bfa78111c5082",
|
14
|
-
"ver":1,
|
15
|
-
"vin_sz":1,
|
16
|
-
"vout_sz":1,
|
17
|
-
"lock_time":0,
|
18
|
-
"size":134,
|
19
|
-
"in":[
|
20
|
-
{
|
21
|
-
"prev_out":{
|
22
|
-
"hash":"0000000000000000000000000000000000000000000000000000000000000000",
|
23
|
-
"n":4294967295
|
24
|
-
},
|
25
|
-
"coinbase":"04ffff001d0102"
|
26
|
-
}
|
27
|
-
],
|
28
|
-
"out":[
|
29
|
-
{
|
30
|
-
"value":"50.00000000",
|
31
|
-
"scriptPubKey":"04d46c4968bde02899d2aa0963367c7a6ce34eec332b32e42e5f3407e052d64ac625da6f0718e7b302140434bd725706957c092db53805b821a85b23a7ac61725b OP_CHECKSIG"
|
32
|
-
}
|
33
|
-
]
|
34
|
-
},
|
35
|
-
{
|
36
|
-
"hash":"f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16",
|
37
|
-
"ver":1,
|
38
|
-
"vin_sz":1,
|
39
|
-
"vout_sz":2,
|
40
|
-
"lock_time":0,
|
41
|
-
"size":275,
|
42
|
-
"in":[
|
43
|
-
{
|
44
|
-
"prev_out":{
|
45
|
-
"hash":"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9",
|
46
|
-
"n":0
|
47
|
-
},
|
48
|
-
"scriptSig":"304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901"
|
49
|
-
}
|
50
|
-
],
|
51
|
-
"out":[
|
52
|
-
{
|
53
|
-
"value":"10.00000000",
|
54
|
-
"scriptPubKey":"04ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84c OP_CHECKSIG"
|
55
|
-
},
|
56
|
-
{
|
57
|
-
"value":"40.00000000",
|
58
|
-
"scriptPubKey":"0411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3 OP_CHECKSIG"
|
59
|
-
}
|
60
|
-
]
|
61
|
-
}
|
62
|
-
],
|
63
|
-
"mrkl_tree":[
|
64
|
-
"b1fea52486ce0c62bb442b530a3f0132b826c74e473d1f2c220bfa78111c5082",
|
65
|
-
"f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16",
|
66
|
-
"7dac2c5666815c17a3b36427de37bb9d2e2c5ccec3f8633eb91a4205cb4c10ff"
|
67
|
-
]
|
68
|
-
}
|
@@ -1,39 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"hash":"000000008d9dc510f23c2657fc4f67bea30078cc05a90eb89e84cc475c080805",
|
3
|
-
"ver":1,
|
4
|
-
"prev_block":"00000000408c48f847aa786c2268fc3e6ec2af68e8468a34a28c61b7f1de0dc6",
|
5
|
-
"mrkl_root":"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9",
|
6
|
-
"time":1231473279,
|
7
|
-
"bits":486604799,
|
8
|
-
"nonce":1397702696,
|
9
|
-
"n_tx":1,
|
10
|
-
"size":215,
|
11
|
-
"tx":[
|
12
|
-
{
|
13
|
-
"hash":"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9",
|
14
|
-
"ver":1,
|
15
|
-
"vin_sz":1,
|
16
|
-
"vout_sz":1,
|
17
|
-
"lock_time":0,
|
18
|
-
"size":134,
|
19
|
-
"in":[
|
20
|
-
{
|
21
|
-
"prev_out":{
|
22
|
-
"hash":"0000000000000000000000000000000000000000000000000000000000000000",
|
23
|
-
"n":4294967295
|
24
|
-
},
|
25
|
-
"coinbase":"04ffff001d0134"
|
26
|
-
}
|
27
|
-
],
|
28
|
-
"out":[
|
29
|
-
{
|
30
|
-
"value":"50.00000000",
|
31
|
-
"scriptPubKey":"0411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3 OP_CHECKSIG"
|
32
|
-
}
|
33
|
-
]
|
34
|
-
}
|
35
|
-
],
|
36
|
-
"mrkl_tree":[
|
37
|
-
"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9"
|
38
|
-
]
|
39
|
-
}
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,32 +0,0 @@
|
|
1
|
-
-----BEGIN-TRANSACTION-3fX59xPj-------------------------------------------------
|
2
|
-
_TXDIST_fabfb5da_3fX59xPj_00a0
|
3
|
-
010000000292807c8e70a28c687daea2998d6273d074e56fa8a55a0b10556974cf2b526e61000000
|
4
|
-
0000ffffffffe3c1ee0711611b01af3dee55b1484f0d6b65d17dce4eff0e6e06242e6cf457e10000
|
5
|
-
000000ffffffff02b0feea0b000000001976a91457996661391fa4e95bed27d7e8fe47f47cb8e428
|
6
|
-
88ac00a0acb9030000001976a914dc504e07b1107110f601fb679dd3f56cee9ff71e88ac00000000
|
7
|
-
0100000001eb626e4f73d88f415a8e8cb32b8d73eed47aa1039d0ed2f013abdc741ce6828c010000
|
8
|
-
008c493046022100b0da540e4924518f8989a9da798ca2d9e761b69a173b8cc41a3e3e3c6d77cd50
|
9
|
-
022100ecfa61730e58005338420516744ef680428dcfc05022dec70a851365c8575b190141042dc5
|
10
|
-
be3afa5887aee4a377032ed014361b0b9b61eb3ea6b8a8821bfe13ee4b65cd25d9630e4f227a53e8
|
11
|
-
bf637f85452c9981bcbd64ef77e22ce97b0f547c783effffffff0200d6117e030000001976a914cf
|
12
|
-
f580fd243f64f0ad7bf69faf41c0bf42d86d8988ac00205fa0120000001976a9148d573ef6984fd9
|
13
|
-
f8847d420001f7ac49b222a24988ac000000000100000001f2782db40ae147398a31cff9c7cc3423
|
14
|
-
014a073a92e463741244330cc304168f000000008c493046022100c9311b9eef0cc69219cb96838f
|
15
|
-
dd621530a80c46269a00dccc66498bc03ccf7a0221003742ee652a0a76fd28ad81aa73bb7f7a0a6a
|
16
|
-
81850af58f62d9a184d10e5eec30014104f815e8ef4cad584e04974889d7636e8933803d2e72991d
|
17
|
-
b5288c9e953c2465533905f98b7b688898c7c1f0708f2e49f0dd0abc06859ffed5144e8a1018a4e8
|
18
|
-
63ffffffff02008c8647000000001976a914d4e211215967f8e3744693bf85f47eb4ee9567fc88ac
|
19
|
-
603d4e95010000001976a914e9a6b50901c1969d2b0fd43a3ccfa3fef3291efe88ac00000000
|
20
|
-
_TXINPUT_00_150.00000000
|
21
|
-
_SIG_mzUYGfqGpyXmppYpmWJ31Y4zTxR4ZCod22_00_008c
|
22
|
-
4930460221007699967c3ec09d072599558d2e7082fae0820206b63aa66afea124634ed11a080221
|
23
|
-
0003346f7e963e645ecae2855026dc7332eb7237012539b34cd441c3cef97fbd4d01410497d5e1a0
|
24
|
-
0e1db90e893d1f2e547e2ee83b5d6bf4ddaa3d514e6dc2d94b6bcb5a72be1fcec766b8c382502caa
|
25
|
-
9ec09fe478bad07d3f38ff47b2eb42e681c384cc
|
26
|
-
_TXINPUT_01_12.00000000
|
27
|
-
_SIG_mzvaN8JUhHLz3Gdec1zBRxs5rNaYLQnbD1_01_008c
|
28
|
-
49304602210081554f8b08a1ad8caa69e34f4794d54952dac7c5efcf2afe080985d6bd5b00770221
|
29
|
-
00dea20ca3dbae1d15ec61bec57b4b8062e7d7c47614aba032c5a32f651f471cfd014104c30936d2
|
30
|
-
456298a566aa76fefeab8a7cb7a91e8a936a11757c911b4c669f0434d12ab0936fc13986b156156f
|
31
|
-
9b389ed244bbb580112be07dbe23949a4764dffb
|
32
|
-
-------END-TRANSACTION-3fX59xPj-------------------------------------------------
|
@@ -1,19 +0,0 @@
|
|
1
|
-
-----BEGIN-TRANSACTION-7Q74Wkre-------------------------------------------------
|
2
|
-
_TXDIST_fabfb5da_7Q74Wkre_0077
|
3
|
-
01000000019e2427307130506eafdda0af0f63b8e3193ca69576051176e9eb72822f9483b1000000
|
4
|
-
0000ffffffff0200943577000000001976a91419b8a1e3a0bbd0263d7a739b08e60f38dbfd7d5988
|
5
|
-
ac60a86659000000001976a9142d6b96901d5f345be776993073c4a2480f3c73a988ac0000000001
|
6
|
-
0000000107142cfa30008349f67e64a0ad4300814b27c2e264a187727f64f2bf746bce9f00000000
|
7
|
-
8c4930460221009eb7baac7ae0c161617c5ee59f6fe9c47cc11dd3472845e9268e739dfc064b6e02
|
8
|
-
210025ebb1a8f4b2136fb67ae2e737ad38667b83ceccbb3c3ca47b98a2d0cb7d916f014104e74942
|
9
|
-
d869b34395a2a75449056ac62db4209af97f34980e50f0882b9487e9bb556df5b3d6668c3e1dabdc
|
10
|
-
23e65e36a54dc7b0c8aa0ce235315b454e0cc2373affffffff02b0ff9cd0000000001976a9144ece
|
11
|
-
746ce438fb05e8482914ebd26f06bc57aac588ac002f6859000000001976a91419b8a1e3a0bbd026
|
12
|
-
3d7a739b08e60f38dbfd7d5988ac00000000
|
13
|
-
_TXINPUT_00_34.99949999
|
14
|
-
_SIG_mnheKkGdmw8d1fUV15XZbfmLR6AjQjVthy_00_008c
|
15
|
-
49304602210087bc1ff770c6cb3c7e47b9a3acb7dce678c16350f29acaa92e4ab231692256cf0221
|
16
|
-
002da46fc1f39e132e726dea46a6e87e4278e85d36ccd393e39e931b89d55fc3a2014104955ec564
|
17
|
-
6652d1b5bb14b2f867ef8879bcf224f1eab01072147fdfe0992440a234b36792937a23df736e8430
|
18
|
-
613da6f0466bfc5505f2ad41b056131b7af13086
|
19
|
-
-------END-TRANSACTION-7Q74Wkre-------------------------------------------------
|
@@ -1,14 +0,0 @@
|
|
1
|
-
-----BEGIN-TRANSACTION-7Q74Wkre-------------------------------------------------
|
2
|
-
_TXDIST_fabfb5da_7Q74Wkre_0077
|
3
|
-
01000000019e2427307130506eafdda0af0f63b8e3193ca69576051176e9eb72822f9483b1000000
|
4
|
-
0000ffffffff0200943577000000001976a91419b8a1e3a0bbd0263d7a739b08e60f38dbfd7d5988
|
5
|
-
ac60a86659000000001976a9142d6b96901d5f345be776993073c4a2480f3c73a988ac0000000001
|
6
|
-
0000000107142cfa30008349f67e64a0ad4300814b27c2e264a187727f64f2bf746bce9f00000000
|
7
|
-
8c4930460221009eb7baac7ae0c161617c5ee59f6fe9c47cc11dd3472845e9268e739dfc064b6e02
|
8
|
-
210025ebb1a8f4b2136fb67ae2e737ad38667b83ceccbb3c3ca47b98a2d0cb7d916f014104e74942
|
9
|
-
d869b34395a2a75449056ac62db4209af97f34980e50f0882b9487e9bb556df5b3d6668c3e1dabdc
|
10
|
-
23e65e36a54dc7b0c8aa0ce235315b454e0cc2373affffffff02b0ff9cd0000000001976a9144ece
|
11
|
-
746ce438fb05e8482914ebd26f06bc57aac588ac002f6859000000001976a91419b8a1e3a0bbd026
|
12
|
-
3d7a739b08e60f38dbfd7d5988ac00000000
|
13
|
-
_TXINPUT_00_34.99950000
|
14
|
-
-------END-TRANSACTION-7Q74Wkre-------------------------------------------------
|
@@ -1,183 +0,0 @@
|
|
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
|