Class: Bitcoin::Storage::Backends::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/storage/storage.rb

Direct Known Subclasses

Activerecord, Dummy

Instance Method Summary (collapse)

Constructor Details

- (Base) initialize(config = {})

A new instance of Base



12
13
14
15
16
# File 'lib/bitcoin/storage/storage.rb', line 12

def initialize(config = {})
  @config = config
  @log    = config[:log] || Bitcoin::Storage.log
  inject_genesis
end

Instance Method Details

- (Object) get_block(blk_hash)

get block with given hash



63
64
65
# File 'lib/bitcoin/storage/storage.rb', line 63

def get_block(blk_hash)
  raise "Not implemented"
end

- (Object) get_depth

return depth of the head block



34
35
36
# File 'lib/bitcoin/storage/storage.rb', line 34

def get_depth
  raise "Not implemented"
end

- (Object) get_head

get the hash of the leading block



29
30
31
# File 'lib/bitcoin/storage/storage.rb', line 29

def get_head
  raise "Not implemented"
end

- (Object) get_locator

compute blockchain locator



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bitcoin/storage/storage.rb', line 39

def get_locator
  return [Bitcoin::hth("\x00"*32)]  if get_depth == -1
  locator = []
  pointer = get_head
  step = 1
  while pointer && pointer != Bitcoin::network[:genesis_hash]
    locator << pointer
    depth = get_block_depth(pointer) - step
    break unless depth > 0
    prev_block = get_block_by_depth(depth) # TODO
    break unless prev_block
    pointer = prev_block.hash
    step *= 2  if locator.size > 10
  end
  locator << Bitcoin::network[:genesis_hash]
  locator
end

- (Object) get_tx(tx_hash)

get tx with given hash



73
74
75
# File 'lib/bitcoin/storage/storage.rb', line 73

def get_tx(tx_hash)
  raise "Not implemented"
end

- (Object) inject_genesis

inject the genesis block into storage



22
23
24
25
26
# File 'lib/bitcoin/storage/storage.rb', line 22

def inject_genesis
  return  if get_block_by_hash(Bitcoin.network[:genesis_hash])
  genesis = Bitcoin.network[:genesis_block]
  store_block(genesis)
end

- (Object) log

get the storage logger



19
# File 'lib/bitcoin/storage/storage.rb', line 19

def log; @log; end

- (Object) store_block(blk)

store given block



58
59
60
# File 'lib/bitcoin/storage/storage.rb', line 58

def store_block(blk)
  raise "Not implemented"
end

- (Object) store_tx(tx)

store given tx



68
69
70
# File 'lib/bitcoin/storage/storage.rb', line 68

def store_tx(tx)
  raise "Not implemented"
end