Git Product home page Git Product logo

ark-net's Introduction

ARK.Net

Waffle.io - Columns and their card count GitHub forks GitHub stars GitHub license

Why Ark.NET

Ark.NET is the ARK Ecosystem library for the .NET platform. It implements all most relevant ARK functionalities to help you develop efficient .NET applications built upon ARK platform. It provides also low level access to ARK so you can easily build your application on top of it.

The package supports:

  • With full features, Windows Desktop applications, Mono Desktop applications, and platform supported at .NET Standard Library. Works on all .NET solutions with framework >= 4.7.1 & Net Standard 2.0.
  • Async/Await with corresponding synchronous methods.

Source Browser

How to install?

With nuget:

nuget

Install-Package ark.net Go on the nuget website for more information.

From source:

To compile it by yourself, you can git clone, open the project and hit the compile button on visual studio. In command prompt:

git clone https://github.com/ArkEcosystem/ark-net
cd ark-net

How to get started?

All ark-node service responses have object representations. You can use service classes under service folder. Responses are IEnumerable for a list or an object for a single item. Every method has a corresponding async method.

It's best to let the code do the speaking. For more examples look at the ARK.NET Tests, where all tests are written and you can see the api usage. Some code snippets are below.

Ark.Net Client init

First call needs to be start, so all settings within the library can initialize before going into action. Multiple instances of ArkNetApi can be used at the same time (DevNet & MainNet in the same application)

private ArkNetApi _arkNetApi;
public ArkNetApi ArkNetApi
{
    get { return _arkNetApi ?? (_arkNetApi = new ArkNetApi()); }
}
await ArkNetApi.Start(NetworkType.MainNet); //Other type is DevNet
//or
await ArkNetApi.Start(specificPeerIp, specificPeerPort);
//or (Multiple addresses)
await ArkNetApi.Start(listArkPeerAddresses);

Account/Wallet layer

//Existing account
var accCtnrl = new AccountController(ArkNetApi, "top secret pass");

//Send ARK
var result = accCtnrl.SendArk(100, "AUgTuukcKeE4XFdzaK6rEHMD5FLmVBSmHk", "Akr.Net test trans from Account");

//Vote 4 Delegate                
var result = accCtnrl.VoteForDelegate(delegateName);

//Un-Vote Delegate                
var result = accCtnrl.UnVoteDelegate(delegateName);

//Create and send transaction.  Transaction can be saved offine (.ToJson()) and sent later.              
var transaction = accCtnrl.CreateTransaction(100, "AUgTuukcKeE4XFdzaK6rEHMD5FLmVBSmHk", "Akr.Net test trans from Account");
var result = accCtnrl.SendTransaction(transaction);

//Get Account
var account = accCtnrl.GetArkAccount();

//New Account
new AccountController(ArkNetApi, ArkNetApi.AccountService.GeneratePassphrase());

Service layer

For a full list of available api calls please look at the ARK.NET Test project

//PeerService
var peers = ArkNetApi.PeerService.GetAll();
var peersOK = peers.Where(x => x.Status.Equals("OK"));

//TransactionService
var trans = ArkNetApi.TransactionService.GetAll();

//BlockService
var blocks = ArkNetApi.BlockService.GetAll();

//AccountService - Generate passphrase
var result = ArkNetApi.AccountService.GeneratePassphrase();

//DelegateService
var delegates = ArkNetApi.DelegateService.GetAll();

//LoaderService
var autoConfigParams = ArkNetApi.LoaderService.GetAutoConfigureParameters();
...

Core Layer

Layer is used for core Ark blockchain communication (transaction, crypto...). It is wrapped by api libraries that are called from the service and Account layer.

//Create & send transaction
TransactionApi tx = ArkNetApi.TransactionApi.CreateTransaction(recepient, amount, description, passphrase);
Peer peer = ArkNetApi.NetworkApi.GetRandomPeer();
var result = peer.PostTransaction(tx);

//Connect to a specific peer to perform requests
var peerApi = new PeerApi(ArkNetApi.NetworkApi, ipAddress, Port)
await peerApi.MakeRequest(ArkStaticStrings.ArkHttpMethods.GET, ArkStaticStrings.ArkApiPaths.Loader.GET_STATUS);

//Force specific peer.  All API calls will flow through this peer.  Set back to null to resume decentralized use.  Monitoring a specific peer is a use case for this functionality.
ArkNetApi.NetworkApi.ForcedPeer = ArkNetApi.PeerService.GetPeer(ip, port);
//or
ArkNetApi.NetworkApi.ForcedPeer = new PeerApi(ArkNetApi.NetworkApi, ipAddress, Port);

// Switch network (Can also create new ArkNetApi instance as alternative solution)
await ArkNetApi.SwitchNetwork(NetworkType.DevNet)

//New network
_arkNetApiDevNet = new ArkNetApi();
await _arkNetApiDevNet.Start(NetworkType.DevNet);      

Logging

Any logging framework can be used to capture the logs from within ArkNet. It is up to the user of the library to implement IArkLogger and pass it to ArkNetApi.Start(). Below is an example implementation using Log4Net.

public class Log4netAdapter : IArkLogger
{
    private readonly ILog _log4NetLog;

    public Log4netAdapter(ILog log4NetLog)
    {
        _log4NetLog = log4NetLog;
    }

    public void Log(ArkLogEntry entry)
    {
        if (entry.LogLevel == ArkLogLevel.Debug)
            _log4NetLog.Debug(entry.Message, entry.Exception);
        else if (entry.LogLevel == ArkLogLevel.Info)
            _log4NetLog.Info(entry.Message, entry.Exception);
        else if (entry.LogLevel == ArkLogLevel.Warn)
            _log4NetLog.Warn(entry.Message, entry.Exception);
        else if (entry.LogLevel == ArkLogLevel.Error)
            _log4NetLog.Error(entry.Message, entry.Exception);
        else
            _log4NetLog.Fatal(entry.Message, entry.Exception);
    }
}

ILog log = LogManager.GetLogger(typeof(LoggingTests));
await ArkNetApi.Start(NetworkType.MainNet, new Log4netAdapter(log);

More information about ARK Ecosystem and etc

Please, use github issues for questions or feedback. For confidential requests or specific demands, contact us on our public channels.

Useful link for a free IDE :

Visual Studio Community Edition : https://www.visualstudio.com/products/visual-studio-community-vs

Authors

Chris ([email protected]) & Sharkdev-j, with a lot of help from FX Thoorens [email protected] and ARK Community

Support this project

alt text Ark address:AUgTuukcKeE4XFdzaK6rEHMD5FLmVBSmHk

License

License: MIT

Copyright (c) 2018 ARK

ark-net's People

Contributors

abalalojik avatar boldninja avatar dnovacik avatar fix avatar kristjank avatar sharkdev-a avatar travisdmathis avatar trigger67 avatar ukyuu avatar waffle-iron avatar

Watchers

 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.