cardano_wallet 0.2.9 → 0.3.4

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: f9ad05abba294de18063a3e1e381ce3e06e95644f4209526eba555f9a2504dae
4
- data.tar.gz: 24ee6eeb1fd928c07df71c9e2875fae4b150c6ac564ecfd1775001f1d712468b
3
+ metadata.gz: 4c4ef984dbf796ca336b600e76893886c71143afe2e1e595213b811422583449
4
+ data.tar.gz: e5301c79329e5479d586da24699387bef0b51b2e0d13039a71205516987bfe55
5
5
  SHA512:
6
- metadata.gz: a94ebe1b3dc75ed9da0c3a7da543e607c3228baa1f9f127f09cd8d3f50e37f54dca7c2c6e84176f8ae4f0c8e0933e5c38b6dc536efddc98b5a2b34e5db7c4adf
7
- data.tar.gz: '042836808eb65faf1a67f5508dd7ea12fd4b82c61cd6e7d9da8f4cb728fd45e6d9bf96ef1ea1afeedba8fdb56d9e53ff16a49dd08987edf678bd64aeb657708c'
6
+ metadata.gz: d3993f7213a754bf4a84635f332771daba159a8fe7bd0f843b1a69ee8c8732ac948574a5511bd11b6f7c95a0ca17b5f47befe4fff1154cf3364a16dea3d42bb4
7
+ data.tar.gz: 7e622616a8ca9d661446150aeaa0afec89036a43d0c442f6bd16f94f5ce1a154b53f8b812ae5d46cd77e4c19cad4cf26609e5810e843e60ab268ba27ee606950
@@ -1,10 +1,3 @@
1
- # This workflow uses actions that are not certified by GitHub.
2
- # They are provided by a third-party and are governed by
3
- # separate terms of service, privacy policy, and support
4
- # documentation.
5
- # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
- # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
-
8
1
  name: Tests
9
2
 
10
3
  on:
@@ -12,6 +5,7 @@ on:
12
5
  branches: [ master ]
13
6
  pull_request:
14
7
  branches: [ master ]
8
+ workflow_dispatch:
15
9
 
16
10
  jobs:
17
11
  test:
@@ -20,17 +14,36 @@ jobs:
20
14
 
21
15
  steps:
22
16
  - uses: actions/checkout@v2
23
- - name: Set up cardano-wallet
24
- run: NODE_CONFIG_PATH=`pwd`/spec/testnet docker-compose -f docker-compose-shelley.yml up --detach
17
+
25
18
  - name: Set up Ruby
26
19
  uses: ruby/setup-ruby@v1
20
+
27
21
  - name: Install dependencies
28
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]
29
+
30
+ - name: Set up cardano-wallet and cardano-node
31
+ run: |
32
+ echo "Wallet: $WALLET"
33
+ echo "Node: $NODE"
34
+ NODE_CONFIG_PATH=`pwd`/configs docker-compose up --detach
35
+ docker run --rm inputoutput/cardano-wallet:$WALLET version
36
+ docker run --rm inputoutput/cardano-node:$NODE version
37
+ ls ~/node-db-nightly-docker
38
+
29
39
  - name: Run all tests except nighlty
30
- run: bundle exec rspec . -t ~nightly
40
+ run: rake spec
41
+
42
+ - name: Stop docker-compose
43
+ run: NODE_CONFIG_PATH=`pwd`/configs docker-compose down
31
44
  env:
32
45
  CI: true
33
46
  CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
34
47
  NETWORK: testnet
35
48
  WALLET: dev-master-shelley
36
- NODE: 1.21.1
49
+ NODE: 1.25.1
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
 
34
+ spec.add_development_dependency 'bip_mnemonic', '~> 0.0.4'
35
+ spec.add_development_dependency 'codecov', '0.2.8'
32
36
  spec.add_development_dependency 'rake', '~> 12.3'
33
37
  spec.add_development_dependency 'rspec', '~> 3.7'
34
- spec.add_development_dependency 'bip_mnemonic', '~> 0.0.4'
35
- spec.add_development_dependency 'codecov', '~> 0.2.8'
38
+ spec.add_development_dependency 'rubocop', '~> 1.11'
36
39
  spec.add_development_dependency 'simplecov'
37
-
38
40
  end
data/dev CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  NETWORK=testnet \
4
4
  WALLET=dev-master-shelley \
5
- NODE=1.20.0 \
5
+ NODE=1.24.2 \
6
6
  NODE_CONFIG_PATH=`pwd`/spec/testnet \
7
7
  docker-compose -f docker-compose-shelley.yml \
8
8
  $1 $2 $3 $4
@@ -4,7 +4,7 @@ services:
4
4
  cardano-node:
5
5
  image: inputoutput/cardano-node:${NODE}
6
6
  volumes:
7
- - node-db:/data
7
+ - ~/node-db-nightly-docker:/data
8
8
  - node-ipc:/ipc
9
9
  - ${NODE_CONFIG_PATH}:/config
10
10
  command: run --socket-path /ipc/node.socket --config /config/${NETWORK}-config.json --topology /config/${NETWORK}-topology.json --database-path /data
@@ -22,6 +22,5 @@ services:
22
22
  restart: on-failure
23
23
 
24
24
  volumes:
25
- node-db:
26
25
  wallet-shelley-db:
27
26
  node-ipc:
@@ -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
@@ -39,19 +40,35 @@ module CardanoWallet
39
40
  def migrations
40
41
  Migrations.new @opt
41
42
  end
43
+
44
+ # API for Assets
45
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Assets
46
+ def assets
47
+ Assets.new @opt
48
+ end
49
+ end
50
+
51
+ ##
52
+ # Init for Byron assets APIs
53
+ class Assets < Base
54
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listByronAssets
55
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronAsset
56
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronAssetDefault
57
+ def get(wid, policy_id = nil, asset_name = nil)
58
+ ep = "/byron-wallets/#{wid}/assets"
59
+ ep += "/#{policy_id}" if policy_id
60
+ ep += "/#{asset_name}" if asset_name
61
+ self.class.get(ep)
62
+ end
42
63
  end
43
64
 
44
65
  # Byron wallets
45
66
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Wallets
46
67
  class Wallets < Base
47
- def initialize opt
48
- super
49
- end
50
-
51
68
  # List Byron wallets
52
69
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listByronWallets
53
70
  def list
54
- self.class.get("/byron-wallets")
71
+ self.class.get('/byron-wallets')
55
72
  end
56
73
 
57
74
  # Get Byron wallet details
@@ -67,14 +84,13 @@ module CardanoWallet
67
84
  # create({style: "random",
68
85
  # name: "Random Wallet from mnemonic_sentence",
69
86
  # passphrase: "Secure Passphrase",
70
- # mnemonic_sentence: %w[arctic decade pink easy jar index base bright vast ocean hard pizza],
87
+ # mnemonic_sentence: %w[arctic decade pizza ...],
71
88
  # })
72
89
  def create(params)
73
90
  Utils.verify_param_is_hash!(params)
74
- self.class.post( "/byron-wallets",
75
- :body => params.to_json,
76
- :headers => { 'Content-Type' => 'application/json' }
77
- )
91
+ self.class.post('/byron-wallets',
92
+ body: params.to_json,
93
+ headers: { 'Content-Type' => 'application/json' })
78
94
  end
79
95
 
80
96
  # Delete Byron wallet
@@ -91,9 +107,8 @@ module CardanoWallet
91
107
  def update_metadata(wid, params)
92
108
  Utils.verify_param_is_hash!(params)
93
109
  self.class.put("/byron-wallets/#{wid}",
94
- :body => params.to_json,
95
- :headers => { 'Content-Type' => 'application/json' }
96
- )
110
+ body: params.to_json,
111
+ headers: { 'Content-Type' => 'application/json' })
97
112
  end
98
113
 
99
114
  # See Byron wallet's utxo distribution
@@ -110,27 +125,22 @@ module CardanoWallet
110
125
  def update_passphrase(wid, params)
111
126
  Utils.verify_param_is_hash!(params)
112
127
  self.class.put("/byron-wallets/#{wid}/passphrase",
113
- :body => params.to_json,
114
- :headers => { 'Content-Type' => 'application/json' }
115
- )
128
+ body: params.to_json,
129
+ headers: { 'Content-Type' => 'application/json' })
116
130
  end
117
131
  end
118
132
 
119
133
  # Byron addresses
120
134
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Addresses
121
135
  class Addresses < Base
122
- def initialize opt
123
- super
124
- end
125
-
126
136
  # List Byron addresses.
127
137
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listByronAddresses
128
138
  #
129
139
  # @example
130
140
  # list(wid, {state: "used"})
131
- def list(wid, q = {})
132
- q.empty? ? query = '' : query = Utils.to_query(q)
133
- 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}")
134
144
  end
135
145
 
136
146
  # Create address for Byron random wallet.
@@ -144,10 +154,9 @@ module CardanoWallet
144
154
  # create(wid, {passphrase: "Secure Passphrase"})
145
155
  def create(wid, params)
146
156
  Utils.verify_param_is_hash!(params)
147
- self.class.post( "/byron-wallets/#{wid}/addresses",
148
- :body => params.to_json,
149
- :headers => { 'Content-Type' => 'application/json' }
150
- )
157
+ self.class.post("/byron-wallets/#{wid}/addresses",
158
+ body: params.to_json,
159
+ headers: { 'Content-Type' => 'application/json' })
151
160
  end
152
161
 
153
162
  # Import address to Byron wallet.
@@ -164,39 +173,38 @@ module CardanoWallet
164
173
  # @param addresses [Array] array of addresses
165
174
  def bulk_import(wid, addresses)
166
175
  self.class.put("/byron-wallets/#{wid}/addresses",
167
- :body => { :addresses => addresses
168
- }.to_json,
169
- :headers => { 'Content-Type' => 'application/json' } )
176
+ body: { addresses: addresses }.to_json,
177
+ headers: { 'Content-Type' => 'application/json' })
170
178
  end
171
179
  end
172
180
 
173
181
  # API for CoinSelections
174
182
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Coin-Selections
175
183
  class CoinSelections < Base
176
- def initialize opt
177
- super
178
- end
179
-
180
184
  # Show random coin selection for particular payment
181
185
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/byronSelectCoins
182
186
  #
183
187
  # @example
184
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 } ] } ])
185
192
  def random(wid, payments)
186
- 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
187
199
  self.class.post("/byron-wallets/#{wid}/coin-selections/random",
188
- :body => {:payments => payments_formatted}.to_json,
189
- :headers => { 'Content-Type' => 'application/json' })
200
+ body: { payments: payments_formatted }.to_json,
201
+ headers: { 'Content-Type' => 'application/json' })
190
202
  end
191
203
  end
192
204
 
193
205
  # Byron transactions
194
206
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postByronTransactionFee
195
207
  class Transactions < Base
196
- def initialize opt
197
- super
198
- end
199
-
200
208
  # Get tx by id
201
209
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronTransaction
202
210
  def get(wid, tx_id)
@@ -208,9 +216,9 @@ module CardanoWallet
208
216
  #
209
217
  # @example
210
218
  # list(wid, {start: "2012-09-25T10:15:00Z", order: "descending"})
211
- def list(wid, q = {})
212
- q.empty? ? query = '' : query = Utils.to_query(q)
213
- 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}")
214
222
  end
215
223
 
216
224
  # Create a transaction from the Byron wallet.
@@ -221,13 +229,21 @@ module CardanoWallet
221
229
  #
222
230
  # @example
223
231
  # create(wid, passphrase, [{addr1: 1000000}, {addr2: 1000000}])
232
+ # create(wid, passphrase, [{ "address": "addr1..",
233
+ # "amount": { "quantity": 42000000, "unit": "lovelace" },
234
+ # "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ])
235
+
224
236
  def create(wid, passphrase, payments)
225
- payments_formatted = Utils.format_payments(payments)
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
226
243
  self.class.post("/byron-wallets/#{wid}/transactions",
227
- :body => { :payments => payments_formatted,
228
- :passphrase => passphrase
229
- }.to_json,
230
- :headers => { 'Content-Type' => 'application/json' } )
244
+ body: { payments: payments_formatted,
245
+ passphrase: passphrase }.to_json,
246
+ headers: { 'Content-Type' => 'application/json' })
231
247
  end
232
248
 
233
249
  # Estimate fees for transaction
@@ -235,11 +251,19 @@ module CardanoWallet
235
251
  #
236
252
  # @example
237
253
  # payment_fees(wid, [{addr1: 1000000}, {addr2: 1000000}])
254
+ # payment_fees(wid, [{ "address": "addr1..",
255
+ # "amount": { "quantity": 42000000, "unit": "lovelace" },
256
+ # "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ])
238
257
  def payment_fees(wid, payments)
239
- payments_formatted = Utils.format_payments(payments)
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
240
264
  self.class.post("/byron-wallets/#{wid}/payment-fees",
241
- :body => { :payments => payments_formatted }.to_json,
242
- :headers => { 'Content-Type' => 'application/json' } )
265
+ body: { payments: payments_formatted }.to_json,
266
+ headers: { 'Content-Type' => 'application/json' })
243
267
  end
244
268
 
245
269
  # Forget a transaction.
@@ -252,10 +276,6 @@ module CardanoWallet
252
276
  # Byron migrations
253
277
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Byron-Migrations
254
278
  class Migrations < Base
255
- def initialize opt
256
- super
257
- end
258
-
259
279
  # Calculate migration cost
260
280
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getByronWalletMigrationInfo
261
281
  def cost(wid)
@@ -269,12 +289,10 @@ module CardanoWallet
269
289
  # @param [Array] array of addresses
270
290
  def migrate(wid, passphrase, addresses)
271
291
  self.class.post("/byron-wallets/#{wid}/migrations",
272
- :body => { :addresses => addresses,
273
- :passphrase => passphrase
274
- }.to_json,
275
- :headers => { 'Content-Type' => 'application/json' } )
292
+ body: { addresses: addresses,
293
+ passphrase: passphrase }.to_json,
294
+ headers: { 'Content-Type' => 'application/json' })
276
295
  end
277
-
278
296
  end
279
297
  end
280
298
  end