cardano_wallet 0.3.2 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +14 -15
- data/.gitignore +4 -0
- data/.rubocop.yml +24 -0
- data/Gemfile +3 -1
- data/README.md +9 -25
- data/Rakefile +30 -10
- data/bin/console +4 -3
- data/bin/run_all_tests +6 -0
- data/cardano_wallet.gemspec +20 -18
- data/{docker-compose-shelley.yml → docker-compose.yml} +1 -1
- data/lib/cardano_wallet.rb +12 -7
- data/lib/cardano_wallet/base.rb +13 -6
- data/lib/cardano_wallet/byron.rb +68 -90
- data/lib/cardano_wallet/misc.rb +25 -44
- data/lib/cardano_wallet/shared.rb +116 -0
- data/lib/cardano_wallet/shelley.rb +89 -119
- data/lib/cardano_wallet/utils.rb +14 -10
- data/lib/cardano_wallet/version.rb +3 -1
- metadata +36 -20
- data/.github/workflows/nightly.yml +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43840673c63b02899e8bcdb4c28e088bb5a7a154dd322f59d1ab250f318d7a7c
|
4
|
+
data.tar.gz: 493f143440c24e484add14976c3ec92a70b72f15022f22166d8596e23c254c4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9076c4d8e5861439b5af3f7f981ccf633bfc3b8fb5b4a62596228ece4d2d13a3c3df9f8dfad6502c8735525fb0b07032e5d552c5242ca99b5ea39c704c2b19b8
|
7
|
+
data.tar.gz: 70629fd858e3a46d159a547c3735ab470a6797cbcf68645fb131646608d069fee41227627d78491872e03191be068cd9e00277845bbe2c433e4de37e0bceafc9
|
data/.github/workflows/tests.yml
CHANGED
@@ -15,33 +15,32 @@ jobs:
|
|
15
15
|
steps:
|
16
16
|
- uses: actions/checkout@v2
|
17
17
|
|
18
|
-
- name:
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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`/
|
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:
|
40
|
+
run: rake spec
|
42
41
|
|
43
42
|
- name: Stop docker-compose
|
44
|
-
run: NODE_CONFIG_PATH=`pwd`/
|
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
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
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
|
-
|
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
|
-
|
28
|
+
In Gemfile:
|
25
29
|
|
26
30
|
```ruby
|
27
31
|
gem 'cardano_wallet'
|
28
32
|
```
|
29
33
|
|
30
|
-
|
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
|
-
|
2
|
-
|
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 :
|
10
|
+
task default: :spec
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
4
|
-
require
|
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
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/bin/run_all_tests
ADDED
data/cardano_wallet.gemspec
CHANGED
@@ -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 =
|
6
|
+
spec.name = 'cardano_wallet'
|
5
7
|
spec.version = CardanoWallet::VERSION
|
6
|
-
spec.authors = [
|
7
|
-
spec.email = [
|
8
|
+
spec.authors = ['Piotr Stachyra']
|
9
|
+
spec.email = ['piotr.stachyra@gmail.com']
|
8
10
|
|
9
|
-
spec.summary =
|
10
|
-
spec.description =
|
11
|
-
spec.homepage =
|
12
|
-
spec.license =
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
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[
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
|
16
18
|
|
17
|
-
spec.metadata[
|
18
|
-
spec.metadata[
|
19
|
-
spec.metadata[
|
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
|
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 =
|
28
|
+
spec.bindir = 'exe'
|
27
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = [
|
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
|
@@ -18,7 +18,7 @@ services:
|
|
18
18
|
- ${NODE_CONFIG_PATH}:/config
|
19
19
|
ports:
|
20
20
|
- 8090:8090
|
21
|
-
command: serve --testnet /config/${NETWORK}-byron-genesis.json --node-socket /ipc/node.socket --database /wallet-db --listen-address 0.0.0.0
|
21
|
+
command: serve --testnet /config/${NETWORK}-byron-genesis.json --node-socket /ipc/node.socket --database /wallet-db --listen-address 0.0.0.0
|
22
22
|
restart: on-failure
|
23
23
|
|
24
24
|
volumes:
|
data/lib/cardano_wallet.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
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)
|
data/lib/cardano_wallet/base.rb
CHANGED
@@ -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,
|
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
|
-
|
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
|
26
|
+
self.class.ssl_ca_file(File.read(ENV['SSL_CERT_FILE']))
|
25
27
|
end
|
26
|
-
self.class.pem(File.read
|
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
|
data/lib/cardano_wallet/byron.rb
CHANGED
@@ -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(
|
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
|
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(
|
98
|
-
|
99
|
-
|
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
|
-
:
|
118
|
-
:
|
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
|
-
:
|
137
|
-
:
|
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,
|
155
|
-
|
156
|
-
self.class.get("/byron-wallets/#{wid}/addresses#{
|
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(
|
171
|
-
|
172
|
-
|
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
|
-
|
191
|
-
|
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..",
|
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.
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
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
|
-
:
|
218
|
-
:
|
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,
|
241
|
-
|
242
|
-
self.class.get("/byron-wallets/#{wid}/transactions#{
|
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..",
|
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.
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
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
|
-
|
264
|
-
|
265
|
-
|
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..",
|
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.
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
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
|
-
|
284
|
-
|
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
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
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
|
-
|
315
|
-
|
316
|
-
|
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
|