jl777
7 years ago
committed by
GitHub
70 changed files with 3140 additions and 391 deletions
@ -0,0 +1,4 @@ |
|||
[submodule "cpp-ethereum"] |
|||
path = cpp-ethereum |
|||
url = https://github.com/artemii235/cpp-ethereum.git |
|||
branch = develop |
@ -0,0 +1,15 @@ |
|||
cmake_minimum_required(VERSION 3.5.1) |
|||
include("cmake/HunterGate.cmake") |
|||
HunterGate( |
|||
URL "https://github.com/ruslo/hunter/archive/v0.19.173.tar.gz" |
|||
SHA1 "750fb1d621af971fad6f303356b13017ad9f5e15" |
|||
LOCAL |
|||
) |
|||
project(SuperNET) |
|||
include_directories("${CMAKE_SOURCE_DIR}") |
|||
add_subdirectory(cpp-ethereum) |
|||
add_subdirectory(iguana/exchanges) |
|||
add_subdirectory(iguana/exchanges/etomicswap) |
|||
add_subdirectory(iguana/secp256k1) |
|||
add_subdirectory(crypto777) |
|||
add_subdirectory(crypto777/jpeg) |
@ -0,0 +1,18 @@ |
|||
# cryptopp has very bad CMakeLists.txt config. |
|||
# We have to enforce "cross compiling mode" there by setting CMAKE_SYSTEM_VERSION=NO |
|||
# to any "false" value. |
|||
hunter_config(cryptopp VERSION ${HUNTER_cryptopp_VERSION} CMAKE_ARGS CMAKE_SYSTEM_VERSION=NO) |
|||
|
|||
hunter_config( |
|||
libjson-rpc-cpp |
|||
VERSION ${HUNTER_libjson-rpc-cpp_VERSION} |
|||
CMAKE_ARGS |
|||
UNIX_DOMAIN_SOCKET_SERVER=NO |
|||
UNIX_DOMAIN_SOCKET_CLIENT=NO |
|||
FILE_DESCRIPTOR_SERVER=NO |
|||
FILE_DESCRIPTOR_CLIENT=NO |
|||
TCP_SOCKET_SERVER=NO |
|||
TCP_SOCKET_CLIENT=NO |
|||
HTTP_SERVER=NO |
|||
HTTP_CLIENT=NO |
|||
) |
@ -0,0 +1,529 @@ |
|||
# Copyright (c) 2013-2017, Ruslan Baratov |
|||
# All rights reserved. |
|||
# |
|||
# Redistribution and use in source and binary forms, with or without |
|||
# modification, are permitted provided that the following conditions are met: |
|||
# |
|||
# * Redistributions of source code must retain the above copyright notice, this |
|||
# list of conditions and the following disclaimer. |
|||
# |
|||
# * Redistributions in binary form must reproduce the above copyright notice, |
|||
# this list of conditions and the following disclaimer in the documentation |
|||
# and/or other materials provided with the distribution. |
|||
# |
|||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
|||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|||
|
|||
# This is a gate file to Hunter package manager. |
|||
# Include this file using `include` command and add package you need, example: |
|||
# |
|||
# cmake_minimum_required(VERSION 3.0) |
|||
# |
|||
# include("cmake/HunterGate.cmake") |
|||
# HunterGate( |
|||
# URL "https://github.com/path/to/hunter/archive.tar.gz" |
|||
# SHA1 "798501e983f14b28b10cda16afa4de69eee1da1d" |
|||
# ) |
|||
# |
|||
# project(MyProject) |
|||
# |
|||
# hunter_add_package(Foo) |
|||
# hunter_add_package(Boo COMPONENTS Bar Baz) |
|||
# |
|||
# Projects: |
|||
# * https://github.com/hunter-packages/gate/ |
|||
# * https://github.com/ruslo/hunter |
|||
|
|||
option(HUNTER_ENABLED "Enable Hunter package manager support" ON) |
|||
if(HUNTER_ENABLED) |
|||
if(CMAKE_VERSION VERSION_LESS "3.0") |
|||
message(FATAL_ERROR "At least CMake version 3.0 required for hunter dependency management." |
|||
" Update CMake or set HUNTER_ENABLED to OFF.") |
|||
endif() |
|||
endif() |
|||
|
|||
include(CMakeParseArguments) # cmake_parse_arguments |
|||
|
|||
option(HUNTER_STATUS_PRINT "Print working status" ON) |
|||
option(HUNTER_STATUS_DEBUG "Print a lot info" OFF) |
|||
|
|||
set(HUNTER_WIKI "https://github.com/ruslo/hunter/wiki") |
|||
|
|||
function(hunter_gate_status_print) |
|||
foreach(print_message ${ARGV}) |
|||
if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG) |
|||
message(STATUS "[hunter] ${print_message}") |
|||
endif() |
|||
endforeach() |
|||
endfunction() |
|||
|
|||
function(hunter_gate_status_debug) |
|||
foreach(print_message ${ARGV}) |
|||
if(HUNTER_STATUS_DEBUG) |
|||
string(TIMESTAMP timestamp) |
|||
message(STATUS "[hunter *** DEBUG *** ${timestamp}] ${print_message}") |
|||
endif() |
|||
endforeach() |
|||
endfunction() |
|||
|
|||
function(hunter_gate_wiki wiki_page) |
|||
message("------------------------------ WIKI -------------------------------") |
|||
message(" ${HUNTER_WIKI}/${wiki_page}") |
|||
message("-------------------------------------------------------------------") |
|||
message("") |
|||
message(FATAL_ERROR "") |
|||
endfunction() |
|||
|
|||
function(hunter_gate_internal_error) |
|||
message("") |
|||
foreach(print_message ${ARGV}) |
|||
message("[hunter ** INTERNAL **] ${print_message}") |
|||
endforeach() |
|||
message("[hunter ** INTERNAL **] [Directory:${CMAKE_CURRENT_LIST_DIR}]") |
|||
message("") |
|||
hunter_gate_wiki("error.internal") |
|||
endfunction() |
|||
|
|||
function(hunter_gate_fatal_error) |
|||
cmake_parse_arguments(hunter "" "WIKI" "" "${ARGV}") |
|||
string(COMPARE EQUAL "${hunter_WIKI}" "" have_no_wiki) |
|||
if(have_no_wiki) |
|||
hunter_gate_internal_error("Expected wiki") |
|||
endif() |
|||
message("") |
|||
foreach(x ${hunter_UNPARSED_ARGUMENTS}) |
|||
message("[hunter ** FATAL ERROR **] ${x}") |
|||
endforeach() |
|||
message("[hunter ** FATAL ERROR **] [Directory:${CMAKE_CURRENT_LIST_DIR}]") |
|||
message("") |
|||
hunter_gate_wiki("${hunter_WIKI}") |
|||
endfunction() |
|||
|
|||
function(hunter_gate_user_error) |
|||
hunter_gate_fatal_error(${ARGV} WIKI "error.incorrect.input.data") |
|||
endfunction() |
|||
|
|||
function(hunter_gate_self root version sha1 result) |
|||
string(COMPARE EQUAL "${root}" "" is_bad) |
|||
if(is_bad) |
|||
hunter_gate_internal_error("root is empty") |
|||
endif() |
|||
|
|||
string(COMPARE EQUAL "${version}" "" is_bad) |
|||
if(is_bad) |
|||
hunter_gate_internal_error("version is empty") |
|||
endif() |
|||
|
|||
string(COMPARE EQUAL "${sha1}" "" is_bad) |
|||
if(is_bad) |
|||
hunter_gate_internal_error("sha1 is empty") |
|||
endif() |
|||
|
|||
string(SUBSTRING "${sha1}" 0 7 archive_id) |
|||
|
|||
if(EXISTS "${root}/cmake/Hunter") |
|||
set(hunter_self "${root}") |
|||
else() |
|||
set( |
|||
hunter_self |
|||
"${root}/_Base/Download/Hunter/${version}/${archive_id}/Unpacked" |
|||
) |
|||
endif() |
|||
|
|||
set("${result}" "${hunter_self}" PARENT_SCOPE) |
|||
endfunction() |
|||
|
|||
# Set HUNTER_GATE_ROOT cmake variable to suitable value. |
|||
function(hunter_gate_detect_root) |
|||
# Check CMake variable |
|||
string(COMPARE NOTEQUAL "${HUNTER_ROOT}" "" not_empty) |
|||
if(not_empty) |
|||
set(HUNTER_GATE_ROOT "${HUNTER_ROOT}" PARENT_SCOPE) |
|||
hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable") |
|||
return() |
|||
endif() |
|||
|
|||
# Check environment variable |
|||
string(COMPARE NOTEQUAL "$ENV{HUNTER_ROOT}" "" not_empty) |
|||
if(not_empty) |
|||
set(HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT}" PARENT_SCOPE) |
|||
hunter_gate_status_debug("HUNTER_ROOT detected by environment variable") |
|||
return() |
|||
endif() |
|||
|
|||
# Check HOME environment variable |
|||
string(COMPARE NOTEQUAL "$ENV{HOME}" "" result) |
|||
if(result) |
|||
set(HUNTER_GATE_ROOT "$ENV{HOME}/.hunter" PARENT_SCOPE) |
|||
hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable") |
|||
return() |
|||
endif() |
|||
|
|||
# Check SYSTEMDRIVE and USERPROFILE environment variable (windows only) |
|||
if(WIN32) |
|||
string(COMPARE NOTEQUAL "$ENV{SYSTEMDRIVE}" "" result) |
|||
if(result) |
|||
set(HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE}/.hunter" PARENT_SCOPE) |
|||
hunter_gate_status_debug( |
|||
"HUNTER_ROOT set using SYSTEMDRIVE environment variable" |
|||
) |
|||
return() |
|||
endif() |
|||
|
|||
string(COMPARE NOTEQUAL "$ENV{USERPROFILE}" "" result) |
|||
if(result) |
|||
set(HUNTER_GATE_ROOT "$ENV{USERPROFILE}/.hunter" PARENT_SCOPE) |
|||
hunter_gate_status_debug( |
|||
"HUNTER_ROOT set using USERPROFILE environment variable" |
|||
) |
|||
return() |
|||
endif() |
|||
endif() |
|||
|
|||
hunter_gate_fatal_error( |
|||
"Can't detect HUNTER_ROOT" |
|||
WIKI "error.detect.hunter.root" |
|||
) |
|||
endfunction() |
|||
|
|||
macro(hunter_gate_lock dir) |
|||
if(NOT HUNTER_SKIP_LOCK) |
|||
if("${CMAKE_VERSION}" VERSION_LESS "3.2") |
|||
hunter_gate_fatal_error( |
|||
"Can't lock, upgrade to CMake 3.2 or use HUNTER_SKIP_LOCK" |
|||
WIKI "error.can.not.lock" |
|||
) |
|||
endif() |
|||
hunter_gate_status_debug("Locking directory: ${dir}") |
|||
file(LOCK "${dir}" DIRECTORY GUARD FUNCTION) |
|||
hunter_gate_status_debug("Lock done") |
|||
endif() |
|||
endmacro() |
|||
|
|||
function(hunter_gate_download dir) |
|||
string( |
|||
COMPARE |
|||
NOTEQUAL |
|||
"$ENV{HUNTER_DISABLE_AUTOINSTALL}" |
|||
"" |
|||
disable_autoinstall |
|||
) |
|||
if(disable_autoinstall AND NOT HUNTER_RUN_INSTALL) |
|||
hunter_gate_fatal_error( |
|||
"Hunter not found in '${dir}'" |
|||
"Set HUNTER_RUN_INSTALL=ON to auto-install it from '${HUNTER_GATE_URL}'" |
|||
"Settings:" |
|||
" HUNTER_ROOT: ${HUNTER_GATE_ROOT}" |
|||
" HUNTER_SHA1: ${HUNTER_GATE_SHA1}" |
|||
WIKI "error.run.install" |
|||
) |
|||
endif() |
|||
string(COMPARE EQUAL "${dir}" "" is_bad) |
|||
if(is_bad) |
|||
hunter_gate_internal_error("Empty 'dir' argument") |
|||
endif() |
|||
|
|||
string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" is_bad) |
|||
if(is_bad) |
|||
hunter_gate_internal_error("HUNTER_GATE_SHA1 empty") |
|||
endif() |
|||
|
|||
string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" is_bad) |
|||
if(is_bad) |
|||
hunter_gate_internal_error("HUNTER_GATE_URL empty") |
|||
endif() |
|||
|
|||
set(done_location "${dir}/DONE") |
|||
set(sha1_location "${dir}/SHA1") |
|||
|
|||
set(build_dir "${dir}/Build") |
|||
set(cmakelists "${dir}/CMakeLists.txt") |
|||
|
|||
hunter_gate_lock("${dir}") |
|||
if(EXISTS "${done_location}") |
|||
# while waiting for lock other instance can do all the job |
|||
hunter_gate_status_debug("File '${done_location}' found, skip install") |
|||
return() |
|||
endif() |
|||
|
|||
file(REMOVE_RECURSE "${build_dir}") |
|||
file(REMOVE_RECURSE "${cmakelists}") |
|||
|
|||
file(MAKE_DIRECTORY "${build_dir}") # check directory permissions |
|||
|
|||
# Disabling languages speeds up a little bit, reduces noise in the output |
|||
# and avoids path too long windows error |
|||
file( |
|||
WRITE |
|||
"${cmakelists}" |
|||
"cmake_minimum_required(VERSION 3.0)\n" |
|||
"project(HunterDownload LANGUAGES NONE)\n" |
|||
"include(ExternalProject)\n" |
|||
"ExternalProject_Add(\n" |
|||
" Hunter\n" |
|||
" URL\n" |
|||
" \"${HUNTER_GATE_URL}\"\n" |
|||
" URL_HASH\n" |
|||
" SHA1=${HUNTER_GATE_SHA1}\n" |
|||
" DOWNLOAD_DIR\n" |
|||
" \"${dir}\"\n" |
|||
" SOURCE_DIR\n" |
|||
" \"${dir}/Unpacked\"\n" |
|||
" CONFIGURE_COMMAND\n" |
|||
" \"\"\n" |
|||
" BUILD_COMMAND\n" |
|||
" \"\"\n" |
|||
" INSTALL_COMMAND\n" |
|||
" \"\"\n" |
|||
")\n" |
|||
) |
|||
|
|||
if(HUNTER_STATUS_DEBUG) |
|||
set(logging_params "") |
|||
else() |
|||
set(logging_params OUTPUT_QUIET) |
|||
endif() |
|||
|
|||
hunter_gate_status_debug("Run generate") |
|||
|
|||
# Need to add toolchain file too. |
|||
# Otherwise on Visual Studio + MDD this will fail with error: |
|||
# "Could not find an appropriate version of the Windows 10 SDK installed on this machine" |
|||
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}") |
|||
get_filename_component(absolute_CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" ABSOLUTE) |
|||
set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=${absolute_CMAKE_TOOLCHAIN_FILE}") |
|||
else() |
|||
# 'toolchain_arg' can't be empty |
|||
set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=") |
|||
endif() |
|||
|
|||
string(COMPARE EQUAL "${CMAKE_MAKE_PROGRAM}" "" no_make) |
|||
if(no_make) |
|||
set(make_arg "") |
|||
else() |
|||
# Test case: remove Ninja from PATH but set it via CMAKE_MAKE_PROGRAM |
|||
set(make_arg "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}") |
|||
endif() |
|||
|
|||
execute_process( |
|||
COMMAND |
|||
"${CMAKE_COMMAND}" |
|||
"-H${dir}" |
|||
"-B${build_dir}" |
|||
"-G${CMAKE_GENERATOR}" |
|||
"${toolchain_arg}" |
|||
${make_arg} |
|||
WORKING_DIRECTORY "${dir}" |
|||
RESULT_VARIABLE download_result |
|||
${logging_params} |
|||
) |
|||
|
|||
if(NOT download_result EQUAL 0) |
|||
hunter_gate_internal_error("Configure project failed") |
|||
endif() |
|||
|
|||
hunter_gate_status_print( |
|||
"Initializing Hunter workspace (${HUNTER_GATE_SHA1})" |
|||
" ${HUNTER_GATE_URL}" |
|||
" -> ${dir}" |
|||
) |
|||
execute_process( |
|||
COMMAND "${CMAKE_COMMAND}" --build "${build_dir}" |
|||
WORKING_DIRECTORY "${dir}" |
|||
RESULT_VARIABLE download_result |
|||
${logging_params} |
|||
) |
|||
|
|||
if(NOT download_result EQUAL 0) |
|||
hunter_gate_internal_error("Build project failed") |
|||
endif() |
|||
|
|||
file(REMOVE_RECURSE "${build_dir}") |
|||
file(REMOVE_RECURSE "${cmakelists}") |
|||
|
|||
file(WRITE "${sha1_location}" "${HUNTER_GATE_SHA1}") |
|||
file(WRITE "${done_location}" "DONE") |
|||
|
|||
hunter_gate_status_debug("Finished") |
|||
endfunction() |
|||
|
|||
# Must be a macro so master file 'cmake/Hunter' can |
|||
# apply all variables easily just by 'include' command |
|||
# (otherwise PARENT_SCOPE magic needed) |
|||
macro(HunterGate) |
|||
if(HUNTER_GATE_DONE) |
|||
# variable HUNTER_GATE_DONE set explicitly for external project |
|||
# (see `hunter_download`) |
|||
set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES) |
|||
endif() |
|||
|
|||
# First HunterGate command will init Hunter, others will be ignored |
|||
get_property(_hunter_gate_done GLOBAL PROPERTY HUNTER_GATE_DONE SET) |
|||
|
|||
if(NOT HUNTER_ENABLED) |
|||
# Empty function to avoid error "unknown function" |
|||
function(hunter_add_package) |
|||
endfunction() |
|||
elseif(_hunter_gate_done) |
|||
hunter_gate_status_debug("Secondary HunterGate (use old settings)") |
|||
hunter_gate_self( |
|||
"${HUNTER_CACHED_ROOT}" |
|||
"${HUNTER_VERSION}" |
|||
"${HUNTER_SHA1}" |
|||
_hunter_self |
|||
) |
|||
include("${_hunter_self}/cmake/Hunter") |
|||
else() |
|||
set(HUNTER_GATE_LOCATION "${CMAKE_CURRENT_LIST_DIR}") |
|||
|
|||
string(COMPARE NOTEQUAL "${PROJECT_NAME}" "" _have_project_name) |
|||
if(_have_project_name) |
|||
hunter_gate_fatal_error( |
|||
"Please set HunterGate *before* 'project' command. " |
|||
"Detected project: ${PROJECT_NAME}" |
|||
WIKI "error.huntergate.before.project" |
|||
) |
|||
endif() |
|||
|
|||
cmake_parse_arguments( |
|||
HUNTER_GATE "LOCAL" "URL;SHA1;GLOBAL;FILEPATH" "" ${ARGV} |
|||
) |
|||
|
|||
string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" _empty_sha1) |
|||
string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" _empty_url) |
|||
string( |
|||
COMPARE |
|||
NOTEQUAL |
|||
"${HUNTER_GATE_UNPARSED_ARGUMENTS}" |
|||
"" |
|||
_have_unparsed |
|||
) |
|||
string(COMPARE NOTEQUAL "${HUNTER_GATE_GLOBAL}" "" _have_global) |
|||
string(COMPARE NOTEQUAL "${HUNTER_GATE_FILEPATH}" "" _have_filepath) |
|||
|
|||
if(_have_unparsed) |
|||
hunter_gate_user_error( |
|||
"HunterGate unparsed arguments: ${HUNTER_GATE_UNPARSED_ARGUMENTS}" |
|||
) |
|||
endif() |
|||
if(_empty_sha1) |
|||
hunter_gate_user_error("SHA1 suboption of HunterGate is mandatory") |
|||
endif() |
|||
if(_empty_url) |
|||
hunter_gate_user_error("URL suboption of HunterGate is mandatory") |
|||
endif() |
|||
if(_have_global) |
|||
if(HUNTER_GATE_LOCAL) |
|||
hunter_gate_user_error("Unexpected LOCAL (already has GLOBAL)") |
|||
endif() |
|||
if(_have_filepath) |
|||
hunter_gate_user_error("Unexpected FILEPATH (already has GLOBAL)") |
|||
endif() |
|||
endif() |
|||
if(HUNTER_GATE_LOCAL) |
|||
if(_have_global) |
|||
hunter_gate_user_error("Unexpected GLOBAL (already has LOCAL)") |
|||
endif() |
|||
if(_have_filepath) |
|||
hunter_gate_user_error("Unexpected FILEPATH (already has LOCAL)") |
|||
endif() |
|||
endif() |
|||
if(_have_filepath) |
|||
if(_have_global) |
|||
hunter_gate_user_error("Unexpected GLOBAL (already has FILEPATH)") |
|||
endif() |
|||
if(HUNTER_GATE_LOCAL) |
|||
hunter_gate_user_error("Unexpected LOCAL (already has FILEPATH)") |
|||
endif() |
|||
endif() |
|||
|
|||
hunter_gate_detect_root() # set HUNTER_GATE_ROOT |
|||
|
|||
# Beautify path, fix probable problems with windows path slashes |
|||
get_filename_component( |
|||
HUNTER_GATE_ROOT "${HUNTER_GATE_ROOT}" ABSOLUTE |
|||
) |
|||
hunter_gate_status_debug("HUNTER_ROOT: ${HUNTER_GATE_ROOT}") |
|||
if(NOT HUNTER_ALLOW_SPACES_IN_PATH) |
|||
string(FIND "${HUNTER_GATE_ROOT}" " " _contain_spaces) |
|||
if(NOT _contain_spaces EQUAL -1) |
|||
hunter_gate_fatal_error( |
|||
"HUNTER_ROOT (${HUNTER_GATE_ROOT}) contains spaces." |
|||
"Set HUNTER_ALLOW_SPACES_IN_PATH=ON to skip this error" |
|||
"(Use at your own risk!)" |
|||
WIKI "error.spaces.in.hunter.root" |
|||
) |
|||
endif() |
|||
endif() |
|||
|
|||
string( |
|||
REGEX |
|||
MATCH |
|||
"[0-9]+\\.[0-9]+\\.[0-9]+[-_a-z0-9]*" |
|||
HUNTER_GATE_VERSION |
|||
"${HUNTER_GATE_URL}" |
|||
) |
|||
string(COMPARE EQUAL "${HUNTER_GATE_VERSION}" "" _is_empty) |
|||
if(_is_empty) |
|||
set(HUNTER_GATE_VERSION "unknown") |
|||
endif() |
|||
|
|||
hunter_gate_self( |
|||
"${HUNTER_GATE_ROOT}" |
|||
"${HUNTER_GATE_VERSION}" |
|||
"${HUNTER_GATE_SHA1}" |
|||
_hunter_self |
|||
) |
|||
|
|||
set(_master_location "${_hunter_self}/cmake/Hunter") |
|||
if(EXISTS "${HUNTER_GATE_ROOT}/cmake/Hunter") |
|||
# Hunter downloaded manually (e.g. by 'git clone') |
|||
set(_unused "xxxxxxxxxx") |
|||
set(HUNTER_GATE_SHA1 "${_unused}") |
|||
set(HUNTER_GATE_VERSION "${_unused}") |
|||
else() |
|||
get_filename_component(_archive_id_location "${_hunter_self}/.." ABSOLUTE) |
|||
set(_done_location "${_archive_id_location}/DONE") |
|||
set(_sha1_location "${_archive_id_location}/SHA1") |
|||
|
|||
# Check Hunter already downloaded by HunterGate |
|||
if(NOT EXISTS "${_done_location}") |
|||
hunter_gate_download("${_archive_id_location}") |
|||
endif() |
|||
|
|||
if(NOT EXISTS "${_done_location}") |
|||
hunter_gate_internal_error("hunter_gate_download failed") |
|||
endif() |
|||
|
|||
if(NOT EXISTS "${_sha1_location}") |
|||
hunter_gate_internal_error("${_sha1_location} not found") |
|||
endif() |
|||
file(READ "${_sha1_location}" _sha1_value) |
|||
string(COMPARE EQUAL "${_sha1_value}" "${HUNTER_GATE_SHA1}" _is_equal) |
|||
if(NOT _is_equal) |
|||
hunter_gate_internal_error( |
|||
"Short SHA1 collision:" |
|||
" ${_sha1_value} (from ${_sha1_location})" |
|||
" ${HUNTER_GATE_SHA1} (HunterGate)" |
|||
) |
|||
endif() |
|||
if(NOT EXISTS "${_master_location}") |
|||
hunter_gate_user_error( |
|||
"Master file not found:" |
|||
" ${_master_location}" |
|||
"try to update Hunter/HunterGate" |
|||
) |
|||
endif() |
|||
endif() |
|||
include("${_master_location}") |
|||
set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES) |
|||
endif() |
|||
endmacro() |
@ -0,0 +1,4 @@ |
|||
# Require C++11. |
|||
set(CMAKE_CXX_STANDARD 11) |
|||
set(CMAKE_CXX_STANDARD_REQUIRED True) |
|||
set(CMAKE_CXX_EXTENSIONS Off) |
@ -0,0 +1,4 @@ |
|||
file(GLOB sources "*.c") |
|||
file(GLOB headers "*.h") |
|||
add_library(libcrypto777 ${sources} ${headers}) |
|||
target_link_libraries(libcrypto777 PUBLIC curl) |
@ -0,0 +1,4 @@ |
|||
file(GLOB sources "*.c") |
|||
file(GLOB headers "*.h") |
|||
add_library(libjpeg ${sources} ${headers}) |
|||
target_sources(libjpeg PRIVATE "unix/jmemname.c") |
@ -0,0 +1,3 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"ETH\",\"rel\":\"KMD\",\"margin\":0.05,\"refbase\":\"ethereum\",\"refrel\":\"coinmarketcap\"}" |
@ -0,0 +1,3 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"buy\",\"base\":\"ETH\",\"rel\":\"KMD\",\"relvolume\":1,\"price\":300}" |
@ -0,0 +1,5 @@ |
|||
#!/bin/bash |
|||
source passphrase |
|||
source coins |
|||
./stop |
|||
iguana/exchanges/marketmaker "{\"netid\":9999,\"seednode\":\"5.9.253.204\",\"gui\":\"nogui\",\"client\":1, \"userhome\":\"/${HOME#"/"}\", \"passphrase\":\"$passphrase\", \"coins\":$coins}" & |
File diff suppressed because one or more lines are too long
@ -0,0 +1,5 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"ETH\"}" |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"KMD\"}" |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"ETOMIC\"}" |
@ -0,0 +1,3 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"ETH\",\"rel\":\"KMD\"}" |
@ -0,0 +1 @@ |
|||
export passphrase="<put a very strong passphrase here>" |
@ -0,0 +1,5 @@ |
|||
#!/bin/bash |
|||
source passphrase |
|||
source coins |
|||
./stop |
|||
$1 iguana/exchanges/marketmaker "{\"netid\":9999,\"gui\":\"nogui\", \"profitmargin\":0.01, \"userhome\":\"/${HOME#"/"}\", \"passphrase\":\"$passphrase\", \"coins\":$coins}" & |
@ -0,0 +1,4 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
source passphrase |
|||
curl --url "http://127.0.0.1:7783" --data "{\"netid\":9999,\"seednode\":\"5.9.253.204\",\"userpass\":\"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f\",\"method\":\"passphrase\",\"passphrase\":\"$passphrase\",\"gui\":\"nogui\"}" |
@ -0,0 +1,3 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"stop\"}" |
@ -0,0 +1,2 @@ |
|||
#export userpass="<put the userpass value from the first API call here>" |
|||
export userpass="c3d8c2a364b7d18c1f9d7321d017b92e9f9c791e4f5c741214fefdea8a071256" |
@ -0,0 +1 @@ |
|||
curl --url "http://127.0.0.1:7776" --data "{\"conf\":\"NINJA.conf\",\"path\":\"${HOME#"/"}/.komodo/NINJA\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"NINJA\",\"name\":\"NINJA\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"78a7bd45\",\"p2p\":15430,\"rpc\":15431,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"192.241.134.19\"}" |
@ -0,0 +1,7 @@ |
|||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) |
|||
add_executable(marketmaker mm.c) |
|||
include_directories(../../crypto777) |
|||
target_sources(marketmaker PRIVATE ../mini-gmp.c) |
|||
target_sources(marketmaker PRIVATE ../groestl.c) |
|||
target_sources(marketmaker PRIVATE ../segwit_addr.c) |
|||
target_link_libraries(marketmaker PRIVATE nanomsg curl pthread m libcrypto777 libjpeg libsecp256k1 "-Wl,--allow-multiple-definition" etomiclib) |
@ -0,0 +1,406 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 The SuperNET Developers. * |
|||
* * |
|||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * |
|||
* the top-level directory of this distribution for the individual copyright * |
|||
* holder information and the developer policies on copyright and licensing. * |
|||
* * |
|||
* Unless otherwise agreed in a custom licensing agreement, no part of the * |
|||
* SuperNET software, including this file may be copied, modified, propagated * |
|||
* or distributed except according to the terms contained in the LICENSE file * |
|||
* * |
|||
* Removal or modification of this copyright notice is prohibited. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_etomic.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
//
|
|||
// Created by artem on 24.01.18.
|
|||
//
|
|||
#include "etomicswap/etomiclib.h" |
|||
#include "etomicswap/etomiccurl.h" |
|||
#include <inttypes.h> |
|||
|
|||
char *LP_etomicalice_send_payment(struct basilisk_swap *swap) |
|||
{ |
|||
AliceSendsEthPaymentInput input; AliceSendsErc20PaymentInput input20; BasicTxData txData; |
|||
|
|||
// set input and txData fields from the swap data structure
|
|||
memset(&txData,0,sizeof(txData)); |
|||
if ( strcmp(swap->I.alicestr,"ETH") == 0 ) |
|||
{ |
|||
memset(&input,0,sizeof(input)); |
|||
strcpy(input.bobAddress, swap->I.etomicsrc); |
|||
uint8arrayToHex(input.bobHash, swap->I.secretBn, 20); |
|||
uint8arrayToHex(input.aliceHash, swap->I.secretAm, 20); |
|||
uint8arrayToHex(input.dealId, swap->alicepayment.I.actualtxid.bytes, 32); |
|||
|
|||
strcpy(txData.from, swap->I.etomicdest); |
|||
strcpy(txData.to, ETOMIC_ALICECONTRACT); |
|||
satoshisToWei(txData.amount, swap->I.alicesatoshis); |
|||
uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32); |
|||
|
|||
return(aliceSendsEthPayment(input,txData)); |
|||
} |
|||
else |
|||
{ |
|||
memset(&input20,0,sizeof(input20)); |
|||
strcpy(input20.bobAddress, swap->I.etomicdest); |
|||
uint8arrayToHex(input20.bobHash, swap->I.secretBn, 20); |
|||
uint8arrayToHex(input20.aliceHash, swap->I.secretAm, 20); |
|||
uint8arrayToHex(input20.dealId, swap->alicepayment.utxotxid.bytes, 32); |
|||
strcpy(input20.tokenAddress, swap->I.alicetomic); |
|||
satoshisToWei(input20.amount, swap->I.alicesatoshis); |
|||
|
|||
strcpy(txData.from, swap->I.etomicsrc); |
|||
strcpy(txData.to, ETOMIC_ALICECONTRACT); |
|||
strcpy(txData.amount, "0"); |
|||
uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32); |
|||
return(aliceSendsErc20Payment(input20,txData)); |
|||
} |
|||
} |
|||
|
|||
char *LP_etomicalice_reclaims_payment(struct LP_swap_remember *swap) |
|||
{ |
|||
AliceReclaimsAlicePaymentInput input; |
|||
BasicTxData txData; |
|||
memset(&txData,0,sizeof(txData)); |
|||
memset(&input,0,sizeof(input)); |
|||
|
|||
struct iguana_info *ecoin; |
|||
bits256 privkey; |
|||
ecoin = LP_coinfind("ETOMIC"); |
|||
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr); |
|||
|
|||
uint8arrayToHex(input.dealId, swap->txids[BASILISK_ALICEPAYMENT].bytes, 32); |
|||
satoshisToWei(input.amount, swap->values[BASILISK_ALICEPAYMENT]); |
|||
|
|||
if (swap->alicetomic[0] != 0) { |
|||
strcpy(input.tokenAddress, swap->alicetomic); |
|||
} else { |
|||
strcpy(input.tokenAddress, "0x0000000000000000000000000000000000000000"); |
|||
} |
|||
strcpy(input.bobAddress, swap->etomicdest); |
|||
uint8arrayToHex(input.aliceHash, swap->secretAm, 20); |
|||
bits256 invertedSecret; |
|||
int32_t i; |
|||
for (i=0; i<32; i++) { |
|||
invertedSecret.bytes[i] = swap->privBn.bytes[31 - i]; |
|||
} |
|||
uint8arrayToHex(input.bobSecret, invertedSecret.bytes, 32); |
|||
|
|||
strcpy(txData.from, swap->etomicsrc); |
|||
strcpy(txData.to, ETOMIC_ALICECONTRACT); |
|||
strcpy(txData.amount, "0"); |
|||
uint8arrayToHex(txData.secretKey, privkey.bytes, 32); |
|||
return aliceReclaimsAlicePayment(input, txData); |
|||
} |
|||
|
|||
char *LP_etomicbob_spends_alice_payment(struct LP_swap_remember *swap) |
|||
{ |
|||
BobSpendsAlicePaymentInput input; |
|||
BasicTxData txData; |
|||
|
|||
memset(&txData,0,sizeof(txData)); |
|||
memset(&input,0,sizeof(input)); |
|||
|
|||
struct iguana_info *ecoin; |
|||
bits256 privkey; |
|||
ecoin = LP_coinfind("ETOMIC"); |
|||
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr); |
|||
|
|||
uint8arrayToHex(input.dealId, swap->txids[BASILISK_ALICEPAYMENT].bytes, 32); |
|||
satoshisToWei(input.amount, swap->destamount); |
|||
|
|||
if (swap->alicetomic[0] != 0) { |
|||
strcpy(input.tokenAddress, swap->alicetomic); |
|||
} else { |
|||
strcpy(input.tokenAddress, "0x0000000000000000000000000000000000000000"); |
|||
} |
|||
|
|||
strcpy(input.aliceAddress, swap->etomicdest); |
|||
bits256 invertedSecret; int32_t i; |
|||
for (i=0; i<32; i++) { |
|||
invertedSecret.bytes[i] = swap->privAm.bytes[31 - i]; |
|||
} |
|||
uint8arrayToHex(input.aliceSecret, invertedSecret.bytes, 32); |
|||
uint8arrayToHex(input.bobHash, swap->secretBn, 20); |
|||
|
|||
strcpy(txData.from, swap->etomicsrc); |
|||
strcpy(txData.to, ETOMIC_ALICECONTRACT); |
|||
strcpy(txData.amount, "0"); |
|||
uint8arrayToHex(txData.secretKey, privkey.bytes, 32); |
|||
return bobSpendsAlicePayment(input, txData); |
|||
} |
|||
|
|||
char *LP_etomicbob_sends_deposit(struct basilisk_swap *swap) |
|||
{ |
|||
BobSendsEthDepositInput input; |
|||
BobSendsErc20DepositInput input20; |
|||
BasicTxData txData; |
|||
memset(&txData,0,sizeof(txData)); |
|||
memset(&input,0,sizeof(input)); |
|||
memset(&input20,0,sizeof(input20)); |
|||
if ( strcmp(swap->I.bobstr,"ETH") == 0 ) { |
|||
uint8arrayToHex(input.depositId, swap->bobdeposit.I.actualtxid.bytes, 32); |
|||
strcpy(input.aliceAddress, swap->I.etomicdest); |
|||
uint8arrayToHex(input.bobHash, swap->I.secretBn, 20); |
|||
|
|||
strcpy(txData.from, swap->I.etomicsrc); |
|||
strcpy(txData.to, ETOMIC_BOBCONTRACT); |
|||
satoshisToWei(txData.amount, swap->bobdeposit.I.amount); |
|||
uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32); |
|||
return bobSendsEthDeposit(input, txData); |
|||
} else { |
|||
uint8arrayToHex(input20.depositId, swap->bobdeposit.I.actualtxid.bytes, 32); |
|||
strcpy(input20.aliceAddress, swap->I.etomicdest); |
|||
uint8arrayToHex(input20.bobHash, swap->I.secretBn, 20); |
|||
satoshisToWei(input20.amount, swap->bobdeposit.I.amount); |
|||
strcpy(input20.tokenAddress, swap->I.bobtomic); |
|||
|
|||
strcpy(txData.from, swap->I.etomicsrc); |
|||
strcpy(txData.to, ETOMIC_BOBCONTRACT); |
|||
strcpy(txData.amount, "0"); |
|||
uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32); |
|||
return bobSendsErc20Deposit(input20, txData); |
|||
} |
|||
} |
|||
|
|||
char *LP_etomicbob_refunds_deposit(struct LP_swap_remember *swap) |
|||
{ |
|||
BobRefundsDepositInput input; |
|||
BasicTxData txData; |
|||
memset(&txData,0,sizeof(txData)); |
|||
memset(&input,0,sizeof(input)); |
|||
|
|||
struct iguana_info *ecoin; |
|||
bits256 privkey; |
|||
ecoin = LP_coinfind("ETOMIC"); |
|||
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr); |
|||
|
|||
EthTxReceipt receipt = getEthTxReceipt(swap->bobDepositEthTx); |
|||
uint8arrayToHex(input.depositId, swap->txids[BASILISK_BOBDEPOSIT].bytes, 32); |
|||
strcpy(input.aliceAddress, swap->etomicdest); |
|||
sprintf(input.aliceCanClaimAfter, "%" PRIu64, receipt.blockNumber + 960); |
|||
|
|||
bits256 invertedSecret; |
|||
int32_t i; |
|||
for (i=0; i<32; i++) { |
|||
invertedSecret.bytes[i] = swap->privBn.bytes[31 - i]; |
|||
} |
|||
uint8arrayToHex(input.bobSecret, invertedSecret.bytes, 32); |
|||
|
|||
if (swap->bobtomic[0] != 0) { |
|||
strcpy(input.tokenAddress, swap->bobtomic); |
|||
} else { |
|||
strcpy(input.tokenAddress, "0x0000000000000000000000000000000000000000"); |
|||
} |
|||
satoshisToWei(input.amount, swap->values[BASILISK_BOBDEPOSIT]); |
|||
|
|||
strcpy(txData.from, swap->etomicsrc); |
|||
strcpy(txData.to, ETOMIC_BOBCONTRACT); |
|||
strcpy(txData.amount, "0"); |
|||
uint8arrayToHex(txData.secretKey, privkey.bytes, 32); |
|||
return bobRefundsDeposit(input, txData); |
|||
} |
|||
|
|||
char *LP_etomicbob_sends_payment(struct basilisk_swap *swap) |
|||
{ |
|||
BobSendsEthPaymentInput input; |
|||
BobSendsErc20PaymentInput input20; |
|||
BasicTxData txData; |
|||
memset(&txData,0,sizeof(txData)); |
|||
memset(&input,0,sizeof(input)); |
|||
memset(&input20,0,sizeof(input20)); |
|||
|
|||
if ( strcmp(swap->I.bobstr,"ETH") == 0 ) { |
|||
uint8arrayToHex(input.paymentId, swap->bobpayment.I.actualtxid.bytes, 32); |
|||
strcpy(input.aliceAddress, swap->I.etomicdest); |
|||
uint8arrayToHex(input.aliceHash, swap->I.secretAm, 20); |
|||
|
|||
strcpy(txData.from, swap->I.etomicsrc); |
|||
strcpy(txData.to, ETOMIC_BOBCONTRACT); |
|||
satoshisToWei(txData.amount, swap->bobpayment.I.amount); |
|||
uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32); |
|||
return bobSendsEthPayment(input, txData); |
|||
} else { |
|||
uint8arrayToHex(input20.paymentId, swap->bobpayment.I.actualtxid.bytes, 32); |
|||
strcpy(input20.aliceAddress, swap->I.etomicdest); |
|||
uint8arrayToHex(input20.aliceHash, swap->I.secretAm, 20); |
|||
satoshisToWei(input20.amount, swap->bobpayment.I.amount); |
|||
strcpy(input20.tokenAddress, swap->I.bobtomic); |
|||
|
|||
strcpy(txData.from, swap->I.etomicsrc); |
|||
strcpy(txData.to, ETOMIC_BOBCONTRACT); |
|||
strcpy(txData.amount, "0"); |
|||
uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32); |
|||
return bobSendsErc20Payment(input20, txData); |
|||
} |
|||
} |
|||
|
|||
char *LP_etomicbob_reclaims_payment(struct LP_swap_remember *swap) |
|||
{ |
|||
BobReclaimsBobPaymentInput input; |
|||
BasicTxData txData; |
|||
memset(&txData,0,sizeof(txData)); |
|||
memset(&input,0,sizeof(input)); |
|||
|
|||
struct iguana_info *ecoin; |
|||
bits256 privkey; |
|||
ecoin = LP_coinfind("ETOMIC"); |
|||
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr); |
|||
|
|||
EthTxReceipt receipt = getEthTxReceipt(swap->bobPaymentEthTx); |
|||
uint8arrayToHex(input.paymentId, swap->txids[BASILISK_BOBPAYMENT].bytes, 32); |
|||
strcpy(input.aliceAddress, swap->etomicdest); |
|||
sprintf(input.bobCanClaimAfter, "%" PRIu64, receipt.blockNumber + 480); |
|||
uint8arrayToHex(input.aliceHash, swap->secretAm, 20); |
|||
|
|||
if (swap->bobtomic[0] != 0) { |
|||
strcpy(input.tokenAddress, swap->bobtomic); |
|||
} else { |
|||
strcpy(input.tokenAddress, "0x0000000000000000000000000000000000000000"); |
|||
} |
|||
satoshisToWei(input.amount, swap->values[BASILISK_BOBPAYMENT]); |
|||
|
|||
strcpy(txData.from, swap->etomicsrc); |
|||
strcpy(txData.to, ETOMIC_BOBCONTRACT); |
|||
strcpy(txData.amount, "0"); |
|||
uint8arrayToHex(txData.secretKey, privkey.bytes, 32); |
|||
return bobReclaimsBobPayment(input, txData); |
|||
} |
|||
|
|||
char *LP_etomicalice_spends_bob_payment(struct LP_swap_remember *swap) |
|||
{ |
|||
AliceSpendsBobPaymentInput input; |
|||
BasicTxData txData; |
|||
|
|||
memset(&txData,0,sizeof(txData)); |
|||
memset(&input,0,sizeof(input)); |
|||
EthTxReceipt receipt = getEthTxReceipt(swap->bobPaymentEthTx); |
|||
|
|||
struct iguana_info *ecoin; |
|||
bits256 privkey; |
|||
ecoin = LP_coinfind("ETOMIC"); |
|||
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr); |
|||
|
|||
uint8arrayToHex(input.paymentId, swap->txids[BASILISK_BOBPAYMENT].bytes, 32); |
|||
satoshisToWei(input.amount, swap->values[BASILISK_BOBPAYMENT]); |
|||
sprintf(input.bobCanClaimAfter, "%" PRIu64, receipt.blockNumber + 480); |
|||
|
|||
if (swap->bobtomic[0] != 0) { |
|||
strcpy(input.tokenAddress, swap->bobtomic); |
|||
} else { |
|||
strcpy(input.tokenAddress, "0x0000000000000000000000000000000000000000"); |
|||
} |
|||
|
|||
strcpy(input.bobAddress, swap->etomicsrc); |
|||
bits256 invertedSecret; int32_t i; |
|||
|
|||
for (i=0; i<32; i++) { |
|||
invertedSecret.bytes[i] = swap->privAm.bytes[31 - i]; |
|||
} |
|||
uint8arrayToHex(input.aliceSecret, invertedSecret.bytes, 32); |
|||
|
|||
strcpy(txData.from, swap->etomicdest); |
|||
strcpy(txData.to, ETOMIC_BOBCONTRACT); |
|||
strcpy(txData.amount, "0"); |
|||
uint8arrayToHex(txData.secretKey, privkey.bytes, 32); |
|||
return aliceSpendsBobPayment(input, txData); |
|||
} |
|||
|
|||
char *LP_etomicalice_claims_bob_deposit(struct LP_swap_remember *swap) |
|||
{ |
|||
AliceClaimsBobDepositInput input; |
|||
BasicTxData txData; |
|||
|
|||
memset(&txData,0,sizeof(txData)); |
|||
memset(&input,0,sizeof(input)); |
|||
EthTxReceipt receipt = getEthTxReceipt(swap->bobDepositEthTx); |
|||
|
|||
struct iguana_info *ecoin; |
|||
bits256 privkey; |
|||
ecoin = LP_coinfind("ETOMIC"); |
|||
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr); |
|||
|
|||
uint8arrayToHex(input.depositId, swap->txids[BASILISK_BOBDEPOSIT].bytes, 32); |
|||
satoshisToWei(input.amount, swap->values[BASILISK_BOBDEPOSIT]); |
|||
sprintf(input.aliceCanClaimAfter, "%" PRIu64, receipt.blockNumber + 960); |
|||
|
|||
if (swap->bobtomic[0] != 0) { |
|||
strcpy(input.tokenAddress, swap->bobtomic); |
|||
} else { |
|||
strcpy(input.tokenAddress, "0x0000000000000000000000000000000000000000"); |
|||
} |
|||
|
|||
strcpy(input.bobAddress, swap->etomicsrc); |
|||
uint8arrayToHex(input.bobHash, swap->secretBn, 20); |
|||
|
|||
strcpy(txData.from, swap->etomicdest); |
|||
strcpy(txData.to, ETOMIC_BOBCONTRACT); |
|||
strcpy(txData.amount, "0"); |
|||
uint8arrayToHex(txData.secretKey, privkey.bytes, 32); |
|||
return aliceClaimsBobDeposit(input, txData); |
|||
} |
|||
|
|||
char *sendEthTx(struct basilisk_swap *swap, struct basilisk_rawtx *rawtx) |
|||
{ |
|||
if (rawtx == &swap->alicepayment && swap->I.alicetomic[0] != 0) { |
|||
return LP_etomicalice_send_payment(swap); |
|||
} else if (rawtx == &swap->bobdeposit && swap->I.bobtomic[0] != 0) { |
|||
return LP_etomicbob_sends_deposit(swap); |
|||
} else if (rawtx == &swap->bobpayment && swap->I.bobtomic[0] != 0) { |
|||
return LP_etomicbob_sends_payment(swap); |
|||
} else { |
|||
char *result = malloc(67); |
|||
strcpy(result, "0x0000000000000000000000000000000000000000000000000000000000000000"); |
|||
return result; |
|||
} |
|||
} |
|||
|
|||
int32_t LP_etomic_priv2addr(char *coinaddr,bits256 privkey) |
|||
{ |
|||
char str[65],*addrstr; |
|||
bits256_str(str,privkey); |
|||
if ( (addrstr= privKey2Addr(str)) != 0 ) |
|||
{ |
|||
strcpy(coinaddr,addrstr); |
|||
free(addrstr); |
|||
return(0); |
|||
} |
|||
return(-1); |
|||
} |
|||
|
|||
int32_t LP_etomic_priv2pub(uint8_t *pub64,bits256 privkey) |
|||
{ |
|||
char *pubstr,str[72]; int32_t retval = -1; |
|||
bits256_str(str,privkey); |
|||
if ( (pubstr= getPubKeyFromPriv(str)) != 0 ) |
|||
{ |
|||
if ( strlen(pubstr) == 130 && pubstr[0] == '0' && pubstr[1] == 'x' ) |
|||
{ |
|||
decode_hex(pub64,64,pubstr+2); |
|||
retval = 0; |
|||
} |
|||
free(pubstr); |
|||
} |
|||
return(retval); |
|||
} |
|||
|
|||
int32_t LP_etomic_pub2addr(char *coinaddr,uint8_t pub64[64]) |
|||
{ |
|||
char pubkeystr[131],*addrstr; |
|||
strcpy(pubkeystr,"0x"); |
|||
init_hexbytes_noT(pubkeystr+2,pub64,64); |
|||
if ( (addrstr= pubKey2Addr(pubkeystr)) != 0 ) |
|||
{ |
|||
strcpy(coinaddr,addrstr); |
|||
free(addrstr); |
|||
return(0); |
|||
} |
|||
return(-1); |
|||
} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,10 @@ |
|||
cmake_minimum_required(VERSION 2.8.9) |
|||
add_library(etomiclib etomiclib.cpp) |
|||
add_library(etomiccurl etomiccurl.c) |
|||
add_executable(alice alice.c) |
|||
add_executable(bob bob.c) |
|||
include_directories("${CMAKE_SOURCE_DIR}/cpp-ethereum") |
|||
target_link_libraries(etomiccurl PUBLIC curl libcrypto777) |
|||
target_link_libraries(etomiclib PUBLIC ethcore devcrypto devcore etomiccurl) |
|||
target_link_libraries(alice PUBLIC etomiclib) |
|||
target_link_libraries(bob PUBLIC etomiclib etomiccurl) |
@ -0,0 +1,106 @@ |
|||
//
|
|||
// Created by artem on 24.01.18.
|
|||
//
|
|||
#include <stdio.h> |
|||
#include <curl/curl.h> |
|||
#include <stdlib.h> |
|||
#include "etomiclib.h" |
|||
#include <cjson/cJSON.h> |
|||
|
|||
char* aliceContractAddress = "0xe1D4236C5774D35Dc47dcc2E5E0CcFc463A3289c"; |
|||
char* aliceAddress = "0x485d2cc2d13a9e12E4b53D606DB1c8adc884fB8a"; |
|||
char* bobAddress = "0xA7EF3f65714AE266414C9E58bB4bAa4E6FB82B41"; |
|||
char* tokenAddress = "0xc0eb7AeD740E1796992A08962c15661bDEB58003"; |
|||
|
|||
int main(int argc, char** argv) { |
|||
enum { INIT_ETH, INIT_ERC20, ALICE_CLAIMS, BOB_CLAIMS, ALICE_APPROVES_ERC20 }; |
|||
|
|||
if (argc < 2) { |
|||
return 1; |
|||
} |
|||
|
|||
int action = atoi(argv[1]); |
|||
char* result; |
|||
BasicTxData txData; |
|||
switch (action) |
|||
{ |
|||
case INIT_ETH: |
|||
txData.amount = "1000000000000000000"; |
|||
txData.from = aliceAddress; |
|||
txData.to = aliceContractAddress; |
|||
txData.secretKey = getenv("ALICE_PK"); |
|||
|
|||
AliceSendsEthPaymentInput input = { |
|||
.dealId = argv[2], |
|||
.bobAddress = bobAddress, |
|||
.aliceHash = argv[3], |
|||
.bobHash = argv[4] |
|||
}; |
|||
|
|||
result = aliceSendsEthPayment(input, txData); |
|||
break; |
|||
case INIT_ERC20: |
|||
txData.amount = "0"; |
|||
txData.from = aliceAddress; |
|||
txData.to = aliceContractAddress; |
|||
txData.secretKey = getenv("ALICE_PK"); |
|||
|
|||
AliceSendsErc20PaymentInput input1 = { |
|||
.dealId = argv[2], |
|||
.bobAddress = bobAddress, |
|||
.aliceHash = argv[3], |
|||
.bobHash = argv[4], |
|||
.amount = "1000000000000000000", |
|||
.tokenAddress = tokenAddress |
|||
}; |
|||
|
|||
result = aliceSendsErc20Payment(input1, txData); |
|||
break; |
|||
case ALICE_CLAIMS: |
|||
txData.amount = "0"; |
|||
txData.from = aliceAddress; |
|||
txData.to = aliceContractAddress; |
|||
txData.secretKey = getenv("ALICE_PK"); |
|||
|
|||
AliceReclaimsAlicePaymentInput input2 = { |
|||
.dealId = argv[2], |
|||
.bobAddress = bobAddress, |
|||
.aliceHash = argv[3], |
|||
.bobSecret = argv[4], |
|||
.tokenAddress = argv[5], |
|||
.amount = "1000000000000000000" |
|||
}; |
|||
|
|||
result = aliceReclaimsAlicePayment(input2, txData); |
|||
break; |
|||
case BOB_CLAIMS: |
|||
txData.amount = "0"; |
|||
txData.from = bobAddress; |
|||
txData.to = aliceContractAddress; |
|||
txData.secretKey = getenv("BOB_PK"); |
|||
|
|||
BobSpendsAlicePaymentInput input3 = { |
|||
.dealId = argv[2], |
|||
.aliceAddress = aliceAddress, |
|||
.aliceSecret = argv[3], |
|||
.bobHash = argv[4], |
|||
.tokenAddress = argv[5], |
|||
.amount = "1000000000000000000" |
|||
}; |
|||
|
|||
result = bobSpendsAlicePayment(input3, txData); |
|||
break; |
|||
case ALICE_APPROVES_ERC20: |
|||
result = approveErc20( |
|||
"1000000000000000000", |
|||
"0x485d2cc2d13a9e12E4b53D606DB1c8adc884fB8a", |
|||
getenv("ALICE_PK") |
|||
); |
|||
break; |
|||
default: |
|||
return 1; |
|||
} |
|||
printf("%s\n", result); |
|||
free(result); |
|||
return 0; |
|||
} |
@ -0,0 +1,218 @@ |
|||
//
|
|||
// Created by artem on 24.01.18.
|
|||
//
|
|||
#include <stdio.h> |
|||
#include <curl/curl.h> |
|||
#include <stdlib.h> |
|||
#include <inttypes.h> |
|||
#include <string.h> |
|||
#include "etomiclib.h" |
|||
#include "etomiccurl.h" |
|||
|
|||
char* bobContractAddress = "0x9387Fd3a016bB0205e4e131Dde886B9d2BC000A2"; |
|||
char* aliceAddress = "0x485d2cc2d13a9e12E4b53D606DB1c8adc884fB8a"; |
|||
char* bobAddress = "0xA7EF3f65714AE266414C9E58bB4bAa4E6FB82B41"; |
|||
char* tokenAddress = "0xc0eb7AeD740E1796992A08962c15661bDEB58003"; |
|||
|
|||
int main(int argc, char** argv) |
|||
{ |
|||
enum { |
|||
BOB_ETH_DEPOSIT, |
|||
BOB_ERC20_DEPOSIT, |
|||
BOB_CLAIMS_DEPOSIT, |
|||
ALICE_CLAIMS_DEPOSIT, |
|||
BOB_ETH_PAYMENT, |
|||
BOB_ERC20_PAYMENT, |
|||
BOB_CLAIMS_PAYMENT, |
|||
ALICE_CLAIMS_PAYMENT, |
|||
BOB_APPROVES_ERC20, |
|||
BOB_ETH_BALANCE, |
|||
BOB_ERC20_BALANCE, |
|||
TX_RECEIPT |
|||
}; |
|||
if (argc < 2) { |
|||
return 1; |
|||
} |
|||
int action = atoi(argv[1]); |
|||
BasicTxData txData; |
|||
char* result; |
|||
switch (action) |
|||
{ |
|||
case BOB_ETH_DEPOSIT: |
|||
strcpy(txData.amount, "1000000000000000000"); |
|||
strcpy(txData.from, bobAddress); |
|||
strcpy(txData.to, bobContractAddress); |
|||
strcpy(txData.secretKey, getenv("BOB_PK")); |
|||
|
|||
BobSendsEthDepositInput input; |
|||
|
|||
strcpy(input.aliceAddress, aliceAddress); |
|||
strcpy(input.depositId, argv[2]); |
|||
strcpy(input.bobHash, argv[3]); |
|||
|
|||
result = bobSendsEthDeposit(input, txData); |
|||
printf("%s\n", result); |
|||
free(result); |
|||
break; |
|||
case BOB_ERC20_DEPOSIT: |
|||
strcpy(txData.amount, "0"); |
|||
strcpy(txData.from, bobAddress); |
|||
strcpy(txData.to, bobContractAddress); |
|||
strcpy(txData.secretKey, getenv("BOB_PK")); |
|||
|
|||
BobSendsErc20DepositInput input1 = { |
|||
.amount = "1000000000000000000" |
|||
}; |
|||
|
|||
strcpy(input1.depositId, argv[2]); |
|||
strcpy(input1.aliceAddress, aliceAddress); |
|||
strcpy(input1.bobHash, argv[3]); |
|||
strcpy(input1.tokenAddress, tokenAddress); |
|||
|
|||
result = bobSendsErc20Deposit(input1, txData); |
|||
printf("%s\n", result); |
|||
free(result); |
|||
break; |
|||
case BOB_CLAIMS_DEPOSIT: |
|||
strcpy(txData.amount, "0"); |
|||
strcpy(txData.from, bobAddress); |
|||
strcpy(txData.to, bobContractAddress); |
|||
strcpy(txData.secretKey, getenv("BOB_PK")); |
|||
|
|||
BobRefundsDepositInput input2; |
|||
strcpy(input2.depositId, argv[2]); |
|||
strcpy(input2.amount, "1000000000000000000"); |
|||
strcpy(input2.aliceAddress, aliceAddress); |
|||
strcpy(input2.tokenAddress, argv[3]); |
|||
strcpy(input2.aliceCanClaimAfter, argv[4]); |
|||
strcpy(input2.bobSecret, argv[5]); |
|||
|
|||
result = bobRefundsDeposit(input2, txData); |
|||
printf("%s\n", result); |
|||
free(result); |
|||
break; |
|||
case ALICE_CLAIMS_DEPOSIT: |
|||
strcpy(txData.amount, "0"); |
|||
strcpy(txData.from, aliceAddress); |
|||
strcpy(txData.to, bobContractAddress); |
|||
strcpy(txData.secretKey, getenv("ALICE_PK")); |
|||
|
|||
AliceClaimsBobDepositInput input3; |
|||
strcpy(input3.depositId, argv[2]); |
|||
strcpy(input3.amount, "1000000000000000000"); |
|||
strcpy(input3.bobAddress, bobAddress); |
|||
strcpy(input3.tokenAddress, argv[3]); |
|||
strcpy(input3.aliceCanClaimAfter, argv[4]); |
|||
strcpy(input3.bobHash, argv[5]); |
|||
|
|||
result = aliceClaimsBobDeposit(input3, txData); |
|||
printf("%s\n", result); |
|||
free(result); |
|||
break; |
|||
case BOB_ETH_PAYMENT: |
|||
strcpy(txData.amount, "1000000000000000000"); |
|||
strcpy(txData.from, bobAddress); |
|||
strcpy(txData.to, bobContractAddress); |
|||
strcpy(txData.secretKey, getenv("BOB_PK")); |
|||
|
|||
BobSendsEthPaymentInput input4; |
|||
strcpy(input4.paymentId, argv[2]); |
|||
strcpy(input4.aliceHash, argv[3]); |
|||
strcpy(input4.aliceAddress, aliceAddress); |
|||
|
|||
result = bobSendsEthPayment(input4, txData); |
|||
printf("%s\n", result); |
|||
free(result); |
|||
break; |
|||
case BOB_ERC20_PAYMENT: |
|||
strcpy(txData.amount, "0"); |
|||
strcpy(txData.from, bobAddress); |
|||
strcpy(txData.to, bobContractAddress); |
|||
strcpy(txData.secretKey, getenv("BOB_PK")); |
|||
|
|||
BobSendsErc20PaymentInput input5; |
|||
|
|||
strcpy(input5.paymentId, argv[2]); |
|||
strcpy(input5.amount, "1000000000000000000"); |
|||
strcpy(input5.tokenAddress, tokenAddress); |
|||
strcpy(input5.aliceAddress, aliceAddress); |
|||
strcpy(input5.aliceHash, argv[3]); |
|||
|
|||
result = bobSendsErc20Payment(input5, txData); |
|||
printf("%s\n", result); |
|||
free(result); |
|||
break; |
|||
case BOB_CLAIMS_PAYMENT: |
|||
strcpy(txData.amount, "0"); |
|||
strcpy(txData.from, bobAddress); |
|||
strcpy(txData.to, bobContractAddress); |
|||
strcpy(txData.secretKey, getenv("BOB_PK")); |
|||
|
|||
BobReclaimsBobPaymentInput input6; |
|||
|
|||
strcpy(input6.paymentId, argv[2]); |
|||
strcpy(input6.aliceAddress, aliceAddress); |
|||
strcpy(input6.amount, "1000000000000000000"); |
|||
strcpy(input6.tokenAddress, argv[3]); |
|||
strcpy(input6.bobCanClaimAfter, argv[4]); |
|||
strcpy(input6.aliceHash, argv[5]); |
|||
|
|||
result = bobReclaimsBobPayment(input6, txData); |
|||
printf("%s\n", result); |
|||
free(result); |
|||
break; |
|||
case ALICE_CLAIMS_PAYMENT: |
|||
strcpy(txData.amount, "0"); |
|||
strcpy(txData.from, aliceAddress); |
|||
strcpy(txData.to, bobContractAddress); |
|||
strcpy(txData.secretKey, getenv("ALICE_PK")); |
|||
|
|||
AliceSpendsBobPaymentInput input7; |
|||
|
|||
strcpy(input7.paymentId, argv[2]); |
|||
strcpy(input7.bobAddress, bobAddress); |
|||
strcpy(input7.amount, "1000000000000000000"); |
|||
strcpy(input7.tokenAddress, argv[3]); |
|||
strcpy(input7.bobCanClaimAfter, argv[4]); |
|||
strcpy(input7.aliceSecret, argv[5]); |
|||
|
|||
result = aliceSpendsBobPayment(input7, txData); |
|||
printf("%s\n", result); |
|||
free(result); |
|||
break; |
|||
case BOB_APPROVES_ERC20: |
|||
result = approveErc20( |
|||
"10000000000000000000", |
|||
"0xA7EF3f65714AE266414C9E58bB4bAa4E6FB82B41", |
|||
getenv("BOB_PK") |
|||
|
|||
); |
|||
printf("%s\n", result); |
|||
free(result); |
|||
break; |
|||
case BOB_ETH_BALANCE: |
|||
printf("%" PRIu64 "\n", getEthBalance(bobAddress)); |
|||
break; |
|||
case BOB_ERC20_BALANCE: |
|||
printf("%" PRIu64 "\n", getErc20Balance(bobAddress, tokenAddress)); |
|||
break; |
|||
case TX_RECEIPT: |
|||
printf("getTxReceipt\n"); |
|||
EthTxReceipt txReceipt; |
|||
txReceipt = getEthTxReceipt("0x82afa1b00f8a63e1a91430162e5cb2d4ebe915831ffd56e6e3227814913e23e6"); |
|||
printf("%" PRIu64 "\n", txReceipt.blockNumber); |
|||
printf("%s\n", txReceipt.blockHash); |
|||
break; |
|||
default: |
|||
return 1; |
|||
} |
|||
char *pubkey = getPubKeyFromPriv(getenv("BOB_PK")); |
|||
printf("pubkey: %s\n", pubkey); |
|||
free(pubkey); |
|||
|
|||
uint64_t satoshis = 100000000; |
|||
char weiBuffer[100]; |
|||
satoshisToWei(weiBuffer, satoshis); |
|||
printf("wei: %s\n", weiBuffer); |
|||
return 0; |
|||
} |
@ -0,0 +1,196 @@ |
|||
#include "etomiccurl.h" |
|||
#include <curl/curl.h> |
|||
#include <memory.h> |
|||
#include <stdlib.h> |
|||
#include "../../../includes/cJSON.h" |
|||
|
|||
static char *ethRpcUrl = ETOMIC_URL; |
|||
|
|||
struct string { |
|||
char *ptr; |
|||
size_t len; |
|||
}; |
|||
|
|||
void init_eth_string(struct string *s) { |
|||
s->len = 0; |
|||
s->ptr = malloc(s->len+1); |
|||
if (s->ptr == NULL) { |
|||
fprintf(stderr, "malloc() failed\n"); |
|||
exit(EXIT_FAILURE); |
|||
} |
|||
s->ptr[0] = '\0'; |
|||
} |
|||
|
|||
size_t writefunc(void *ptr, size_t size, size_t nmemb, struct string *s) |
|||
{ |
|||
size_t new_len = s->len + size*nmemb; |
|||
s->ptr = realloc(s->ptr, new_len+1); |
|||
if (s->ptr == NULL) { |
|||
fprintf(stderr, "realloc() failed\n"); |
|||
exit(EXIT_FAILURE); |
|||
} |
|||
memcpy(s->ptr+s->len, ptr, size*nmemb); |
|||
s->ptr[new_len] = '\0'; |
|||
s->len = new_len; |
|||
|
|||
return size*nmemb; |
|||
} |
|||
|
|||
char* sendRequest(char* request) |
|||
{ |
|||
CURL *curl; |
|||
CURLcode res; |
|||
struct curl_slist *headers = NULL; |
|||
curl = curl_easy_init(); |
|||
if (curl) { |
|||
struct string s; |
|||
init_eth_string(&s); |
|||
|
|||
headers = curl_slist_append(headers, "Accept: application/json"); |
|||
headers = curl_slist_append(headers, "Content-Type: application/json"); |
|||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); |
|||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST"); |
|||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); |
|||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); |
|||
curl_easy_setopt(curl, CURLOPT_URL, ethRpcUrl); |
|||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request); |
|||
/* Perform the request, res will get the return code */ |
|||
res = curl_easy_perform(curl); |
|||
/* Check for errors */ |
|||
if (res != CURLE_OK) { |
|||
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); |
|||
} |
|||
|
|||
/* always cleanup */ |
|||
curl_easy_cleanup(curl); |
|||
return s.ptr; |
|||
} else { |
|||
return NULL; |
|||
} |
|||
} |
|||
|
|||
char* sendRawTx(char* rawTx) |
|||
{ |
|||
char* string; |
|||
cJSON *request = cJSON_CreateObject(); |
|||
cJSON *params = cJSON_CreateArray(); |
|||
cJSON_AddItemToObject(request, "jsonrpc", cJSON_CreateString("2.0")); |
|||
cJSON_AddItemToObject(request, "method", cJSON_CreateString("eth_sendRawTransaction")); |
|||
cJSON_AddItemToArray(params, cJSON_CreateString(rawTx)); |
|||
cJSON_AddItemToObject(request, "params", params); |
|||
cJSON_AddItemToObject(request, "id", cJSON_CreateNumber(2)); |
|||
string = cJSON_PrintUnformatted(request); |
|||
char* requestResult = sendRequest(string); |
|||
cJSON *json = cJSON_Parse(requestResult); |
|||
cJSON_Delete(request); |
|||
char* tmp = cJSON_GetObjectItem(json, "result")->valuestring; |
|||
char* txId = (char*)malloc(strlen(tmp) + 1); |
|||
strcpy(txId, tmp); |
|||
cJSON_Delete(json); |
|||
free(requestResult); |
|||
free(string); |
|||
return txId; |
|||
} |
|||
|
|||
int getNonce(char* address) |
|||
{ |
|||
char* string; |
|||
cJSON *request = cJSON_CreateObject(); |
|||
cJSON *params = cJSON_CreateArray(); |
|||
cJSON_AddItemToObject(request, "jsonrpc", cJSON_CreateString("2.0")); |
|||
cJSON_AddItemToObject(request, "method", cJSON_CreateString("eth_getTransactionCount")); |
|||
cJSON_AddItemToArray(params, cJSON_CreateString(address)); |
|||
cJSON_AddItemToArray(params, cJSON_CreateString("pending")); |
|||
cJSON_AddItemToObject(request, "params", params); |
|||
cJSON_AddItemToObject(request, "id", cJSON_CreateNumber(2)); |
|||
string = cJSON_PrintUnformatted(request); |
|||
char* requestResult = sendRequest(string); |
|||
cJSON_Delete(request); |
|||
cJSON *json = cJSON_Parse(requestResult); |
|||
int nonce = (int)strtol(cJSON_GetObjectItem(json, "result")->valuestring, NULL, 0); |
|||
cJSON_Delete(json); |
|||
free(requestResult); |
|||
free(string); |
|||
return nonce; |
|||
} |
|||
|
|||
char* getEthBalanceRequest(char* address) |
|||
{ |
|||
char* string; |
|||
cJSON *request = cJSON_CreateObject(); |
|||
cJSON *params = cJSON_CreateArray(); |
|||
cJSON_AddItemToObject(request, "jsonrpc", cJSON_CreateString("2.0")); |
|||
cJSON_AddItemToObject(request, "method", cJSON_CreateString("eth_getBalance")); |
|||
cJSON_AddItemToArray(params, cJSON_CreateString(address)); |
|||
cJSON_AddItemToArray(params, cJSON_CreateString("latest")); |
|||
cJSON_AddItemToObject(request, "params", params); |
|||
cJSON_AddItemToObject(request, "id", cJSON_CreateNumber(2)); |
|||
string = cJSON_PrintUnformatted(request); |
|||
char* requestResult = sendRequest(string); |
|||
cJSON_Delete(request); |
|||
cJSON *json = cJSON_Parse(requestResult); |
|||
char* tmp = cJSON_GetObjectItem(json, "result")->valuestring; |
|||
char* balance = (char*)malloc(strlen(tmp) + 1); |
|||
strcpy(balance, tmp); |
|||
cJSON_Delete(json); |
|||
free(requestResult); |
|||
free(string); |
|||
return balance; |
|||
} |
|||
|
|||
char* ethCall(char* to, const char* data) |
|||
{ |
|||
char* string; |
|||
cJSON *request = cJSON_CreateObject(); |
|||
cJSON *params = cJSON_CreateArray(); |
|||
cJSON *txObject = cJSON_CreateObject(); |
|||
cJSON_AddItemToObject(request, "jsonrpc", cJSON_CreateString("2.0")); |
|||
cJSON_AddItemToObject(request, "method", cJSON_CreateString("eth_call")); |
|||
cJSON_AddStringToObject(txObject, "to", to); |
|||
cJSON_AddStringToObject(txObject, "data", data); |
|||
cJSON_AddItemToArray(params, txObject); |
|||
cJSON_AddItemToArray(params, cJSON_CreateString("latest")); |
|||
cJSON_AddItemToObject(request, "params", params); |
|||
cJSON_AddItemToObject(request, "id", cJSON_CreateNumber(2)); |
|||
string = cJSON_PrintUnformatted(request); |
|||
char* requestResult = sendRequest(string); |
|||
cJSON_Delete(request); |
|||
cJSON *json = cJSON_Parse(requestResult); |
|||
char* tmp = cJSON_GetObjectItem(json, "result")->valuestring; |
|||
char* result = (char*)malloc(strlen(tmp) + 1); |
|||
strcpy(result, tmp); |
|||
cJSON_Delete(json); |
|||
free(requestResult); |
|||
free(string); |
|||
return result; |
|||
} |
|||
|
|||
EthTxReceipt getEthTxReceipt(char *txId) |
|||
{ |
|||
EthTxReceipt result; |
|||
|
|||
char* string; |
|||
cJSON *request = cJSON_CreateObject(); |
|||
cJSON *params = cJSON_CreateArray(); |
|||
cJSON_AddItemToObject(request, "jsonrpc", cJSON_CreateString("2.0")); |
|||
cJSON_AddItemToObject(request, "method", cJSON_CreateString("eth_getTransactionReceipt")); |
|||
cJSON_AddItemToArray(params, cJSON_CreateString(txId)); |
|||
cJSON_AddItemToObject(request, "params", params); |
|||
cJSON_AddItemToObject(request, "id", cJSON_CreateNumber(2)); |
|||
string = cJSON_PrintUnformatted(request); |
|||
char *requestResult = sendRequest(string); |
|||
cJSON_Delete(request); |
|||
cJSON *json = cJSON_Parse(requestResult); |
|||
cJSON *tmp = cJSON_GetObjectItem(json, "result"); |
|||
if (is_cJSON_Null(tmp)) { |
|||
strcpy(result.blockHash, "0x0000000000000000000000000000000000000000000000000000000000000000"); |
|||
result.blockNumber = 0; |
|||
} else { |
|||
strcpy(result.blockHash, cJSON_GetObjectItem(tmp, "blockHash")->valuestring); |
|||
result.blockNumber = (uint64_t) strtol(cJSON_GetObjectItem(tmp, "blockNumber")->valuestring, NULL, 0); |
|||
} |
|||
cJSON_Delete(json); |
|||
free(requestResult); |
|||
free(string); |
|||
return result; |
|||
} |
@ -0,0 +1,28 @@ |
|||
#include <stdint.h> |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C"{ |
|||
#endif |
|||
|
|||
#define ETOMIC_TESTNET |
|||
#ifdef ETOMIC_TESTNET |
|||
#define ETOMIC_URL "https://ropsten.infura.io/y07GHxUyTgeN2mdfOonu"
|
|||
#else |
|||
#define ETOMIC_URL "https://mainnet.infura.io/y07GHxUyTgeN2mdfOonu"
|
|||
#endif |
|||
|
|||
typedef struct |
|||
{ |
|||
uint64_t blockNumber; |
|||
char blockHash[75]; |
|||
} EthTxReceipt; |
|||
|
|||
char* sendRawTx(char* rawTx); |
|||
char* ethCall(char* to, const char* data); |
|||
int getNonce(char* address); |
|||
char* getEthBalanceRequest(char* address); |
|||
EthTxReceipt getEthTxReceipt(char *txId); |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
@ -0,0 +1,375 @@ |
|||
//
|
|||
// Created by artem on 24.01.18.
|
|||
//
|
|||
#include "etomiclib.h" |
|||
#include "etomiccurl.h" |
|||
#include <iostream> |
|||
#include <cpp-ethereum/libethcore/Common.h> |
|||
#include <cpp-ethereum/libethcore/CommonJS.h> |
|||
#include <cpp-ethereum/libethcore/TransactionBase.h> |
|||
#include <inttypes.h> |
|||
|
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
|
|||
char* stringStreamToChar(std::stringstream& ss) |
|||
{ |
|||
const std::string tmp = ss.str(); |
|||
auto result = (char*)malloc(strlen(tmp.c_str()) + 1); |
|||
strcpy(result, tmp.c_str()); |
|||
return result; |
|||
} |
|||
|
|||
TransactionSkeleton txDataToSkeleton(BasicTxData txData) |
|||
{ |
|||
TransactionSkeleton tx; |
|||
tx.from = jsToAddress(txData.from); |
|||
tx.to = jsToAddress(txData.to); |
|||
tx.value = jsToU256(txData.amount); |
|||
tx.gas = 300000; |
|||
tx.gasPrice = ETOMIC_GASMULT * exp10<9>(); |
|||
tx.nonce = getNonce(txData.from); |
|||
return tx; |
|||
} |
|||
|
|||
char* signTx(TransactionSkeleton& tx, char* secret) |
|||
{ |
|||
Secret& secretKey = *(new Secret(secret)); |
|||
auto baseTx = new TransactionBase(tx, secretKey); |
|||
RLPStream& rlpStream = *(new RLPStream()); |
|||
baseTx->streamRLP(rlpStream); |
|||
std::stringstream& ss = *(new std::stringstream); |
|||
ss << rlpStream.out(); |
|||
return stringStreamToChar(ss); |
|||
} |
|||
|
|||
char* approveErc20(char* amount, char* from, char* secret) |
|||
{ |
|||
TransactionSkeleton tx; |
|||
tx.from = jsToAddress(from); |
|||
tx.to = jsToAddress("0xc0eb7AeD740E1796992A08962c15661bDEB58003"); |
|||
tx.value = 0; // exp10<18>();
|
|||
tx.gas = 300000; |
|||
tx.gasPrice = ETOMIC_GASMULT * exp10<9>(); |
|||
tx.nonce = getNonce(from); |
|||
std::stringstream ss; |
|||
ss << "0x095ea7b3" |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress("0xe1D4236C5774D35Dc47dcc2E5E0CcFc463A3289c")) |
|||
<< toHex(toBigEndian(jsToU256(amount))); |
|||
tx.data = jsToBytes(ss.str()); |
|||
char* rawTx = signTx(tx, secret); |
|||
char* result = sendRawTx(rawTx); |
|||
free(rawTx); |
|||
return result; |
|||
} |
|||
|
|||
char* aliceSendsEthPayment(AliceSendsEthPaymentInput input, BasicTxData txData) |
|||
{ |
|||
TransactionSkeleton tx = txDataToSkeleton(txData); |
|||
std::stringstream ss; |
|||
ss << "0x47c7b6e2" |
|||
<< toHex(jsToBytes(input.dealId)) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.bobAddress)) |
|||
<< toHex(jsToBytes(input.aliceHash)) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToBytes(input.bobHash)) |
|||
<< "000000000000000000000000"; |
|||
tx.data = jsToBytes(ss.str()); |
|||
char* rawTx = signTx(tx, txData.secretKey); |
|||
char* result = sendRawTx(rawTx); |
|||
free(rawTx); |
|||
return result; |
|||
} |
|||
|
|||
char* aliceSendsErc20Payment(AliceSendsErc20PaymentInput input, BasicTxData txData) |
|||
{ |
|||
TransactionSkeleton tx = txDataToSkeleton(txData); |
|||
std::stringstream ss; |
|||
ss << "0x184db3bf" |
|||
<< toHex(jsToBytes(input.dealId)) |
|||
<< toHex(toBigEndian(jsToU256(input.amount))) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.bobAddress)) |
|||
<< toHex(jsToBytes(input.aliceHash)) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToBytes(input.bobHash)) |
|||
<< "000000000000000000000000" |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.tokenAddress)); |
|||
tx.data = jsToBytes(ss.str()); |
|||
char* rawTx = signTx(tx, txData.secretKey); |
|||
char* result = sendRawTx(rawTx); |
|||
free(rawTx); |
|||
return result; |
|||
} |
|||
|
|||
char* aliceReclaimsAlicePayment(AliceReclaimsAlicePaymentInput input, BasicTxData txData) |
|||
{ |
|||
TransactionSkeleton tx = txDataToSkeleton(txData); |
|||
std::stringstream ss; |
|||
ss << "0x8b9a167a" |
|||
<< toHex(jsToBytes(input.dealId)) |
|||
<< toHex(toBigEndian(jsToU256(input.amount))) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.tokenAddress)) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.bobAddress)) |
|||
<< toHex(jsToBytes(input.aliceHash)) |
|||
<< "000000000000000000000000" |
|||
<< "00000000000000000000000000000000000000000000000000000000000000c0" |
|||
<< "0000000000000000000000000000000000000000000000000000000000000020" |
|||
<< toHex(jsToBytes(input.bobSecret)); |
|||
tx.data = jsToBytes(ss.str()); |
|||
char* rawTx = signTx(tx, txData.secretKey); |
|||
char* result = sendRawTx(rawTx); |
|||
free(rawTx); |
|||
return result; |
|||
} |
|||
|
|||
char* bobSpendsAlicePayment(BobSpendsAlicePaymentInput input, BasicTxData txData) |
|||
{ |
|||
TransactionSkeleton tx = txDataToSkeleton(txData); |
|||
std::stringstream ss; |
|||
ss << "0x392ec66b" |
|||
<< toHex(jsToBytes(input.dealId)) |
|||
<< toHex(toBigEndian(jsToU256(input.amount))) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.tokenAddress)) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.aliceAddress)) |
|||
<< toHex(jsToBytes(input.bobHash)) |
|||
<< "000000000000000000000000" |
|||
<< "00000000000000000000000000000000000000000000000000000000000000c0" |
|||
<< "0000000000000000000000000000000000000000000000000000000000000020" |
|||
<< toHex(jsToBytes(input.aliceSecret)); |
|||
tx.data = jsToBytes(ss.str()); |
|||
char* rawTx = signTx(tx, txData.secretKey); |
|||
char* result = sendRawTx(rawTx); |
|||
free(rawTx); |
|||
return result; |
|||
} |
|||
|
|||
char* bobSendsEthDeposit(BobSendsEthDepositInput input, BasicTxData txData) |
|||
{ |
|||
TransactionSkeleton tx = txDataToSkeleton(txData); |
|||
std::stringstream ss; |
|||
ss << "0xc2c5143f" |
|||
<< toHex(jsToBytes(input.depositId)) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.aliceAddress)) |
|||
<< toHex(jsToBytes(input.bobHash)) |
|||
<< "000000000000000000000000"; |
|||
tx.data = jsToBytes(ss.str()); |
|||
char* rawTx = signTx(tx, txData.secretKey); |
|||
char* result = sendRawTx(rawTx); |
|||
free(rawTx); |
|||
return result; |
|||
} |
|||
|
|||
char* bobSendsErc20Deposit(BobSendsErc20DepositInput input, BasicTxData txData) |
|||
{ |
|||
TransactionSkeleton tx = txDataToSkeleton(txData); |
|||
std::stringstream ss; |
|||
ss << "0xce8bbe4b" |
|||
<< toHex(jsToBytes(input.depositId)) |
|||
<< toHex(toBigEndian(jsToU256(input.amount))) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.aliceAddress)) |
|||
<< toHex(jsToBytes(input.bobHash)) |
|||
<< "000000000000000000000000" |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.tokenAddress)); |
|||
tx.data = jsToBytes(ss.str()); |
|||
char* rawTx = signTx(tx, txData.secretKey); |
|||
char* result = sendRawTx(rawTx); |
|||
free(rawTx); |
|||
return result; |
|||
} |
|||
|
|||
char* bobRefundsDeposit(BobRefundsDepositInput input, BasicTxData txData) |
|||
{ |
|||
TransactionSkeleton tx = txDataToSkeleton(txData); |
|||
std::stringstream ss; |
|||
ss << "0x1dbe6508" |
|||
<< toHex(jsToBytes(input.depositId)) |
|||
<< toHex(toBigEndian(jsToU256(input.amount))) |
|||
<< toHex(toBigEndian(jsToU256(input.aliceCanClaimAfter))) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.aliceAddress)) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.tokenAddress)) |
|||
<< "00000000000000000000000000000000000000000000000000000000000000c0" |
|||
<< "0000000000000000000000000000000000000000000000000000000000000020" |
|||
<< toHex(jsToBytes(input.bobSecret)); |
|||
tx.data = jsToBytes(ss.str()); |
|||
char* rawTx = signTx(tx, txData.secretKey); |
|||
char* result = sendRawTx(rawTx); |
|||
free(rawTx); |
|||
return result; |
|||
} |
|||
|
|||
char* aliceClaimsBobDeposit(AliceClaimsBobDepositInput input, BasicTxData txData) |
|||
{ |
|||
TransactionSkeleton tx = txDataToSkeleton(txData); |
|||
std::stringstream ss; |
|||
ss << "0x960173b5" |
|||
<< toHex(jsToBytes(input.depositId)) |
|||
<< toHex(toBigEndian(jsToU256(input.amount))) |
|||
<< toHex(toBigEndian(jsToU256(input.aliceCanClaimAfter))) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.bobAddress)) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.tokenAddress)) |
|||
<< toHex(jsToBytes(input.bobHash)) |
|||
<< "000000000000000000000000"; |
|||
tx.data = jsToBytes(ss.str()); |
|||
char* rawTx = signTx(tx, txData.secretKey); |
|||
char* result = sendRawTx(rawTx); |
|||
free(rawTx); |
|||
return result; |
|||
} |
|||
|
|||
char* bobSendsEthPayment(BobSendsEthPaymentInput input, BasicTxData txData) |
|||
{ |
|||
TransactionSkeleton tx = txDataToSkeleton(txData); |
|||
std::stringstream ss; |
|||
ss << "0xcf36fe8e" |
|||
<< toHex(jsToBytes(input.paymentId)) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.aliceAddress)) |
|||
<< toHex(jsToBytes(input.aliceHash)) |
|||
<< "000000000000000000000000"; |
|||
tx.data = jsToBytes(ss.str()); |
|||
char* rawTx = signTx(tx, txData.secretKey); |
|||
char* result = sendRawTx(rawTx); |
|||
free(rawTx); |
|||
return result; |
|||
} |
|||
|
|||
char* bobSendsErc20Payment(BobSendsErc20PaymentInput input, BasicTxData txData) |
|||
{ |
|||
TransactionSkeleton tx = txDataToSkeleton(txData); |
|||
std::stringstream ss; |
|||
ss << "0x34f64dfd" |
|||
<< toHex(jsToBytes(input.paymentId)) |
|||
<< toHex(toBigEndian(jsToU256(input.amount))) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.aliceAddress)) |
|||
<< toHex(jsToBytes(input.aliceHash)) |
|||
<< "000000000000000000000000" |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.tokenAddress)); |
|||
tx.data = jsToBytes(ss.str()); |
|||
char* rawTx = signTx(tx, txData.secretKey); |
|||
char* result = sendRawTx(rawTx); |
|||
free(rawTx); |
|||
return result; |
|||
} |
|||
|
|||
char* bobReclaimsBobPayment(BobReclaimsBobPaymentInput input, BasicTxData txData) |
|||
{ |
|||
TransactionSkeleton tx = txDataToSkeleton(txData); |
|||
std::stringstream ss; |
|||
ss << "0xb7cc2312" |
|||
<< toHex(jsToBytes(input.paymentId)) |
|||
<< toHex(toBigEndian(jsToU256(input.amount))) |
|||
<< toHex(toBigEndian(jsToU256(input.bobCanClaimAfter))) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.aliceAddress)) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.tokenAddress)) |
|||
<< toHex(jsToBytes(input.aliceHash)) |
|||
<< "000000000000000000000000"; |
|||
tx.data = jsToBytes(ss.str()); |
|||
char* rawTx = signTx(tx, txData.secretKey); |
|||
char* result = sendRawTx(rawTx); |
|||
free(rawTx); |
|||
return result; |
|||
} |
|||
|
|||
char* aliceSpendsBobPayment(AliceSpendsBobPaymentInput input, BasicTxData txData) |
|||
{ |
|||
TransactionSkeleton tx = txDataToSkeleton(txData); |
|||
std::stringstream ss; |
|||
ss << "0x97004255" |
|||
<< toHex(jsToBytes(input.paymentId)) |
|||
<< toHex(toBigEndian(jsToU256(input.amount))) |
|||
<< toHex(toBigEndian(jsToU256(input.bobCanClaimAfter))) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.bobAddress)) |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(input.tokenAddress)) |
|||
<< "00000000000000000000000000000000000000000000000000000000000000c0" |
|||
<< "0000000000000000000000000000000000000000000000000000000000000020" |
|||
<< toHex(jsToBytes(input.aliceSecret)); |
|||
tx.data = jsToBytes(ss.str()); |
|||
char* rawTx = signTx(tx, txData.secretKey); |
|||
char* result = sendRawTx(rawTx); |
|||
free(rawTx); |
|||
return result; |
|||
} |
|||
|
|||
char* privKey2Addr(char* privKey) |
|||
{ |
|||
Secret& secretKey = *(new Secret(privKey)); |
|||
std::stringstream& ss = *(new std::stringstream); |
|||
ss << "0x" << toAddress(secretKey); |
|||
return stringStreamToChar(ss); |
|||
}; |
|||
|
|||
char* pubKey2Addr(char* pubKey) |
|||
{ |
|||
Public& publicKey = *(new Public(pubKey)); |
|||
std::stringstream& ss = *(new std::stringstream); |
|||
ss << "0x" << toAddress(publicKey); |
|||
return stringStreamToChar(ss); |
|||
}; |
|||
|
|||
char* getPubKeyFromPriv(char* privKey) |
|||
{ |
|||
Public publicKey = toPublic(*(new Secret(privKey))); |
|||
std::stringstream& ss = *(new std::stringstream); |
|||
ss << "0x" << publicKey; |
|||
return stringStreamToChar(ss); |
|||
} |
|||
|
|||
uint64_t getEthBalance(char* address) |
|||
{ |
|||
char* hexBalance = getEthBalanceRequest(address); |
|||
// convert wei to satoshi
|
|||
u256 balance = jsToU256(hexBalance) / exp10<10>(); |
|||
free(hexBalance); |
|||
return static_cast<uint64_t>(balance); |
|||
} |
|||
|
|||
uint64_t getErc20Balance(char* address, char* tokenAddress) |
|||
{ |
|||
std::stringstream ss; |
|||
ss << "0x70a08231" |
|||
<< "000000000000000000000000" |
|||
<< toHex(jsToAddress(address)); |
|||
std::stringstream& resultStream = *(new std::stringstream); |
|||
char* hexBalance = ethCall(tokenAddress, ss.str().c_str()); |
|||
// convert wei to satoshi
|
|||
u256 balance = jsToU256(hexBalance) / exp10<10>(); |
|||
free(hexBalance); |
|||
return static_cast<uint64_t>(balance); |
|||
} |
|||
|
|||
void uint8arrayToHex(char *dest, uint8_t *input, int len) |
|||
{ |
|||
strcpy(dest, "0x"); |
|||
for (int i = 0; i < len; i++) |
|||
{ |
|||
sprintf(dest + (i + 1) * 2, "%02x", input[i]); |
|||
} |
|||
dest[(len + 1) * 2] = '\0'; |
|||
} |
|||
|
|||
void satoshisToWei(char *dest, uint64_t input) |
|||
{ |
|||
sprintf(dest, "%" PRIu64, input); |
|||
strcat(dest, "0000000000"); |
|||
} |
@ -0,0 +1,151 @@ |
|||
//
|
|||
// Created by artem on 24.01.18.
|
|||
//
|
|||
#include <stdint.h> |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
#define ETOMIC_TESTNET |
|||
#ifdef ETOMIC_TESTNET |
|||
#define ETOMIC_ALICECONTRACT "0xe1D4236C5774D35Dc47dcc2E5E0CcFc463A3289c" |
|||
#define ETOMIC_BOBCONTRACT "0x9387Fd3a016bB0205e4e131Dde886B9d2BC000A2" |
|||
#define ETOMIC_GASMULT 100 |
|||
#else |
|||
#define ETOMIC_ALICECONTRACT "0x9bC5418CEdED51dB08467fc4b62F32C5D9EBdA55" |
|||
#define ETOMIC_BOBCONTRACT "0xB1Ad803ea4F57401639c123000C75F5B66E4D123" |
|||
#define ETOMIC_GASMULT 4 |
|||
#endif |
|||
|
|||
#define ETOMIC_SATOSHICAT "0000000000" |
|||
|
|||
typedef struct { |
|||
char from[65]; |
|||
char to[65]; |
|||
char amount[100]; |
|||
char secretKey[70]; |
|||
} BasicTxData; |
|||
|
|||
typedef struct { |
|||
char dealId[70]; |
|||
char bobAddress[65]; |
|||
char aliceHash[65]; |
|||
char bobHash[65]; |
|||
} AliceSendsEthPaymentInput; |
|||
|
|||
typedef struct { |
|||
char dealId[70]; |
|||
char amount[100]; |
|||
char tokenAddress[65]; |
|||
char bobAddress[65]; |
|||
char aliceHash[65]; |
|||
char bobHash[65]; |
|||
} AliceSendsErc20PaymentInput; |
|||
|
|||
typedef struct { |
|||
char dealId[70]; |
|||
char amount[100]; |
|||
char tokenAddress[65]; |
|||
char bobAddress[65]; |
|||
char aliceHash[65]; |
|||
char bobSecret[70]; |
|||
} AliceReclaimsAlicePaymentInput; |
|||
|
|||
typedef struct { |
|||
char dealId[70]; |
|||
char amount[100]; |
|||
char tokenAddress[65]; |
|||
char aliceAddress[65]; |
|||
char aliceSecret[70]; |
|||
char bobHash[65]; |
|||
} BobSpendsAlicePaymentInput; |
|||
|
|||
typedef struct { |
|||
char depositId[70]; |
|||
char aliceAddress[65]; |
|||
char bobHash[65]; |
|||
} BobSendsEthDepositInput; |
|||
|
|||
typedef struct { |
|||
char depositId[70]; |
|||
char amount[100]; |
|||
char tokenAddress[65]; |
|||
char aliceAddress[65]; |
|||
char bobHash[65]; |
|||
} BobSendsErc20DepositInput; |
|||
|
|||
typedef struct { |
|||
char depositId[70]; |
|||
char amount[100]; |
|||
char tokenAddress[65]; |
|||
char aliceAddress[65]; |
|||
char bobSecret[70]; |
|||
char aliceCanClaimAfter[100]; |
|||
} BobRefundsDepositInput; |
|||
|
|||
typedef struct { |
|||
char depositId[70]; |
|||
char amount[100]; |
|||
char tokenAddress[65]; |
|||
char bobAddress[65]; |
|||
char bobHash[65]; |
|||
char aliceCanClaimAfter[100]; |
|||
} AliceClaimsBobDepositInput; |
|||
|
|||
typedef struct { |
|||
char paymentId[70]; |
|||
char aliceAddress[65]; |
|||
char aliceHash[65]; |
|||
} BobSendsEthPaymentInput; |
|||
|
|||
typedef struct { |
|||
char paymentId[70]; |
|||
char amount[100]; |
|||
char tokenAddress[65]; |
|||
char aliceAddress[65]; |
|||
char aliceHash[65]; |
|||
} BobSendsErc20PaymentInput; |
|||
|
|||
typedef struct { |
|||
char paymentId[70]; |
|||
char amount[100]; |
|||
char tokenAddress[65]; |
|||
char aliceAddress[65]; |
|||
char aliceHash[65]; |
|||
char bobCanClaimAfter[100]; |
|||
} BobReclaimsBobPaymentInput; |
|||
|
|||
typedef struct { |
|||
char paymentId[70]; |
|||
char amount[100]; |
|||
char tokenAddress[65]; |
|||
char aliceSecret[70]; |
|||
char bobAddress[65]; |
|||
char bobCanClaimAfter[100]; |
|||
} AliceSpendsBobPaymentInput; |
|||
|
|||
char* approveErc20(char amount[100], char* from, char* secret); |
|||
char* aliceSendsEthPayment(AliceSendsEthPaymentInput input, BasicTxData txData); |
|||
char* aliceSendsErc20Payment(AliceSendsErc20PaymentInput input, BasicTxData txData); |
|||
char* aliceReclaimsAlicePayment(AliceReclaimsAlicePaymentInput input, BasicTxData txData); |
|||
char* bobSpendsAlicePayment(BobSpendsAlicePaymentInput input, BasicTxData txData); |
|||
char* bobSendsEthDeposit(BobSendsEthDepositInput input, BasicTxData txData); |
|||
char* bobSendsErc20Deposit(BobSendsErc20DepositInput input, BasicTxData txData); |
|||
char* bobRefundsDeposit(BobRefundsDepositInput input, BasicTxData txData); |
|||
char* aliceClaimsBobDeposit(AliceClaimsBobDepositInput input, BasicTxData txData); |
|||
char* bobSendsEthPayment(BobSendsEthPaymentInput input, BasicTxData txData); |
|||
char* bobSendsErc20Payment(BobSendsErc20PaymentInput input, BasicTxData txData); |
|||
char* bobReclaimsBobPayment(BobReclaimsBobPaymentInput input, BasicTxData txData); |
|||
char* aliceSpendsBobPayment(AliceSpendsBobPaymentInput input, BasicTxData txData); |
|||
char* privKey2Addr(char* privKey); |
|||
char* pubKey2Addr(char* pubKey); |
|||
char* getPubKeyFromPriv(char* privKey); |
|||
uint64_t getEthBalance(char* address); |
|||
uint64_t getErc20Balance(char* address, char tokenAddress[65]); |
|||
void uint8arrayToHex(char *dest, uint8_t *input, int len); |
|||
void satoshisToWei(char *dest, uint64_t input); |
|||
// Your prototype or Definition
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
@ -0,0 +1,3 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"timelock\",\"coin\":\"KMD\",\"duration\":1000,\"amount\":1}" |
@ -0,0 +1,3 @@ |
|||
#!/bin/bash |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"unlockedspend\",\"coin\":\"KMD\",\"txid\":\"e858e382a816b4cab22e3fd3e29901c7ef497cd1fdad7683314cc9187eca34fd\"}" |
@ -0,0 +1,5 @@ |
|||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) |
|||
file(GLOB sources "src/secp256k1.c") |
|||
file(GLOB headers "src/*.h") |
|||
add_definitions(-DHAVE_CONFIG_H) |
|||
add_library(libsecp256k1 ${sources} ${headers}) |
@ -0,0 +1,15 @@ |
|||
@echo off |
|||
rem Sample script to build cpp-ethereum libs by Decker (don't fully tested yet) |
|||
rem Make sure cpp-ethereum is empty, before run. |
|||
|
|||
git submodule init |
|||
git submodule update --init --recursive |
|||
cd cpp-ethereum |
|||
rem git submodule init |
|||
rem git submodule update --init |
|||
call scripts\install_deps.bat |
|||
mkdir build_win64_release |
|||
cd build_win64_release |
|||
cmake .. -G "Visual Studio 14 2015 Win64" |
|||
cmake --build . --config Release |
|||
rem cmake --build . |
Loading…
Reference in new issue