lib/nanook/block.rb in nanook-2.3.0 vs lib/nanook/block.rb in nanook-2.4.0

- old
+ new

@@ -64,17 +64,57 @@ def chain(limit: 1000) response = rpc(:chain, :block, count: limit)[:blocks] Nanook::Util.coerce_empty_string_to_type(response, Array) end + # Request confirmation for a block from online representative nodes. + # Will return immediately with a boolean to indicate if the request for + # confirmation was successful. Note that this boolean does not indicate + # the confirmation status of the block. If confirmed, your block should + # appear in {Nanook::Node#confirmation_history} within a short amount of + # time, or you can use the convenience method {Nanook::Block#confirmed_recently?} + # + # ==== Example: + # block.confirm # => true + # + # @return [Boolean] if the confirmation request was sent successful + def confirm + rpc(:block_confirm, :hash)[:started] == 1 + end + + # Check if the block appears in the list of recently confirmed blocks by + # online representatives. The full list of blocks can be queried for with {Nanook::Node#confirmation_history}. + # + # This method can work in conjunction with {Nanook::Block#confirm}, + # whereby you can send any block (old or new) out to online representatives to + # confirm. The confirmation process can take up to a couple of minutes. + # + # The method returning +false+ can indicate that the block is still in the process of being + # confirmed and that you should call the method again soon, or that it + # was confirmed earlier than the list available in {Nanook::Node#confirmation_history}, + # or that it was not confirmed. + # + # ==== Example: + # block.confirmed_recently? # => true + # + # @return [Boolean] +true+ if the block has been recently confirmed by + # online representatives. + def confirmed_recently? + @rpc.call(:confirmation_history)[:confirmations].map{|h| h[:hash]}.include?(@block) + end + alias_method :recently_confirmed?, :confirmed_recently? + # Generate work for a block. # # ==== Example: # block.generate_work # => "2bf29ef00786a6bc" # + # @param use_peers [Boolean] if set to +true+, then the node will query + # its work peers (if it has any, see {Nanook::WorkPeer#list}). + # When +false+, the node will only generate work locally (default is +false+) # @return [String] the work id of the work completed. - def generate_work - rpc(:work_generate, :hash)[:work] + def generate_work(use_peers: false) + rpc(:work_generate, :hash, use_peers: use_peers)[:work] end # Returns Array of Hashes containing information about a chain of # send/receive blocks, starting from this block. #