GithubHelp home page GithubHelp logo

franccan / iotex-antenna-embedded Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 1.0 357 KB

SDK of IoTeX blockchain for embedded devices

Home Page: https://docs.iotex.io/

Makefile 1.56% Shell 0.39% C 96.76% Python 0.25% C++ 1.04%

iotex-antenna-embedded's Introduction

iotex-antenna-embedded

iotex-antenna-embedded is our C/C++ SDK allowing you to interact with a local or remote iotex block chain node, using https connection.

Build

// Linux/macOS
cd iotex-antenna-embedded && make 

// cross compile
cd iotex-antenna-embedded && make CROSS_COMPILE=xxxxxx

// run unittest
make unittest

// build example
make example

// archiving libs docs and example
make release

Third Party Modules

Configure

For Linux Distributions or mac OS , you may do not need any configure, just call iotex_emb_init(NULL), then using the API interact with a iotex block chain node.

For embedded Linux device, you may need configure the cert file or directory, to tell library where to find the SSL Certificate. Configure cert by passing a iotex_emb_config structure to iotex_emb_init.

typedef struct iotex_st_config {
    uint32_t ver;		// pharos API version, default 1
    long verify_cert;		// set 1 verify the pharos SSL certificate
    long verify_host;		// set 2 verify the certificate's name against host
    const char *cert_dir;	// SSL certificate directory, set NULL will auto search
    const char *cert_file;	// SSL certificate file, set NULL will auto search
} iotex_st_config;

Notice

For easy use iotex_emb_init wouldn't copy iotex_st_config.cert_dir\cert_file content, so it must pointer to an static char string such as static variable or Macro. For Linux Distributions or mac OS, you may set NULL let software auto search certificate and directory.

Interfaces

All of iotex-antenna-embedded API, return zero means success, failed will return a negative error code, error code's meaning you can reference iotex_em_error.

For some system do not support __uint128_t, define Macro _NO_128INT_ (make no_int128 ), it will use 40 bytes raw string instead. Also u128 module provides a series of functions to uniform process 128 bit numbers.

All exports data structure and API start with iotex prefix

  • api: iotex_emb_
  • struct: iotex_st_
  • enum: iotex_em_

Example

#include <stdio.h>
#include "u128.h"
#include "iotex_emb.h"

int main(int argc, char **argv) {

    int ret;
    iotex_st_config config = {0};
    iotex_st_account_meta account;
    char u128_str[UINT128_RAW_MAX_LEN];
    const char *account_address = (argc >= 2) ? argv[1] : "io1e2nqsyt7fkpzs5x7zf2uk0jj72teu5n6aku3tr";

    /* Configure cert file */
    config.cert_file = "cacert.pem";

    if ((ret = iotex_emb_init(&config)) != 0) {

        fprintf(stderr, "Initialize iotex emb failed, error code: %d\n", ret);
        return -1;
    }

    /* Get account metadata */
    if ((ret = iotex_emb_get_account_meta(account_address, &account)) != 0) {

        fprintf(stderr, "Get account metadata failed, error code: %d\n", ret);
        return -1;
    }

    fprintf(stdout, "Account: %s, balance: %s\n", account.address, u1282str(account.balance, u128_str, sizeof(u128_str)));

    /* Not required */
    iotex_emb_exit();
    return 0;
}

Run example

// make
cd example && make

// set running env
source ../scripts/env.sh

// run
../objs/account_meta
../objs/transfer

iotex-antenna-embedded's People

Contributors

amaork avatar dustinxie avatar raullenchai avatar

Forkers

savrixx

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.