Module: Solana::Ruby::Kit::Rpc::Api::GetLatestBlockhash

Extended by:
T::Sig
Included in:
Client
Defined in:
lib/solana/ruby/kit/rpc/api/get_latest_blockhash.rb

Overview

Returns the latest blockhash and its expiry block height. Mirrors TypeScript’s ‘GetLatestBlockhashApi.getLatestBlockhash(config?)`.

Returns a RpcContextualValue with:

.slot  

Instance Method Summary collapse

Instance Method Details

#get_latest_blockhash(commitment: nil, min_context_slot: nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/solana/ruby/kit/rpc/api/get_latest_blockhash.rb', line 31

def get_latest_blockhash(commitment: nil, min_context_slot: nil)
  config = {}
  config['commitment']      = commitment.to_s if commitment
  config['minContextSlot']  = min_context_slot if min_context_slot

  params = config.empty? ? [] : [config]
  result = transport.request('getLatestBlockhash', params)

  value = LatestBlockhash.new(
    blockhash:               result['value']['blockhash'],
    last_valid_block_height: Kernel.Integer(result['value']['lastValidBlockHeight'])
  )

  RpcTypes::RpcContextualValue.new(
    slot:  Kernel.Integer(result['context']['slot']),
    value: value
  )
end