cardano_wallet 0.3.0 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0de7182a62723fefbe32712a08ac13765fe4507ac90969d3b752aff67fb05af
4
- data.tar.gz: e6346e28024ce715b14ab9964634f4dc5bf80f7d63526bae0a6c4bc4d2bce22f
3
+ metadata.gz: c950332d6aa59108f227517d4c832b4f5e0427be93205ba6b6f88a93b85ef7dd
4
+ data.tar.gz: fb58ff9bd30d1adbd5ad9014093ca4e58cb3d625103b45e31b4289625a46e31a
5
5
  SHA512:
6
- metadata.gz: d2e7311a7a4ef549aae1f9fb571f1ccc7e84800b9ffe10b80f08b23586a3e2cadd73aefb3215ad1bef28e5f8f09198323fafb01a4d0f3053770dd27d087f1281
7
- data.tar.gz: 3e4df4399289e3772061e4e8e68cae38a58308cbfb837b940af4736e36b1052884791cc641811a3b987307f75075e8df306bd0778683e83acf1479edd760a381
6
+ metadata.gz: 7a1e6e2eeb3734432a792d6e00736fd816fa3244f8f1651ad6daa7ddf91ac9ccb60392ae370bf0e45d9e199af7258e82afa8c75f50d34662bab535e4508398fd
7
+ data.tar.gz: f03b8111111b85cc59c8f22ea86fea2e5159a6634b69c1c06e20d786394ba037fa1f866aff081ad2c18aa1fb85e172e9fcb5f796e40b3124cb1000c5d47ad542
@@ -15,33 +15,32 @@ jobs:
15
15
  steps:
16
16
  - uses: actions/checkout@v2
17
17
 
18
- - name: Cache node db
19
- id: cache
20
- uses: actions/cache@v2
21
- with:
22
- path: ~/node-db-nightly-docker
23
- key: ${{ runner.os }}-node-db-tests-docker-${{ hashFiles('**/protocolMagicId') }}
18
+ - name: Set up Ruby
19
+ uses: ruby/setup-ruby@v1
20
+
21
+ - name: Install dependencies
22
+ run: bundle install
23
+
24
+ - name: Run rubocop
25
+ run: rubocop
26
+
27
+ - name: Get recent configs
28
+ run: bundle exec rake get_latest_configs[testnet]
24
29
 
25
30
  - name: Set up cardano-wallet and cardano-node
26
31
  run: |
27
32
  echo "Wallet: $WALLET"
28
33
  echo "Node: $NODE"
29
- NODE_CONFIG_PATH=`pwd`/spec/testnet docker-compose -f docker-compose-shelley.yml up --detach
34
+ NODE_CONFIG_PATH=`pwd`/configs docker-compose up --detach
30
35
  docker run --rm inputoutput/cardano-wallet:$WALLET version
31
36
  docker run --rm inputoutput/cardano-node:$NODE version
32
37
  ls ~/node-db-nightly-docker
33
38
 
34
- - name: Set up Ruby
35
- uses: ruby/setup-ruby@v1
36
-
37
- - name: Install dependencies
38
- run: bundle install
39
-
40
39
  - name: Run all tests except nighlty
41
- run: rspec . -t ~nightly
40
+ run: rake spec
42
41
 
43
42
  - name: Stop docker-compose
44
- run: NODE_CONFIG_PATH=`pwd`/spec/testnet docker-compose -f docker-compose-shelley.yml down
43
+ run: NODE_CONFIG_PATH=`pwd`/configs docker-compose down
45
44
  env:
46
45
  CI: true
47
46
  CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
data/.gitignore CHANGED
@@ -6,6 +6,10 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /configs/
10
+ /node_db/
11
+ /wallet_db/
12
+ /binaries/
9
13
 
10
14
  Gemfile.lock
11
15
 
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
4
+
5
+ Metrics/AbcSize:
6
+ Enabled: false
7
+
8
+ Metrics/ClassLength:
9
+ Enabled: false
10
+
11
+ Metrics/BlockLength:
12
+ Enabled: false
13
+
14
+ Metrics/MethodLength:
15
+ Enabled: false
16
+
17
+ Metrics/PerceivedComplexity:
18
+ Enabled: false
19
+
20
+ Metrics/CyclomaticComplexity:
21
+ Enabled: false
22
+
23
+ Metrics/ParameterLists:
24
+ Max: 10
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in cardano_wallet.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
 
2
+
2
3
  <a href="https://badge.fury.io/rb/cardano_wallet">
3
4
  <img src="https://badge.fury.io/rb/cardano_wallet.svg" alt="Gem Version">
4
5
  </a>
@@ -11,27 +12,26 @@
11
12
  <a href="https://github.com/piotr-iohk/cardano-wallet-rb/actions?query=workflow%3ATests">
12
13
  <img src="https://github.com/piotr-iohk/cardano-wallet-rb/workflows/Tests/badge.svg" />
13
14
  </a>
14
- <a href="https://github.com/piotr-iohk/cardano-wallet-rb/actions?query=workflow%3ANightly">
15
- <img src="https://github.com/piotr-iohk/cardano-wallet-rb/workflows/Nightly/badge.svg" />
16
- </a>
15
+
17
16
 
18
17
  # cardano-wallet-rb
19
18
 
20
19
  Ruby wrapper over [cardano-wallet's](https://github.com/input-output-hk/cardano-wallet) REST [API](https://input-output-hk.github.io/cardano-wallet/api/edge/).
21
20
 
21
+ ## E2E tests
22
+
23
+ Cardano-wallet-rb is used for e2e testing of [cardano-wallet](https://github.com/input-output-hk/cardano-wallet/test/e2e) against public testnet.
24
+
25
+
22
26
  ## Installation
23
27
 
24
- Add this line to your application's Gemfile:
28
+ In Gemfile:
25
29
 
26
30
  ```ruby
27
31
  gem 'cardano_wallet'
28
32
  ```
29
33
 
30
- And then execute:
31
-
32
- $ bundle install
33
-
34
- Or install it yourself as:
34
+ Or:
35
35
 
36
36
  $ gem install cardano_wallet
37
37
 
@@ -43,22 +43,6 @@ For `cardano-wallet` REST Api see: https://input-output-hk.github.io/cardano-wal
43
43
 
44
44
  ## Usage
45
45
 
46
- ### Initialize
47
-
48
- ```ruby
49
- # default options
50
- CW = CardanoWallet.new
51
-
52
- # custom options
53
- CW1 = CardanoWallet.new({port: 8091})
54
- CW2 = CardanoWallet.new({port: 443,
55
- protocol: "https",
56
- cacert: "/root/ca.cert",
57
- pem: "/root/client.pem"})
58
- CW3 = CardanoWallet.new({url: "http://localhost:8090/v2"})
59
- ```
60
-
61
- ### Exercise
62
46
  ```ruby
63
47
  CW = CardanoWallet.new
64
48
 
data/Rakefile CHANGED
@@ -1,16 +1,36 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'httparty'
6
+ require_relative 'lib/cardano_wallet'
3
7
 
4
8
  RSpec::Core::RakeTask.new(:spec)
5
9
 
6
- task :default => :spec
10
+ task default: :spec
7
11
 
8
- require_relative "lib/cardano_wallet"
9
- task :wait_until_node_synced do
10
- desc "Wait for node to be synced"
11
- network = CardanoWallet.new.misc.network
12
- while network.information["sync_progress"]["status"] == "syncing" do
13
- puts "Syncing... #{network.information["sync_progress"]["progress"]["quantity"]}%"
14
- sleep 15
12
+ def wget(url, file = nil)
13
+ file ||= File.basename(url)
14
+ resp = HTTParty.get(url)
15
+ File.open(file, 'wb') do |f|
16
+ f.write(resp.body)
15
17
  end
18
+ puts "#{url} -> #{resp.code}"
19
+ end
20
+
21
+ def mk_dir(path)
22
+ Dir.mkdir(path) unless File.exist?(path)
23
+ end
24
+
25
+ task :get_latest_configs, [:env] do |_, args|
26
+ puts "\n >> Get latest configs for '#{args[:env]}'"
27
+
28
+ base_url = 'https://hydra.iohk.io/job/Cardano/cardano-node/cardano-deployment/latest-finished/download/1'
29
+ env = args[:env]
30
+ path = File.join(Dir.pwd, 'configs')
31
+ mk_dir(path)
32
+ wget("#{base_url}/#{env}-config.json", "#{path}/#{env}-config.json")
33
+ wget("#{base_url}/#{env}-byron-genesis.json", "#{path}/#{env}-byron-genesis.json")
34
+ wget("#{base_url}/#{env}-shelley-genesis.json", "#{path}/#{env}-shelley-genesis.json")
35
+ wget("#{base_url}/#{env}-topology.json", "#{path}/#{env}-topology.json")
16
36
  end
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "cardano_wallet"
4
+ require 'bundler/setup'
5
+ require 'cardano_wallet'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "cardano_wallet"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
data/bin/run_all_tests ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+
3
+ NODE_DB=./node_db \
4
+ WALLET_DB=./wallet_db \
5
+ TOKEN_METADATA=http://metadata-server-mock.herokuapp.com/ \
6
+ bundle exec rake run_on["testnet"]
@@ -1,38 +1,40 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'lib/cardano_wallet/version'
2
4
 
3
5
  Gem::Specification.new do |spec|
4
- spec.name = "cardano_wallet"
6
+ spec.name = 'cardano_wallet'
5
7
  spec.version = CardanoWallet::VERSION
6
- spec.authors = ["Piotr Stachyra"]
7
- spec.email = ["piotr.stachyra@gmail.com"]
8
+ spec.authors = ['Piotr Stachyra']
9
+ spec.email = ['piotr.stachyra@gmail.com']
8
10
 
9
- spec.summary = %q{Ruby wrapper over cardano-wallet.}
10
- spec.description = %q{Ruby wrapper over cardano-wallet.}
11
- spec.homepage = "https://github.com/piotr-iohk/cardano-wallet-rb"
12
- spec.license = "MIT"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
11
+ spec.summary = 'Ruby wrapper over cardano-wallet.'
12
+ spec.description = 'Ruby wrapper over cardano-wallet.'
13
+ spec.homepage = 'https://github.com/piotr-iohk/cardano-wallet-rb'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
14
16
 
15
- spec.metadata["allowed_push_host"] = "https://rubygems.org/"
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
16
18
 
17
- spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = spec.homepage
19
- spec.metadata["changelog_uri"] = spec.homepage
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = spec.homepage
21
+ spec.metadata['changelog_uri'] = spec.homepage
20
22
 
21
23
  # Specify which files should be added to the gem when it is released.
22
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
26
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
27
  end
26
- spec.bindir = "exe"
28
+ spec.bindir = 'exe'
27
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
30
+ spec.require_paths = ['lib']
29
31
 
30
32
  spec.add_runtime_dependency 'httparty', '~> 0.18.0'
31
33
 
32
- spec.add_development_dependency 'rake', '~> 12.3'
33
- spec.add_development_dependency 'rspec', '~> 3.7'
34
34
  spec.add_development_dependency 'bip_mnemonic', '~> 0.0.4'
35
35
  spec.add_development_dependency 'codecov', '0.2.8'
36
+ spec.add_development_dependency 'rake', '~> 12.3'
37
+ spec.add_development_dependency 'rspec', '~> 3.7'
38
+ spec.add_development_dependency 'rubocop', '~> 1.11'
36
39
  spec.add_development_dependency 'simplecov'
37
-
38
40
  end
File without changes
@@ -1,12 +1,17 @@
1
- require "httparty"
1
+ # frozen_string_literal: true
2
2
 
3
- require_relative "cardano_wallet/version"
4
- require_relative "cardano_wallet/base"
5
- require_relative "cardano_wallet/utils"
6
- require_relative "cardano_wallet/shelley"
7
- require_relative "cardano_wallet/byron"
8
- require_relative "cardano_wallet/misc"
3
+ require 'httparty'
9
4
 
5
+ require_relative 'cardano_wallet/version'
6
+ require_relative 'cardano_wallet/base'
7
+ require_relative 'cardano_wallet/utils'
8
+ require_relative 'cardano_wallet/shelley'
9
+ require_relative 'cardano_wallet/byron'
10
+ require_relative 'cardano_wallet/misc'
11
+ require_relative 'cardano_wallet/shared'
12
+
13
+ ##
14
+ # Main module
10
15
  module CardanoWallet
11
16
  def self.new(options = {})
12
17
  CardanoWallet::Base.new(options)
@@ -1,11 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CardanoWallet
4
+ ##
5
+ # Base class for all APIs
2
6
  class Base
3
7
  include HTTParty
4
8
 
5
9
  attr_accessor :opt
6
10
 
7
11
  def initialize(opt = {})
8
- raise ArgumentError, "argument should be Hash" unless opt.is_a?(Hash)
12
+ raise ArgumentError, 'argument should be Hash' unless opt.is_a?(Hash)
9
13
 
10
14
  opt[:protocol] ||= 'http'
11
15
  opt[:host] ||= 'localhost'
@@ -15,15 +19,13 @@ module CardanoWallet
15
19
  opt[:pem] ||= ''
16
20
  opt[:timeout] ||= -1
17
21
  self.class.base_uri opt[:url]
18
- unless(opt[:timeout] == -1)
19
- self.class.default_timeout(opt[:timeout].to_i)
20
- end
22
+ self.class.default_timeout(opt[:timeout].to_i) unless opt[:timeout] == -1
21
23
 
22
24
  unless opt[:cacert].empty?
23
25
  ENV['SSL_CERT_FILE'] = opt[:cacert]
24
- self.class.ssl_ca_file(File.read ENV['SSL_CERT_FILE'])
26
+ self.class.ssl_ca_file(File.read(ENV['SSL_CERT_FILE']))
25
27
  end
26
- self.class.pem(File.read opt[:pem]) unless opt[:pem].empty?
28
+ self.class.pem(File.read(opt[:pem])) unless opt[:pem].empty?
27
29
 
28
30
  @opt = opt
29
31
  end
@@ -33,6 +35,11 @@ module CardanoWallet
33
35
  Shelley.new @opt
34
36
  end
35
37
 
38
+ # Init API for Shared wallets
39
+ def shared
40
+ Shared.new @opt
41
+ end
42
+
36
43
  # Init API for Byron
37
44
  def byron
38
45
  Byron.new @opt
@@ -1,15 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CardanoWallet
4
+ ##
5
+ # Byron APIs
2
6
  module Byron
3
-
4
7
  def self.new(opt)
5
8
  Init.new opt
6
9
  end
7
10
 
11
+ ##
12
+ # Init class for Byron APIs
8
13
  class Init < Base
9
- def initialize opt
10
- super
11
- end
12
-
13
14
  # Get API for Byron wallets
14
15
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Wallets
15
16
  def wallets
@@ -47,11 +48,9 @@ module CardanoWallet
47
48
  end
48
49
  end
49
50
 
51
+ ##
52
+ # Init for Byron assets APIs
50
53
  class Assets < Base
51
- def initialize opt
52
- super
53
- end
54
-
55
54
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listByronAssets
56
55
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronAsset
57
56
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronAssetDefault
@@ -61,20 +60,15 @@ module CardanoWallet
61
60
  ep += "/#{asset_name}" if asset_name
62
61
  self.class.get(ep)
63
62
  end
64
-
65
63
  end
66
64
 
67
65
  # Byron wallets
68
66
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Wallets
69
67
  class Wallets < Base
70
- def initialize opt
71
- super
72
- end
73
-
74
68
  # List Byron wallets
75
69
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listByronWallets
76
70
  def list
77
- self.class.get("/byron-wallets")
71
+ self.class.get('/byron-wallets')
78
72
  end
79
73
 
80
74
  # Get Byron wallet details
@@ -90,14 +84,13 @@ module CardanoWallet
90
84
  # create({style: "random",
91
85
  # name: "Random Wallet from mnemonic_sentence",
92
86
  # passphrase: "Secure Passphrase",
93
- # mnemonic_sentence: %w[arctic decade pink easy jar index base bright vast ocean hard pizza],
87
+ # mnemonic_sentence: %w[arctic decade pizza ...],
94
88
  # })
95
89
  def create(params)
96
90
  Utils.verify_param_is_hash!(params)
97
- self.class.post( "/byron-wallets",
98
- :body => params.to_json,
99
- :headers => { 'Content-Type' => 'application/json' }
100
- )
91
+ self.class.post('/byron-wallets',
92
+ body: params.to_json,
93
+ headers: { 'Content-Type' => 'application/json' })
101
94
  end
102
95
 
103
96
  # Delete Byron wallet
@@ -114,9 +107,8 @@ module CardanoWallet
114
107
  def update_metadata(wid, params)
115
108
  Utils.verify_param_is_hash!(params)
116
109
  self.class.put("/byron-wallets/#{wid}",
117
- :body => params.to_json,
118
- :headers => { 'Content-Type' => 'application/json' }
119
- )
110
+ body: params.to_json,
111
+ headers: { 'Content-Type' => 'application/json' })
120
112
  end
121
113
 
122
114
  # See Byron wallet's utxo distribution
@@ -133,27 +125,22 @@ module CardanoWallet
133
125
  def update_passphrase(wid, params)
134
126
  Utils.verify_param_is_hash!(params)
135
127
  self.class.put("/byron-wallets/#{wid}/passphrase",
136
- :body => params.to_json,
137
- :headers => { 'Content-Type' => 'application/json' }
138
- )
128
+ body: params.to_json,
129
+ headers: { 'Content-Type' => 'application/json' })
139
130
  end
140
131
  end
141
132
 
142
133
  # Byron addresses
143
134
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Addresses
144
135
  class Addresses < Base
145
- def initialize opt
146
- super
147
- end
148
-
149
136
  # List Byron addresses.
150
137
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listByronAddresses
151
138
  #
152
139
  # @example
153
140
  # list(wid, {state: "used"})
154
- def list(wid, q = {})
155
- q.empty? ? query = '' : query = Utils.to_query(q)
156
- self.class.get("/byron-wallets/#{wid}/addresses#{query}")
141
+ def list(wid, query = {})
142
+ query_formatted = query.empty? ? '' : Utils.to_query(query)
143
+ self.class.get("/byron-wallets/#{wid}/addresses#{query_formatted}")
157
144
  end
158
145
 
159
146
  # Create address for Byron random wallet.
@@ -167,10 +154,9 @@ module CardanoWallet
167
154
  # create(wid, {passphrase: "Secure Passphrase"})
168
155
  def create(wid, params)
169
156
  Utils.verify_param_is_hash!(params)
170
- self.class.post( "/byron-wallets/#{wid}/addresses",
171
- :body => params.to_json,
172
- :headers => { 'Content-Type' => 'application/json' }
173
- )
157
+ self.class.post("/byron-wallets/#{wid}/addresses",
158
+ body: params.to_json,
159
+ headers: { 'Content-Type' => 'application/json' })
174
160
  end
175
161
 
176
162
  # Import address to Byron wallet.
@@ -187,39 +173,38 @@ module CardanoWallet
187
173
  # @param addresses [Array] array of addresses
188
174
  def bulk_import(wid, addresses)
189
175
  self.class.put("/byron-wallets/#{wid}/addresses",
190
- :body => { :addresses => addresses
191
- }.to_json,
192
- :headers => { 'Content-Type' => 'application/json' } )
176
+ body: { addresses: addresses }.to_json,
177
+ headers: { 'Content-Type' => 'application/json' })
193
178
  end
194
179
  end
195
180
 
196
181
  # API for CoinSelections
197
182
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Coin-Selections
198
183
  class CoinSelections < Base
199
- def initialize opt
200
- super
201
- end
202
-
203
184
  # Show random coin selection for particular payment
204
185
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/byronSelectCoins
205
186
  #
206
187
  # @example
207
188
  # random(wid, [{addr1: 1000000}, {addr2: 1000000}])
189
+ # random(wid, [{ "address": "addr1..",
190
+ # "amount": { "quantity": 42000000, "unit": "lovelace" },
191
+ # "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ])
208
192
  def random(wid, payments)
209
- payments_formatted = Utils.format_payments(payments)
193
+ Utils.verify_param_is_array!(payments)
194
+ payments_formatted = if payments.any? { |p| p.key?(:address) || p.key?('address') }
195
+ payments
196
+ else
197
+ Utils.format_payments(payments)
198
+ end
210
199
  self.class.post("/byron-wallets/#{wid}/coin-selections/random",
211
- :body => {:payments => payments_formatted}.to_json,
212
- :headers => { 'Content-Type' => 'application/json' })
200
+ body: { payments: payments_formatted }.to_json,
201
+ headers: { 'Content-Type' => 'application/json' })
213
202
  end
214
203
  end
215
204
 
216
205
  # Byron transactions
217
206
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postByronTransactionFee
218
207
  class Transactions < Base
219
- def initialize opt
220
- super
221
- end
222
-
223
208
  # Get tx by id
224
209
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronTransaction
225
210
  def get(wid, tx_id)
@@ -231,9 +216,9 @@ module CardanoWallet
231
216
  #
232
217
  # @example
233
218
  # list(wid, {start: "2012-09-25T10:15:00Z", order: "descending"})
234
- def list(wid, q = {})
235
- q.empty? ? query = '' : query = Utils.to_query(q)
236
- self.class.get("/byron-wallets/#{wid}/transactions#{query}")
219
+ def list(wid, query = {})
220
+ query_formatted = query.empty? ? '' : Utils.to_query(query)
221
+ self.class.get("/byron-wallets/#{wid}/transactions#{query_formatted}")
237
222
  end
238
223
 
239
224
  # Create a transaction from the Byron wallet.
@@ -244,19 +229,21 @@ module CardanoWallet
244
229
  #
245
230
  # @example
246
231
  # create(wid, passphrase, [{addr1: 1000000}, {addr2: 1000000}])
247
- # create(wid, passphrase, [{ "address": "addr1..", "amount": { "quantity": 42000000, "unit": "lovelace" }, "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ])
232
+ # create(wid, passphrase, [{ "address": "addr1..",
233
+ # "amount": { "quantity": 42000000, "unit": "lovelace" },
234
+ # "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ])
248
235
 
249
236
  def create(wid, passphrase, payments)
250
- if payments.any?{|p| p.has_key?("address".to_sym) || p.has_key?("address")}
251
- payments_formatted = payments
252
- else
253
- payments_formatted = Utils.format_payments(payments)
254
- end
237
+ Utils.verify_param_is_array!(payments)
238
+ payments_formatted = if payments.any? { |p| p.key?(:address) || p.key?('address') }
239
+ payments
240
+ else
241
+ Utils.format_payments(payments)
242
+ end
255
243
  self.class.post("/byron-wallets/#{wid}/transactions",
256
- :body => { :payments => payments_formatted,
257
- :passphrase => passphrase
258
- }.to_json,
259
- :headers => { 'Content-Type' => 'application/json' } )
244
+ body: { payments: payments_formatted,
245
+ passphrase: passphrase }.to_json,
246
+ headers: { 'Content-Type' => 'application/json' })
260
247
  end
261
248
 
262
249
  # Estimate fees for transaction
@@ -264,16 +251,19 @@ module CardanoWallet
264
251
  #
265
252
  # @example
266
253
  # payment_fees(wid, [{addr1: 1000000}, {addr2: 1000000}])
267
- # payment_fees(wid, [{ "address": "addr1..", "amount": { "quantity": 42000000, "unit": "lovelace" }, "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ])
254
+ # payment_fees(wid, [{ "address": "addr1..",
255
+ # "amount": { "quantity": 42000000, "unit": "lovelace" },
256
+ # "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ])
268
257
  def payment_fees(wid, payments)
269
- if payments.any?{|p| p.has_key?("address".to_sym) || p.has_key?("address")}
270
- payments_formatted = payments
271
- else
272
- payments_formatted = Utils.format_payments(payments)
273
- end
258
+ Utils.verify_param_is_array!(payments)
259
+ payments_formatted = if payments.any? { |p| p.key?(:address) || p.key?('address') }
260
+ payments
261
+ else
262
+ Utils.format_payments(payments)
263
+ end
274
264
  self.class.post("/byron-wallets/#{wid}/payment-fees",
275
- :body => { :payments => payments_formatted }.to_json,
276
- :headers => { 'Content-Type' => 'application/json' } )
265
+ body: { payments: payments_formatted }.to_json,
266
+ headers: { 'Content-Type' => 'application/json' })
277
267
  end
278
268
 
279
269
  # Forget a transaction.
@@ -286,14 +276,12 @@ module CardanoWallet
286
276
  # Byron migrations
287
277
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Migrations
288
278
  class Migrations < Base
289
- def initialize opt
290
- super
291
- end
292
-
293
- # Calculate migration cost
294
- # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronWalletMigrationInfo
295
- def cost(wid)
296
- self.class.get("/byron-wallets/#{wid}/migrations")
279
+ # Get migration plan
280
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/createByronWalletMigrationPlan
281
+ def plan(wid, addresses)
282
+ self.class.post("/byron-wallets/#{wid}/migrations/plan",
283
+ body: { addresses: addresses }.to_json,
284
+ headers: { 'Content-Type' => 'application/json' })
297
285
  end
298
286
 
299
287
  # Migrate all funds from Byron wallet.
@@ -303,12 +291,10 @@ module CardanoWallet
303
291
  # @param [Array] array of addresses
304
292
  def migrate(wid, passphrase, addresses)
305
293
  self.class.post("/byron-wallets/#{wid}/migrations",
306
- :body => { :addresses => addresses,
307
- :passphrase => passphrase
308
- }.to_json,
309
- :headers => { 'Content-Type' => 'application/json' } )
294
+ body: { addresses: addresses,
295
+ passphrase: passphrase }.to_json,
296
+ headers: { 'Content-Type' => 'application/json' })
310
297
  end
311
-
312
298
  end
313
299
  end
314
300
  end