- c++17
- cmake
- boost multiprecision installed includes (>=1.66, exclude 1.68!)
- Wasm compiler: emscripten
- cmake-js to build node.js addons
$ git clone https://github.com/mile-core/mile-csa-api
$ cd ./mile-csa-api; mkdir build; cd ./build
$ cmake ..; make -j4
$ make test
$ cmake -Dwasm=True ..; make -j4; cd platforms/wasm
$ cp ../../../platforms/wasm/milecsa_wasm_test.html ./
$ emrun --serve_root ./ --browser chrome milecsa_wasm_test.html
or in case of using Node.js install http-server
once
$ npm install http-server -g
and then
$ cmake -Dwasm=True ..; make -j4; cd platforms/wasm
$ cp ../../../platforms/wasm/milecsa_wasm_test.html ./index.html
$ http-server -o
Install cmake-js if it needs:
$ npm install -g cmake-js
Build addon milecsa with boost module on Ubuntu18.04:
$ cd platforms/nodejs
$ npm install
$ cmake-js rebuild
$ npm test
Build addon milecsa mudule on mac os:
$ mkdir -p build; cd build;
$ cmake -Dnodejs=True ..; make nodejs;
$ make nodejs-test
$ sudo apt install curl
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
$ sudo apt install nodejs
$ node --version
- MILE CSA JavaScript API
- emrun --serve_root ./ --browser chrome your_app.html
$ wget https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.tar.gz
$ tar -xzf boost_1_*
$ cd boost_1_*
$ ./bootstrap.sh --prefix=/usr
$ ./b2 install --prefix=/usr --with=all -j4
- Centos7 (gcc v7.0)
- Ubuntu 18.4
- OSX 10.13, XCode10
#include "milecsa_light_api.hpp"
// available tokens:
milecsa::token stable = milecsa::assets::XDR;
milecsa::token index = milecsa::assets::MILE;
// Properties
std::cout << "Name: " << stable.name;
std::cout << "Code: " << stable.code;
std::cout << "Precision: " << stable.precision;
// Fixed point conversion to string presentation
std::string amount = asset.value_to_string(100.1f);
#include "milecsa.hpp"
// to create a wallet pair you only use one of the follow methodes
//
// milecsa::keys::Pair::Random
// milecsa::keys::Pair::FromPrivateKey
// milecsa::keys::Pair::WithSecret
auto pair = milecsa::keys::Pair::Random(...);
//
//
// getters
//
milecsa::keys::Key public_key = pair.get_public_key();
milecsa::keys::Key private_key = pair.get_private_key();
std::cout << " Public key as base58 encoded string : " << public_key.encode() << std::endl;
std::cout << " Private key as base58 encoded string: " << private_key.encode() << std::endl;
#include "milecsa.hpp"
if (auto pair =
milecsa::keys::Pair::Random([errorMessage, &result](
milecsa::result code,
std::string error) mutable -> void {
//
// Handle error. For example, the block can contain async error processing.
//
}))
{
//
// Handle wallet pair.
//
std::cout << " Public key: " << pair->get_public_key().encode() << std::endl;
std::cout << " Private key: " << pair->get_private_key().encode() << std::endl;
}
#include "milecsa.hpp"
std::strint pk = "TENDFTskF7RbYgLBLX6zusCVJMRGhU2aANktKXZfHAcXUJTAVisci8jAG79x8V2toc2ivpTahkDBvZGUeAnyewM8VfrFz";
if (auto pair =
milecsa::keys::Pair::FromPrivateKey(pk, [errorMessage, &result](
milecsa::result code,
std::string error) mutable -> void {
result = code;
errorMessage = error;
}))
{
//
// Handle error.
//
}
else {
//
// Handle wallet pair.
//
std::cout << " Public key: " << pair->get_public_key().encode() << std::endl;
std::cout << " Private key: " << pair->get_private_key().encode() << std::endl;
}
#include "milecsa.hpp"
std::string secret = "the most secret phrase";
if (auto pair =
milecsa::keys::Pair::WithSecret(secret, [errorMessage, &result](
milecsa::result code,
std::string error) mutable -> void {
//
// Handle error. For example, the block can contain async error processing.
//
}))
{
//
// Handle wallet pair.
//
std::cout << " Public key: " << pair->get_public_key().encode() << std::endl;
std::cout << " Private key: " << pair->get_private_key().encode() << std::endl;
}
#include "milecsa.hpp"
std::strint pk = "TENDFTskF7RbYgLBLX6zusCVJMRGhU2aANktKXZfHAcXUJTAVisci8jAG79x8V2toc2ivpTahkDBvZGUeAnyewM8VfrFz";
if (milecsa::keys::Pair::ValidatePrivateKey(pk, [errorMessage, &result](
milecsa::result code,
std::string error) mutable -> void {
//
// Handling invalid private key
//
})) {
//
// Handling valid key
//
}
#include "milecsa.hpp"
std::strint pk = "7PNJQMVBwUccsQsmGh93KQYget74UXyoHUDpUbARLuUw6F53o";
if (milecsa::keys::Pair::ValidatePublicKey(pk, [errorMessage, &result](
milecsa::result code,
std::string error) mutable -> void {
//
// Handling invalid private key
//
})) {
//
// Handling valid key
//
}
#include "milecsa.hpp"
#include "json.hpp"
using json = nlohmann::json ;
using transfer = milecsa::transaction::Transfer<json>;
uint256_t last_block_id = get_current_block_id();
srand(time(0));
if (auto trx_body = transfer::CreateRequest(
keyPair,
destination,
last_block_id, // block id
rand(), // trx id
milecsa::assets::XDR, // asset
10.0f)->get_body()){
auto json_body = trx_body->dump();
}
else {
//
// Handle error
//
}
#include "milecsa.hpp"
#include "json.hpp"
using json = nlohmann::json ;
milecsa::result result;
//
// Error handler
//
auto error = [&](milecsa::result code, const std::string &error) mutable -> void {
//
// Handle the error catch
//
};
std::string transaction;
std::string fee;
std::string digest;
std::string signature;
float amount = 100.1f
float fee = 0.0f // always == 0.0
if (auto transfer = milecsa::transaction::Transfer<json>::CreateRequest(
keyPair,
dstWalletPublicKey,
blockId,
transactionId,
milecsa::assets::XDR,
amount,
fee,
description,
error)) {
//
// getting json string
//
if (auto trx = transfer->get_body()) transaction = trx->dump();
// transaction digest
if (auto dgst = transfer->get_digest()) digest = *dgst;
// transaction sigature
if (auto sig = transfer->get_signature()) signature = *sig;
//
// Send json-rpc request to node...
//
}