lib/nanook/block.rb in nanook-0.7.0 vs lib/nanook/block.rb in nanook-1.0.0

- old
+ new

@@ -1,11 +1,26 @@ class Nanook + + # The <tt>Nanook::Block</tt> class contains methods to discover + # publicly-available information about blocks on the nano network. + # + # A block is represented by a unique hash + # + # Initialize this class through the convenient Nanook#block method: + # + # nanook = Nanook.new + # account = nanook.block("991CF19...") + # + # Or compose the longhand way like this: + # + # rpc_conn = Nanook::Rpc.new + # block = Nanook::Block.new(rpc_conn, "991CF19...") class Block - def initialize(block, rpc) - @block = block + def initialize(rpc, block) @rpc = rpc + @block = block block_required! # All methods expect a block end def account rpc(:block_account, :hash)[:account] @@ -26,10 +41,14 @@ def history(limit: 1000) rpc(:history, :hash, count: limit)[:history] end + def id + @block + end + def info(allow_unchecked: false) if allow_unchecked # TODO not actually sure what this response looks like when it's not an unchecked block, assuming its blank response = rpc(:unchecked_get, :hash) if response[:error] != "Block not found" @@ -71,9 +90,13 @@ end def successors(limit: 1000) response = rpc(:successors, :block, count: limit)[:blocks] Nanook::Util.coerce_empty_string_to_type(response, Array) + end + + def inspect # :nodoc: + "#{self.class.name}(id: \"#{id}\", object_id: \"#{"0x00%x" % (object_id << 1)}\")" end private # Some RPC calls expect the param that represents the block to be named