Module: CardanoWallet::Utils

Defined in:
lib/cardano_wallet/utils.rb

Overview

General Utils not connected to API

Examples:

@cw = CardanoWallet.new
@cw.utils

Defined Under Namespace

Classes: Mnemonic

Class Method Summary collapse

Class Method Details

.format_payments(payments) ⇒ Array of Hashes

Returns - [:amount=>{:quantity=>1, :unit=>“lovelace”}, …}].

Parameters:

  • payments (Array of Hashes)
    • 1, 2

Returns:

  • (Array of Hashes)
    • :amount=>{:quantity=>1, :unit=>“lovelace”}, …}


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/cardano_wallet/utils.rb', line 64

def self.format_payments(payments)
  verify_param_is_array!(payments)
  unless payments.all? { |p| p.size == 1 && p.is_a?(Hash) }
    raise ArgumentError, 'argument should be Array of single Hashes'
  end

  payments.map do |p|
    a = p.collect do |addr, amt|
      { address: addr.to_s,
        amount: { quantity: amt.to_i,
                  unit: 'lovelace' } }
    end.flatten
    Hash[*a]
  end
end

.new(opt) ⇒ Object



10
11
12
# File 'lib/cardano_wallet/utils.rb', line 10

def self.new(opt)
  Mnemonic.new opt
end

.to_query(query) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/cardano_wallet/utils.rb', line 80

def self.to_query(query)
  verify_param_is_hash!(query)
  q = query.collect do |k, v|
    "#{k}=#{v}"
  end.join '&'
  "?#{q}"
end

.verify_param_is_array!(param) ⇒ Object

Raises:

  • (ArgumentError)


57
58
59
# File 'lib/cardano_wallet/utils.rb', line 57

def self.verify_param_is_array!(param)
  raise ArgumentError, 'argument should be Array' unless param.is_a?(Array)
end

.verify_param_is_hash!(param) ⇒ Object

Raises:

  • (ArgumentError)


53
54
55
# File 'lib/cardano_wallet/utils.rb', line 53

def self.verify_param_is_hash!(param)
  raise ArgumentError, 'argument should be Hash' unless param.is_a?(Hash)
end