cardano_wallet 0.3.2 → 0.3.3
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} +1 -1
- data/lib/cardano_wallet.rb +12 -7
- data/lib/cardano_wallet/base.rb +13 -6
- data/lib/cardano_wallet/byron.rb +62 -86
- data/lib/cardano_wallet/misc.rb +25 -44
- data/lib/cardano_wallet/shared.rb +76 -0
- data/lib/cardano_wallet/shelley.rb +81 -113
- 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: cosigner, account_public_key: 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: cosigner, account_public_key: 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,57 +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
|
-
# random(wid, [{ "address": "addr1..",
|
198
|
+
# random(wid, [{ "address": "addr1..",
|
199
|
+
# "amount": { "quantity": 42000000, "unit": "lovelace" },
|
200
|
+
# "assets": [{"policy_id": "pid", "asset_name": "name", "quantity": 0 } ] } ])
|
224
201
|
def random(wid, payments, withdrawal = nil, metadata = nil)
|
225
202
|
Utils.verify_param_is_array!(payments)
|
226
|
-
if payments.any?{|p| p.
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
payload = { :
|
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 }
|
232
209
|
payload[:withdrawal] = withdrawal if withdrawal
|
233
210
|
payload[:metadata] = metadata if metadata
|
234
211
|
|
235
212
|
self.class.post("/wallets/#{wid}/coin-selections/random",
|
236
|
-
:
|
237
|
-
:
|
213
|
+
body: payload.to_json,
|
214
|
+
headers: { 'Content-Type' => 'application/json' })
|
238
215
|
end
|
239
216
|
|
240
217
|
# Coin selection -> Delegation action
|
@@ -246,18 +223,14 @@ module CardanoWallet
|
|
246
223
|
def random_deleg(wid, deleg_action)
|
247
224
|
Utils.verify_param_is_hash!(deleg_action)
|
248
225
|
self.class.post("/wallets/#{wid}/coin-selections/random",
|
249
|
-
:
|
250
|
-
:
|
226
|
+
body: { delegation_action: deleg_action }.to_json,
|
227
|
+
headers: { 'Content-Type' => 'application/json' })
|
251
228
|
end
|
252
229
|
end
|
253
230
|
|
254
231
|
# API for Transactions
|
255
232
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Transactions
|
256
233
|
class Transactions < Base
|
257
|
-
def initialize opt
|
258
|
-
super
|
259
|
-
end
|
260
|
-
|
261
234
|
# Get tx by id
|
262
235
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getTransaction
|
263
236
|
def get(wid, tx_id)
|
@@ -269,9 +242,9 @@ module CardanoWallet
|
|
269
242
|
#
|
270
243
|
# @example
|
271
244
|
# list(wid, {start: "2012-09-25T10:15:00Z", order: "descending"})
|
272
|
-
def list(wid,
|
273
|
-
|
274
|
-
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}")
|
275
248
|
end
|
276
249
|
|
277
250
|
# Create a transaction from the wallet
|
@@ -285,24 +258,26 @@ module CardanoWallet
|
|
285
258
|
#
|
286
259
|
# @example
|
287
260
|
# create(wid, passphrase, [{addr1: 1000000}, {addr2: 1000000}], 'self', {"1": "abc"}, ttl = 10)
|
288
|
-
# 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)
|
289
265
|
def create(wid, passphrase, payments, withdrawal = nil, metadata = nil, ttl = nil)
|
290
266
|
Utils.verify_param_is_array!(payments)
|
291
|
-
if payments.any?{|p| p.
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
payload = { :
|
297
|
-
:passphrase
|
298
|
-
}
|
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 }
|
299
274
|
payload[:withdrawal] = withdrawal if withdrawal
|
300
275
|
payload[:metadata] = metadata if metadata
|
301
|
-
payload[:time_to_live] = { quantity: ttl, unit:
|
276
|
+
payload[:time_to_live] = { quantity: ttl, unit: 'second' } if ttl
|
302
277
|
|
303
278
|
self.class.post("/wallets/#{wid}/transactions",
|
304
|
-
|
305
|
-
|
279
|
+
body: payload.to_json,
|
280
|
+
headers: { 'Content-Type' => 'application/json' })
|
306
281
|
end
|
307
282
|
|
308
283
|
# Estimate fees for transaction
|
@@ -310,24 +285,27 @@ module CardanoWallet
|
|
310
285
|
#
|
311
286
|
# @example
|
312
287
|
# payment_fees(wid, [{addr1: 1000000}, {addr2: 1000000}], {"1": "abc"}, ttl = 10)
|
313
|
-
# 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)
|
314
292
|
def payment_fees(wid, payments, withdrawal = nil, metadata = nil, ttl = nil)
|
315
293
|
Utils.verify_param_is_array!(payments)
|
316
|
-
if payments.any?{|p| p.
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
294
|
+
payments_formatted = if payments.any? { |p| p.key?(:address) || p.key?('address') }
|
295
|
+
payments
|
296
|
+
else
|
297
|
+
Utils.format_payments(payments)
|
298
|
+
end
|
321
299
|
|
322
|
-
payload = { :
|
300
|
+
payload = { payments: payments_formatted }
|
323
301
|
|
324
302
|
payload[:withdrawal] = withdrawal if withdrawal
|
325
303
|
payload[:metadata] = metadata if metadata
|
326
|
-
payload[:time_to_live] = { quantity: ttl, unit:
|
304
|
+
payload[:time_to_live] = { quantity: ttl, unit: 'second' } if ttl
|
327
305
|
|
328
306
|
self.class.post("/wallets/#{wid}/payment-fees",
|
329
|
-
|
330
|
-
|
307
|
+
body: payload.to_json,
|
308
|
+
headers: { 'Content-Type' => 'application/json' })
|
331
309
|
end
|
332
310
|
|
333
311
|
# Forget a transaction
|
@@ -340,10 +318,6 @@ module CardanoWallet
|
|
340
318
|
# API for StakePools
|
341
319
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Stake-Pools
|
342
320
|
class StakePools < Base
|
343
|
-
def initialize opt
|
344
|
-
super
|
345
|
-
end
|
346
|
-
|
347
321
|
# Stake pools maintenance actions
|
348
322
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postMaintenanceAction
|
349
323
|
#
|
@@ -351,21 +325,21 @@ module CardanoWallet
|
|
351
325
|
# maintenance_action({ "maintenance_action": "gc_stake_pools" })
|
352
326
|
def trigger_maintenance_actions(action = {})
|
353
327
|
Utils.verify_param_is_hash!(action)
|
354
|
-
self.class.post(
|
355
|
-
|
356
|
-
|
328
|
+
self.class.post('/stake-pools/maintenance-actions',
|
329
|
+
body: action.to_json,
|
330
|
+
headers: { 'Content-Type' => 'application/json' })
|
357
331
|
end
|
358
332
|
|
359
333
|
# Metdata GC Status
|
360
334
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getMaintenanceActions
|
361
335
|
def view_maintenance_actions
|
362
|
-
self.class.get(
|
336
|
+
self.class.get('/stake-pools/maintenance-actions')
|
363
337
|
end
|
364
338
|
|
365
339
|
# List all stake pools
|
366
340
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listStakePools
|
367
341
|
def list(stake = {})
|
368
|
-
stake.empty? ?
|
342
|
+
query = stake.empty? ? '' : Utils.to_query(stake)
|
369
343
|
self.class.get("/stake-pools#{query}")
|
370
344
|
end
|
371
345
|
|
@@ -373,16 +347,16 @@ module CardanoWallet
|
|
373
347
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/joinStakePool
|
374
348
|
def join(sp_id, wid, passphrase)
|
375
349
|
self.class.put("/stake-pools/#{sp_id}/wallets/#{wid}",
|
376
|
-
|
377
|
-
|
350
|
+
body: { passphrase: passphrase }.to_json,
|
351
|
+
headers: { 'Content-Type' => 'application/json' })
|
378
352
|
end
|
379
353
|
|
380
354
|
# Quit stape pool
|
381
355
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/quitStakePool
|
382
356
|
def quit(wid, passphrase)
|
383
357
|
self.class.delete("#{@api}/stake-pools/*/wallets/#{wid}",
|
384
|
-
|
385
|
-
|
358
|
+
body: { passphrase: passphrase }.to_json,
|
359
|
+
headers: { 'Content-Type' => 'application/json' })
|
386
360
|
end
|
387
361
|
|
388
362
|
# Estimate delegation fees
|
@@ -395,10 +369,6 @@ module CardanoWallet
|
|
395
369
|
# Shelley migrations
|
396
370
|
# @see https://input-output-hk.github.io/cardano-wallet/api/#tag/Migrations
|
397
371
|
class Migrations < Base
|
398
|
-
def initialize opt
|
399
|
-
super
|
400
|
-
end
|
401
|
-
|
402
372
|
# Calculate migration cost
|
403
373
|
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/getShelleyWalletMigrationInfo
|
404
374
|
def cost(wid)
|
@@ -412,12 +382,10 @@ module CardanoWallet
|
|
412
382
|
# @param [Array] array of addresses
|
413
383
|
def migrate(wid, passphrase, addresses)
|
414
384
|
self.class.post("/wallets/#{wid}/migrations",
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
:headers => { 'Content-Type' => 'application/json' } )
|
385
|
+
body: { addresses: addresses,
|
386
|
+
passphrase: passphrase }.to_json,
|
387
|
+
headers: { 'Content-Type' => 'application/json' })
|
419
388
|
end
|
420
|
-
|
421
389
|
end
|
422
390
|
end
|
423
391
|
end
|