lib/sibit/blockchain.rb in sibit-0.14.3 vs lib/sibit/blockchain.rb in sibit-0.14.4
- old
+ new
@@ -102,10 +102,29 @@
URI('https://blockchain.info/latestblock')
)['hash']
end
# This method should fetch a Blockchain block and return as a hash.
- def block(_hash)
- raise Sibit::Error, 'block() not implemented yet'
+ def block(hash)
+ json = Sibit::Json.new(http: @http, log: @log).get(
+ URI("https://blockchain.info/rawblock/#{hash}")
+ )
+ {
+ hash: json['hash'],
+ orphan: !json['main_chain'],
+ next: json['next_block'][0],
+ previous: json['prev_block'],
+ txns: json['tx'].map do |t|
+ {
+ hash: t['hash'],
+ outputs: t['out'].map do |o|
+ {
+ address: o['hash'],
+ value: o['value']
+ }
+ end
+ }
+ end
+ }
end
end
end