Commit 3d977d7b167a23595a28132963bd7f18651bd27a

Authored by comboy
Committed by Julian Langschaedel
1 parent 8d9647492c

revert txout api change

Showing 4 changed files with 15 additions and 12 deletions Side-by-side Diff

lib/bitcoin/protocol/tx.rb
... ... @@ -122,7 +122,7 @@
122 122  
123 123 pin = @in.map.with_index{|input,idx|
124 124 if idx == input_idx
125   - subscript = subscript.out[ input.prev_out_index ].pk_script if subscript.respond_to?(:out) # legacy api (outpoint_tx)
  125 + subscript = subscript.out[ input.prev_out_index ].script if subscript.respond_to?(:out) # legacy api (outpoint_tx)
126 126 input.to_payload(subscript)
127 127 else
128 128 case (hash_type & 0x1f)
lib/bitcoin/protocol/txout.rb
... ... @@ -43,8 +43,8 @@
43 43  
44 44 alias :parse_payload :parse_data
45 45  
46   - def script
47   - @script ||= Bitcoin::Script.new(@pk_script)
  46 + def parsed_script
  47 + @parsed_script ||= Bitcoin::Script.new(pk_script)
48 48 end
49 49  
50 50 def to_payload
... ... @@ -57,8 +57,8 @@
57 57  
58 58 def to_hash(options = {})
59 59 h = { 'value' => "%.8f" % (@value / 100000000.0),
60   - 'scriptPubKey' => script.to_string }
61   - h["address"] = script.get_address if script.is_hash160? && options[:with_address]
  60 + 'scriptPubKey' => parsed_script.to_string }
  61 + h["address"] = parsed_script.get_address if parsed_script.is_hash160? && options[:with_address]
62 62 h
63 63 end
64 64  
... ... @@ -75,6 +75,9 @@
75 75  
76 76 alias :amount :value
77 77 alias :amount= :value=
  78 +
  79 + alias :script :pk_script
  80 + alias :script= :pk_script=
78 81  
79 82 # create output spending +value+ btc (base units) to +address+
80 83 def self.value_to_address(value, address)
lib/bitcoin/storage/dummy/dummy_store.rb
... ... @@ -107,8 +107,8 @@
107 107 def get_txouts_for_hash160(hash160, unconfirmed = false)
108 108 @tx.values.map(&:out).flatten.map {|o|
109 109 o = wrap_txout(o)
110   - if o.script.is_multisig?
111   - o.script.get_multisig_pubkeys.map{|pk| Bitcoin.hash160(pk.unpack("H*")[0])}.include?(hash160) ? o : nil
  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 112 else
113 113 o.hash160 == hash160 ? o : nil
114 114 end
... ... @@ -158,7 +158,7 @@
158 158 def wrap_txout(output)
159 159 return nil unless output
160 160 tx = @tx.values.find{|t| t.out.include?(output)}
161   - data = {tx_id: tx.hash, tx_idx: tx.out.index(output), hash160: output.script.get_hash160}
  161 + data = {tx_id: tx.hash, tx_idx: tx.out.index(output), hash160: output.parsed_script.get_hash160}
162 162 txout = Bitcoin::Storage::Models::TxOut.new(self, data)
163 163 [:value, :pk_script_length, :pk_script].each do |attr|
164 164 txout.send("#{attr}=", output.send(attr))
lib/bitcoin/storage/models.rb
... ... @@ -134,7 +134,7 @@
134 134 end
135 135  
136 136 def hash160
137   - script.get_hash160
  137 + parsed_script.get_hash160
138 138 end
139 139  
140 140 # get the transaction this output is in
141 141  
... ... @@ -149,12 +149,12 @@
149 149  
150 150 # get all addresses this txout corresponds to (if possible)
151 151 def get_address
152   - script.get_address
  152 + parsed_script.get_address
153 153 end
154 154  
155 155 # get the single address this txout corresponds to (first for multisig tx)
156 156 def get_addresses
157   - script.get_addresses
  157 + parsed_script.get_addresses
158 158 end
159 159  
160 160 def get_namecoin_name
... ... @@ -162,7 +162,7 @@
162 162 end
163 163  
164 164 def type
165   - script.type
  165 + parsed_script.type
166 166 end
167 167  
168 168 end