Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Bitcoin full node as a C Programming Language library

NotificationsYou must be signed in to change notification settings

k-nuth/c-api

Repository files navigation

C APIGithub ReleasesBuild statusCTelegramSlack

Bitcoin full node as a C Programming Language library

Knuth is a high performance implementation of the Bitcoin protocol focused on users requiring extra performance and flexibility, what makes it the best platform for wallets, exchanges, block explorers and miners.

Getting started

Install and run Knuth is very easy:

  1. Install and configure the Knuth build helper:
$ pip install kthbuild --user --upgrade$ conan config install https://github.com/k-nuth/ci-utils/raw/master/conan/config2023.zip
  1. Install the appropriate library:
$ conan install --requires=c-api/0.61.0 --update

"Hello, Knuth!":

// hello_knuth.c#include<inttypes.h>#include<stdint.h>#include<stdio.h>#include<kth/capi.h>intmain() {kth_node_tnode=kth_node_construct("my_config_file",stdout,stderr);kth_node_initchain(node);kth_node_run_wait(node);kth_chain_tchain=kth_node_get_chain(node);uint64_theight;chain_get_last_height(chain,&height);printf("%"PRIu64"\n",height);kth_node_destruct(node);}

Explanation:

#include<inttypes.h>#include<stdint.h>#include<stdio.h>

Includes C standard library stuff, like format conversion specifiers, fixed width integer types (uint64_t) and input/output features. (stdout,stderr andprintf()).

#include<kth/capi.h>

Gives access to Knuth C-API features.

kth_node_tnode=kth_node_construct("my_config_file",stdout,stderr);

Construct a Knuthnode object, which is necessary to run the node, interact with the blockchain, with the P2P peers and other components of the API.

"my_config_file" is the path to the configuration file; in theconfig repository you can find some example files.If you pass an empty string (""), default configuration will be used.

stdout andstderr are pointers to the standard output and standard error streams. These are used to tell the Knuth node where to print the logs.You can use any object of typeFILE*. For example, you can make the Knuth node redirect the logs to a file.If you pass null pointers (NULL or0), there will be no logging information.

kth_node_initchain(node);

Initialize the filesystem database where theblockchain will be stored.You need to have enough disk space to store the blockchain.

This is equivalent to executing:kth -i -c my_config_file.

kth_node_run_wait(node);

Run the node.In this step, the connections and handshake with the peers will be established, and the initial process of downloading blocks will start. Once this stage has finished, the node will begin to receive transactions and blocks through the P2P network.

This is equivalent to executing:kth -c my_config_file.

kth_chain_tchain=kth_node_get_chain(node);

Get access to the blockchain query interface (commands and queries).

uint64_theight;chain_get_last_height(chain,&height);printf("%"PRIu64"\n",height);

Ask the blockchain what is the height of the last downloaded block and print it in the standard output.

kth_node_destruct(node);

Destroy the node object created earlier.(We are in land ofThe C Programming Language, there is no automatic handling of resources here, you have to do it manually.)

Build and run:

Note: Here we are building the code using the GNU Compiler Collection (GCC) on Linux. You can use other compilers and operating systems as well. If you have any questions, you cancontact us here.

To build and run the code example, first you have to create a tool file calledconanfile.txt in orded to manage the dependencies of the code:

$printf"[requires]\nc-api/0.61.0\n[options]\nc-api:shared=True\n[imports]\ninclude/kth, *.h -> ./include/kth\ninclude/kth, *.hpp -> ./include/kth\nlib, *.so -> ./lib\n"> conanfile.txt

Then, run the following command to bring the dependencies to the local directory:

$ conan install.

Now, you can build our code example:

$ gcc -Iinclude -c hello_knuth.c$ gcc -Llib -o hello_knuth hello_knuth.o -lkth-c-api

...run it and enjoy the Knuth programmable APIs:

$ ./hello_knuth

For more more detailed instructions, please refer to ourdocumentation.

Issues

Each of our modules has its own Github repository, but in case you want to create an issue, please do so in ourmain repository.

About

Bitcoin full node as a C Programming Language library

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp