cardano_wallet 0.3.0 → 0.3.5
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 +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} +0 -0
- data/lib/cardano_wallet.rb +12 -7
- data/lib/cardano_wallet/base.rb +13 -6
- data/lib/cardano_wallet/byron.rb +71 -85
- data/lib/cardano_wallet/misc.rb +25 -44
- data/lib/cardano_wallet/shared.rb +76 -0
- data/lib/cardano_wallet/shelley.rb +94 -112
- 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
data/lib/cardano_wallet/misc.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module CardanoWallet
|
4
|
+
##
|
5
|
+
# misc
|
2
6
|
module Misc
|
3
|
-
|
4
7
|
def self.new(opt)
|
5
8
|
Init.new opt
|
6
9
|
end
|
7
10
|
|
11
|
+
##
|
12
|
+
# Base Class for Misc API
|
8
13
|
class Init < Base
|
9
|
-
def initialize opt
|
10
|
-
super
|
11
|
-
end
|
12
|
-
|
13
14
|
# Call API for Network
|
14
15
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Network
|
15
16
|
def network
|
@@ -30,72 +31,57 @@ module CardanoWallet
|
|
30
31
|
def settings
|
31
32
|
Settings.new @opt
|
32
33
|
end
|
33
|
-
|
34
34
|
end
|
35
35
|
|
36
36
|
# API for Network
|
37
37
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Settings
|
38
38
|
class Settings < Base
|
39
|
-
def initialize opt
|
40
|
-
super
|
41
|
-
end
|
42
|
-
|
43
39
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getSettings
|
44
40
|
def get
|
45
|
-
self.class.get(
|
41
|
+
self.class.get('/settings')
|
46
42
|
end
|
47
43
|
|
48
44
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/putSettings
|
49
45
|
def update(params)
|
50
46
|
CardanoWallet::Utils.verify_param_is_hash!(params)
|
51
|
-
self.class.put(
|
52
|
-
:
|
53
|
-
:
|
54
|
-
)
|
47
|
+
self.class.put('/settings',
|
48
|
+
body: { 'settings' => params }.to_json,
|
49
|
+
headers: { 'Content-Type' => 'application/json' })
|
55
50
|
end
|
56
51
|
end
|
57
52
|
|
58
53
|
# API for Network
|
59
54
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Network
|
60
55
|
class Network < Base
|
61
|
-
def initialize opt
|
62
|
-
super
|
63
|
-
end
|
64
|
-
|
65
56
|
# Get network information
|
66
57
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getNetworkInformation
|
67
58
|
def information
|
68
|
-
self.class.get(
|
59
|
+
self.class.get('/network/information')
|
69
60
|
end
|
70
61
|
|
71
62
|
# Check network clock
|
72
63
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getNetworkClock
|
73
64
|
def clock
|
74
|
-
self.class.get(
|
65
|
+
self.class.get('/network/clock')
|
75
66
|
end
|
76
67
|
|
77
68
|
# Check network parameters
|
78
69
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getNetworkParameters
|
79
70
|
def parameters
|
80
|
-
self.class.get(
|
71
|
+
self.class.get('/network/parameters')
|
81
72
|
end
|
82
|
-
|
83
73
|
end
|
84
74
|
|
85
75
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Utils
|
86
76
|
class Utils < Base
|
87
|
-
def initialize opt
|
88
|
-
super
|
89
|
-
end
|
90
|
-
|
91
77
|
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/signMetadata
|
92
78
|
def sign_metadata(wid, role, index, pass, metadata)
|
93
79
|
payload = { passphrase: pass }
|
94
80
|
payload[:metadata] = metadata if metadata
|
95
81
|
|
96
82
|
self.class.post("/wallets/#{wid}/signatures/#{role}/#{index}",
|
97
|
-
:
|
98
|
-
:
|
83
|
+
body: payload.to_json,
|
84
|
+
headers: { 'Content-Type' => 'application/json' })
|
99
85
|
end
|
100
86
|
|
101
87
|
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/getWalletKey
|
@@ -111,10 +97,10 @@ module CardanoWallet
|
|
111
97
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postAnyAddress
|
112
98
|
def post_address(payload)
|
113
99
|
CardanoWallet::Utils.verify_param_is_hash!(payload)
|
114
|
-
self.class.post(
|
115
|
-
:
|
116
|
-
:
|
117
|
-
|
100
|
+
self.class.post('/addresses',
|
101
|
+
body: payload.to_json,
|
102
|
+
headers: { 'Content-Type' => 'application/json',
|
103
|
+
'Accept' => 'application/json' })
|
118
104
|
end
|
119
105
|
|
120
106
|
# Current SMASH health
|
@@ -122,26 +108,21 @@ module CardanoWallet
|
|
122
108
|
#
|
123
109
|
# @example
|
124
110
|
# smash_health({url: "https://smash.cardano-mainnet.iohk.io/"})
|
125
|
-
def smash_health(
|
126
|
-
|
127
|
-
self.class.get("/smash/health#{
|
111
|
+
def smash_health(query = {})
|
112
|
+
query_formatted = query.empty? ? '' : CardanoWallet::Utils.to_query(query)
|
113
|
+
self.class.get("/smash/health#{query_formatted}")
|
128
114
|
end
|
129
|
-
|
130
115
|
end
|
131
116
|
|
132
117
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Proxy
|
133
118
|
class Proxy < Base
|
134
|
-
def initialize opt
|
135
|
-
super
|
136
|
-
end
|
137
|
-
|
138
119
|
# Submit a transaction that was created and signed outside of cardano-wallet.
|
139
120
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postExternalTransaction
|
140
121
|
# @param binary_blob [String] Signed transaction message binary blob.
|
141
122
|
def submit_external_transaction(binary_blob)
|
142
|
-
self.class.post(
|
143
|
-
:
|
144
|
-
:
|
123
|
+
self.class.post('/proxy/transactions',
|
124
|
+
body: binary_blob,
|
125
|
+
headers: { 'Content-Type' => 'application/octet-stream' })
|
145
126
|
end
|
146
127
|
end
|
147
128
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CardanoWallet
|
4
|
+
# Init API for Shelley Shared wallets
|
5
|
+
module Shared
|
6
|
+
def self.new(opt)
|
7
|
+
Init.new opt
|
8
|
+
end
|
9
|
+
|
10
|
+
##
|
11
|
+
# Base class for Shelley Shared Wallets API
|
12
|
+
class Init < Base
|
13
|
+
# Call API for Wallets
|
14
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Shared-Wallets
|
15
|
+
def wallets
|
16
|
+
Wallets.new @opt
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# API for Wallets
|
21
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Shared-Wallets
|
22
|
+
class Wallets < Base
|
23
|
+
# List all wallets
|
24
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listWallets
|
25
|
+
# def list
|
26
|
+
# self.class.get('/shared-wallets')
|
27
|
+
# end
|
28
|
+
|
29
|
+
# Get wallet details
|
30
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getSharedWallet
|
31
|
+
def get(wid)
|
32
|
+
self.class.get("/shared-wallets/#{wid}")
|
33
|
+
end
|
34
|
+
|
35
|
+
# Create a wallet based on the params.
|
36
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postSharedWallet
|
37
|
+
#
|
38
|
+
# @example Create wallet from mnemonic sentence
|
39
|
+
# create({name: "Wallet from mnemonic_sentence",
|
40
|
+
# passphrase: "Secure Passphrase",
|
41
|
+
# mnemonic_sentence: %w[story egg fun ... ],
|
42
|
+
# account_index: "1852H",
|
43
|
+
# payment_script_template: {...},
|
44
|
+
# ...
|
45
|
+
# })
|
46
|
+
def create(params)
|
47
|
+
Utils.verify_param_is_hash!(params)
|
48
|
+
self.class.post('/shared-wallets',
|
49
|
+
body: params.to_json,
|
50
|
+
headers: { 'Content-Type' => 'application/json' })
|
51
|
+
end
|
52
|
+
|
53
|
+
# Delete wallet
|
54
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/deleteSharedWallet
|
55
|
+
def delete(wid)
|
56
|
+
self.class.delete("/shared-wallets/#{wid}")
|
57
|
+
end
|
58
|
+
|
59
|
+
# Update payment script
|
60
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/patchSharedWalletInPayment
|
61
|
+
def update_payment_script(wid, cosigner, acc_pub_key)
|
62
|
+
self.class.patch("/shared-wallets/#{wid}/payment-script-template",
|
63
|
+
body: { cosigner => acc_pub_key }.to_json,
|
64
|
+
headers: { 'Content-Type' => 'application/json' })
|
65
|
+
end
|
66
|
+
|
67
|
+
# Update delegation script
|
68
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/patchSharedWalletInDelegation
|
69
|
+
def update_delegation_script(wid, cosigner, acc_pub_key)
|
70
|
+
self.class.patch("/shared-wallets/#{wid}/delegation-script-template",
|
71
|
+
body: { cosigner => acc_pub_key }.to_json,
|
72
|
+
headers: { 'Content-Type' => 'application/json' })
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -1,17 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module CardanoWallet
|
2
4
|
# Init API for Shelley
|
3
5
|
module Shelley
|
4
|
-
|
5
6
|
def self.new(opt)
|
6
7
|
Init.new opt
|
7
8
|
end
|
8
9
|
|
10
|
+
##
|
11
|
+
# Base class for Shelley API
|
9
12
|
class Init < Base
|
10
|
-
|
11
|
-
def initialize opt
|
12
|
-
super
|
13
|
-
end
|
14
|
-
|
15
13
|
# Call API for Wallets
|
16
14
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Wallets
|
17
15
|
def wallets
|
@@ -59,14 +57,11 @@ module CardanoWallet
|
|
59
57
|
def assets
|
60
58
|
Assets.new @opt
|
61
59
|
end
|
62
|
-
|
63
60
|
end
|
64
61
|
|
62
|
+
##
|
63
|
+
# Base class for Shelley Assets API
|
65
64
|
class Assets < Base
|
66
|
-
def initialize opt
|
67
|
-
super
|
68
|
-
end
|
69
|
-
|
70
65
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listAssets
|
71
66
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getAsset
|
72
67
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getAssetDefault
|
@@ -76,23 +71,20 @@ module CardanoWallet
|
|
76
71
|
ep += "/#{asset_name}" if asset_name
|
77
72
|
self.class.get(ep)
|
78
73
|
end
|
79
|
-
|
80
74
|
end
|
81
75
|
|
76
|
+
##
|
77
|
+
# Base class for Shelley Keys API
|
82
78
|
class Keys < Base
|
83
|
-
def initialize opt
|
84
|
-
super
|
85
|
-
end
|
86
|
-
|
87
79
|
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/signMetadata
|
88
80
|
def sign_metadata(wid, role, index, pass, metadata)
|
89
81
|
payload = { passphrase: pass }
|
90
82
|
payload[:metadata] = metadata if metadata
|
91
83
|
|
92
84
|
self.class.post("/wallets/#{wid}/signatures/#{role}/#{index}",
|
93
|
-
:
|
94
|
-
:
|
95
|
-
|
85
|
+
body: payload.to_json,
|
86
|
+
headers: { 'Content-Type' => 'application/json',
|
87
|
+
'Accept' => 'application/octet-stream' })
|
96
88
|
end
|
97
89
|
|
98
90
|
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/getWalletKey
|
@@ -104,24 +96,18 @@ module CardanoWallet
|
|
104
96
|
def create_acc_public_key(wid, index, pass, extended)
|
105
97
|
payload = { passphrase: pass, extended: extended }
|
106
98
|
self.class.post("/wallets/#{wid}/keys/#{index}",
|
107
|
-
:
|
108
|
-
:
|
109
|
-
)
|
99
|
+
body: payload.to_json,
|
100
|
+
headers: { 'Content-Type' => 'application/json' })
|
110
101
|
end
|
111
|
-
|
112
102
|
end
|
113
103
|
|
114
104
|
# API for Wallets
|
115
105
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Wallets
|
116
106
|
class Wallets < Base
|
117
|
-
def initialize opt
|
118
|
-
super
|
119
|
-
end
|
120
|
-
|
121
107
|
# List all wallets
|
122
108
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listWallets
|
123
109
|
def list
|
124
|
-
self.class.get(
|
110
|
+
self.class.get('/wallets')
|
125
111
|
end
|
126
112
|
|
127
113
|
# Get wallet details
|
@@ -136,19 +122,18 @@ module CardanoWallet
|
|
136
122
|
# @example Create wallet from mnemonic sentence
|
137
123
|
# create({name: "Wallet from mnemonic_sentence",
|
138
124
|
# passphrase: "Secure Passphrase",
|
139
|
-
# mnemonic_sentence: %w[story egg fun
|
125
|
+
# mnemonic_sentence: %w[story egg fun ... ],
|
140
126
|
# })
|
141
127
|
# @example Create wallet from pub key
|
142
128
|
# create({name: "Wallet from pub key",
|
143
|
-
# account_public_key: "
|
129
|
+
# account_public_key: "b47546e...",
|
144
130
|
# address_pool_gap: 20,
|
145
131
|
# })
|
146
132
|
def create(params)
|
147
133
|
Utils.verify_param_is_hash!(params)
|
148
|
-
self.class.post(
|
149
|
-
|
150
|
-
|
151
|
-
)
|
134
|
+
self.class.post('/wallets',
|
135
|
+
body: params.to_json,
|
136
|
+
headers: { 'Content-Type' => 'application/json' })
|
152
137
|
end
|
153
138
|
|
154
139
|
# Delete wallet
|
@@ -165,9 +150,8 @@ module CardanoWallet
|
|
165
150
|
def update_metadata(wid, params)
|
166
151
|
Utils.verify_param_is_hash!(params)
|
167
152
|
self.class.put("/wallets/#{wid}",
|
168
|
-
:
|
169
|
-
:
|
170
|
-
)
|
153
|
+
body: params.to_json,
|
154
|
+
headers: { 'Content-Type' => 'application/json' })
|
171
155
|
end
|
172
156
|
|
173
157
|
# See wallet's utxo distribution
|
@@ -184,47 +168,50 @@ module CardanoWallet
|
|
184
168
|
def update_passphrase(wid, params)
|
185
169
|
Utils.verify_param_is_hash!(params)
|
186
170
|
self.class.put("/wallets/#{wid}/passphrase",
|
187
|
-
:
|
188
|
-
:
|
189
|
-
)
|
171
|
+
body: params.to_json,
|
172
|
+
headers: { 'Content-Type' => 'application/json' })
|
190
173
|
end
|
191
174
|
end
|
192
175
|
|
193
176
|
# API for Addresses
|
194
177
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Addresses
|
195
178
|
class Addresses < Base
|
196
|
-
def initialize opt
|
197
|
-
super
|
198
|
-
end
|
199
|
-
|
200
179
|
# List addresses
|
201
180
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listAddresses
|
202
181
|
#
|
203
182
|
# @example
|
204
183
|
# list(wid, {state: "used"})
|
205
|
-
def list(wid,
|
206
|
-
|
207
|
-
self.class.get("/wallets/#{wid}/addresses#{
|
184
|
+
def list(wid, query = {})
|
185
|
+
query_formatted = query.empty? ? '' : Utils.to_query(query)
|
186
|
+
self.class.get("/wallets/#{wid}/addresses#{query_formatted}")
|
208
187
|
end
|
209
188
|
end
|
210
189
|
|
211
190
|
# API for CoinSelections
|
212
191
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Coin-Selections
|
213
192
|
class CoinSelections < Base
|
214
|
-
def initialize opt
|
215
|
-
super
|
216
|
-
end
|
217
|
-
|
218
193
|
# Show random coin selection for particular payment
|
219
194
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/selectCoins
|
220
195
|
#
|
221
196
|
# @example
|
222
197
|
# random(wid, [{addr1: 1000000}, {addr2: 1000000}])
|
223
|
-
|
224
|
-
|
198
|
+
# random(wid, [{ "address": "addr1..",
|
199
|
+
# "amount": { "quantity": 42000000, "unit": "lovelace" },
|
200
|
+
# "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ])
|
201
|
+
def random(wid, payments, withdrawal = nil, metadata = nil)
|
202
|
+
Utils.verify_param_is_array!(payments)
|
203
|
+
payments_formatted = if payments.any? { |p| p.key?(:address) || p.key?('address') }
|
204
|
+
payments
|
205
|
+
else
|
206
|
+
Utils.format_payments(payments)
|
207
|
+
end
|
208
|
+
payload = { payments: payments_formatted }
|
209
|
+
payload[:withdrawal] = withdrawal if withdrawal
|
210
|
+
payload[:metadata] = metadata if metadata
|
211
|
+
|
225
212
|
self.class.post("/wallets/#{wid}/coin-selections/random",
|
226
|
-
|
227
|
-
:
|
213
|
+
body: payload.to_json,
|
214
|
+
headers: { 'Content-Type' => 'application/json' })
|
228
215
|
end
|
229
216
|
|
230
217
|
# Coin selection -> Delegation action
|
@@ -236,18 +223,14 @@ module CardanoWallet
|
|
236
223
|
def random_deleg(wid, deleg_action)
|
237
224
|
Utils.verify_param_is_hash!(deleg_action)
|
238
225
|
self.class.post("/wallets/#{wid}/coin-selections/random",
|
239
|
-
:
|
240
|
-
:
|
226
|
+
body: { delegation_action: deleg_action }.to_json,
|
227
|
+
headers: { 'Content-Type' => 'application/json' })
|
241
228
|
end
|
242
229
|
end
|
243
230
|
|
244
231
|
# API for Transactions
|
245
232
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Transactions
|
246
233
|
class Transactions < Base
|
247
|
-
def initialize opt
|
248
|
-
super
|
249
|
-
end
|
250
|
-
|
251
234
|
# Get tx by id
|
252
235
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getTransaction
|
253
236
|
def get(wid, tx_id)
|
@@ -259,9 +242,9 @@ module CardanoWallet
|
|
259
242
|
#
|
260
243
|
# @example
|
261
244
|
# list(wid, {start: "2012-09-25T10:15:00Z", order: "descending"})
|
262
|
-
def list(wid,
|
263
|
-
|
264
|
-
self.class.get("/wallets/#{wid}/transactions#{
|
245
|
+
def list(wid, query = {})
|
246
|
+
query_formatted = query.empty? ? '' : Utils.to_query(query)
|
247
|
+
self.class.get("/wallets/#{wid}/transactions#{query_formatted}")
|
265
248
|
end
|
266
249
|
|
267
250
|
# Create a transaction from the wallet
|
@@ -275,23 +258,26 @@ module CardanoWallet
|
|
275
258
|
#
|
276
259
|
# @example
|
277
260
|
# create(wid, passphrase, [{addr1: 1000000}, {addr2: 1000000}], 'self', {"1": "abc"}, ttl = 10)
|
278
|
-
# create(wid, passphrase, [{ "address": "addr1..",
|
261
|
+
# create(wid, passphrase, [{ "address": "addr1..",
|
262
|
+
# "amount": { "quantity": 42000000, "unit": "lovelace" },
|
263
|
+
# "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ],
|
264
|
+
# 'self', {"1": "abc"}, ttl = 10)
|
279
265
|
def create(wid, passphrase, payments, withdrawal = nil, metadata = nil, ttl = nil)
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
266
|
+
Utils.verify_param_is_array!(payments)
|
267
|
+
payments_formatted = if payments.any? { |p| p.key?(:address) || p.key?('address') }
|
268
|
+
payments
|
269
|
+
else
|
270
|
+
Utils.format_payments(payments)
|
271
|
+
end
|
272
|
+
payload = { payments: payments_formatted,
|
273
|
+
passphrase: passphrase }
|
288
274
|
payload[:withdrawal] = withdrawal if withdrawal
|
289
275
|
payload[:metadata] = metadata if metadata
|
290
|
-
payload[:time_to_live] = { quantity: ttl, unit:
|
276
|
+
payload[:time_to_live] = { quantity: ttl, unit: 'second' } if ttl
|
291
277
|
|
292
278
|
self.class.post("/wallets/#{wid}/transactions",
|
293
|
-
|
294
|
-
|
279
|
+
body: payload.to_json,
|
280
|
+
headers: { 'Content-Type' => 'application/json' })
|
295
281
|
end
|
296
282
|
|
297
283
|
# Estimate fees for transaction
|
@@ -299,23 +285,27 @@ module CardanoWallet
|
|
299
285
|
#
|
300
286
|
# @example
|
301
287
|
# payment_fees(wid, [{addr1: 1000000}, {addr2: 1000000}], {"1": "abc"}, ttl = 10)
|
302
|
-
# payment_fees(wid, [{ "address": "addr1..",
|
288
|
+
# payment_fees(wid, [{ "address": "addr1..",
|
289
|
+
# "amount": { "quantity": 42000000, "unit": "lovelace" },
|
290
|
+
# "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ],
|
291
|
+
# {"1": "abc"}, ttl = 10)
|
303
292
|
def payment_fees(wid, payments, withdrawal = nil, metadata = nil, ttl = nil)
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
293
|
+
Utils.verify_param_is_array!(payments)
|
294
|
+
payments_formatted = if payments.any? { |p| p.key?(:address) || p.key?('address') }
|
295
|
+
payments
|
296
|
+
else
|
297
|
+
Utils.format_payments(payments)
|
298
|
+
end
|
309
299
|
|
310
|
-
payload = { :
|
300
|
+
payload = { payments: payments_formatted }
|
311
301
|
|
312
302
|
payload[:withdrawal] = withdrawal if withdrawal
|
313
303
|
payload[:metadata] = metadata if metadata
|
314
|
-
payload[:time_to_live] = { quantity: ttl, unit:
|
304
|
+
payload[:time_to_live] = { quantity: ttl, unit: 'second' } if ttl
|
315
305
|
|
316
306
|
self.class.post("/wallets/#{wid}/payment-fees",
|
317
|
-
|
318
|
-
|
307
|
+
body: payload.to_json,
|
308
|
+
headers: { 'Content-Type' => 'application/json' })
|
319
309
|
end
|
320
310
|
|
321
311
|
# Forget a transaction
|
@@ -328,10 +318,6 @@ module CardanoWallet
|
|
328
318
|
# API for StakePools
|
329
319
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Stake-Pools
|
330
320
|
class StakePools < Base
|
331
|
-
def initialize opt
|
332
|
-
super
|
333
|
-
end
|
334
|
-
|
335
321
|
# Stake pools maintenance actions
|
336
322
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postMaintenanceAction
|
337
323
|
#
|
@@ -339,21 +325,21 @@ module CardanoWallet
|
|
339
325
|
# maintenance_action({ "maintenance_action": "gc_stake_pools" })
|
340
326
|
def trigger_maintenance_actions(action = {})
|
341
327
|
Utils.verify_param_is_hash!(action)
|
342
|
-
self.class.post(
|
343
|
-
|
344
|
-
|
328
|
+
self.class.post('/stake-pools/maintenance-actions',
|
329
|
+
body: action.to_json,
|
330
|
+
headers: { 'Content-Type' => 'application/json' })
|
345
331
|
end
|
346
332
|
|
347
333
|
# Metdata GC Status
|
348
334
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getMaintenanceActions
|
349
335
|
def view_maintenance_actions
|
350
|
-
self.class.get(
|
336
|
+
self.class.get('/stake-pools/maintenance-actions')
|
351
337
|
end
|
352
338
|
|
353
339
|
# List all stake pools
|
354
340
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listStakePools
|
355
341
|
def list(stake = {})
|
356
|
-
stake.empty? ?
|
342
|
+
query = stake.empty? ? '' : Utils.to_query(stake)
|
357
343
|
self.class.get("/stake-pools#{query}")
|
358
344
|
end
|
359
345
|
|
@@ -361,16 +347,16 @@ module CardanoWallet
|
|
361
347
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/joinStakePool
|
362
348
|
def join(sp_id, wid, passphrase)
|
363
349
|
self.class.put("/stake-pools/#{sp_id}/wallets/#{wid}",
|
364
|
-
|
365
|
-
|
350
|
+
body: { passphrase: passphrase }.to_json,
|
351
|
+
headers: { 'Content-Type' => 'application/json' })
|
366
352
|
end
|
367
353
|
|
368
354
|
# Quit stape pool
|
369
355
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/quitStakePool
|
370
356
|
def quit(wid, passphrase)
|
371
357
|
self.class.delete("#{@api}/stake-pools/*/wallets/#{wid}",
|
372
|
-
|
373
|
-
|
358
|
+
body: { passphrase: passphrase }.to_json,
|
359
|
+
headers: { 'Content-Type' => 'application/json' })
|
374
360
|
end
|
375
361
|
|
376
362
|
# Estimate delegation fees
|
@@ -383,14 +369,12 @@ module CardanoWallet
|
|
383
369
|
# Shelley migrations
|
384
370
|
# @see https://input-output-hk.github.io/cardano-wallet/api/#tag/Migrations
|
385
371
|
class Migrations < Base
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
def cost(wid)
|
393
|
-
self.class.get("/wallets/#{wid}/migrations")
|
372
|
+
# Get migration plan
|
373
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/createShelleyWalletMigrationPlan
|
374
|
+
def plan(wid, addresses)
|
375
|
+
self.class.post("/wallets/#{wid}/migrations/plan",
|
376
|
+
body: { addresses: addresses }.to_json,
|
377
|
+
headers: { 'Content-Type' => 'application/json' })
|
394
378
|
end
|
395
379
|
|
396
380
|
# Migrate all funds from Shelley wallet.
|
@@ -400,12 +384,10 @@ module CardanoWallet
|
|
400
384
|
# @param [Array] array of addresses
|
401
385
|
def migrate(wid, passphrase, addresses)
|
402
386
|
self.class.post("/wallets/#{wid}/migrations",
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
:headers => { 'Content-Type' => 'application/json' } )
|
387
|
+
body: { addresses: addresses,
|
388
|
+
passphrase: passphrase }.to_json,
|
389
|
+
headers: { 'Content-Type' => 'application/json' })
|
407
390
|
end
|
408
|
-
|
409
391
|
end
|
410
392
|
end
|
411
393
|
end
|