From c8dbce93bab7fc27dfb9b1878d594615b3f0a9d6 Mon Sep 17 00:00:00 2001 From: Rich Pelavin Date: Fri, 15 May 2020 00:37:02 +0000 Subject: [PATCH] Clean up of address generation --- .../ruby/docker-compose.yaml | 20 ++++++------- .../ruby/lib/catapult/bootstrap/addresses.rb | 29 ++++++++++++------- 2 files changed, 29 insertions(+), 20 deletions(-) rename docker-compose.yaml => common/ruby/docker-compose.yaml (77%) diff --git a/docker-compose.yaml b/common/ruby/docker-compose.yaml similarity index 77% rename from docker-compose.yaml rename to common/ruby/docker-compose.yaml index 523b025..4ee47a0 100644 --- a/docker-compose.yaml +++ b/common/ruby/docker-compose.yaml @@ -18,17 +18,17 @@ version: '3' services: generate-raw-addresses: build: - context: ./common/ruby + context: ./ dockerfile: Dockerfile-dev command: bash -c "/bin-mount/generate-raw-addresses-if-needed 53 /addresses/raw-addresses.txt /addresses/addresses.yaml" volumes: - - ./bin/bash:/bin-mount - - ./build/generated-addresses:/addresses:rw - - ./build/state:/state:rw + - ../../bin/bash:/bin-mount + - ../../build/generated-addresses:/addresses:rw + - ../../build/state:/state:rw setup-network: build: - context: ./common/ruby + context: ./ dockerfile: Dockerfile-dev command: bash -c "sleep infinity" # command: bash -c "/usr/app/bin/setup-network.rb && touch /state/configs-generated" @@ -38,8 +38,8 @@ services: - BASE_CONFIG_DIR=/config-build - NEMESIS_DIR=/nemesis volumes: - - ./common/ruby:/usr/app - - ./build/generated-addresses:/addresses - - ./build/catapult-config:/config-build - - ./build/nemesis:/nemesis:rw - - ./build/state:/state:rw + - ./:/usr/app + - ../../build/generated-addresses:/addresses + - ../../build/catapult-config:/config-build + - ../../build/nemesis:/nemesis:rw + - ../../build/state:/state:rw diff --git a/common/ruby/lib/catapult/bootstrap/addresses.rb b/common/ruby/lib/catapult/bootstrap/addresses.rb index 12bb5bc..5a6da0d 100644 --- a/common/ruby/lib/catapult/bootstrap/addresses.rb +++ b/common/ruby/lib/catapult/bootstrap/addresses.rb @@ -25,24 +25,29 @@ class Addresses ParseKey.nemesis_signer_private_key => 1 } - def initialize(input_file_path, address_total) - @input_file_path = input_file_path - @address_total = address_total + def initialize(address_total, raw_addresses_path: nil ) + @address_total = address_total + @raw_addresses_path = raw_addresses_path end - - def self.parse(input_file_path, address_total, output_form: nil) - new(input_file_path, address_total).parse(output_form: output_form) + + def self.generate_and_parse(address_total) + new(address_total).generate_and_parse + end + + # TODO: these can be deprecated + def self.parse(raw_addresses_path, address_total, output_form: nil) + new(address_total, raw_addresses_path: raw_addresses_path).parse(output_form: output_form) end def parse(output_form: nil) - Parse.parse(self.raw_address_info, self.section_sizes, break_into_sections: true, output_form: output_form) + Parse.parse(raw_address_info_from_file, self.section_sizes, break_into_sections: true, output_form: output_form) end protected - attr_reader :input_file_path, :address_total + attr_reader :address_total - def raw_address_info - @raw_address_info ||= ::File.open(self.input_file_path).read + def raw_addresses_path + @raw_addresses_path || fail("@raw_addresses_path is nil") end def section_sizes @@ -56,6 +61,10 @@ def num_harvesting_keys end private + + def raw_address_info_from_file + ::File.open(self.raw_addresses_path).read + end def ret_section_sizes # Rules are that nemesis_addresses_harvesting_vrf has same size as nemesis_addresses_harvesting and