Code Monkey home page Code Monkey logo

cs-api's Introduction

C# API

Bitcoin full node as a C# library

Latest Release Build Status License Telegram Slack

Knuth C# API is a high performance implementation of the Bitcoin protocol focused on users requiring extra performance and flexibility. It is a Bitcoin node you can use as a library.

Prerequisites

Knuth C# API is a wrapper over our C++ libraries, therefore in order to use the C# library we will need the toolchain to build the C++ libraries. Don't panic, you won't have to manually build our C++ libraries, you just have to provide some prerequisites, our build system will take care of the rest.

To speed up the compilation, we provide some pre-built C++ libraries for some common computer platforms, but case there are no pre-built binaries for your platform, our build system will automatically try to build from source code. In such a scenario, the following requirements must be added to the previous ones:

Getting started

  1. Create a new C# console project:
$ mkdir HelloKnuth
$ cd HelloKnuth
$ dotnet new console
  1. Add a reference to our C# API package:
$ dotnet add package kth-bch
  1. Edit Program.cs and write some code:
using System;
using System.Threading.Tasks;
using Knuth;

namespace HelloKnuth {
    public class Program {
        private static bool running_;

        static async Task Main(string[] args) {
            Console.CancelKeyPress += OnSigInterrupt;

            var config = Knuth.Config.Settings.GetDefault(NetworkType.Mainnet);
            using (var node = new Knuth.Node(config)) {
                await node.LaunchAsync();
                Console.WriteLine("Knuth node has been launched.");

                var height = await node.Chain.GetLastHeightAsync();
                Console.WriteLine($"Current height in local copy: {height.Result}");

                if (await ComeBackAfterTheBCHHardFork(node)) {
                    Console.WriteLine("Bitcoin Cash has been created!");
                }
            }
            Console.WriteLine("Good bye!");
        }

        private static async Task<bool> ComeBackAfterTheBCHHardFork(Node node) {
            UInt64 hfHeight = 478559;
            while (running_) {
                var res = await node.Chain.GetLastHeightAsync();
                if (res.Result >= hfHeight) return true;
                await Task.Delay(10000);
            }
            return false;
        }

        private static void OnSigInterrupt(object sender, ConsoleCancelEventArgs args) {
            Console.WriteLine("Stop signal detected.");
            args.Cancel = true;
            running_ = false;
        }
    }
}

  1. Enjoy Knuth node as a C# library:
$ dotnet run

Repository under construction, the first version will be released shortly.

cs-api's People

Contributors

bitprim-ci avatar dario-ramos avatar deswurstes avatar fpelliccioni avatar hanchon avatar mdallago avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.