cardano_wallet 0.1.7 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e71c5cdb72ca953d4289d8d343e1e769c0cd0cb24f6bc51c8487fd189c7dff2
4
- data.tar.gz: 4c4712df87921f80adf52b49db9cb8752f397b9fef31c3dd10fe895e18caa29b
3
+ metadata.gz: b3d493df353517eb41d713b9b12973fadd1b56da5f17f8a15763181285d13a82
4
+ data.tar.gz: 6848865dea8cd920f95d0268065293aba195e67e4cfd1b1324a62e355e119347
5
5
  SHA512:
6
- metadata.gz: 515592573f6cdff23f85e26b32430f2913192d04d841dd23f1e1b4c2b5a11c698861f6b5c2039052ce0f6327f82c7c523cf907feb67f8a1a5b3195c1fa27b73c
7
- data.tar.gz: 3e8f0e8a30a9eda51a229c202d08adf6d91f7a67a58dbb933f1c50df83182e9b4eb448352ff9e4d5790913ecfe297f753831496807636c5ebac75cd8d065dc45
6
+ metadata.gz: d02a807c61dad05dd08fc300990702a10ed631a25268735189772e4f54dabb411d4ab5d2688e10333b9d88558a881de1eaf1545cd3a9547cc29bf4f36116f909
7
+ data.tar.gz: 4007b0db748e9f88244257e30a9a939dea56e213eec84fce632b603c1d2dbfb55e73222db8f13bb6ab6855e3aa0e8c5e3c575f6ce89d55d7cb51c063a5dffb45
@@ -12,7 +12,7 @@ jobs:
12
12
  steps:
13
13
  - uses: actions/checkout@v2
14
14
  - name: Set up cardano-wallet
15
- run: NODE_CONFIG_PATH=`pwd`/spec/shelley-testnet docker-compose -f docker-compose-shelley.yml up --detach
15
+ run: NODE_CONFIG_PATH=`pwd`/spec/testnet docker-compose -f docker-compose-shelley.yml up --detach
16
16
  - name: Set up Ruby
17
17
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
18
18
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
@@ -25,10 +25,10 @@ jobs:
25
25
  - name: Wait until node is synced
26
26
  run: bundle exec rake wait_until_node_synced
27
27
  - name: Run all tests
28
- run: bundle exec rspec
28
+ run: bundle exec rspec .
29
29
  env:
30
30
  CI: true
31
31
  CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
32
32
  NETWORK: testnet
33
33
  WALLET: dev-master-shelley
34
- NODE: master
34
+ NODE: 1.21.1
@@ -21,7 +21,7 @@ jobs:
21
21
  steps:
22
22
  - uses: actions/checkout@v2
23
23
  - name: Set up cardano-wallet
24
- run: NODE_CONFIG_PATH=`pwd`/spec/shelley-testnet docker-compose -f docker-compose-shelley.yml up --detach
24
+ run: NODE_CONFIG_PATH=`pwd`/spec/testnet docker-compose -f docker-compose-shelley.yml up --detach
25
25
  - name: Set up Ruby
26
26
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
27
27
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
@@ -38,4 +38,4 @@ jobs:
38
38
  CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
39
39
  NETWORK: testnet
40
40
  WALLET: dev-master-shelley
41
- NODE: master
41
+ NODE: 1.21.1
data/README.md CHANGED
@@ -65,7 +65,6 @@ CW = CardanoWallet.new
65
65
  BYRON = CW.byron
66
66
  SHELLEY = CW.shelley
67
67
  MISC = CW.misc
68
- PROXY = CW.proxy
69
68
 
70
69
  #Byron
71
70
  BYRON.wallets.list.each_with_index do |wal, i|
@@ -82,9 +81,8 @@ SHELLEY.wallets.get(w['id'])
82
81
  #Misc
83
82
  MISC.network.information
84
83
  MISC.network.clock
85
-
86
- #Proxy
87
- PROXY.submit_external_transaction(File.new("/tmp/blob.bin").read)
84
+ MISC.proxy.submit_external_transaction(File.new("/tmp/blob.bin").read)
85
+ MISC.utils.addresses("addr_test1vqrlltfahghjxl5sy5h5mvfrrlt6me5fqphhwjqvj5jd88cccqcek")
88
86
  ```
89
87
 
90
88
  Refer to [documentation](https://rubydoc.info/gems/cardano_wallet) for more details.
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'rake', '~> 12.3'
33
33
  spec.add_development_dependency 'rspec', '~> 3.7'
34
34
  spec.add_development_dependency 'bip_mnemonic', '~> 0.0.4'
35
- spec.add_development_dependency 'codecov'
35
+ spec.add_development_dependency 'codecov', '~> 0.2.8'
36
36
  spec.add_development_dependency 'simplecov'
37
37
 
38
38
  end
data/dev CHANGED
@@ -1 +1,8 @@
1
- NETWORK=testnet WALLET=dev-master-byron NODE=master docker-compose $1
1
+ #!/bin/sh
2
+
3
+ NETWORK=testnet \
4
+ WALLET=dev-master-shelley \
5
+ NODE=1.20.0 \
6
+ NODE_CONFIG_PATH=`pwd`/spec/testnet \
7
+ docker-compose -f docker-compose-shelley.yml \
8
+ $1 $2 $3 $4
@@ -7,7 +7,7 @@ services:
7
7
  - node-db:/data
8
8
  - node-ipc:/ipc
9
9
  - ${NODE_CONFIG_PATH}:/config
10
- command: run --socket-path /ipc/node.socket --config /config/shelley_testnet-config.json --topology /config/shelley_testnet-topology.json --database-path /data
10
+ command: run --socket-path /ipc/node.socket --config /config/${NETWORK}-config.json --topology /config/${NETWORK}-topology.json --database-path /data
11
11
  restart: on-failure
12
12
 
13
13
  cardano-wallet:
@@ -18,7 +18,7 @@ services:
18
18
  - ${NODE_CONFIG_PATH}:/config
19
19
  ports:
20
20
  - 8090:8090
21
- command: serve --testnet /config/shelley_testnet-genesis.json --node-socket /ipc/node.socket --database /wallet-db --listen-address 0.0.0.0
21
+ command: serve --testnet /config/${NETWORK}-byron-genesis.json --node-socket /ipc/node.socket --database /wallet-db --listen-address 0.0.0.0
22
22
  restart: on-failure
23
23
 
24
24
  volumes:
@@ -6,7 +6,6 @@ require_relative "cardano_wallet/utils"
6
6
  require_relative "cardano_wallet/shelley"
7
7
  require_relative "cardano_wallet/byron"
8
8
  require_relative "cardano_wallet/misc"
9
- require_relative "cardano_wallet/proxy"
10
9
 
11
10
  module CardanoWallet
12
11
  def self.new(options = {})
@@ -13,7 +13,11 @@ module CardanoWallet
13
13
  opt[:url] ||= "#{opt[:protocol]}://#{opt[:host]}:#{opt[:port]}/v2"
14
14
  opt[:cacert] ||= ''
15
15
  opt[:pem] ||= ''
16
+ opt[:timeout] ||= -1
16
17
  self.class.base_uri opt[:url]
18
+ unless(opt[:timeout] == -1)
19
+ self.class.default_timeout(opt[:timeout].to_i)
20
+ end
17
21
 
18
22
  unless opt[:cacert].empty?
19
23
  ENV['SSL_CERT_FILE'] = opt[:cacert]
@@ -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, {address1: 123, address2: 456})
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 [Hash] addres, amount pair
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",
@@ -15,6 +15,43 @@ module CardanoWallet
15
15
  def network
16
16
  Network.new @opt
17
17
  end
18
+
19
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Utils
20
+ def utils
21
+ Utils.new @opt
22
+ end
23
+
24
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Proxy
25
+ def proxy
26
+ Proxy.new @opt
27
+ end
28
+
29
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Settings
30
+ def settings
31
+ Settings.new @opt
32
+ end
33
+ end
34
+
35
+ # API for Network
36
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Settings
37
+ class Settings < Base
38
+ def initialize opt
39
+ super
40
+ end
41
+
42
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getSettings
43
+ def get
44
+ self.class.get("/settings")
45
+ end
46
+
47
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/putSettings
48
+ def update(params)
49
+ CardanoWallet::Utils.verify_param_is_hash!(params)
50
+ self.class.put("/settings",
51
+ :body => {"settings" => params}.to_json,
52
+ :headers => { 'Content-Type' => 'application/json' }
53
+ )
54
+ end
18
55
  end
19
56
 
20
57
  # API for Network
@@ -43,5 +80,34 @@ module CardanoWallet
43
80
  end
44
81
 
45
82
  end
83
+
84
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Utils
85
+ class Utils < Base
86
+ def initialize opt
87
+ super
88
+ end
89
+
90
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/inspectAddress
91
+ def addresses(address_id)
92
+ self.class.get("/addresses/#{address_id}")
93
+ end
94
+
95
+ end
96
+
97
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Proxy
98
+ class Proxy < Base
99
+ def initialize opt
100
+ super
101
+ end
102
+
103
+ # Submit a transaction that was created and signed outside of cardano-wallet.
104
+ # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postExternalTransaction
105
+ # @param binary_blob [String] Signed transaction message binary blob.
106
+ def submit_external_transaction(binary_blob)
107
+ self.class.post("/proxy/transactions",
108
+ :body => binary_blob,
109
+ :headers => { 'Content-Type' => 'application/octet-stream' })
110
+ end
111
+ end
46
112
  end
47
113
  end
@@ -158,7 +158,7 @@ module CardanoWallet
158
158
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/selectCoins
159
159
  #
160
160
  # @example
161
- # random(wid, {address1: 123, address2: 456})
161
+ # random(wid, [{addr1: 1000000}, {addr2: 1000000}])
162
162
  def random(wid, payments)
163
163
  payments_formatted = Utils.format_payments(payments)
164
164
  self.class.post("/wallets/#{wid}/coin-selections/random",
@@ -194,18 +194,22 @@ module CardanoWallet
194
194
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransaction
195
195
  # @param wid [String] source wallet id
196
196
  # @param passphrase [String] source wallet's passphrase
197
- # @param payments [Hash] addres, amount pair
198
- # @param q [Hash] query param (currently only withdrawRewards = true | false)
197
+ # @param payments [Array of Hashes] addres, amount pair
198
+ # @param withdrawal [String or Array] 'self' or mnemonic sentence
199
+ # @param metadata [Hash] special metadata JSON subset format (cf: https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransaction)
199
200
  #
200
201
  # @example
201
- # create(wid, passphrase, {addr1: 1000000}, q)
202
- def create(wid, passphrase, payments, q = {})
202
+ # create(wid, passphrase, [{addr1: 1000000}, {addr2: 1000000}], 'self', {"1": "abc"})
203
+ def create(wid, passphrase, payments, withdrawal = nil, metadata = nil)
203
204
  payments_formatted = Utils.format_payments(payments)
204
- q.empty? ? query = '' : query = Utils.to_query(q)
205
- self.class.post("/wallets/#{wid}/transactions#{query}",
206
- :body => { :payments => payments_formatted,
207
- :passphrase => passphrase
208
- }.to_json,
205
+ payload = { :payments => payments_formatted,
206
+ :passphrase => passphrase
207
+ }
208
+ payload[:withdrawal] = withdrawal if withdrawal
209
+ payload[:metadata] = metadata if metadata
210
+
211
+ self.class.post("/wallets/#{wid}/transactions",
212
+ :body => payload.to_json,
209
213
  :headers => { 'Content-Type' => 'application/json' } )
210
214
  end
211
215
 
@@ -213,12 +217,16 @@ module CardanoWallet
213
217
  # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransactionFee
214
218
  #
215
219
  # @example
216
- # payment_fees(wid, {addr1: 1000000})
217
- def payment_fees(wid, payments, q = {})
220
+ # payment_fees(wid, [{addr1: 1000000}, {addr2: 1000000}], {"1": "abc"})
221
+ def payment_fees(wid, payments, withdrawal = nil, metadata = nil)
218
222
  payments_formatted = Utils.format_payments(payments)
219
- q.empty? ? query = '' : query = Utils.to_query(q)
220
- self.class.post("/wallets/#{wid}/payment-fees#{query}",
221
- :body => { :payments => payments_formatted }.to_json,
223
+ payload = { :payments => payments_formatted }
224
+
225
+ payload[:withdrawal] = withdrawal if withdrawal
226
+ payload[:metadata] = metadata if metadata
227
+
228
+ self.class.post("/wallets/#{wid}/payment-fees",
229
+ :body => payload.to_json,
222
230
  :headers => { 'Content-Type' => 'application/json' } )
223
231
  end
224
232
 
@@ -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
- verify_param_is_hash!(payments)
10
- payments.collect do |addr, amt|
11
- {:address => addr.to_s,
12
- :amount => {:quantity => amt.to_i,
13
- :unit => "lovelace"}
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
 
@@ -1,3 +1,3 @@
1
1
  module CardanoWallet
2
- VERSION = "0.1.7"
2
+ VERSION = "0.2.2"
3
3
  end
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.1.7
4
+ version: 0.2.2
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-07-23 00:00:00.000000000 Z
11
+ date: 2020-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: codecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.2.8
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.2.8
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -117,12 +117,10 @@ files:
117
117
  - cardano_wallet.gemspec
118
118
  - dev
119
119
  - docker-compose-shelley.yml
120
- - docker-compose.yml
121
120
  - lib/cardano_wallet.rb
122
121
  - lib/cardano_wallet/base.rb
123
122
  - lib/cardano_wallet/byron.rb
124
123
  - lib/cardano_wallet/misc.rb
125
- - lib/cardano_wallet/proxy.rb
126
124
  - lib/cardano_wallet/shelley.rb
127
125
  - lib/cardano_wallet/utils.rb
128
126
  - lib/cardano_wallet/version.rb
@@ -149,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
147
  - !ruby/object:Gem::Version
150
148
  version: '0'
151
149
  requirements: []
152
- rubygems_version: 3.0.3
150
+ rubygems_version: 3.1.2
153
151
  signing_key:
154
152
  specification_version: 4
155
153
  summary: Ruby wrapper over cardano-wallet.
@@ -1,38 +0,0 @@
1
- version: "3.5"
2
-
3
- services:
4
- cardano-node:
5
- image: inputoutput/cardano-node:${NODE}
6
- environment:
7
- NETWORK:
8
- volumes:
9
- - node-${NETWORK}-db:/data
10
- - node-ipc:/ipc
11
- - node-config:/nix/store
12
- restart: on-failure
13
-
14
- cardano-wallet:
15
- image: inputoutput/cardano-wallet:${WALLET}
16
- volumes:
17
- - wallet-${NETWORK}-db:/wallet-db
18
- - node-ipc:/ipc
19
- - node-config:/config
20
- ports:
21
- - 8090:8090
22
- entrypoint: []
23
- command: bash -c "
24
- ([[ $$NETWORK == \"mainnet\" ]] && $$CMD --mainnet) ||
25
- ([[ $$NETWORK == \"testnet\" ]] && $$CMD --testnet /config/*testnet-genesis.json)
26
- "
27
- environment:
28
- CMD: "cardano-wallet-byron serve --node-socket /ipc/node.socket --database /wallet-db --listen-address 0.0.0.0"
29
- NETWORK:
30
- restart: on-failure
31
-
32
- volumes:
33
- node-mainnet-db:
34
- node-testnet-db:
35
- wallet-mainnet-db:
36
- wallet-testnet-db:
37
- node-ipc:
38
- node-config:
@@ -1,26 +0,0 @@
1
- module CardanoWallet
2
- module Proxy
3
-
4
- # Call API for Proxy
5
- # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Proxy
6
- def self.new(opt)
7
- Init.new opt
8
- end
9
-
10
- class Init < Base
11
- def initialize opt
12
- super
13
- end
14
-
15
- # Submit a transaction that was created and signed outside of cardano-wallet.
16
- # @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postExternalTransaction
17
- # @param binary_blob [String] Signed transaction message binary blob.
18
- def submit_external_transaction(binary_blob)
19
- self.class.post("/proxy/transactions",
20
- :body => binary_blob,
21
- :headers => { 'Content-Type' => 'application/octet-stream' })
22
- end
23
- end
24
-
25
- end
26
- end