Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented client for the hardware wallet daemon REST API #33

Open
wants to merge 13 commits into
base: v0.25dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*.exe
*.o
*.so

deps_curl/
sb

lib/skyhwd/build
build
data
pkg
Expand Down Expand Up @@ -162,4 +162,4 @@ seeds.csv
histogram
# Ignore compilator by qemu
qemu_*
core
core
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test && sudo apt-get update -qq; fi
- ./ci-scripts/install-travis-gcc.sh
- eval "CC=gcc-6 && CXX=g++-6"
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" && mkdir ${DEPS_DIR} && cd ${DEPS_DIR} && travis_retry wget --no-check-certificate https://cmake.org/files/v3.3/cmake-3.3.2-Linux-x86_64.tar.gz && echo "f3546812c11ce7f5d64dc132a566b749 *cmake-3.3.2-Linux-x86_64.tar.gz" > cmake_md5.txt && md5sum -c cmake_md5.txt && tar -xvf cmake-3.3.2-Linux-x86_64.tar.gz > /dev/null && mv cmake-3.3.2-Linux-x86_64 cmake-install && PATH=${DEPS_DIR}/cmake-install:${DEPS_DIR}/cmake-install/bin:$PATH && cd ${TRAVIS_BUILD_DIR} ; fi

env:
global:
Expand All @@ -136,12 +137,12 @@ env:


install:
# Install gox
- if [[ -z "$QEMU_PLATFORM" ]]; then go get github.com/gz-c/gox; fi
- if [[ -z "$QEMU_PLATFORM" ]]; then go get github.com/gz-c/gox ; fi
- if [[ -z "$QEMU_PLATFORM" ]]; then go get -t ./... ; fi
- if [[ -z "$QEMU_PLATFORM" ]]; then make install-linters ; fi
- if [[ -z "$QEMU_PLATFORM" ]]; then VERSION=1.10.2 ./ci-scripts/install-golangci-lint.sh ; fi
- if [[ -z "$QEMU_PLATFORM" ]]; then make install-deps-libc ; fi
- if [[ -z "$QEMU_PLATFORM" ]]; then make install-lib-skyhwd ; fi

script:
- echo $PWD
Expand Down
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,32 @@ install-deps-Linux: ## Install deps on GNU/Linux
install-deps-Darwin: ## Install deps on Mac OSX
brew install $(PKG_LIB_TEST)

install-libraries-deps: ## Install deps on GNU/Linux
rm -rf deps
mkdir deps
if [[ "$(UNAME_S)" == "Linux" ]]; then (cd deps && wget --no-check-certificate https://cmake.org/files/v3.3/cmake-3.3.2-Linux-x86_64.tar.gz && echo "f3546812c11ce7f5d64dc132a566b749 *cmake-3.3.2-Linux-x86_64.tar.gz" > cmake_md5.txt && md5sum -c cmake_md5.txt && tar -xvf cmake-3.3.2-Linux-x86_64.tar.gz > /dev/null && mv cmake-3.3.2-Linux-x86_64 cmake-install && PATH=$(pwd)/deps/cmake-install:$(pwd)/deps/cmake-install/bin:$PATH ) && (cd deps && sudo apt remove curl && wget http://curl.haxx.se/download/curl-7.58.0.tar.gz && tar -xvf curl-7.58.0.tar.gz && cd curl-7.58.0/ && bash ./configure && make && sudo make install) ; fi
if [[ "$(UNAME_S)" == "Linux" ]]; then brew install curl ; fi
# install uncrustify
git clone https://github.com/uncrustify/uncrustify.git
(cd uncrustify && mkdir build && cd build && cmake .. && make && sudo make install)

install-linters: install-linters-$(UNAME_S) ## Install linters
go get -u github.com/FiloSottile/vendorcheck
# For some reason this install method is not recommended, see https://github.com/golangci/golangci-lint#install
# However, they suggest `curl ... | bash` which we should not do
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
VERSION=1.10.2 ./ci-scripts/install-golangci-lint.sh

install-deps-libc: install-deps-libc-$(OSNAME)
install-deps-libc: install-deps-libc-$(OSNAME) install-libraries-deps

install-deps-libc-linux: configure-build ## Install locally dependencies for testing libskycoin
wget -c https://github.com/libcheck/check/releases/download/0.12.0/check-0.12.0.tar.gz
tar -xzf check-0.12.0.tar.gz
cd check-0.12.0 && ./configure --prefix=/usr --disable-static && make && sudo make install

install-lib-skyhwd: ## Install Sky Hardware wallet deamon rest wrapper
(cd lib/skyhwd && mkdir build && cd build && cmake .. && make && sudo make install)

install-deps-libc-osx: configure-build ## Install locally dependencies for testing libskycoin
brew install check

Expand Down
23 changes: 23 additions & 0 deletions lib/skyhwd/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
1 change: 1 addition & 0 deletions lib/skyhwd/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0.0-SNAPSHOT
120 changes: 120 additions & 0 deletions lib/skyhwd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
cmake_minimum_required (VERSION 2.6)
project (CGenerator)

cmake_policy(SET CMP0063 NEW)

set(CMAKE_C_VISIBILITY_PRESET default)
set(CMAKE_CXX_VISIBILITY_PRESET default)
set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF)
set(CMAKE_BUILD_TYPE Debug)

set(pkgName "hardware_wallet_daemon_api")

find_package(CURL 7.58.0 REQUIRED)
if(CURL_FOUND)
include_directories(${CURL_INCLUDE_DIR})
set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${CURL_LIBRARIES} )
else(CURL_FOUND)
message(FATAL_ERROR "Could not find the CURL library and development files.")
endif()

set(SRCS
src/list.c
src/apiKey.c
src/apiClient.c
external/cJSON.c
model/apply_settings_request.c
model/check_message_signature_request.c
model/csrf_response.c
model/features_response.c
model/features_response_data.c
model/generate_addresses_request.c
model/generate_addresses_response.c
model/generate_mnemonic_request.c
model/http_error_response.c
model/http_error_response_error.c
model/http_success_response.c
model/inline_response_200.c
model/passphrase_request.c
model/pin_matrix_request.c
model/recovery_request.c
model/set_mnemonic_request.c
model/sign_message_request.c
model/sign_message_response.c
model/transaction_input.c
model/transaction_output.c
model/transaction_sign_request.c
model/transaction_sign_response.c
model/word_request.c
api/DefaultAPI.c

)

set(HDRS
include/apiClient.h
include/list.h
include/keyValuePair.h
external/cJSON.h
model/apply_settings_request.h
model/check_message_signature_request.h
model/csrf_response.h
model/features_response.h
model/features_response_data.h
model/generate_addresses_request.h
model/generate_addresses_response.h
model/generate_mnemonic_request.h
model/http_error_response.h
model/http_error_response_error.h
model/http_success_response.h
model/inline_response_200.h
model/passphrase_request.h
model/pin_matrix_request.h
model/recovery_request.h
model/set_mnemonic_request.h
model/sign_message_request.h
model/sign_message_response.h
model/transaction_input.h
model/transaction_output.h
model/transaction_sign_request.h
model/transaction_sign_response.h
model/word_request.h
api/DefaultAPI.h

)

# Add library with project file with projectname as library name
add_library(${pkgName} SHARED ${SRCS} ${HDRS})
# Link dependent libraries
target_link_libraries(${pkgName} ${CURL_LIBRARIES} )
#install library to destination
install(TARGETS ${pkgName} DESTINATION ${CMAKE_INSTALL_PREFIX})

# Setting file variables to null
set(SRCS "")
set(HDRS "")


## This section shows how to use the above compiled libary to compile the source files
## set source files
#set(SRCS
# unit-tests/manual-PetAPI.c
# unit-tests/manual-StoreAPI.c
# unit-tests/manual-UserAPI.c
# unit-tests/manual-order.c
# unit-tests/manual-user.c)

##set header files
#set(HDRS
#)

## loop over all files in SRCS variable
#foreach(SOURCE_FILE ${SRCS})
# # Get only the file name from the file as add_executable doesnot support executable with slash("/")
# get_filename_component(FILE_NAME_ONLY ${SOURCE_FILE} NAME_WE)
# # Remove .c from the file name and set it as executable name
# string( REPLACE ".c" "" EXECUTABLE_FILE ${FILE_NAME_ONLY})
# # Add executable for every source file in SRCS
# add_executable(unit-${EXECUTABLE_FILE} ${SOURCE_FILE})
# # Link above created libary to executable and dependent libary curl
# target_link_libraries(unit-${EXECUTABLE_FILE} ${CURL_LIBRARIES} ${pkgName} )
#endforeach(SOURCE_FILE ${SRCS})
64 changes: 64 additions & 0 deletions lib/skyhwd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# C API client for hardware_wallet_daemon_api

## Overview
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI spec](https://openapis.org) from a remote server, you can easily generate an API client.

- API version: 0.1.0
- Package version:
- Build package: org.openapitools.codegen.languages.CLibcurlClientCodegen

## Installation
You'll need the `curl 7.58.0` package in order to build the API. To have code formatted nicely you also need to have uncrustify version 0.67.

# Prerequisites

## Install the `curl 7.58.0` package with the following command on Linux.
```bash
sudo apt remove curl
wget http://curl.haxx.se/download/curl-7.58.0.tar.gz
tar -xvf curl-7.58.0.tar.gz
cd curl-7.58.0/
./configure
make
sudo make install
```
## Install the `uncrustify 0.67` package with the following command on Linux.
```bash
git clone https://github.com/uncrustify/uncrustify.git
cd uncrustify
mkdir build
cd build
cmake ..
make
sudo make install
```

## Compile the sample:
This will compile the generated code and create a library in build folder which has to be linked to the codes where API will be used.
```bash
mkdir build
cd build
// To install library to specific location use following command
cmake -DCMAKE_INSTALL_PREFIX=/pathtolocaiton ..
// for normal install use following command
cmake ..
make
sudo make install
```
## How to use compiled library
Considering the test/source code which uses the API is written in main.c(respective api include is written and all objects necessary are defined and created)

To compile main.c(considering the file is present in build folder) use following command
-L - locaiton of the library(not required if cmake with normal installation is performed)
-l library name
```bash
gcc main.c -L. -lpetstore -o main
```
once compile, you can run it with ``` ./main ```

Note: You dont need to specify includes for models and include folder seperately as they are path linked. You just have to import the api.h file in your code, the include linking will work.

## Author

[email protected]

Loading