API Reference C¶
Overview¶
The C implementation of the Incubed client is prepared and optimized to run on small embedded devices. Because each device is different, we prepare different modules that should be combined. This allows us to only generate the code needed and reduce requirements for flash and memory.
This is why Incubed consists of different modules. While the core module is always required, additional functions will be prepared by different modules:
Verifier¶
Incubed is a minimal verification client, which means that each response needs to be verifiable. Depending on the expected requests and responses, you need to carefully choose which verifier you may need to register. For Ethereum, we have developed three modules:
- nano: a minimal module only able to verify transaction receipts (
eth_getTransactionReceipt
). - basic: module able to verify almost all other standard RPC functions (except
eth_call
). - full: module able to verify standard RPC functions. It also implements a full EVM to handle
eth_call
.
Depending on the module, you need to register the verifier before using it. This is done by calling the in3_register...
function like in3_register_eth_full().
Transport¶
To verify responses, you need to be able to send requests. The way to handle them depends heavily on your hardware capabilities. For example, if your device only supports Bluetooth, you may use this connection to deliver the request to a device with an existing internet connection and get the response in the same way, but if your device is able to use a direct internet connection, you may use a curl-library to execute them. This is why the core client only defines function pointer in3_transport_send, which must handle the requests.
At the moment we offer these modules; other implementations are supported by different hardware modules.
- curl: module with a dependency on curl, which executes these requests and supports HTTPS. This module runs a standard OS with curl installed.
API¶
While Incubed operates on JSON-RPC level, as a developer, you might want to use a better-structured API to prepare these requests for you. These APIs are optional but make life easier:
- eth: This module offers all standard RPC functions as described in the Ethereum JSON-RPC Specification. In addition, it allows you to sign and encode/decode calls and transactions.
- usn: This module offers basic USN functions like renting, event handling, and message verification.
Building¶
While we provide binaries, you can also build from source:
requirements¶
- cmake
- curl : curl is used as transport for command-line tools.
- optional: libsycrypt, which would be used for unlocking keystore files using
scrypt
as kdf method. if it does not exist you can still build, but not decrypt such keys.
for osx brew install libscrypt
and for debian sudo apt-get install libscrypt-dev
Incubed uses cmake for configuring:
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release .. && make
make install
CMake options¶
EVM_GAS¶
if true the gas costs are verified when validating a eth_call. This is a optimization since most calls are only interessted in the result. EVM_GAS would be required if the contract uses gas-dependend op-codes.
Type: BOOL
, Default-Value: ON
FAST_MATH¶
Math optimizations used in the EVM. This will also increase the filesize.
Type: BOOL
, Default-Value: OFF
IN3API¶
build the USN-API which offer better interfaces and additional functions on top of the pure verification
Type: BOOL
, Default-Value: ON
IN3_LIB¶
if true a shared anmd static library with all in3-modules will be build.
Type: BOOL
, Default-Value: ON
IN3_STAGING¶
if true, the client will use the staging-network instead of the live ones
Type: BOOL
, Default-Value: ON
SEGGER_RTT¶
Use the segger real time transfer terminal as the logging mechanism
Type: BOOL
, Default-Value: OFF
TEST¶
builds the tests and also adds special memory-management, which detects memory leaks, but will cause slower performance
Type: BOOL
, Default-Value: OFF
USE_SCRYPT¶
if scrypt is installed, it will link dynamicly to the shared scrypt lib.
Type: BOOL
, Default-Value: OFF
WASM¶
Includes the WASM-Build. In order to build it you need emscripten as toolchain. Usually you also want to turn off other builds in this case.
Type: BOOL
, Default-Value: OFF
Examples¶
The full list of examples can be found here: https://git.slock.it/in3/c/in3-core/tree/develop/examples/c
Creating an Incubed Instance¶
creating always follow these steps:
#include <client/client.h> // the core client
#include <eth_full.h> // the full ethereum verifier containing the EVM
#include <in3_curl.h> // transport implementation
// register verifiers, in this case a full verifier allowing eth_call
// this needs to be called only once.
in3_register_eth_full();
// use curl as the default for sending out requests
// this needs to be called only once.
in3_register_curl();
// create new client
in3_t* client = in3_new();
// ready to use ...
Calling a Function¶
// define a address (20byte)
address_t contract;
// copy the hexcoded string into this address
hex2byte_arr("0x845E484b505443814B992Bf0319A5e8F5e407879", -1, contract, 20);
// ask for the number of servers registered
json_ctx_t* response = eth_call_fn(client, contract, "totalServers():uint256");
// handle response
if (!response) {
printf("Could not get the response: %s", eth_last_error());
return;
}
// convert the result to a integer
int number_of_servers = d_int(response->result);
// don't forget to free the response!
free_json(response);
// out put result
printf("Found %i servers registered : \n", number_of_servers);
// now we call a function with a complex result...
for (int i = 0; i < number_of_servers; i++) {
// get all the details for one server.
response = eth_call_fn(c, contract, "servers(uint256):(string,address,uint,uint,uint,address)", to_uint256(i));
// handle error
if (!response) {
printf("Could not get the response: %s", eth_last_error());
return;
}
// decode data
char* url = d_get_string_at(response->result, 0); // get the first item of the result (the url)
bytes_t* owner = d_get_bytes_at(response->result, 1); // get the second item of the result (the owner)
uint64_t deposit = d_get_long_at(response->result, 2); // get the third item of the result (the deposit)
// print values
printf("Server %i : %s owner = ", i, url);
ba_print(owner->data, owner->len);
printf(", deposit = %" PRIu64 "\n", deposit);
// clean up
free_json(response);
}
Module api/eth1¶
eth_api.h¶
Ethereum API.
This header-file defines easy to use function, which are preparing the JSON-RPC-Request, which is then executed and verified by the incubed-client.
Location: src/api/eth1/eth_api.h
BLKNUM (blk)¶
Initializer macros for eth_blknum_t.
#define BLKNUM (blk) ((eth_blknum_t){.u64 = blk, .is_u64 = true})
BLKNUM_LATEST ()¶
#define BLKNUM_LATEST () ((eth_blknum_t){.def = BLK_LATEST, .is_u64 = false})
BLKNUM_EARLIEST ()¶
#define BLKNUM_EARLIEST () ((eth_blknum_t){.def = BLK_EARLIEST, .is_u64 = false})
BLKNUM_PENDING ()¶
#define BLKNUM_PENDING () ((eth_blknum_t){.def = BLK_PENDING, .is_u64 = false})
eth_blknum_def_t¶
Abstract type for holding a block number.
The enum type contains the following values:
BLK_LATEST | 0 |
BLK_EARLIEST | 1 |
BLK_PENDING | 2 |
eth_tx_t¶
A transaction.
The stuct contains following fields:
bytes32_t | hash | the blockhash |
bytes32_t | block_hash | hash of ther containnig block |
uint64_t |
block_number | number of the containing block |
address_t | from | sender of the tx |
uint64_t |
gas | gas send along |
uint64_t |
gas_price | gas price used |
bytes_t | data | data send along with the transaction |
uint64_t |
nonce | nonce of the transaction |
address_t | to | receiver of the address 0x0000. . -Address is used for contract creation. |
uint256_t | value | the value in wei send |
int |
transaction_index | the transaction index |
uint8_t |
signature | signature of the transaction |
eth_block_t¶
An Ethereum Block.
The stuct contains following fields:
uint64_t |
number | the blockNumber |
bytes32_t | hash | the blockhash |
uint64_t |
gasUsed | gas used by all the transactions |
uint64_t |
gasLimit | gasLimit |
address_t | author | the author of the block. |
uint256_t | difficulty | the difficulty of the block. |
bytes_t | extra_data | the extra_data of the block. |
uint8_t |
logsBloom | the logsBloom-data |
bytes32_t | parent_hash | the hash of the parent-block |
bytes32_t | sha3_uncles | root hash of the uncle-trie |
bytes32_t | state_root | root hash of the state-trie |
bytes32_t | receipts_root | root of the receipts trie |
bytes32_t | transaction_root | root of the transaction trie |
int |
tx_count | number of transactions in the block |
eth_tx_t * | tx_data | array of transaction data or NULL if not requested |
bytes32_t * | tx_hashes | array of transaction hashes or NULL if not requested |
uint64_t |
timestamp | the unix timestamp of the block |
bytes_t * | seal_fields | sealed fields |
int |
seal_fields_count | number of seal fields |
eth_log_t¶
A linked list of Ethereum Logs.
The stuct contains following fields:
bool |
removed | true when the log was removed, due to a chain reorganization. false if its a valid log |
size_t |
log_index | log index position in the block |
size_t |
transaction_index | transactions index position log was created from |
bytes32_t | transaction_hash | hash of the transactions this log was created from |
bytes32_t | block_hash | hash of the block where this log was in |
uint64_t |
block_number | the block number where this log was in |
address_t | address | address from which this log originated |
bytes_t | data | non-indexed arguments of the log |
bytes32_t * | topics | array of 0 to 4 32 Bytes DATA of indexed log arguments |
size_t |
topic_count | counter for topics |
eth_logstruct , * | next | pointer to next log in list or NULL |
eth_tx_receipt_t¶
A transaction receipt.
The stuct contains following fields:
bytes32_t | transaction_hash | the transaction hash |
int |
transaction_index | the transaction index |
bytes32_t | block_hash | hash of ther containnig block |
uint64_t |
block_number | number of the containing block |
uint64_t |
cumulative_gas_used | total amount of gas used by block |
uint64_t |
gas_used | amount of gas used by this specific transaction |
bytes_t * | contract_address | contract address created (if the transaction was a contract creation) or NULL |
bool |
status | 1 if transaction succeeded, 0 otherwise. |
eth_log_t * | logs | array of log objects, which this transaction generated |
eth_getStorageAt¶
uint256_t eth_getStorageAt(in3_t *in3, address_t account, bytes32_t key, eth_blknum_t block);
Returns the storage value of a given address.
arguments:
in3_t * | in3 |
address_t | account |
bytes32_t | key |
eth_blknum_t | block |
returns: uint256_t
eth_getCode¶
bytes_t eth_getCode(in3_t *in3, address_t account, eth_blknum_t block);
Returns the code of the account of given address.
(Make sure you free the data-point of the result after use.)
arguments:
in3_t * | in3 |
address_t | account |
eth_blknum_t | block |
returns: bytes_t
eth_getBalance¶
uint256_t eth_getBalance(in3_t *in3, address_t account, eth_blknum_t block);
Returns the balance of the account of given address.
arguments:
in3_t * | in3 |
address_t | account |
eth_blknum_t | block |
returns: uint256_t
eth_blockNumber¶
uint64_t eth_blockNumber(in3_t *in3);
Returns the current price per gas in wei.
arguments:
in3_t * | in3 |
returns: uint64_t
eth_gasPrice¶
uint64_t eth_gasPrice(in3_t *in3);
Returns the current blockNumber, if bn==0 an error occured and you should check eth_last_error()
arguments:
in3_t * | in3 |
returns: uint64_t
eth_getBlockByNumber¶
eth_block_t* eth_getBlockByNumber(in3_t *in3, eth_blknum_t number, bool include_tx);
Returns the block for the given number (if number==0, the latest will be returned).
If result is null, check eth_last_error()! otherwise make sure to free the result after using it!
arguments:
in3_t * | in3 |
eth_blknum_t | number |
bool |
include_tx |
returns: eth_block_t *
eth_getBlockByHash¶
eth_block_t* eth_getBlockByHash(in3_t *in3, bytes32_t hash, bool include_tx);
Returns the block for the given hash.
If result is null, check eth_last_error()! otherwise make sure to free the result after using it!
arguments:
in3_t * | in3 |
bytes32_t | hash |
bool |
include_tx |
returns: eth_block_t *
eth_getLogs¶
eth_log_t* eth_getLogs(in3_t *in3, char *fopt);
Returns a linked list of logs.
If result is null, check eth_last_error()! otherwise make sure to free the log, its topics and data after using it!
arguments:
in3_t * | in3 |
char * |
fopt |
returns: eth_log_t *
eth_newFilter¶
in3_ret_t eth_newFilter(in3_t *in3, json_ctx_t *options);
Creates a new event filter with specified options and returns its id (>0) on success or 0 on failure.
arguments:
in3_t * | in3 |
json_ctx_t * | options |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
eth_newBlockFilter¶
in3_ret_t eth_newBlockFilter(in3_t *in3);
Creates a new block filter with specified options and returns its id (>0) on success or 0 on failure.
arguments:
in3_t * | in3 |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
eth_newPendingTransactionFilter¶
in3_ret_t eth_newPendingTransactionFilter(in3_t *in3);
Creates a new pending txn filter with specified options and returns its id on success or 0 on failure.
arguments:
in3_t * | in3 |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
eth_uninstallFilter¶
bool eth_uninstallFilter(in3_t *in3, size_t id);
Uninstalls a filter and returns true on success or false on failure.
arguments:
in3_t * | in3 |
size_t |
id |
returns: bool
eth_getFilterChanges¶
in3_ret_t eth_getFilterChanges(in3_t *in3, size_t id, bytes32_t **block_hashes, eth_log_t **logs);
Sets the logs (for event filter) or blockhashes (for block filter) that match a filter; returns <0 on error, otherwise no.
of block hashes matched (for block filter) or 0 (for log filter)
arguments:
in3_t * | in3 |
size_t |
id |
bytes32_t ** | block_hashes |
eth_log_t ** | logs |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
eth_getFilterLogs¶
in3_ret_t eth_getFilterLogs(in3_t *in3, size_t id, eth_log_t **logs);
Sets the logs (for event filter) or blockhashes (for block filter) that match a filter; returns <0 on error, otherwise no.
of block hashes matched (for block filter) or 0 (for log filter)
arguments:
in3_t * | in3 |
size_t |
id |
eth_log_t ** | logs |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
eth_chainId¶
uint64_t eth_chainId(in3_t *in3);
Returns the currently configured chain id.
arguments:
in3_t * | in3 |
returns: uint64_t
eth_getBlockTransactionCountByHash¶
uint64_t eth_getBlockTransactionCountByHash(in3_t *in3, bytes32_t hash);
Returns the number of transactions in a block from a block matching the given block hash.
arguments:
in3_t * | in3 |
bytes32_t | hash |
returns: uint64_t
eth_getBlockTransactionCountByNumber¶
uint64_t eth_getBlockTransactionCountByNumber(in3_t *in3, eth_blknum_t block);
Returns the number of transactions in a block from a block matching the given block number.
arguments:
in3_t * | in3 |
eth_blknum_t | block |
returns: uint64_t
eth_call_fn¶
json_ctx_t* eth_call_fn(in3_t *in3, address_t contract, eth_blknum_t block, char *fn_sig,...);
Returns the result of a function_call.
If result is null, check eth_last_error()! otherwise make sure to free the result after using it with free_json()!
arguments:
in3_t * | in3 |
address_t | contract |
eth_blknum_t | block |
char * |
fn_sig |
... |
returns: json_ctx_t *
eth_estimate_fn¶
uint64_t eth_estimate_fn(in3_t *in3, address_t contract, eth_blknum_t block, char *fn_sig,...);
Returns the result of a function_call.
If result is null, check eth_last_error()! otherwise make sure to free the result after using it with free_json()!
arguments:
in3_t * | in3 |
address_t | contract |
eth_blknum_t | block |
char * |
fn_sig |
... |
returns: uint64_t
eth_getTransactionByHash¶
eth_tx_t* eth_getTransactionByHash(in3_t *in3, bytes32_t tx_hash);
Returns the information about a transaction requested by transaction hash.
If result is null, check eth_last_error()! otherwise make sure to free the result after using it!
arguments:
in3_t * | in3 |
bytes32_t | tx_hash |
returns: eth_tx_t *
eth_getTransactionByBlockHashAndIndex¶
eth_tx_t* eth_getTransactionByBlockHashAndIndex(in3_t *in3, bytes32_t block_hash, size_t index);
Returns the information about a transaction by block hash and transaction index position.
If result is null, check eth_last_error()! otherwise make sure to free the result after using it!
arguments:
in3_t * | in3 |
bytes32_t | block_hash |
size_t |
index |
returns: eth_tx_t *
eth_getTransactionByBlockNumberAndIndex¶
eth_tx_t* eth_getTransactionByBlockNumberAndIndex(in3_t *in3, eth_blknum_t block, size_t index);
Returns the information about a transaction by block number and transaction index position.
If result is null, check eth_last_error()! otherwise make sure to free the result after using it!
arguments:
in3_t * | in3 |
eth_blknum_t | block |
size_t |
index |
returns: eth_tx_t *
eth_getTransactionCount¶
uint64_t eth_getTransactionCount(in3_t *in3, address_t address, eth_blknum_t block);
Returns the number of transactions sent from an address.
arguments:
in3_t * | in3 |
address_t | address |
eth_blknum_t | block |
returns: uint64_t
eth_getUncleByBlockNumberAndIndex¶
eth_block_t* eth_getUncleByBlockNumberAndIndex(in3_t *in3, bytes32_t hash, size_t index);
Returns information about a uncle of a block by number and uncle index position.
If result is null, check eth_last_error()! otherwise make sure to free the result after using it!
arguments:
in3_t * | in3 |
bytes32_t | hash |
size_t |
index |
returns: eth_block_t *
eth_getUncleCountByBlockHash¶
uint64_t eth_getUncleCountByBlockHash(in3_t *in3, bytes32_t hash);
Returns the number of uncles in a block from a block matching the given block hash.
arguments:
in3_t * | in3 |
bytes32_t | hash |
returns: uint64_t
eth_getUncleCountByBlockNumber¶
uint64_t eth_getUncleCountByBlockNumber(in3_t *in3, eth_blknum_t block);
Returns the number of uncles in a block from a block matching the given block number.
arguments:
in3_t * | in3 |
eth_blknum_t | block |
returns: uint64_t
eth_sendTransaction¶
bytes_t* eth_sendTransaction(in3_t *in3, address_t from, address_t to, OPTIONAL_T(uint64_t) gas, OPTIONAL_T(uint64_t) gas_price, OPTIONAL_T(uint256_t) value, OPTIONAL_T(bytes_t) data, OPTIONAL_T(uint64_t) nonce);
Creates new message call transaction or a contract creation.
Returns (32 Bytes) - the transaction hash, or the zero hash if the transaction is not yet available. Free result after use with b_free().
arguments:
in3_t * | in3 |
address_t | from |
address_t | to |
OPTIONAL_T(uint64_t) |
gas |
OPTIONAL_T(uint64_t) |
gas_price |
uint256_tOPTIONAL_T(,) | value |
bytes_tOPTIONAL_T(,) | data |
OPTIONAL_T(uint64_t) |
nonce |
returns: bytes_t *
eth_sendRawTransaction¶
bytes_t* eth_sendRawTransaction(in3_t *in3, bytes_t data);
Creates new message call transaction or a contract creation for signed transactions.
Returns (32 Bytes) - the transaction hash, or the zero hash if the transaction is not yet available. Free after use with b_free().
arguments:
in3_t * | in3 |
bytes_t | data |
returns: bytes_t *
eth_getTransactionReceipt¶
eth_tx_receipt_t* eth_getTransactionReceipt(in3_t *in3, bytes32_t tx_hash);
Returns the receipt of a transaction by transaction hash.
Free result after use with free_tx_receipt()
arguments:
in3_t * | in3 |
bytes32_t | tx_hash |
returns: eth_tx_receipt_t *
eth_wait_for_receipt¶
char* eth_wait_for_receipt(in3_t *in3, bytes32_t tx_hash);
Waits for receipt of a transaction requested by transaction hash.
arguments:
in3_t * | in3 |
bytes32_t | tx_hash |
returns: char *
as_double¶
long double as_double(uint256_t d);
Converts a uint256_t in a long double.
Important: since a long double stores max 16 byte, there is no guarantee to have the full precision.
Converts a uint256_t in a long double.
arguments:
uint256_t | d |
returns: long double
as_long¶
uint64_t as_long(uint256_t d);
Converts a uint256_t in a long .
Important: since a long double stores 8 byte, this will only use the last 8 byte of the value.
Converts a uint256_t in a long .
arguments:
uint256_t | d |
returns: uint64_t
to_uint256¶
uint256_t to_uint256(uint64_t value);
Converts a uint64_t into its uint256_t representation.
arguments:
uint64_t |
value |
returns: uint256_t
decrypt_key¶
in3_ret_t decrypt_key(d_token_t *key_data, char *password, bytes32_t dst);
Decrypts the private key from a json keystore file using PBKDF2 or SCRYPT (if enabled)
arguments:
d_token_t * | key_data |
char * |
password |
bytes32_t | dst |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
free_tx_receipt¶
void free_tx_receipt(eth_tx_receipt_t *txr);
Frees a eth_tx_receipt_t object.
arguments:
eth_tx_receipt_t * | txr |
Module api/usn¶
usn_api.h¶
USN API.
This header-file defines easy to use function, which are verifying USN-Messages.
Location: src/api/usn/usn_api.h
usn_msg_type_t¶
The enum type contains the following values:
USN_ACTION | 0 |
USN_REQUEST | 1 |
USN_RESPONSE | 2 |
usn_event_type_t¶
The enum type contains the following values:
BOOKING_NONE | 0 |
BOOKING_START | 1 |
BOOKING_STOP | 2 |
usn_verify_message¶
usn_msg_result_t usn_verify_message(usn_device_conf_t *conf, char *message);
arguments:
usn_device_conf_t * | conf |
char * |
message |
returns: usn_msg_result_t
usn_register_device¶
in3_ret_t usn_register_device(usn_device_conf_t *conf, char *url);
arguments:
usn_device_conf_t * | conf |
char * |
url |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
usn_update_state¶
unsigned int usn_update_state(usn_device_conf_t *conf, unsigned int wait_time);
arguments:
usn_device_conf_t * | conf |
unsigned int |
wait_time |
returns: unsigned int
usn_update_bookings¶
in3_ret_t usn_update_bookings(usn_device_conf_t *conf);
arguments:
usn_device_conf_t * | conf |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
usn_remove_old_bookings¶
void usn_remove_old_bookings(usn_device_conf_t *conf);
arguments:
usn_device_conf_t * | conf |
usn_get_next_event¶
usn_event_t usn_get_next_event(usn_device_conf_t *conf);
arguments:
usn_device_conf_t * | conf |
returns: usn_event_t
usn_rent¶
in3_ret_t usn_rent(in3_t *c, address_t contract, address_t token, char *url, uint32_t seconds, bytes32_t tx_hash);
arguments:
in3_t * | c |
address_t | contract |
address_t | token |
char * |
url |
uint32_t |
seconds |
bytes32_t | tx_hash |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
usn_return¶
in3_ret_t usn_return(in3_t *c, address_t contract, char *url, bytes32_t tx_hash);
arguments:
in3_t * | c |
address_t | contract |
char * |
url |
bytes32_t | tx_hash |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
usn_price¶
in3_ret_t usn_price(in3_t *c, address_t contract, address_t token, char *url, uint32_t seconds, address_t controller, bytes32_t price);
arguments:
in3_t * | c |
address_t | contract |
address_t | token |
char * |
url |
uint32_t |
seconds |
address_t | controller |
bytes32_t | price |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
Module cmd/in3¶
Module core¶
cache.h¶
handles caching and storage.
storing nodelists and other caches with the storage handler as specified in the client. If no storage handler is specified nothing will be cached.
Location: src/core/client/cache.h
in3_cache_update_nodelist¶
in3_ret_t in3_cache_update_nodelist(in3_t *c, in3_chain_t *chain);
reads the nodelist from cache.
This function is usually called internally to fill the weights and nodelist from the the cache. If you call in3_cache_init
there is no need to call this explicitly.
arguments:
in3_t * | c | the incubed client |
in3_chain_t * | chain | chain to configure |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_cache_store_nodelist¶
in3_ret_t in3_cache_store_nodelist(in3_ctx_t *ctx, in3_chain_t *chain);
stores the nodelist to thes cache.
It will automaticly called if the nodelist has changed and read from the nodes or the wirght of a node changed.
arguments:
in3_ctx_t * | ctx | the current incubed context |
in3_chain_t * | chain | the chain upating to cache |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
client.h¶
incubed main client file.
This includes the definition of the client and used enum values.
Location: src/core/client/client.h
IN3_PROTO_VER¶
#define IN3_PROTO_VER 0x2
ETH_CHAIN_ID_MAINNET¶
#define ETH_CHAIN_ID_MAINNET 0x01L
ETH_CHAIN_ID_KOVAN¶
#define ETH_CHAIN_ID_KOVAN 0x2aL
ETH_CHAIN_ID_TOBALABA¶
#define ETH_CHAIN_ID_TOBALABA 0x44dL
ETH_CHAIN_ID_GOERLI¶
#define ETH_CHAIN_ID_GOERLI 0x5L
ETH_CHAIN_ID_EVAN¶
#define ETH_CHAIN_ID_EVAN 0x4b1L
ETH_CHAIN_ID_IPFS¶
#define ETH_CHAIN_ID_IPFS 0x7d0
ETH_CHAIN_ID_VOLTA¶
#define ETH_CHAIN_ID_VOLTA 0x12046
ETH_CHAIN_ID_LOCAL¶
#define ETH_CHAIN_ID_LOCAL 0xFFFFL
IN3_SIGN_ERR_REJECTED¶
return value used by the signer if the the signature-request was rejected.
#define IN3_SIGN_ERR_REJECTED -1
IN3_SIGN_ERR_ACCOUNT_NOT_FOUND¶
return value used by the signer if the requested account was not found.
#define IN3_SIGN_ERR_ACCOUNT_NOT_FOUND -2
IN3_SIGN_ERR_INVALID_MESSAGE¶
return value used by the signer if the message was invalid.
#define IN3_SIGN_ERR_INVALID_MESSAGE -3
IN3_SIGN_ERR_GENERAL_ERROR¶
return value used by the signer for unspecified errors.
#define IN3_SIGN_ERR_GENERAL_ERROR -4
in3_chain_type_t¶
the type of the chain.
for incubed a chain can be any distributed network or database with incubed support. Depending on this chain-type the previously registered verifyer will be choosen and used.
The enum type contains the following values:
CHAIN_ETH | 0 | Ethereum chain. |
CHAIN_SUBSTRATE | 1 | substrate chain |
CHAIN_IPFS | 2 | ipfs verifiaction |
CHAIN_BTC | 3 | Bitcoin chain. |
CHAIN_IOTA | 4 | IOTA chain. |
CHAIN_GENERIC | 5 | other chains |
in3_proof_t¶
the type of proof.
Depending on the proof-type different levels of proof will be requested from the node.
The enum type contains the following values:
PROOF_NONE | 0 | No Verification. |
PROOF_STANDARD | 1 | Standard Verification of the important properties. |
PROOF_FULL | 2 | All field will be validated including uncles. |
in3_verification_t¶
verification as delivered by the server.
This will be part of the in3-request and will be generated based on the prooftype.
The enum type contains the following values:
VERIFICATION_NEVER | 0 | No Verifacation. |
VERIFICATION_PROOF | 1 | Includes the proof of the data. |
VERIFICATION_PROOF_WITH_SIGNATURE | 2 | Proof + Signatures. |
d_signature_type_t¶
type of the requested signature
The enum type contains the following values:
SIGN_EC_RAW | 0 | sign the data directly |
SIGN_EC_HASH | 1 | hash and sign the data |
in3_filter_type_t¶
The enum type contains the following values:
FILTER_EVENT | 0 | Event filter. |
FILTER_BLOCK | 1 | Block filter. |
FILTER_PENDING | 2 | Pending filter (Unsupported) |
in3_request_config_t¶
the configuration as part of each incubed request.
This will be generated for each request based on the client-configuration. the verifier may access this during verification in order to check against the request.
The stuct contains following fields:
uint64_t |
chainId | the chain to be used. this is holding the integer-value of the hexstring. |
uint8_t |
includeCode | if true the code needed will always be devlivered. |
uint8_t |
useFullProof | this flaqg is set, if the proof is set to “PROOF_FULL” |
uint8_t |
useBinary | this flaqg is set, the client should use binary-format |
bytes_t * | verifiedHashes | a list of blockhashes already verified. The Server will not send any proof for them again . |
uint16_t |
verifiedHashesCount | number of verified blockhashes |
uint16_t |
latestBlock | the last blocknumber the nodelistz changed |
uint16_t |
finality | number of signatures( in percent) needed in order to reach finality. |
in3_verification_t | verification | Verification-type. |
bytes_t * | clientSignature | the signature of the client with the client key |
bytes_t * | signatures | the addresses of servers requested to sign the blockhash |
uint8_t |
signaturesCount | number or addresses |
in3_node_t¶
incubed node-configuration.
These information are read from the Registry contract and stored in this struct representing a server or node.
The stuct contains following fields:
uint32_t |
index | index within the nodelist, also used in the contract as key |
bytes_t * | address | address of the server |
uint64_t |
deposit | the deposit stored in the registry contract, which this would lose if it sends a wrong blockhash |
uint32_t |
capacity | the maximal capacity able to handle |
uint64_t |
props | a bit set used to identify the cabalilities of the server. |
char * |
url | the url of the node |
in3_node_weight_t¶
Weight or reputation of a node.
Based on the past performance of the node a weight is calulcated given faster nodes a heigher weight and chance when selecting the next node from the nodelist. These weights will also be stored in the cache (if available)
The stuct contains following fields:
float |
weight | current weight |
uint32_t |
response_count | counter for responses |
uint32_t |
total_response_time | total of all response times |
uint64_t |
blacklistedUntil | if >0 this node is blacklisted until k. k is a unix timestamp |
in3_chain_t¶
Chain definition inside incubed.
for incubed a chain can be any distributed network or database with incubed support.
The stuct contains following fields:
uint64_t |
chainId | chainId, which could be a free or based on the public ethereum networkId |
in3_chain_type_t | type | chaintype |
uint64_t |
lastBlock | last blocknumber the nodeList was updated, which is used to detect changed in the nodelist |
bool |
needsUpdate | if true the nodelist should be updated and will trigger a in3_nodeList-request before the next request is send. |
int |
nodeListLength | number of nodes in the nodeList |
in3_node_t * | nodeList | array of nodes |
in3_node_weight_t * | weights | stats and weights recorded for each node |
bytes_t ** | initAddresses | array of addresses of nodes that should always part of the nodeList |
bytes_t * | contract | the address of the registry contract |
bytes32_t | registry_id | the identifier of the registry |
uint8_t |
version | version of the chain |
json_ctx_t * | spec | optional chain specification, defining the transaitions and forks |
in3_storage_get_item¶
storage handler function for reading from cache.
typedef bytes_t*(* in3_storage_get_item) (void *cptr, char *key)
returns: bytes_t *(*
: the found result. if the key is found this function should return the values as bytes otherwise NULL
.
in3_storage_set_item¶
storage handler function for writing to the cache.
typedef void(* in3_storage_set_item) (void *cptr, char *key, bytes_t *value)
in3_storage_handler_t¶
storage handler to handle cache.
The stuct contains following fields:
in3_storage_get_item | get_item | function pointer returning a stored value for the given key. |
in3_storage_set_item | set_item | function pointer setting a stored value for the given key. |
void * |
cptr | custom pointer which will will be passed to functions |
in3_sign¶
signing function.
signs the given data and write the signature to dst. the return value must be the number of bytes written to dst. In case of an error a negativ value must be returned. It should be one of the IN3_SIGN_ERR… values.
typedef in3_ret_t(* in3_sign) (void *wallet, d_signature_type_t type, bytes_t message, bytes_t account, uint8_t *dst)
returns: in3_ret_t(*
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_response_t¶
response-object.
if the error has a length>0 the response will be rejected
The stuct contains following fields:
sb_t | error | a stringbuilder to add any errors! |
sb_t | result | a stringbuilder to add the result |
in3_transport_send¶
the transport function to be implemented by the transport provider.
typedef in3_ret_t(* in3_transport_send) (char **urls, int urls_len, char *payload, in3_response_t *results)
returns: in3_ret_t(*
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_filter_t¶
The stuct contains following fields:
in3_filter_type_t | type | filter type: (event, block or pending) |
char * |
options | associated filter options |
uint64_t |
last_block | block no. when filter was created OR eth_getFilterChanges was called |
void(* |
release | method to release owned resources |
in3_filter_handler_t¶
The stuct contains following fields:
in3_filter_t ** | array | |
size_t |
count | array of filters |
in3_t¶
Incubed Configuration.
This struct holds the configuration and also point to internal resources such as filters or chain configs.
The stuct contains following fields:
uint32_t |
cacheTimeout | number of seconds requests can be cached. |
uint16_t |
nodeLimit | the limit of nodes to store in the client. |
bytes_t * | key | the client key to sign requests |
uint32_t |
maxCodeCache | number of max bytes used to cache the code in memory |
uint32_t |
maxBlockCache | number of number of blocks cached in memory |
in3_proof_t | proof | the type of proof used |
uint8_t |
requestCount | the number of request send when getting a first answer |
uint8_t |
signatureCount | the number of signatures used to proof the blockhash. |
uint64_t |
minDeposit | min stake of the server. Only nodes owning at least this amount will be chosen. |
uint16_t |
replaceLatestBlock | if specified, the blocknumber latest will be replaced by blockNumber- specified value |
uint16_t |
finality | the number of signatures in percent required for the request |
uint16_t |
max_attempts | the max number of attempts before giving up |
uint32_t |
timeout | specifies the number of milliseconds before the request times out. increasing may be helpful if the device uses a slow connection. |
uint64_t |
chainId | servers to filter for the given chain. The chain-id based on EIP-155. |
uint8_t |
autoUpdateList | if true the nodelist will be automaticly updated if the lastBlock is newer |
in3_storage_handler_t * | cacheStorage | a cache handler offering 2 functions ( setItem(string,string), getItem(string) ) |
in3_signer_t * | signer | signer-struct managing a wallet |
in3_transport_send | transport | the transporthandler sending requests |
uint8_t |
includeCode | includes the code when sending eth_call-requests |
uint8_t |
use_binary | if true the client will use binary format |
uint8_t |
use_http | if true the client will try to use http instead of https |
in3_chain_t * | chains | chain spec and nodeList definitions |
uint16_t |
chainsCount | number of configured chains |
in3_filter_handler_t * | filters | filter handler |
in3_new¶
in3_t* in3_new();
creates a new Incubes configuration and returns the pointer.
you need to free this instance with in3_free
after use!
Before using the client you still need to set the tramsport and optional the storage handlers:
- example of initialization:
// register verifiers
in3_register_eth_full();
// create new client
in3_t* client = in3_new();
// configure storage...
in3_storage_handler_t storage_handler;
storage_handler.get_item = storage_get_item;
storage_handler.set_item = storage_set_item;
// configure transport
client->transport = send_curl;
// configure storage
client->cacheStorage = &storage_handler;
// init cache
in3_cache_init(client);
// ready to use ...
returns: in3_t *
: the incubed instance.
in3_client_rpc¶
in3_ret_t in3_client_rpc(in3_t *c, char *method, char *params, char **result, char **error);
sends a request and stores the result in the provided buffer
arguments:
in3_t * | c | the pointer to the incubed client config. |
char * |
method | the name of the rpc-funcgtion to call. |
char * |
params | docs for input parameter v. |
char ** |
result | pointer to string which will be set if the request was successfull. This will hold the result as json-rpc-string. (make sure you free this after use!) |
char ** |
error | pointer to a string containg the error-message. (make sure you free it after use!) |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_client_register_chain¶
in3_ret_t in3_client_register_chain(in3_t *client, uint64_t chain_id, in3_chain_type_t type, address_t contract, bytes32_t registry_id, uint8_t version, json_ctx_t *spec);
registers a new chain or replaces a existing (but keeps the nodelist)
arguments:
in3_t * | client | the pointer to the incubed client config. |
uint64_t |
chain_id | the chain id. |
in3_chain_type_t | type | the verification type of the chain. |
address_t | contract | contract of the registry. |
bytes32_t | registry_id | the identifier of the registry. |
uint8_t |
version | the chain version. |
json_ctx_t * | spec | chainspec or NULL. |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_client_add_node¶
in3_ret_t in3_client_add_node(in3_t *client, uint64_t chain_id, char *url, uint64_t props, address_t address);
adds a node to a chain ore updates a existing node
[in] public address of the signer.
arguments:
in3_t * | client | the pointer to the incubed client config. |
uint64_t |
chain_id | the chain id. |
char * |
url | url of the nodes. |
uint64_t |
props | properties of the node. |
address_t | address |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_client_remove_node¶
in3_ret_t in3_client_remove_node(in3_t *client, uint64_t chain_id, address_t address);
removes a node from a nodelist
[in] public address of the signer.
arguments:
in3_t * | client | the pointer to the incubed client config. |
uint64_t |
chain_id | the chain id. |
address_t | address |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_client_clear_nodes¶
in3_ret_t in3_client_clear_nodes(in3_t *client, uint64_t chain_id);
removes all nodes from the nodelist
[in] the chain id.
arguments:
in3_t * | client | the pointer to the incubed client config. |
uint64_t |
chain_id |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_free¶
void in3_free(in3_t *a);
frees the references of the client
arguments:
in3_t * | a | the pointer to the incubed client config to free. |
in3_cache_init¶
in3_ret_t in3_cache_init(in3_t *c);
inits the cache.
arguments:
in3_t * | c | the incubed client |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_configure¶
in3_ret_t in3_configure(in3_t *c, char *config);
configures the clent based on a json-config.
For details about the structure of ther config see https://in3.readthedocs.io/en/develop/api-ts.html#type-in3config
arguments:
in3_t * | c |
char * |
config |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_set_default_transport¶
void in3_set_default_transport(in3_transport_send transport);
defines a default transport which is used when creating a new client.
arguments:
in3_transport_send | transport |
in3_set_default_storage¶
void in3_set_default_storage(in3_storage_handler_t *cacheStorage);
defines a default storage handler which is used when creating a new client.
arguments:
in3_storage_handler_t * | cacheStorage |
in3_set_default_signer¶
void in3_set_default_signer(in3_signer_t *signer);
defines a default signer which is used when creating a new client.
arguments:
in3_signer_t * | signer |
context.h¶
Request Context.
This is used for each request holding request and response-pointers.
Location: src/core/client/context.h
node_weight_t¶
the weight of a ceertain node as linked list
The stuct contains following fields:
in3_node_t * | node | the node definition including the url |
in3_node_weight_t * | weight | the current weight and blacklisting-stats |
float |
s | The starting value. |
float |
w | weight value |
weightstruct , * | next | next in the linkedlistt or NULL if this is the last element |
new_ctx¶
in3_ctx_t* new_ctx(in3_t *client, char *req_data);
creates a new context.
the request data will be parsed and represented in the context.
arguments:
in3_t * | client |
char * |
req_data |
returns: in3_ctx_t *
ctx_parse_response¶
in3_ret_t ctx_parse_response(in3_ctx_t *ctx, char *response_data, int len);
arguments:
in3_ctx_t * | ctx |
char * |
response_data |
int |
len |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
ctx_create_payload¶
in3_ret_t ctx_create_payload(in3_ctx_t *c, sb_t *sb);
arguments:
in3_ctx_t * | c |
sb_t * | sb |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
ctx_set_error¶
in3_ret_t ctx_set_error(in3_ctx_t *c, char *msg, in3_ret_t errnumber);
arguments:
in3_ctx_t * | c |
char * |
msg |
in3_ret_t | errnumber |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
ctx_get_error¶
in3_ret_t ctx_get_error(in3_ctx_t *ctx, int id);
arguments:
in3_ctx_t * | ctx |
int |
id |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_client_rpc_ctx¶
in3_ctx_t* in3_client_rpc_ctx(in3_t *c, char *method, char *params);
sends a request and returns a context used to access the result or errors.
This context MUST be freed with free_ctx(ctx) after usage to release the resources.
arguments:
in3_t * | c |
char * |
method |
char * |
params |
returns: in3_ctx_t *
nodelist.h¶
handles nodelists.
Location: src/core/client/nodelist.h
in3_nodelist_clear¶
void in3_nodelist_clear(in3_chain_t *chain);
removes all nodes and their weights from the nodelist
arguments:
in3_chain_t * | chain |
in3_node_list_get¶
in3_ret_t in3_node_list_get(in3_ctx_t *ctx, uint64_t chain_id, bool update, in3_node_t **nodeList, int *nodeListLength, in3_node_weight_t **weights);
check if the nodelist is up to date.
if not it will fetch a new version first (if the needs_update-flag is set).
arguments:
in3_ctx_t * | ctx |
uint64_t |
chain_id |
bool |
update |
in3_node_t ** | nodeList |
int * |
nodeListLength |
in3_node_weight_t ** | weights |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_node_list_fill_weight¶
node_weight_t* in3_node_list_fill_weight(in3_t *c, in3_node_t *all_nodes, in3_node_weight_t *weights, int len, _time_t now, float *total_weight, int *total_found);
filters and fills the weights on a returned linked list.
arguments:
in3_t * | c |
in3_node_t * | all_nodes |
in3_node_weight_t * | weights |
int |
len |
_time_t |
now |
float * |
total_weight |
int * |
total_found |
returns: node_weight_t *
in3_node_list_pick_nodes¶
in3_ret_t in3_node_list_pick_nodes(in3_ctx_t *ctx, node_weight_t **nodes);
picks (based on the config) a random number of nodes and returns them as weightslist.
arguments:
in3_ctx_t * | ctx |
node_weight_t ** | nodes |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
send.h¶
handles caching and storage.
handles the request.
Location: src/core/client/send.h
in3_send_ctx¶
in3_ret_t in3_send_ctx(in3_ctx_t *ctx);
executes a request context by picking nodes and sending it.
arguments:
in3_ctx_t * | ctx |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
verifier.h¶
Verification Context.
This context is passed to the verifier.
Location: src/core/client/verifier.h
in3_verify¶
function to verify the result.
typedef in3_ret_t(* in3_verify) (in3_vctx_t *c)
returns: in3_ret_t(*
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_pre_handle¶
typedef in3_ret_t(* in3_pre_handle) (in3_ctx_t *ctx, in3_response_t **response)
returns: in3_ret_t(*
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_verifier_t¶
The stuct contains following fields:
in3_verify | verify |
in3_pre_handle |
pre_handle |
in3_chain_type_t | type |
verifierstruct , * | next |
in3_get_verifier¶
in3_verifier_t* in3_get_verifier(in3_chain_type_t type);
returns the verifier for the given chainType
arguments:
in3_chain_type_t | type |
returns: in3_verifier_t *
in3_register_verifier¶
void in3_register_verifier(in3_verifier_t *verifier);
arguments:
in3_verifier_t * | verifier |
vc_err¶
in3_ret_t vc_err(in3_vctx_t *vc, char *msg);
arguments:
in3_vctx_t * | vc |
char * |
msg |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
bytes.h¶
util helper on byte arrays.
Location: src/core/util/bytes.h
bb_new ()¶
#define bb_new () bb_newl(32)
bb_read (bb,i,vptr)¶
#define bb_read (_bb_,_i_,_vptr_) bb_readl((_bb_), (_i_), (_vptr_), sizeof(*_vptr_))
bb_read_next (bb,iptr,vptr)¶
#define bb_read_next (_bb_,_iptr_,_vptr_) do { \
size_t _l_ = sizeof(*_vptr_); \
bb_readl((_bb_), *(_iptr_), (_vptr_), _l_); \
*(_iptr_) += _l_; \
} while (0)
bb_readl (bb,i,vptr,l)¶
#define bb_readl (_bb_,_i_,_vptr_,_l_) memcpy((_vptr_), (_bb_)->b.data + (_i_), _l_)
b_read (b,i,vptr)¶
#define b_read (_b_,_i_,_vptr_) b_readl((_b_), (_i_), _vptr_, sizeof(*_vptr_))
b_readl (b,i,vptr,l)¶
#define b_readl (_b_,_i_,_vptr_,_l_) memcpy(_vptr_, (_b_)->data + (_i_), (_l_))
bytes_t¶
a byte array
The stuct contains following fields:
uint32_t |
len | the length of the array ion bytes |
uint8_t * |
data | the byte-data |
b_new¶
bytes_t* b_new(char *data, int len);
allocates a new byte array with 0 filled
arguments:
char * |
data |
int |
len |
returns: bytes_t *
ba_print¶
void ba_print(uint8_t *a, size_t l);
prints a the bytes as hex to stdout
arguments:
uint8_t * |
a |
size_t |
l |
b_cmp¶
int b_cmp(bytes_t *a, bytes_t *b);
compares 2 byte arrays and returns 1 for equal and 0 for not equal
arguments:
bytes_t * | a |
bytes_t * | b |
returns: int
bytes_cmp¶
int bytes_cmp(bytes_t a, bytes_t b);
compares 2 byte arrays and returns 1 for equal and 0 for not equal
arguments:
bytes_t | a |
bytes_t | b |
returns: int
b_read_byte¶
uint8_t b_read_byte(bytes_t *b, size_t *pos);
reads a byte on the current position and updates the pos afterwards.
arguments:
bytes_t * | b |
size_t * |
pos |
returns: uint8_t
b_read_short¶
uint16_t b_read_short(bytes_t *b, size_t *pos);
reads a short on the current position and updates the pos afterwards.
arguments:
bytes_t * | b |
size_t * |
pos |
returns: uint16_t
b_read_int¶
uint32_t b_read_int(bytes_t *b, size_t *pos);
reads a integer on the current position and updates the pos afterwards.
arguments:
bytes_t * | b |
size_t * |
pos |
returns: uint32_t
b_read_int_be¶
uint32_t b_read_int_be(bytes_t *b, size_t *pos, size_t len);
reads a unsigned integer as bigendian on the current position and updates the pos afterwards.
arguments:
bytes_t * | b |
size_t * |
pos |
size_t |
len |
returns: uint32_t
b_read_long¶
uint64_t b_read_long(bytes_t *b, size_t *pos);
reads a long on the current position and updates the pos afterwards.
arguments:
bytes_t * | b |
size_t * |
pos |
returns: uint64_t
b_new_chars¶
char* b_new_chars(bytes_t *b, size_t *pos);
creates a new string (needs to be freed) on the current position and updates the pos afterwards.
arguments:
bytes_t * | b |
size_t * |
pos |
returns: char *
b_new_dyn_bytes¶
bytes_t* b_new_dyn_bytes(bytes_t *b, size_t *pos);
reads bytesn (which have the length stored as prefix) on the current position and updates the pos afterwards.
arguments:
bytes_t * | b |
size_t * |
pos |
returns: bytes_t *
b_new_fixed_bytes¶
bytes_t* b_new_fixed_bytes(bytes_t *b, size_t *pos, int len);
reads bytes with a fixed length on the current position and updates the pos afterwards.
arguments:
bytes_t * | b |
size_t * |
pos |
int |
len |
returns: bytes_t *
bb_free¶
void bb_free(bytes_builder_t *bb);
frees a bytebuilder and its content.
arguments:
bytes_builder_t * | bb |
bb_check_size¶
int bb_check_size(bytes_builder_t *bb, size_t len);
internal helper to increase the buffer if needed
arguments:
bytes_builder_t * | bb |
size_t |
len |
returns: int
bb_write_chars¶
void bb_write_chars(bytes_builder_t *bb, char *c, int len);
writes a string to the builder.
arguments:
bytes_builder_t * | bb |
char * |
c |
int |
len |
bb_write_dyn_bytes¶
void bb_write_dyn_bytes(bytes_builder_t *bb, bytes_t *src);
writes bytes to the builder with a prefixed length.
arguments:
bytes_builder_t * | bb |
bytes_t * | src |
bb_write_fixed_bytes¶
void bb_write_fixed_bytes(bytes_builder_t *bb, bytes_t *src);
writes fixed bytes to the builder.
arguments:
bytes_builder_t * | bb |
bytes_t * | src |
bb_write_int¶
void bb_write_int(bytes_builder_t *bb, uint32_t val);
writes a ineteger to the builder.
arguments:
bytes_builder_t * | bb |
uint32_t |
val |
bb_write_long¶
void bb_write_long(bytes_builder_t *bb, uint64_t val);
writes s long to the builder.
arguments:
bytes_builder_t * | bb |
uint64_t |
val |
bb_write_long_be¶
void bb_write_long_be(bytes_builder_t *bb, uint64_t val, int len);
writes any integer value with the given length of bytes
arguments:
bytes_builder_t * | bb |
uint64_t |
val |
int |
len |
bb_write_byte¶
void bb_write_byte(bytes_builder_t *bb, uint8_t val);
writes a single byte to the builder.
arguments:
bytes_builder_t * | bb |
uint8_t |
val |
bb_write_short¶
void bb_write_short(bytes_builder_t *bb, uint16_t val);
writes a short to the builder.
arguments:
bytes_builder_t * | bb |
uint16_t |
val |
bb_write_raw_bytes¶
void bb_write_raw_bytes(bytes_builder_t *bb, void *ptr, size_t len);
writes the bytes to the builder.
arguments:
bytes_builder_t * | bb |
void * |
ptr |
size_t |
len |
bb_clear¶
void bb_clear(bytes_builder_t *bb);
resets the content of the builder.
arguments:
bytes_builder_t * | bb |
bb_replace¶
void bb_replace(bytes_builder_t *bb, int offset, int delete_len, uint8_t *data, int data_len);
replaces or deletes a part of the content.
arguments:
bytes_builder_t * | bb |
int |
offset |
int |
delete_len |
uint8_t * |
data |
int |
data_len |
bb_move_to_bytes¶
bytes_t* bb_move_to_bytes(bytes_builder_t *bb);
frees the builder and moves the content in a newly created bytes struct (which needs to be freed later).
arguments:
bytes_builder_t * | bb |
returns: bytes_t *
bb_push¶
void bb_push(bytes_builder_t *bb, uint8_t *data, uint8_t len);
arguments:
bytes_builder_t * | bb |
uint8_t * |
data |
uint8_t |
len |
bb_read_long¶
uint64_t bb_read_long(bytes_builder_t *bb, size_t *i);
arguments:
bytes_builder_t * | bb |
size_t * |
i |
returns: uint64_t
bb_read_int¶
uint32_t bb_read_int(bytes_builder_t *bb, size_t *i);
arguments:
bytes_builder_t * | bb |
size_t * |
i |
returns: uint32_t
data.h¶
json-parser.
The parser can read from :
- json
- bin
When reading from json all ‘0x’… values will be stored as bytes_t. If the value is lower than 0xFFFFFFF, it is converted as integer.
Location: src/core/util/data.h
DATA_DEPTH_MAX¶
the max DEPTH of the JSON-data allowed.
It will throw an error if reached.
#define DATA_DEPTH_MAX 11
printX¶
#define printX printf
fprintX¶
#define fprintX fprintf
snprintX¶
#define snprintX snprintf
vprintX¶
#define vprintX vprintf
d_type_t¶
type of a token.
The enum type contains the following values:
T_BYTES | 0 | content is stored as data ptr. |
T_STRING | 1 | content is stored a c-str |
T_ARRAY | 2 | the node is an array with the length stored in length |
T_OBJECT | 3 | the node is an object with properties |
T_BOOLEAN | 4 | boolean with the value stored in len |
T_INTEGER | 5 | a integer with the value stored |
T_NULL | 6 | a NULL-value |
d_key_t¶
typedef uint16_t d_key_t
d_token_t¶
a token holding any kind of value.
use d_type, d_len or the cast-function to get the value.
The stuct contains following fields:
uint32_t |
len | the length of the content (or number of properties) depending + type. |
uint8_t * |
data | the byte or string-data |
d_key_t |
key | the key of the property. |
str_range_t¶
internal type used to represent the a range within a string.
The stuct contains following fields:
char * |
data | pointer to the start of the string |
size_t |
len | len of the characters |
json_ctx_t¶
parser for json or binary-data.
it needs to freed after usage.
The stuct contains following fields:
d_token_t * | result | the list of all tokens. the first token is the main-token as returned by the parser. |
size_t |
allocated | |
size_t |
len | amount of tokens allocated result |
size_t |
depth | number of tokens in result |
char * |
c | max depth of tokens in result |
d_iterator_t¶
iterator over elements of a array opf object.
usage:
for (d_iterator_t iter = d_iter( parent ); iter.left ; d_iter_next(&iter)) {
uint32_t val = d_int(iter.token);
}
The stuct contains following fields:
int |
left | number of result left |
d_token_t * | token | current token |
d_to_bytes¶
bytes_t d_to_bytes(d_token_t *item);
returns the byte-representation of token.
In case of a number it is returned as bigendian. booleans as 0x01 or 0x00 and NULL as 0x. Objects or arrays will return 0x.
arguments:
d_token_t * | item |
returns: bytes_t
d_bytes_to¶
int d_bytes_to(d_token_t *item, uint8_t *dst, const int max);
writes the byte-representation to the dst.
details see d_to_bytes.
arguments:
d_token_t * | item |
uint8_t * |
dst |
const int |
max |
returns: int
d_bytes¶
bytes_t* d_bytes(const d_token_t *item);
returns the value as bytes (Carefully, make sure that the token is a bytes-type!)
arguments:
d_token_tconst , * | item |
returns: bytes_t *
d_bytesl¶
bytes_t* d_bytesl(d_token_t *item, size_t l);
returns the value as bytes with length l (may reallocates)
arguments:
d_token_t * | item |
size_t |
l |
returns: bytes_t *
d_string¶
char* d_string(const d_token_t *item);
converts the value as string.
Make sure the type is string!
arguments:
d_token_tconst , * | item |
returns: char *
d_int¶
uint32_t d_int(const d_token_t *item);
returns the value as integer.
only if type is integer
arguments:
d_token_tconst , * | item |
returns: uint32_t
d_intd¶
uint32_t d_intd(const d_token_t *item, const uint32_t def_val);
returns the value as integer or if NULL the default.
only if type is integer
arguments:
d_token_tconst , * | item |
const uint32_t |
def_val |
returns: uint32_t
d_long¶
uint64_t d_long(const d_token_t *item);
returns the value as long.
only if type is integer or bytes, but short enough
arguments:
d_token_tconst , * | item |
returns: uint64_t
d_longd¶
uint64_t d_longd(const d_token_t *item, const uint64_t def_val);
returns the value as long or if NULL the default.
only if type is integer or bytes, but short enough
arguments:
d_token_tconst , * | item |
const uint64_t |
def_val |
returns: uint64_t
d_create_bytes_vec¶
bytes_t** d_create_bytes_vec(const d_token_t *arr);
arguments:
d_token_tconst , * | arr |
returns: bytes_t **
d_type¶
static d_type_t d_type(const d_token_t *item);
creates a array of bytes from JOSN-array
type of the token
arguments:
d_token_tconst , * | item |
returns: d_type_t
d_len¶
static int d_len(const d_token_t *item);
number of elements in the token (only for object or array, other will return 0)
arguments:
d_token_tconst , * | item |
returns: int
d_eq¶
bool d_eq(const d_token_t *a, const d_token_t *b);
compares 2 token and if the value is equal
arguments:
d_token_tconst , * | a |
d_token_tconst , * | b |
returns: bool
keyn¶
d_key_t keyn(const char *c, const int len);
generates the keyhash for the given stringrange as defined by len
arguments:
const char * |
c |
const int |
len |
returns: d_key_t
d_get¶
d_token_t* d_get(d_token_t *item, const uint16_t key);
returns the token with the given propertyname (only if item is a object)
arguments:
d_token_t * | item |
const uint16_t |
key |
returns: d_token_t *
d_get_or¶
d_token_t* d_get_or(d_token_t *item, const uint16_t key1, const uint16_t key2);
returns the token with the given propertyname or if not found, tries the other.
(only if item is a object)
arguments:
d_token_t * | item |
const uint16_t |
key1 |
const uint16_t |
key2 |
returns: d_token_t *
d_get_at¶
d_token_t* d_get_at(d_token_t *item, const uint32_t index);
returns the token of an array with the given index
arguments:
d_token_t * | item |
const uint32_t |
index |
returns: d_token_t *
d_next¶
d_token_t* d_next(d_token_t *item);
returns the next sibling of an array or object
arguments:
d_token_t * | item |
returns: d_token_t *
d_prev¶
d_token_t* d_prev(d_token_t *item);
returns the prev sibling of an array or object
arguments:
d_token_t * | item |
returns: d_token_t *
d_serialize_binary¶
void d_serialize_binary(bytes_builder_t *bb, d_token_t *t);
write the token as binary data into the builder
arguments:
bytes_builder_t * | bb |
d_token_t * | t |
parse_binary¶
json_ctx_t* parse_binary(bytes_t *data);
parses the data and returns the context with the token, which needs to be freed after usage!
arguments:
bytes_t * | data |
returns: json_ctx_t *
parse_binary_str¶
json_ctx_t* parse_binary_str(char *data, int len);
parses the data and returns the context with the token, which needs to be freed after usage!
arguments:
char * |
data |
int |
len |
returns: json_ctx_t *
parse_json¶
json_ctx_t* parse_json(char *js);
parses json-data, which needs to be freed after usage!
arguments:
char * |
js |
returns: json_ctx_t *
free_json¶
void free_json(json_ctx_t *parser_ctx);
frees the parse-context after usage
arguments:
json_ctx_t * | parser_ctx |
d_to_json¶
str_range_t d_to_json(d_token_t *item);
returns the string for a object or array.
This only works for json as string. For binary it will not work!
arguments:
d_token_t * | item |
returns: str_range_t
d_create_json¶
char* d_create_json(d_token_t *item);
creates a json-string.
It does not work for objects if the parsed data were binary!
arguments:
d_token_t * | item |
returns: char *
json_create_null¶
d_token_t* json_create_null(json_ctx_t *jp);
arguments:
json_ctx_t * | jp |
returns: d_token_t *
json_create_bool¶
d_token_t* json_create_bool(json_ctx_t *jp, bool value);
arguments:
json_ctx_t * | jp |
bool |
value |
returns: d_token_t *
json_create_int¶
d_token_t* json_create_int(json_ctx_t *jp, uint64_t value);
arguments:
json_ctx_t * | jp |
uint64_t |
value |
returns: d_token_t *
json_create_string¶
d_token_t* json_create_string(json_ctx_t *jp, char *value);
arguments:
json_ctx_t * | jp |
char * |
value |
returns: d_token_t *
json_create_bytes¶
d_token_t* json_create_bytes(json_ctx_t *jp, bytes_t value);
arguments:
json_ctx_t * | jp |
bytes_t | value |
returns: d_token_t *
json_create_object¶
d_token_t* json_create_object(json_ctx_t *jp);
arguments:
json_ctx_t * | jp |
returns: d_token_t *
json_create_array¶
d_token_t* json_create_array(json_ctx_t *jp);
arguments:
json_ctx_t * | jp |
returns: d_token_t *
json_object_add_prop¶
d_token_t* json_object_add_prop(d_token_t *object, d_key_t key, d_token_t *value);
arguments:
d_token_t * | object |
d_key_t |
key |
d_token_t * | value |
returns: d_token_t *
json_array_add_value¶
d_token_t* json_array_add_value(d_token_t *object, d_token_t *value);
arguments:
d_token_t * | object |
d_token_t * | value |
returns: d_token_t *
json_get_int_value¶
int json_get_int_value(char *js, char *prop);
parses the json and return the value as int.
arguments:
char * |
js |
char * |
prop |
returns: int
json_get_str_value¶
void json_get_str_value(char *js, char *prop, char *dst);
parses the json and return the value as string.
arguments:
char * |
js |
char * |
prop |
char * |
dst |
json_get_json_value¶
char* json_get_json_value(char *js, char *prop);
parses the json and return the value as json-string.
arguments:
char * |
js |
char * |
prop |
returns: char *
d_get_keystr¶
char* d_get_keystr(d_key_t k);
returns the string for a key.
This only works track_keynames was activated before!
arguments:
d_key_t |
k |
returns: char *
d_track_keynames¶
void d_track_keynames(uint8_t v);
activates the keyname-cache, which stores the string for the keys when parsing.
arguments:
uint8_t |
v |
d_get_stringk¶
static char* d_get_stringk(d_token_t *r, d_key_t k);
reads token of a property as string.
arguments:
d_token_t * | r |
d_key_t |
k |
returns: char *
d_get_string¶
static char* d_get_string(d_token_t *r, char *k);
reads token of a property as string.
arguments:
d_token_t * | r |
char * |
k |
returns: char *
d_get_string_at¶
static char* d_get_string_at(d_token_t *r, uint32_t pos);
reads string at given pos of an array.
arguments:
d_token_t * | r |
uint32_t |
pos |
returns: char *
d_get_intk¶
static uint32_t d_get_intk(d_token_t *r, d_key_t k);
reads token of a property as int.
arguments:
d_token_t * | r |
d_key_t |
k |
returns: uint32_t
d_get_intkd¶
static uint32_t d_get_intkd(d_token_t *r, d_key_t k, uint32_t d);
reads token of a property as int.
arguments:
d_token_t * | r |
d_key_t |
k |
uint32_t |
d |
returns: uint32_t
d_get_int¶
static uint32_t d_get_int(d_token_t *r, char *k);
reads token of a property as int.
arguments:
d_token_t * | r |
char * |
k |
returns: uint32_t
d_get_int_at¶
static uint32_t d_get_int_at(d_token_t *r, uint32_t pos);
reads a int at given pos of an array.
arguments:
d_token_t * | r |
uint32_t |
pos |
returns: uint32_t
d_get_longk¶
static uint64_t d_get_longk(d_token_t *r, d_key_t k);
reads token of a property as long.
arguments:
d_token_t * | r |
d_key_t |
k |
returns: uint64_t
d_get_longkd¶
static uint64_t d_get_longkd(d_token_t *r, d_key_t k, uint64_t d);
reads token of a property as long.
arguments:
d_token_t * | r |
d_key_t |
k |
uint64_t |
d |
returns: uint64_t
d_get_long¶
static uint64_t d_get_long(d_token_t *r, char *k);
reads token of a property as long.
arguments:
d_token_t * | r |
char * |
k |
returns: uint64_t
d_get_long_at¶
static uint64_t d_get_long_at(d_token_t *r, uint32_t pos);
reads long at given pos of an array.
arguments:
d_token_t * | r |
uint32_t |
pos |
returns: uint64_t
d_get_bytesk¶
static bytes_t* d_get_bytesk(d_token_t *r, d_key_t k);
reads token of a property as bytes.
arguments:
d_token_t * | r |
d_key_t |
k |
returns: bytes_t *
d_get_bytes¶
static bytes_t* d_get_bytes(d_token_t *r, char *k);
reads token of a property as bytes.
arguments:
d_token_t * | r |
char * |
k |
returns: bytes_t *
d_get_bytes_at¶
static bytes_t* d_get_bytes_at(d_token_t *r, uint32_t pos);
reads bytes at given pos of an array.
arguments:
d_token_t * | r |
uint32_t |
pos |
returns: bytes_t *
d_is_binary_ctx¶
static bool d_is_binary_ctx(json_ctx_t *ctx);
check if the parser context was created from binary data.
arguments:
json_ctx_t * | ctx |
returns: bool
d_get_byteskl¶
bytes_t* d_get_byteskl(d_token_t *r, d_key_t k, uint32_t minl);
arguments:
d_token_t * | r |
d_key_t |
k |
uint32_t |
minl |
returns: bytes_t *
d_getl¶
d_token_t* d_getl(d_token_t *item, uint16_t k, uint32_t minl);
arguments:
d_token_t * | item |
uint16_t |
k |
uint32_t |
minl |
returns: d_token_t *
d_iter¶
static d_iterator_t d_iter(d_token_t *parent);
creates a iterator for a object or array
arguments:
d_token_t * | parent |
returns: d_iterator_t
d_iter_next¶
static bool d_iter_next(d_iterator_t *const iter);
fetched the next token an returns a boolean indicating whther there is a next or not.
arguments:
d_iterator_t *const | iter |
returns: bool
debug.h¶
logs debug data only if the DEBUG-flag is set.
Location: src/core/util/debug.h
dbg_log (msg,…)¶
dbg_log_raw (msg,…)¶
msg_dump¶
void msg_dump(const char *s, unsigned char *data, unsigned len);
arguments:
const char * |
s |
unsigned char * |
data |
unsigned |
len |
error.h¶
defines the return-values of a function call.
Location: src/core/util/error.h
OPTIONAL_T (t)¶
#define OPTIONAL_T (t) opt_##t
DEFINE_OPTIONAL_T (t)¶
#define DEFINE_OPTIONAL_T (t) typedef struct { \
t value; \
bool defined; \
} OPTIONAL_T(t)
OPTIONAL_T_UNDEFINED (t)¶
#define OPTIONAL_T_UNDEFINED (t) ((OPTIONAL_T(t)){.defined = false})
OPTIONAL_T_VALUE (t,v)¶
#define OPTIONAL_T_VALUE (t,v) ((OPTIONAL_T(t)){.value = v, .defined = true})
in3_ret_t¶
ERROR types used as return values.
All values (except IN3_OK) indicate an error.
The enum type contains the following values:
IN3_OK | 0 | Success. |
IN3_EUNKNOWN | -1 | Unknown error - usually accompanied with specific error msg. |
IN3_ENOMEM | -2 | No memory. |
IN3_ENOTSUP | -3 | Not supported. |
IN3_EINVAL | -4 | Invalid value. |
IN3_EFIND | -5 | Not found. |
IN3_ECONFIG | -6 | Invalid config. |
IN3_ELIMIT | -7 | Limit reached. |
IN3_EVERS | -8 | Version mismatch. |
IN3_EINVALDT | -9 | Data invalid, eg. invalid/incomplete JSON |
IN3_EPASS | -10 | Wrong password. |
IN3_ERPC | -11 | RPC error (i.e. in3_ctx_t::error set) |
IN3_ERPCNRES | -12 | RPC no response. |
IN3_EUSNURL | -13 | USN URL parse error. |
IN3_ETRANS | -14 | Transport error. |
IN3_ERANGE | -15 | Not in range. |
scache.h¶
util helper on byte arrays.
Location: src/core/util/scache.h
cache_entry_t¶
The stuct contains following fields:
bytes_t | key |
bytes_t | value |
uint8_t |
must_free |
uint8_t |
buffer |
cache_entrystruct , * | next |
in3_cache_get_entry¶
bytes_t* in3_cache_get_entry(cache_entry_t *cache, bytes_t *key);
arguments:
cache_entry_t * | cache |
bytes_t * | key |
returns: bytes_t *
in3_cache_add_entry¶
cache_entry_t* in3_cache_add_entry(cache_entry_t *cache, bytes_t key, bytes_t value);
arguments:
cache_entry_t * | cache |
bytes_t | key |
bytes_t | value |
returns: cache_entry_t *
stringbuilder.h¶
simple string buffer used to dynamicly add content.
Location: src/core/util/stringbuilder.h
sb_add_hexuint (sb,i)¶
#define sb_add_hexuint (sb,i) sb_add_hexuint_l(sb, i, sizeof(i))
sb_add_chars¶
sb_t* sb_add_chars(sb_t *sb, char *chars);
arguments:
sb_t * | sb |
char * |
chars |
returns: sb_t *
sb_add_range¶
sb_t* sb_add_range(sb_t *sb, const char *chars, int start, int len);
arguments:
sb_t * | sb |
const char * |
chars |
int |
start |
int |
len |
returns: sb_t *
sb_add_key_value¶
sb_t* sb_add_key_value(sb_t *sb, char *key, char *value, int lv, bool as_string);
arguments:
sb_t * | sb |
char * |
key |
char * |
value |
int |
lv |
bool |
as_string |
returns: sb_t *
utils.h¶
utility functions.
Location: src/core/util/utils.h
SWAP (a,b)¶
#define SWAP (a,b) { \
void* p = a; \
a = b; \
b = p; \
}
min (a,b)¶
#define min (a,b) ((a) < (b) ? (a) : (b))
max (a,b)¶
#define max (a,b) ((a) > (b) ? (a) : (b))
IS_APPROX (n1,n2,err)¶
#define IS_APPROX (n1,n2,err) ((n1 > n2) ? ((n1 - n2) <= err) : ((n2 - n1) <= err))
optimize_len (a,l)¶
#define optimize_len (a,l) while (l > 1 && *a == 0) { \
l--; \
a++; \
}
TRY (exp)¶
#define TRY (exp) { \
int _r = (exp); \
if (_r < 0) return _r; \
}
TRY_SET (var,exp)¶
#define TRY_SET (var,exp) { \
var = (exp); \
if (var < 0) return var; \
}
TRY_GOTO (exp)¶
#define TRY_GOTO (exp) { \
res = (exp); \
if (res < 0) goto clean; \
}
pb_size_t¶
typedef uint32_t pb_size_t
pb_byte_t¶
typedef uint_least8_t pb_byte_t
bytes_to_long¶
uint64_t bytes_to_long(uint8_t *data, int len);
converts the bytes to a unsigned long (at least the last max len bytes)
arguments:
uint8_t * |
data |
int |
len |
returns: uint64_t
bytes_to_int¶
static uint32_t bytes_to_int(uint8_t *data, int len);
converts the bytes to a unsigned int (at least the last max len bytes)
arguments:
uint8_t * |
data |
int |
len |
returns: uint32_t
c_to_long¶
uint64_t c_to_long(char *a, int l);
converts a character into a uint64_t
arguments:
char * |
a |
int |
l |
returns: uint64_t
size_of_bytes¶
int size_of_bytes(int str_len);
the number of bytes used for a conerting a hex into bytes.
arguments:
int |
str_len |
returns: int
strtohex¶
uint8_t strtohex(char c);
converts a hexchar to byte (4bit)
arguments:
char |
c |
returns: uint8_t
u64tostr¶
const unsigned char* u64tostr(uint64_t value, char *pBuf, int szBuf);
converts a uint64_t to string (char*); buffer-size min.
21 bytes
arguments:
uint64_t |
value |
char * |
pBuf |
int |
szBuf |
returns: const unsigned char *
hex2byte_arr¶
int hex2byte_arr(char *buf, int len, uint8_t *out, int outbuf_size);
convert a c string to a byte array storing it into a existing buffer
arguments:
char * |
buf |
int |
len |
uint8_t * |
out |
int |
outbuf_size |
returns: int
hex2byte_new_bytes¶
bytes_t* hex2byte_new_bytes(char *buf, int len);
convert a c string to a byte array creating a new buffer
arguments:
char * |
buf |
int |
len |
returns: bytes_t *
bytes_to_hex¶
int bytes_to_hex(uint8_t *buffer, int len, char *out);
convefrts a bytes into hex
arguments:
uint8_t * |
buffer |
int |
len |
char * |
out |
returns: int
sha3¶
bytes_t* sha3(bytes_t *data);
hashes the bytes and creates a new bytes_t
arguments:
bytes_t * | data |
returns: bytes_t *
sha3_to¶
int sha3_to(bytes_t *data, void *dst);
writes 32 bytes to the pointer.
arguments:
bytes_t * | data |
void * |
dst |
returns: int
long_to_bytes¶
void long_to_bytes(uint64_t val, uint8_t *dst);
converts a long to 8 bytes
arguments:
uint64_t |
val |
uint8_t * |
dst |
int_to_bytes¶
void int_to_bytes(uint32_t val, uint8_t *dst);
converts a int to 4 bytes
arguments:
uint32_t |
val |
uint8_t * |
dst |
hash_cmp¶
int hash_cmp(uint8_t *a, uint8_t *b);
compares 32 bytes and returns 0 if equal
arguments:
uint8_t * |
a |
uint8_t * |
b |
returns: int
_strdupn¶
char* _strdupn(char *src, int len);
duplicate the string
arguments:
char * |
src |
int |
len |
returns: char *
min_bytes_len¶
int min_bytes_len(uint64_t val);
calculate the min number of byte to represents the len
arguments:
uint64_t |
val |
returns: int
uint256_set¶
void uint256_set(uint8_t *src, wlen_t src_len, uint8_t dst[32]);
sets a variable value to 32byte word.
arguments:
uint8_t * |
src |
wlen_t | src_len |
uint8_t |
dst |
str_replace¶
char* str_replace(char *orig, char *rep, char *with);
arguments:
char * |
orig |
char * |
rep |
char * |
with |
returns: char *
str_replace_pos¶
char* str_replace_pos(char *orig, size_t pos, size_t len, const char *rep);
arguments:
char * |
orig |
size_t |
pos |
size_t |
len |
const char * |
rep |
returns: char *
str_find¶
char* str_find(char *haystack, const char *needle);
arguments:
char * |
haystack |
const char * |
needle |
returns: char *
Module transport/curl¶
in3_curl.h¶
transport-handler using libcurl.
Location: src/transport/curl/in3_curl.h
send_curl¶
in3_ret_t send_curl(char **urls, int urls_len, char *payload, in3_response_t *result);
the transport function using curl.
arguments:
char ** |
urls |
int |
urls_len |
char * |
payload |
in3_response_t * | result |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
Module transport/http¶
in3_http.h¶
transport-handler using simple http.
Location: src/transport/http/in3_http.h
send_http¶
in3_ret_t send_http(char **urls, int urls_len, char *payload, in3_response_t *result);
arguments:
char ** |
urls |
int |
urls_len |
char * |
payload |
in3_response_t * | result |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
Module verifier/eth1/basic¶
eth_basic.h¶
Ethereum Nanon verification.
Location: src/verifier/eth1/basic/eth_basic.h
in3_verify_eth_basic¶
in3_ret_t in3_verify_eth_basic(in3_vctx_t *v);
entry-function to execute the verification context.
arguments:
in3_vctx_t * | v |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
eth_verify_tx_values¶
in3_ret_t eth_verify_tx_values(in3_vctx_t *vc, d_token_t *tx, bytes_t *raw);
verifies internal tx-values.
arguments:
in3_vctx_t * | vc |
d_token_t * | tx |
bytes_t * | raw |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
eth_verify_eth_getTransaction¶
in3_ret_t eth_verify_eth_getTransaction(in3_vctx_t *vc, bytes_t *tx_hash);
verifies a transaction.
arguments:
in3_vctx_t * | vc |
bytes_t * | tx_hash |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
eth_verify_account_proof¶
in3_ret_t eth_verify_account_proof(in3_vctx_t *vc);
verify account-proofs
arguments:
in3_vctx_t * | vc |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
eth_verify_eth_getBlock¶
in3_ret_t eth_verify_eth_getBlock(in3_vctx_t *vc, bytes_t *block_hash, uint64_t blockNumber);
verifies a block
arguments:
in3_vctx_t * | vc |
bytes_t * | block_hash |
uint64_t |
blockNumber |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_register_eth_basic¶
void in3_register_eth_basic();
this function should only be called once and will register the eth-nano verifier.
eth_verify_eth_getLog¶
in3_ret_t eth_verify_eth_getLog(in3_vctx_t *vc, int l_logs);
verify logs
arguments:
in3_vctx_t * | vc |
int |
l_logs |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
eth_handle_intern¶
in3_ret_t eth_handle_intern(in3_ctx_t *ctx, in3_response_t **response);
this is called before a request is send
arguments:
in3_ctx_t * | ctx |
in3_response_t ** | response |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
signer.h¶
Ethereum Nano verification.
Location: src/verifier/eth1/basic/signer.h
eth_set_pk_signer¶
in3_ret_t eth_set_pk_signer(in3_t *in3, bytes32_t pk);
sets the signer and a pk to the client
arguments:
in3_t * | in3 |
bytes32_t | pk |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
trie.h¶
Patricia Merkle Tree Imnpl.
Location: src/verifier/eth1/basic/trie.h
trie_node_type_t¶
Node types.
The enum type contains the following values:
NODE_EMPTY | 0 | empty node |
NODE_BRANCH | 1 | a Branch |
NODE_LEAF | 2 | a leaf containing the value. |
NODE_EXT | 3 | a extension |
in3_codec_add_t¶
codec to organize the encoding of the nodes
typedef void(* in3_codec_add_t) (bytes_builder_t *bb, bytes_t *val)
in3_codec_finish_t¶
typedef void(* in3_codec_finish_t) (bytes_builder_t *bb, bytes_t *dst)
in3_codec_decode_index_t¶
typedef int(* in3_codec_decode_index_t) (bytes_t *src, int index, bytes_t *dst)
returns: int(*
trie_node_t¶
single node in the merkle trie.
The stuct contains following fields:
uint8_t |
hash | the hash of the node |
bytes_t | data | the raw data |
bytes_t | items | the data as list |
uint8_t |
own_memory | if true this is a embedded node with own memory |
trie_node_type_t | type | type of the node |
trie_nodestruct , * | next | used as linked list |
trie_codec_t¶
the codec used to encode nodes.
The stuct contains following fields:
in3_codec_add_t | encode_add |
in3_codec_finish_t |
encode_finish |
in3_codec_decode_size_t |
decode_size |
in3_codec_decode_index_t |
decode_item |
trie_t¶
a merkle trie implementation.
This is a Patricia Merkle Tree.
The stuct contains following fields:
in3_hasher_t | hasher | hash-function. |
trie_codec_t * | codec | encoding of the nocds. |
uint8_t |
root | The root-hash. |
trie_node_t * | nodes | linked list of containes nodes |
Module verifier/eth1/evm¶
big.h¶
Ethereum Nanon verification.
Location: src/verifier/eth1/evm/big.h
big_is_zero¶
uint8_t big_is_zero(uint8_t *data, wlen_t l);
arguments:
uint8_t * |
data |
wlen_t | l |
returns: uint8_t
big_shift_left¶
void big_shift_left(uint8_t *a, wlen_t len, int bits);
arguments:
uint8_t * |
a |
wlen_t | len |
int |
bits |
big_shift_right¶
void big_shift_right(uint8_t *a, wlen_t len, int bits);
arguments:
uint8_t * |
a |
wlen_t | len |
int |
bits |
big_cmp¶
int big_cmp(const uint8_t *a, const wlen_t len_a, const uint8_t *b, const wlen_t len_b);
arguments:
const uint8_t * |
a |
wlen_tconst | len_a |
const uint8_t * |
b |
wlen_tconst | len_b |
returns: int
big_signed¶
int big_signed(uint8_t *val, wlen_t len, uint8_t *dst);
returns 0 if the value is positive or 1 if negavtive.
in this case the absolute value is copied to dst.
arguments:
uint8_t * |
val |
wlen_t | len |
uint8_t * |
dst |
returns: int
big_int¶
int32_t big_int(uint8_t *val, wlen_t len);
arguments:
uint8_t * |
val |
wlen_t | len |
returns: int32_t
big_add¶
int big_add(uint8_t *a, wlen_t len_a, uint8_t *b, wlen_t len_b, uint8_t *out, wlen_t max);
arguments:
uint8_t * |
a |
wlen_t | len_a |
uint8_t * |
b |
wlen_t | len_b |
uint8_t * |
out |
wlen_t | max |
returns: int
big_sub¶
int big_sub(uint8_t *a, wlen_t len_a, uint8_t *b, wlen_t len_b, uint8_t *out);
arguments:
uint8_t * |
a |
wlen_t | len_a |
uint8_t * |
b |
wlen_t | len_b |
uint8_t * |
out |
returns: int
big_mul¶
int big_mul(uint8_t *a, wlen_t la, uint8_t *b, wlen_t lb, uint8_t *res, wlen_t max);
arguments:
uint8_t * |
a |
wlen_t | la |
uint8_t * |
b |
wlen_t | lb |
uint8_t * |
res |
wlen_t | max |
returns: int
big_div¶
int big_div(uint8_t *a, wlen_t la, uint8_t *b, wlen_t lb, wlen_t sig, uint8_t *res);
arguments:
uint8_t * |
a |
wlen_t | la |
uint8_t * |
b |
wlen_t | lb |
wlen_t | sig |
uint8_t * |
res |
returns: int
big_mod¶
int big_mod(uint8_t *a, wlen_t la, uint8_t *b, wlen_t lb, wlen_t sig, uint8_t *res);
arguments:
uint8_t * |
a |
wlen_t | la |
uint8_t * |
b |
wlen_t | lb |
wlen_t | sig |
uint8_t * |
res |
returns: int
code.h¶
code cache.
Location: src/verifier/eth1/evm/code.h
in3_get_code¶
cache_entry_t* in3_get_code(in3_vctx_t *vc, uint8_t *address);
arguments:
in3_vctx_t * | vc |
uint8_t * |
address |
returns: cache_entry_t *
evm.h¶
main evm-file.
Location: src/verifier/eth1/evm/evm.h
gas_options¶
EVM_ERROR_BUFFER_TOO_SMALL¶
reading data from a position, which is not initialized
#define EVM_ERROR_BUFFER_TOO_SMALL -3
EVM_ERROR_ILLEGAL_MEMORY_ACCESS¶
the memory-offset does not exist
#define EVM_ERROR_ILLEGAL_MEMORY_ACCESS -4
EVM_ERROR_INVALID_JUMPDEST¶
the jump destination is not marked as valid destination
#define EVM_ERROR_INVALID_JUMPDEST -5
EVM_ERROR_UNSUPPORTED_CALL_OPCODE¶
error handling the call, usually because static-calls are not allowed to change state
#define EVM_ERROR_UNSUPPORTED_CALL_OPCODE -7
EVM_ERROR_BALANCE_TOO_LOW¶
not enough funds to transfer the requested value.
#define EVM_ERROR_BALANCE_TOO_LOW -11
EVM_PROP_FRONTIER¶
#define EVM_PROP_FRONTIER 1
EVM_PROP_EIP150¶
#define EVM_PROP_EIP150 2
EVM_PROP_EIP158¶
#define EVM_PROP_EIP158 4
EVM_PROP_CONSTANTINOPL¶
#define EVM_PROP_CONSTANTINOPL 16
EVM_PROP_NO_FINALIZE¶
#define EVM_PROP_NO_FINALIZE 32768
EVM_PROP_STATIC¶
#define EVM_PROP_STATIC 256
EVM_ENV_BALANCE¶
#define EVM_ENV_BALANCE 1
EVM_ENV_CODE_SIZE¶
#define EVM_ENV_CODE_SIZE 2
EVM_ENV_CODE_COPY¶
#define EVM_ENV_CODE_COPY 3
EVM_ENV_BLOCKHASH¶
#define EVM_ENV_BLOCKHASH 4
EVM_ENV_STORAGE¶
#define EVM_ENV_STORAGE 5
EVM_ENV_BLOCKHEADER¶
#define EVM_ENV_BLOCKHEADER 6
EVM_ENV_CODE_HASH¶
#define EVM_ENV_CODE_HASH 7
EVM_ENV_NONCE¶
#define EVM_ENV_NONCE 8
MATH_ADD¶
#define MATH_ADD 1
MATH_SUB¶
#define MATH_SUB 2
MATH_MUL¶
#define MATH_MUL 3
MATH_DIV¶
#define MATH_DIV 4
MATH_SDIV¶
#define MATH_SDIV 5
MATH_MOD¶
#define MATH_MOD 6
MATH_SMOD¶
#define MATH_SMOD 7
MATH_EXP¶
#define MATH_EXP 8
MATH_SIGNEXP¶
#define MATH_SIGNEXP 9
CALL_CALL¶
#define CALL_CALL 0
CALL_CODE¶
#define CALL_CODE 1
CALL_DELEGATE¶
#define CALL_DELEGATE 2
CALL_STATIC¶
#define CALL_STATIC 3
OP_AND¶
#define OP_AND 0
OP_OR¶
#define OP_OR 1
OP_XOR¶
#define OP_XOR 2
EVM_DEBUG_BLOCK (…)¶
OP_LOG (…)¶
#define OP_LOG (...) EVM_ERROR_UNSUPPORTED_CALL_OPCODE
OP_SLOAD_GAS (…)¶
OP_CREATE (…)¶
#define OP_CREATE (...) EVM_ERROR_UNSUPPORTED_CALL_OPCODE
OP_ACCOUNT_GAS (…)¶
#define OP_ACCOUNT_GAS (...) 0
OP_SELFDESTRUCT (…)¶
#define OP_SELFDESTRUCT (...) EVM_ERROR_UNSUPPORTED_CALL_OPCODE
OP_EXTCODECOPY_GAS (evm)¶
OP_SSTORE (…)¶
#define OP_SSTORE (...) EVM_ERROR_UNSUPPORTED_CALL_OPCODE
EVM_CALL_MODE_STATIC¶
#define EVM_CALL_MODE_STATIC 1
EVM_CALL_MODE_DELEGATE¶
#define EVM_CALL_MODE_DELEGATE 2
EVM_CALL_MODE_CALLCODE¶
#define EVM_CALL_MODE_CALLCODE 3
EVM_CALL_MODE_CALL¶
#define EVM_CALL_MODE_CALL 4
evm_state¶
the current state of the evm
The enum type contains the following values:
EVM_STATE_INIT | 0 | just initialised, but not yet started |
EVM_STATE_RUNNING | 1 | started and still running |
EVM_STATE_STOPPED | 2 | successfully stopped |
EVM_STATE_REVERTED | 3 | stopped, but results must be reverted |
evm_get_env¶
This function provides data from the enviroment.
depending on the key the function will set the out_data-pointer to the result. This means the enviroment is responsible for memory management and also to clean up resources afterwards.
typedef int(* evm_get_env) (void *evm, uint16_t evm_key, uint8_t *in_data, int in_len, uint8_t **out_data, int offset, int len)
returns: int(*
storage_t¶
The stuct contains following fields:
bytes32_t | key |
bytes32_t | value |
account_storagestruct , * | next |
account_t¶
The stuct contains following fields:
address_t | address |
bytes32_t | balance |
bytes32_t | nonce |
bytes_t | code |
storage_t * | storage |
accountstruct , * | next |
evm_t¶
The stuct contains following fields:
bytes_builder_t | stack | |
bytes_builder_t | memory | |
int |
stack_size | |
bytes_t | code | |
uint32_t |
pos | |
evm_state_t | state | |
bytes_t | last_returned | |
bytes_t | return_data | |
uint32_t * |
invalid_jumpdest | |
uint32_t |
properties | |
evm_get_env | env | |
void * |
env_ptr | |
uint8_t * |
address | the address of the current storage |
uint8_t * |
account | the address of the code |
uint8_t * |
origin | the address of original sender of the root-transaction |
uint8_t * |
caller | the address of the parent sender |
bytes_t | call_value | value send |
bytes_t | call_data | data send in the tx |
bytes_t | gas_price | current gasprice |
uint64_t |
gas | |
gas_options |
evm_stack_push¶
int evm_stack_push(evm_t *evm, uint8_t *data, uint8_t len);
arguments:
evm_t * | evm |
uint8_t * |
data |
uint8_t |
len |
returns: int
evm_stack_push_ref¶
int evm_stack_push_ref(evm_t *evm, uint8_t **dst, uint8_t len);
arguments:
evm_t * | evm |
uint8_t ** |
dst |
uint8_t |
len |
returns: int
evm_stack_push_int¶
int evm_stack_push_int(evm_t *evm, uint32_t val);
arguments:
evm_t * | evm |
uint32_t |
val |
returns: int
evm_stack_push_long¶
int evm_stack_push_long(evm_t *evm, uint64_t val);
arguments:
evm_t * | evm |
uint64_t |
val |
returns: int
evm_stack_get_ref¶
int evm_stack_get_ref(evm_t *evm, uint8_t pos, uint8_t **dst);
arguments:
evm_t * | evm |
uint8_t |
pos |
uint8_t ** |
dst |
returns: int
evm_stack_pop¶
int evm_stack_pop(evm_t *evm, uint8_t *dst, uint8_t len);
arguments:
evm_t * | evm |
uint8_t * |
dst |
uint8_t |
len |
returns: int
evm_stack_pop_ref¶
int evm_stack_pop_ref(evm_t *evm, uint8_t **dst);
arguments:
evm_t * | evm |
uint8_t ** |
dst |
returns: int
evm_stack_pop_byte¶
int evm_stack_pop_byte(evm_t *evm, uint8_t *dst);
arguments:
evm_t * | evm |
uint8_t * |
dst |
returns: int
evm_run¶
int evm_run(evm_t *evm, address_t code_address);
arguments:
evm_t * | evm |
address_t | code_address |
returns: int
evm_sub_call¶
int evm_sub_call(evm_t *parent, uint8_t address[20], uint8_t account[20], uint8_t *value, wlen_t l_value, uint8_t *data, uint32_t l_data, uint8_t caller[20], uint8_t origin[20], uint64_t gas, wlen_t mode, uint32_t out_offset, uint32_t out_len);
handle internal calls.
arguments:
evm_t * | parent |
uint8_t |
address |
uint8_t |
account |
uint8_t * |
value |
wlen_t | l_value |
uint8_t * |
data |
uint32_t |
l_data |
uint8_t |
caller |
uint8_t |
origin |
uint64_t |
gas |
wlen_t | mode |
uint32_t |
out_offset |
uint32_t |
out_len |
returns: int
evm_ensure_memory¶
int evm_ensure_memory(evm_t *evm, uint32_t max_pos);
arguments:
evm_t * | evm |
uint32_t |
max_pos |
returns: int
in3_get_env¶
int in3_get_env(void *evm_ptr, uint16_t evm_key, uint8_t *in_data, int in_len, uint8_t **out_data, int offset, int len);
arguments:
void * |
evm_ptr |
uint16_t |
evm_key |
uint8_t * |
in_data |
int |
in_len |
uint8_t ** |
out_data |
int |
offset |
int |
len |
returns: int
evm_call¶
int evm_call(void *vc, uint8_t address[20], uint8_t *value, wlen_t l_value, uint8_t *data, uint32_t l_data, uint8_t caller[20], uint64_t gas, bytes_t **result);
run a evm-call
arguments:
void * |
vc |
uint8_t |
address |
uint8_t * |
value |
wlen_t | l_value |
uint8_t * |
data |
uint32_t |
l_data |
uint8_t |
caller |
uint64_t |
gas |
bytes_t ** | result |
returns: int
evm_print_stack¶
void evm_print_stack(evm_t *evm, uint64_t last_gas, uint32_t pos);
arguments:
evm_t * | evm |
uint64_t |
last_gas |
uint32_t |
pos |
evm_run_precompiled¶
int evm_run_precompiled(evm_t *evm, uint8_t address[20]);
arguments:
evm_t * | evm |
uint8_t |
address |
returns: int
evm_is_precompiled¶
uint8_t evm_is_precompiled(evm_t *evm, uint8_t address[20]);
arguments:
evm_t * | evm |
uint8_t |
address |
returns: uint8_t
gas.h¶
evm gas defines.
Location: src/verifier/eth1/evm/gas.h
op_exec (m,gas)¶
#define op_exec (m,gas) return m;
subgas (g)¶
GAS_CC_NET_SSTORE_NOOP_GAS¶
Once per SSTORE operation if the value doesn’t change.
#define GAS_CC_NET_SSTORE_NOOP_GAS 200
GAS_CC_NET_SSTORE_INIT_GAS¶
Once per SSTORE operation from clean zero.
#define GAS_CC_NET_SSTORE_INIT_GAS 20000
GAS_CC_NET_SSTORE_CLEAN_GAS¶
Once per SSTORE operation from clean non-zero.
#define GAS_CC_NET_SSTORE_CLEAN_GAS 5000
GAS_CC_NET_SSTORE_DIRTY_GAS¶
Once per SSTORE operation from dirty.
#define GAS_CC_NET_SSTORE_DIRTY_GAS 200
GAS_CC_NET_SSTORE_CLEAR_REFUND¶
Once per SSTORE operation for clearing an originally existing storage slot.
#define GAS_CC_NET_SSTORE_CLEAR_REFUND 15000
GAS_CC_NET_SSTORE_RESET_REFUND¶
Once per SSTORE operation for resetting to the original non-zero value.
#define GAS_CC_NET_SSTORE_RESET_REFUND 4800
GAS_CC_NET_SSTORE_RESET_CLEAR_REFUND¶
Once per SSTORE operation for resetting to the original zero valuev.
#define GAS_CC_NET_SSTORE_RESET_CLEAR_REFUND 19800
G_VERY_LOW¶
This is the amount of gas to pay for operations of the set Wverylow.
#define G_VERY_LOW 3
G_EXTCODE¶
This is the amount of gas to pay for operations of the set Wextcode.
#define G_EXTCODE 700
G_SSET¶
This is paid for an SSTORE operation when the storage value is set to non-zero from zero.
#define G_SSET 20000
G_SRESET¶
This is the amount for an SSTORE operation when the storage value’s zeroness remains unchanged or is set to zero.
#define G_SRESET 5000
R_SCLEAR¶
This is the refund given (added into the refund counter) when the storage value is set to zero from non-zero.
#define R_SCLEAR 15000
R_SELFDESTRUCT¶
This is the refund given (added into the refund counter) for self-destructing an account.
#define R_SELFDESTRUCT 24000
G_SELFDESTRUCT¶
This is the amount of gas to pay for a SELFDESTRUCT operation.
#define G_SELFDESTRUCT 5000
G_CODEDEPOSIT¶
This is paid per byte for a CREATE operation to succeed in placing code into the state.
#define G_CODEDEPOSIT 200
G_CALLVALUE¶
This is paid for a non-zero value transfer as part of the CALL operation.
#define G_CALLVALUE 9000
G_CALLSTIPEND¶
This is a stipend for the called contract subtracted from Gcallvalue for a non-zero value transfer.
#define G_CALLSTIPEND 2300
G_NEWACCOUNT¶
This is paid for a CALL or for a SELFDESTRUCT operation which creates an account.
#define G_NEWACCOUNT 25000
G_EXPBYTE¶
This is a partial payment when multiplied by dlog256(exponent)e for the EXP operation.
#define G_EXPBYTE 50
G_TXCREATE¶
This is paid by all contract-creating transactions after the Homestead transition.
#define G_TXCREATE 32000
G_TXDATA_ZERO¶
This is paid for every zero byte of data or code for a transaction.
#define G_TXDATA_ZERO 4
G_TXDATA_NONZERO¶
This is paid for every non-zero byte of data or code for a transaction.
#define G_TXDATA_NONZERO 68
G_SHA3WORD¶
This is paid for each word (rounded up) for input data to a SHA3 operation.
#define G_SHA3WORD 6
G_COPY¶
This is a partial payment for *COPY operations, multiplied by the number of words copied, rounded up.
#define G_COPY 3
G_PRE_MODEXP_GQUAD_DIVISOR¶
Gquaddivisor from modexp precompile for gas calculation.
#define G_PRE_MODEXP_GQUAD_DIVISOR 20
G_PRE_ECPAIRING_WORD¶
Gas costs regarding curve pairing precompile input length.
#define G_PRE_ECPAIRING_WORD 80000
FRONTIER_G_EXPBYTE¶
fork values
This is a partial payment when multiplied by dlog256(exponent)e for the EXP operation.
#define FRONTIER_G_EXPBYTE 10
FRONTIER_G_SLOAD¶
This is a partial payment when multiplied by dlog256(exponent)e for the EXP operation.
#define FRONTIER_G_SLOAD 50
FREE_EVM (…)¶
INIT_EVM (…)¶
INIT_GAS (…)¶
SUBGAS (…)¶
FINALIZE_SUBCALL_GAS (…)¶
UPDATE_SUBCALL_GAS (…)¶
FINALIZE_AND_REFUND_GAS (…)¶
KEEP_TRACK_GAS (evm)¶
#define KEEP_TRACK_GAS (evm) 0
SELFDESTRUCT_GAS (evm,g)¶
#define SELFDESTRUCT_GAS (evm,g) EVM_ERROR_UNSUPPORTED_CALL_OPCODE
UPDATE_ACCOUNT_CODE (…)¶
Module verifier/eth1/full¶
eth_full.h¶
Ethereum Nanon verification.
Location: src/verifier/eth1/full/eth_full.h
in3_verify_eth_full¶
int in3_verify_eth_full(in3_vctx_t *v);
entry-function to execute the verification context.
arguments:
in3_vctx_t * | v |
returns: int
in3_register_eth_full¶
void in3_register_eth_full();
this function should only be called once and will register the eth-full verifier.
Module verifier/eth1/nano¶
chainspec.h¶
Ethereum chain specification.
Location: src/verifier/eth1/nano/chainspec.h
BLOCK_LATEST¶
#define BLOCK_LATEST 0xFFFFFFFFFFFFFFFF
eth_consensus_type_t¶
the consensus type.
The enum type contains the following values:
ETH_POW | 0 | Pro of Work (Ethash) |
ETH_POA_AURA | 1 | Proof of Authority using Aura. |
ETH_POA_CLIQUE | 2 | Proof of Authority using clique. |
consensus_transition_t¶
The stuct contains following fields:
uint64_t |
transition_block |
eth_consensus_type_t | type |
bytes_t | validators |
uint8_t * |
contract |
chainspec_t¶
The stuct contains following fields:
uint64_t |
network_id |
uint64_t |
account_start_nonce |
uint32_t |
eip_transitions_len |
eip_transition_t * | eip_transitions |
uint32_t |
consensus_transitions_len |
consensus_transition_t * | consensus_transitions |
attribute¶
struct __attribute__((__packed__)) eip_;
defines the flags for the current activated EIPs.
Since it does not make sense to support a evm defined before Homestead, homestead EIP is always turned on!
< REVERT instruction
< Bitwise shifting instructions in EVM
< Gas cost changes for IO-heavy operations
< Simple replay attack protection
< EXP cost increase
< Contract code size limit
< Precompiled contracts for addition and scalar multiplication on the elliptic curve alt_bn128
< Precompiled contracts for optimal ate pairing check on the elliptic curve alt_bn128
< Big integer modular exponentiation
< New opcodes: RETURNDATASIZE and RETURNDATACOPY
< New opcode STATICCALL
< Embedding transaction status code in receipts
< Skinny CREATE2
< EXTCODEHASH opcode
< Net gas metering for SSTORE without dirty maps
arguments:
(__packed__)
¶
returns: struct
chainspec_create_from_json¶
chainspec_t* chainspec_create_from_json(d_token_t *data);
arguments:
d_token_t * | data |
returns: chainspec_t *
chainspec_get_eip¶
eip_t chainspec_get_eip(chainspec_t *spec, uint64_t block_number);
arguments:
chainspec_t * | spec |
uint64_t |
block_number |
returns: eip_t
chainspec_get_consensus¶
consensus_transition_t* chainspec_get_consensus(chainspec_t *spec, uint64_t block_number);
arguments:
chainspec_t * | spec |
uint64_t |
block_number |
returns: consensus_transition_t *
chainspec_to_bin¶
in3_ret_t chainspec_to_bin(chainspec_t *spec, bytes_builder_t *bb);
arguments:
chainspec_t * | spec |
bytes_builder_t * | bb |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
chainspec_from_bin¶
chainspec_t* chainspec_from_bin(void *raw);
arguments:
void * |
raw |
returns: chainspec_t *
chainspec_get¶
chainspec_t* chainspec_get(uint64_t chain_id);
arguments:
uint64_t |
chain_id |
returns: chainspec_t *
chainspec_put¶
void chainspec_put(uint64_t chain_id, chainspec_t *spec);
arguments:
uint64_t |
chain_id |
chainspec_t * | spec |
eth_nano.h¶
Ethereum Nanon verification.
Location: src/verifier/eth1/nano/eth_nano.h
in3_verify_eth_nano¶
in3_ret_t in3_verify_eth_nano(in3_vctx_t *v);
entry-function to execute the verification context.
arguments:
in3_vctx_t * | v |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
eth_verify_blockheader¶
in3_ret_t eth_verify_blockheader(in3_vctx_t *vc, bytes_t *header, bytes_t *expected_blockhash);
verifies a blockheader.
verifies a blockheader.
arguments:
in3_vctx_t * | vc |
bytes_t * | header |
bytes_t * | expected_blockhash |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
eth_verify_signature¶
int eth_verify_signature(in3_vctx_t *vc, bytes_t *msg_hash, d_token_t *sig);
verifies a single signature blockheader.
This function will return a positive integer with a bitmask holding the bit set according to the address that signed it. This is based on the signatiures in the request-config.
arguments:
in3_vctx_t * | vc |
bytes_t * | msg_hash |
d_token_t * | sig |
returns: int
ecrecover_signature¶
bytes_t* ecrecover_signature(bytes_t *msg_hash, d_token_t *sig);
returns the address of the signature if the msg_hash is correct
arguments:
bytes_t * | msg_hash |
d_token_t * | sig |
returns: bytes_t *
eth_verify_eth_getTransactionReceipt¶
in3_ret_t eth_verify_eth_getTransactionReceipt(in3_vctx_t *vc, bytes_t *tx_hash);
verifies a transaction receipt.
arguments:
in3_vctx_t * | vc |
bytes_t * | tx_hash |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
eth_verify_in3_nodelist¶
in3_ret_t eth_verify_in3_nodelist(in3_vctx_t *vc, uint32_t node_limit, bytes_t *seed, d_token_t *required_addresses);
verifies the nodelist.
arguments:
in3_vctx_t * | vc |
uint32_t |
node_limit |
bytes_t * | seed |
d_token_t * | required_addresses |
returns: in3_ret_t
the result-status of the function.
Please make sure you check if it was successfull (==IN3_OK
)
in3_register_eth_nano¶
void in3_register_eth_nano();
this function should only be called once and will register the eth-nano verifier.
merkle.h¶
Merkle Proof Verification.
Location: src/verifier/eth1/nano/merkle.h
MERKLE_DEPTH_MAX¶
#define MERKLE_DEPTH_MAX 64
trie_verify_proof¶
int trie_verify_proof(bytes_t *rootHash, bytes_t *path, bytes_t **proof, bytes_t *expectedValue);
verifies a merkle proof.
expectedValue == NULL : value must not exist expectedValue.data ==NULL : please copy the data I want to evaluate it afterwards. expectedValue.data !=NULL : the value must match the data.
arguments:
bytes_t * | rootHash |
bytes_t * | path |
bytes_t ** | proof |
bytes_t * | expectedValue |
returns: int
trie_path_to_nibbles¶
uint8_t* trie_path_to_nibbles(bytes_t path, int use_prefix);
helper function split a path into 4-bit nibbles.
The result must be freed after use!
arguments:
bytes_t | path |
int |
use_prefix |
returns: uint8_t *
: the resulting bytes represent a 4bit-number each and are terminated with a 0xFF.
trie_matching_nibbles¶
int trie_matching_nibbles(uint8_t *a, uint8_t *b);
helper function to find the number of nibbles matching both paths.
arguments:
uint8_t * |
a |
uint8_t * |
b |
returns: int
trie_free_proof¶
void trie_free_proof(bytes_t **proof);
used to free the NULL-terminated proof-array.
arguments:
bytes_t ** | proof |
rlp.h¶
RLP-En/Decoding as described in the Ethereum RLP-Spec.
This decoding works without allocating new memory.
Location: src/verifier/eth1/nano/rlp.h
rlp_decode¶
int rlp_decode(bytes_t *b, int index, bytes_t *dst);
this function decodes the given bytes and returns the element with the given index by updating the reference of dst.
the bytes will only hold references and do not need to be freed!
bytes_t* tx_raw = serialize_tx(tx);
bytes_t item;
// decodes the tx_raw by letting the item point to range of the first element, which should be the body of a list.
if (rlp_decode(tx_raw, 0, &item) !=2) return -1 ;
// now decode the 4th element (which is the value) and let item point to that range.
if (rlp_decode(&item, 4, &item) !=1) return -1 ;
arguments:
bytes_t * | b |
int |
index |
bytes_t * | dst |
returns: int
: - 0 : means item out of range
- 1 : item found
- 2 : list found ( you can then decode the same bytes again)
rlp_decode_in_list¶
int rlp_decode_in_list(bytes_t *b, int index, bytes_t *dst);
this function expects a list item (like the blockheader as first item and will then find the item within this list).
It is a shortcut for
// decode the list
if (rlp_decode(b,0,dst)!=2) return 0;
// and the decode the item
return rlp_decode(dst,index,dst);
arguments:
bytes_t * | b |
int |
index |
bytes_t * | dst |
returns: int
: - 0 : means item out of range
- 1 : item found
- 2 : list found ( you can then decode the same bytes again)
rlp_decode_len¶
int rlp_decode_len(bytes_t *b);
returns the number of elements found in the data.
arguments:
bytes_t * | b |
returns: int
rlp_decode_item_len¶
int rlp_decode_item_len(bytes_t *b, int index);
returns the number of bytes of the element specified by index.
arguments:
bytes_t * | b |
int |
index |
returns: int
: the number of bytes or 0 if not found.
rlp_decode_item_type¶
int rlp_decode_item_type(bytes_t *b, int index);
returns the type of the element specified by index.
arguments:
bytes_t * | b |
int |
index |
returns: int
: - 0 : means item out of range
- 1 : item found
- 2 : list found ( you can then decode the same bytes again)
rlp_encode_item¶
void rlp_encode_item(bytes_builder_t *bb, bytes_t *val);
encode a item as single string and add it to the bytes_builder.
arguments:
bytes_builder_t * | bb |
bytes_t * | val |
rlp_encode_list¶
void rlp_encode_list(bytes_builder_t *bb, bytes_t *val);
encode a the value as list of already encoded items.
arguments:
bytes_builder_t * | bb |
bytes_t * | val |
rlp_encode_to_list¶
bytes_builder_t* rlp_encode_to_list(bytes_builder_t *bb);
converts the data in the builder to a list.
This function is optimized to not increase the memory more than needed and is fastet than creating a second builder to encode the data.
arguments:
bytes_builder_t * | bb |
returns: bytes_builder_t *
: the same builder.
rlp_encode_to_item¶
bytes_builder_t* rlp_encode_to_item(bytes_builder_t *bb);
converts the data in the builder to a rlp-encoded item.
This function is optimized to not increase the memory more than needed and is fastet than creating a second builder to encode the data.
arguments:
bytes_builder_t * | bb |
returns: bytes_builder_t *
: the same builder.
rlp_add_length¶
void rlp_add_length(bytes_builder_t *bb, uint32_t len, uint8_t offset);
helper to encode the prefix for a value
arguments:
bytes_builder_t * | bb |
uint32_t |
len |
uint8_t |
offset |
serialize.h¶
serialization of ETH-Objects.
This incoming tokens will represent their values as properties based on JSON-RPC.
Location: src/verifier/eth1/nano/serialize.h
BLOCKHEADER_PARENT_HASH¶
#define BLOCKHEADER_PARENT_HASH 0
BLOCKHEADER_SHA3_UNCLES¶
#define BLOCKHEADER_SHA3_UNCLES 1
BLOCKHEADER_MINER¶
#define BLOCKHEADER_MINER 2
BLOCKHEADER_STATE_ROOT¶
#define BLOCKHEADER_STATE_ROOT 3
BLOCKHEADER_TRANSACTIONS_ROOT¶
#define BLOCKHEADER_TRANSACTIONS_ROOT 4
BLOCKHEADER_RECEIPT_ROOT¶
#define BLOCKHEADER_RECEIPT_ROOT 5
BLOCKHEADER_LOGS_BLOOM¶
#define BLOCKHEADER_LOGS_BLOOM 6
BLOCKHEADER_DIFFICULTY¶
#define BLOCKHEADER_DIFFICULTY 7
BLOCKHEADER_NUMBER¶
#define BLOCKHEADER_NUMBER 8
BLOCKHEADER_GAS_LIMIT¶
#define BLOCKHEADER_GAS_LIMIT 9
BLOCKHEADER_GAS_USED¶
#define BLOCKHEADER_GAS_USED 10
BLOCKHEADER_TIMESTAMP¶
#define BLOCKHEADER_TIMESTAMP 11
BLOCKHEADER_EXTRA_DATA¶
#define BLOCKHEADER_EXTRA_DATA 12
BLOCKHEADER_SEALED_FIELD1¶
#define BLOCKHEADER_SEALED_FIELD1 13
BLOCKHEADER_SEALED_FIELD2¶
#define BLOCKHEADER_SEALED_FIELD2 14
BLOCKHEADER_SEALED_FIELD3¶
#define BLOCKHEADER_SEALED_FIELD3 15
serialize_tx_receipt¶
bytes_t* serialize_tx_receipt(d_token_t *receipt);
creates rlp-encoded raw bytes for a receipt.
The bytes must be freed with b_free after use!
arguments:
d_token_t * | receipt |
returns: bytes_t *
serialize_tx¶
bytes_t* serialize_tx(d_token_t *tx);
creates rlp-encoded raw bytes for a transaction.
The bytes must be freed with b_free after use!
arguments:
d_token_t * | tx |
returns: bytes_t *
serialize_tx_raw¶
bytes_t* serialize_tx_raw(bytes_t nonce, bytes_t gas_price, bytes_t gas_limit, bytes_t to, bytes_t value, bytes_t data, uint64_t v, bytes_t r, bytes_t s);
creates rlp-encoded raw bytes for a transaction from direct values.
The bytes must be freed with b_free after use!
arguments:
bytes_t | nonce |
bytes_t | gas_price |
bytes_t | gas_limit |
bytes_t | to |
bytes_t | value |
bytes_t | data |
uint64_t |
v |
bytes_t | r |
bytes_t | s |
returns: bytes_t *
serialize_account¶
bytes_t* serialize_account(d_token_t *a);
creates rlp-encoded raw bytes for a account.
The bytes must be freed with b_free after use!
arguments:
d_token_t * | a |
returns: bytes_t *
serialize_block_header¶
bytes_t* serialize_block_header(d_token_t *block);
creates rlp-encoded raw bytes for a blockheader.
The bytes must be freed with b_free after use!
arguments:
d_token_t * | block |
returns: bytes_t *
rlp_add¶
int rlp_add(bytes_builder_t *rlp, d_token_t *t, int ml);
adds the value represented by the token rlp-encoded to the byte_builder.
arguments:
bytes_builder_t * | rlp |
d_token_t * | t |
int |
ml |
returns: int
: 0 if added -1 if the value could not be handled.