Class: Reth::Config
- Inherits:
-
Object
- Object
- Reth::Config
- Defined in:
- lib/reth/config.rb
Constant Summary collapse
- DEFAULT_DATA_DIR =
File.join(Dir.home, '.config', 'reth')
- CONFIG_FILE =
'config.json'
- GENESIS_FILE =
'genesis.json'
- Defaults =
Hashie::Mash.new({ p2p: { listen_host: '0.0.0.0', listen_port: 13333, num_peers: 10 }, discovery: { listen_host: '0.0.0.0', listen_port: 13333 } }).freeze
Class Method Summary collapse
-
.get_default_config(services) ⇒ Object
Collect default_config from services.
- .load(data_dir = DEFAULT_DATA_DIR) ⇒ Object
- .save(config, path) ⇒ Object
- .setup(data_dir = DEFAULT_DATA_DIR) ⇒ Object
- .setup_data_dir(data_dir = DEFAULT_DATA_DIR) ⇒ Object
- .setup_required_config(data_dir = DEFAULT_DATA_DIR) ⇒ Object
Class Method Details
.get_default_config(services) ⇒ Object
Collect default_config from services.
77 78 79 80 81 82 83 |
# File 'lib/reth/config.rb', line 77 def get_default_config(services) config = {} services.each do |s| DEVp2p::Utils.update_config_with_defaults config, s.default_config end config end |
.load(data_dir = DEFAULT_DATA_DIR) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/reth/config.rb', line 59 def load(data_dir=DEFAULT_DATA_DIR) config_path = File.join data_dir, CONFIG_FILE config = File.exist?(config_path) ? JSON.parse(File.read(config_path)) : {} config[:data_dir] = data_dir genesis_path = File.join data_dir, GENESIS_FILE genesis = File.exist?(genesis_path) ? JSON.parse(File.read(genesis_path)) : nil if genesis config[:eth] ||= {} config[:eth][:genesis] = genesis end Defaults.deep_merge(config) end |
.save(config, path) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/reth/config.rb', line 52 def save(config, path) File.open(path, 'wb') do |f| h = config.instance_of?(Hashie::Mash) ? config.to_hash : config f.write JSON.dump(h) end end |
.setup(data_dir = DEFAULT_DATA_DIR) ⇒ Object
30 31 32 33 |
# File 'lib/reth/config.rb', line 30 def setup(data_dir=DEFAULT_DATA_DIR) setup_data_dir data_dir setup_required_config data_dir end |
.setup_data_dir(data_dir = DEFAULT_DATA_DIR) ⇒ Object
35 36 37 |
# File 'lib/reth/config.rb', line 35 def setup_data_dir(data_dir=DEFAULT_DATA_DIR) FileUtils.mkdir_p(data_dir) unless File.exist?(data_dir) end |
.setup_required_config(data_dir = DEFAULT_DATA_DIR) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/reth/config.rb', line 39 def setup_required_config(data_dir=DEFAULT_DATA_DIR) path = File.join data_dir, CONFIG_FILE unless File.exists?(path) config = { node: { privkey_hex: Utils.encode_hex(Utils.mk_random_privkey) } } save config, path end end |