Module: Bluzelle

Defined in:
lib/bluzelle.rb

Defined Under Namespace

Classes: APIError, Client, OptionsError

Class Method Summary collapse

Class Method Details

.new_client(options) ⇒ Object

Raises:



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
69
70
71
# File 'lib/bluzelle.rb', line 42

def self.new_client options
  raise OptionsError, 'address is required' unless options.fetch('address', nil)
  raise OptionsError, 'mnemonic is required' unless options.fetch('mnemonic', nil)

  gas_info = options.fetch('gas_info', {})
  unless gas_info.class.equal?(Hash)
    raise OptionsError, 'gas_info should be a dict of {gas_price, max_fee, max_gas}'
  end

  gas_info_keys = %w[gas_price max_fee max_gas]
  gas_info_keys.each do |k|
    v = gas_info.fetch(k, 0)
    unless v.class.equal?(Integer)
      raise OptionsError, 'gas_info[%s] should be an int' % k
    end

    gas_info[k] = v
  end

  options['debug'] = false unless options.fetch('debug', false)
  options['chain_id'] = DEFAULT_CHAIN_ID unless options.fetch('chain_id', nil)
  options['endpoint'] = DEFAULT_ENDPOINT unless options.fetch('endpoint', nil)

  c = Client.new options
  c.setup_logging
  c.set_private_key
  c.verify_address
  c.
  c
end