cardano-up 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cardano-up.rb CHANGED
@@ -8,13 +8,18 @@ require 'file-tail'
8
8
  require 'json'
9
9
  require 'zlib'
10
10
  require 'zip'
11
+ require 'socket'
12
+ require 'timeout'
11
13
 
12
14
  require 'cardano-up/version'
13
15
  require 'cardano-up/err'
14
16
  require 'cardano-up/utils'
15
17
  require 'cardano-up/tar'
16
- require 'cardano-up/install'
17
- require 'cardano-up/start'
18
+ require 'cardano-up/bins'
19
+ require 'cardano-up/configs'
20
+ require 'cardano-up/launcher'
21
+ require 'cardano-up/session'
22
+ require 'cardano-up/ping'
18
23
  require 'cardano-up/tail'
19
24
 
20
25
  # Cardano Up!
@@ -22,7 +27,6 @@ require 'cardano-up/tail'
22
27
  module CardanoUp
23
28
  CONFIGS_BASE_URL = 'https://book.world.dev.cardano.org/environments'
24
29
  BINS_BASE_URL = 'https://github.com/input-output-hk/cardano-wallet'
25
- HYDRA_BASE_URL = 'https://hydra.iohk.io/job/Cardano/cardano-wallet'
26
30
  ENVS = %w[mainnet preview preprod shelley-qa
27
31
  staging vasil-qa vasil-dev mixed testnet].freeze
28
32
  CONFIG_FILES = ['alonzo-genesis.json', 'byron-genesis.json', 'shelley-genesis.json',
@@ -74,24 +78,24 @@ module CardanoUp
74
78
  c = if configured?
75
79
  CardanoUp.config
76
80
  else
77
- { 'bin_dir' => File.join(@base_dir, 'bins'),
78
- 'state_dir' => File.join(@base_dir, 'state'),
79
- 'log_dir' => File.join(@base_dir, 'state'),
80
- 'config_dir' => File.join(@base_dir, 'configs') }
81
+ { bin_dir: File.join(@base_dir, 'bins'),
82
+ state_dir: File.join(@base_dir, 'state'),
83
+ log_dir: File.join(@base_dir, 'state'),
84
+ config_dir: File.join(@base_dir, 'configs') }
81
85
  end
82
- c['bin_dir'] = bin_dir if bin_dir
83
- c['state_dir'] = state_dir if state_dir
84
- c['log_dir'] = logs_dir if logs_dir
85
- c['config_dir'] = config_dir if config_dir
86
- File.write(@cardano_up_config, JSON.pretty_generate(c))
87
- JSON.parse(File.read(@cardano_up_config))
86
+ c[:bin_dir] = bin_dir if bin_dir
87
+ c[:state_dir] = state_dir if state_dir
88
+ c[:log_dir] = logs_dir if logs_dir
89
+ c[:config_dir] = config_dir if config_dir
90
+ CardanoUp::Utils.to_json(@cardano_up_config, c)
91
+ CardanoUp::Utils.from_json(@cardano_up_config)
88
92
  end
89
93
 
90
94
  # Get config values
91
95
  def self.config
92
96
  raise CardanoUp::ConfigNotSetError unless configured?
93
97
 
94
- JSON.parse(File.read(@cardano_up_config))
98
+ CardanoUp::Utils.from_json(@cardano_up_config)
95
99
  end
96
100
 
97
101
  # Remove configuration file
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cardano-up
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Stachyra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-09 00:00:00.000000000 Z
11
+ date: 2023-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.6.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.6.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: file-tail
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: httparty
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.20.0
47
+ version: 0.21.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.20.0
54
+ version: 0.21.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubyzip
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.3.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.3.2
69
69
  - !ruby/object:Gem::Dependency
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.36'
103
+ version: '1.46'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1.36'
110
+ version: '1.46'
111
111
  description: |-
112
112
  Cardano Up lets you get all essential Cardano
113
113
  tools on your system: cardano-node, cardano-cli, cardano-wallet,
@@ -127,9 +127,12 @@ files:
127
127
  - bin/rebuild
128
128
  - bin/setup
129
129
  - lib/cardano-up.rb
130
+ - lib/cardano-up/bins.rb
131
+ - lib/cardano-up/configs.rb
130
132
  - lib/cardano-up/err.rb
131
- - lib/cardano-up/install.rb
132
- - lib/cardano-up/start.rb
133
+ - lib/cardano-up/launcher.rb
134
+ - lib/cardano-up/ping.rb
135
+ - lib/cardano-up/session.rb
133
136
  - lib/cardano-up/tail.rb
134
137
  - lib/cardano-up/tar.rb
135
138
  - lib/cardano-up/utils.rb
@@ -159,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
162
  - !ruby/object:Gem::Version
160
163
  version: '0'
161
164
  requirements: []
162
- rubygems_version: 3.0.3.1
165
+ rubygems_version: 3.3.7
163
166
  signing_key:
164
167
  specification_version: 4
165
168
  summary: Lightweight manager for Cardano binaries and configs.
@@ -1,248 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CardanoUp
4
- ##
5
- # Start cardano-node and cardano-wallet on your system.
6
- #
7
- # For Linux and MacOS it will attempt to start separate screen sessions for
8
- # wallet and node respectively, therefore 'screen' tool is required on your system.
9
- # @see https://www.gnu.org/software/screen/
10
- # If screen is not present you can install it using your package manager for instance:
11
- # # MacOS:
12
- # brew install screen
13
- # # Linux:
14
- # sudo apt-get install screen
15
- #
16
- # For Windows it will attepmt to install cardano-node and cardano-wallet as Windows services
17
- # using 'nssm' tool.
18
- # @see https://nssm.cc/
19
- # Nssm can be installed via choco package manager:
20
- # choco install nssm
21
- module Start
22
- # Prepare configuration for wallet and node to be started
23
- # @param env [Hash] provide env and wallet_port, e.g. { env: 'mainnet', wallet_port: '8090' }
24
- # @raise CardanoUp::EnvNotSupportedError
25
- # @raise CardanoUp::WalletPortError
26
- def self.prepare_configuration(opt = { env: 'mainnet', wallet_port: '8090' })
27
- env = opt[:env]
28
- raise CardanoUp::EnvNotSupportedError, env unless CardanoUp::ENVS.include? env
29
-
30
- wallet_port = opt[:wallet_port]
31
- raise CardanoUp::WalletPortError if wallet_port.nil? || wallet_port.empty?
32
-
33
- token_metadata_server = env == 'mainnet' ? CardanoUp::MAINNET_TOKEN_SERVER : CardanoUp::TESTNET_TOKEN_SERVER
34
-
35
- CardanoUp.configure_default unless CardanoUp.configured?
36
- configs = CardanoUp.config
37
- bin_dir = configs['bin_dir']
38
- config_dir = File.join(configs['config_dir'], env)
39
- log_dir = File.join(configs['log_dir'], env)
40
- state_dir = File.join(configs['state_dir'], env)
41
- wallet_db_dir = File.join(state_dir, 'wallet-db')
42
- node_db_dir = File.join(state_dir, 'node-db')
43
- [bin_dir, config_dir, log_dir, state_dir, wallet_db_dir, node_db_dir].each do |dir|
44
- FileUtils.mkdir_p(dir)
45
- end
46
-
47
- node_socket = if CardanoUp::Utils.win?
48
- "\\\\.\\pipe\\cardano-node-#{env}"
49
- else
50
- File.join(state_dir, 'node.socket')
51
- end
52
- network = env == 'mainnet' ? '--mainnet' : "--testnet #{config_dir}/byron-genesis.json"
53
-
54
- {
55
- env: env,
56
- wallet_port: wallet_port,
57
- token_metadata_server: token_metadata_server,
58
- bin_dir: bin_dir,
59
- config_dir: config_dir,
60
- log_dir: log_dir,
61
- state_dir: state_dir,
62
- wallet_db_dir: wallet_db_dir,
63
- node_db_dir: node_db_dir,
64
- node_socket: node_socket,
65
- network: network
66
- }
67
- end
68
-
69
- # @param configuration [Hash] output of prepare_configuration
70
- def self.start_node(configuration)
71
- env = configuration[:env]
72
- bin_dir = configuration[:bin_dir]
73
- config_dir = configuration[:config_dir]
74
- log_dir = configuration[:log_dir]
75
- node_db_dir = configuration[:node_db_dir]
76
- node_socket = configuration[:node_socket]
77
-
78
- exe = CardanoUp::Utils.win? ? '.exe' : ''
79
- version = CardanoUp::Utils.cmd "#{bin_dir}/cardano-node#{exe} version"
80
-
81
- if CardanoUp::Utils.win?
82
- # Turn off p2p for Windows
83
- # TODO: remove after https://github.com/input-output-hk/ouroboros-network/issues/3968 released
84
- config_win = JSON.parse(File.read("#{config_dir}/config.json"))
85
- config_win['EnableP2P'] = false
86
- File.write("#{config_dir}/config.json", JSON.pretty_generate(config_win))
87
- topology = %({
88
- "Producers": [
89
- {
90
- "addr": "#{env}-node.world.dev.cardano.org",
91
- "port": 30002,
92
- "valency": 2
93
- }
94
- ]
95
- })
96
- File.write("#{config_dir}/topology.json", topology)
97
-
98
- # create cardano-node.bat file
99
- node_cmd = ["#{bin_dir}/cardano-node.exe run",
100
- "--config #{config_dir}/config.json",
101
- "--topology #{config_dir}/topology.json",
102
- "--database-path #{node_db_dir}",
103
- "--socket-path #{node_socket}"].join(' ')
104
- File.write("#{bin_dir}/cardano-node.bat", node_cmd)
105
- node_service = "cardano-node-#{env}"
106
- install_node = "nssm install #{node_service} #{bin_dir}/cardano-node.bat"
107
- log_stdout_node = "nssm set #{node_service} AppStdout #{log_dir}/node.log"
108
- log_stderr_node = "nssm set #{node_service} AppStderr #{log_dir}/node.log"
109
- start_node = "nssm start #{node_service}"
110
-
111
- CardanoUp::Utils.cmd install_node
112
- CardanoUp::Utils.cmd log_stdout_node
113
- CardanoUp::Utils.cmd log_stderr_node
114
- CardanoUp::Utils.cmd start_node
115
- else
116
- node_cmd = ["#{bin_dir}/cardano-node run",
117
- "--config #{config_dir}/config.json",
118
- "--topology #{config_dir}/topology.json",
119
- "--database-path #{node_db_dir}",
120
- "--socket-path #{node_socket}"].join(' ')
121
- node_service = "NODE_#{env}"
122
- CardanoUp::Utils.cmd "screen -dmS #{node_service} -L -Logfile #{log_dir}/node.log #{node_cmd}"
123
- end
124
-
125
- {
126
- node: {
127
- service: node_service,
128
- network: env,
129
- version: version,
130
- log: "#{log_dir}/node.log",
131
- db_dir: node_db_dir,
132
- socket_path: node_socket,
133
- protocol_magic: get_protocol_magic(config_dir),
134
- bin: node_cmd.split.first,
135
- cmd: node_cmd
136
- }
137
- }
138
- end
139
-
140
- # @param configuration [Hash] output of prepare_configuration
141
- def self.start_wallet(configuration)
142
- env = configuration[:env]
143
- wallet_port = configuration[:wallet_port]
144
- token_metadata_server = configuration[:token_metadata_server]
145
- bin_dir = configuration[:bin_dir]
146
- log_dir = configuration[:log_dir]
147
- wallet_db_dir = configuration[:wallet_db_dir]
148
- node_socket = configuration[:node_socket]
149
- network = configuration[:network]
150
-
151
- exe = CardanoUp::Utils.win? ? '.exe' : ''
152
- version = CardanoUp::Utils.cmd "#{bin_dir}/cardano-wallet#{exe} version"
153
-
154
- if CardanoUp::Utils.win?
155
-
156
- # create cardano-wallet.bat file
157
- wallet_cmd = ["#{bin_dir}/cardano-wallet.exe serve",
158
- "--port #{wallet_port}",
159
- "--node-socket #{node_socket}",
160
- network.to_s,
161
- "--database #{wallet_db_dir}",
162
- "--token-metadata-server #{token_metadata_server}"].join(' ')
163
- File.write("#{bin_dir}/cardano-wallet.bat", wallet_cmd)
164
- wallet_service = "cardano-wallet-#{env}"
165
- install_wallet = "nssm install #{wallet_service} #{bin_dir}/cardano-wallet.bat"
166
- log_stdout_wallet = "nssm set #{wallet_service} AppStdout #{log_dir}/wallet.log"
167
- log_stderr_wallet = "nssm set #{wallet_service} AppStderr #{log_dir}/wallet.log"
168
- start_wallet = "nssm start #{wallet_service}"
169
-
170
- CardanoUp::Utils.cmd install_wallet
171
- CardanoUp::Utils.cmd log_stdout_wallet
172
- CardanoUp::Utils.cmd log_stderr_wallet
173
- CardanoUp::Utils.cmd start_wallet
174
- else
175
- wallet_cmd = ["#{bin_dir}/cardano-wallet serve",
176
- "--port #{wallet_port}",
177
- "--node-socket #{node_socket}",
178
- network.to_s,
179
- "--database #{wallet_db_dir}",
180
- "--token-metadata-server #{token_metadata_server}"].join(' ')
181
- wallet_service = "WALLET_#{env}"
182
- CardanoUp::Utils.cmd "screen -dmS #{wallet_service} -L -Logfile #{log_dir}/wallet.log #{wallet_cmd}"
183
- end
184
-
185
- {
186
- wallet: {
187
- service: wallet_service,
188
- network: env,
189
- version: version,
190
- log: "#{log_dir}/wallet.log",
191
- db_dir: wallet_db_dir,
192
- port: wallet_port.to_i,
193
- host: "http://localhost:#{wallet_port}/v2",
194
- bin: wallet_cmd.split.first,
195
- cmd: wallet_cmd
196
- }
197
- }
198
- end
199
-
200
- # @param configuration [Hash] output of prepare_configuration
201
- def self.start_node_and_wallet(configuration)
202
- cn = start_node(configuration)
203
- cw = start_wallet(configuration)
204
- cn.merge(cw)
205
- end
206
-
207
- # @raise CardanoUp::EnvNotSupportedError
208
- def self.stop_node(env)
209
- raise CardanoUp::EnvNotSupportedError, env unless CardanoUp::ENVS.include? env
210
-
211
- if CardanoUp::Utils.win?
212
- CardanoUp::Utils.cmd "nssm stop cardano-node-#{env}"
213
- CardanoUp::Utils.cmd "nssm remove cardano-node-#{env} confirm"
214
- else
215
- CardanoUp::Utils.cmd "screen -S NODE_#{env} -X at '0' stuff '^C'"
216
- CardanoUp::Utils.cmd "screen -XS NODE_#{env} quit"
217
- end
218
- end
219
-
220
- # @raise CardanoUp::EnvNotSupportedError
221
- def self.stop_wallet(env)
222
- raise CardanoUp::EnvNotSupportedError, env unless CardanoUp::ENVS.include? env
223
-
224
- if CardanoUp::Utils.win?
225
- CardanoUp::Utils.cmd "nssm stop cardano-wallet-#{env}"
226
- CardanoUp::Utils.cmd "nssm remove cardano-wallet-#{env} confirm"
227
- else
228
- CardanoUp::Utils.cmd "screen -S WALLET_#{env} -X at '0' stuff '^C'"
229
- CardanoUp::Utils.cmd "screen -XS WALLET_#{env} quit"
230
- end
231
- end
232
-
233
- # @raise CardanoUp::EnvNotSupportedError
234
- def self.stop_node_and_wallet(env)
235
- stop_wallet(env)
236
- stop_node(env)
237
- end
238
-
239
- ##
240
- # Get protocol magic from config's byron-genesis.json
241
- def get_protocol_magic(config)
242
- byron_genesis = JSON.parse(File.read(File.join(config, 'byron-genesis.json')))
243
- byron_genesis['protocolConsts']['protocolMagic'].to_i
244
- end
245
- module_function :get_protocol_magic
246
- private_class_method :get_protocol_magic
247
- end
248
- end