bitcoin-ruby 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +2 -7
  4. data/COPYING +1 -1
  5. data/Gemfile +2 -6
  6. data/Gemfile.lock +34 -0
  7. data/README.rdoc +16 -68
  8. data/Rakefile +3 -6
  9. data/bin/bitcoin_shell +0 -1
  10. data/{concept-examples/blockchain-pow.rb → examples/concept-blockchain-pow.rb} +0 -0
  11. data/lib/bitcoin.rb +350 -296
  12. data/lib/bitcoin/builder.rb +3 -1
  13. data/lib/bitcoin/connection.rb +2 -1
  14. data/lib/bitcoin/contracthash.rb +76 -0
  15. data/lib/bitcoin/dogecoin.rb +97 -0
  16. data/lib/bitcoin/ffi/bitcoinconsensus.rb +74 -0
  17. data/lib/bitcoin/ffi/openssl.rb +98 -2
  18. data/lib/bitcoin/ffi/secp256k1.rb +144 -0
  19. data/lib/bitcoin/key.rb +12 -2
  20. data/lib/bitcoin/logger.rb +3 -12
  21. data/lib/bitcoin/protocol/block.rb +3 -9
  22. data/lib/bitcoin/protocol/parser.rb +6 -2
  23. data/lib/bitcoin/protocol/tx.rb +44 -13
  24. data/lib/bitcoin/protocol/txin.rb +4 -2
  25. data/lib/bitcoin/protocol/txout.rb +2 -2
  26. data/lib/bitcoin/script.rb +212 -37
  27. data/lib/bitcoin/trezor/mnemonic.rb +130 -0
  28. data/lib/bitcoin/version.rb +1 -1
  29. data/spec/bitcoin/bitcoin_spec.rb +32 -3
  30. data/spec/bitcoin/builder_spec.rb +18 -0
  31. data/spec/bitcoin/contracthash_spec.rb +45 -0
  32. data/spec/bitcoin/dogecoin_spec.rb +176 -0
  33. data/spec/bitcoin/ffi_openssl.rb +45 -0
  34. data/spec/bitcoin/fixtures/156e6e1b84c5c3bd3a0927b25e4119fadce6e6d5186f363317511d1d680fae9a.json +24 -0
  35. data/spec/bitcoin/fixtures/8d0b238a06b5a70be75d543902d02d7a514d68d3252a949a513865ac3538874c.json +24 -0
  36. data/spec/bitcoin/fixtures/coinbase-toshi.json +33 -0
  37. data/spec/bitcoin/fixtures/coinbase.json +24 -0
  38. data/spec/bitcoin/fixtures/dogecoin-block-60323982f9c5ff1b5a954eac9dc1269352835f47c2c5222691d80f0d50dcf053.bin +0 -0
  39. data/spec/bitcoin/fixtures/rawtx-01-toshi.json +46 -0
  40. data/spec/bitcoin/fixtures/rawtx-02-toshi.json +46 -0
  41. data/spec/bitcoin/fixtures/rawtx-03-toshi.json +73 -0
  42. data/spec/bitcoin/fixtures/rawtx-testnet-04fdc38d6722ab4b12d79113fc4b2896bdcc5169710690ee4e78541b98e467b4.bin +0 -0
  43. data/spec/bitcoin/fixtures/rawtx-testnet-0b294c7d11dd21bcccb8393e6744fed7d4d1981a08c00e3e88838cc421f33c9f.bin +0 -0
  44. data/spec/bitcoin/fixtures/rawtx-testnet-3bc52ac063291ad92d95ddda5fd776a342083b95607ad32ed8bc6f8f7d30449e.bin +0 -0
  45. data/spec/bitcoin/fixtures/rawtx-testnet-6f0bbdd4e71a8af4305018d738184df32dbb6f27284fdebd5b56d16947f7c181.bin +0 -0
  46. data/spec/bitcoin/fixtures/rawtx-testnet-a7c9b06e275e8674cc19a5f7d3e557c72c6d93576e635b33212dbe08ab7cdb60.bin +0 -0
  47. data/spec/bitcoin/fixtures/rawtx-testnet-f80acbd2f594d04ddb0e1cacba662132104909157dff526935a3c88abe9201a5.bin +0 -0
  48. data/spec/bitcoin/protocol/block_spec.rb +0 -22
  49. data/spec/bitcoin/protocol/tx_spec.rb +145 -2
  50. data/spec/bitcoin/script/script_spec.rb +282 -0
  51. data/spec/bitcoin/secp256k1_spec.rb +48 -0
  52. data/spec/bitcoin/spec_helper.rb +0 -51
  53. data/spec/bitcoin/trezor/mnemonic_spec.rb +161 -0
  54. metadata +48 -98
  55. data/bin/bitcoin_dns_seed +0 -130
  56. data/bin/bitcoin_gui +0 -80
  57. data/bin/bitcoin_node +0 -153
  58. data/bin/bitcoin_node_cli +0 -81
  59. data/bin/bitcoin_wallet +0 -402
  60. data/doc/CONFIG.rdoc +0 -66
  61. data/doc/EXAMPLES.rdoc +0 -13
  62. data/doc/NAMECOIN.rdoc +0 -34
  63. data/doc/NODE.rdoc +0 -225
  64. data/doc/STORAGE.rdoc +0 -33
  65. data/doc/WALLET.rdoc +0 -102
  66. data/examples/balance.rb +0 -66
  67. data/examples/forwarder.rb +0 -73
  68. data/examples/index_nhash.rb +0 -24
  69. data/examples/reindex_p2sh_addrs.rb +0 -44
  70. data/examples/relay_tx.rb +0 -22
  71. data/examples/verify_tx.rb +0 -57
  72. data/lib/bitcoin/config.rb +0 -58
  73. data/lib/bitcoin/gui/addr_view.rb +0 -44
  74. data/lib/bitcoin/gui/bitcoin-ruby.png +0 -0
  75. data/lib/bitcoin/gui/bitcoin-ruby.svg +0 -80
  76. data/lib/bitcoin/gui/conn_view.rb +0 -38
  77. data/lib/bitcoin/gui/connection.rb +0 -70
  78. data/lib/bitcoin/gui/em_gtk.rb +0 -30
  79. data/lib/bitcoin/gui/gui.builder +0 -1643
  80. data/lib/bitcoin/gui/gui.rb +0 -292
  81. data/lib/bitcoin/gui/helpers.rb +0 -115
  82. data/lib/bitcoin/gui/tree_view.rb +0 -84
  83. data/lib/bitcoin/gui/tx_view.rb +0 -69
  84. data/lib/bitcoin/namecoin.rb +0 -280
  85. data/lib/bitcoin/network/command_client.rb +0 -104
  86. data/lib/bitcoin/network/command_handler.rb +0 -570
  87. data/lib/bitcoin/network/connection_handler.rb +0 -387
  88. data/lib/bitcoin/network/node.rb +0 -565
  89. data/lib/bitcoin/storage/dummy/dummy_store.rb +0 -179
  90. data/lib/bitcoin/storage/models.rb +0 -171
  91. data/lib/bitcoin/storage/sequel/migrations.rb +0 -99
  92. data/lib/bitcoin/storage/sequel/migrations/001_base_schema.rb +0 -52
  93. data/lib/bitcoin/storage/sequel/migrations/002_tx.rb +0 -45
  94. data/lib/bitcoin/storage/sequel/migrations/003_change_txin_script_sig_to_blob.rb +0 -18
  95. data/lib/bitcoin/storage/sequel/migrations/004_change_txin_prev_out_to_blob.rb +0 -18
  96. data/lib/bitcoin/storage/sequel/migrations/005_change_tx_hash_to_bytea.rb +0 -14
  97. data/lib/bitcoin/storage/sequel/migrations/006_add_tx_nhash.rb +0 -31
  98. data/lib/bitcoin/storage/sequel/migrations/007_add_prev_out_index_index.rb +0 -16
  99. data/lib/bitcoin/storage/sequel/migrations/008_add_txin_p2sh_type.rb +0 -31
  100. data/lib/bitcoin/storage/sequel/migrations/009_add_addrs_type.rb +0 -56
  101. data/lib/bitcoin/storage/sequel/sequel_store.rb +0 -551
  102. data/lib/bitcoin/storage/storage.rb +0 -517
  103. data/lib/bitcoin/storage/utxo/migrations/001_base_schema.rb +0 -52
  104. data/lib/bitcoin/storage/utxo/migrations/002_utxo.rb +0 -18
  105. data/lib/bitcoin/storage/utxo/migrations/003_update_indices.rb +0 -14
  106. data/lib/bitcoin/storage/utxo/migrations/004_add_addrs_type.rb +0 -14
  107. data/lib/bitcoin/storage/utxo/utxo_store.rb +0 -374
  108. data/lib/bitcoin/validation.rb +0 -400
  109. data/lib/bitcoin/wallet/coinselector.rb +0 -33
  110. data/lib/bitcoin/wallet/keygenerator.rb +0 -77
  111. data/lib/bitcoin/wallet/keystore.rb +0 -207
  112. data/lib/bitcoin/wallet/txdp.rb +0 -118
  113. data/lib/bitcoin/wallet/wallet.rb +0 -281
  114. data/spec/bitcoin/fixtures/freicoin-block-000000005d231b285e63af83edae2d8f5e50e70d396468643092b9239fd3be3c.bin +0 -0
  115. data/spec/bitcoin/fixtures/freicoin-block-000000005d231b285e63af83edae2d8f5e50e70d396468643092b9239fd3be3c.json +0 -43
  116. data/spec/bitcoin/fixtures/freicoin-genesis-block-000000005b1e3d23ecfd2dd4a6e1a35238aa0392c0a8528c40df52376d7efe2c.bin +0 -0
  117. data/spec/bitcoin/fixtures/freicoin-genesis-block-000000005b1e3d23ecfd2dd4a6e1a35238aa0392c0a8528c40df52376d7efe2c.json +0 -67
  118. data/spec/bitcoin/namecoin_spec.rb +0 -182
  119. data/spec/bitcoin/node/command_api_spec.rb +0 -663
  120. data/spec/bitcoin/storage/models_spec.rb +0 -104
  121. data/spec/bitcoin/storage/reorg_spec.rb +0 -236
  122. data/spec/bitcoin/storage/storage_spec.rb +0 -387
  123. data/spec/bitcoin/storage/validation_spec.rb +0 -300
  124. data/spec/bitcoin/wallet/coinselector_spec.rb +0 -38
  125. data/spec/bitcoin/wallet/keygenerator_spec.rb +0 -69
  126. data/spec/bitcoin/wallet/keystore_spec.rb +0 -190
  127. data/spec/bitcoin/wallet/txdp_spec.rb +0 -76
  128. data/spec/bitcoin/wallet/wallet_spec.rb +0 -238
@@ -1,179 +0,0 @@
1
- # encoding: ascii-8bit
2
-
3
- module Bitcoin::Storage::Backends
4
- class DummyStore < StoreBase
5
-
6
- attr_accessor :blk, :tx
7
-
8
- def initialize *args
9
- reset
10
- super(*args)
11
- end
12
-
13
- def reset
14
- @blk, @tx = [], {}
15
- end
16
-
17
- def persist_block(blk, chain, depth, prev_work = 0)
18
- return [depth, chain] unless blk && chain == 0
19
- if block = get_block(blk.hash)
20
- log.info { "Block already stored; skipping" }
21
- return false
22
- end
23
-
24
- blk.tx.each {|tx| store_tx(tx) }
25
- @blk << blk
26
-
27
- log.info { "NEW HEAD: #{blk.hash} DEPTH: #{get_depth}" }
28
- [depth, chain]
29
- end
30
-
31
- def store_tx(tx, validate = true)
32
- if @tx.keys.include?(tx.hash)
33
- log.info { "Tx already stored; skipping" }
34
- return tx
35
- end
36
- @tx[tx.hash] = tx
37
- end
38
-
39
- def has_block(blk_hash)
40
- !!get_block(blk_hash)
41
- end
42
-
43
- def has_tx(tx_hash)
44
- !!get_tx(tx_hash)
45
- end
46
-
47
- def get_depth
48
- @blk.size - 1
49
- end
50
-
51
- def get_head
52
- wrap_block(@blk[-1])
53
- end
54
-
55
- def get_block_by_depth(depth)
56
- wrap_block(@blk[depth])
57
- end
58
-
59
- def get_block_by_prev_hash(hash)
60
- wrap_block(@blk.find {|blk| blk.prev_block == [hash].pack("H*").reverse})
61
- end
62
-
63
- def get_block(blk_hash)
64
- wrap_block(@blk.find {|blk| blk.hash == blk_hash})
65
- end
66
-
67
- def get_block_by_id(blk_id)
68
- wrap_block(@blk[blk_id])
69
- end
70
-
71
- def get_block_by_tx(tx_hash)
72
- wrap_block(@blk.find {|blk| blk.tx.map(&:hash).include?(tx_hash) })
73
- end
74
-
75
- def get_idx_from_tx_hash(tx_hash)
76
- return nil unless tx = get_tx(tx_hash)
77
- return nil unless blk = tx.get_block
78
- blk.tx.index tx
79
- end
80
-
81
- def get_tx(tx_hash)
82
- transaction = @tx[tx_hash]
83
- return nil unless transaction
84
- wrap_tx(transaction)
85
- end
86
-
87
- def get_tx_by_id(tx_id)
88
- wrap_tx(@tx[tx_id])
89
- end
90
-
91
- def get_txin_for_txout(tx_hash, txout_idx)
92
- txin = @tx.values.map(&:in).flatten.find {|i| i.prev_out_index == txout_idx &&
93
- i.prev_out == [tx_hash].pack("H*").reverse }
94
- wrap_txin(txin)
95
- end
96
-
97
- def get_txout_for_txin(txin)
98
- return nil unless tx = @tx[txin.prev_out.reverse_hth]
99
- wrap_tx(tx).out[txin.prev_out_index]
100
- end
101
-
102
- def get_txouts_for_pk_script(script)
103
- txouts = @tx.values.map(&:out).flatten.select {|o| o.pk_script == script}
104
- txouts.map {|o| wrap_txout(o) }
105
- end
106
-
107
- def get_txouts_for_hash160(hash160, type = :hash160, unconfirmed = false)
108
- @tx.values.map(&:out).flatten.map {|o|
109
- o = wrap_txout(o)
110
- if o.parsed_script.is_multisig?
111
- o.parsed_script.get_multisig_pubkeys.map{|pk| Bitcoin.hash160(pk.unpack("H*")[0])}.include?(hash160) ? o : nil
112
- else
113
- o.hash160 == hash160 && o.type == type ? o : nil
114
- end
115
- }.compact
116
- end
117
-
118
- def wrap_block(block)
119
- return nil unless block
120
- data = { id: @blk.index(block), depth: @blk.index(block),
121
- work: @blk.index(block), chain: MAIN, size: block.size }
122
- blk = Bitcoin::Storage::Models::Block.new(self, data)
123
- [:ver, :prev_block, :mrkl_root, :time, :bits, :nonce].each do |attr|
124
- blk.send("#{attr}=", block.send(attr))
125
- end
126
- block.tx.each do |tx|
127
- blk.tx << get_tx(tx.hash)
128
- end
129
- blk.recalc_block_hash
130
- blk
131
- end
132
-
133
- def wrap_tx(transaction)
134
- return nil unless transaction
135
- blk = @blk.find{|b| b.tx.include?(transaction)}
136
- data = { id: transaction.hash, blk_id: @blk.index(blk),
137
- size: transaction.size }
138
- tx = Bitcoin::Storage::Models::Tx.new(self, data)
139
- tx.ver = transaction.ver
140
- tx.lock_time = transaction.lock_time
141
- transaction.in.each {|i| tx.add_in(wrap_txin(i))}
142
- transaction.out.each {|o| tx.add_out(wrap_txout(o))}
143
- tx.hash = tx.hash_from_payload(tx.to_payload)
144
- tx
145
- end
146
-
147
- def wrap_txin(input)
148
- return nil unless input
149
- tx = @tx.values.find{|t| t.in.include?(input)}
150
- data = { tx_id: tx.hash, tx_idx: tx.in.index(input)}
151
- txin = Bitcoin::Storage::Models::TxIn.new(self, data)
152
- [:prev_out, :prev_out_index, :script_sig_length, :script_sig, :sequence].each do |attr|
153
- txin.send("#{attr}=", input.send(attr))
154
- end
155
- txin
156
- end
157
-
158
- def wrap_txout(output)
159
- return nil unless output
160
- tx = @tx.values.find{|t| t.out.include?(output)}
161
- data = {tx_id: tx.hash, tx_idx: tx.out.index(output), hash160: output.parsed_script.get_hash160}
162
- txout = Bitcoin::Storage::Models::TxOut.new(self, data)
163
- [:value, :pk_script_length, :pk_script].each do |attr|
164
- txout.send("#{attr}=", output.send(attr))
165
- end
166
- txout
167
- end
168
-
169
- def to_s
170
- "DummyStore"
171
- end
172
-
173
- def check_consistency(*args)
174
- log.warn { "Dummy store doesn't support consistency check" }
175
- end
176
-
177
-
178
- end
179
- end
@@ -1,171 +0,0 @@
1
- # encoding: ascii-8bit
2
-
3
- # StorageModels defines objects that are returned from storage.
4
- # These objects inherit from their Bitcoin::Protocol counterpart
5
- # and add some additional data and methods.
6
- #
7
- # * Bitcoin::Storage::Models::Block
8
- # * Bitcoin::Storage::Models::Tx
9
- # * Bitcoin::Storage::Models::TxIn
10
- # * Bitcoin::Storage::Models::TxOut
11
- module Bitcoin::Storage::Models
12
-
13
- # Block retrieved from storage. (see Bitcoin::Protocol::Block)
14
- class Block < Bitcoin::Protocol::Block
15
-
16
- attr_accessor :ver, :prev_block, :mrkl_root, :time, :bits, :nonce, :tx
17
- attr_reader :store, :id, :depth, :chain, :work, :size
18
-
19
- def initialize store, data
20
- @store = store
21
- @id = data[:id]
22
- @depth = data[:depth]
23
- @chain = data[:chain]
24
- @work = data[:work]
25
- @size = data[:size]
26
- @tx = []
27
- end
28
-
29
- # get the block this one builds upon
30
- def get_prev_block
31
- @store.get_block(@prev_block.reverse_hth)
32
- end
33
-
34
- # get the block that builds upon this one
35
- def get_next_block
36
- @store.get_block_by_prev_hash(@hash)
37
- end
38
-
39
- def total_out
40
- @total_out ||= tx.inject(0){ |m,t| m + t.total_out }
41
- end
42
-
43
- def total_in
44
- @total_in ||= tx.inject(0){ |m,t| m + t.total_in }
45
- end
46
-
47
- def total_fee
48
- @total_fee ||= tx.inject(0){ |m,t| m + t.fee }
49
- end
50
- end
51
-
52
- # Transaction retrieved from storage. (see Bitcoin::Protocol::Tx)
53
- class Tx < Bitcoin::Protocol::Tx
54
-
55
- attr_accessor :ver, :lock_time, :hash
56
- attr_reader :store, :id, :blk_id, :size, :idx
57
-
58
- def initialize store, data
59
- @store = store
60
- @id = data[:id]
61
- @blk_id = data[:blk_id]
62
- @size = data[:size]
63
- @idx = data[:idx]
64
- super(nil)
65
- end
66
-
67
- # get the block this transaction is in
68
- def get_block
69
- return nil unless @blk_id
70
- @block ||= @store.get_block_by_id(@blk_id)
71
- end
72
-
73
- # get the number of blocks that confirm this tx in the main chain
74
- def confirmations
75
- return 0 unless get_block
76
- @store.get_head.depth - get_block.depth + 1
77
- end
78
-
79
- def total_out
80
- @total_out ||= self.out.inject(0){ |e, o| e + o.value }
81
- end
82
-
83
- # if tx_in is coinbase, set in value as total_out, fee could be 0
84
- def total_in
85
- @total_in ||= self.in.inject(0){ |m, input|
86
- m + (input.coinbase? ? total_out : (input.get_prev_out.try(:value) || 0))
87
- }
88
- end
89
-
90
- def fee
91
- @fee ||= total_in - total_out
92
- end
93
- end
94
-
95
- # Transaction input retrieved from storage. (see Bitcoin::Protocol::TxIn
96
- class TxIn < Bitcoin::Protocol::TxIn
97
-
98
- attr_reader :store, :id, :tx_id, :tx_idx, :p2sh_type
99
-
100
- def initialize store, data
101
- @store = store
102
- @id = data[:id]
103
- @tx_id = data[:tx_id]
104
- @tx_idx = data[:tx_idx]
105
- @p2sh_type = data[:p2sh_type]
106
- end
107
-
108
- # get the transaction this input is in
109
- def get_tx
110
- @tx ||= @store.get_tx_by_id(@tx_id)
111
- end
112
-
113
- # get the previous output referenced by this input
114
- def get_prev_out
115
- @prev_tx_out ||= begin
116
- prev_tx = @store.get_tx(@prev_out.reverse_hth)
117
- return nil unless prev_tx
118
- prev_tx.out[@prev_out_index]
119
- end
120
- end
121
-
122
- end
123
-
124
- # Transaction output retrieved from storage. (see Bitcoin::Protocol::TxOut)
125
- class TxOut < Bitcoin::Protocol::TxOut
126
-
127
- attr_reader :store, :id, :tx_id, :tx_idx, :type
128
-
129
- def initialize store, data
130
- @store = store
131
- @id = data[:id]
132
- @tx_id = data[:tx_id]
133
- @tx_idx = data[:tx_idx]
134
- @type = data[:type]
135
- end
136
-
137
- def hash160
138
- parsed_script.get_hash160
139
- end
140
-
141
- # get the transaction this output is in
142
- def get_tx
143
- @tx ||= @store.get_tx_by_id(@tx_id)
144
- end
145
-
146
- # get the next input that references this output
147
- def get_next_in
148
- @store.get_txin_for_txout(get_tx.hash, @tx_idx)
149
- end
150
-
151
- # get all addresses this txout corresponds to (if possible)
152
- def get_address
153
- parsed_script.get_address
154
- end
155
-
156
- # get the single address this txout corresponds to (first for multisig tx)
157
- def get_addresses
158
- parsed_script.get_addresses
159
- end
160
-
161
- def get_namecoin_name
162
- @store.get_name_by_txout_id(@id)
163
- end
164
-
165
- def type
166
- parsed_script.type
167
- end
168
-
169
- end
170
-
171
- end
@@ -1,99 +0,0 @@
1
- # encoding: ascii-8bit
2
-
3
- module Bitcoin::Storage::Backends::SequelMigrations
4
-
5
- def migrate
6
- binary = @db.database_type == :postgres ? :bytea : :blob
7
-
8
- unless @db.tables.include?(:blk)
9
- @db.create_table :blk do
10
- primary_key :id
11
- column :hash, binary, :null => false, :unique => true, :index => true
12
- column :depth, :int, :null => false, :index => true
13
- column :version, :bigint, :null => false
14
- column :prev_hash, binary, :null => false, :index => true
15
- column :mrkl_root, binary, :null => false
16
- column :time, :bigint, :null => false
17
- column :bits, :bigint, :null => false
18
- column :nonce, :bigint, :null => false
19
- column :blk_size, :int, :null => false
20
- column :chain, :int, :null => false
21
- column :work, binary, :index => true
22
- column :aux_pow, binary
23
- end
24
- end
25
-
26
- unless @db.tables.include?(:tx)
27
- @db.create_table :tx do
28
- primary_key :id
29
- column :hash, binary, :null => false, :unique => true, :index => true
30
- column :version, :bigint, :null => false
31
- column :lock_time, :bigint, :null => false
32
- column :coinbase, :bool, :null => false
33
- column :tx_size, :int, :null => false
34
- end
35
- end
36
-
37
- unless @db.tables.include?(:blk_tx)
38
- @db.create_table :blk_tx do
39
- column :blk_id, :int, :null => false, :index => true
40
- column :tx_id, :int, :null => false, :index => true
41
- column :idx, :int, :null => false
42
- end
43
- end
44
-
45
- unless @db.tables.include?(:txin)
46
- @db.create_table :txin do
47
- primary_key :id
48
- column :tx_id, :int, :null => false, :index => true
49
- column :tx_idx, :int, :null => false
50
- column :script_sig, binary, :null => false
51
- column :prev_out, binary, :null => false, :index => true
52
- column :prev_out_index, :bigint, :null => false
53
- column :sequence, :bigint, :null => false
54
- end
55
- end
56
-
57
- unless @db.tables.include?(:txout)
58
- @db.create_table :txout do
59
- primary_key :id
60
- column :tx_id, :int, :null => false, :index => true
61
- column :tx_idx, :int, :null => false
62
- column :pk_script, binary, :null => false
63
- column :value, :bigint
64
- column :type, :int, :null => false, :index => true
65
- end
66
- end
67
-
68
- unless @db.tables.include?(:addr)
69
- @db.create_table :addr do
70
- primary_key :id
71
- column :hash160, String, :null => false, :index => true
72
- end
73
- end
74
-
75
- unless @db.tables.include?(:addr_txout)
76
- @db.create_table :addr_txout do
77
- column :addr_id, :int, :null => false, :index => true
78
- column :txout_id, :int, :null => false, :index => true
79
- end
80
- end
81
-
82
- unless @db.views.include?(:unconfirmed)
83
- @db.create_view(:unconfirmed,
84
- "SELECT * FROM tx WHERE NOT EXISTS " +
85
- "(SELECT 1 FROM blk_tx WHERE blk_tx.tx_id = tx.id)" +
86
- "ORDER BY tx.id DESC")
87
- end
88
-
89
- unless @db.tables.include?(:names)
90
- @db.create_table :names do
91
- column :txout_id, :int, :null => false, :index => true
92
- column :hash, binary, :index => true
93
- column :name, binary, :index => true
94
- column :value, binary
95
- end
96
- end
97
- end
98
-
99
- end