lib/bitcoin/storage/dummy/dummy_store.rb in bitcoin-ruby-0.0.5 vs lib/bitcoin/storage/dummy/dummy_store.rb in bitcoin-ruby-0.0.6
- old
+ new
@@ -70,10 +70,16 @@
def get_block_by_tx(tx_hash)
wrap_block(@blk.find {|blk| blk.tx.map(&:hash).include?(tx_hash) })
end
+ def get_idx_from_tx_hash(tx_hash)
+ return nil unless tx = get_tx(tx_hash)
+ return nil unless blk = tx.get_block
+ blk.tx.index tx
+ end
+
def get_tx(tx_hash)
transaction = @tx[tx_hash]
return nil unless transaction
wrap_tx(transaction)
end
@@ -86,19 +92,28 @@
txin = @tx.values.map(&:in).flatten.find {|i| i.prev_out_index == txout_idx &&
i.prev_out == [tx_hash].pack("H*").reverse }
wrap_txin(txin)
end
+ def get_txout_for_txin(txin)
+ return nil unless tx = @tx[txin.prev_out.reverse_hth]
+ wrap_tx(tx).out[txin.prev_out_index]
+ end
+
def get_txouts_for_pk_script(script)
txouts = @tx.values.map(&:out).flatten.select {|o| o.pk_script == script}
txouts.map {|o| wrap_txout(o) }
end
- def get_txouts_for_hash160(hash160, unconfirmed = false)
+ def get_txouts_for_hash160(hash160, type = :hash160, unconfirmed = false)
@tx.values.map(&:out).flatten.map {|o|
o = wrap_txout(o)
- o.hash160 == hash160 ? o : nil
+ if o.parsed_script.is_multisig?
+ o.parsed_script.get_multisig_pubkeys.map{|pk| Bitcoin.hash160(pk.unpack("H*")[0])}.include?(hash160) ? o : nil
+ else
+ o.hash160 == hash160 && o.type == type ? o : nil
+ end
}.compact
end
def wrap_block(block)
return nil unless block
@@ -141,20 +156,24 @@
end
def wrap_txout(output)
return nil unless output
tx = @tx.values.find{|t| t.out.include?(output)}
- data = {tx_id: tx.hash, tx_idx: tx.out.index(output),
- hash160: Bitcoin::Script.new(output.pk_script).get_hash160 }
+ data = {tx_id: tx.hash, tx_idx: tx.out.index(output), hash160: output.parsed_script.get_hash160}
txout = Bitcoin::Storage::Models::TxOut.new(self, data)
[:value, :pk_script_length, :pk_script].each do |attr|
txout.send("#{attr}=", output.send(attr))
end
txout
end
def to_s
"DummyStore"
end
+
+ def check_consistency(*args)
+ log.warn { "Dummy store doesn't support consistency check" }
+ end
+
end
end