Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
5 changes: 1 addition & 4 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ jobs:
run: ./scripts/auto.sh -s bdk exec 'rm coverage.xml || true'
- name: Collect coverage into one XML report
run: ./scripts/auto.sh -s bdk exec \
'gcovr -d \
--gcov-ignore-errors=all \
--gcov-ignore-parse-errors=all \
--sonarqube -o coverage.xml'
'gcovr -d --gcov-ignore-parse-errors --sonarqube -o coverage.xml'
- name: Run SonarQube Scanner
run: ./scripts/auto.sh -s bdk exec \
'env SONAR_TOKEN=${{ env.SONAR_TOKEN }}
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# Start from a base Debian image
FROM debian:trixie

# Set shell to Bash because Docker standards are stupid
SHELL ["/bin/bash", "-c"]

# Update the system
RUN apt-get update && apt-get upgrade -y

Expand All @@ -15,7 +18,7 @@ WORKDIR /bdk-cpp
COPY . /bdk-cpp

# Install Docker-specific dependencies
RUN apt-get -y install nano vim unison curl jq unzip gcovr
RUN apt-get -y install nano vim unison curl jq unzip

# Install dependencies
RUN bash /bdk-cpp/scripts/deps.sh --install
Expand Down
11 changes: 10 additions & 1 deletion docker/bdk_cpp.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
# Start from a base Debian image
FROM debian:trixie

# Set shell to Bash because Docker standards are stupid
SHELL ["/bin/bash", "-c"]

# Update the system
RUN apt-get update && apt-get upgrade -y

# Install Docker-specific dependencies
RUN apt-get -y install nano vim unison curl jq unzip gcovr
RUN apt-get -y install nano vim unison curl jq unzip wget
RUN apt-get install -y python3 python3-pip python3-venv

# Create venv and install gcovr (for SonarQube)
# Locked at 5.0 due to https://github.com/gcovr/gcovr/issues/583#issuecomment-1079974142
RUN pip install gcovr==5.0 --break-system-packages

# Copy the deps script to the container
COPY scripts/deps.sh /
Expand Down Expand Up @@ -39,6 +47,7 @@ RUN /sonarcloud.sh
ENV PATH=/root/.sonar/build-wrapper-linux-x86:$PATH
ENV PATH=/root/.sonar/sonar-scanner-6.2.1.4610-linux-x64/bin:$PATH
ENV PATH=/root/.sonar/sonar-scanner-6.2.0.4584-linux-x64/bin:$PATH
ENV PATH=/usr/local/bin:$PATH

# Copy the entrypoint script
COPY docker/entrypoint.sh /entrypoint.sh
Expand Down
2 changes: 1 addition & 1 deletion src/contract/abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See the LICENSE.txt file in the project root for more information.
#include "../utils/intconv.h"
#include "../utils/uintconv.h"
#include "../utils/strconv.h"
#include "../utils/utils.h" // libs/json.hpp -> string
#include "../utils/utils.h" // FunctionTypes, libs/json.hpp -> string

/// Namespace for Solidity ABI-related operations.
namespace ABI {
Expand Down
9 changes: 4 additions & 5 deletions src/contract/contractmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,15 @@ void ContractManager::ethCall(const evmc_message& callInfo, ContractHost* host)
PointerNullifier nullifier(this->host_);
const Address caller(callInfo.sender);
const Functor functor = EVMCConv::getFunctor(callInfo);
/// Call the function on this->createContractFuncs_
// Call the function on this->createContractFuncs_
auto it = this->createContractFuncs_.find(functor);
if (it == this->createContractFuncs_.end()) {
throw DynamicException("ContractManager: Invalid function call");
}
it->second(callInfo,
ContractHost::deriveContractAddress(this->host_->getNonce(caller), caller),
this->contracts_,
this->getContractChainId(),
this->host_);
ContractHost::deriveContractAddress(this->host_->getNonce(caller), caller),
this->contracts_, this->getContractChainId(), this->host_
);
}

Bytes ContractManager::ethCallView(const evmc_message& callInfo, ContractHost* host) const {
Expand Down
20 changes: 10 additions & 10 deletions src/contract/contractmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ class ContractManager : public BaseContract {

/// Functions to create contracts.
boost::unordered_flat_map<
Functor,
std::function<
void(const evmc_message&,
const Address&,
boost::unordered_flat_map<Address, std::unique_ptr<BaseContract>, SafeHash>& contracts_,
const uint64_t&,
ContractHost*
)>,
SafeHash
> createContractFuncs_;
Functor,
std::function<void(
const evmc_message&,
const Address&,
boost::unordered_flat_map<Address, std::unique_ptr<BaseContract>, SafeHash>& contracts_,
const uint64_t&,
ContractHost*
)>,
SafeHash
> createContractFuncs_;

/**
* Get all deployed contracts.
Expand Down
12 changes: 12 additions & 0 deletions src/contract/templates/dexv2/dexv2pair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ DEXV2Pair::DEXV2Pair(
factory_(this), token0_(this), token1_(this), reserve0_(this), reserve1_(this),
blockTimestampLast_(this), price0CumulativeLast_(this), price1CumulativeLast_(this), kLast_(this)
{
// Explicitly initialize numbers to 0 to avoid junk values on DB load
this->factory_ = creator;
this->reserve0_ = 0;
this->reserve1_ = 0;
this->blockTimestampLast_ = 0;
this->price0CumulativeLast_ = 0;
this->price1CumulativeLast_ = 0;
this->kLast_ = 0;

this->factory_.commit();
this->token0_.commit();
Expand Down Expand Up @@ -256,7 +263,12 @@ void DEXV2Pair::sync() {


DBBatch DEXV2Pair::dump() const {
// We have to dump the tokens as well
DBBatch dbBatch = BaseContract::dump();
DBBatch erc20Batch = ERC20::dump();
for (const auto& dbItem : erc20Batch.getPuts()) dbBatch.push_back(dbItem);
for (const auto& dbItem : erc20Batch.getDels()) dbBatch.delete_key(dbItem);

dbBatch.push_back(StrConv::stringToBytes("factory_"), this->factory_.get().view(), this->getDBPrefix());
dbBatch.push_back(StrConv::stringToBytes("token0_"), this->token0_.get().view(), this->getDBPrefix());
dbBatch.push_back(StrConv::stringToBytes("token1_"), this->token1_.get().view(), this->getDBPrefix());
Expand Down
2 changes: 1 addition & 1 deletion src/contract/templates/erc721test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ERC721Test::ERC721Test(const Address &address, const DB& db)
ERC721Test::ERC721Test(
const std::string &erc721name, const std::string &erc721symbol, const uint64_t& maxTokens,
const Address &address, const Address &creator, const uint64_t &chainId
) : DynamicContract(erc721name, address, creator, chainId),
) : DynamicContract("ERC721Test", address, creator, chainId),
ERC721(erc721name, erc721symbol, address, creator, chainId),
tokenIdCounter_(this, 0), maxTokens_(this, maxTokens), totalSupply_(this, 0)
{
Expand Down
4 changes: 0 additions & 4 deletions src/contract/templates/erc721uristorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ ERC721URIStorage::ERC721URIStorage(const Address& address, const DB& db)
: DynamicContract(address, db),
ERC721(address, db),
_tokenURIs(this) {

for (const auto& dbEntry : db.getBatch(this->getNewPrefix("tokenURIs_"))) {
this->_tokenURIs[Utils::fromBigEndian<uint256_t>(dbEntry.key)] = StrConv::bytesToString(dbEntry.value);
}
Expand All @@ -36,21 +35,18 @@ ERC721URIStorage::ERC721URIStorage(
) : DynamicContract(derivedTypeName, address, creator, chainId),
ERC721(derivedTypeName, erc721_name, erc721_symbol, address, creator, chainId),
_tokenURIs(this) {

ERC721URIStorage::registerContractFunctions();
}

DBBatch ERC721URIStorage::dump() const {
DBBatch batchedOperations = ERC721::dump();

for (auto it = this->_tokenURIs.cbegin(); it != this->_tokenURIs.cend(); ++it) {
batchedOperations.push_back(
Utils::uintToBytes(it->first),
StrConv::stringToBytes(it->second),
this->getNewPrefix("tokenURIs_")
);
}

return batchedOperations;
}

Expand Down
13 changes: 7 additions & 6 deletions src/contract/templates/erc721uristorage.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/*
Copyright (c) [2023-2024] [AppLayer Developers]
This software is distributed under the MIT License.
See the LICENSE.txt file in the project root for more information.
*/

#ifndef ERC721URISTORAGE_H
#define ERC721URISTORAGE_H

#include "erc721.h"


/// Template for an ERC721URIStorage contract.
/// Roughly based on the OpenZeppelin implementation.
class ERC721URIStorage : virtual public ERC721 {
Expand Down Expand Up @@ -33,21 +38,17 @@ class ERC721URIStorage : virtual public ERC721 {
void registerContractFunctions() override;

public:

/**
* ConstructorArguments is a tuple of the contract constructor arguments in the order they appear in the constructor.
*/
using ConstructorArguments = std::tuple<const std::string&, const std::string&>;


/**
* Constructor for loading contract from DB.
* @param address The address where the contract will be deployed.
* @param db Reference to the database object.
*/
ERC721URIStorage(
const Address& address, const DB& db
);
ERC721URIStorage(const Address& address, const DB& db);

/**
* Constructor to be used when creating a new contract.
Expand Down
7 changes: 6 additions & 1 deletion src/contract/templates/nativewrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ NativeWrapper::NativeWrapper(
NativeWrapper::~NativeWrapper() = default;

DBBatch NativeWrapper::dump() const {
return BaseContract::dump();
// We need to dump all the data from the parent class as well
DBBatch batch = ERC20::dump();
DBBatch baseDump = BaseContract::dump();
for (const auto& dbItem : baseDump.getPuts()) batch.push_back(dbItem);
for (const auto& dbItem : baseDump.getDels()) batch.delete_key(dbItem);
return batch;
}

void NativeWrapper::registerContractFunctions() {
Expand Down
2 changes: 1 addition & 1 deletion src/contract/templates/pebble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ DBBatch Pebble::dump() const {
for (auto it = this->minters_.cbegin(); it != this->minters_.cend(); ++it) {
batch.push_back(it->first.asBytes(), UintConv::uint8ToBytes(static_cast<uint8_t>(it->second)), this->getNewPrefix("minters_"));
}
batch.push_back(StrConv::stringToBytes("authorized_"), this->authorizer_.get().asBytes(), this->getDBPrefix());
batch.push_back(StrConv::stringToBytes("authorizer_"), this->authorizer_.get().asBytes(), this->getDBPrefix());
return batch;
}

Expand Down
22 changes: 12 additions & 10 deletions src/contract/templates/throwtestA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ See the LICENSE.txt file in the project root for more information.
#include "throwtestA.h"

ThrowTestA::ThrowTestA(
const Address& address, const Address& creator,
const uint64_t& chainId
) : DynamicContract("ThrowTestA", address, creator, chainId) {
const Address& address, const Address& creator, const uint64_t& chainId
) : DynamicContract("ThrowTestA", address, creator, chainId), num_(this) {
this->num_.commit();
registerContractFunctions();
this->num_.enableRegister();
}

ThrowTestA::ThrowTestA(
const Address& address,
const DB& db
) : DynamicContract(address, db) {
ThrowTestA::ThrowTestA(const Address& address, const DB& db) : DynamicContract(address, db) {
this->num_ = UintConv::bytesToUint8(db.get(std::string("num_"), this->getDBPrefix()));
this->num_.commit();
registerContractFunctions();
this->num_.enableRegister();
}

ThrowTestA::~ThrowTestA() { return; }

DBBatch ThrowTestA::dump() const
{
return BaseContract::dump();
DBBatch ThrowTestA::dump() const {
DBBatch dbBatch = BaseContract::dump();
dbBatch.push_back(StrConv::stringToBytes("num_"), UintConv::uint8ToBytes(this->num_.get()), this->getDBPrefix());
return dbBatch;
}

uint8_t ThrowTestA::getNumA() const { return this->num_.get(); }
Expand Down
22 changes: 12 additions & 10 deletions src/contract/templates/throwtestB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ See the LICENSE.txt file in the project root for more information.
#include "throwtestB.h"

ThrowTestB::ThrowTestB(
const Address& address, const Address& creator,
const uint64_t& chainId
) : DynamicContract("ThrowTestB", address, creator, chainId) {
const Address& address, const Address& creator, const uint64_t& chainId
) : DynamicContract("ThrowTestB", address, creator, chainId), num_(this) {
this->num_.commit();
registerContractFunctions();
this->num_.enableRegister();
}

ThrowTestB::ThrowTestB(
const Address& address,
const DB& db
) : DynamicContract(address, db) {
ThrowTestB::ThrowTestB(const Address& address, const DB& db) : DynamicContract(address, db) {
this->num_ = UintConv::bytesToUint8(db.get(std::string("num_"), this->getDBPrefix()));
this->num_.commit();
registerContractFunctions();
this->num_.enableRegister();
}

ThrowTestB::~ThrowTestB() { return; }

DBBatch ThrowTestB::dump() const
{
return BaseContract::dump();
DBBatch ThrowTestB::dump() const {
DBBatch dbBatch = BaseContract::dump();
dbBatch.push_back(StrConv::stringToBytes("num_"), UintConv::uint8ToBytes(this->num_.get()), this->getDBPrefix());
return dbBatch;
}

uint8_t ThrowTestB::getNumB() const { return this->num_.get(); }
Expand Down
22 changes: 12 additions & 10 deletions src/contract/templates/throwtestC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ See the LICENSE.txt file in the project root for more information.
#include "throwtestC.h"

ThrowTestC::ThrowTestC(
const Address& address, const Address& creator,
const uint64_t& chainId
) : DynamicContract("ThrowTestC", address, creator, chainId) {
const Address& address, const Address& creator, const uint64_t& chainId
) : DynamicContract("ThrowTestC", address, creator, chainId), num_(this) {
this->num_.commit();
registerContractFunctions();
this->num_.enableRegister();
}

ThrowTestC::ThrowTestC(
const Address& address,
const DB& db
) : DynamicContract(address, db) {
ThrowTestC::ThrowTestC(const Address& address, const DB& db) : DynamicContract(address, db) {
this->num_ = UintConv::bytesToUint8(db.get(std::string("num_"), this->getDBPrefix()));
this->num_.commit();
registerContractFunctions();
this->num_.enableRegister();
}

ThrowTestC::~ThrowTestC() { return; }

DBBatch ThrowTestC::dump() const
{
return BaseContract::dump();
DBBatch ThrowTestC::dump() const {
DBBatch dbBatch = BaseContract::dump();
dbBatch.push_back(StrConv::stringToBytes("num_"), UintConv::uint8ToBytes(this->num_.get()), this->getDBPrefix());
return dbBatch;
}

uint8_t ThrowTestC::getNumC() const { return this->num_.get(); }
Expand Down
Loading