Skip to content

Commit

Permalink
Boltz/Mod/BoltzSwapper/*: Use new detailed-Boltz factory interface, a…
Browse files Browse the repository at this point in the history
…dd AutonomousOrganization swap.
  • Loading branch information
ZmnSCPxj committed Apr 18, 2021
1 parent d14a1c4 commit 3379983
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
24 changes: 21 additions & 3 deletions Boss/Mod/BoltzSwapper/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,31 @@

namespace {

auto const boltz_instances = std::map<Boss::Msg::Network, std::vector<std::string>>
auto const boltz_instances = std::map< Boss::Msg::Network
, std::vector<Boss::Mod::BoltzSwapper::Instance>
>
{ { Boss::Msg::Network_Bitcoin
, { "https://boltz.exchange/api"
/* Historically, the clearnet API endpoint was used as the in-database label
* for Boltz services.
* The boltz.exchange service thus uses the API endpoint as the label for
* back-compatibility.
* Other services since then were added after we had a separate label.
*/
, { { "https://boltz.exchange/api"
, "https://boltz.exchange/api"
, "http://boltzzzbnus4m7mta3cxmflnps4fp7dueu2tgurstbvrbt6xswzcocyd.onion/api"
}
, { "AutonomousOrganization@github.com"
, ""
, "http://jsyqqszgfrya6nj7nhi4hu4tdpuvfursl7dyxeiukzit5mvckqbzxpad.onion"
}
}
}
, { Boss::Msg::Network_Testnet
, { "https://testnet.boltz.exchange/api"
, { { "https://testnet.boltz.exchange/api"
, "https://testnet.boltz.exchange/api"
, "http://tboltzzrsoc3npe6sydcrh37mtnfhnbrilqi45nao6cgc6dr7n2eo3id.onion/api"
}
}
}
};
Expand Down
16 changes: 9 additions & 7 deletions Boss/Mod/BoltzSwapper/ServiceCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class ServiceCreator::Core : public std::enable_shared_from_this<Core> {
private:
S::Bus& bus;
Boltz::ServiceFactory factory;
std::queue<std::string> instances;
std::queue<Instance> instances;
std::vector<std::unique_ptr<ServiceModule>>& services;

bool first;
std::ostringstream report;

Core( S::Bus& bus_
, Boltz::ServiceFactory factory_
, std::queue<std::string> instances_
, std::queue<Instance> instances_
, std::vector<std::unique_ptr<ServiceModule>>& services_
) : bus(bus_)
, factory(std::move(factory_))
Expand All @@ -39,7 +39,7 @@ class ServiceCreator::Core : public std::enable_shared_from_this<Core> {
std::shared_ptr<Core>
create( S::Bus& bus
, Boltz::ServiceFactory factory
, std::queue<std::string> instances
, std::queue<Instance> instances
, std::vector<std::unique_ptr<ServiceModule>>& services
) {
return std::shared_ptr<Core>(
Expand Down Expand Up @@ -75,9 +75,10 @@ class ServiceCreator::Core : public std::enable_shared_from_this<Core> {
first = false;
else
report << ", ";
report << "Boltz::Service(\"" << instance << "\")";
report << "Boltz::Service(\"" << instance.label << "\")";

return factory.create_service(instance
return factory.create_service_detailed(
instance.label, instance.clearnet, instance.onion
).then([this](std::unique_ptr<Boltz::Service> core) {
auto wrapper = Util::make_unique<ServiceModule>
( bus, std::move(core) );
Expand All @@ -102,9 +103,10 @@ void ServiceCreator::start() {
, init.db
, init.signer
, env
, init.always_use_proxy ? init.proxy : ""
, init.proxy
, init.always_use_proxy
);
auto q = std::queue<std::string>();
auto q = std::queue<Instance>();
for (auto const& instance : it->second)
q.push(instance);
auto core = Core::create( bus
Expand Down
17 changes: 15 additions & 2 deletions Boss/Mod/BoltzSwapper/ServiceCreator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ namespace S { class Bus; }

namespace Boss { namespace Mod { namespace BoltzSwapper {

/** struct Boss::Mod::BoltzSwapper::Instance
*
* @brief Describes an instance of a Boltz-like exchange.
*/
struct Instance {
/* Label to use in database. */
std::string label;
/* Clearnet API endpoint; can be "" if no clearnet. */
std::string clearnet;
/* Tor API endpoint; can be "" if no onion. */
std::string onion;
};

/** class Boss::Mod::BoltzSwapper::ServiceCreator
*
* @brief Constructs `ServiceModule` objects and
Expand All @@ -26,7 +39,7 @@ class ServiceCreator {
Boltz::EnvIF& env;

/* Known BOLTZ instances and the networks they are for. */
std::map<Boss::Msg::Network, std::vector<std::string>> const&
std::map<Boss::Msg::Network, std::vector<Instance>> const&
instances;

/* The actual services we are maintaining. */
Expand All @@ -45,7 +58,7 @@ class ServiceCreator {
ServiceCreator( S::Bus& bus_
, Ev::ThreadPool& threadpool_
, Boltz::EnvIF& env_
, std::map<Boss::Msg::Network, std::vector<std::string>> const& instances_
, std::map<Boss::Msg::Network, std::vector<Instance>> const& instances_
) : bus(bus_)
, threadpool(threadpool_)
, env(env_)
Expand Down

0 comments on commit 3379983

Please sign in to comment.