Skip to content
Open
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
Binary file removed .gitbook/assets/applayer_step1.mp4
Binary file not shown.
Binary file removed .gitbook/assets/applayer_step2.mp4
Binary file not shown.
Binary file removed .gitbook/assets/applayer_step3.mp4
Binary file not shown.
Binary file removed .gitbook/assets/applayer_step4.mp4
Binary file not shown.
Binary file removed .gitbook/assets/applayer_step5.mp4
Binary file not shown.
Binary file added .gitbook/assets/mmwallet1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/mmwallet2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/mmwallet3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/mmwallet4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/mmwallet5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/mmwallet6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed .gitbook/assets/utils-folder.png
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ layout:

Welcome to the central hub for AppLayer documentation. This repository contains information on all the core components of the AppLayer network, such as design and architecture details, how the Blockchain Development Kit (BDK) works, a glossary of terms, community resources, documentation, developer guides, code snippets and more.

The reader should be substantially familiar with Unified Modeling Language (UML), as some sections contain diagrams that further elaborate the concepts explained.
The reader should be substantially familiar with Unified Modeling Language (UML), as some sections contain diagrams that further elaborate the concepts explained in them.
85 changes: 40 additions & 45 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,52 @@

* [Welcome to AppLayer Docs](README.md)
* [Introducing AppLayer](introducing-applayer/README.md)
* [A Primer on Smart Contracts](introducing-applayer/a-primer-on-smart-contracts.md)
* [The Problem With EVMs](introducing-applayer/the-problem-with-evms.md)
* [What is AppLayer?](introducing-applayer/what-is-applayer.md)
* [How AppLayer works](how-applayer-works/README.md)
* [Validators](how-applayer-works/validators.md)
* [Sentinels](how-applayer-works/sentinels.md)
* [Application Chains](how-applayer-works/appchains.md)
* [Bridging](how-applayer-works/bridging/README.md)
* [AppLayer-to-AppLayer Data Bridging](how-applayer-works/bridging/applayer-to-applayer-data-bridging.md)
* [AppLayer-to-AppLayer Token Bridging](how-applayer-works/bridging/applayer-to-applayer-token-bridging.md)
* [AppLayer-to-External Bridging (Ethereum, Solana, etc.)](how-applayer-works/bridging/applayer-to-external-bridging.md)
* [Understanding rdPoS](understanding-rdpos/README.md)
* [Blockchains overview](understanding-rdpos/blockchains-overview.md)
* [How rdPoS works](understanding-rdpos/how-rdpos-works.md)
* [Validator implementations](understanding-rdpos/validator-implementations.md)
* [Slashing](understanding-rdpos/slashing.md)
* [A Primer on Smart Contracts and EVMs](introducing-applayer/a-primer-on-smart-contracts-and-evms.md)
* [Enter AppLayer](introducing-applayer/enter-applayer.md)
* [Getting started](getting-started/README.md)
* [Setting up a wallet](getting-started/setting-up-a-wallet.md)
* [AppLayer Testnet](getting-started/applayer-testnet/README.md)
* [Deploying contracts](getting-started/applayer-testnet/deploying-contracts.md)
* [Developing with BDK](getting-started/developing-with-bdk/README.md)
* [Environment setup](getting-started/developing-with-bdk/environment-setup.md)
* [Compilation and deployment](getting-started/developing-with-bdk/compilation-and-deployment.md)
* [Connecting the wallet](getting-started/developing-with-bdk/connecting-the-wallet.md)
* [Contract Tester](getting-started/developing-with-bdk/contract-tester.md)
* [Contracts](contracts/README.md)
* [Solidity ABI](contracts/solidity-abi.md)
* [Internal and external contract calls](contracts/internal-and-external-contract-calls.md)
* [Precompiled contracts](contracts/precompiled-contracts/README.md)
* [Dynamic and Protocol Contracts](contracts/precompiled-contracts/dynamic-and-protocol-contracts.md)
* [Dynamic Contract Templates](contracts/precompiled-contracts/dynamic-contract-templates.md)
* [Managing precompiled contracts](contracts/precompiled-contracts/managing-precompiled-contracts.md)
* [SafeVariables and commit/revert logic](contracts/precompiled-contracts/safevariables-and-commit-revert-logic.md)
* [How to code a precompiled contract](contracts/precompiled-contracts/how-to-code-a-precompiled-contract.md)
* [Creating a Dynamic Contract (Simple)](contracts/precompiled-contracts/creating-a-dynamic-contract-simple/README.md)
* [Simple Contract Header](contracts/precompiled-contracts/creating-a-dynamic-contract-simple/simple-contract-header.md)
* [Simple Contract Source](contracts/precompiled-contracts/creating-a-dynamic-contract-simple/simple-contract-source.md)
* [Deploying and testing](contracts/precompiled-contracts/creating-a-dynamic-contract-simple/deploying-and-testing.md)
* [Creating a Dynamic Contract (Advanced)](contracts/precompiled-contracts/creating-a-dynamic-contract-advanced.md)
* [Creating a Protocol Contract](contracts/precompiled-contracts/creating-a-protocol-contract.md)
* [EVM contracts](contracts/evm-contracts/README.md)
* [Handling contract calls](contracts/evm-contracts/handling-contract-calls.md)
* [Executing contract calls via EVMC](contracts/evm-contracts/executing-contract-calls-via-evmc.md)
* [Calling contracts](contracts/evm-contracts/calling-contracts.md)
* [BDK implementation](bdk-implementation/README.md)
* [The utils folder](bdk-implementation/the-utils-folder.md)
* [The contract folder](bdk-implementation/the-contract-folder.md)
* [The core folder](bdk-implementation/the-core-folder.md)
* [Transactions and Blocks](bdk-implementation/transactions-and-blocks.md)
* [Source code overview](bdk-implementation/source-code-overview.md)
* [Transactions and blocks](bdk-implementation/transactions-and-blocks.md)
* [Database](bdk-implementation/database.md)
* [Contract call handling](bdk-implementation/contract-call-handling.md)
* [RLP (Recursive-Length Prefix)](bdk-implementation/rlp-recursive-length-prefix.md)
* [P2P Overview](bdk-implementation/p2p-overview.md)
* [P2P Encoding](bdk-implementation/p2p-encoding.md)
* [Understanding contracts](understanding-contracts/README.md)
* [Solidity ABI](understanding-contracts/solidity-abi.md)
* [Internal and external contract calls](understanding-contracts/internal-and-external-contract-calls.md)
* [Setting up the development environment](understanding-contracts/setting-up-the-development-environment.md)
* [Contract Tester](understanding-contracts/contract-tester.md)
* [Precompiled contracts](precompiled-contracts/README.md)
* [Types of pre-compiled contracts](precompiled-contracts/types-of-precompiled-contracts.md)
* [Dynamic and Protocol Contracts](precompiled-contracts/dynamic-and-protocol-contracts.md)
* [SafeVariables and commit/revert logic](precompiled-contracts/safevariables-and-commit-revert-logic.md)
* [How to code a precompiled contract](precompiled-contracts/how-to-code-a-precompiled-contract.md)
* [Creating a Dynamic Contract (Simple)](precompiled-contracts/creating-a-dynamic-contract-simple/README.md)
* [Simple Contract Header](precompiled-contracts/creating-a-dynamic-contract-simple/simple-contract-header.md)
* [Simple Contract Source](precompiled-contracts/creating-a-dynamic-contract-simple/simple-contract-source.md)
* [Deploying and testing](precompiled-contracts/creating-a-dynamic-contract-simple/deploying-and-testing.md)
* [Creating a Dynamic Contract (Advanced)](precompiled-contracts/creating-a-dynamic-contract-advanced.md)
* [Creating a Protocol Contract (Advanced)](precompiled-contracts/creating-a-protocol-contract-advanced.md)
* [EVM contracts](evm-contracts/README.md)
* [State management and VM instance creation](evm-contracts/state-management-and-vm-instance-creation.md)
* [Seamless C++/EVM integration](evm-contracts/seamless-cpp-evm-integration.md)
* [C++ to other contract calls](evm-contracts/cpp-to-other-contract-calls.md)
* [EVM to other contract calls](evm-contracts/evm-to-other-contract-calls.md)
* [Executing contract calls via EVMC](evm-contracts/executing-contract-calls-via-evmc.md)
* [Calling EVM contracts from C++](evm-contracts/calling-evm-contracts-from-cpp.md)
* [Calling C++ contracts from EVM](evm-contracts/calling-cpp-contracts-from-evm.md)
* [Getting started with AppLayer Testnet](getting-started-with-applayer-testnet.md)
* [Future Plans](future-plans/README.md)
* [Sentinels](future-plans/sentinels.md)
* [Application Chains](future-plans/appchains.md)
* [Bridging](future-plans/bridging/README.md)
* [AppLayer-to-AppLayer Data Bridging](future-plans/bridging/applayer-to-applayer-data-bridging.md)
* [AppLayer-to-AppLayer Token Bridging](future-plans/bridging/applayer-to-applayer-token-bridging.md)
* [AppLayer-to-External Bridging (Ethereum, Solana, etc.)](future-plans/bridging/applayer-to-external-bridging.md)
* [rdPoS](future-plans/rdpos.md)
* [Join our Community](join-our-community.md)
* [Get in Touch](get-in-touch.md)
* [Glossary](glossary.md)
148 changes: 13 additions & 135 deletions bdk-implementation/README.md
Original file line number Diff line number Diff line change
@@ -1,135 +1,13 @@
---
description: How the functional elements of AppLayer interact with each other.
---

# Blockchain Development Kit (BDK) implementation

This chapter aims to explain in technical detail how the BDK is implemented, as well as its submodules and how everything comes together to deliver a blazing fast blockchain.

The first few subchapters paint a more holistic view of the BDK, as most components are pretty straight-forward to understand. Developers are expected to use the [Doxygen](https://doxygen.nl) documentation as a reference to further understand how the project works. The later subchapters show some components that are particularly denser and/or complex enough that they warrant their own separated explanations.

Looking at a higher level of abstraction, the original C++ implementation of the BDK is structured like this:

* The `src/bins` folder contains the source files for the project's main executables - the blockchain executable itself, contract ABI generator, network simulator, faucet API and other testing-related executables are all coded here in their respective subfolders
* The `src/bytes` folder contains code related to the `bytes` class, a container that deals with raw bytes - specifically the `bytes::join()` function and the `bytes::View` class, both used extensively across the project
* The `src/contract` folder contains everything related to the logic of smart contracts - from ABI parsing to custom variable types and template contracts
* The `src/core` folder contains the heart of the BDK - the main components of the blockchain and what makes it tick
* The `src/libs` folder contains third-party libraries not inherently tied to the project but used throughout development
* The `src/net` folder contains everything related to networking, communication between nodes and support for protocols such as gRPC, HTTP, P2P, JSON-RPC, etc.
* The `src/utils` folder contains several commonly-used functions, structures, classes and overall logic to support the functioning of the BDK as a whole

There is also a `tests` folder that contains several unit tests for each of the components described above.

## Source tree

For the more visually inclined, here is a source tree (headers only) containing all of the files inside the `src` folder (except `src/bins` as it only contains source files), their respective subfolders and which components are declared in them. Each component is further explained through the following subchapters of this documentation. For more technical details (e.g. API references for developers), please refer to the [Doxygen](https://www.doxygen.nl) documentation on the project's own repository.

```
src
├── bytes
│   ├── initializer.h (bytes::Initializer, bytes::SizedInitializer)
│   ├── join.h (bytes::join())
│   ├── range.h (bytes::Range, bytes::DataRange, bytes::BorrowedDataRange)
│   └── view.h (bytes::View, bytes::Span)
├── contract (Contracts)
│   ├── abi.h (ABI - encoders, decoders, helper structs, etc.)
│   ├── calltracer.h (trace namespace, Call struct, CallTracer class)
│   ├── contractfactory.h (ContractFactory)
│   ├── contract.h (ContractGlobals, ContractLocals, BaseContract)
│   ├── contracthost.h (ContractHost)
│   ├── contractmanager.h (ContractManager)
│   ├── contractstack.h (ContractStack)
│   ├── customcontracts.h (for declaring custom contracts)
│   ├── dynamiccontract.h (DynamicContract)
│   ├── event.h (Event)
│   ├── templates (folder for contract templates)
│   │ ├── dexv2 (subfolder for the DEXV2 contract components)
│   │ │ ├── dexv2factory.h (DEXV2Factory)
│   │ │ ├── dexv2library.h (DEXV2Library)
│   │ │ ├── dexv2pair.h (DEXV2Pair)
│   │ │ ├── dexv2router02.h (DEXV2Router02)
│   │ │ └── uq112x112.h (UQ112x112 - used in DEX contracts for fixed-point fractions)
│   │ ├── erc20.h (ERC20)
│   │ ├── erc20wrapper.h (ERC20Wrapper)
│   │ ├── erc721.h (ERC721)
│   │ ├── erc721test.h (ERC721Test, used solely for testing purposes)
│   │   ├── erc721uristorage.h (ERC721URIStorage, converted from OpenZeppelin)
│   │ ├── nativewrapper.h (NativeWrapper)
│   │   ├── ownable.h (Ownable, converted from OpenZeppelin)
│   │   ├── pebble.h (Pebble)
│   │ ├── randomnesstest.h (RandomnessTest)
│   │ ├── simplecontract.h (SimpleContract)
│   │   ├── snailtracer.h, snailtraceroptimized.h (SnailTracer and SnailTracerOptimized, converted from the original EVM impl)
│   │ ├── testThrowVars.h (TestThrowVars, used solely for testing purposes)
│   │ └── throwtestA.h, throwtestB.h, throwtestC.h (for testing nested contract calls)
│   └── variables (Safe Variables for use within Dynamic Contracts)
│   ├── reentrancyguard.h (ReentrancyGuard)
│   ├── safeaddress.h (SafeAddress)
│   ├── safearray.h (SafeArray)
│   ├── safebase.h (SafeBase - used as base for all other types)
│   ├── safebool.h (SafeBool)
│   ├── safebytes.h (SafeBytes)
│   ├── safeint.h (SafeInt and respective aliases)
│   ├── safestring.h (SafeString)
│   ├── safetuple.h (SafeTuple)
│   ├── safeuint.h (SafeUint and respective aliases)
│   ├── safeunorderedmap.h (SafeUnorderedMap)
│   └── safevector.h (SafeVector)
├── core (Core components)
│   ├── blockchain.h (Blockchain, Syncer)
│   ├── consensus.h (Consensus)
│   ├── dump.h (Dumpable, DumpManager, DumpWorker)
│   ├── rdpos.h (Validator, rdPoS)
│   ├── state.h (BlockValidationStatus, State)
│   └── storage.h (Storage)
├── libs (Third-party libraries)
│ ├── BS_thread_pool_light.hpp (https://github.com/bshoshany/thread-pool)
│ ├── catch2/catch_amalgamated.hpp (https://github.com/catchorg/Catch2)
│ ├── json.hpp (https://github.com/nlohmann/json)
│ ├── wyhash.h (https://github.com/wangyi-fudan/wyhash)
│ └── zpp_bits.h (https://github.com/eyalz800/zpp_bits)
├── net (Networking)
│   ├── http (HTTP part of networking)
│   │   ├── httpclient.h (HTTPClient)
│   │   ├── httplistener.h (HTTPListener)
│   │   ├── httpparser.h (parser functions for HTTP requests)
│   │   ├── httpserver.h (HTTPServer)
│   │   ├── httpsession.h (HTTPQueue, HTTPSession)
│   │   └── jsonrpc (Namespace for handling JSONRPC data)
│   │   ├── blocktag.h (BlockTag, BlockTagOrNumber)
│   │   ├── call.h (call() - a function that processes a JSON RPC call)
│   │   ├── error.h (Error - for abstracting JSON RPC errors)
│   │   ├── methods.h (contains all implemented JSON RPC methods)
│   │   ├── parser.h (Parser and helper tempate functions)
│   │   └── variadicparser.h (VariadicParser and helper template functions)
│   └── p2p (P2P part of networking)
│   ├── broadcaster.h (Broadcaster)
│   ├── discovery.h (DiscoveryWorker - worker thread for ManagerDiscovery)
│   ├── encoding.h (collection of enums, structs, classes, encoders and decoders used in P2P communications)
│   ├── managerbase.h (ManagerBase - used as base for ManagerDiscovery and ManagerNormal)
│   ├── managerdiscovery.h (ManagerDiscovery)
│   ├── managernormal.h (ManagerNormal)
│   ├── nodeconns.h (NodeConns)
│   └── session.h (Session)
└── utils (Utility components)
├── clargs.h (definitions for helper functions, enums and structs that deal with command-line argument parsing)
├── contractreflectioninterface.h (ContractReflectionInterface - interface for registering Dynamic Contracts)
├── db.h (DBPrefix, DBServer, DBEntry, DBBatch, DB)
├── dynamicexception.h (DynamicException - custom exception class)
├── ecdsa.h (PrivKey, Pubkey, UPubkey, Secp256k1)
├── evmcconv.h (EVMCConv - namespace for EVMC-related data conversion functions)
├── finalizedblock.h (FinalizedBlock)
├── hex.h (Hex)
├── intconv.h (IntConv - namespace for signed integer aliases and data conversion functions)
├── jsonabi.h (JsonAbi - namespace for writing contract ABIs to JSON format)
├── logger.h (LogType, Log, LogInfo, Logger, LogicalLocationProvider)
├── merkle.h (Merkle)
├── options.h (Options singleton - generated by CMake through a .in file)
├── randomgen.h (RandomGen)
├── safehash.h (SafeHash, FNVHash)
├── strconv.h (StrConv - namespace for string-related data conversion and manipulation functions)
├── strings.h (FixedBytes and its derivatives - Hash, Functor, Signature, Address, StorageKey)
├── tx.h (TxBlock, TxValidator)
├── uintconv.h (UintConv - namespace for unsigned integer aliases and data conversion functions)
└── utils.h (Utils namespace and other misc struct and enum definitions)
```
---
description: How the functional elements of AppLayer interact with each other
---

# BDK implementation

This chapter aims to explain how the BDK and some of its most important components are implemented from a more conceptual point-of-view, giving an initial idea on how everything comes together to deliver a blazing fast blockchain.

Some subchapters paint a more holistic view of the BDK, as most components are pretty straight-forward to understand. Other subchapters focus on some components that are particularly dense and/or complex enough that they warrant their own separated explanations.

Developers are expected to read the [Doxygen](https://doxygen.nl) documentation alongside this one to further understand how the project works from a more technical point-of-view - as it is constantly being iterated upon, we make extensive use of comments and self-documenting code to keep up with the internals.

We will focus on the original implementation of the BDK (the C++ one, commonly referred to as "bdk-cpp"). Future implementations, if/when they appear, may be handled separately.
Loading