bitcoin-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. data/.gitignore +12 -0
  2. data/COPYING +18 -0
  3. data/Gemfile +4 -0
  4. data/README.rdoc +189 -0
  5. data/Rakefile +104 -0
  6. data/bin/bitcoin_dns_seed +130 -0
  7. data/bin/bitcoin_gui +80 -0
  8. data/bin/bitcoin_node +174 -0
  9. data/bin/bitcoin_shell +12 -0
  10. data/bin/bitcoin_wallet +323 -0
  11. data/bitcoin-ruby.gemspec +27 -0
  12. data/concept-examples/blockchain-pow.rb +151 -0
  13. data/doc/CONFIG.rdoc +66 -0
  14. data/doc/EXAMPLES.rdoc +9 -0
  15. data/doc/NODE.rdoc +35 -0
  16. data/doc/STORAGE.rdoc +21 -0
  17. data/doc/WALLET.rdoc +102 -0
  18. data/examples/balance.rb +60 -0
  19. data/examples/bbe_verify_tx.rb +55 -0
  20. data/examples/connect.rb +36 -0
  21. data/examples/relay_tx.rb +22 -0
  22. data/examples/verify_tx.rb +57 -0
  23. data/lib/bitcoin.rb +370 -0
  24. data/lib/bitcoin/builder.rb +266 -0
  25. data/lib/bitcoin/config.rb +56 -0
  26. data/lib/bitcoin/connection.rb +126 -0
  27. data/lib/bitcoin/ffi/openssl.rb +121 -0
  28. data/lib/bitcoin/gui/addr_view.rb +42 -0
  29. data/lib/bitcoin/gui/bitcoin-ruby.png +0 -0
  30. data/lib/bitcoin/gui/bitcoin-ruby.svg +80 -0
  31. data/lib/bitcoin/gui/conn_view.rb +36 -0
  32. data/lib/bitcoin/gui/connection.rb +68 -0
  33. data/lib/bitcoin/gui/em_gtk.rb +28 -0
  34. data/lib/bitcoin/gui/gui.builder +1643 -0
  35. data/lib/bitcoin/gui/gui.rb +290 -0
  36. data/lib/bitcoin/gui/helpers.rb +113 -0
  37. data/lib/bitcoin/gui/tree_view.rb +82 -0
  38. data/lib/bitcoin/gui/tx_view.rb +67 -0
  39. data/lib/bitcoin/key.rb +125 -0
  40. data/lib/bitcoin/logger.rb +65 -0
  41. data/lib/bitcoin/network/command_client.rb +93 -0
  42. data/lib/bitcoin/network/command_handler.rb +179 -0
  43. data/lib/bitcoin/network/connection_handler.rb +274 -0
  44. data/lib/bitcoin/network/node.rb +399 -0
  45. data/lib/bitcoin/protocol.rb +140 -0
  46. data/lib/bitcoin/protocol/address.rb +48 -0
  47. data/lib/bitcoin/protocol/alert.rb +47 -0
  48. data/lib/bitcoin/protocol/block.rb +154 -0
  49. data/lib/bitcoin/protocol/handler.rb +38 -0
  50. data/lib/bitcoin/protocol/parser.rb +148 -0
  51. data/lib/bitcoin/protocol/tx.rb +205 -0
  52. data/lib/bitcoin/protocol/txin.rb +97 -0
  53. data/lib/bitcoin/protocol/txout.rb +73 -0
  54. data/lib/bitcoin/protocol/version.rb +70 -0
  55. data/lib/bitcoin/script.rb +634 -0
  56. data/lib/bitcoin/storage/dummy.rb +164 -0
  57. data/lib/bitcoin/storage/models.rb +133 -0
  58. data/lib/bitcoin/storage/sequel.rb +335 -0
  59. data/lib/bitcoin/storage/sequel_store/sequel_migrations.rb +84 -0
  60. data/lib/bitcoin/storage/storage.rb +243 -0
  61. data/lib/bitcoin/version.rb +3 -0
  62. data/lib/bitcoin/wallet/coinselector.rb +30 -0
  63. data/lib/bitcoin/wallet/keygenerator.rb +75 -0
  64. data/lib/bitcoin/wallet/keystore.rb +203 -0
  65. data/lib/bitcoin/wallet/txdp.rb +116 -0
  66. data/lib/bitcoin/wallet/wallet.rb +243 -0
  67. data/spec/bitcoin/bitcoin_spec.rb +472 -0
  68. data/spec/bitcoin/builder_spec.rb +90 -0
  69. data/spec/bitcoin/fixtures/0d0affb5964abe804ffe85e53f1dbb9f29e406aa3046e2db04fba240e63c7fdd.json +27 -0
  70. data/spec/bitcoin/fixtures/23b397edccd3740a74adb603c9756370fafcde9bcc4483eb271ecad09a94dd63.json +23 -0
  71. data/spec/bitcoin/fixtures/477fff140b363ec2cc51f3a65c0c58eda38f4d41f04a295bbd62babf25e4c590.json +27 -0
  72. data/spec/bitcoin/fixtures/60a20bd93aa49ab4b28d514ec10b06e1829ce6818ec06cd3aabd013ebcdc4bb1.json +45 -0
  73. data/spec/bitcoin/fixtures/bc179baab547b7d7c1d5d8d6f8b0cc6318eaa4b0dd0a093ad6ac7f5a1cb6b3ba.json +34 -0
  74. data/spec/bitcoin/fixtures/rawblock-0.bin +0 -0
  75. data/spec/bitcoin/fixtures/rawblock-0.json +39 -0
  76. data/spec/bitcoin/fixtures/rawblock-1.bin +0 -0
  77. data/spec/bitcoin/fixtures/rawblock-1.json +39 -0
  78. data/spec/bitcoin/fixtures/rawblock-131025.bin +0 -0
  79. data/spec/bitcoin/fixtures/rawblock-131025.json +5063 -0
  80. data/spec/bitcoin/fixtures/rawblock-170.bin +0 -0
  81. data/spec/bitcoin/fixtures/rawblock-170.json +68 -0
  82. data/spec/bitcoin/fixtures/rawblock-9.bin +0 -0
  83. data/spec/bitcoin/fixtures/rawblock-9.json +39 -0
  84. data/spec/bitcoin/fixtures/rawblock-testnet-26478.bin +0 -0
  85. data/spec/bitcoin/fixtures/rawblock-testnet-26478.json +64 -0
  86. data/spec/bitcoin/fixtures/rawtx-01.bin +0 -0
  87. data/spec/bitcoin/fixtures/rawtx-01.json +27 -0
  88. data/spec/bitcoin/fixtures/rawtx-02.bin +0 -0
  89. data/spec/bitcoin/fixtures/rawtx-02.json +27 -0
  90. data/spec/bitcoin/fixtures/rawtx-03.bin +0 -0
  91. data/spec/bitcoin/fixtures/rawtx-03.json +48 -0
  92. data/spec/bitcoin/fixtures/rawtx-04.json +27 -0
  93. data/spec/bitcoin/fixtures/rawtx-0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9.bin +0 -0
  94. data/spec/bitcoin/fixtures/rawtx-05.json +23 -0
  95. data/spec/bitcoin/fixtures/rawtx-14be6fff8c6014f7c9493b4a6e4a741699173f39d74431b6b844fcb41ebb9984.bin +0 -0
  96. data/spec/bitcoin/fixtures/rawtx-2f4a2717ec8c9f077a87dde6cbe0274d5238793a3f3f492b63c744837285e58a.bin +0 -0
  97. data/spec/bitcoin/fixtures/rawtx-2f4a2717ec8c9f077a87dde6cbe0274d5238793a3f3f492b63c744837285e58a.json +27 -0
  98. data/spec/bitcoin/fixtures/rawtx-406b2b06bcd34d3c8733e6b79f7a394c8a431fbf4ff5ac705c93f4076bb77602.json +23 -0
  99. data/spec/bitcoin/fixtures/rawtx-52250a162c7d03d2e1fbc5ebd1801a88612463314b55102171c5b5d817d2d7b2.bin +0 -0
  100. data/spec/bitcoin/fixtures/rawtx-b5d4e8883533f99e5903ea2cf001a133a322fa6b1370b18a16c57c946a40823d.bin +0 -0
  101. data/spec/bitcoin/fixtures/rawtx-ba1ff5cd66713133c062a871a8adab92416f1e38d17786b2bf56ac5f6ffdfdf5.json +37 -0
  102. data/spec/bitcoin/fixtures/rawtx-c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73.json +24 -0
  103. data/spec/bitcoin/fixtures/rawtx-de35d060663750b3975b7997bde7fb76307cec5b270d12fcd9c4ad98b279c28c.json +23 -0
  104. data/spec/bitcoin/fixtures/rawtx-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16.bin +0 -0
  105. data/spec/bitcoin/fixtures/rawtx-testnet-a220adf1902c46a39db25a24bc4178b6a88440f977a7e2cabfdd8b5c1dd35cfb.json +27 -0
  106. data/spec/bitcoin/fixtures/rawtx-testnet-e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f.bin +0 -0
  107. data/spec/bitcoin/fixtures/rawtx-testnet-e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f.json +41 -0
  108. data/spec/bitcoin/fixtures/reorg/blk_0_to_4.dat +0 -0
  109. data/spec/bitcoin/fixtures/reorg/blk_3A.dat +0 -0
  110. data/spec/bitcoin/fixtures/reorg/blk_4A.dat +0 -0
  111. data/spec/bitcoin/fixtures/reorg/blk_5A.dat +0 -0
  112. data/spec/bitcoin/fixtures/testnet/block_0.bin +0 -0
  113. data/spec/bitcoin/fixtures/testnet/block_1.bin +0 -0
  114. data/spec/bitcoin/fixtures/testnet/block_2.bin +0 -0
  115. data/spec/bitcoin/fixtures/testnet/block_3.bin +0 -0
  116. data/spec/bitcoin/fixtures/testnet/block_4.bin +0 -0
  117. data/spec/bitcoin/fixtures/testnet/block_5.bin +0 -0
  118. data/spec/bitcoin/fixtures/txdp-1.txt +32 -0
  119. data/spec/bitcoin/fixtures/txdp-2-signed.txt +19 -0
  120. data/spec/bitcoin/fixtures/txdp-2-unsigned.txt +14 -0
  121. data/spec/bitcoin/key_spec.rb +123 -0
  122. data/spec/bitcoin/network_spec.rb +48 -0
  123. data/spec/bitcoin/protocol/addr_spec.rb +68 -0
  124. data/spec/bitcoin/protocol/alert_spec.rb +20 -0
  125. data/spec/bitcoin/protocol/block_spec.rb +101 -0
  126. data/spec/bitcoin/protocol/inv_spec.rb +124 -0
  127. data/spec/bitcoin/protocol/ping_spec.rb +49 -0
  128. data/spec/bitcoin/protocol/tx_spec.rb +226 -0
  129. data/spec/bitcoin/protocol/version_spec.rb +77 -0
  130. data/spec/bitcoin/reorg_spec.rb +129 -0
  131. data/spec/bitcoin/script/opcodes_spec.rb +417 -0
  132. data/spec/bitcoin/script/script_spec.rb +246 -0
  133. data/spec/bitcoin/spec_helper.rb +36 -0
  134. data/spec/bitcoin/storage_spec.rb +229 -0
  135. data/spec/bitcoin/wallet/coinselector_spec.rb +35 -0
  136. data/spec/bitcoin/wallet/keygenerator_spec.rb +64 -0
  137. data/spec/bitcoin/wallet/keystore_spec.rb +188 -0
  138. data/spec/bitcoin/wallet/txdp_spec.rb +74 -0
  139. data/spec/bitcoin/wallet/wallet_spec.rb +207 -0
  140. metadata +295 -0
@@ -0,0 +1,24 @@
1
+ {
2
+ "hash":"c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73",
3
+ "ver":1,
4
+ "vin_sz":1,
5
+ "vout_sz":1,
6
+ "lock_time":0,
7
+ "size":225,
8
+ "in":[
9
+ {
10
+ "prev_out":{
11
+ "hash":"406b2b06bcd34d3c8733e6b79f7a394c8a431fbf4ff5ac705c93f4076bb77602",
12
+ "n":0
13
+ },
14
+ "scriptSig":"3046022100d23459d03ed7e9511a47d13292d3430a04627de6235b6e51a40f9cd386f2abe3022100e7d25b080f0bb8d8d5f878bba7d54ad2fda650ea8d158a33ee3cbd11768191fd00 04b0e2c879e4daf7b9ab68350228c159766676a14f5815084ba166432aab46198d4cca98fa3e9981d0a90b2effc514b76279476550ba3663fdcaff94c38420e9d5",
15
+ "sequence":0
16
+ }
17
+ ],
18
+ "out":[
19
+ {
20
+ "value":"0.04000000",
21
+ "scriptPubKey":"OP_DUP OP_HASH160 9a7b0f3b80c6baaeedce0a0842553800f832ba1f OP_EQUALVERIFY OP_CHECKSIG"
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "hash":"de35d060663750b3975b7997bde7fb76307cec5b270d12fcd9c4ad98b279c28c",
3
+ "ver":1,
4
+ "vin_sz":1,
5
+ "vout_sz":1,
6
+ "lock_time":0,
7
+ "size":221,
8
+ "in":[
9
+ {
10
+ "prev_out":{
11
+ "hash":"14925a9b197f15b6ba973313354c19ac9ae044c7e1b5518925ab773f52f6adc8",
12
+ "n":1
13
+ },
14
+ "scriptSig":"3044022032b6ee603a6df9f1830bd760e0347c1844a6623e99a8696321e56dadc01571a90220139ff8000df587633d338c79f343f7258d49c41e7a3b0e21557024cd25fcf0e101 04ef74b6f3e660a29d0e29edcdcd6e662554f61abf90ccadc699aef81bbd273eec270555f933b2053098981eb5343fc2f1f381b493e4da5ca051d69ed12d347aa5"
15
+ }
16
+ ],
17
+ "out":[
18
+ {
19
+ "value":"1.00000000",
20
+ "scriptPubKey":"OP_HASH160 8f55563b9a19f321c211e9b9f38cdf686ea07845 OP_EQUAL"
21
+ }
22
+ ]
23
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "hash":"a220adf1902c46a39db25a24bc4178b6a88440f977a7e2cabfdd8b5c1dd35cfb",
3
+ "ver":1,
4
+ "vin_sz":1,
5
+ "vout_sz":2,
6
+ "lock_time":0,
7
+ "size":295,
8
+ "in":[
9
+ {
10
+ "prev_out":{
11
+ "hash":"0000000000000000000000000000000000000000000000000000000000000000",
12
+ "n":4294967295
13
+ },
14
+ "coinbase":"b713e387dc308380489f496835dbb7c8a764924bea50842983f6e14d710d70092d10400300000000eb02534c805d49b09676fc1947152834e21cc574a25bbb683d19e3460000000000f2052a0100000000000000f559065821baa74c"
15
+ }
16
+ ],
17
+ "out":[
18
+ {
19
+ "value":"49.21875000",
20
+ "scriptPubKey":"044868e50c8454c1dd51f824bf81a944c6aaed24fb348f7c44aaea4a2630fd8e0d1b5590c2402494d8f80bc6ffd4d4bc4f336b1a84fa2f07e4f4498d4f77ff315f OP_CHECKSIG"
21
+ },
22
+ {
23
+ "value":"0.78125000",
24
+ "scriptPubKey":"0489175c7658845fd7c33d61029ebf4042e8386443ff6e6628fdb5ac938c31072dc61cee691ae1e8355c3a87cb4813cc9bf036fdb09078d35eacf9e9ab52374ebe OP_CHECKSIG"
25
+ }
26
+ ]
27
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "hash":"e232e0055dbdca88bbaa79458683195a0b7c17c5b6c524a8d146721d4d4d652f",
3
+ "ver":1,
4
+ "vin_sz":3,
5
+ "vout_sz":2,
6
+ "lock_time":0,
7
+ "size":732,
8
+ "in":[
9
+ {
10
+ "prev_out":{
11
+ "hash":"b0975fbd0c2d2966537cec3419d9d969ae7448da48f9e635bce6db39066ec071",
12
+ "n":1
13
+ },
14
+ "scriptSig":"304402200117cdd3ec6259af29acea44db354a6f57ac10d8496782033f5fe0febfd77f1b02202ceb02d60dbb43e6d4e03e5b5fbadc031f8bbb3c6c34ad307939947987f600bf01 0452d63c092209529ca2c75e056e947bc95f9daffb371e601b46d24377aaa3d004ab3c6be2d6d262b34d736b95f3b0ef6876826c93c4077d619c02ebd974c7facd"
15
+ },
16
+ {
17
+ "prev_out":{
18
+ "hash":"f82b768f4c45d4f15620738698d9abec32fc15804161ba05ec4377aa66a85aa6",
19
+ "n":0
20
+ },
21
+ "scriptSig":"3046022100ea0a9b41c9372837e52898205c7bebf86b28936a3ee725672d0ca8f434f876f0022100beb7243a51fbc0997e55cb519d3b9cbd59f7aba68d80ba1e8adbb53443cda3c001 043efd1ca3cffc50638031281d227ff347a3a27bc145e2f846891d29f87bc068c27710559c4d9cd71f7e9e763d6e2753172406eb1ed1fadcaf9a8972b4270f05b4"
22
+ },
23
+ {
24
+ "prev_out":{
25
+ "hash":"06002eef0a08a65adec4b2313c30185cb2ec55f173722a3a731bee5141d166d8",
26
+ "n":0
27
+ },
28
+ "scriptSig":"3045022052210f95f6b413c74ce12cfc1b14a36cb267f9fa3919fa6e20dade1cd570439f022100b9e5b325f312904804f043d06c6ebc8e4b1c6cd272856c48ab1736b9d562e10c01 0423fdddfe7e4d70d762dd6596771e035f4b43d54d28c2231be1102056f81f067914fe4fb6fd6e3381228ee5587ddd2028c846025741e963d9b1d6cf2c2dea0dbc"
29
+ }
30
+ ],
31
+ "out":[
32
+ {
33
+ "value":"0.03338000",
34
+ "scriptPubKey":"048a33e9fd2de28137574cc69fe5620199abe37b7d08a51c528876fe6c5fa7fc28535f5a667244445e79fffc9df85ec3d79d77693b1f37af0e2d7c1fa2e7113a48 OP_CHECKSIG"
35
+ },
36
+ {
37
+ "value":"1.23000000",
38
+ "scriptPubKey":"2 OP_TOALTSTACK 0 OP_TOALTSTACK OP_TUCK OP_CHECKSIG OP_SWAP OP_HASH160 3cd1def404e12a85ead2b4d3f5f9f817fb0d46ef OP_EQUAL OP_BOOLAND OP_FROMALTSTACK OP_ADD OP_TOALTSTACK OP_TUCK OP_CHECKSIG OP_SWAP OP_HASH160 6a4e7d5f798e90e84db9244d4805459f87275943 OP_EQUAL OP_BOOLAND OP_FROMALTSTACK OP_ADD OP_TOALTSTACK OP_TUCK OP_CHECKSIG OP_SWAP OP_HASH160 486efdd300987a054510b4ce1148d4ad290d911e OP_EQUAL OP_BOOLAND OP_FROMALTSTACK OP_ADD OP_TOALTSTACK OP_FROMALTSTACK OP_FROMALTSTACK OP_GREATERTHANOREQUAL"
39
+ }
40
+ ]
41
+ }
@@ -0,0 +1,32 @@
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-------------------------------------------------
@@ -0,0 +1,19 @@
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-------------------------------------------------
@@ -0,0 +1,14 @@
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-------------------------------------------------
@@ -0,0 +1,123 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe "Bitcoin::Key" do
4
+
5
+ before do
6
+ Bitcoin.network = :bitcoin
7
+ @key_data = {
8
+ :priv => "2ebd3738f59ae4fd408d717bf325b4cb979a409b0153f6d3b4b91cdfe046fb1e",
9
+ :pub => "045fcb2fb2802b024f371cc22bc392268cc579e47e7936e0d1f05064e6e1103b8a81954eb6d3d33b8b6e73e9269013e843e83919f7ce4039bb046517a0cad5a3b1" }
10
+ @key = Bitcoin::Key.new(@key_data[:priv], @key_data[:pub])
11
+ end
12
+
13
+ it "should generate a key" do
14
+ k = Bitcoin::Key.generate
15
+ k.priv.size.should == 64
16
+ k.pub.size.should == 130
17
+ #p k.priv, k.pub
18
+ end
19
+
20
+ it "should create empty key" do
21
+ k = Bitcoin::Key.new
22
+ k.priv.should == nil
23
+ k.pub.should == nil
24
+ end
25
+
26
+ it "should create key from priv + pub" do
27
+ k = Bitcoin::Key.new(@key_data[:priv], @key_data[:pub])
28
+ k.priv.should == @key_data[:priv]
29
+ k.pub.should == @key_data[:pub]
30
+ end
31
+
32
+ it "should create key from only priv" do
33
+ k = Bitcoin::Key.new(@key_data[:priv])
34
+ k.priv.should == @key_data[:priv]
35
+ k.pub.should == @key_data[:pub]
36
+ end
37
+
38
+ it "should create key from only pub" do
39
+ k = Bitcoin::Key.new(nil, @key_data[:pub])
40
+ k.pub.should == @key_data[:pub]
41
+ end
42
+
43
+ it "should set public key" do
44
+ k = Bitcoin::Key.new
45
+ k.pub = @key_data[:pub]
46
+ k.pub.should == @key_data[:pub]
47
+ end
48
+
49
+ it "should set private key" do
50
+ k = Bitcoin::Key.new
51
+ k.priv = @key_data[:priv]
52
+ k.priv.should == @key_data[:priv]
53
+ k.pub.should == @key_data[:pub]
54
+ end
55
+
56
+ it "should get addr" do
57
+ @key.addr.should == "1JbYZRKyysprVjSSBobs8LX6QVjzsscQNU"
58
+ end
59
+
60
+ it "should sign data" do
61
+ @key.sign("foobar").size.should >= 69
62
+ end
63
+
64
+ it "should verify signature" do
65
+ sig = @key.sign("foobar")
66
+ key2 = Bitcoin::Key.new(nil, @key.pub)
67
+ @key.verify("foobar", sig).should == true
68
+ end
69
+
70
+ it "should export private key in base58 format" do
71
+ Bitcoin.network = :bitcoin
72
+ str = Bitcoin::Key.new("e9873d79c6d87dc0fb6a5778633389f4453213303da61f20bd67fc233aa33262").to_base58
73
+ str.should == "5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF"
74
+ Bitcoin.network = :testnet
75
+ str = Bitcoin::Key.new("d21fa2c7ad710ffcd9bcc22a9f96357bda1a2521ca7181dd610140ecea2cecd8").to_base58
76
+ str.should == "93BTVFoqffueSaC5fqjLjLyn29S41JzvAZm2hC35SYMoYDXT1bY"
77
+ Bitcoin.network = :bitcoin
78
+ end
79
+
80
+ it "should import private key in base58 format" do
81
+ Bitcoin.network = :bitcoin
82
+ key = Bitcoin::Key.from_base58("5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF")
83
+ key.priv.should == "e9873d79c6d87dc0fb6a5778633389f4453213303da61f20bd67fc233aa33262"
84
+ key.addr.should == "1CC3X2gu58d6wXUWMffpuzN9JAfTUWu4Kj"
85
+ Bitcoin.network = :testnet
86
+ key = Bitcoin::Key.from_base58("93BTVFoqffueSaC5fqjLjLyn29S41JzvAZm2hC35SYMoYDXT1bY")
87
+ key.priv.should == "d21fa2c7ad710ffcd9bcc22a9f96357bda1a2521ca7181dd610140ecea2cecd8"
88
+ key.addr.should == "n3eH91H14mSnGx4Va2ngtLFCeLPRyYymRg"
89
+ Bitcoin.network = :bitcoin
90
+ end
91
+
92
+ end
93
+
94
+ begin
95
+ describe "Bitcoin::OpenSSL_EC" do
96
+ Bitcoin::OpenSSL_EC
97
+
98
+ it 'resolves public from private key' do
99
+ Bitcoin.network = :testnet
100
+ privkey = ["56e28a425a7b588973b5db962a09b1aca7bdc4a7268cdd671d03c52a997255dc"].pack("H*")
101
+ pubkey = ["04324c6ebdcf079db6c9209a6b715b955622561262cde13a8a1df8ae0ef030eaa1552e31f8be90c385e27883a9d82780283d19507d7fa2e1e71a1d11bc3a52caf3"].pack("H*")
102
+
103
+ Bitcoin::OpenSSL_EC.regenerate_key(privkey).should == [privkey, pubkey].map{|i| i.unpack("H*")[0] }
104
+
105
+ [
106
+ ["b51386f8275d49d8d30287d7b1afa805790bdd1fe8b13d22d25928c67ea55d02", "0470305ae5278a22499980286d9c513861d89e7b7317c8b891c554d5c8fdd256b03daa0340be4104f8c84cfa98f0da8f16567fcdd3a00fd993adbbe91695671a56"],
107
+ ["d8ebece51adc5fb99dd6994bcb8fa1221d01576fd76af9134ab36f8d4698b55c", "047503421850d3a6eecb7c9de33b367c4d3f96a34ff257ad0c34e234e29f3672525c6b4353ce6fdc9de3f885fdea798982e2252e610065dbdb62cd8cab1fe45822"],
108
+ ["c95c79fb0cc1fe47b384751df0627be40bbe481ec94eeafeb6dc40e94c40de43", "04b746ca07e718c7ca26d4eeec037492777f48bb5c750e972621698f699f530535c0ffa96dad581102d0471add88e691af85955d1fd42f68506f8092fddfe0c47a"],
109
+ ["5b61f807cc938b0fd3ec8f6006737d0002ceca09f296204138c4459de8a856f6", "0487357bf30c13d47d955666f42f87690cfd18be96cc74cda711da74bf76b08ebc6055aba30680e6288df14bda68c781cbf71eaad096c3639e9724c5e26f3acf54"]
110
+ ].each{|key|
111
+ privkey, pubkey = [ key.first ].pack("H*")
112
+ Bitcoin::OpenSSL_EC.regenerate_key(privkey).should == key
113
+ }
114
+
115
+ 250.times.map{
116
+ keypair = Bitcoin.generate_key;
117
+ Bitcoin::OpenSSL_EC.regenerate_key(keypair.first) == keypair
118
+ }.all?.should == true
119
+ end
120
+
121
+ end
122
+ rescue LoadError
123
+ end
@@ -0,0 +1,48 @@
1
+ require_relative 'spec_helper.rb'
2
+
3
+ describe 'Bitcoin::network' do
4
+
5
+ it 'returns network descriptor' do
6
+ Bitcoin.network = :bitcoin
7
+ net = Bitcoin::network
8
+ net[:magic_head].should == "\xF9\xBE\xB4\xD9"
9
+ net[:address_version].should == "00"
10
+ net[:genesis_hash].should == "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
11
+ end
12
+
13
+ it 'can be set to main net' do
14
+ Bitcoin::network = :bitcoin
15
+ Bitcoin::network.should == Bitcoin::NETWORKS[:bitcoin]
16
+ end
17
+
18
+ class Test_Handler
19
+ attr_reader :inv
20
+ def on_inv_transaction inv
21
+ @inv = inv
22
+ end
23
+ end
24
+
25
+ it 'uses correct magic_head when parsing a message' do
26
+ pkt = ["f9 be b4 d9 69 6e 76 00 00 00 00 00 00 00 00 00 49 00 00 00 11 ea 1c 91 02 01 00 00 00 e0 41 c2 38 f7 32 1a 68 0a 34 06 bf fd 72 12 e3 d1 2c b5 12 2a 8c 0b 52 76 de 82 30 b1 00 7a 42 01 00 00 00 33 00 09 71 a9 70 7b 6c 6d 6e 77 aa 2e ac 43 f3 e5 67 84 cb 61 b2 35 fb 8d fe e0 86 8b 40 7c f3".split(" ").join].pack("H*")
27
+
28
+ parser1 = Bitcoin::Protocol::Parser.new(handler1 = Test_Handler.new)
29
+ parser2 = Bitcoin::Protocol::Parser.new(handler2 = Test_Handler.new)
30
+
31
+ Bitcoin::network = :testnet
32
+ parser2.parse(pkt).should == ""
33
+ handler2.inv.should == nil
34
+
35
+ Bitcoin::network = :bitcoin
36
+ parser1.parse(pkt).should == ''
37
+ handler1.inv.should == ["f37c408b86e0fe8dfb35b261cb8467e5f343ac2eaa776e6d6c7b70a971090033"].pack("H*")
38
+ end
39
+
40
+ it 'uses correct magic head when creating a message' do
41
+ Bitcoin::network = :testnet
42
+ Bitcoin::Protocol.pkt('foo', "bar")[0...4].should == "\xFA\xBF\xB5\xDA"
43
+
44
+ Bitcoin::network = :bitcoin
45
+ Bitcoin::Protocol.pkt('foo', "bar")[0...4].should == "\xF9\xBE\xB4\xD9"
46
+ end
47
+
48
+ end
@@ -0,0 +1,68 @@
1
+ require_relative '../spec_helper.rb'
2
+
3
+ describe 'Bitcoin::Protocol::Parser (addr)' do
4
+
5
+ it 'parses address packet' do
6
+ pkt = [
7
+ "f9 be b4 d9 61 64 64 72 00 00 00 00 00 00 00 00 1f 00 00 00 e8 b4 c9 ba 01 2b dd d7 4d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 52 53 de 04 20 8d"
8
+ .split(" ").join].pack("H*")
9
+
10
+ class Addr_Handler < Bitcoin::Protocol::Handler
11
+ attr_reader :addr
12
+ def on_addr(addr); (@addr ||= []) << addr; end
13
+ end
14
+
15
+ parser = Bitcoin::Protocol::Parser.new( handler = Addr_Handler.new )
16
+ parser.parse(pkt + "AAAA").should == "AAAA"
17
+
18
+ handler.addr.size .should == 1
19
+ handler.addr.first.alive? .should == false
20
+ handler.addr.map{|i| i.values }.should == [
21
+ [1305992491, 1, "82.83.222.4", 8333]
22
+ ]
23
+ end
24
+
25
+ end
26
+
27
+ describe 'Bitcoin::Protocol::Addr' do
28
+
29
+ before do
30
+ @pkt = [
31
+ "2b dd d7 4d 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 52 53 de 04 20 8d"
32
+ .split(" ").join].pack("H*")
33
+ end
34
+
35
+ it 'parse addr payload' do
36
+ addr = Bitcoin::Protocol::Addr.new(@pkt)
37
+ addr.values.should == [1305992491, 1, "82.83.222.4", 8333]
38
+ end
39
+
40
+ it 'initalize time, service and port' do
41
+ addr = Bitcoin::Protocol::Addr.new(nil)
42
+ t = Time.now.to_i; (t-10..t+10).include?(addr[:time]).should == true
43
+ addr[:service] .should == 1
44
+ addr[:port] .should == Bitcoin.network[:default_port]
45
+ addr[:ip] .should == "127.0.0.1"
46
+ end
47
+
48
+ it 'addr payload' do
49
+ addr = Bitcoin::Protocol::Addr.new
50
+ addr[:time] = 1305992491
51
+ addr[:service] = 1
52
+ addr[:ip] = "82.83.222.4"
53
+ addr[:port] = 8333
54
+ addr.to_payload.should == @pkt
55
+ addr.to_payload.bytesize.should == 30
56
+ end
57
+
58
+
59
+ it 'pack addr packet' do
60
+ addr = Bitcoin::Protocol::Addr.new
61
+ addr[:time] = 1305992491
62
+ addr[:service] = 1
63
+ addr[:ip] = "82.83.222.4"
64
+ addr[:port] = 8333
65
+ Bitcoin::Protocol::Addr.pkt(addr).should ==
66
+ Bitcoin::Protocol.pkt("addr", "\x01" + addr.to_payload)
67
+ end
68
+ end