diff --git a/.gitmodules b/.gitmodules index b144fa1cc..08e822e5c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -229,3 +229,6 @@ [submodule "range-v3"] path = lib-shared/range-v3 url = https://github.com/ericniebler/range-v3.git +[submodule "eternal"] + path = lib-shared/eternal + url = https://github.com/mapbox/eternal.git diff --git a/eth-sender/source/main.cpp b/eth-sender/source/main.cpp index b2a52b9fa..84bbf788a 100644 --- a/eth-sender/source/main.cpp +++ b/eth-sender/source/main.cpp @@ -26,6 +26,10 @@ #include #include +#include + +#include + #include "base58.hpp" #include "contract.hpp" #include "currency.hpp" @@ -971,8 +975,8 @@ task CommandChain(const std::string &command, Args &args, const S & co_return co_await CommandExecutor(args, chain_, executor_); } else if (command == "secret") { - const auto secret(Option(args())); - executor_ = Make(secret); + const auto path(Option(args())); + executor_ = Make(Bless(Chomp(Load(path)))); co_return co_await CommandExecutor(args, chain_, executor_); } else if (command == "trezor") { @@ -1006,8 +1010,50 @@ task CommandChain(const std::string &command, Args &args, const S & } task CommandEvm(Args &args) { - const auto rpc(args()); - chain_ = co_await Chain::New(Endpoint{rpc, base_}); + using ctre::literals::operator""_ctre; + + constexpr const auto chains(mapbox::eternal::map>({ + {"arbitrum", {42161, "ETH", "https://arb1.arbitrum.io/rpc"}}, + {"aurora", {1313161554, "NEAR", "https://mainnet.aurora.dev/"}}, + {"avalanche", {43114, "AVAX", "https://api.avax.network/ext/bc/C/rpc"}}, + {"base", {8453, "ETH", "https://mainnet.base.org/"}}, + {"binance", {56, "BNB", "https://bsc-dataseed.binance.org/"}}, + {"boba", {288, "ETH", "https://mainnet.boba.network/"}}, + {"celo", {42220, "CELO", "https://forno.celo.org/"}}, + {"etc", {61, "ETC", "https://etc.rivet.link/"}}, + {"ethereum", {1, "ETH", "https://cloudflare-eth.com/"}}, + {"ftm", {250, "FTM", "https://rpc.ftm.tools/"}}, + {"fuse", {122, "FUSE", "https://rpc.fuse.io/"}}, + {"gnosis", {100, "DAI", "https://rpc.gnosischain.com/"}}, + {"heco", {128, "HECO", "https://http-mainnet.hecochain.com/"}}, + {"klaytn", {8217, "KLAY", "https://public-en-cypress.klaytn.net/"}}, + {"metis", {1088, "ETH", "https://andromeda.metis.io/?owner=1088"}}, + {"moonriver", {1285, "MOVR", "https://rpc.moonriver.moonbeam.network/"}}, + {"neon", {245022934, "NEON", "https://neon-proxy-mainnet.solana.p2p.org/"}}, + {"okex", {66, "OKT", "https://exchainrpc.okex.org/"}}, + {"optimism", {10, "ETH", "https://mainnet.optimism.io/"}}, + {"polygon", {137, "MATIC", "https://polygon-rpc.com/"}}, + {"ronin", {2020, "RON", "https://api.roninchain.com/rpc"}}, + {"rsk", {30, "BTC", "https://public-node.rsk.co/"}}, + {"telos", {40, "TLOS", "https://mainnet.telos.net/evm"}}, + })); + + if (const auto command(args()); false) { + } else if (command == "chains") { + for (auto i(chains.begin()); i != chains.end(); ++i) + std::cout << i->first.c_str() << " " << std::get<0>(i->second) << " " << std::get<1>(i->second).c_str() << " " << std::get<2>(i->second).c_str() << std::endl; + co_return; + } else if (command == "chain") { + const auto arg(args()); + const auto chain(chains.find(arg.c_str())); + orc_assert_(chain != chains.end(), "unknown chain " << arg); + currency_ = std::get<1>(chain->second).c_str(); + chain_ = co_await Chain::New(Endpoint{std::get<2>(chain->second).c_str(), base_}, std::get<0>(chain->second)); + } else if (command == "rpc") { + const auto arg(args()); + orc_assert_("https?://.*"_ctre.match(arg), "invalid RPC URL: " << arg); + chain_ = co_await Chain::New(Endpoint{arg, base_}); + } else orc_assert_(false, "unknown command " << command); #define ORC_PARAM(name, prefix, suffix) \ else if (arg == "--" #name) { \ @@ -1017,7 +1063,6 @@ task CommandEvm(Args &args) { prefix name##suffix = Option(args()); \ } - // XXX: this should get moved into CommandEvm const auto command([&]() { for (;;) { auto arg(args()); orc_assert(!arg.empty()); diff --git a/lib-shared/eternal b/lib-shared/eternal new file mode 160000 index 000000000..dd2f5b9ff --- /dev/null +++ b/lib-shared/eternal @@ -0,0 +1 @@ +Subproject commit dd2f5b9ff38fcd36b59efd9d289127fa73efc6cb diff --git a/lib-shared/source/address.cpp b/lib-shared/source/address.cpp index f82229d66..a8b8f8f7d 100644 --- a/lib-shared/source/address.cpp +++ b/lib-shared/source/address.cpp @@ -20,20 +20,19 @@ /* }}} */ +#include + #include #include "address.hpp" -#include "ctre.hpp" #include "error.hpp" namespace orc { -// NOLINTNEXTLINE(google-build-using-namespace) -using namespace ctre::literals; - Address::Address(const std::string_view &address) : uint160_t(address) { + using ctre::literals::operator""_ctre; orc_assert_("0x[0-9a-fA-F]{40}"_ctre.match(address), "invalid address " << address); //orc_assert(eevm::is_checksum_address(address)); } diff --git a/lib-shared/source/buffer.cpp b/lib-shared/source/buffer.cpp index b42fc1a31..e4e7dd111 100644 --- a/lib-shared/source/buffer.cpp +++ b/lib-shared/source/buffer.cpp @@ -204,6 +204,13 @@ std::string Join(const std::string &delimeter, const std::vector &a return data.str(); } +std::string Chomp(std::string &&value) { + const auto size(value.size()); + if (size != 0 && value[size - 1] == '\n') + value.resize(size - 1); + return std::move(value); +} + Mutable &Mutable::operator =(const Buffer &buffer) { auto here(data()); size_t rest(size()); diff --git a/lib-shared/source/buffer.hpp b/lib-shared/source/buffer.hpp index 1f5ca4f4a..e7cfe228c 100644 --- a/lib-shared/source/buffer.hpp +++ b/lib-shared/source/buffer.hpp @@ -326,6 +326,8 @@ auto Split(const View &value, const View &delimeter) { std::string Join(const std::string &delimeter, const std::vector &args); +std::string Chomp(std::string &&value); + template auto Keys(const std::map &args) { std::vector keys; diff --git a/lib-shared/target.mk b/lib-shared/target.mk index b2f89aabf..048683dc7 100644 --- a/lib-shared/target.mk +++ b/lib-shared/target.mk @@ -57,6 +57,9 @@ endif cflags += -I$(pwd)/ctre/single-header +cflags += -I$(pwd)/eternal/include + + source += $(wildcard $(pwd)/jsoncpp/src/lib_json/*.cpp) cflags += -I$(pwd)/jsoncpp/include