cardano_wallet 0.3.1 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f416f0ff4fd389ce9af664e9c128f0765cda62c346f6b2f3b5237a884e43a253
4
- data.tar.gz: 5769fb34859b6c2ddc7376a718ba5c0fc7962810cc1d3fc6012a82219d979302
3
+ metadata.gz: f149bd85ed1c3a010b17f066f6c8a8e246206b0d4d8850d407119a85f41c13c8
4
+ data.tar.gz: f93405819fda7d70f52ba8f9012388b872705eec927f2d8d0b33bed7a89cf465
5
5
  SHA512:
6
- metadata.gz: 8b3492bd2f7f215a3ef7008ae997189eab233ab821764f93a1bae69f3bf859258c519dd808e433ec2edcc6f9ba183e59dc28e3439d974dc35dec498f106becf7
7
- data.tar.gz: 877550274108bc8c06203b9f488493c930d57b45c71ce7601f0116d129826f5638801dc46355b123ec2bf784977129e9a73fdfbc430e1d52f7bd13c28dbe39f8
6
+ metadata.gz: 8bb6a4745be667c10ae3d9d9710156c6ae596d4ebd6c1314e379b0e30d62c73f2bc4640e9b6925d17eac8dbdd71da50cf820a156c92b484349068beb30c53450
7
+ data.tar.gz: a18defeaa4668b984d98b6518857855297215935bf20a6df293800356bd8db4e2fae694eef28b35b31cedd41d8bd2925013e1c415e1e50710a4391ae9293cf9b
@@ -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,45 +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}])
208
- # random(wid, [{ "address": "addr1..", "amount": { "quantity": 42000000, "unit": "lovelace" }, "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ])
189
+ # random(wid, [{ "address": "addr1..",
190
+ # "amount": { "quantity": 42000000, "unit": "lovelace" },
191
+ # "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ])
209
192
  def random(wid, payments)
210
193
  Utils.verify_param_is_array!(payments)
211
- if payments.any?{|p| p.has_key?("address".to_sym) || p.has_key?("address")}
212
- payments_formatted = payments
213
- else
214
- payments_formatted = Utils.format_payments(payments)
215
- end
194
+ payments_formatted = if payments.any? { |p| p.key?(:address) || p.key?('address') }
195
+ payments
196
+ else
197
+ Utils.format_payments(payments)
198
+ end
216
199
  self.class.post("/byron-wallets/#{wid}/coin-selections/random",
217
- :body => {:payments => payments_formatted}.to_json,
218
- :headers => { 'Content-Type' => 'application/json' })
200
+ body: { payments: payments_formatted }.to_json,
201
+ headers: { 'Content-Type' => 'application/json' })
219
202
  end
220
203
  end
221
204
 
222
205
  # Byron transactions
223
206
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postByronTransactionFee
224
207
  class Transactions < Base
225
- def initialize opt
226
- super
227
- end
228
-
229
208
  # Get tx by id
230
209
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronTransaction
231
210
  def get(wid, tx_id)
@@ -237,9 +216,9 @@ module CardanoWallet
237
216
  #
238
217
  # @example
239
218
  # list(wid, {start: "2012-09-25T10:15:00Z", order: "descending"})
240
- def list(wid, q = {})
241
- q.empty? ? query = '' : query = Utils.to_query(q)
242
- 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}")
243
222
  end
244
223
 
245
224
  # Create a transaction from the Byron wallet.
@@ -250,20 +229,21 @@ module CardanoWallet
250
229
  #
251
230
  # @example
252
231
  # create(wid, passphrase, [{addr1: 1000000}, {addr2: 1000000}])
253
- # 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 } ] } ])
254
235
 
255
236
  def create(wid, passphrase, payments)
256
237
  Utils.verify_param_is_array!(payments)
257
- if payments.any?{|p| p.has_key?("address".to_sym) || p.has_key?("address")}
258
- payments_formatted = payments
259
- else
260
- payments_formatted = Utils.format_payments(payments)
261
- end
238
+ payments_formatted = if payments.any? { |p| p.key?(:address) || p.key?('address') }
239
+ payments
240
+ else
241
+ Utils.format_payments(payments)
242
+ end
262
243
  self.class.post("/byron-wallets/#{wid}/transactions",
263
- :body => { :payments => payments_formatted,
264
- :passphrase => passphrase
265
- }.to_json,
266
- :headers => { 'Content-Type' => 'application/json' } )
244
+ body: { payments: payments_formatted,
245
+ passphrase: passphrase }.to_json,
246
+ headers: { 'Content-Type' => 'application/json' })
267
247
  end
268
248
 
269
249
  # Estimate fees for transaction
@@ -271,17 +251,19 @@ module CardanoWallet
271
251
  #
272
252
  # @example
273
253
  # payment_fees(wid, [{addr1: 1000000}, {addr2: 1000000}])
274
- # 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 } ] } ])
275
257
  def payment_fees(wid, payments)
276
258
  Utils.verify_param_is_array!(payments)
277
- if payments.any?{|p| p.has_key?("address".to_sym) || p.has_key?("address")}
278
- payments_formatted = payments
279
- else
280
- payments_formatted = Utils.format_payments(payments)
281
- end
259
+ payments_formatted = if payments.any? { |p| p.key?(:address) || p.key?('address') }
260
+ payments
261
+ else
262
+ Utils.format_payments(payments)
263
+ end
282
264
  self.class.post("/byron-wallets/#{wid}/payment-fees",
283
- :body => { :payments => payments_formatted }.to_json,
284
- :headers => { 'Content-Type' => 'application/json' } )
265
+ body: { payments: payments_formatted }.to_json,
266
+ headers: { 'Content-Type' => 'application/json' })
285
267
  end
286
268
 
287
269
  # Forget a transaction.
@@ -294,14 +276,12 @@ module CardanoWallet
294
276
  # Byron migrations
295
277
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Migrations
296
278
  class Migrations < Base
297
- def initialize opt
298
- super
299
- end
300
-
301
- # Calculate migration cost
302
- # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronWalletMigrationInfo
303
- def cost(wid)
304
- 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' })
305
285
  end
306
286
 
307
287
  # Migrate all funds from Byron wallet.
@@ -311,12 +291,10 @@ module CardanoWallet
311
291
  # @param [Array] array of addresses
312
292
  def migrate(wid, passphrase, addresses)
313
293
  self.class.post("/byron-wallets/#{wid}/migrations",
314
- :body => { :addresses => addresses,
315
- :passphrase => passphrase
316
- }.to_json,
317
- :headers => { 'Content-Type' => 'application/json' } )
294
+ body: { addresses: addresses,
295
+ passphrase: passphrase }.to_json,
296
+ headers: { 'Content-Type' => 'application/json' })
318
297
  end
319
-
320
298
  end
321
299
  end
322
300
  end