Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang format script added to auto-format C++ code; fixes #293 #294

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions scripts/clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

# Usage: ./scripts/clang-format.sh
echo "Running clang format..."

check_format_files=$(git ls-files | grep -E "tools|tests|src|cmake-tests" \
| grep -E "\..*pp")
clang-format -i --style=file ${check_format_files[@]}

echo "Done."
2 changes: 1 addition & 1 deletion src/parsec/agent/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace cbdc::parsec::agent::rpc {
client::client(std::vector<network::endpoint_t> endpoints)
: m_client(std::make_unique<decltype(m_client)::element_type>(
std::move(endpoints))) {}
std::move(endpoints))) {}

auto client::init() -> bool {
return m_client->init();
Expand Down
10 changes: 5 additions & 5 deletions src/parsec/agent/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ namespace cbdc::parsec::agent::rpc {
/// \param is_readonly_run true if agent should skip writing any state changes.
/// \param result_callback function to call with execution result.
/// \return true if the request was sent successfully.
auto exec(runtime_locking_shard::key_type function,
parameter_type param,
bool is_readonly_run,
const interface::exec_callback_type& result_callback)
-> bool;
auto
exec(runtime_locking_shard::key_type function,
parameter_type param,
bool is_readonly_run,
const interface::exec_callback_type& result_callback) -> bool;

private:
std::unique_ptr<cbdc::rpc::tcp_client<request, response>> m_client;
Expand Down
8 changes: 4 additions & 4 deletions src/parsec/agent/format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include "util/serialization/format.hpp"

namespace cbdc {
auto operator<<(serializer& ser, const parsec::agent::rpc::request& req)
-> serializer& {
auto operator<<(serializer& ser,
const parsec::agent::rpc::request& req) -> serializer& {
return ser << req.m_function << req.m_param << req.m_is_readonly_run;
}

auto operator>>(serializer& deser, parsec::agent::rpc::request& req)
-> serializer& {
auto operator>>(serializer& deser,
parsec::agent::rpc::request& req) -> serializer& {
return deser >> req.m_function >> req.m_param >> req.m_is_readonly_run;
}
}
8 changes: 4 additions & 4 deletions src/parsec/agent/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include "util/serialization/serializer.hpp"

namespace cbdc {
auto operator<<(serializer& ser, const parsec::agent::rpc::request& req)
-> serializer&;
auto operator>>(serializer& deser, parsec::agent::rpc::request& req)
-> serializer&;
auto operator<<(serializer& ser,
const parsec::agent::rpc::request& req) -> serializer&;
auto operator>>(serializer& deser,
parsec::agent::rpc::request& req) -> serializer&;
}

#endif
9 changes: 4 additions & 5 deletions src/parsec/agent/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,10 @@ namespace cbdc::parsec::agent {
res_cb(std::move(res));
}

auto
impl::do_try_lock_request(broker::key_type key,
broker::lock_type locktype,
broker::interface::try_lock_callback_type res_cb)
-> bool {
auto impl::do_try_lock_request(
broker::key_type key,
broker::lock_type locktype,
broker::interface::try_lock_callback_type res_cb) -> bool {
// TODO: permissions for keys
std::unique_lock l(m_mut);
assert(m_ticket_number.has_value());
Expand Down
9 changes: 4 additions & 5 deletions src/parsec/agent/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,10 @@ namespace cbdc::parsec::agent {

/// Request the broker to attempt to lock the parameterized key
/// \return true is returned unless the system is in an unexpected state
[[nodiscard]] auto
do_try_lock_request(broker::key_type key,
broker::lock_type locktype,
broker::interface::try_lock_callback_type res_cb)
-> bool;
[[nodiscard]] auto do_try_lock_request(
broker::key_type key,
broker::lock_type locktype,
broker::interface::try_lock_callback_type res_cb) -> bool;

void
handle_rollback(broker::interface::rollback_return_type rollback_res);
Expand Down
4 changes: 2 additions & 2 deletions src/parsec/agent/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ namespace cbdc::parsec::agent {

/// Return the key of the function bytecode managed by this agent.
/// \return function bytecode key.
[[nodiscard]] auto get_function() const
-> runtime_locking_shard::key_type;
[[nodiscard]] auto
get_function() const -> runtime_locking_shard::key_type;

/// Return the function parameter managed by this agent.
/// \return function parameter.
Expand Down
20 changes: 10 additions & 10 deletions src/parsec/agent/runners/evm/address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ namespace cbdc::parsec::agent::runner {
return new_addr;
}

auto contract_address2(const evmc::address& sender,
const evmc::bytes32& salt,
const cbdc::hash_t& bytecode_hash)
-> evmc::address {
auto
contract_address2(const evmc::address& sender,
const evmc::bytes32& salt,
const cbdc::hash_t& bytecode_hash) -> evmc::address {
// Specs: https://eips.ethereum.org/EIPS/eip-1014

auto new_addr = evmc::address();
Expand All @@ -53,9 +53,9 @@ namespace cbdc::parsec::agent::runner {
return new_addr;
}

auto eth_addr(const std::unique_ptr<secp256k1_pubkey>& pk,
const std::shared_ptr<secp256k1_context>& ctx)
-> evmc::address {
auto
eth_addr(const std::unique_ptr<secp256k1_pubkey>& pk,
const std::shared_ptr<secp256k1_context>& ctx) -> evmc::address {
static constexpr int uncompressed_pubkey_len = 65;
auto pubkey_serialized
= std::array<unsigned char, uncompressed_pubkey_len>();
Expand Down Expand Up @@ -84,9 +84,9 @@ namespace cbdc::parsec::agent::runner {
return addr;
}

auto eth_addr(const cbdc::privkey_t& key,
const std::shared_ptr<secp256k1_context>& ctx)
-> evmc::address {
auto
eth_addr(const cbdc::privkey_t& key,
const std::shared_ptr<secp256k1_context>& ctx) -> evmc::address {
auto pk = std::make_unique<secp256k1_pubkey>();
[[maybe_unused]] const auto pub_ret
= ::secp256k1_ec_pubkey_create(ctx.get(), pk.get(), key.data());
Expand Down
12 changes: 6 additions & 6 deletions src/parsec/agent/runners/evm/address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ namespace cbdc::parsec::agent::runner {
/// \param key key to calculate the address for
/// \param ctx secp256k1 context to use
/// \return the address corresponding to the passed private key
auto eth_addr(const cbdc::privkey_t& key,
const std::shared_ptr<secp256k1_context>& ctx)
-> evmc::address;
auto
eth_addr(const cbdc::privkey_t& key,
const std::shared_ptr<secp256k1_context>& ctx) -> evmc::address;

/// Calculates an eth address from a public key
/// \param pk key to calculate the address for
/// \param ctx secp256k1 context to use
/// \return the address corresponding to the passed public key
auto eth_addr(const std::unique_ptr<secp256k1_pubkey>& pk,
const std::shared_ptr<secp256k1_context>& ctx)
-> evmc::address;
auto
eth_addr(const std::unique_ptr<secp256k1_pubkey>& pk,
const std::shared_ptr<secp256k1_context>& ctx) -> evmc::address;
}

#endif
86 changes: 43 additions & 43 deletions src/parsec/agent/runners/evm/format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
#include "util/serialization/format.hpp"

namespace cbdc {
auto operator<<(serializer& ser,
const parsec::agent::runner::evm_account& acc)
-> serializer& {
auto
operator<<(serializer& ser,
const parsec::agent::runner::evm_account& acc) -> serializer& {
return ser << acc.m_balance << acc.m_nonce;
}

auto operator>>(serializer& deser, parsec::agent::runner::evm_account& acc)
-> serializer& {
auto operator>>(serializer& deser,
parsec::agent::runner::evm_account& acc) -> serializer& {
return deser >> acc.m_balance >> acc.m_nonce;
}

auto operator<<(serializer& ser, const evmc::address& addr)
-> serializer& {
auto operator<<(serializer& ser,
const evmc::address& addr) -> serializer& {
ser.write(addr.bytes, sizeof(addr.bytes));
return ser;
}
Expand All @@ -40,12 +40,12 @@ namespace cbdc {
return deser;
}

auto operator<<(serializer& ser, const parsec::agent::runner::evm_sig& s)
-> serializer& {
auto operator<<(serializer& ser,
const parsec::agent::runner::evm_sig& s) -> serializer& {
return ser << s.m_v << s.m_r << s.m_s;
}
auto operator>>(serializer& deser, parsec::agent::runner::evm_sig& s)
-> serializer& {
auto operator>>(serializer& deser,
parsec::agent::runner::evm_sig& s) -> serializer& {
return deser >> s.m_v >> s.m_r >> s.m_s;
}

Expand All @@ -55,30 +55,30 @@ namespace cbdc {
return ser << at.m_address << at.m_storage_keys;
}

auto operator>>(serializer& deser,
parsec::agent::runner::evm_access_tuple& at)
-> serializer& {
auto
operator>>(serializer& deser,
parsec::agent::runner::evm_access_tuple& at) -> serializer& {
return deser >> at.m_address >> at.m_storage_keys;
}

auto operator<<(serializer& ser, const parsec::agent::runner::evm_tx& tx)
-> serializer& {
auto operator<<(serializer& ser,
const parsec::agent::runner::evm_tx& tx) -> serializer& {
return ser << tx.m_type << tx.m_to << tx.m_value << tx.m_nonce
<< tx.m_gas_price << tx.m_gas_limit << tx.m_gas_tip_cap
<< tx.m_gas_fee_cap << tx.m_input << tx.m_access_list
<< tx.m_sig;
}

auto operator>>(serializer& deser, parsec::agent::runner::evm_tx& tx)
-> serializer& {
auto operator>>(serializer& deser,
parsec::agent::runner::evm_tx& tx) -> serializer& {
return deser >> tx.m_type >> tx.m_to >> tx.m_value >> tx.m_nonce
>> tx.m_gas_price >> tx.m_gas_limit >> tx.m_gas_tip_cap
>> tx.m_gas_fee_cap >> tx.m_input >> tx.m_access_list >> tx.m_sig;
}

auto operator<<(serializer& ser,
const parsec::agent::runner::evm_dryrun_tx& tx)
-> serializer& {
auto
operator<<(serializer& ser,
const parsec::agent::runner::evm_dryrun_tx& tx) -> serializer& {
return ser << tx.m_from << tx.m_tx;
}

Expand All @@ -87,19 +87,19 @@ namespace cbdc {
return deser >> tx.m_from >> tx.m_tx;
}

auto operator<<(serializer& ser, const parsec::agent::runner::evm_log& l)
-> serializer& {
auto operator<<(serializer& ser,
const parsec::agent::runner::evm_log& l) -> serializer& {
return ser << l.m_addr << l.m_data << l.m_topics;
}

auto operator>>(serializer& deser, parsec::agent::runner::evm_log& l)
-> serializer& {
auto operator>>(serializer& deser,
parsec::agent::runner::evm_log& l) -> serializer& {
return deser >> l.m_addr >> l.m_data >> l.m_topics;
}

auto operator<<(serializer& ser,
const parsec::agent::runner::evm_tx_receipt& r)
-> serializer& {
auto
operator<<(serializer& ser,
const parsec::agent::runner::evm_tx_receipt& r) -> serializer& {
return ser << r.m_tx << r.m_create_address << r.m_gas_used << r.m_logs
<< r.m_output_data << r.m_ticket_number << r.m_timestamp
<< r.m_success;
Expand All @@ -112,30 +112,30 @@ namespace cbdc {
>> r.m_timestamp >> r.m_success;
}

auto operator<<(serializer& ser, const parsec::agent::runner::code_key& k)
-> serializer& {
auto operator<<(serializer& ser,
const parsec::agent::runner::code_key& k) -> serializer& {
return ser << k.m_addr << uint8_t{};
}

auto operator>>(serializer& deser, parsec::agent::runner::code_key& k)
-> serializer& {
auto operator>>(serializer& deser,
parsec::agent::runner::code_key& k) -> serializer& {
uint8_t b{};
return deser >> k.m_addr >> b;
}

auto operator<<(serializer& ser,
const parsec::agent::runner::storage_key& k)
-> serializer& {
auto
operator<<(serializer& ser,
const parsec::agent::runner::storage_key& k) -> serializer& {
return ser << k.m_addr << k.m_key;
}
auto operator>>(serializer& deser, parsec::agent::runner::storage_key& k)
-> serializer& {
auto operator>>(serializer& deser,
parsec::agent::runner::storage_key& k) -> serializer& {
return deser >> k.m_addr >> k.m_key;
}

auto operator>>(serializer& deser,
parsec::agent::runner::evm_pretend_block& b)
-> serializer& {
auto
operator>>(serializer& deser,
parsec::agent::runner::evm_pretend_block& b) -> serializer& {
return deser >> b.m_ticket_number >> b.m_transactions;
}
auto operator<<(serializer& ser,
Expand All @@ -149,9 +149,9 @@ namespace cbdc {
return deser >> lq.m_addresses >> lq.m_from_block >> lq.m_to_block
>> lq.m_topics;
}
auto operator<<(serializer& ser,
const parsec::agent::runner::evm_log_query& lq)
-> serializer& {
auto
operator<<(serializer& ser,
const parsec::agent::runner::evm_log_query& lq) -> serializer& {
return ser << lq.m_addresses << lq.m_from_block << lq.m_to_block
<< lq.m_topics;
}
Expand Down
Loading
Loading