cardano_wallet 0.2.1 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/nightly.yml +1 -1
- data/.github/workflows/tests.yml +1 -1
- data/lib/cardano_wallet/byron.rb +4 -4
- data/lib/cardano_wallet/misc.rb +25 -0
- data/lib/cardano_wallet/shelley.rb +51 -6
- data/lib/cardano_wallet/utils.rb +17 -6
- data/lib/cardano_wallet/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e03252209057d5605ab9020ce1ef5ff66f123c6de43039595fbcfeefcc93ceb
|
4
|
+
data.tar.gz: 17be8811e28fa42f2b7dcc3f143d15d1f3b86ff186031c30dccbd71ee6487028
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92fb3ce4f8d6083e03dce79d4a617b672d28c5952590b5ac9604ebd01352ed03d59e62aa3a42f6a1674800a10fa3e26355897dabebfde916a90c73a1e7471a94
|
7
|
+
data.tar.gz: db0decbb39674070b8741ade621a3e1dd5d6fe8a8539dc13ceaac303bc7b86fc6304c13709caa9f5bfafaecde3f56468ceadbfe879f77243cc407f92716d3526
|
data/.github/workflows/tests.yml
CHANGED
data/lib/cardano_wallet/byron.rb
CHANGED
@@ -181,7 +181,7 @@ module CardanoWallet
|
|
181
181
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/byronSelectCoins
|
182
182
|
#
|
183
183
|
# @example
|
184
|
-
# random(wid, {
|
184
|
+
# random(wid, [{addr1: 1000000}, {addr2: 1000000}])
|
185
185
|
def random(wid, payments)
|
186
186
|
payments_formatted = Utils.format_payments(payments)
|
187
187
|
self.class.post("/byron-wallets/#{wid}/coin-selections/random",
|
@@ -217,10 +217,10 @@ module CardanoWallet
|
|
217
217
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postByronTransaction
|
218
218
|
# @param wid [String] source wallet id
|
219
219
|
# @param passphrase [String] source wallet's passphrase
|
220
|
-
# @param payments [
|
220
|
+
# @param payments [Array of Hashes] addres, amount pair
|
221
221
|
#
|
222
222
|
# @example
|
223
|
-
# create(wid, passphrase, {addr1: 1000000})
|
223
|
+
# create(wid, passphrase, [{addr1: 1000000}, {addr2: 1000000}])
|
224
224
|
def create(wid, passphrase, payments)
|
225
225
|
payments_formatted = Utils.format_payments(payments)
|
226
226
|
self.class.post("/byron-wallets/#{wid}/transactions",
|
@@ -234,7 +234,7 @@ module CardanoWallet
|
|
234
234
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransactionFee
|
235
235
|
#
|
236
236
|
# @example
|
237
|
-
# payment_fees(wid, {addr1: 1000000})
|
237
|
+
# payment_fees(wid, [{addr1: 1000000}, {addr2: 1000000}])
|
238
238
|
def payment_fees(wid, payments)
|
239
239
|
payments_formatted = Utils.format_payments(payments)
|
240
240
|
self.class.post("/byron-wallets/#{wid}/payment-fees",
|
data/lib/cardano_wallet/misc.rb
CHANGED
@@ -30,6 +30,7 @@ module CardanoWallet
|
|
30
30
|
def settings
|
31
31
|
Settings.new @opt
|
32
32
|
end
|
33
|
+
|
33
34
|
end
|
34
35
|
|
35
36
|
# API for Network
|
@@ -87,11 +88,35 @@ module CardanoWallet
|
|
87
88
|
super
|
88
89
|
end
|
89
90
|
|
91
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/signMetadata
|
92
|
+
def sign_metadata(wid, role, index, pass, metadata)
|
93
|
+
payload = { passphrase: pass }
|
94
|
+
payload[:metadata] = metadata if metadata
|
95
|
+
|
96
|
+
self.class.post("/wallets/#{wid}/signatures/#{role}/#{index}",
|
97
|
+
:body => payload.to_json,
|
98
|
+
:headers => { 'Content-Type' => 'application/json' } )
|
99
|
+
end
|
100
|
+
|
101
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/getWalletKey
|
102
|
+
def get_public_key(wid, role, index)
|
103
|
+
self.class.get("/wallets/#{wid}/keys/#{role}/#{index}")
|
104
|
+
end
|
105
|
+
|
90
106
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/inspectAddress
|
91
107
|
def addresses(address_id)
|
92
108
|
self.class.get("/addresses/#{address_id}")
|
93
109
|
end
|
94
110
|
|
111
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postAnyAddress
|
112
|
+
def post_address(payload)
|
113
|
+
CardanoWallet::Utils.verify_param_is_hash!(payload)
|
114
|
+
self.class.post("/addresses",
|
115
|
+
:body => payload.to_json,
|
116
|
+
:headers => { 'Content-Type' => 'application/json',
|
117
|
+
'Accept' => 'application/json'} )
|
118
|
+
end
|
119
|
+
|
95
120
|
end
|
96
121
|
|
97
122
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Proxy
|
@@ -48,6 +48,35 @@ module CardanoWallet
|
|
48
48
|
Migrations.new @opt
|
49
49
|
end
|
50
50
|
|
51
|
+
# API for Keys
|
52
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/#tag/Keys
|
53
|
+
def keys
|
54
|
+
Keys.new @opt
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
class Keys < Base
|
60
|
+
def initialize opt
|
61
|
+
super
|
62
|
+
end
|
63
|
+
|
64
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/signMetadata
|
65
|
+
def sign_metadata(wid, role, index, pass, metadata)
|
66
|
+
payload = { passphrase: pass }
|
67
|
+
payload[:metadata] = metadata if metadata
|
68
|
+
|
69
|
+
self.class.post("/wallets/#{wid}/signatures/#{role}/#{index}",
|
70
|
+
:body => payload.to_json,
|
71
|
+
:headers => { 'Content-Type' => 'application/json',
|
72
|
+
'Accept' => 'application/octet-stream'} )
|
73
|
+
end
|
74
|
+
|
75
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/#operation/getWalletKey
|
76
|
+
def get_public_key(wid, role, index)
|
77
|
+
self.class.get("/wallets/#{wid}/keys/#{role}/#{index}")
|
78
|
+
end
|
79
|
+
|
51
80
|
end
|
52
81
|
|
53
82
|
# API for Wallets
|
@@ -158,13 +187,26 @@ module CardanoWallet
|
|
158
187
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/selectCoins
|
159
188
|
#
|
160
189
|
# @example
|
161
|
-
# random(wid, {
|
190
|
+
# random(wid, [{addr1: 1000000}, {addr2: 1000000}])
|
162
191
|
def random(wid, payments)
|
163
192
|
payments_formatted = Utils.format_payments(payments)
|
164
193
|
self.class.post("/wallets/#{wid}/coin-selections/random",
|
165
194
|
:body => {:payments => payments_formatted}.to_json,
|
166
195
|
:headers => { 'Content-Type' => 'application/json' })
|
167
196
|
end
|
197
|
+
|
198
|
+
# Coin selection -> Delegation action
|
199
|
+
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/selectCoins
|
200
|
+
#
|
201
|
+
# @example
|
202
|
+
# random(wid, {action: "join", pool: "poolid"})
|
203
|
+
# random(wid, {action: "quit"})
|
204
|
+
def random_deleg(wid, deleg_action)
|
205
|
+
payments_formatted = Utils.verify_param_is_hash!(deleg_action)
|
206
|
+
self.class.post("/wallets/#{wid}/coin-selections/random",
|
207
|
+
:body => {:delegation_action => deleg_action}.to_json,
|
208
|
+
:headers => { 'Content-Type' => 'application/json' })
|
209
|
+
end
|
168
210
|
end
|
169
211
|
|
170
212
|
# API for Transactions
|
@@ -194,19 +236,21 @@ module CardanoWallet
|
|
194
236
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransaction
|
195
237
|
# @param wid [String] source wallet id
|
196
238
|
# @param passphrase [String] source wallet's passphrase
|
197
|
-
# @param payments [
|
239
|
+
# @param payments [Array of Hashes] addres, amount pair
|
198
240
|
# @param withdrawal [String or Array] 'self' or mnemonic sentence
|
199
241
|
# @param metadata [Hash] special metadata JSON subset format (cf: https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransaction)
|
242
|
+
# @param ttl [Int] transaction's time-to-live in seconds
|
200
243
|
#
|
201
244
|
# @example
|
202
|
-
# create(wid, passphrase, {addr1: 1000000}, 'self', {"1": "abc"})
|
203
|
-
def create(wid, passphrase, payments, withdrawal = nil, metadata = nil)
|
245
|
+
# create(wid, passphrase, [{addr1: 1000000}, {addr2: 1000000}], 'self', {"1": "abc"}, ttl = 10)
|
246
|
+
def create(wid, passphrase, payments, withdrawal = nil, metadata = nil, ttl = nil)
|
204
247
|
payments_formatted = Utils.format_payments(payments)
|
205
248
|
payload = { :payments => payments_formatted,
|
206
249
|
:passphrase => passphrase
|
207
250
|
}
|
208
251
|
payload[:withdrawal] = withdrawal if withdrawal
|
209
252
|
payload[:metadata] = metadata if metadata
|
253
|
+
payload[:time_to_live] = { quantity: ttl, unit: "second" } if ttl
|
210
254
|
|
211
255
|
self.class.post("/wallets/#{wid}/transactions",
|
212
256
|
:body => payload.to_json,
|
@@ -217,13 +261,14 @@ module CardanoWallet
|
|
217
261
|
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransactionFee
|
218
262
|
#
|
219
263
|
# @example
|
220
|
-
# payment_fees(wid, {addr1: 1000000}, {"1": "abc"})
|
221
|
-
def payment_fees(wid, payments, withdrawal = nil, metadata = nil)
|
264
|
+
# payment_fees(wid, [{addr1: 1000000}, {addr2: 1000000}], {"1": "abc"}, ttl = 10)
|
265
|
+
def payment_fees(wid, payments, withdrawal = nil, metadata = nil, ttl = nil)
|
222
266
|
payments_formatted = Utils.format_payments(payments)
|
223
267
|
payload = { :payments => payments_formatted }
|
224
268
|
|
225
269
|
payload[:withdrawal] = withdrawal if withdrawal
|
226
270
|
payload[:metadata] = metadata if metadata
|
271
|
+
payload[:time_to_live] = { quantity: ttl, unit: "second" } if ttl
|
227
272
|
|
228
273
|
self.class.post("/wallets/#{wid}/payment-fees",
|
229
274
|
:body => payload.to_json,
|
data/lib/cardano_wallet/utils.rb
CHANGED
@@ -5,13 +5,24 @@ module CardanoWallet
|
|
5
5
|
raise ArgumentError, "argument should be Hash" unless param.is_a?(Hash)
|
6
6
|
end
|
7
7
|
|
8
|
+
def self.verify_param_is_array!(param)
|
9
|
+
raise ArgumentError, "argument should be Array" unless param.is_a?(Array)
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# @param payments [Array of Hashes] - [{addr1: 1}, {addr2: 2}]
|
14
|
+
# @return [Array of Hashes] - [{:address=>"addr1", :amount=>{:quantity=>1, :unit=>"lovelace"}}, {:address=>"addr2", :amount=>{:quantity=>2, :unit=>"lovelace"}}]
|
8
15
|
def self.format_payments(payments)
|
9
|
-
|
10
|
-
payments.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
verify_param_is_array!(payments)
|
17
|
+
raise ArgumentError, "argument should be Array of single Hashes" unless payments.all?{|p| p.size == 1 && p.is_a?(Hash)}
|
18
|
+
payments.map do |p|
|
19
|
+
a = p.collect do |addr, amt|
|
20
|
+
{:address => addr.to_s,
|
21
|
+
:amount => {:quantity => amt.to_i,
|
22
|
+
:unit => "lovelace"}
|
23
|
+
}
|
24
|
+
end.flatten
|
25
|
+
Hash[*a]
|
15
26
|
end
|
16
27
|
end
|
17
28
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cardano_wallet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Stachyra
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
147
|
- !ruby/object:Gem::Version
|
148
148
|
version: '0'
|
149
149
|
requirements: []
|
150
|
-
rubygems_version: 3.1.
|
150
|
+
rubygems_version: 3.1.4
|
151
151
|
signing_key:
|
152
152
|
specification_version: 4
|
153
153
|
summary: Ruby wrapper over cardano-wallet.
|