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
63
64
65
66
67
68
|
# 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']
begin
Bitcoin2Graphdb::Bitcoin.provider.block(block.previous_block_hash) if block.previous_block_hash
rescue OpenAssets::Provider::ApiError
raise Bitcoin2Graphdb::Error, 'previous block not found. maybe re-org occured.'
end
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
|