Skip to content

Commit

Permalink
Attempt to deprecate all of my cj wrapper scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
saurik committed Jul 31, 2024
1 parent 21f5268 commit c16a497
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
55 changes: 50 additions & 5 deletions eth-sender/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>

#include <ctre.hpp>

#include <mapbox/eternal.hpp>

#include "base58.hpp"
#include "contract.hpp"
#include "currency.hpp"
Expand Down Expand Up @@ -971,8 +975,8 @@ task<void> CommandChain(const std::string &command, Args &args, const S<Chain> &
co_return co_await CommandExecutor(args, chain_, executor_);

} else if (command == "secret") {
const auto secret(Option<Bytes>(args()));
executor_ = Make<SecretExecutor>(secret);
const auto path(Option<std::string>(args()));
executor_ = Make<SecretExecutor>(Bless(Chomp(Load(path))));
co_return co_await CommandExecutor(args, chain_, executor_);

} else if (command == "trezor") {
Expand Down Expand Up @@ -1006,8 +1010,50 @@ task<void> CommandChain(const std::string &command, Args &args, const S<Chain> &
}

task<void> 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<mapbox::eternal::string, std::tuple<uint64_t, mapbox::eternal::string, mapbox::eternal::string>>({
{"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) { \
Expand All @@ -1017,7 +1063,6 @@ task<void> CommandEvm(Args &args) {
prefix name##suffix = Option<decltype(prefix name##suffix)>(args()); \
}

// XXX: this should get moved into CommandEvm
const auto command([&]() { for (;;) {
auto arg(args());
orc_assert(!arg.empty());
Expand Down
1 change: 1 addition & 0 deletions lib-shared/eternal
Submodule eternal added at dd2f5b
7 changes: 3 additions & 4 deletions lib-shared/source/address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,19 @@
/* }}} */


#include <ctre.hpp>

#include <eEVM/util.h>

#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));
}
Expand Down
7 changes: 7 additions & 0 deletions lib-shared/source/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ std::string Join(const std::string &delimeter, const std::vector<std::string> &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());
Expand Down
2 changes: 2 additions & 0 deletions lib-shared/source/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ auto Split(const View &value, const View &delimeter) {

std::string Join(const std::string &delimeter, const std::vector<std::string> &args);

std::string Chomp(std::string &&value);

template <typename Value_>
auto Keys(const std::map<std::string, Value_> &args) {
std::vector<std::string> keys;
Expand Down
3 changes: 3 additions & 0 deletions lib-shared/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c16a497

Please sign in to comment.