Class: Graphdb::Model::Block

Inherits:
ActiveNodeBase show all
Defined in:
lib/graphdb/model/block.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveNodeBase

remove_module

Class Method Details

.create_from_block_height(block_height) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/graphdb/model/block.rb', line 38

def self.create_from_block_height(block_height)
  block = new
  block.block_hash = Bitcoin2Graphdb::Bitcoin.provider.block_hash(block_height)
  hash = Bitcoin2Graphdb::Bitcoin.provider.block(block.block_hash)
  block.size = hash['size']
  block.height = hash['height']
  block.version = hash['version']
  block.merkle_root = hash['merkleroot']
  block.time = Time.at(hash['time'])
  block.nonce = hash['nonce']
  block.bits = hash['bits']
  block.difficulty = hash['difficulty']
  block.chain_work = hash['chainwork']
  block.previous_block_hash = hash['previousblockhash']
  block.next_block_hash = hash['nextblockhash']
  block.confirmations = hash['confirmations']
  block.save!
  unless block.genesis_block?
    hash['tx'].each do |txid|
      block.transactions << Graphdb::Model::Transaction.create_from_txid(txid)
    end
  end
  block.save!
  block
end

Instance Method Details

#genesis_block?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/graphdb/model/block.rb', line 64

def genesis_block?
  Bitcoin.network[:genesis_hash] == block_hash
end