cardano_wallet 0.2.8 → 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 +24 -11
- 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/dev +1 -1
- data/{docker-compose-shelley.yml → docker-compose.yml} +1 -2
- data/lib/cardano_wallet.rb +12 -7
- data/lib/cardano_wallet/base.rb +13 -6
- data/lib/cardano_wallet/byron.rb +84 -66
- data/lib/cardano_wallet/misc.rb +31 -40
- data/lib/cardano_wallet/shared.rb +76 -0
- data/lib/cardano_wallet/shelley.rb +111 -88
- data/lib/cardano_wallet/utils.rb +14 -10
- data/lib/cardano_wallet/version.rb +3 -1
- metadata +34 -18
- data/.github/workflows/nightly.yml +0 -29
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,27 +97,32 @@ 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
|
|
106
|
+
# Current SMASH health
|
107
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getCurrentSmashHealth
|
108
|
+
#
|
109
|
+
# @example
|
110
|
+
# smash_health({url: "https://smash.cardano-mainnet.iohk.io/"})
|
111
|
+
def smash_health(query = {})
|
112
|
+
query_formatted = query.empty? ? '' : CardanoWallet::Utils.to_query(query)
|
113
|
+
self.class.get("/smash/health#{query_formatted}")
|
114
|
+
end
|
120
115
|
end
|
121
116
|
|
122
117
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Proxy
|
123
118
|
class Proxy < Base
|
124
|
-
def initialize opt
|
125
|
-
super
|
126
|
-
end
|
127
|
-
|
128
119
|
# Submit a transaction that was created and signed outside of cardano-wallet.
|
129
120
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postExternalTransaction
|
130
121
|
# @param binary_blob [String] Signed transaction message binary blob.
|
131
122
|
def submit_external_transaction(binary_blob)
|
132
|
-
self.class.post(
|
133
|
-
:
|
134
|
-
:
|
123
|
+
self.class.post('/proxy/transactions',
|
124
|
+
body: binary_blob,
|
125
|
+
headers: { 'Content-Type' => 'application/octet-stream' })
|
135
126
|
end
|
136
127
|
end
|
137
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
|
@@ -54,22 +52,39 @@ module CardanoWallet
|
|
54
52
|
Keys.new @opt
|
55
53
|
end
|
56
54
|
|
55
|
+
# API for Assets
|
56
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Assets
|
57
|
+
def assets
|
58
|
+
Assets.new @opt
|
59
|
+
end
|
57
60
|
end
|
58
61
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
+
##
|
63
|
+
# Base class for Shelley Assets API
|
64
|
+
class Assets < Base
|
65
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listAssets
|
66
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getAsset
|
67
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getAssetDefault
|
68
|
+
def get(wid, policy_id = nil, asset_name = nil)
|
69
|
+
ep = "/wallets/#{wid}/assets"
|
70
|
+
ep += "/#{policy_id}" if policy_id
|
71
|
+
ep += "/#{asset_name}" if asset_name
|
72
|
+
self.class.get(ep)
|
62
73
|
end
|
74
|
+
end
|
63
75
|
|
76
|
+
##
|
77
|
+
# Base class for Shelley Keys API
|
78
|
+
class Keys < Base
|
64
79
|
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/signMetadata
|
65
80
|
def sign_metadata(wid, role, index, pass, metadata)
|
66
81
|
payload = { passphrase: pass }
|
67
82
|
payload[:metadata] = metadata if metadata
|
68
83
|
|
69
84
|
self.class.post("/wallets/#{wid}/signatures/#{role}/#{index}",
|
70
|
-
:
|
71
|
-
:
|
72
|
-
|
85
|
+
body: payload.to_json,
|
86
|
+
headers: { 'Content-Type' => 'application/json',
|
87
|
+
'Accept' => 'application/octet-stream' })
|
73
88
|
end
|
74
89
|
|
75
90
|
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/getWalletKey
|
@@ -77,19 +92,22 @@ module CardanoWallet
|
|
77
92
|
self.class.get("/wallets/#{wid}/keys/#{role}/#{index}")
|
78
93
|
end
|
79
94
|
|
95
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/postAccountKey
|
96
|
+
def create_acc_public_key(wid, index, pass, extended)
|
97
|
+
payload = { passphrase: pass, extended: extended }
|
98
|
+
self.class.post("/wallets/#{wid}/keys/#{index}",
|
99
|
+
body: payload.to_json,
|
100
|
+
headers: { 'Content-Type' => 'application/json' })
|
101
|
+
end
|
80
102
|
end
|
81
103
|
|
82
104
|
# API for Wallets
|
83
105
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Wallets
|
84
106
|
class Wallets < Base
|
85
|
-
def initialize opt
|
86
|
-
super
|
87
|
-
end
|
88
|
-
|
89
107
|
# List all wallets
|
90
108
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listWallets
|
91
109
|
def list
|
92
|
-
self.class.get(
|
110
|
+
self.class.get('/wallets')
|
93
111
|
end
|
94
112
|
|
95
113
|
# Get wallet details
|
@@ -104,19 +122,18 @@ module CardanoWallet
|
|
104
122
|
# @example Create wallet from mnemonic sentence
|
105
123
|
# create({name: "Wallet from mnemonic_sentence",
|
106
124
|
# passphrase: "Secure Passphrase",
|
107
|
-
# mnemonic_sentence: %w[story egg fun
|
125
|
+
# mnemonic_sentence: %w[story egg fun ... ],
|
108
126
|
# })
|
109
127
|
# @example Create wallet from pub key
|
110
128
|
# create({name: "Wallet from pub key",
|
111
|
-
# account_public_key: "
|
129
|
+
# account_public_key: "b47546e...",
|
112
130
|
# address_pool_gap: 20,
|
113
131
|
# })
|
114
132
|
def create(params)
|
115
133
|
Utils.verify_param_is_hash!(params)
|
116
|
-
self.class.post(
|
117
|
-
|
118
|
-
|
119
|
-
)
|
134
|
+
self.class.post('/wallets',
|
135
|
+
body: params.to_json,
|
136
|
+
headers: { 'Content-Type' => 'application/json' })
|
120
137
|
end
|
121
138
|
|
122
139
|
# Delete wallet
|
@@ -133,9 +150,8 @@ module CardanoWallet
|
|
133
150
|
def update_metadata(wid, params)
|
134
151
|
Utils.verify_param_is_hash!(params)
|
135
152
|
self.class.put("/wallets/#{wid}",
|
136
|
-
:
|
137
|
-
:
|
138
|
-
)
|
153
|
+
body: params.to_json,
|
154
|
+
headers: { 'Content-Type' => 'application/json' })
|
139
155
|
end
|
140
156
|
|
141
157
|
# See wallet's utxo distribution
|
@@ -152,47 +168,50 @@ module CardanoWallet
|
|
152
168
|
def update_passphrase(wid, params)
|
153
169
|
Utils.verify_param_is_hash!(params)
|
154
170
|
self.class.put("/wallets/#{wid}/passphrase",
|
155
|
-
:
|
156
|
-
:
|
157
|
-
)
|
171
|
+
body: params.to_json,
|
172
|
+
headers: { 'Content-Type' => 'application/json' })
|
158
173
|
end
|
159
174
|
end
|
160
175
|
|
161
176
|
# API for Addresses
|
162
177
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Addresses
|
163
178
|
class Addresses < Base
|
164
|
-
def initialize opt
|
165
|
-
super
|
166
|
-
end
|
167
|
-
|
168
179
|
# List addresses
|
169
180
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listAddresses
|
170
181
|
#
|
171
182
|
# @example
|
172
183
|
# list(wid, {state: "used"})
|
173
|
-
def list(wid,
|
174
|
-
|
175
|
-
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}")
|
176
187
|
end
|
177
188
|
end
|
178
189
|
|
179
190
|
# API for CoinSelections
|
180
191
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Coin-Selections
|
181
192
|
class CoinSelections < Base
|
182
|
-
def initialize opt
|
183
|
-
super
|
184
|
-
end
|
185
|
-
|
186
193
|
# Show random coin selection for particular payment
|
187
194
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/selectCoins
|
188
195
|
#
|
189
196
|
# @example
|
190
197
|
# random(wid, [{addr1: 1000000}, {addr2: 1000000}])
|
191
|
-
|
192
|
-
|
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
|
+
|
193
212
|
self.class.post("/wallets/#{wid}/coin-selections/random",
|
194
|
-
|
195
|
-
:
|
213
|
+
body: payload.to_json,
|
214
|
+
headers: { 'Content-Type' => 'application/json' })
|
196
215
|
end
|
197
216
|
|
198
217
|
# Coin selection -> Delegation action
|
@@ -204,18 +223,14 @@ module CardanoWallet
|
|
204
223
|
def random_deleg(wid, deleg_action)
|
205
224
|
Utils.verify_param_is_hash!(deleg_action)
|
206
225
|
self.class.post("/wallets/#{wid}/coin-selections/random",
|
207
|
-
:
|
208
|
-
:
|
226
|
+
body: { delegation_action: deleg_action }.to_json,
|
227
|
+
headers: { 'Content-Type' => 'application/json' })
|
209
228
|
end
|
210
229
|
end
|
211
230
|
|
212
231
|
# API for Transactions
|
213
232
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Transactions
|
214
233
|
class Transactions < Base
|
215
|
-
def initialize opt
|
216
|
-
super
|
217
|
-
end
|
218
|
-
|
219
234
|
# Get tx by id
|
220
235
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getTransaction
|
221
236
|
def get(wid, tx_id)
|
@@ -227,34 +242,42 @@ module CardanoWallet
|
|
227
242
|
#
|
228
243
|
# @example
|
229
244
|
# list(wid, {start: "2012-09-25T10:15:00Z", order: "descending"})
|
230
|
-
def list(wid,
|
231
|
-
|
232
|
-
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}")
|
233
248
|
end
|
234
249
|
|
235
250
|
# Create a transaction from the wallet
|
236
251
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransaction
|
237
252
|
# @param wid [String] source wallet id
|
238
253
|
# @param passphrase [String] source wallet's passphrase
|
239
|
-
# @param payments [Array of Hashes]
|
254
|
+
# @param payments [Array of Hashes] address / amount list or full payments payload with assets
|
240
255
|
# @param withdrawal [String or Array] 'self' or mnemonic sentence
|
241
256
|
# @param metadata [Hash] special metadata JSON subset format (cf: https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransaction)
|
242
257
|
# @param ttl [Int] transaction's time-to-live in seconds
|
243
258
|
#
|
244
259
|
# @example
|
245
260
|
# create(wid, passphrase, [{addr1: 1000000}, {addr2: 1000000}], 'self', {"1": "abc"}, ttl = 10)
|
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)
|
246
265
|
def create(wid, passphrase, payments, withdrawal = nil, metadata = nil, ttl = nil)
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
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 }
|
251
274
|
payload[:withdrawal] = withdrawal if withdrawal
|
252
275
|
payload[:metadata] = metadata if metadata
|
253
|
-
payload[:time_to_live] = { quantity: ttl, unit:
|
276
|
+
payload[:time_to_live] = { quantity: ttl, unit: 'second' } if ttl
|
254
277
|
|
255
278
|
self.class.post("/wallets/#{wid}/transactions",
|
256
|
-
|
257
|
-
|
279
|
+
body: payload.to_json,
|
280
|
+
headers: { 'Content-Type' => 'application/json' })
|
258
281
|
end
|
259
282
|
|
260
283
|
# Estimate fees for transaction
|
@@ -262,17 +285,27 @@ module CardanoWallet
|
|
262
285
|
#
|
263
286
|
# @example
|
264
287
|
# payment_fees(wid, [{addr1: 1000000}, {addr2: 1000000}], {"1": "abc"}, ttl = 10)
|
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)
|
265
292
|
def payment_fees(wid, payments, withdrawal = nil, metadata = nil, ttl = nil)
|
266
|
-
|
267
|
-
|
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
|
299
|
+
|
300
|
+
payload = { payments: payments_formatted }
|
268
301
|
|
269
302
|
payload[:withdrawal] = withdrawal if withdrawal
|
270
303
|
payload[:metadata] = metadata if metadata
|
271
|
-
payload[:time_to_live] = { quantity: ttl, unit:
|
304
|
+
payload[:time_to_live] = { quantity: ttl, unit: 'second' } if ttl
|
272
305
|
|
273
306
|
self.class.post("/wallets/#{wid}/payment-fees",
|
274
|
-
|
275
|
-
|
307
|
+
body: payload.to_json,
|
308
|
+
headers: { 'Content-Type' => 'application/json' })
|
276
309
|
end
|
277
310
|
|
278
311
|
# Forget a transaction
|
@@ -285,10 +318,6 @@ module CardanoWallet
|
|
285
318
|
# API for StakePools
|
286
319
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Stake-Pools
|
287
320
|
class StakePools < Base
|
288
|
-
def initialize opt
|
289
|
-
super
|
290
|
-
end
|
291
|
-
|
292
321
|
# Stake pools maintenance actions
|
293
322
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postMaintenanceAction
|
294
323
|
#
|
@@ -296,21 +325,21 @@ module CardanoWallet
|
|
296
325
|
# maintenance_action({ "maintenance_action": "gc_stake_pools" })
|
297
326
|
def trigger_maintenance_actions(action = {})
|
298
327
|
Utils.verify_param_is_hash!(action)
|
299
|
-
self.class.post(
|
300
|
-
|
301
|
-
|
328
|
+
self.class.post('/stake-pools/maintenance-actions',
|
329
|
+
body: action.to_json,
|
330
|
+
headers: { 'Content-Type' => 'application/json' })
|
302
331
|
end
|
303
332
|
|
304
333
|
# Metdata GC Status
|
305
334
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getMaintenanceActions
|
306
335
|
def view_maintenance_actions
|
307
|
-
self.class.get(
|
336
|
+
self.class.get('/stake-pools/maintenance-actions')
|
308
337
|
end
|
309
338
|
|
310
339
|
# List all stake pools
|
311
340
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listStakePools
|
312
341
|
def list(stake = {})
|
313
|
-
stake.empty? ?
|
342
|
+
query = stake.empty? ? '' : Utils.to_query(stake)
|
314
343
|
self.class.get("/stake-pools#{query}")
|
315
344
|
end
|
316
345
|
|
@@ -318,16 +347,16 @@ module CardanoWallet
|
|
318
347
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/joinStakePool
|
319
348
|
def join(sp_id, wid, passphrase)
|
320
349
|
self.class.put("/stake-pools/#{sp_id}/wallets/#{wid}",
|
321
|
-
|
322
|
-
|
350
|
+
body: { passphrase: passphrase }.to_json,
|
351
|
+
headers: { 'Content-Type' => 'application/json' })
|
323
352
|
end
|
324
353
|
|
325
354
|
# Quit stape pool
|
326
355
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/quitStakePool
|
327
356
|
def quit(wid, passphrase)
|
328
357
|
self.class.delete("#{@api}/stake-pools/*/wallets/#{wid}",
|
329
|
-
|
330
|
-
|
358
|
+
body: { passphrase: passphrase }.to_json,
|
359
|
+
headers: { 'Content-Type' => 'application/json' })
|
331
360
|
end
|
332
361
|
|
333
362
|
# Estimate delegation fees
|
@@ -340,10 +369,6 @@ module CardanoWallet
|
|
340
369
|
# Shelley migrations
|
341
370
|
# @see https://input-output-hk.github.io/cardano-wallet/api/#tag/Migrations
|
342
371
|
class Migrations < Base
|
343
|
-
def initialize opt
|
344
|
-
super
|
345
|
-
end
|
346
|
-
|
347
372
|
# Calculate migration cost
|
348
373
|
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/getShelleyWalletMigrationInfo
|
349
374
|
def cost(wid)
|
@@ -357,12 +382,10 @@ module CardanoWallet
|
|
357
382
|
# @param [Array] array of addresses
|
358
383
|
def migrate(wid, passphrase, addresses)
|
359
384
|
self.class.post("/wallets/#{wid}/migrations",
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
:headers => { 'Content-Type' => 'application/json' } )
|
385
|
+
body: { addresses: addresses,
|
386
|
+
passphrase: passphrase }.to_json,
|
387
|
+
headers: { 'Content-Type' => 'application/json' })
|
364
388
|
end
|
365
|
-
|
366
389
|
end
|
367
390
|
end
|
368
391
|
end
|