Module: CardanoWallet::Utils
- Defined in:
- lib/cardano_wallet/utils.rb
Overview
General Utils not connected to API
Defined Under Namespace
Classes: Mnemonic
Class Method Summary collapse
-
.format_payments(payments) ⇒ Array of Hashes
-
[:amount=>{:quantity=>1, :unit=>“lovelace”}, …}].
-
- .new(opt) ⇒ Object
- .to_query(query) ⇒ Object
- .verify_param_is_array!(param) ⇒ Object
- .verify_param_is_hash!(param) ⇒ Object
Class Method Details
.format_payments(payments) ⇒ Array of Hashes
Returns - [: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
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
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 |