From e0d69c5d0650ddaccb4fbcce3e71c7176ed62c20 Mon Sep 17 00:00:00 2001 From: Danil Pismenny Date: Thu, 4 Mar 2021 17:12:45 +0300 Subject: [PATCH 1/2] Enhancement: Combine all registries into one file --- config/initializers/blockchain_api.rb | 3 --- .../initializers/{wallet_api.rb => registries.rb} | 13 +++++++++++++ config/initializers/upstreams.rb | 3 --- 3 files changed, 13 insertions(+), 6 deletions(-) delete mode 100644 config/initializers/blockchain_api.rb rename config/initializers/{wallet_api.rb => registries.rb} (54%) delete mode 100644 config/initializers/upstreams.rb diff --git a/config/initializers/blockchain_api.rb b/config/initializers/blockchain_api.rb deleted file mode 100644 index 5d6fcfa046..0000000000 --- a/config/initializers/blockchain_api.rb +++ /dev/null @@ -1,3 +0,0 @@ -Peatio::Blockchain.registry[:bitcoin] = Bitcoin::Blockchain -Peatio::Blockchain.registry[:geth] = Ethereum::Blockchain -Peatio::Blockchain.registry[:parity] = Ethereum::Blockchain diff --git a/config/initializers/wallet_api.rb b/config/initializers/registries.rb similarity index 54% rename from config/initializers/wallet_api.rb rename to config/initializers/registries.rb index fc1287ef8f..bde513b0d7 100644 --- a/config/initializers/wallet_api.rb +++ b/config/initializers/registries.rb @@ -1,3 +1,5 @@ +# Wallets + Peatio::Wallet.registry[:bitcoind] = Bitcoin::Wallet Peatio::Wallet.registry[:geth] = Ethereum::Wallet Peatio::Wallet.registry[:parity] = Ethereum::Wallet @@ -5,3 +7,14 @@ Peatio::Wallet.registry[:ow_hdwallet] = OWHDWallet::Wallet Peatio::Wallet.registry[:opendax] = OWHDWallet::Wallet Peatio::Wallet.registry[:opendax_cloud] = OpendaxCloud::Wallet + +# Blockchains + +Peatio::Blockchain.registry[:bitcoin] = Bitcoin::Blockchain +Peatio::Blockchain.registry[:geth] = Ethereum::Blockchain +Peatio::Blockchain.registry[:parity] = Ethereum::Blockchain + + +# Upstreams +require 'peatio/upstream/opendax' +Peatio::Upstream.registry[:opendax] = Peatio::Upstream::Opendax diff --git a/config/initializers/upstreams.rb b/config/initializers/upstreams.rb deleted file mode 100644 index 055e92f356..0000000000 --- a/config/initializers/upstreams.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'peatio/upstream/opendax' - -Peatio::Upstream.registry[:opendax] = Peatio::Upstream::Opendax From 9ea101306f22f1b9c05022bb59ed83be8f250abb Mon Sep 17 00:00:00 2001 From: Danil Pismenny Date: Thu, 4 Mar 2021 17:21:41 +0300 Subject: [PATCH 2/2] Enhancement: Move registries into config/registries.yml --- .gitignore | 1 + config/initializers/registries.rb | 34 ++++++++++++++----------------- config/registries.yml | 16 +++++++++++++++ 3 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 config/registries.yml diff --git a/.gitignore b/.gitignore index f865301c4b..72b3220eaa 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ tmp /config/secrets /config/seed /config/bench/*.yml +/config/registries.local.yml # Ignore translations.js /public/javascripts/translations.js diff --git a/config/initializers/registries.rb b/config/initializers/registries.rb index bde513b0d7..9efa6b1454 100644 --- a/config/initializers/registries.rb +++ b/config/initializers/registries.rb @@ -1,20 +1,16 @@ -# Wallets +registries = { + wallets: Peatio::Wallet.registry, + blockchains: Peatio::Blockchain.registry, + upstreams: Peatio::Upstream.registry +} -Peatio::Wallet.registry[:bitcoind] = Bitcoin::Wallet -Peatio::Wallet.registry[:geth] = Ethereum::Wallet -Peatio::Wallet.registry[:parity] = Ethereum::Wallet -Peatio::Wallet.registry[:gnosis] = Gnosis::Wallet -Peatio::Wallet.registry[:ow_hdwallet] = OWHDWallet::Wallet -Peatio::Wallet.registry[:opendax] = OWHDWallet::Wallet -Peatio::Wallet.registry[:opendax_cloud] = OpendaxCloud::Wallet - -# Blockchains - -Peatio::Blockchain.registry[:bitcoin] = Bitcoin::Blockchain -Peatio::Blockchain.registry[:geth] = Ethereum::Blockchain -Peatio::Blockchain.registry[:parity] = Ethereum::Blockchain - - -# Upstreams -require 'peatio/upstream/opendax' -Peatio::Upstream.registry[:opendax] = Peatio::Upstream::Opendax +%w(config/registries.local.yml config/registries.yml).each do |config_file| + next unless File.exists? config_file + YAML.load_file(config_file).each_pair do |registry_name, items| + registry = registries[registry_name.to_sym] || raise("Unknown registry (#{registry_name}) defined in #{config_file}") + items.each do |item_name, item_class| + registry[item_name.to_sym] = item_name.classify + end + end + break +end diff --git a/config/registries.yml b/config/registries.yml new file mode 100644 index 0000000000..f6f341f952 --- /dev/null +++ b/config/registries.yml @@ -0,0 +1,16 @@ +wallets: + bitcoind: Bitcoin::Wallet + geth: Ethereum::Wallet + parity: Ethereum::Wallet + gnosis: Gnosis::Wallet + opendax: OWHDWallet::Wallet + ow_hdwallet: OWHDWallet::Wallet + opendax_cloud: OpendaxCloud::Wallet + +blockchains: + bitcoin: Bitcoin::Blockchain + geth: Ethereum::Blockchain + parity: Ethereum::Blockchain + +upstreams: + opendax: Peatio::Upstream::Opendax