Skip to content

Commit

Permalink
warning as errors in clang
Browse files Browse the repository at this point in the history
  • Loading branch information
darcys22 committed Sep 3, 2023
1 parent 7e216fd commit f008392
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
5 changes: 5 additions & 0 deletions include/ethyl/provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
#pragma once

#include <string>
#include <optional>

#include <cpr/cpr.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuseless-cast"
#include <nlohmann/json.hpp>
#pragma GCC diagnostic pop

#include "transaction.hpp"

Expand Down
1 change: 1 addition & 0 deletions src/provider.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// provider.cpp
#include <iostream>
#include <thread>

#include "ethyl/provider.hpp"
#include "ethyl/utils.hpp"
Expand Down
22 changes: 10 additions & 12 deletions src/signer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void Signer::initContext() {
if (!fill_random(randomize, sizeof(randomize))) {
throw std::runtime_error("Failed to generate randomness");
}
int return_val = secp256k1_context_randomize(ctx, randomize);
assert(return_val);
if (!secp256k1_context_randomize(ctx, randomize))
throw std::runtime_error("Failed to randomize context");
}

Signer::~Signer() {
Expand All @@ -37,7 +37,6 @@ std::pair<std::vector<unsigned char>, std::vector<unsigned char>> Signer::genera
unsigned char seckey[32];
unsigned char compressed_pubkey[33];
size_t len;
int return_val;
secp256k1_pubkey pubkey;

while (1) {
Expand All @@ -49,12 +48,12 @@ std::pair<std::vector<unsigned char>, std::vector<unsigned char>> Signer::genera
}
}

return_val = secp256k1_ec_pubkey_create(ctx, &pubkey, seckey);
assert(return_val);
if (!secp256k1_ec_pubkey_create(ctx, &pubkey, seckey))
throw std::runtime_error("Failed to create pubkey");

len = sizeof(compressed_pubkey);
return_val = secp256k1_ec_pubkey_serialize(ctx, compressed_pubkey, &len, &pubkey, SECP256K1_EC_COMPRESSED);
assert(return_val);
if (!secp256k1_ec_pubkey_serialize(ctx, compressed_pubkey, &len, &pubkey, SECP256K1_EC_COMPRESSED))
throw std::runtime_error("Failed to serialize pubkey");
assert(len == sizeof(compressed_pubkey));

return {std::vector<unsigned char>(seckey, seckey + sizeof(seckey)),
Expand Down Expand Up @@ -96,13 +95,12 @@ std::vector<unsigned char> Signer::sign(const std::array<unsigned char, 32>& has
secp256k1_ecdsa_recoverable_signature sig;
unsigned char serialized_signature[64];
int recid;
int return_val;

return_val = secp256k1_ecdsa_sign_recoverable(ctx, &sig, hash.data(), seckey.data(), NULL, NULL);
assert(return_val);
if (!secp256k1_ecdsa_sign_recoverable(ctx, &sig, hash.data(), seckey.data(), NULL, NULL))
throw std::runtime_error("Failed to sign");

return_val = secp256k1_ecdsa_recoverable_signature_serialize_compact(ctx, serialized_signature, &recid, &sig);
assert(return_val);
if (!secp256k1_ecdsa_recoverable_signature_serialize_compact(ctx, serialized_signature, &recid, &sig))
throw std::runtime_error("Failed to serialize signature");

// Create a vector and fill it with the serialized signature
std::vector<unsigned char> signature(serialized_signature, serialized_signature + sizeof(serialized_signature));
Expand Down

0 comments on commit f008392

Please sign in to comment.