Coder Social home page Coder Social logo

ark-cpp's Introduction

THIS LIBRARY IS DEPRECATED AND IS NO LONGER MAINTAINED

This Repo is archived for historical reference

You can find the current Ark Cpp SDK's at the following links:
https://github.com/ArkEcosystem/cpp-client
https://github.com/ArkEcosystem/cpp-crypto

Ark for Machines v0.8

language version License: MIT
environment
environment
environment
environment

Build Status

Build status

Not production ready.

Supported Boards

What can this do?

GET information from the Ark Blockchain using Arduino boards.
Create models of basic Ark "types." (e.g. Accounts, Blocks, Delegates, Peers, etc)

What CAN'T this do (yet)?

Generate Ark Addresses & Signatures.
Create Signed transaction for broadcast to the Ark Ecosystem.

How to use this

  1. Define the network

ARK::Network devnet = ARK::Constants::Networks::Devnet::model;

or

ARK::Network devnet {
"578e820911f24e039733b45e4882b73e301f813a0d2c31330dafda84534ffa23",
"DARK",
"DѦ",
"https://dexplorer.ark.io/",
30
};

  1. Create the manager instance

ARK::API::Manager arkManager(devnet)

  1. Use manager to get info from the Ark Blockchain

auto status = arkManager.loaderStatus() Serial.print(status) prints {
"success":true,
"loaded":false,
"now":2348744,
"blocksCount":0
}

Examples

Get VendorField of a given Transaction ID using the ESP8266

/*
* demo_sketch.ino
*/

#include <ESP8266WiFi.h>

const char* ssid = "yourSSID";
const char* password = "yourWiFiPassword";

void testVendorField()
{
  Network devnet = Constants::Networks::Model::Devnet;
  ARK::API::Manager arkManager(devnet);

  Hash txID = "4e68a917d06382ce335656eef5560a537fc806ecadf3972c5221b86babecc63e";

  auto vendorField = arkManager.getVendorField(txID);
    Serial.print("\nvendorField: ");
    Serial.println(vendorField);
}

void setup()
{
  Serial.begin(115200);
  reportFreeHeap();
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println();

  testVendorField();
}

void loop(){}

vendorField: 1ARK-GOLang is saying whoop whooop

Get Ark Account from a given Ark Address

  Address darkAddress("DHQ4Fjsyiop3qBR4otAjAu6cBHkgRELqGA");
  auto account = arkManager.account(darkAddress);
    Serial.print("\naccount: ");
    Serial.println(account);

account:
address: DHQ4Fjsyiop3qBR4otAjAu6cBHkgRELqGA
unconfirmedBalance: 106914.85341862
balance: 106914.85341862
publicKey: 0275776018638e5c40f1b922901e96cac2caa734585ef302b4a2801ee9a338a456
unconfirmedSignature: 1
secondSignature: 1
secondPublicKey: 03ad2a481719c80571061f0c941d57e91c928700d8dd132726edfc0bf9c4cb2869
multisignatures:
u_multisignatures:

todo

  • API

    • add models & constants
    • add static endpoints
    • Network manager
    • Network Client
    • API Gets
    • API Posts
      • test api posts
      • finish api posts
    • Error Handling
      • test error handling
      • finish error handling
  • Crypto

    • Test Crypto
      • test sha256
      • test bigint
      • test secp256k1 ECDSA
      • test ripemd160
      • test base58
      • test Address generation
      • test Signing/Signature Generation
    • Add Crypto
      • add sha256
      • add bigint
      • add secp256k1 ECDSA
      • add ripemd160
      • add base58
      • add Address generation
      • add Signing/Signature Generation
  • TODO

    • Documentation
    • Handle Large Callbacks

ark-cpp's People

Contributors

ciband avatar per1234 avatar sleepdefic1t avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ark-cpp's Issues

improve on Hash Type

Improve on the concept of a Hash type in the Ark-Cpp wrapper

The aim of this issue is to open the discussion of storing hash-types as bytes with optional retrieval as a hex-string.

objectives:

  • improve the storage size of hashable types
  • improve handling of hashable types
  • improve ability to model new hash-types
  • introduce a clean way to check for hash-type conformance

POC Implementation available in

https://github.com/sleepdefic1t/Ark-Cpp/tree/improvements_preview/src/types

Tested implementation uses Hashable as a temple such that hashes, keys, and signatures may be defined via

#define HASH_STORAGE_BYTE_COUNT 32
#define Hash Hashable<HASH_STORAGE_BYTE_COUNT>
#define PUBKEY_STORAGE_BYTE_COUNT 33
#define Publickey Hashable<PUBKEY_STORAGE_BYTE_COUNT>
#define PRIVKEY_STORAGE_BYTE_COUNT 32
#define Privatekey Hashable<PRIVKEY_STORAGE_BYTE_COUNT>
#define SIGNATURE_BYTE_COUNT 71
#define Signature Hashable<SIGNATURE_BYTE_COUNT>

Sample class implementation

template <size_t COUNT>
class Hashable :
	public Printable
{
  public:
	/************************************************** 
	* Constructor 
	* @brief: default empty constructor
	**************************************************/
	Hashable() : bytes_() {};
	/*************************************************/

	/************************************************** 
	* Constructor 
	* @param: const char *const newHash
	* @brief: also checks if Hash is empty before storage
	**************************************************/
	Hashable(const char *const newHash)
	{ 
		strlen(newHash) != 0 ?
			this->set(newHash) :
			void(this->bytes_[0] = '\0');
	};
	/*************************************************/

	/************************************************** 
	* Deconstructor 
	* @brief: fill this->bytes_ with random data before deconstruction
	**************************************************/
	~Hashable() {
		Sanitize(this->bytes_, COUNT);
	};
	/*************************************************/

	/************************************************** 
	* @brief: returns element count of Hashable object
	**************************************************/
	size_t count() const { return COUNT; };
	/*************************************************/

	/************************************************** 
	* @brief: returns size of Hashable object
	**************************************************/
	size_t size() const { return sizeof(this->bytes_); };
	/*************************************************/

	/************************************************** 
	* @brief: returns vector of stored bytes
	**************************************************/
	const inline std::vector<uint8_t> vBytes() const
	{
		return std::vector<uint8_t>(this->bytes_);
	};
	/*************************************************/

	/************************************************** 
	* @brief: returns vector of hex-string representation of stored bytes
	**************************************************/
	const inline std::vector<char> vHex() const
	{
		return (this->bytes_[0] != '\0') ?
				std::vector<char>(this->hex().c_str()) :
				std::vector<char>(1);
	};
	/*************************************************/

	/************************************************** 
	* @brief: returns hex-string representation of stored bytes
	**************************************************/
	std::string hex() const
	{
		if (this->bytes_[0] != '\0')
		{
			char hexBuffer[(COUNT * 2) + 1];
			BytesToHex(this->bytes_, hexBuffer, COUNT);
			return std::string( hexBuffer );
		}
		else
		{
			return std::string("");
		};
	}
	/*************************************************/

	/************************************************** 
	* @brief: returns hex c-string ('\0' or NULL Terminated string) representation of stored bytes
	**************************************************/
	operator const char *() const
	{
		return this->hex().c_str();
	};
	/*************************************************/

	/**************************************************
	* @param: Print& p 
	* @brief: prints Hashable object
	**************************************************/
	virtual size_t printTo(Print& p) const
	{
		size_t size = 0;
		size += p.print( this->hex().c_str() );
		return size;
	};
	/*************************************************/

  protected:
	uint8_t bytes_[COUNT];

	/**************************************************
	* @param: const char *const newHash 
	* @brief: Sets new Hash, copying byte-values to internal storage
	**************************************************/
	void set(const char *const newHash)
	{
		if (isHex(newHash))
		{ 
			HexToBytes(newHash, this->bytes_);
		}
		else
		{ 
			std::memmove(this->bytes_, newHash, COUNT);
		};
	};
	/*************************************************/

};

note: Sanitize method introduced to randomize byte data before deconstruction.
This will necessarily have to use proven T/RNG functions in the crypto libraries,
but is currently implemented as follows:

static uint8_t getRandomDigit()
{	
#ifdef USE_IOT
	randomSeed(random(0, 1024));
	return random(0, 255);
#else
	std::default_random_engine generator;
	std::uniform_int_distribution<uint32_t> distribution(0, 255);
	return distribution(generator);
#endif
}

static void Sanitize(uint8_t* buffer, size_t size)
{
	for (unsigned int i = 0; i < size; i++)
	{
		buffer[i] = getRandomDigit();
	};
};

Update Travis CI to have dedicated PlatformIO builds.

Currently every configuration (Linux-GCC, Linux-Clang, OSX 10.12, OSX 10.13) builds platformIO.

This needs to be changed to the following configurations:

  • Linux-GCC
  • Linux-Clang
  • Linux-PlatformIO
  • OSX-10.12
    *OSX-10.13
    *OSX-PlatformIO (10.12 since that is Travis CI's stable image)

improve API file structure

Improve the file structure of API files in the Ark-Cpp wrapper

The aim of this issue is to open the discussion of how to reduce the complexity and count of the API files

objectives:

  • reduce complexity and overhead
  • improve readability
  • improve overall size of the Ark-Cpp wrapper

POC Implementation available in

https://github.com/sleepdefic1t/Ark-Cpp/tree/improvements_preview/src/api

The *_gettable classes have now been streamlined to the point where is appears ready for merging into the *able class prototypes/protocols.

This will leave each API "type" (Account, Block, etc) with only its implementation and applicable API Callback Models (*_respondable).

Also proposed for discussion is an improved naming convention for *_respondable's to better convey that they are indeed callback models.
ex account_model.h

Sample header/declaration implementation



#ifndef ACCOUNTABLE_H
#define ACCOUNTABLE_H

#include "utilities/platform.h"
#include "api/accountable/account_respondable.h"
#include "models/account.h"
#include "models/delegate.h"
#include "types/address.h"
#include "types/balance.h"
#include "types/crypto/eckey.h"
#include "utilities/connector.h"
#include "api/paths.h"
#include "utilities/json.h"

namespace ARK
{
namespace API
{
/*************************************************
*	PUBLIC: ARK::API::Accountable
*	public API::Account::Gettable
*	virtual ARK::Utilities::Network::Connectable
*    
*	API's Account Model
**************************************************/
class Accountable :
	virtual ARK::Utilities::Network::Connectable
{
    public:
	/*************************************************
	*	/api/accounts/getBalance?address=arkAddress
	*
	*	@param:	Address arkAddress
	*	@return:	ARK::API::Account::Respondable::Balances
	*
	*	@brief:	Uses Ark Address to get an Accounts Confirmed	and Unconfirmed Balances from a Node via API.
	**************************************************/
	ARK::API::Account::Respondable::Balances accountBalance(const Address &arkAddress);
	/*************************************************/

	/**************************************************************************************************/

	/*************************************************
	*	api/accounts/getPublickey?address=arkAddress
	*
	*	@param:	Address arkAddress
	*	@return:	Publickey
	*
	*	@brief:	Uses Ark Address to get an Accounts Publickey from a Node via API.
	**************************************************/
	Publickey accountPublickey(const Address &arkAddress);
	/*************************************************/

	/**************************************************************************************************/

	/*************************************************
	*	/api/accounts/delegates/fee?address=arkAddress
	*
	*	@param:	Address arkAddress
	*	@return:	Balance
	*
	*	@brief:	Uses Ark Address to get Delegate Registration Fee from a Node via API.
	**************************************************/
	Balance accountDelegatesFee(const Address &arkAddress);
	/*************************************************/

	/**************************************************************************************************/

	/*************************************************
	*	/api/accounts/delegates?address=arkAddress
	*
	*	@param:	Address arkAddress
	*	@return:	ARK::Delegate
	*
	*	@brief:	Uses Ark Address to get Delegate Object from a Node via API.
	**************************************************/
	ARK::Delegate accountDelegates(const Address &arkAddress);
	/*************************************************/

	/**************************************************************************************************/

	/*************************************************
	*	/api/accounts?address=arkAddress
	*
	*	@param:	Address arkAddress
	*	@return:	ARK::Account
	*
	*	@brief:	Uses Ark Address to get Account Object from a Node via API.
	**************************************************/
	ARK::Account account(const Address &arkAddress);
	/*************************************************/

};
/*************************************************/

};
};

Sample cpp/definition implementation



#include "api/accountable/accountable.h"


/*************************************************
*	/api/accounts/getBalance?address=arkAddress
*
*	EXAMPLE:
*	{
*		"success":true,
*		"balance":  "Balance",
*		"unconfirmedBalance": "Balance"
*	}
**************************************************/
ARK::API::Account::Respondable::Balances ARK::API::Accountable::accountBalance(
		const Address &arkAddress
)
{
	char uri[68 + 1] = { '\0' };
		strcpy(uri, ARK::API::Paths::Account::getBalance_s);
		strcat(uri, "?address=");
		strcat(uri, arkAddress.getValue());
	auto callback = netConnector.callback(uri);
	auto parser = ARK::Utilities::make_json_string(callback);
	return {
		parser->valueFor("balance").c_str(),
		parser->valueFor("unconfirmedBalance").c_str()
	};
};
/*************************************************/

/**************************************************************************************************/

/*************************************************
*	api/accounts/getPublickey?address=arkAddress
*
*	EXAMPLE:
*	{
*		"success":true,
*		"publicKey":  "Publickey"
*	}
**************************************************/
Publickey ARK::API::Accountable::accountPublickey(
		const Address &arkAddress
)
{
	char uri[94 + 1] = { '\0' };
		strcpy(uri, ARK::API::Paths::Account::getPublickey_s);
		strcat(uri, "?address=");
		strcat(uri, arkAddress.getValue());
	auto callback = netConnector.callback(uri);
	auto parser = ARK::Utilities::make_json_string(callback);
	return {
		parser->valueFor("publicKey").c_str()
	};
};
/*************************************************/

/**************************************************************************************************/

/*************************************************
*	/api/accounts/delegates/fee?address=arkAddress
*
*	EXAMPLE:
*	{
*		"success":true,
*		"fee":2500000000
*	}
**************************************************/
Balance ARK::API::Accountable::accountDelegatesFee(
		const Address &arkAddress
)
{
	char uri[95 + 1] = { '\0' };
		strcpy(uri, ARK::API::Paths::Account::delegatesFee_s);
		strcat(uri, "?address=");
		strcat(uri, arkAddress.getValue());
	auto callback = netConnector.callback(uri);
	auto parser = ARK::Utilities::make_json_string(callback);
	return Balance(parser->valueFor("fee").c_str());
};
/*************************************************/

/**************************************************************************************************/

/*************************************************
*	/api/accounts/delegates?address=arkAddress
*
*	EXAMPLE:
*	{
*		"success":true,
*		"delegates":
*		[
*			{
*				"username": "sleepdeficit",
*				"address":  "Address",
*				"publicKey":  "Publickey",
*				"vote": "Balance",
*				"producedblocks": const char*,
*				"missedblocks": String,
*				"rate": int,
*				"approval": double,
*				"productivity": double
*			}
*		]
*	}
**************************************************/
ARK::Delegate ARK::API::Accountable::accountDelegates(
		const Address &arkAddress
)
{
	char uri[91 + 1] = { '\0' };
		strcpy(uri, ARK::API::Paths::Account::delegates_s);
		strcat(uri, "?address=");
		strcat(uri, arkAddress.getValue());
	auto callback = netConnector.callback(uri);
	auto parser = ARK::Utilities::make_json_string(callback);
	return {
		parser->subarrayValueIn("delegates", 0, "username").c_str(),
		parser->subarrayValueIn("delegates", 0, "address").c_str(),
		parser->subarrayValueIn("delegates", 0, "publicKey").c_str(),
		parser->subarrayValueIn("delegates", 0, "vote").c_str(),
		convert_to_int(parser->subarrayValueIn("delegates", 0, "producedblocks").c_str()),
		convert_to_int(parser->subarrayValueIn("delegates", 0, "missedblocks").c_str()),
		convert_to_int(parser->subarrayValueIn("delegates", 0, "rate").c_str()),
		convert_to_float(parser->subarrayValueIn("delegates", 0, "approval").c_str()),
		convert_to_float(parser->subarrayValueIn("delegates", 0, "productivity").c_str())
	};
};
/*************************************************/

/**************************************************************************************************/

/*************************************************
*	/api/accounts?address=arkAddress
*
*	EXAMPLE:
*	{
*		"success":true,
*		"account":
*		{
*			"address":  "Address",
*			"unconfirmedBalance": "Balance",
*			"balance":  "Balance",
*			"publicKey":  "Publickey",
*			"unconfirmedSignature": int,
*			"secondSignature":  int,
*			"secondPublicKey":  "Publickey",
*			"multisignatures":[],
*			"u_multisignatures":[]
*		}
*	}
**************************************************/
ARK::Account ARK::API::Accountable::account(
		const Address &arkAddress
)
{
	char uri[81 + 1] = { '\0' };
		strcpy(uri, ARK::API::Paths::Account::accounts_s);
		strcat(uri, "?address=");
		strcat(uri, arkAddress.getValue());
	auto callback = netConnector.callback(uri);
	auto parser = ARK::Utilities::make_json_string(callback);
		/********************
		*	FIXME 
		* multisignatures & u_multisignatures returns an array of Transaction ID's (Hash type)
		********************/
	return {
		parser->valueIn("account", "address").c_str(),
		parser->valueIn("account", "unconfirmedBalance").c_str(),
		parser->valueIn("account", "balance").c_str(),
		parser->valueIn("account", "publicKey").c_str(),
		convert_to_int(parser->valueIn("account", "unconfirmedSignature").c_str()),
		convert_to_int(parser->valueIn("account", "secondSignature").c_str()),
		parser->valueIn("account", "secondPublicKey").c_str(),
		// parser->subarrayValueIn("account", 0, "multisignatures").c_str(),	//	FIXME
		// multisigsArray,																										//	FIXME
		// parser->subarrayValueIn("account", 0, "u_multisignatures").c_str()	//	FIXME
		// u_multisigsArray																										//	FIXME
	};
};
/*************************************************/

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.