cardano_wallet 0.3.1 → 0.3.6
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 +68 -90
- data/lib/cardano_wallet/misc.rb +25 -44
- data/lib/cardano_wallet/shared.rb +101 -0
- data/lib/cardano_wallet/shelley.rb +93 -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
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,101 @@
|
|
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
|
+
|
19
|
+
# Call API for Shared Keys
|
20
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Shared-Keys
|
21
|
+
def keys
|
22
|
+
Keys.new @opt
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# API for Keys
|
27
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Shared-Keys
|
28
|
+
class Keys < Base
|
29
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/getSharedWalletKey
|
30
|
+
# https://localhost:8090/v2/shared-wallets/{walletId}/keys/{role}/{index}?hash=false
|
31
|
+
def get_public_key(wid, role, index, hash = {})
|
32
|
+
hash_query = hash.empty? ? '' : Utils.to_query(hash)
|
33
|
+
self.class.get("/shared-wallets/#{wid}/keys/#{role}/#{index}#{hash_query}")
|
34
|
+
end
|
35
|
+
|
36
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/postAccountKeyShared
|
37
|
+
def create_acc_public_key(wid, index, pass, format)
|
38
|
+
payload = { passphrase: pass, format: format }
|
39
|
+
self.class.post("/shared-wallets/#{wid}/keys/#{index}",
|
40
|
+
body: payload.to_json,
|
41
|
+
headers: { 'Content-Type' => 'application/json' })
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# API for Wallets
|
46
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Shared-Wallets
|
47
|
+
class Wallets < Base
|
48
|
+
# List all wallets
|
49
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listWallets
|
50
|
+
# def list
|
51
|
+
# self.class.get('/shared-wallets')
|
52
|
+
# end
|
53
|
+
|
54
|
+
# Get wallet details
|
55
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getSharedWallet
|
56
|
+
def get(wid)
|
57
|
+
self.class.get("/shared-wallets/#{wid}")
|
58
|
+
end
|
59
|
+
|
60
|
+
# Create a wallet based on the params.
|
61
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postSharedWallet
|
62
|
+
#
|
63
|
+
# @example Create wallet from mnemonic sentence
|
64
|
+
# create({name: "Wallet from mnemonic_sentence",
|
65
|
+
# passphrase: "Secure Passphrase",
|
66
|
+
# mnemonic_sentence: %w[story egg fun ... ],
|
67
|
+
# account_index: "1852H",
|
68
|
+
# payment_script_template: {...},
|
69
|
+
# ...
|
70
|
+
# })
|
71
|
+
def create(params)
|
72
|
+
Utils.verify_param_is_hash!(params)
|
73
|
+
self.class.post('/shared-wallets',
|
74
|
+
body: params.to_json,
|
75
|
+
headers: { 'Content-Type' => 'application/json' })
|
76
|
+
end
|
77
|
+
|
78
|
+
# Delete wallet
|
79
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/deleteSharedWallet
|
80
|
+
def delete(wid)
|
81
|
+
self.class.delete("/shared-wallets/#{wid}")
|
82
|
+
end
|
83
|
+
|
84
|
+
# Update payment script
|
85
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/patchSharedWalletInPayment
|
86
|
+
def update_payment_script(wid, cosigner, acc_pub_key)
|
87
|
+
self.class.patch("/shared-wallets/#{wid}/payment-script-template",
|
88
|
+
body: { cosigner => acc_pub_key }.to_json,
|
89
|
+
headers: { 'Content-Type' => 'application/json' })
|
90
|
+
end
|
91
|
+
|
92
|
+
# Update delegation script
|
93
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/patchSharedWalletInDelegation
|
94
|
+
def update_delegation_script(wid, cosigner, acc_pub_key)
|
95
|
+
self.class.patch("/shared-wallets/#{wid}/delegation-script-template",
|
96
|
+
body: { cosigner => acc_pub_key }.to_json,
|
97
|
+
headers: { 'Content-Type' => 'application/json' })
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
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
|
@@ -101,27 +93,21 @@ module CardanoWallet
|
|
101
93
|
end
|
102
94
|
|
103
95
|
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/postAccountKey
|
104
|
-
def create_acc_public_key(wid, index, pass,
|
105
|
-
payload = { passphrase: pass,
|
96
|
+
def create_acc_public_key(wid, index, pass, format)
|
97
|
+
payload = { passphrase: pass, format: format }
|
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,53 +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..",
|
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)
|
225
202
|
Utils.verify_param_is_array!(payments)
|
226
|
-
if payments.any?{|p| p.
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
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
|
+
|
231
212
|
self.class.post("/wallets/#{wid}/coin-selections/random",
|
232
|
-
|
233
|
-
:
|
213
|
+
body: payload.to_json,
|
214
|
+
headers: { 'Content-Type' => 'application/json' })
|
234
215
|
end
|
235
216
|
|
236
217
|
# Coin selection -> Delegation action
|
@@ -242,18 +223,14 @@ module CardanoWallet
|
|
242
223
|
def random_deleg(wid, deleg_action)
|
243
224
|
Utils.verify_param_is_hash!(deleg_action)
|
244
225
|
self.class.post("/wallets/#{wid}/coin-selections/random",
|
245
|
-
:
|
246
|
-
:
|
226
|
+
body: { delegation_action: deleg_action }.to_json,
|
227
|
+
headers: { 'Content-Type' => 'application/json' })
|
247
228
|
end
|
248
229
|
end
|
249
230
|
|
250
231
|
# API for Transactions
|
251
232
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Transactions
|
252
233
|
class Transactions < Base
|
253
|
-
def initialize opt
|
254
|
-
super
|
255
|
-
end
|
256
|
-
|
257
234
|
# Get tx by id
|
258
235
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getTransaction
|
259
236
|
def get(wid, tx_id)
|
@@ -265,9 +242,9 @@ module CardanoWallet
|
|
265
242
|
#
|
266
243
|
# @example
|
267
244
|
# list(wid, {start: "2012-09-25T10:15:00Z", order: "descending"})
|
268
|
-
def list(wid,
|
269
|
-
|
270
|
-
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}")
|
271
248
|
end
|
272
249
|
|
273
250
|
# Create a transaction from the wallet
|
@@ -281,24 +258,26 @@ module CardanoWallet
|
|
281
258
|
#
|
282
259
|
# @example
|
283
260
|
# create(wid, passphrase, [{addr1: 1000000}, {addr2: 1000000}], 'self', {"1": "abc"}, ttl = 10)
|
284
|
-
# 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)
|
285
265
|
def create(wid, passphrase, payments, withdrawal = nil, metadata = nil, ttl = nil)
|
286
266
|
Utils.verify_param_is_array!(payments)
|
287
|
-
if payments.any?{|p| p.
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
payload = { :
|
293
|
-
:passphrase
|
294
|
-
}
|
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 }
|
295
274
|
payload[:withdrawal] = withdrawal if withdrawal
|
296
275
|
payload[:metadata] = metadata if metadata
|
297
|
-
payload[:time_to_live] = { quantity: ttl, unit:
|
276
|
+
payload[:time_to_live] = { quantity: ttl, unit: 'second' } if ttl
|
298
277
|
|
299
278
|
self.class.post("/wallets/#{wid}/transactions",
|
300
|
-
|
301
|
-
|
279
|
+
body: payload.to_json,
|
280
|
+
headers: { 'Content-Type' => 'application/json' })
|
302
281
|
end
|
303
282
|
|
304
283
|
# Estimate fees for transaction
|
@@ -306,24 +285,27 @@ module CardanoWallet
|
|
306
285
|
#
|
307
286
|
# @example
|
308
287
|
# payment_fees(wid, [{addr1: 1000000}, {addr2: 1000000}], {"1": "abc"}, ttl = 10)
|
309
|
-
# 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)
|
310
292
|
def payment_fees(wid, payments, withdrawal = nil, metadata = nil, ttl = nil)
|
311
293
|
Utils.verify_param_is_array!(payments)
|
312
|
-
if payments.any?{|p| p.
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
294
|
+
payments_formatted = if payments.any? { |p| p.key?(:address) || p.key?('address') }
|
295
|
+
payments
|
296
|
+
else
|
297
|
+
Utils.format_payments(payments)
|
298
|
+
end
|
317
299
|
|
318
|
-
payload = { :
|
300
|
+
payload = { payments: payments_formatted }
|
319
301
|
|
320
302
|
payload[:withdrawal] = withdrawal if withdrawal
|
321
303
|
payload[:metadata] = metadata if metadata
|
322
|
-
payload[:time_to_live] = { quantity: ttl, unit:
|
304
|
+
payload[:time_to_live] = { quantity: ttl, unit: 'second' } if ttl
|
323
305
|
|
324
306
|
self.class.post("/wallets/#{wid}/payment-fees",
|
325
|
-
|
326
|
-
|
307
|
+
body: payload.to_json,
|
308
|
+
headers: { 'Content-Type' => 'application/json' })
|
327
309
|
end
|
328
310
|
|
329
311
|
# Forget a transaction
|
@@ -336,10 +318,6 @@ module CardanoWallet
|
|
336
318
|
# API for StakePools
|
337
319
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Stake-Pools
|
338
320
|
class StakePools < Base
|
339
|
-
def initialize opt
|
340
|
-
super
|
341
|
-
end
|
342
|
-
|
343
321
|
# Stake pools maintenance actions
|
344
322
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postMaintenanceAction
|
345
323
|
#
|
@@ -347,21 +325,21 @@ module CardanoWallet
|
|
347
325
|
# maintenance_action({ "maintenance_action": "gc_stake_pools" })
|
348
326
|
def trigger_maintenance_actions(action = {})
|
349
327
|
Utils.verify_param_is_hash!(action)
|
350
|
-
self.class.post(
|
351
|
-
|
352
|
-
|
328
|
+
self.class.post('/stake-pools/maintenance-actions',
|
329
|
+
body: action.to_json,
|
330
|
+
headers: { 'Content-Type' => 'application/json' })
|
353
331
|
end
|
354
332
|
|
355
333
|
# Metdata GC Status
|
356
334
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getMaintenanceActions
|
357
335
|
def view_maintenance_actions
|
358
|
-
self.class.get(
|
336
|
+
self.class.get('/stake-pools/maintenance-actions')
|
359
337
|
end
|
360
338
|
|
361
339
|
# List all stake pools
|
362
340
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listStakePools
|
363
341
|
def list(stake = {})
|
364
|
-
stake.empty? ?
|
342
|
+
query = stake.empty? ? '' : Utils.to_query(stake)
|
365
343
|
self.class.get("/stake-pools#{query}")
|
366
344
|
end
|
367
345
|
|
@@ -369,16 +347,16 @@ module CardanoWallet
|
|
369
347
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/joinStakePool
|
370
348
|
def join(sp_id, wid, passphrase)
|
371
349
|
self.class.put("/stake-pools/#{sp_id}/wallets/#{wid}",
|
372
|
-
|
373
|
-
|
350
|
+
body: { passphrase: passphrase }.to_json,
|
351
|
+
headers: { 'Content-Type' => 'application/json' })
|
374
352
|
end
|
375
353
|
|
376
354
|
# Quit stape pool
|
377
355
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/quitStakePool
|
378
356
|
def quit(wid, passphrase)
|
379
357
|
self.class.delete("#{@api}/stake-pools/*/wallets/#{wid}",
|
380
|
-
|
381
|
-
|
358
|
+
body: { passphrase: passphrase }.to_json,
|
359
|
+
headers: { 'Content-Type' => 'application/json' })
|
382
360
|
end
|
383
361
|
|
384
362
|
# Estimate delegation fees
|
@@ -391,14 +369,12 @@ module CardanoWallet
|
|
391
369
|
# Shelley migrations
|
392
370
|
# @see https://input-output-hk.github.io/cardano-wallet/api/#tag/Migrations
|
393
371
|
class Migrations < Base
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
def cost(wid)
|
401
|
-
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' })
|
402
378
|
end
|
403
379
|
|
404
380
|
# Migrate all funds from Shelley wallet.
|
@@ -408,12 +384,10 @@ module CardanoWallet
|
|
408
384
|
# @param [Array] array of addresses
|
409
385
|
def migrate(wid, passphrase, addresses)
|
410
386
|
self.class.post("/wallets/#{wid}/migrations",
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
:headers => { 'Content-Type' => 'application/json' } )
|
387
|
+
body: { addresses: addresses,
|
388
|
+
passphrase: passphrase }.to_json,
|
389
|
+
headers: { 'Content-Type' => 'application/json' })
|
415
390
|
end
|
416
|
-
|
417
391
|
end
|
418
392
|
end
|
419
393
|
end
|