Browse Source

Merge pull request #621 from jl777/dev

Dev
patch-1
jl777 7 years ago
committed by GitHub
parent
commit
bc4dbdded9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      .gitignore
  2. 4
      .gitmodules
  3. 15
      CMakeLists.txt
  4. 12
      README.md
  5. 18
      cmake/Hunter/config.cmake
  6. 529
      cmake/HunterGate.cmake
  7. 4
      cmake/toolchain.cmake
  8. 1
      cpp-ethereum
  9. 4
      crypto777/CMakeLists.txt
  10. 1
      crypto777/OS_portable.h
  11. 4
      crypto777/jpeg/CMakeLists.txt
  12. 3
      etomic_build/autoprice
  13. 3
      etomic_build/buy
  14. 5
      etomic_build/client
  15. 3
      etomic_build/coins
  16. 5
      etomic_build/enable
  17. 3
      etomic_build/orderbook
  18. 1
      etomic_build/passphrase
  19. 5
      etomic_build/run
  20. 4
      etomic_build/setpassphrase
  21. 3
      etomic_build/stop
  22. 2
      etomic_build/userpass
  23. 11
      iguana/Readme.md
  24. 1
      iguana/coins/ninja_7776
  25. 7
      iguana/exchanges/CMakeLists.txt
  26. 46
      iguana/exchanges/LP_bitcoin.c
  27. 4
      iguana/exchanges/LP_coins.c
  28. 45
      iguana/exchanges/LP_commands.c
  29. 406
      iguana/exchanges/LP_etomic.c
  30. 15
      iguana/exchanges/LP_include.h
  31. 112
      iguana/exchanges/LP_instantdex.c
  32. 10
      iguana/exchanges/LP_mmjson.c
  33. 58
      iguana/exchanges/LP_nativeDEX.c
  34. 80
      iguana/exchanges/LP_network.c
  35. 138
      iguana/exchanges/LP_ordermatch.c
  36. 4
      iguana/exchanges/LP_peers.c
  37. 7
      iguana/exchanges/LP_portfolio.c
  38. 10
      iguana/exchanges/LP_prices.c
  39. 38
      iguana/exchanges/LP_privkey.c
  40. 197
      iguana/exchanges/LP_remember.c
  41. 9
      iguana/exchanges/LP_rpc.c
  42. 17
      iguana/exchanges/LP_secp.c
  43. 29
      iguana/exchanges/LP_signatures.c
  44. 194
      iguana/exchanges/LP_swap.c
  45. 300
      iguana/exchanges/LP_transaction.c
  46. 6
      iguana/exchanges/LP_utxo.c
  47. 2
      iguana/exchanges/coins
  48. 10
      iguana/exchanges/etomicswap/CMakeLists.txt
  49. 106
      iguana/exchanges/etomicswap/alice.c
  50. 218
      iguana/exchanges/etomicswap/bob.c
  51. 196
      iguana/exchanges/etomicswap/etomiccurl.c
  52. 28
      iguana/exchanges/etomicswap/etomiccurl.h
  53. 375
      iguana/exchanges/etomicswap/etomiclib.cpp
  54. 151
      iguana/exchanges/etomicswap/etomiclib.h
  55. 1
      iguana/exchanges/mm.c
  56. 13
      iguana/exchanges/prices/autoprice
  57. 3
      iguana/exchanges/timelock
  58. 3
      iguana/exchanges/unlockedspend
  59. 2
      iguana/iguana_notary.c
  60. 4
      iguana/m_LP_StaticNanoMsg
  61. 2
      iguana/m_mm
  62. 2
      iguana/m_mm_StaticNanoMsg
  63. 1
      iguana/m_splitfund
  64. 2
      iguana/m_unix
  65. 1
      iguana/mini-gmp.c
  66. 5
      iguana/secp256k1/CMakeLists.txt
  67. 1
      iguana/secp256k1/include/secp256k1_recovery.h
  68. 8
      marketmaker.vcxproj
  69. 4
      marketmaker_build_32_64.cmd
  70. 15
      marketmaker_build_cpp-ethereum.cmd

5
.gitignore

@ -53,7 +53,6 @@ iguana/help.json
iguana/autoAPI.md iguana/autoAPI.md
iguana/basilisk.o-2ad8cb38 iguana/basilisk.o-2ad8cb38
=======
*.pbxproj *.pbxproj
iguana/tmp/.tmpmarker iguana/tmp/.tmpmarker
@ -255,4 +254,8 @@ iguana/DB/UNSPENTS/.tmpmarker
iguana/DB/instantdex_RQ4z6KrMZeEnCSCsChv1ZoR9ExQitHjbpg_append.json iguana/DB/instantdex_RQ4z6KrMZeEnCSCsChv1ZoR9ExQitHjbpg_append.json
iguana/DB/instantdex_RQ4z6KrMZeEnCSCsChv1ZoR9ExQitHjbpg.json iguana/DB/instantdex_RQ4z6KrMZeEnCSCsChv1ZoR9ExQitHjbpg.json
build
.idea
Release/* Release/*

4
.gitmodules

@ -0,0 +1,4 @@
[submodule "cpp-ethereum"]
path = cpp-ethereum
url = https://github.com/artemii235/cpp-ethereum.git
branch = develop

15
CMakeLists.txt

@ -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)

12
README.md

@ -255,3 +255,15 @@ Execute the OSX deploy script:
./osx_deploy.sh ./osx_deploy.sh
``` ```
The iguana binary and its linked libraries are in ```$HOME/tmp/iguana```. The iguana binary and its linked libraries are in ```$HOME/tmp/iguana```.
# Cmake build of marketmaker with linked etomic lib for ETH/ERC20 atomic swaps:
0. `make sure g++-7 ln to /usr/bin/g++`
1. `cd ~/SuperNET`
2. `git checkout dev`
3. `git submodule update --init --recursive`
4. `mkdir build`
5. `cd build`
6. `cmake ..`
7. `cmake --build . --target marketmaker`
8. `cd build/iguana/exchanges`
9. `./marketmaker`

18
cmake/Hunter/config.cmake

@ -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
)

529
cmake/HunterGate.cmake

@ -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()

4
cmake/toolchain.cmake

@ -0,0 +1,4 @@
# Require C++11.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS Off)

1
cpp-ethereum

@ -0,0 +1 @@
Subproject commit 633c62c08bc73c7c3935c948a8d6c656a3659976

4
crypto777/CMakeLists.txt

@ -0,0 +1,4 @@
file(GLOB sources "*.c")
file(GLOB headers "*.h")
add_library(libcrypto777 ${sources} ${headers})
target_link_libraries(libcrypto777 PUBLIC curl)

1
crypto777/OS_portable.h

@ -31,6 +31,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#define HAVE_STRUCT_TIMESPEC #define HAVE_STRUCT_TIMESPEC
#include <ctype.h> #include <ctype.h>
#include <fcntl.h> #include <fcntl.h>

4
crypto777/jpeg/CMakeLists.txt

@ -0,0 +1,4 @@
file(GLOB sources "*.c")
file(GLOB headers "*.h")
add_library(libjpeg ${sources} ${headers})
target_sources(libjpeg PRIVATE "unix/jmemname.c")

3
etomic_build/autoprice

@ -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\"}"

3
etomic_build/buy

@ -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}"

5
etomic_build/client

@ -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}" &

3
etomic_build/coins

File diff suppressed because one or more lines are too long

5
etomic_build/enable

@ -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\"}"

3
etomic_build/orderbook

@ -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\"}"

1
etomic_build/passphrase

@ -0,0 +1 @@
export passphrase="<put a very strong passphrase here>"

5
etomic_build/run

@ -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}" &

4
etomic_build/setpassphrase

@ -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\"}"

3
etomic_build/stop

@ -0,0 +1,3 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"stop\"}"

2
etomic_build/userpass

@ -0,0 +1,2 @@
#export userpass="<put the userpass value from the first API call here>"
export userpass="c3d8c2a364b7d18c1f9d7321d017b92e9f9c791e4f5c741214fefdea8a071256"

11
iguana/Readme.md

@ -191,3 +191,14 @@ struct iguana_account // 12 bytes
uint64_t balance; uint32_t lastunspentind; uint64_t balance; uint32_t lastunspentind;
} __attribute__((packed)); // pkind } __attribute__((packed)); // pkind
# Cmake build of marketmaker with linked etomic lib for ETH/ERC20 atomic swaps:
1. Clone this repository.
1. `git checkout etomic`
1. `git submodule update --init --recursive`
1. `mkdir build`
1. `cd build`
1. `cmake ..`
1. `cmake --build . --target marketmaker`
1. `cd exchanges/iguana`
1. `export BOB_PK=YOUR_PRIVATE_KEY`
1. `./marketmaker`

1
iguana/coins/ninja_7776

@ -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\"}"

7
iguana/exchanges/CMakeLists.txt

@ -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)

46
iguana/exchanges/LP_bitcoin.c

@ -118,6 +118,7 @@ static struct bitcoin_opcode { UT_hash_handle hh; uint8_t opcode,flags,stackitem
#define IGUANA_OP_SWAP 0x7c #define IGUANA_OP_SWAP 0x7c
#define IGUANA_OP_TUCK 0x7d #define IGUANA_OP_TUCK 0x7d
#define IGUANA_OP_SIZE 0x82
#define IGUANA_OP_EQUAL 0x87 #define IGUANA_OP_EQUAL 0x87
#define IGUANA_OP_EQUALVERIFY 0x88 #define IGUANA_OP_EQUALVERIFY 0x88
@ -1911,6 +1912,10 @@ int32_t bitcoin_p2shspend(uint8_t *script,int32_t n,uint8_t rmd160[20])
int32_t bitcoin_secret160verify(uint8_t *script,int32_t n,uint8_t secret160[20]) int32_t bitcoin_secret160verify(uint8_t *script,int32_t n,uint8_t secret160[20])
{ {
script[n++] = IGUANA_OP_SIZE; // add SIZE 32 EQUALVERIFY
script[n++] = 1;
script[n++] = 32;
script[n++] = SCRIPT_OP_EQUALVERIFY;
script[n++] = SCRIPT_OP_HASH160; script[n++] = SCRIPT_OP_HASH160;
script[n++] = 0x14; script[n++] = 0x14;
memcpy(&script[n],secret160,0x14); memcpy(&script[n],secret160,0x14);
@ -2052,11 +2057,14 @@ bits256 bits256_calcaddrhash(char *symbol,uint8_t *serialized,int32_t len)
int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr) int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr)
{ {
bits256 hash; uint8_t *buf,_buf[26],data5[128],rmd21[21]; char prefixaddr[64],hrp[64]; int32_t len,len5,offset; bits256 hash; uint8_t *buf,_buf[26],data5[128],rmd21[21]; char prefixaddr[64],hrp[64]; int32_t len,len5,offset;
*addrtypep = 0;
memset(rmd160,0,20);
if ( coinaddr == 0 || coinaddr[0] == 0 ) if ( coinaddr == 0 || coinaddr[0] == 0 )
{
*addrtypep = 0;
memset(rmd160,0,20);
return(0); return(0);
if ( coinaddr[0] == '0' && coinaddr[1] == 'x' && is_hexstr(coinaddr+2,0) == 40 )
{
decode_hex(rmd160,20,coinaddr+2); // not rmd160 hash but hopefully close enough;
return(20);
} }
if ( strcmp(symbol,"BCH") == 0 )//&& strlen(coinaddr) == 42 ) if ( strcmp(symbol,"BCH") == 0 )//&& strlen(coinaddr) == 42 )
{ {
@ -2110,7 +2118,37 @@ int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_
char *bitcoin_address(char *symbol,char *coinaddr,uint8_t taddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len) char *bitcoin_address(char *symbol,char *coinaddr,uint8_t taddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len)
{ {
int32_t offset,i,len5; char prefixed[64]; uint8_t data[64],data5[64]; bits256 hash; static void *ctx;
int32_t offset,i,len5; char prefixed[64]; uint8_t data[64],data5[64],bigpubkey[65]; bits256 hash; struct iguana_info *coin;
#ifndef NOTETOMIC
if ( (coin= LP_coinfind(symbol)) != 0 && coin->etomic[0] != 0 )
{
if ( len == 20 )
{
strcpy(coinaddr,"0x");
init_hexbytes_noT(coinaddr+2,pubkey_or_rmd160,20);
return(coinaddr);
}
else if ( len == 33 || len == 65 )
{
if ( len == 33 )
{
if ( ctx == 0 )
ctx = bitcoin_ctx();
bitcoin_expandcompressed(ctx,bigpubkey,pubkey_or_rmd160);
LP_etomic_pub2addr(coinaddr,bigpubkey+1);
/*for (i=0; i<33; i++)
printf("%02x",pubkey_or_rmd160[i]);
printf(" compressed -> ");
for (i=0; i<65; i++)
printf("%02x",bigpubkey[i]);
printf(" -> %s\n",coinaddr);*/
}
else LP_etomic_pub2addr(coinaddr,pubkey_or_rmd160+1);
return(coinaddr);
}
}
#endif
coinaddr[0] = 0; coinaddr[0] = 0;
offset = 1 + (taddr != 0); offset = 1 + (taddr != 0);
if ( len != 20 ) if ( len != 20 )

4
iguana/exchanges/LP_coins.c

@ -275,8 +275,8 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif)
struct iguana_info *LP_conflicts_find(struct iguana_info *refcoin) struct iguana_info *LP_conflicts_find(struct iguana_info *refcoin)
{ {
struct iguana_info *coin=0,*tmp; struct iguana_info *coin=0,*tmp; int32_t n;
if ( refcoin != 0 ) if ( refcoin != 0 && (n= (int32_t)strlen(refcoin->serverport)) > 3 && strcmp(":80",&refcoin->serverport[n-3]) != 0 )
{ {
HASH_ITER(hh,LP_coins,coin,tmp) HASH_ITER(hh,LP_coins,coin,tmp)
{ {

45
iguana/exchanges/LP_commands.c

@ -163,6 +163,8 @@ bot_pause(botid)\n\
calcaddress(passphrase)\n\ calcaddress(passphrase)\n\
instantdex_deposit(weeks, amount, broadcast=1)\n\ instantdex_deposit(weeks, amount, broadcast=1)\n\
instantdex_claim()\n\ instantdex_claim()\n\
timelock(coin, duration, destaddr=(tradeaddr), amount)\n\
unlockedspend(coin, txid)\n\
jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
\"}")); \"}"));
//sell(base, rel, price, basevolume, timeout=10, duration=3600)\n\ //sell(base, rel, price, basevolume, timeout=10, duration=3600)\n\
@ -177,19 +179,8 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
{ {
if ( G.USERPASS_COUNTER == 0 ) if ( G.USERPASS_COUNTER == 0 )
{ {
char pub33str[67];
G.USERPASS_COUNTER = 1; G.USERPASS_COUNTER = 1;
if ( 0 ) LP_cmdcount++;
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"userpass",G.USERPASS);
jaddbits256(retjson,"mypubkey",G.LP_mypub25519);
init_hexbytes_noT(pub33str,G.LP_pubsecp,33);
jaddstr(retjson,"pubsecp",pub33str);
jadd(retjson,"coins",LP_coinsjson(LP_showwif));
LP_cmdcount++;
return(jprint(retjson,1));
}
} }
// if passphrase api and passphrase is right, ignore userpass, use hass of passphrase // if passphrase api and passphrase is right, ignore userpass, use hass of passphrase
if ( strcmp(method,"passphrase") == 0 && (passphrase= jstr(argjson,"passphrase")) != 0 ) if ( strcmp(method,"passphrase") == 0 && (passphrase= jstr(argjson,"passphrase")) != 0 )
@ -449,7 +440,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
//* //*
if ( (ptr= LP_coinsearch(coin)) != 0 ) if ( (ptr= LP_coinsearch(coin)) != 0 )
{ {
if ( ptr->userpass[0] == 0 && strcmp(ptr->symbol,"ETH") != 0 ) if ( ptr->userpass[0] == 0 && ptr->etomic[0] == 0 )
{ {
cJSON *retjson = cJSON_CreateObject(); cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error",LP_DONTCHANGE_ERRMSG0); jaddstr(retjson,"error",LP_DONTCHANGE_ERRMSG0);
@ -458,21 +449,13 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
} }
if ( LP_conflicts_find(ptr) == 0 ) if ( LP_conflicts_find(ptr) == 0 )
{ {
cJSON *array;
ptr->inactive = 0; ptr->inactive = 0;
cJSON *array; //int32_t notarized; if ( ptr->smartaddr[0] != 0 )
/*if ( strcmp(ptr->symbol,"ETH") != 0 && LP_getheight(&notarized,ptr) <= 0 )
{
ptr->inactive = (uint32_t)time(NULL);
return(clonestr("{\"error\":\"coin cant be activated till synced\"}"));
}
else*/
{
if ( ptr->smartaddr[0] != 0 )
LP_unspents_load(coin,ptr->smartaddr);
LP_unspents_load(coin,ptr->smartaddr); LP_unspents_load(coin,ptr->smartaddr);
if ( strcmp(ptr->symbol,"KMD") == 0 ) LP_unspents_load(coin,ptr->smartaddr);
LP_importaddress("KMD",BOTS_BONDADDRESS); if ( strcmp(ptr->symbol,"KMD") == 0 )
} LP_importaddress("KMD",BOTS_BONDADDRESS);
array = cJSON_CreateArray(); array = cJSON_CreateArray();
jaddi(array,LP_coinjson(ptr,0)); jaddi(array,LP_coinjson(ptr,0));
return(jprint(array,1)); return(jprint(array,1));
@ -530,6 +513,14 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
{ {
return(LP_sendrawtransaction(coin,jstr(argjson,"signedtx"))); return(LP_sendrawtransaction(coin,jstr(argjson,"signedtx")));
} }
else if ( strcmp(method,"timelock") == 0 )
{
return(LP_timelock(coin,juint(argjson,"duration"),jstr(argjson,"destaddr"),jdouble(argjson,"amount")*SATOSHIDEN));
}
else if ( strcmp(method,"unlockedspend") == 0 )
{
return(LP_unlockedspend(ctx,coin,jbits256(argjson,"txid")));
}
else if ( strcmp(method,"getrawtransaction") == 0 ) else if ( strcmp(method,"getrawtransaction") == 0 )
{ {
return(jprint(LP_gettx(coin,jbits256(argjson,"txid"),0),1)); return(jprint(LP_gettx(coin,jbits256(argjson,"txid"),0),1));
@ -780,7 +771,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
myipaddr = LP_mypeer->ipaddr; myipaddr = LP_mypeer->ipaddr;
else printf("LP_psock dont have actual ipaddr?\n"); else printf("LP_psock dont have actual ipaddr?\n");
} }
if ( jint(argjson,"ispaired") != 0 ) if ( jint(argjson,"ispaired") != 0 && jobj(argjson,"netid") != 0 && juint(argjson,"netid") == G.netid )
{ {
retstr = LP_psock(&psock,myipaddr,1,jint(argjson,"cmdchannel"),jbits256(argjson,"pubkey")); retstr = LP_psock(&psock,myipaddr,1,jint(argjson,"cmdchannel"),jbits256(argjson,"pubkey"));
//printf("LP_commands.(%s)\n",retstr); //printf("LP_commands.(%s)\n",retstr);

406
iguana/exchanges/LP_etomic.c

@ -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);
}

15
iguana/exchanges/LP_include.h

@ -22,7 +22,7 @@
#define LP_INCLUDE_H #define LP_INCLUDE_H
#ifndef LP_TECHSUPPORT #ifndef LP_TECHSUPPORT
#define LP_TECHSUPPORT 0 #define LP_TECHSUPPORT 1
#endif #endif
#define LP_DONT_CMDCHANNEL #define LP_DONT_CMDCHANNEL
@ -35,7 +35,7 @@ voind dontprintf(char *formatstr,...) {}
#define LP_MAJOR_VERSION "0" #define LP_MAJOR_VERSION "0"
#define LP_MINOR_VERSION "1" #define LP_MINOR_VERSION "1"
#define LP_BUILD_NUMBER "17770" #define LP_BUILD_NUMBER "27770"
#define LP_BARTERDEX_VERSION 1 #define LP_BARTERDEX_VERSION 1
#define LP_MAGICBITS 1 #define LP_MAGICBITS 1
@ -202,7 +202,7 @@ struct basilisk_swap;
struct basilisk_rawtxinfo struct basilisk_rawtxinfo
{ {
char destaddr[64]; char destaddr[64],ethTxid[75];
bits256 txid,signedtxid,actualtxid; bits256 txid,signedtxid,actualtxid;
int64_t amount,change,inputsum; int64_t amount,change,inputsum;
int32_t redeemlen,datalen,completed,vintype,vouttype,numconfirms,spendlen,secretstart,suppress_pubkeys; int32_t redeemlen,datalen,completed,vintype,vouttype,numconfirms,spendlen,secretstart,suppress_pubkeys;
@ -235,7 +235,7 @@ struct basilisk_rawtx
struct basilisk_swapinfo struct basilisk_swapinfo
{ {
struct basilisk_request req; struct basilisk_request req;
char bobstr[128],alicestr[128]; char bobstr[128],alicestr[128],bobtomic[64],alicetomic[64],etomicsrc[65],etomicdest[65];
bits256 myhash,otherhash,orderhash; bits256 myhash,otherhash,orderhash;
uint32_t statebits,otherstatebits,started,expiration,finished,dead,reftime,putduration,callduration; uint32_t statebits,otherstatebits,started,expiration,finished,dead,reftime,putduration,callduration;
int32_t bobconfirms,aliceconfirms,iambob,reclaimed,bobspent,alicespent,pad,aliceistrusted,bobistrusted,otheristrusted,otherstrust,alicemaxconfirms,bobmaxconfirms; int32_t bobconfirms,aliceconfirms,iambob,reclaimed,bobspent,alicespent,pad,aliceistrusted,bobistrusted,otheristrusted,otherstrust,alicemaxconfirms,bobmaxconfirms;
@ -276,7 +276,7 @@ struct LP_swap_remember
uint32_t finishtime,tradeid,requestid,quoteid,plocktime,dlocktime,expiration,state,otherstate; uint32_t finishtime,tradeid,requestid,quoteid,plocktime,dlocktime,expiration,state,otherstate;
int32_t iambob,finishedflag,origfinishedflag,Predeemlen,Dredeemlen,sentflags[sizeof(txnames)/sizeof(*txnames)]; int32_t iambob,finishedflag,origfinishedflag,Predeemlen,Dredeemlen,sentflags[sizeof(txnames)/sizeof(*txnames)];
uint8_t secretAm[20],secretAm256[32],secretBn[20],secretBn256[32],Predeemscript[1024],Dredeemscript[1024],pubkey33[33],other33[33]; uint8_t secretAm[20],secretAm256[32],secretBn[20],secretBn256[32],Predeemscript[1024],Dredeemscript[1024],pubkey33[33],other33[33];
char Agui[65],Bgui[65],gui[65],src[65],dest[65],destaddr[64],Adestaddr[64],Sdestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[65],bobcoin[65],*txbytes[sizeof(txnames)/sizeof(*txnames)]; char Agui[65],Bgui[65],gui[65],src[65],dest[65],bobtomic[128],alicetomic[128],etomicsrc[65],etomicdest[65],destaddr[64],Adestaddr[64],Sdestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[65],bobcoin[65],*txbytes[sizeof(txnames)/sizeof(*txnames)],bobDepositEthTx[75],bobPaymentEthTx[75];
}; };
struct LP_outpoint struct LP_outpoint
@ -305,7 +305,7 @@ struct iguana_info
int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,height; uint16_t busport,did_addrutxo_reset; int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,height; uint16_t busport,did_addrutxo_reset;
uint32_t txversion,dPoWtime,lastresetutxo,loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime; uint32_t txversion,dPoWtime,lastresetutxo,loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime;
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms; uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms;
char symbol[128],smartaddr[64],userpass[1024],serverport[128],instantdex_address[64],estimatefeestr[32],getinfostr[32]; char symbol[128],smartaddr[64],userpass[1024],serverport[128],instantdex_address[64],estimatefeestr[32],getinfostr[32],etomic[64];
// portfolio // portfolio
double price_kmd,force,perc,goal,goalperc,relvolume,rate; double price_kmd,force,perc,goal,goalperc,relvolume,rate;
void *electrum; void *ctx; void *electrum; void *ctx;
@ -379,7 +379,7 @@ struct LP_quoteinfo
uint64_t satoshis,txfee,destsatoshis,desttxfee,aliceid; uint64_t satoshis,txfee,destsatoshis,desttxfee,aliceid;
uint32_t timestamp,quotetime,tradeid; uint32_t timestamp,quotetime,tradeid;
int32_t vout,vout2,destvout,feevout,pair; int32_t vout,vout2,destvout,feevout,pair;
char srccoin[65],coinaddr[64],destcoin[65],destaddr[64],gui[64]; char srccoin[65],coinaddr[64],destcoin[65],destaddr[64],gui[64],etomicsrc[65],etomicdest[65];
}; };
struct LP_endpoint { int32_t pair; char ipaddr[64]; uint16_t port; }; struct LP_endpoint { int32_t pair; char ipaddr[64]; uint16_t port; };
@ -548,6 +548,7 @@ void LP_postutxos(char *symbol,char *coinaddr);
int32_t LP_listunspent_both(char *symbol,char *coinaddr,int32_t fullflag); int32_t LP_listunspent_both(char *symbol,char *coinaddr,int32_t fullflag);
uint16_t LP_randpeer(char *destip); uint16_t LP_randpeer(char *destip);
void LP_tradebot_pauseall(); void LP_tradebot_pauseall();
int32_t LP_etomic_pub2addr(char *coinaddr,uint8_t pub64[64]);
void LP_portfolio_reset(); void LP_portfolio_reset();
int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr); int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr);
struct LP_pubkey_info *LP_pubkeyadd(bits256 pubkey); struct LP_pubkey_info *LP_pubkeyadd(bits256 pubkey);

112
iguana/exchanges/LP_instantdex.c

@ -65,7 +65,8 @@ void LP_instantdex_deposituniq(FILE *fp,bits256 txid)
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
fseek(fp,sizeof(prevtxid) * i,SEEK_SET); fseek(fp,sizeof(prevtxid) * i,SEEK_SET);
fread(&prevtxid,1,sizeof(prevtxid),fp); if ( fread(&prevtxid,1,sizeof(prevtxid),fp) != sizeof(prevtxid) )
printf("error reading deposit file\n");
if ( bits256_cmp(prevtxid,txid) == 0 ) if ( bits256_cmp(prevtxid,txid) == 0 )
{ {
//printf("%s duplicate of deposits[%d]\n",bits256_str(str,prevtxid),i); //printf("%s duplicate of deposits[%d]\n",bits256_str(str,prevtxid),i);
@ -92,7 +93,8 @@ void LP_instantdex_filescreate(char *coinaddr)
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
fseek(fp,sizeof(txid) * i,SEEK_SET); fseek(fp,sizeof(txid) * i,SEEK_SET);
fread(&txid,1,sizeof(txid),fp); if ( fread(&txid,1,sizeof(txid),fp) != sizeof(txid) )
printf("error reating %s\n",fname);
jaddibits256(array,txid); jaddibits256(array,txid);
if ( (txobj= LP_gettxout("KMD",coinaddr,txid,0)) != 0 ) if ( (txobj= LP_gettxout("KMD",coinaddr,txid,0)) != 0 )
free_json(txobj); free_json(txobj);
@ -283,6 +285,112 @@ int64_t LP_claimtx(void *ctx,struct iguana_info *coin,bits256 *claimtxidp,bits25
return(sum); return(sum);
} }
uint32_t LP_claimtime(struct iguana_info *coin,uint32_t expiration)
{
uint32_t heighttime,now = (uint32_t)time(NULL);
heighttime = LP_heighttime(coin->symbol,coin->height);
printf("claimtime: now %u height.%d heighttime.%u expiration.%u\n",now,coin->height,heighttime,expiration);
if ( heighttime >= expiration )
return(heighttime + 1);
return(0);
}
char *LP_unlockedspend(void *ctx,char *symbol,bits256 utxotxid)
{
cJSON *txjson,*vouts,*vout0,*opret,*sobj,*retjson; uint16_t utxovout; char *signedtx,*opretstr,vinaddr[64],destaddr[64]; uint32_t expiration,claimtime; uint8_t redeemscript[128]; bits256 signedtxid,sendtxid; int32_t numvouts,redeemlen; int64_t satoshis,destamount; struct iguana_info *coin;
if ( (coin= LP_coinfind(symbol)) == 0 )
return(clonestr("{\"error\":\"cant find coin\"}"));
retjson = cJSON_CreateObject();
utxovout = 0;
memset(&sendtxid,0,sizeof(sendtxid));
if ( (txjson= LP_gettx(coin->symbol,utxotxid,1)) != 0 )
{
if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && numvouts >= 2 )
{
vout0 = jitem(vouts,0);
LP_destaddr(vinaddr,vout0);
satoshis = LP_value_extract(vout0,0);
opret = jitem(vouts,numvouts - 1);
jaddstr(retjson,"result","success");
jaddbits256(retjson,"lockedtxid",utxotxid);
jaddnum(retjson,"amount",dstr(satoshis));
if ( (sobj= jobj(opret,"scriptPubKey")) != 0 )
{
if ( (opretstr= jstr(sobj,"hex")) != 0 )
{
jaddstr(retjson,"opreturn",opretstr);
redeemlen = (int32_t)strlen(opretstr) >> 1;
if ( redeemlen == 34 )
{
decode_hex(redeemscript,redeemlen,opretstr);
if ( redeemscript[0] == SCRIPT_OP_RETURN && redeemscript[1] == 32 && redeemscript[2] == 4 && redeemscript[7] == 0xb1 && redeemscript[8] == 0x75 && redeemscript[9] == 0x76 && redeemscript[10] == 0xa9 && redeemscript[11] == 0x14 && redeemscript[32] == 0x88 && redeemscript[33] == 0xac )
{
expiration = 0;
expiration = (expiration << 8) | redeemscript[6];
expiration = (expiration << 8) | redeemscript[5];
expiration = (expiration << 8) | redeemscript[4];
expiration = (expiration << 8) | redeemscript[3];
bitcoin_address(symbol,destaddr,coin->taddr,coin->pubtype,&redeemscript[12],20);
jaddstr(retjson,"address",destaddr);
jaddnum(retjson,"expiration",expiration);
claimtime = LP_claimtime(coin,expiration);
jaddnum(retjson,"claimtime",claimtime);
if ( claimtime != 0 && strcmp(destaddr,coin->smartaddr) == 0 && time(NULL) > expiration )
{
char str[65]; printf("LP_timespend satoshis %.8f %s/v%d\n",dstr(satoshis - coin->txfee),bits256_str(str,utxotxid),utxovout);
if ( (signedtx= basilisk_swap_bobtxspend(&signedtxid,coin->txfee,"timespend",coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,ctx,G.LP_privkey,0,redeemscript+2,redeemlen-2,0,0,utxotxid,utxovout,coin->smartaddr,G.LP_pubsecp,0,claimtime,&destamount,0,0,vinaddr,0,coin->zcash)) != 0 )
{
//sendtxid = LP_broadcast("timespend",symbol,signedtx,signedtxid);
jaddstr(retjson,"signedtx",signedtx);
jaddbits256(retjson,"txid",signedtxid);
if ( bits256_cmp(sendtxid,signedtxid) == 0 )
jaddbits256(retjson,"sendtxid",sendtxid);
else printf("error sending %s\n",bits256_str(str,signedtxid));
free(signedtx);
}
else
{
printf("error doing timespend %s/v%d %.8f\n",bits256_str(str,utxotxid),utxovout,dstr(satoshis));
jaddstr(retjson,"error","couldnt sign timespend");
}
}
} else jaddstr(retjson,"error","mismatched redeemscript");
}
}
}
}
free_json(txjson);
}
return(jprint(retjson,1));
}
char *LP_timelock(char *symbol,uint32_t duration,char *destaddr,uint64_t satoshis)
{
struct iguana_info *coin; uint32_t expiration; char *retstr,p2shaddr[64],redeemscript[256]; cJSON *argjson,*array,*item; int32_t n=0; uint8_t addrtype,rmd160[20],p2sh160[20],script[40];
if ( (coin= LP_coinfind(symbol)) != 0 )
{
expiration = (uint32_t)time(NULL) + duration;
if ( destaddr == 0 )
destaddr = coin->smartaddr;
bitcoin_addr2rmd160(symbol,coin->taddr,&addrtype,rmd160,destaddr);
n = bitcoin_timelockspend(script,0,rmd160,expiration);
init_hexbytes_noT(redeemscript,script,n);
calc_rmd160_sha256(p2sh160,script,n);
bitcoin_address(symbol,p2shaddr,coin->taddr,coin->p2shtype,p2sh160,20);
argjson = cJSON_CreateObject();
array = cJSON_CreateArray();
item = cJSON_CreateObject();
jaddnum(item,p2shaddr,dstr(satoshis + coin->txfee));
jaddi(array,item);
jadd(argjson,"outputs",array);
jaddstr(argjson,"opreturn",redeemscript);
//printf("deposit.(%s)\n",jprint(argjson,0));
if ( (retstr= LP_withdraw(coin,argjson)) != 0 )
return(retstr);
else return(clonestr("{\"error\":\"timelock got null return from LP_withdraw\"}"));
} else return(clonestr("{\"error\":\"cant find coin\"}"));
}
int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info *coin,bits256 utxotxid) int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info *coin,bits256 utxotxid)
{ {
uint8_t redeemscript[512]; bits256 claimtxid; cJSON *txjson,*vout0,*vout1,*vout2,*vouts,*item; int32_t numvouts; char str[65],vinaddr[64],destaddr[64],checkaddr[64]; int32_t j,utxovout,flagi = 0,redeemlen,weeki,iter; int64_t weeksatoshis,satoshis; uint32_t expiration,claimtime; uint8_t redeemscript[512]; bits256 claimtxid; cJSON *txjson,*vout0,*vout1,*vout2,*vouts,*item; int32_t numvouts; char str[65],vinaddr[64],destaddr[64],checkaddr[64]; int32_t j,utxovout,flagi = 0,redeemlen,weeki,iter; int64_t weeksatoshis,satoshis; uint32_t expiration,claimtime;

10
iguana/exchanges/LP_mmjson.c

@ -46,17 +46,17 @@
#define MMJSON_ARRAY8 228 #define MMJSON_ARRAY8 228
#define MMJSON_ARRAY16 227 #define MMJSON_ARRAY16 227
#define MMJSON_ARRAY32 226 #define MMJSON_ARRAY32 226
#define MMJSON_BOUNDARY 98
int32_t MM_numfields; int32_t MM_numfields;
char *MM_fields[256] = char *MM_fields[] =
{ {
"timestamp", "getdPoW", "dPoW", "aliceid", "src", "base", "basevol", "dest", "rel", "relvol", "price", "requestid", "quoteid", "finished", "expired", "bobdeposit", "alicepayment", "bobpayment", "paymentspent", "Apaymentspent", "depositspent", "ind", "method", "swapstatus", "method2", "gettradestatus", "coin", "rmd160", "pub", "pubsecp", "sig", "session", "notify", "pubkey", "price64", "credits", "utxocoin", "n", "bal", "min", "max", "postprice", "notarized", "notarizedhash", "notarizationtxid", "wantnotify", "isLP", "gui", "nogui", "tradeid", "address", "txid", "vout", "srchash", "txfee", "quotetime", "satoshis", "desthash", "txid2", "vout2", "destaddr", "desttxid", "destvout", "feetxid", "feevout", "desttxfee", "destsatoshis", "pending", "reserved", "broadcast", "ismine", "simplegui", "request", "proof", "connect", "expiration", "iambob", "Bgui", "", "Agui", "bob", "srcamount", "bobtxfee", "alice", "destamount", "alicetxfee", "sentflags", "values", "result", "success", "status", "finishtime", "tradestatus", "pair", "connected", "warning", "critical", "endcritical", "timestamp", "getdPoW", "dPoW", "aliceid", "src", "base", "basevol", "dest", "rel", "relvol", "price", "requestid", "quoteid", "finished", "expired", "bobdeposit", "alicepayment", "bobpayment", "paymentspent", "Apaymentspent", "depositspent", "ind", "method", "swapstatus", "method2", "gettradestatus", "coin", "rmd160", "pub", "pubsecp", "sig", "session", "notify", "pubkey", "price64", "credits", "utxocoin", "n", "bal", "min", "max", "postprice", "notarized", "notarizedhash", "notarizationtxid", "wantnotify", "isLP", "gui", "nogui", "tradeid", "address", "txid", "vout", "srchash", "txfee", "quotetime", "satoshis", "desthash", "txid2", "vout2", "destaddr", "desttxid", "destvout", "feetxid", "feevout", "desttxfee", "destsatoshis", "pending", "reserved", "broadcast", "ismine", "simplegui", "request", "proof", "connect", "expiration", "iambob", "Bgui", "", "Agui", "bob", "srcamount", "bobtxfee", "alice", "destamount", "alicetxfee", "sentflags", "values", "result", "success", "status", "finishtime", "tradestatus", "pair", "connected", "warning", "critical", "endcritical", "cli", "etomic", "bobtomic", "alicetomic", "etomicsrc", "etomicdest"
}; };
#define MMJSON_BOUNDARY ((int32_t)(sizeof(MM_fields)/sizeof(*MM_fields)))
char *MM_coins[256] = char *MM_coins[] =
{ {
"KMD", "BTC", "CRC", "VOT", "INN", "MOON", "CRW", "EFL", "GBX", "BCO", "BLK", "BTG", "BCH", "ABY", "STAK", "XZC", "QTUM", "PURA", "DSR", "MNZ", "BTCZ", "MAGA", "BSD", "IOP", "BLOCK", "CHIPS", "888", "ARG", "GLT", "ZER", "HODLC", "UIS", "HUC", "PIVX", "BDL", "ARC", "ZCL", "VIA", "ERC", "FAIR", "FLO", "SXC", "CREA", "TRC", "BTA", "SMC", "NMC", "NAV", "EMC2", "SYS", "I0C", "DASH", "STRAT", "MUE", "MONA", "XMY", "MAC", "BTX", "XRE", "LBC", "SIB", "VTC", "REVS", "JUMBLR", "DOGE", "HUSH", "ZEC", "DGB", "ZET", "GAME", "LTC", "SUPERNET", "WLC", "PANGEA", "DEX", "BET", "CRYPTO", "HODL", "MSHARK", "BOTS", "MGW", "COQUI", "KV", "CEAL", "MESH", "KMD", "BTC", "CRC", "VOT", "INN", "MOON", "CRW", "EFL", "GBX", "BCO", "BLK", "BTG", "BCH", "ABY", "STAK", "XZC", "QTUM", "PURA", "DSR", "MNZ", "BTCZ", "MAGA", "BSD", "IOP", "BLOCK", "CHIPS", "888", "ARG", "GLT", "ZER", "HODLC", "UIS", "HUC", "PIVX", "BDL", "ARC", "ZCL", "VIA", "ERC", "FAIR", "FLO", "SXC", "CREA", "TRC", "BTA", "SMC", "NMC", "NAV", "EMC2", "SYS", "I0C", "DASH", "STRAT", "MUE", "MONA", "XMY", "MAC", "BTX", "XRE", "LBC", "SIB", "VTC", "REVS", "JUMBLR", "DOGE", "HUSH", "ZEC", "DGB", "ZET", "GAME", "LTC", "SUPERNET", "WLC", "PANGEA", "DEX", "BET", "CRYPTO", "HODL", "MSHARK", "BOTS", "MGW", "COQUI", "KV", "CEAL", "MESH", "ETOMIC", "BTCH", "ETH"
}; };
int32_t mmjson_coinfind(char *symbol) int32_t mmjson_coinfind(char *symbol)

58
iguana/exchanges/LP_nativeDEX.c

@ -178,6 +178,9 @@ char *blocktrail_listtransactions(char *symbol,char *coinaddr,int32_t num,int32_
#include "LP_prices.c" #include "LP_prices.c"
#include "LP_scan.c" #include "LP_scan.c"
#include "LP_transaction.c" #include "LP_transaction.c"
#ifndef NOTETOMIC
#include "LP_etomic.c"
#endif
#include "LP_stats.c" #include "LP_stats.c"
#include "LP_remember.c" #include "LP_remember.c"
#include "LP_instantdex.c" #include "LP_instantdex.c"
@ -485,6 +488,11 @@ void command_rpcloop(void *ctx)
command_rpcloop_stats.threshold = 2500.; command_rpcloop_stats.threshold = 2500.;
while ( LP_STOP_RECEIVED == 0 ) while ( LP_STOP_RECEIVED == 0 )
{ {
if ( G.initializing != 0 )
{
sleep(1);
continue;
}
LP_millistats_update(&command_rpcloop_stats); LP_millistats_update(&command_rpcloop_stats);
nonz = LP_nanomsg_recvs(ctx); nonz = LP_nanomsg_recvs(ctx);
//if ( LP_mybussock >= 0 ) //if ( LP_mybussock >= 0 )
@ -520,11 +528,11 @@ void LP_coinsloop(void *_coins)
} }
while ( LP_STOP_RECEIVED == 0 ) while ( LP_STOP_RECEIVED == 0 )
{ {
/*if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 ) if ( G.initializing != 0 )
{ {
sleep(10); sleep(1);
continue; continue;
}*/ }
if ( strcmp("BTC",coins) == 0 ) if ( strcmp("BTC",coins) == 0 )
LP_millistats_update(&LP_coinsloopBTC_stats); LP_millistats_update(&LP_coinsloopBTC_stats);
else if ( strcmp("KMD",coins) == 0 ) else if ( strcmp("KMD",coins) == 0 )
@ -790,7 +798,7 @@ void bech32_tests()
void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins) void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins)
{ {
int32_t i,n,notarized; cJSON *item; char *symbol; struct iguana_info *coin; int32_t i,n,notarized; cJSON *item; char *symbol,*etomic; struct iguana_info *coin;
for (i=0; i<sizeof(activecoins)/sizeof(*activecoins); i++) for (i=0; i<sizeof(activecoins)/sizeof(*activecoins); i++)
{ {
printf("%s, ",activecoins[i]); printf("%s, ",activecoins[i]);
@ -825,9 +833,14 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins)
LP_priceinfoadd(jstr(item,"coin")); LP_priceinfoadd(jstr(item,"coin"));
if ( (coin= LP_coinfind(symbol)) != 0 ) if ( (coin= LP_coinfind(symbol)) != 0 )
{ {
if ( LP_getheight(&notarized,coin) <= 0 ) if ( (etomic= jstr(item,"etomic")) != 0 )
coin->inactive = (uint32_t)time(NULL); safecopy(coin->etomic,etomic,sizeof(coin->etomic));
else LP_unspents_load(coin->symbol,coin->smartaddr); else
{
if ( LP_getheight(&notarized,coin) <= 0 )
coin->inactive = (uint32_t)time(NULL);
else LP_unspents_load(coin->symbol,coin->smartaddr);
}
if ( coin->txfee == 0 && strcmp(coin->symbol,"BTC") != 0 ) if ( coin->txfee == 0 && strcmp(coin->symbol,"BTC") != 0 )
coin->txfee = LP_MIN_TXFEE; coin->txfee = LP_MIN_TXFEE;
if ( 0 && strcmp(coin->symbol,"BCH") == 0 ) if ( 0 && strcmp(coin->symbol,"BCH") == 0 )
@ -904,7 +917,11 @@ void LP_pubkeysloop(void *ctx)
sleep(10); sleep(10);
while ( LP_STOP_RECEIVED == 0 ) while ( LP_STOP_RECEIVED == 0 )
{ {
//if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") != 0 ) if ( G.initializing != 0 )
{
sleep(1);
continue;
}
{ {
LP_millistats_update(&LP_pubkeysloop_stats); LP_millistats_update(&LP_pubkeysloop_stats);
if ( time(NULL) > lasttime+100 ) if ( time(NULL) > lasttime+100 )
@ -955,6 +972,11 @@ void LP_swapsloop(void *ctx)
} }
while ( LP_STOP_RECEIVED == 0 ) while ( LP_STOP_RECEIVED == 0 )
{ {
if ( G.initializing != 0 )
{
sleep(1);
continue;
}
LP_millistats_update(&LP_swapsloop_stats); LP_millistats_update(&LP_swapsloop_stats);
nonz = 0; nonz = 0;
DL_FOREACH_SAFE(LP_pendingswaps,sp,tmp) DL_FOREACH_SAFE(LP_pendingswaps,sp,tmp)
@ -979,6 +1001,11 @@ void gc_loop(void *ctx)
LP_gcloop_stats.threshold = 11000.; LP_gcloop_stats.threshold = 11000.;
while ( LP_STOP_RECEIVED == 0 ) while ( LP_STOP_RECEIVED == 0 )
{ {
if ( G.initializing != 0 )
{
sleep(1);
continue;
}
flag = 0; flag = 0;
LP_millistats_update(&LP_gcloop_stats); LP_millistats_update(&LP_gcloop_stats);
portable_mutex_lock(&LP_gcmutex); portable_mutex_lock(&LP_gcmutex);
@ -1014,6 +1041,11 @@ void queue_loop(void *ctx)
queue_loop_stats.threshold = 1000.; queue_loop_stats.threshold = 1000.;
while ( LP_STOP_RECEIVED == 0 ) while ( LP_STOP_RECEIVED == 0 )
{ {
if ( G.initializing != 0 )
{
sleep(1);
continue;
}
LP_millistats_update(&queue_loop_stats); LP_millistats_update(&queue_loop_stats);
//printf("LP_Q.%p next.%p prev.%p\n",LP_Q,LP_Q!=0?LP_Q->next:0,LP_Q!=0?LP_Q->prev:0); //printf("LP_Q.%p next.%p prev.%p\n",LP_Q,LP_Q!=0?LP_Q->next:0,LP_Q!=0?LP_Q->prev:0);
n = nonz = flag = 0; n = nonz = flag = 0;
@ -1123,6 +1155,11 @@ void LP_reserved_msgs(void *ignore)
LP_reserved_msgs_stats.threshold = 1000.; LP_reserved_msgs_stats.threshold = 1000.;
while ( LP_STOP_RECEIVED == 0 ) while ( LP_STOP_RECEIVED == 0 )
{ {
if ( G.initializing != 0 )
{
sleep(1);
continue;
}
nonz = 0; nonz = 0;
LP_millistats_update(&LP_reserved_msgs_stats); LP_millistats_update(&LP_reserved_msgs_stats);
if ( num_Reserved_msgs[1] > 0 ) if ( num_Reserved_msgs[1] > 0 )
@ -1462,6 +1499,11 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
//fprintf(stderr,"."); //fprintf(stderr,".");
sleep(3); sleep(3);
} }
if ( G.initializing != 0 )
{
sleep(1);
continue;
}
if ( LP_mainloop_iter(ctx,myipaddr,mypeer,LP_mypubsock) != 0 ) if ( LP_mainloop_iter(ctx,myipaddr,mypeer,LP_mypubsock) != 0 )
nonz++; nonz++;
if ( IAMLP != 0 && didremote == 0 && LP_cmdcount > 0 ) if ( IAMLP != 0 && didremote == 0 && LP_cmdcount > 0 )

80
iguana/exchanges/LP_network.c

@ -103,28 +103,28 @@ char *nanomsg_transportname(int32_t bindflag,char *str,char *ipaddr,uint16_t por
} }
/*char *nanomsg_transportname2(int32_t bindflag,char *str,char *ipaddr,uint16_t port) /*char *nanomsg_transportname2(int32_t bindflag,char *str,char *ipaddr,uint16_t port)
{ {
sprintf(str,"ws://%s:%u",bindflag == 0 ? ipaddr : "*",port+10); sprintf(str,"ws://%s:%u",bindflag == 0 ? ipaddr : "*",port+10);
return(str); return(str);
} }
int32_t _LP_send(int32_t sock,void *msg,int32_t sendlen,int32_t freeflag) int32_t _LP_send(int32_t sock,void *msg,int32_t sendlen,int32_t freeflag)
{ {
int32_t sentbytes; int32_t sentbytes;
if ( sock < 0 ) if ( sock < 0 )
{ {
printf("LP_send.(%s) to illegal socket\n",(char *)msg); printf("LP_send.(%s) to illegal socket\n",(char *)msg);
if ( freeflag != 0 ) if ( freeflag != 0 )
free(msg); free(msg);
return(-1); return(-1);
} }
if ( (sentbytes= nn_send(sock,msg,sendlen,0)) != sendlen ) if ( (sentbytes= nn_send(sock,msg,sendlen,0)) != sendlen )
printf("LP_send sent %d instead of %d\n",sentbytes,sendlen); printf("LP_send sent %d instead of %d\n",sentbytes,sendlen);
else printf("SENT.(%s)\n",(char *)msg); else printf("SENT.(%s)\n",(char *)msg);
if ( freeflag != 0 ) if ( freeflag != 0 )
free(msg); free(msg);
return(sentbytes); return(sentbytes);
}*/ }*/
int32_t LP_sockcheck(int32_t sock) int32_t LP_sockcheck(int32_t sock)
{ {
@ -314,7 +314,7 @@ void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON
#endif #endif
{ {
free(msg); free(msg);
//printf("broadcast %s\n",jstr(argjson,"method")); //printf("broadcast %s\n",jstr(argjson,"method"));
jdelete(argjson,"method"); jdelete(argjson,"method");
jaddstr(argjson,"method","broadcast"); jaddstr(argjson,"method","broadcast");
if ( jobj(argjson,"timestamp") == 0 ) if ( jobj(argjson,"timestamp") == 0 )
@ -332,7 +332,7 @@ void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON
} }
free(msg); free(msg);
} }
void LP_broadcast_message(int32_t pubsock,char *base,char *rel,bits256 destpub25519,char *msgstr) void LP_broadcast_message(int32_t pubsock,char *base,char *rel,bits256 destpub25519,char *msgstr)
{ {
uint8_t encoded[LP_ENCRYPTED_MAXSIZE],space[sizeof(encoded)],*msg,*nonce,*cipher; int32_t encrypted=0,msglen; uint32_t crc32=0; cJSON *argjson; char *methodstr,method[64],cipherstr[LP_ENCRYPTED_MAXSIZE*2+1]; uint8_t encoded[LP_ENCRYPTED_MAXSIZE],space[sizeof(encoded)],*msg,*nonce,*cipher; int32_t encrypted=0,msglen; uint32_t crc32=0; cJSON *argjson; char *methodstr,method[64],cipherstr[LP_ENCRYPTED_MAXSIZE*2+1];
@ -388,7 +388,7 @@ void LP_broadcast_message(int32_t pubsock,char *base,char *rel,bits256 destpub25
if ( msgstr != 0 ) if ( msgstr != 0 )
free(msgstr); free(msgstr);
} }
uint32_t LP_swapsend(int32_t pairsock,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t nextbits,uint32_t crcs[2]) uint32_t LP_swapsend(int32_t pairsock,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t nextbits,uint32_t crcs[2])
{ {
uint8_t *buf; int32_t sentbytes,offset=0,i; uint8_t *buf; int32_t sentbytes,offset=0,i;
@ -413,7 +413,7 @@ uint32_t LP_swapsend(int32_t pairsock,struct basilisk_swap *swap,uint32_t msgbit
free(buf); free(buf);
return(nextbits); return(nextbits);
} }
struct LP_queuedcommand struct LP_queuedcommand
{ {
struct LP_queuedcommand *next,*prev; struct LP_queuedcommand *next,*prev;
@ -471,7 +471,7 @@ void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats
DL_APPEND(LP_commandQ,ptr); DL_APPEND(LP_commandQ,ptr);
portable_mutex_unlock(&LP_commandQmutex); portable_mutex_unlock(&LP_commandQmutex);
} }
void mynn_close(int32_t sock) void mynn_close(int32_t sock)
{ {
struct nn_pollfd pfd; int32_t n; void *buf; struct nn_pollfd pfd; int32_t n; void *buf;
@ -490,7 +490,7 @@ void mynn_close(int32_t sock)
nn_close(sock); nn_close(sock);
} }
} }
void LP_psockloop(void *_ptr) void LP_psockloop(void *_ptr)
{ {
static struct nn_pollfd *pfds; static struct nn_pollfd *pfds;
@ -652,7 +652,7 @@ void LP_psockloop(void *_ptr)
} else usleep(100000); } else usleep(100000);
} }
} }
void LP_psockadd(int32_t ispaired,int32_t publicsock,uint16_t recvport,int32_t sendsock,uint16_t sendport,char *subaddr,char *publicaddr,int32_t cmdchannel) void LP_psockadd(int32_t ispaired,int32_t publicsock,uint16_t recvport,int32_t sendsock,uint16_t sendport,char *subaddr,char *publicaddr,int32_t cmdchannel)
{ {
struct psock *ptr; struct psock *ptr;
@ -671,7 +671,7 @@ void LP_psockadd(int32_t ispaired,int32_t publicsock,uint16_t recvport,int32_t s
ptr->lasttime = (uint32_t)time(NULL); ptr->lasttime = (uint32_t)time(NULL);
portable_mutex_unlock(&LP_psockmutex); portable_mutex_unlock(&LP_psockmutex);
} }
int32_t LP_psockmark(char *publicaddr) int32_t LP_psockmark(char *publicaddr)
{ {
int32_t i,retval = -1; struct psock *ptr; int32_t i,retval = -1; struct psock *ptr;
@ -690,7 +690,7 @@ int32_t LP_psockmark(char *publicaddr)
portable_mutex_unlock(&LP_psockmutex); portable_mutex_unlock(&LP_psockmutex);
return(retval); return(retval);
} }
char *_LP_psock_create(int32_t *pullsockp,int32_t *pubsockp,char *ipaddr,uint16_t publicport,uint16_t subport,int32_t ispaired,int32_t cmdchannel,bits256 pubkey) char *_LP_psock_create(int32_t *pullsockp,int32_t *pubsockp,char *ipaddr,uint16_t publicport,uint16_t subport,int32_t ispaired,int32_t cmdchannel,bits256 pubkey)
{ {
int32_t i,pullsock,bindflag=(IAMLP != 0),pubsock,arg; struct LP_pubkey_info *pubp; char pushaddr[128],subaddr[128]; cJSON *retjson = 0; int32_t i,pullsock,bindflag=(IAMLP != 0),pubsock,arg; struct LP_pubkey_info *pubp; char pushaddr[128],subaddr[128]; cJSON *retjson = 0;
@ -778,7 +778,7 @@ char *_LP_psock_create(int32_t *pullsockp,int32_t *pubsockp,char *ipaddr,uint16_
} }
return(0); return(0);
} }
char *LP_psock(int32_t *pullsockp,char *ipaddr,int32_t ispaired,int32_t cmdchannel,bits256 pubkey) char *LP_psock(int32_t *pullsockp,char *ipaddr,int32_t ispaired,int32_t cmdchannel,bits256 pubkey)
{ {
char *retstr=0; uint16_t i,publicport,subport,maxport; int32_t pubsock=-1; char *retstr=0; uint16_t i,publicport,subport,maxport; int32_t pubsock=-1;
@ -818,28 +818,28 @@ char *LP_psock(int32_t *pullsockp,char *ipaddr,int32_t ispaired,int32_t cmdchann
Pcmdport = MAX_PSOCK_PORT; Pcmdport = MAX_PSOCK_PORT;
return(clonestr("{\"error\",\"cant find psock ports\"}")); return(clonestr("{\"error\",\"cant find psock ports\"}"));
} }
/* /*
LP_pushaddr_get makes transparent the fact that most nodes cannot bind()! LP_pushaddr_get makes transparent the fact that most nodes cannot bind()!
The idea is to create an LP node NN_PAIR sock that the LP node binds to and client node connects to. Additionally, the LP node creates an NN_PULL that other nodes can NN_PUSH to and returns this address in pushaddr/retval for the client node to register with. The desired result is that other than the initial LP node, all the other nodes do a normal NN_PUSH, requiring no change to the NN_PUSH/NN_PULL logic. Of course, the initial LP node needs to autoforward all packets from the public NN_PULL to the NN_PUB The idea is to create an LP node NN_PAIR sock that the LP node binds to and client node connects to. Additionally, the LP node creates an NN_PULL that other nodes can NN_PUSH to and returns this address in pushaddr/retval for the client node to register with. The desired result is that other than the initial LP node, all the other nodes do a normal NN_PUSH, requiring no change to the NN_PUSH/NN_PULL logic. Of course, the initial LP node needs to autoforward all packets from the public NN_PULL to the NN_PUB
similar to LP_pushaddr_get, create an NN_PAIR for DEX atomic data, can be assumed to have a max lifetime of 2*INSTANTDEX_LOCKTIME similar to LP_pushaddr_get, create an NN_PAIR for DEX atomic data, can be assumed to have a max lifetime of 2*INSTANTDEX_LOCKTIME
both are combined in LP_psock_get both are combined in LP_psock_get
*/ */
char *issue_LP_psock(char *destip,uint16_t destport,int32_t ispaired,int32_t cmdchannel) char *issue_LP_psock(char *destip,uint16_t destport,int32_t ispaired,int32_t cmdchannel)
{ {
char str[65],url[512],*retstr; char str[65],url[512],*retstr;
sprintf(url,"http://%s:%u/api/stats/psock?ispaired=%d&cmdchannel=%d&pubkey=%s",destip,destport-1,ispaired,cmdchannel,bits256_str(str,G.LP_mypub25519)); sprintf(url,"http://%s:%u/api/stats/psock?ispaired=%d&cmdchannel=%d&pubkey=%s&netid=%d",destip,destport-1,ispaired,cmdchannel,bits256_str(str,G.LP_mypub25519),G.netid);
//return(LP_issue_curl("psock",destip,destport,url)); //return(LP_issue_curl("psock",destip,destport,url));
retstr = issue_curlt(url,LP_HTTP_TIMEOUT*10); retstr = issue_curlt(url,LP_HTTP_TIMEOUT*10);
printf("issue_LP_psock got (%s) from %s\n",retstr,url); // this is needed?! printf("issue_LP_psock got (%s) from %s\n",retstr,url); // this is needed?!
return(retstr); return(retstr);
} }
uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired,int32_t cmdchannel,char *ipaddr) uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired,int32_t cmdchannel,char *ipaddr)
{ {
uint16_t publicport = 0; char *retstr,*addr; cJSON *retjson; struct LP_peerinfo *peer,*tmp; uint16_t publicport = 0; char *retstr,*addr; cJSON *retjson; struct LP_peerinfo *peer,*tmp;
@ -869,7 +869,7 @@ uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired,int32_
} }
return(0); return(0);
} }
int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char *myipaddr,uint16_t mypullport,int32_t ispaired) int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char *myipaddr,uint16_t mypullport,int32_t ispaired)
{ {
int32_t nntype,pullsock,timeout; char bindaddr[128],connectaddr[128]; int32_t nntype,pullsock,timeout; char bindaddr[128],connectaddr[128];

138
iguana/exchanges/LP_ordermatch.c

@ -103,27 +103,29 @@ int32_t LP_quote_checkmempool(struct LP_quoteinfo *qp,struct LP_utxoinfo *autxo,
double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,struct LP_quoteinfo *qp,int32_t iambob) double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,struct LP_quoteinfo *qp,int32_t iambob)
{ {
double qprice=0.; char str[65]; cJSON *txout; uint64_t txfee,desttxfee,srcvalue=0,srcvalue2=0,destvalue=0,destvalue2=0; double qprice=0.; char str[65],srccoin[65],destcoin[65],bobtomic[64],alicetomic[64]; cJSON *txout; uint64_t txfee,desttxfee,srcvalue=0,srcvalue2=0,destvalue=0,destvalue2=0;
//printf(">>>>>>> quote satoshis.(%.8f %.8f) %s %.8f -> %s %.8f\n",dstr(qp->satoshis),dstr(qp->destsatoshis),qp->srccoin,dstr(qp->satoshis),qp->destcoin,dstr(qp->destsatoshis)); LP_etomicsymbol(srccoin,bobtomic,qp->srccoin);
LP_etomicsymbol(destcoin,alicetomic,qp->destcoin);
//printf(">>>>>>> quote satoshis.(%.8f %.8f) %s %.8f -> %s %.8f\n",dstr(qp->satoshis),dstr(qp->destsatoshis),qp->srccoin,dstr(qp->satoshis),qp->destcoin,dstr(qp->destsatoshis));
if ( butxo != 0 ) if ( butxo != 0 )
{ {
if ( LP_iseligible(&srcvalue,&srcvalue2,1,qp->srccoin,qp->txid,qp->vout,qp->satoshis,qp->txid2,qp->vout2) == 0 ) if ( LP_iseligible(&srcvalue,&srcvalue2,1,srccoin,qp->txid,qp->vout,qp->satoshis,qp->txid2,qp->vout2) == 0 )
{ {
//printf("bob not eligible %s (%.8f %.8f)\n",jprint(LP_quotejson(qp),1),dstr(srcvalue),dstr(srcvalue2)); //printf("bob not eligible %s (%.8f %.8f)\n",jprint(LP_quotejson(qp),1),dstr(srcvalue),dstr(srcvalue2));
return(-2); return(-2);
} }
if ( (txout= LP_gettxout(qp->srccoin,qp->coinaddr,qp->txid,qp->vout)) != 0 ) if ( (txout= LP_gettxout(srccoin,qp->coinaddr,qp->txid,qp->vout)) != 0 )
free_json(txout); free_json(txout);
else else
{ {
printf("%s %s payment %s/v%d is spent\n",qp->srccoin,qp->coinaddr,bits256_str(str,qp->txid),qp->vout); printf("%s %s payment %s/v%d is spent\n",srccoin,qp->coinaddr,bits256_str(str,qp->txid),qp->vout);
return(-21); return(-21);
} }
if ( (txout= LP_gettxout(qp->srccoin,qp->coinaddr,qp->txid2,qp->vout2)) != 0 ) if ( (txout= LP_gettxout(srccoin,qp->coinaddr,qp->txid2,qp->vout2)) != 0 )
free_json(txout); free_json(txout);
else else
{ {
printf("%s %s deposit %s/v%d is spent\n",qp->srccoin,qp->coinaddr,bits256_str(str,qp->txid2),qp->vout2); printf("%s %s deposit %s/v%d is spent\n",srccoin,qp->coinaddr,bits256_str(str,qp->txid2),qp->vout2);
return(-22); return(-22);
} }
if ( bits256_cmp(butxo->deposit.txid,qp->txid2) != 0 || butxo->deposit.vout != qp->vout2 ) if ( bits256_cmp(butxo->deposit.txid,qp->txid2) != 0 || butxo->deposit.vout != qp->vout2 )
@ -139,24 +141,24 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str
} }
if ( autxo != 0 ) if ( autxo != 0 )
{ {
if ( LP_iseligible(&destvalue,&destvalue2,0,qp->destcoin,qp->desttxid,qp->destvout,qp->destsatoshis,qp->feetxid,qp->feevout) == 0 ) if ( LP_iseligible(&destvalue,&destvalue2,0,destcoin,qp->desttxid,qp->destvout,qp->destsatoshis,qp->feetxid,qp->feevout) == 0 )
{ {
//alice not eligible 0.36893923 -> dest 0.55020000 1.49130251 (0.61732249 0.00104324) 14b8b74808d2d34a70e5eddd1cad47d855858f8b23cac802576d4d37b5f8af8f/v1 abec6e76169bcb738235ca67fab02cc55390f39e422aa71f1badf8747c290cc4/v1 //alice not eligible 0.36893923 -> dest 0.55020000 1.49130251 (0.61732249 0.00104324) 14b8b74808d2d34a70e5eddd1cad47d855858f8b23cac802576d4d37b5f8af8f/v1 abec6e76169bcb738235ca67fab02cc55390f39e422aa71f1badf8747c290cc4/v1
//char str[65],str2[65]; printf("alice not eligible %.8f -> dest %.8f %.8f (%.8f %.8f) %s/v%d %s/v%d\n",dstr(qp->satoshis),dstr(qp->destsatoshis),(double)qp->destsatoshis/qp->satoshis,dstr(destvalue),dstr(destvalue2),bits256_str(str,qp->desttxid),qp->destvout,bits256_str(str2,qp->feetxid),qp->feevout); //char str[65],str2[65]; printf("alice not eligible %.8f -> dest %.8f %.8f (%.8f %.8f) %s/v%d %s/v%d\n",dstr(qp->satoshis),dstr(qp->destsatoshis),(double)qp->destsatoshis/qp->satoshis,dstr(destvalue),dstr(destvalue2),bits256_str(str,qp->desttxid),qp->destvout,bits256_str(str2,qp->feetxid),qp->feevout);
return(-3); return(-3);
} }
if ( (txout= LP_gettxout(qp->destcoin,qp->destaddr,qp->desttxid,qp->destvout)) != 0 ) if ( (txout= LP_gettxout(destcoin,qp->destaddr,qp->desttxid,qp->destvout)) != 0 )
free_json(txout); free_json(txout);
else else
{ {
printf("%s %s Apayment %s/v%d is spent\n",qp->destcoin,qp->destaddr,bits256_str(str,qp->desttxid),qp->destvout); printf("%s %s Apayment %s/v%d is spent\n",destcoin,qp->destaddr,bits256_str(str,qp->desttxid),qp->destvout);
return(-23); return(-23);
} }
if ( (txout= LP_gettxout(qp->destcoin,qp->destaddr,qp->feetxid,qp->feevout)) != 0 ) if ( (txout= LP_gettxout(destcoin,qp->destaddr,qp->feetxid,qp->feevout)) != 0 )
free_json(txout); free_json(txout);
else else
{ {
printf("%s %s dexfee %s/v%d is spent\n",qp->destcoin,qp->destaddr,bits256_str(str,qp->feetxid),qp->feevout); printf("%s %s dexfee %s/v%d is spent\n",destcoin,qp->destaddr,bits256_str(str,qp->feetxid),qp->feevout);
return(-24); return(-24);
} }
} }
@ -383,6 +385,13 @@ uint64_t LP_basesatoshis(double relvolume,double price,uint64_t txfee,uint64_t d
struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iambob,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double relvolume,double price,uint64_t desttxfee) struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iambob,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double relvolume,double price,uint64_t desttxfee)
{ {
struct LP_address *ap; uint64_t fee,targetval,targetval2; int32_t m,mini; struct LP_address_utxo *up,*up2; double ratio; struct LP_address *ap; uint64_t fee,targetval,targetval2; int32_t m,mini; struct LP_address_utxo *up,*up2; double ratio;
if ( coin->etomic[0] != 0 )
{
if ( (coin= LP_coinfind("ETOMIC")) != 0 )
coinaddr = coin->smartaddr;
}
if ( coin == 0 )
return(0);
memset(butxo,0,sizeof(*butxo)); memset(butxo,0,sizeof(*butxo));
if ( iambob != 0 ) if ( iambob != 0 )
{ {
@ -451,7 +460,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb
int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double price,struct LP_quoteinfo *qp) int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double price,struct LP_quoteinfo *qp)
{ {
char pairstr[512],otheraddr[64]; cJSON *reqjson; bits256 privkey; int32_t i,pair=-1,retval = -1,DEXselector = 0; int64_t dtrust; struct basilisk_swap *swap; struct iguana_info *coin,*kmdcoin; char pairstr[512],otheraddr[64]; cJSON *reqjson; bits256 privkey; int32_t i,pair=-1,retval = -1,DEXselector = 0; int64_t dtrust; struct basilisk_swap *swap; struct iguana_info *ecoin,*coin,*kmdcoin;
qp->quotetime = (uint32_t)time(NULL); qp->quotetime = (uint32_t)time(NULL);
if ( (coin= LP_coinfind(qp->srccoin)) == 0 ) if ( (coin= LP_coinfind(qp->srccoin)) == 0 )
{ {
@ -459,6 +468,11 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
return(-1); return(-1);
} }
privkey = LP_privkey(coin->symbol,coin->smartaddr,coin->taddr); privkey = LP_privkey(coin->symbol,coin->smartaddr,coin->taddr);
if ( coin->etomic[0] != 0 )
{
if ( (ecoin= LP_coinfind("ETOMIC")) != 0 )
privkey = LP_privkey(ecoin->symbol,ecoin->smartaddr,ecoin->taddr);
}
if ( bits256_nonz(privkey) != 0 && bits256_cmp(G.LP_mypub25519,qp->srchash) == 0 ) if ( bits256_nonz(privkey) != 0 && bits256_cmp(G.LP_mypub25519,qp->srchash) == 0 )
{ {
LP_requestinit(&qp->R,qp->srchash,qp->desthash,base,qp->satoshis-qp->txfee,rel,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); LP_requestinit(&qp->R,qp->srchash,qp->desthash,base,qp->satoshis-qp->txfee,rel,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector);
@ -484,12 +498,16 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
if ( (kmdcoin= LP_coinfind("KMD")) != 0 ) if ( (kmdcoin= LP_coinfind("KMD")) != 0 )
jadd(reqjson,"proof",LP_instantdex_txids(0,kmdcoin->smartaddr)); jadd(reqjson,"proof",LP_instantdex_txids(0,kmdcoin->smartaddr));
//char str[65]; printf("BOB pubsock.%d binds to %d (%s)\n",pubsock,pair,bits256_str(str,qp->desthash)); //char str[65]; printf("BOB pubsock.%d binds to %d (%s)\n",pubsock,pair,bits256_str(str,qp->desthash));
LP_importaddress(qp->destcoin,qp->destaddr);
LP_otheraddress(qp->srccoin,otheraddr,qp->destcoin,qp->destaddr);
LP_importaddress(qp->srccoin,otheraddr);
bits256 zero; bits256 zero;
memset(zero.bytes,0,sizeof(zero)); memset(zero.bytes,0,sizeof(zero));
for (i=0; i<10; i++) for (i=0; i<1; i++)
{ {
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0));
sleep(3); break;
sleep(10);
if ( swap->received != 0 ) if ( swap->received != 0 )
{ {
printf("swap %u-%u has started t%u\n",swap->I.req.requestid,swap->I.req.quoteid,swap->received); printf("swap %u-%u has started t%u\n",swap->I.req.requestid,swap->I.req.quoteid,swap->received);
@ -499,13 +517,10 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0));
} }
free_json(reqjson); free_json(reqjson);
LP_importaddress(qp->destcoin,qp->destaddr);
LP_otheraddress(qp->srccoin,otheraddr,qp->destcoin,qp->destaddr);
LP_importaddress(qp->srccoin,otheraddr);
retval = 0; retval = 0;
} else printf("error launching swaploop\n"); } else printf("error launching swaploop\n");
} else printf("couldnt bind to any port %s\n",pairstr); } else printf("couldnt bind to any port %s\n",pairstr);
} } else printf("cant find privkey for %s\n",coin->smartaddr);
if ( retval < 0 ) if ( retval < 0 )
{ {
if ( pair >= 0 ) if ( pair >= 0 )
@ -528,7 +543,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q
qp->srchash = destpubkey; qp->srchash = destpubkey;
LP_query(ctx,myipaddr,mypubsock,"request",qp); LP_query(ctx,myipaddr,mypubsock,"request",qp);
LP_Alicequery = *qp, LP_Alicemaxprice = maxprice, Alice_expiration = qp->timestamp + timeout, LP_Alicedestpubkey = destpubkey; LP_Alicequery = *qp, LP_Alicemaxprice = maxprice, Alice_expiration = qp->timestamp + timeout, LP_Alicedestpubkey = destpubkey;
char str[65]; printf("LP_trade %s/%s %.8f vol %.8f dest.(%s) maxprice %.8f\n",qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey),maxprice); char str[65]; printf("LP_trade %s/%s %.8f vol %.8f dest.(%s) maxprice %.8f etomicdest.(%s)\n",qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey),maxprice,qp->etomicdest);
return(LP_recent_swaps(0)); return(LP_recent_swaps(0));
} }
@ -819,7 +834,7 @@ double LP_trades_pricevalidate(struct LP_quoteinfo *qp,struct iguana_info *coin,
memset(autxo,0,sizeof(*autxo)); memset(autxo,0,sizeof(*autxo));
memset(butxo,0,sizeof(*butxo)); memset(butxo,0,sizeof(*butxo));
LP_abutxo_set(autxo,butxo,qp); LP_abutxo_set(autxo,butxo,qp);
if ( strcmp(qp->coinaddr,coin->smartaddr) != 0 ) if ( coin->etomic[0] == 0 && strcmp(qp->coinaddr,coin->smartaddr) != 0 )
{ {
printf("bob is patching qp->coinaddr %s mismatch != %s\n",qp->coinaddr,coin->smartaddr); printf("bob is patching qp->coinaddr %s mismatch != %s\n",qp->coinaddr,coin->smartaddr);
strcpy(qp->coinaddr,coin->smartaddr); strcpy(qp->coinaddr,coin->smartaddr);
@ -844,25 +859,43 @@ double LP_trades_pricevalidate(struct LP_quoteinfo *qp,struct iguana_info *coin,
struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,struct LP_quoteinfo *newqp,char *pairstr) struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,struct LP_quoteinfo *newqp,char *pairstr)
{ {
double price=0.,p=0.,qprice,myprice,bestprice,range,bid,ask; struct iguana_info *coin; struct LP_utxoinfo A,B,*autxo,*butxo; cJSON *reqjson; char str[65]; struct LP_address_utxo *utxos[1000]; int32_t i,r,counter,max = (int32_t)(sizeof(utxos)/sizeof(*utxos)); double price=0.,p=0.,qprice,myprice,bestprice,range,bid,ask; struct iguana_info *coin,*othercoin; struct LP_utxoinfo A,B,*autxo,*butxo; cJSON *reqjson; char str[65]; struct LP_address_utxo *utxos[1000]; int32_t i,r,counter,max = (int32_t)(sizeof(utxos)/sizeof(*utxos));
*newqp = *qp; *newqp = *qp;
qp = newqp; qp = newqp;
//printf("bob %s received REQUEST.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid); //printf("bob %s received REQUEST.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid);
if ( (coin= LP_coinfind(qp->srccoin)) == 0 ) if ( (coin= LP_coinfind(qp->srccoin)) == 0 || (othercoin= LP_coinfind(qp->destcoin)) == 0 )
return(0); return(0);
if ( (myprice= LP_trades_bobprice(&bid,&ask,qp)) == 0. ) if ( (myprice= LP_trades_bobprice(&bid,&ask,qp)) == 0. )
{
printf("myprice %.8f bid %.8f ask %.8f\n",myprice,bid,ask);
return(0); return(0);
}
autxo = &A; autxo = &A;
butxo = &B; butxo = &B;
memset(autxo,0,sizeof(*autxo)); memset(autxo,0,sizeof(*autxo));
memset(butxo,0,sizeof(*butxo)); memset(butxo,0,sizeof(*butxo));
LP_abutxo_set(autxo,butxo,qp); LP_abutxo_set(autxo,butxo,qp);
strcpy(qp->coinaddr,coin->smartaddr);
if ( bits256_nonz(qp->srchash) == 0 || bits256_cmp(qp->srchash,G.LP_mypub25519) == 0 ) if ( bits256_nonz(qp->srchash) == 0 || bits256_cmp(qp->srchash,G.LP_mypub25519) == 0 )
{ {
qprice = (double)qp->destsatoshis / (qp->satoshis - qp->txfee); qprice = (double)qp->destsatoshis / (qp->satoshis - qp->txfee);
strcpy(qp->gui,G.gui); strcpy(qp->gui,G.gui);
strcpy(qp->coinaddr,coin->smartaddr); if ( coin->etomic[0] != 0 )
strcpy(butxo->coinaddr,coin->smartaddr); strcpy(qp->etomicsrc,coin->smartaddr);
else if ( othercoin->etomic[0] != 0 )
strcpy(qp->etomicsrc,othercoin->smartaddr);
if ( coin->etomic[0] != 0 )//|| othercoin->etomic[0] != 0 )
{
struct iguana_info *ecoin;
if ( (ecoin= LP_coinfind("ETOMIC")) != 0 )
strcpy(qp->coinaddr,ecoin->smartaddr);
else
{
printf("ETOMIC coin not found\n");
return(0);
}
}
strcpy(butxo->coinaddr,qp->coinaddr);
qp->srchash = G.LP_mypub25519; qp->srchash = G.LP_mypub25519;
memset(&qp->txid,0,sizeof(qp->txid)); memset(&qp->txid,0,sizeof(qp->txid));
memset(&qp->txid2,0,sizeof(qp->txid2)); memset(&qp->txid2,0,sizeof(qp->txid2));
@ -880,7 +913,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
} }
else else
{ {
printf("ignore as qprice %.8f vs myprice %.8f\n",qprice,myprice); //printf("ignore as qprice %.8f vs myprice %.8f\n",qprice,myprice);
return(0); return(0);
} }
//LP_RTmetrics_update(qp->srccoin,qp->destcoin); //LP_RTmetrics_update(qp->srccoin,qp->destcoin);
@ -892,6 +925,21 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
//printf("LP_address_utxo_reset.%s\n",coin->symbol); //printf("LP_address_utxo_reset.%s\n",coin->symbol);
//LP_address_utxo_reset(coin); //LP_address_utxo_reset(coin);
//printf("done LP_address_utxo_reset.%s\n",coin->symbol); //printf("done LP_address_utxo_reset.%s\n",coin->symbol);
if ( coin->etomic[0] != 0 )
strcpy(qp->etomicsrc,coin->smartaddr);
else if ( othercoin->etomic[0] != 0 )
strcpy(qp->etomicsrc,othercoin->smartaddr);
if ( coin->etomic[0] != 0 )//|| othercoin->etomic[0] != 0 )
{
struct iguana_info *ecoin;
if ( (ecoin= LP_coinfind("ETOMIC")) != 0 )
strcpy(qp->coinaddr,ecoin->smartaddr);
else
{
printf("ETOMIC coin not found\n");
return(0);
}
}
i = 0; i = 0;
while ( i < 33 && price >= myprice ) while ( i < 33 && price >= myprice )
{ {
@ -925,7 +973,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
printf("i.%d qprice %.8f myprice %.8f price %.8f [%.8f]\n",i,qprice,myprice,price,p); printf("i.%d qprice %.8f myprice %.8f price %.8f [%.8f]\n",i,qprice,myprice,price,p);
if ( LP_allocated(qp->txid,qp->vout) == 0 && LP_allocated(qp->txid2,qp->vout2) == 0 ) if ( LP_allocated(qp->txid,qp->vout) == 0 && LP_allocated(qp->txid2,qp->vout2) == 0 )
{ {
printf("found unallocated txids\n"); //printf("found unallocated txids\n");
reqjson = LP_quotejson(qp); reqjson = LP_quotejson(qp);
LP_unavailableset(qp->txid,qp->vout,qp->timestamp + LP_RESERVETIME,qp->desthash); LP_unavailableset(qp->txid,qp->vout,qp->timestamp + LP_RESERVETIME,qp->desthash);
LP_unavailableset(qp->txid2,qp->vout2,qp->timestamp + LP_RESERVETIME,qp->desthash); LP_unavailableset(qp->txid2,qp->vout2,qp->timestamp + LP_RESERVETIME,qp->desthash);
@ -939,7 +987,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
memset(zero.bytes,0,sizeof(zero)); memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0));
free_json(reqjson); free_json(reqjson);
printf("Send RESERVED id.%llu\n",(long long)qp->aliceid); //printf("Send RESERVED id.%llu\n",(long long)qp->aliceid);
return(qp); return(qp);
} else printf("request processing selected ineligible utxos?\n"); } else printf("request processing selected ineligible utxos?\n");
return(0); return(0);
@ -953,7 +1001,7 @@ struct LP_quoteinfo *LP_trades_gotreserved(void *ctx,struct LP_quoteinfo *qp,str
qp = newqp; qp = newqp;
if ( (qprice= LP_trades_alicevalidate(ctx,qp)) > 0. ) if ( (qprice= LP_trades_alicevalidate(ctx,qp)) > 0. )
{ {
printf("got qprice %.8f\n",qprice); //printf("got qprice %.8f\n",qprice);
LP_aliceid(qp->tradeid,qp->aliceid,"reserved",0,0); LP_aliceid(qp->tradeid,qp->aliceid,"reserved",0,0);
if ( (retstr= LP_quotereceived(qp)) != 0 ) if ( (retstr= LP_quotereceived(qp)) != 0 )
free(retstr); free(retstr);
@ -976,6 +1024,7 @@ struct LP_quoteinfo *LP_trades_gotconnect(void *ctx,struct LP_quoteinfo *qp,stru
return(0); return(0);
if ( LP_reservation_check(qp->txid,qp->vout,qp->desthash) == 0 && LP_reservation_check(qp->txid2,qp->vout2,qp->desthash) == 0 ) if ( LP_reservation_check(qp->txid,qp->vout,qp->desthash) == 0 && LP_reservation_check(qp->txid2,qp->vout2,qp->desthash) == 0 )
{ {
printf("CONNECT STARTBOB!\n");
LP_connectstartbob(ctx,LP_mypubsock,qp->srccoin,qp->destcoin,qprice,qp); LP_connectstartbob(ctx,LP_mypubsock,qp->srccoin,qp->destcoin,qprice,qp);
return(qp); return(qp);
} else printf("connect message from non-reserved (%llu)\n",(long long)qp->aliceid); } else printf("connect message from non-reserved (%llu)\n",(long long)qp->aliceid);
@ -990,7 +1039,7 @@ struct LP_quoteinfo *LP_trades_gotconnected(void *ctx,struct LP_quoteinfo *qp,st
qp = newqp; qp = newqp;
if ( LP_trades_alicevalidate(ctx,qp) > 0. ) if ( LP_trades_alicevalidate(ctx,qp) > 0. )
{ {
//printf("LP_trades_alicevalidate fine\n"); printf("CONNECTED ALICE\n");
LP_aliceid(qp->tradeid,qp->aliceid,"connected",0,0); LP_aliceid(qp->tradeid,qp->aliceid,"connected",0,0);
if ( (retstr= LP_connectedalice(qp,pairstr)) != 0 ) if ( (retstr= LP_connectedalice(qp,pairstr)) != 0 )
free(retstr); free(retstr);
@ -1222,7 +1271,11 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
char *method,str[65]; int32_t i,num,DEXselector = 0; uint64_t aliceid; double qprice,bestprice,price,bid,ask; cJSON *proof; uint64_t rq; struct iguana_info *coin; struct LP_quoteinfo Q,Q2; int32_t counter,retval=-1; char *method,str[65]; int32_t i,num,DEXselector = 0; uint64_t aliceid; double qprice,bestprice,price,bid,ask; cJSON *proof; uint64_t rq; struct iguana_info *coin; struct LP_quoteinfo Q,Q2; int32_t counter,retval=-1;
if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"reserved") == 0 ||strcmp(method,"connected") == 0 || strcmp(method,"request") == 0 || strcmp(method,"connect") == 0) ) if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"reserved") == 0 ||strcmp(method,"connected") == 0 || strcmp(method,"request") == 0 || strcmp(method,"connect") == 0) )
{ {
LP_quoteparse(&Q,argjson); if ( LP_quoteparse(&Q,argjson) < 0 )
{
printf("ERROR parsing.(%s)\n",jprint(argjson,0));
return(1);
}
if ( Q.satoshis < Q.txfee ) if ( Q.satoshis < Q.txfee )
return(1); return(1);
LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector); LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector);
@ -1418,11 +1471,26 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel
return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); return(clonestr("{\"error\":\"cant set ordermatch quote\"}"));
if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,G.LP_mypub25519,autxo->coinaddr) < 0 ) if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,G.LP_mypub25519,autxo->coinaddr) < 0 )
return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); return(clonestr("{\"error\":\"cant set ordermatch quote info\"}"));
if ( relcoin->etomic[0] != 0 || basecoin->etomic[0] != 0 )
{
struct iguana_info *coin;
if ( relcoin->etomic[0] != 0 )
strcpy(Q.etomicdest,relcoin->smartaddr);
else if (basecoin->etomic[0] != 0 )
{
strcpy(Q.etomicdest,basecoin->smartaddr);
printf("Q.etomicdest (%s)\n",Q.etomicdest);
}
if ( relcoin->etomic[0] != 0 )
{
if ((coin= LP_coinfind("ETOMIC")) != 0 )
strcpy(Q.destaddr,coin->smartaddr);
else return(clonestr("{\"error\":\"cant find ETOMIC\"}"));
}
}
int32_t changed; int32_t changed;
if ( strcmp(base,"BTC") == 0 || strcmp("BTC",rel) == 0 ) LP_mypriceset(&changed,rel,base,1. / maxprice);
printf("%s/%s maxprice %.8f qprice %.8f txfee %.8f desttxfee %.8f\n",base,rel,maxprice,(double)destsatoshis/(bestsatoshis - txfee),dstr(txfee),dstr(desttxfee)); LP_mypriceset(&changed,base,rel,0.);
LP_mypriceset(&changed,autxo->coin,base,1. / maxprice);
LP_mypriceset(&changed,base,autxo->coin,0.);
return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid,destpubkey)); return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid,destpubkey));
} }

4
iguana/exchanges/LP_peers.c

@ -113,7 +113,7 @@ void LP_peer_pairsock(bits256 pubkey)
struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char *ipaddr,uint16_t port,uint16_t pushport,uint16_t subport,int32_t isLP,uint32_t sessionid,uint16_t netid) struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char *ipaddr,uint16_t port,uint16_t pushport,uint16_t subport,int32_t isLP,uint32_t sessionid,uint16_t netid)
{ {
uint32_t ipbits; int32_t valid,pushsock,subsock,timeout; char checkip[64],pushaddr[64],subaddr[64]; struct LP_peerinfo *peer = 0; uint32_t ipbits; int32_t valid,pushsock,subsock,timeout; char checkip[64],pushaddr[128],subaddr[128]; struct LP_peerinfo *peer = 0;
#ifdef LP_STRICTPEERS #ifdef LP_STRICTPEERS
if ( strncmp("5.9.253",ipaddr,strlen("5.9.253")) != 0 ) if ( strncmp("5.9.253",ipaddr,strlen("5.9.253")) != 0 )
return(0); return(0);
@ -275,7 +275,7 @@ void LP_peer_recv(char *ipaddr,int32_t ismine,struct LP_pubkey_info *pubp)
if ( (peer= LP_peerfind((uint32_t)calc_ipbits(ipaddr),RPC_port)) != 0 ) if ( (peer= LP_peerfind((uint32_t)calc_ipbits(ipaddr),RPC_port)) != 0 )
{ {
peer->numrecv++; peer->numrecv++;
if ( ismine != 0 && bits256_cmp(G.LP_mypub25519,pubp->pubkey) != 0 && (bits256_nonz(peer->pubkey) == 0 || pubp->pairsock < 0) ) if ( ismine != 0 && bits256_cmp(G.LP_mypub25519,pubp->pubkey) != 0 && (bits256_cmp(peer->pubkey,pubp->pubkey) != 0 || pubp->pairsock != peer->pairsock) )
{ {
peer->pubkey = pubp->pubkey; peer->pubkey = pubp->pubkey;
pubp->pairsock = peer->pairsock; pubp->pairsock = peer->pairsock;

7
iguana/exchanges/LP_portfolio.c

@ -848,9 +848,14 @@ void prices_loop(void *ctx)
{ {
char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp; char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp;
strcpy(prices_loop_stats.name,"prices_loop"); strcpy(prices_loop_stats.name,"prices_loop");
prices_loop_stats.threshold = 191000.; prices_loop_stats.threshold = 600000.;
while ( LP_STOP_RECEIVED == 0 ) while ( LP_STOP_RECEIVED == 0 )
{ {
if ( G.initializing != 0 )
{
sleep(1);
continue;
}
//printf("prices loop autoprices.%d autorefs.%d\n",LP_autoprices,num_LP_autorefs); //printf("prices loop autoprices.%d autorefs.%d\n",LP_autoprices,num_LP_autorefs);
LP_millistats_update(&prices_loop_stats); LP_millistats_update(&prices_loop_stats);
LP_tradebots_timeslice(ctx); LP_tradebots_timeslice(ctx);

10
iguana/exchanges/LP_prices.c

@ -512,7 +512,7 @@ char *LP_myprices()
int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price)
{ {
struct LP_priceinfo *basepp,*relpp; struct LP_pubkey_info *pubp; double minprice,maxprice,margin,buymargin,sellmargin; struct LP_priceinfo *basepp=0,*relpp=0; struct LP_pubkey_info *pubp; double minprice,maxprice,margin,buymargin,sellmargin;
*changedp = 0; *changedp = 0;
//if ( strcmp("DEX",base) == 0 || strcmp("DEX",rel) == 0 ) //if ( strcmp("DEX",base) == 0 || strcmp("DEX",rel) == 0 )
// printf("%s/%s setprice %.8f\n",base,rel,price); // printf("%s/%s setprice %.8f\n",base,rel,price);
@ -553,7 +553,7 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price)
}*/ }*/
basepp->myprices[relpp->ind] = price; // ask basepp->myprices[relpp->ind] = price; // ask
//printf("LP_mypriceset base.%s rel.%s <- price %.8f\n",base,rel,price); //printf("LP_mypriceset base.%s rel.%s <- price %.8f\n",base,rel,price);
//relpp->myprices[basepp->ind] = (1. / price); // bid //relpp->myprices[basepp->ind] = (1. / price); // bid, but best to do one dir at a time
if ( (pubp= LP_pubkeyadd(G.LP_mypub25519)) != 0 ) if ( (pubp= LP_pubkeyadd(G.LP_mypub25519)) != 0 )
{ {
pubp->timestamp = (uint32_t)time(NULL); pubp->timestamp = (uint32_t)time(NULL);
@ -563,7 +563,9 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price)
//pubp->matrix[relpp->ind][basepp->ind] = (1. / price); //pubp->matrix[relpp->ind][basepp->ind] = (1. / price);
} }
return(0); return(0);
} else return(-1); }
printf("base.%s rel.%s %p %p price %.8f error case\n",base!=0?base:"",rel!=0?rel:"",basepp,relpp,price);
return(-1);
} }
double LP_price(char *base,char *rel) double LP_price(char *base,char *rel)
@ -815,7 +817,7 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char *
} }
if ( pubp->timestamp < oldest ) if ( pubp->timestamp < oldest )
continue; continue;
bitcoin_address(base,coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); bitcoin_address(base,coinaddr,basecoin->taddr,basecoin->pubtype,pubp->pubsecp,33);
avesatoshis = maxsatoshis = n = 0; avesatoshis = maxsatoshis = n = 0;
ap = 0; ap = 0;
if ( (price= LP_pubkey_price(&n,&avesatoshis,&maxsatoshis,pubp,baseid,relid)) > SMALLVAL ) //pubp->matrix[baseid][relid]) > SMALLVAL )//&& pubp->timestamps[baseid][relid] >= oldest ) if ( (price= LP_pubkey_price(&n,&avesatoshis,&maxsatoshis,pubp,baseid,relid)) > SMALLVAL ) //pubp->matrix[baseid][relid]) > SMALLVAL )//&& pubp->timestamps[baseid][relid] >= oldest )

38
iguana/exchanges/LP_privkey.c

@ -262,12 +262,17 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan
} }
if ( passphrase != 0 && passphrase[0] != 0 ) if ( passphrase != 0 && passphrase[0] != 0 )
{ {
calc_NXTaddr(G.LP_NXTaddr,userpub.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); if ( strlen(passphrase) == 66 && passphrase[0] == '0' && passphrase[1] == 'x' && is_hexstr(passphrase+2,0) == 64 )
conv_NXTpassword(privkey.bytes,pubkeyp->bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); {
privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64; decode_hex(privkey.bytes,32,passphrase+2);
//vcalc_sha256(0,checkkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); //printf("ETH style privkey.(%s)\n",passphrase);
//printf("SHA256.(%s) ",bits256_str(pstr,checkkey)); }
//printf("privkey.(%s)\n",bits256_str(pstr,privkey)); else
{
calc_NXTaddr(G.LP_NXTaddr,userpub.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
conv_NXTpassword(privkey.bytes,pubkeyp->bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64;
}
bitcoin_priv2wif(coin->symbol,coin->wiftaddr,tmpstr,privkey,coin->wiftype); bitcoin_priv2wif(coin->symbol,coin->wiftaddr,tmpstr,privkey,coin->wiftype);
bitcoin_wif2priv(coin->symbol,coin->wiftaddr,&tmptype,&checkkey,tmpstr); bitcoin_wif2priv(coin->symbol,coin->wiftaddr,&tmptype,&checkkey,tmpstr);
if ( bits256_cmp(privkey,checkkey) != 0 ) if ( bits256_cmp(privkey,checkkey) != 0 )
@ -294,6 +299,27 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan
RS_encode(G.LP_NXTaddr,nxtaddr); RS_encode(G.LP_NXTaddr,nxtaddr);
} }
bitcoin_priv2pub(ctx,coin->symbol,coin->pubkey33,coin->smartaddr,privkey,coin->taddr,coin->pubtype); bitcoin_priv2pub(ctx,coin->symbol,coin->pubkey33,coin->smartaddr,privkey,coin->taddr,coin->pubtype);
#ifndef NOTETOMIC
if ( coin->etomic[0] != 0 )
{
uint8_t check64[64],checktype,checkrmd160[20],rmd160[20]; char checkaddr[64],checkaddr2[64];
if ( LP_etomic_priv2pub(check64,privkey) == 0 )
{
if ( memcmp(check64,coin->pubkey33+1,32) == 0 )
{
if ( LP_etomic_priv2addr(checkaddr,privkey) == 0 && LP_etomic_pub2addr(checkaddr2,check64) == 0 && strcmp(checkaddr,checkaddr2) == 0 )
{
//printf("addr is (%s)\n",checkaddr);
strcpy(coin->smartaddr,checkaddr);
decode_hex(checkrmd160,20,checkaddr+2);
bitcoin_addr2rmd160(coin->symbol,coin->taddr,&checktype,rmd160,checkaddr);
if ( memcmp(rmd160,checkrmd160,20) != 0 )
printf("rmd160 doesnt match\n");
} else printf("error getting addr (%s) != (%s)\n",checkaddr,checkaddr2);
} else printf("pubkey 64 mismatch\n");
} else printf("error creating pubkey\n");
}
#endif
OS_randombytes(tmpkey.bytes,sizeof(tmpkey)); OS_randombytes(tmpkey.bytes,sizeof(tmpkey));
if ( bits256_nonz(privkey) == 0 || (siglen= bitcoin_sign(ctx,coin->symbol,sig,tmpkey,privkey,0)) <= 0 ) if ( bits256_nonz(privkey) == 0 || (siglen= bitcoin_sign(ctx,coin->symbol,sig,tmpkey,privkey,0)) <= 0 )
{ {

197
iguana/exchanges/LP_remember.c

@ -17,7 +17,6 @@
// LP_remember.c // LP_remember.c
// marketmaker // marketmaker
// //
void basilisk_dontforget_userdata(char *userdataname,FILE *fp,uint8_t *script,int32_t scriptlen) void basilisk_dontforget_userdata(char *userdataname,FILE *fp,uint8_t *script,int32_t scriptlen)
{ {
int32_t i; char scriptstr[513]; int32_t i; char scriptstr[513];
@ -66,7 +65,22 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx
fprintf(fp,",\"expiration\":%u",swap->I.expiration); fprintf(fp,",\"expiration\":%u",swap->I.expiration);
fprintf(fp,",\"iambob\":%d",swap->I.iambob); fprintf(fp,",\"iambob\":%d",swap->I.iambob);
fprintf(fp,",\"bobcoin\":\"%s\"",swap->I.bobstr); fprintf(fp,",\"bobcoin\":\"%s\"",swap->I.bobstr);
if ( swap->I.bobtomic[0] != 0 )
fprintf(fp,",\"bobtomic\":\"%s\"",swap->I.bobtomic);
if ( swap->I.etomicsrc[0] != 0 )
fprintf(fp,",\"etomicsrc\":\"%s\"",swap->I.etomicsrc);
if (swap->bobdeposit.I.ethTxid[0] != 0) {
fprintf(fp,",\"bobDepositEthTx\":\"%s\"", swap->bobdeposit.I.ethTxid);
}
if (swap->bobpayment.I.ethTxid[0] != 0) {
fprintf(fp,",\"bobPaymentEthTx\":\"%s\"", swap->bobpayment.I.ethTxid);
}
fprintf(fp,",\"alicecoin\":\"%s\"",swap->I.alicestr); fprintf(fp,",\"alicecoin\":\"%s\"",swap->I.alicestr);
if ( swap->I.alicetomic[0] != 0 )
fprintf(fp,",\"alicetomic\":\"%s\"",swap->I.alicetomic);
if ( swap->I.etomicdest[0] != 0 )
fprintf(fp,",\"etomicdest\":\"%s\"",swap->I.etomicdest);
fprintf(fp,",\"lock\":%u",locktime); fprintf(fp,",\"lock\":%u",locktime);
fprintf(fp,",\"amount\":%.8f",dstr(rawtx->I.amount)); fprintf(fp,",\"amount\":%.8f",dstr(rawtx->I.amount));
if ( bits256_nonz(triggertxid) != 0 ) if ( bits256_nonz(triggertxid) != 0 )
@ -120,6 +134,7 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx
init_hexbytes_noT(secretBn256str,swap->I.secretBn256,32); init_hexbytes_noT(secretBn256str,swap->I.secretBn256,32);
fprintf(fp,",\"secretBn256\":\"%s\"",secretBn256str); fprintf(fp,",\"secretBn256\":\"%s\"",secretBn256str);
} }
for (i=0; i<2; i++) for (i=0; i<2; i++)
if ( bits256_nonz(swap->I.myprivs[i]) != 0 ) if ( bits256_nonz(swap->I.myprivs[i]) != 0 )
fprintf(fp,",\"myprivs%d\":\"%s\"",i,bits256_str(str,swap->I.myprivs[i])); fprintf(fp,",\"myprivs%d\":\"%s\"",i,bits256_str(str,swap->I.myprivs[i]));
@ -235,7 +250,7 @@ bits256 basilisk_swap_privbob_extract(char *symbol,bits256 spendtxid,int32_t vin
privkey.bytes[31 - i] = script[siglen+2+i]; privkey.bytes[31 - i] = script[siglen+2+i];
else privkey.bytes[i] = script[siglen+2+i]; else privkey.bytes[i] = script[siglen+2+i];
} }
//char str[65]; printf("extracted privbob.(%s)\n",bits256_str(str,privkey)); char str[65]; printf("extracted privbob.(%s)\n",bits256_str(str,privkey));
} }
return(privkey); return(privkey);
} }
@ -400,15 +415,20 @@ int32_t basilisk_swap_isfinished(uint32_t requestid,uint32_t quoteid,uint32_t ex
int32_t i,n = 0; uint32_t now = (uint32_t)time(NULL); int32_t i,n = 0; uint32_t now = (uint32_t)time(NULL);
if ( bits256_nonz(paymentspent) != 0 && bits256_nonz(Apaymentspent) != 0 && bits256_nonz(depositspent) != 0 ) if ( bits256_nonz(paymentspent) != 0 && bits256_nonz(Apaymentspent) != 0 && bits256_nonz(depositspent) != 0 )
return(1); return(1);
else if ( sentflags[BASILISK_BOBPAYMENT] == 0 && bits256_nonz(txids[BASILISK_BOBPAYMENT]) == 0 && bits256_nonz(Apaymentspent) != 0 && bits256_nonz(depositspent) != 0 )
return(1);
else if ( sentflags[BASILISK_BOBPAYMENT] == 0 && bits256_nonz(txids[BASILISK_BOBPAYMENT]) == 0 && sentflags[BASILISK_ALICEPAYMENT] == 0 && bits256_nonz(txids[BASILISK_ALICEPAYMENT]) == 0 && bits256_nonz(depositspent) != 0 )
return(1);
else if ( sentflags[BASILISK_BOBPAYMENT] != 0 && sentflags[BASILISK_ALICEPAYMENT] != 0 && sentflags[BASILISK_BOBDEPOSIT] != 0 && sentflags[BASILISK_BOBRECLAIM] != 0 ) else if ( sentflags[BASILISK_BOBPAYMENT] != 0 && sentflags[BASILISK_ALICEPAYMENT] != 0 && sentflags[BASILISK_BOBDEPOSIT] != 0 && sentflags[BASILISK_BOBRECLAIM] != 0 )
{ {
if ( sentflags[BASILISK_ALICECLAIM] != 0 ) if ( sentflags[BASILISK_ALICECLAIM] != 0 )
{ {
printf("edge case unspendable alicepayment %u-%u\n",requestid,quoteid); if ( iambob != 0 )
return(1); {
printf("used to be edge case unspendable alicepayment %u-%u\n",requestid,quoteid);
return(0);
} else return(1);
} }
else if ( iambob != 0 && sentflags[BASILISK_ALICECLAIM] != 0 )
return(1);
} }
if ( now > expiration - INSTANTDEX_LOCKTIME ) if ( now > expiration - INSTANTDEX_LOCKTIME )
{ {
@ -446,9 +466,9 @@ int32_t basilisk_swap_isfinished(uint32_t requestid,uint32_t quoteid,uint32_t ex
{ {
if ( bits256_nonz(depositspent) != 0 ) if ( bits256_nonz(depositspent) != 0 )
{ {
if ( bits256_nonz(Apaymentspent) == 0 && sentflags[BASILISK_BOBREFUND] == 0 ) //if ( bits256_nonz(Apaymentspent) == 0 && sentflags[BASILISK_BOBREFUND] == 0 )
printf("bob was too late in claiming bobrefund %u-%u\n",requestid,quoteid); // printf("used to be bob was too late in claiming bobrefund %u-%u\n",requestid,quoteid);
return(1); return(0);
} }
} }
//else if ( bits256_nonz(Apaymentspent) != 0 ) //else if ( bits256_nonz(Apaymentspent) != 0 )
@ -588,9 +608,17 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap)
jaddstr(item,"Agui",rswap->Agui); jaddstr(item,"Agui",rswap->Agui);
jaddstr(item,"gui",rswap->gui); jaddstr(item,"gui",rswap->gui);
jaddstr(item,"bob",rswap->src); jaddstr(item,"bob",rswap->src);
if ( rswap->bobtomic[0] != 0 )
jaddstr(item,"bobtomic",rswap->bobtomic);
if ( rswap->etomicsrc[0] != 0 )
jaddstr(item,"etomicsrc",rswap->etomicsrc);
jaddnum(item,"srcamount",dstr(rswap->srcamount)); jaddnum(item,"srcamount",dstr(rswap->srcamount));
jaddnum(item,"bobtxfee",dstr(rswap->Btxfee)); jaddnum(item,"bobtxfee",dstr(rswap->Btxfee));
jaddstr(item,"alice",rswap->dest); jaddstr(item,"alice",rswap->dest);
if ( rswap->alicetomic[0] != 0 )
jaddstr(item,"alicetomic",rswap->alicetomic);
if ( rswap->etomicdest[0] != 0 )
jaddstr(item,"etomicdest",rswap->etomicdest);
jaddnum(item,"destamount",dstr(rswap->destamount)); jaddnum(item,"destamount",dstr(rswap->destamount));
jaddnum(item,"alicetxfee",dstr(rswap->Atxfee)); jaddnum(item,"alicetxfee",dstr(rswap->Atxfee));
jadd64bits(item,"aliceid",rswap->aliceid); jadd64bits(item,"aliceid",rswap->aliceid);
@ -638,6 +666,8 @@ int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t
safecopy(rswap->Bgui,jstr(item,"Bgui"),sizeof(rswap->Bgui)); safecopy(rswap->Bgui,jstr(item,"Bgui"),sizeof(rswap->Bgui));
safecopy(rswap->Agui,jstr(item,"Agui"),sizeof(rswap->Agui)); safecopy(rswap->Agui,jstr(item,"Agui"),sizeof(rswap->Agui));
safecopy(rswap->gui,jstr(item,"gui"),sizeof(rswap->gui)); safecopy(rswap->gui,jstr(item,"gui"),sizeof(rswap->gui));
safecopy(rswap->bobtomic,jstr(item,"bobtomic"),sizeof(rswap->bobtomic));
safecopy(rswap->alicetomic,jstr(item,"alicetomic"),sizeof(rswap->alicetomic));
rswap->tradeid = juint(item,"tradeid"); rswap->tradeid = juint(item,"tradeid");
rswap->aliceid = j64bits(item,"aliceid"); rswap->aliceid = j64bits(item,"aliceid");
if ( (secretstr= jstr(item,"secretAm")) != 0 && strlen(secretstr) == 40 ) if ( (secretstr= jstr(item,"secretAm")) != 0 && strlen(secretstr) == 40 )
@ -827,6 +857,31 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap,int32_t forceflag)
free_json(txobj); free_json(txobj);
continue; continue;
} }
if (jstr(txobj,"etomicsrc") != 0) {
strcpy(rswap->etomicsrc,jstr(txobj,"etomicsrc"));
}
if (jstr(txobj,"etomicdest") != 0) {
strcpy(rswap->etomicdest,jstr(txobj,"etomicdest"));
}
if (jstr(txobj,"bobDepositEthTx") != 0) {
strcpy(rswap->bobDepositEthTx, jstr(txobj,"bobDepositEthTx"));
}
if (jstr(txobj,"bobPaymentEthTx") != 0) {
strcpy(rswap->bobPaymentEthTx, jstr(txobj,"bobPaymentEthTx"));
}
if (jstr(txobj,"bobtomic") != 0) {
strcpy(rswap->bobtomic, jstr(txobj,"bobtomic"));
}
if (jstr(txobj,"alicetomic") != 0) {
strcpy(rswap->alicetomic, jstr(txobj,"alicetomic"));
}
rswap->txids[i] = txid; rswap->txids[i] = txid;
if ( jstr(txobj,"Apayment") != 0 ) if ( jstr(txobj,"Apayment") != 0 )
safecopy(rswap->alicepaymentaddr,jstr(txobj,"Apayment"),sizeof(rswap->alicepaymentaddr)); safecopy(rswap->alicepaymentaddr,jstr(txobj,"Apayment"),sizeof(rswap->alicepaymentaddr));
@ -843,6 +898,7 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap,int32_t forceflag)
{ {
rswap->Predeemlen >>= 1; rswap->Predeemlen >>= 1;
decode_hex(rswap->Predeemscript,rswap->Predeemlen,rstr); decode_hex(rswap->Predeemscript,rswap->Predeemlen,rstr);
//printf("%p Predeemscript.(%s)\n",rswap->Predeemscript,rstr);
} }
else if ( strcmp(txnames[i],"bobdeposit") == 0 && (rstr= jstr(txobj,"redeem")) != 0 && (rswap->Dredeemlen= is_hexstr(rstr,0)) > 0 ) else if ( strcmp(txnames[i],"bobdeposit") == 0 && (rstr= jstr(txobj,"redeem")) != 0 && (rswap->Dredeemlen= is_hexstr(rstr,0)) > 0 )
{ {
@ -880,7 +936,7 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap,int32_t forceflag)
{ {
if ( (sentobj= LP_gettx(symbol,txid,1)) == 0 ) if ( (sentobj= LP_gettx(symbol,txid,1)) == 0 )
{ {
char str2[65]; printf("%s %s ready to broadcast %s r%u q%u\n",symbol,bits256_str(str2,txid),txnames[i],rswap->requestid,rswap->quoteid); //char str2[65]; printf("%s %s ready to broadcast %s r%u q%u\n",symbol,bits256_str(str2,txid),txnames[i],rswap->requestid,rswap->quoteid);
} }
else else
{ {
@ -898,6 +954,7 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap,int32_t forceflag)
//printf("%s %s %.8f\n",txnames[i],bits256_str(str,txid),dstr(value)); //printf("%s %s %.8f\n",txnames[i],bits256_str(str,txid),dstr(value));
} }
} }
free_json(txobj); free_json(txobj);
} //else printf("no symbol\n"); } //else printf("no symbol\n");
free(fstr); free(fstr);
@ -976,7 +1033,7 @@ int32_t LP_spends_set(struct LP_swap_remember *rswap)
cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid,int32_t forceflag,int32_t pendingonly) cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid,int32_t forceflag,int32_t pendingonly)
{ {
static void *ctx; static void *ctx;
struct LP_swap_remember rswap; int32_t i,j,flag,numspent,len,secretstart,redeemlen; char str[65],*srcAdest,*srcBdest,*destAdest,*destBdest,otheraddr[64],*fstr,fname[512]; cJSON *item,*txoutobj,*retjson; bits256 rev,signedtxid,zero,deadtxid; uint32_t claimtime; struct iguana_info *bob=0,*alice=0; uint8_t redeemscript[1024],userdata[1024]; long fsize; struct LP_swap_remember rswap; int32_t i,j,flag,numspent,len,secretstart,redeemlen; char str[65],*srcAdest,*srcBdest,*destAdest,*destBdest,otheraddr[64],*fstr,fname[512],bobtomic[128],alicetomic[128],bobstr[65],alicestr[65]; cJSON *item,*txoutobj,*retjson; bits256 rev,revAm,signedtxid,zero,deadtxid; uint32_t claimtime; struct iguana_info *bob=0,*alice=0; uint8_t redeemscript[1024],userdata[1024]; long fsize;
sprintf(fname,"%s/SWAPS/%u-%u.finished",GLOBAL_DBDIR,requestid,quoteid), OS_compatible_path(fname); sprintf(fname,"%s/SWAPS/%u-%u.finished",GLOBAL_DBDIR,requestid,quoteid), OS_compatible_path(fname);
if ( (fstr= OS_filestr(&fsize,fname)) != 0 ) if ( (fstr= OS_filestr(&fsize,fname)) != 0 )
{ {
@ -1001,8 +1058,11 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
otheraddr[0] = 0; otheraddr[0] = 0;
claimtime = (uint32_t)time(NULL) - 777; claimtime = (uint32_t)time(NULL) - 777;
srcAdest = srcBdest = destAdest = destBdest = 0; srcAdest = srcBdest = destAdest = destBdest = 0;
//printf("request.%u quoteid.%u\n",requestid,quoteid); alice = LP_coinfind(rswap.alicecoin);
if ( rswap.bobcoin[0] == 0 || rswap.alicecoin[0] == 0 || strcmp(rswap.bobcoin,rswap.src) != 0 || strcmp(rswap.alicecoin,rswap.dest) != 0 ) bob = LP_coinfind(rswap.bobcoin);
LP_etomicsymbol(bobstr,bobtomic,rswap.src);
LP_etomicsymbol(alicestr,alicetomic,rswap.dest);
if ( rswap.bobcoin[0] == 0 || rswap.alicecoin[0] == 0 || strcmp(rswap.bobcoin,bobstr) != 0 || strcmp(rswap.alicecoin,alicestr) != 0 )
{ {
//printf("legacy r%u-q%u DB SWAPS.(%u %u) %llu files BOB.(%s) Alice.(%s) src.(%s) dest.(%s)\n",requestid,quoteid,rswap.requestid,rswap.quoteid,(long long)rswap.aliceid,rswap.bobcoin,rswap.alicecoin,rswap.src,rswap.dest); //printf("legacy r%u-q%u DB SWAPS.(%u %u) %llu files BOB.(%s) Alice.(%s) src.(%s) dest.(%s)\n",requestid,quoteid,rswap.requestid,rswap.quoteid,(long long)rswap.aliceid,rswap.bobcoin,rswap.alicecoin,rswap.src,rswap.dest);
cJSON *retjson = cJSON_CreateObject(); cJSON *retjson = cJSON_CreateObject();
@ -1017,9 +1077,6 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
return(retjson); return(retjson);
//return(cJSON_Parse("{\"error\":\"mismatched bob/alice vs src/dest coins??\"}")); //return(cJSON_Parse("{\"error\":\"mismatched bob/alice vs src/dest coins??\"}"));
} }
alice = LP_coinfind(rswap.alicecoin);
bob = LP_coinfind(rswap.bobcoin);
//printf("request.%u quoteid.%u alice.%s bob.%s\n",requestid,quoteid,alice!=0?alice->symbol:"",bob!=0?bob->symbol:"");
rswap.Atxfee = LP_txfeecalc(alice,rswap.Atxfee,0); rswap.Atxfee = LP_txfeecalc(alice,rswap.Atxfee,0);
rswap.Btxfee = LP_txfeecalc(bob,rswap.Btxfee,0); rswap.Btxfee = LP_txfeecalc(bob,rswap.Btxfee,0);
if ( rswap.iambob == 0 ) if ( rswap.iambob == 0 )
@ -1034,6 +1091,9 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
printf("this isnt my swap! alice.(%s vs %s)\n",alice->smartaddr,rswap.Adestaddr); printf("this isnt my swap! alice.(%s vs %s)\n",alice->smartaddr,rswap.Adestaddr);
cJSON *retjson = cJSON_CreateObject(); cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","swap for different account"); jaddstr(retjson,"error","swap for different account");
jaddstr(retjson,"alice",alice->symbol);
jaddstr(retjson,"aliceaddr",alice->smartaddr);
jaddstr(retjson,"dest",rswap.dest);
jaddnum(retjson,"requestid",requestid); jaddnum(retjson,"requestid",requestid);
jaddnum(retjson,"quoteid",quoteid); jaddnum(retjson,"quoteid",quoteid);
return(retjson); return(retjson);
@ -1070,6 +1130,9 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
printf("this isnt my swap! bob.(%s vs %s)\n",bob->smartaddr,rswap.destaddr); printf("this isnt my swap! bob.(%s vs %s)\n",bob->smartaddr,rswap.destaddr);
cJSON *retjson = cJSON_CreateObject(); cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","swap for different account"); jaddstr(retjson,"error","swap for different account");
jaddstr(retjson,"bob",bob->symbol);
jaddstr(retjson,"bobaddr",bob->smartaddr);
jaddstr(retjson,"src",rswap.src);
jaddnum(retjson,"requestid",requestid); jaddnum(retjson,"requestid",requestid);
jaddnum(retjson,"quoteid",quoteid); jaddnum(retjson,"quoteid",quoteid);
return(retjson); return(retjson);
@ -1141,23 +1204,32 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
memset(rev.bytes,0,sizeof(rev)); memset(rev.bytes,0,sizeof(rev));
for (j=0; j<32; j++) for (j=0; j<32; j++)
rev.bytes[j] = rswap.privAm.bytes[31 - j]; rev.bytes[j] = rswap.privAm.bytes[31 - j];
//revcalc_rmd160_sha256(secretAm,rev);//privAm); redeemlen = basilisk_swap_bobredeemscript(0,&secretstart,redeemscript,rswap.plocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,rev,rswap.privBn,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256);
//vcalc_sha256(0,secretAm256,rev.bytes,sizeof(rev));
if ( rswap.Predeemlen != 0 ) if ( rswap.Predeemlen != 0 )
redeemlen = rswap.Predeemlen, memcpy(redeemscript,rswap.Predeemscript,rswap.Predeemlen); {
else redeemlen = basilisk_swap_bobredeemscript(0,&secretstart,redeemscript,rswap.plocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,rev,rswap.privBn,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256); if ( rswap.Predeemlen != redeemlen || memcmp(redeemscript,rswap.Predeemscript,redeemlen) != 0 )
printf("Predeemscript error len %d vs %d, cmp.%d\n",rswap.Predeemlen,redeemlen,memcmp(redeemscript,rswap.Predeemscript,redeemlen));
//else printf("Predeem matches\n");
} else printf("%p Predeemscript missing\n",rswap.Predeemscript);
len = basilisk_swapuserdata(userdata,rev,0,rswap.myprivs[0],redeemscript,redeemlen); len = basilisk_swapuserdata(userdata,rev,0,rswap.myprivs[0],redeemscript,redeemlen);
if ( 0 )
{ {
char privaddr[64]; uint8_t privpub33[33]; uint8_t secretAm[20];
bitcoin_pubkey33(ctx,privpub33,rswap.myprivs[0]); calc_rmd160_sha256(secretAm,rswap.privAm.bytes,sizeof(rswap.privAm));
bitcoin_address(rswap.bobcoin,privaddr,0,60,privpub33,33); for (j=0; j<20; j++)
printf("alicespend len.%d redeemlen.%d priv0addr.(%s) priv0.(%s)\n",len,redeemlen,privaddr,bits256_str(str,rswap.myprivs[0])); printf("%02x",secretAm[j]);
printf(" secretAm, privAm %s alicespend len.%d redeemlen.%d\n",bits256_str(str,rswap.privAm),len,redeemlen);
} }
for (j=0; j<32; j++)
rev.bytes[j] = rswap.myprivs[0].bytes[31 - j];
if ( (rswap.txbytes[BASILISK_ALICESPEND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"alicespend",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_ALICESPEND],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) if ( (rswap.txbytes[BASILISK_ALICESPEND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"alicespend",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_ALICESPEND],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 )
{ {
//printf("alicespend.(%s)\n",rswap.txbytes[BASILISK_ALICESPEND]); //printf("alicespend.(%s)\n",rswap.txbytes[BASILISK_ALICESPEND]);
#ifndef NOTETOMIC
if ( rswap.bobtomic[0] != 0 )
{
char *aliceSpendEthTxId = LP_etomicalice_spends_bob_payment(&rswap);
free(aliceSpendEthTxId);
}
#endif
} }
} }
LP_txbytes_update("alicespend",rswap.bobcoin,rswap.txbytes[BASILISK_ALICESPEND],&rswap.txids[BASILISK_ALICESPEND],&rswap.paymentspent,&rswap.sentflags[BASILISK_ALICESPEND]); LP_txbytes_update("alicespend",rswap.bobcoin,rswap.txbytes[BASILISK_ALICESPEND],&rswap.txids[BASILISK_ALICESPEND],&rswap.paymentspent,&rswap.sentflags[BASILISK_ALICESPEND]);
@ -1166,7 +1238,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
} }
if ( rswap.sentflags[BASILISK_ALICECLAIM] == 0 && (rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 || bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0) && bits256_nonz(rswap.depositspent) == 0 ) if ( rswap.sentflags[BASILISK_ALICECLAIM] == 0 && (rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 || bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0) && bits256_nonz(rswap.depositspent) == 0 )
{ {
if ( time(NULL) > rswap.expiration+777 ) if ( time(NULL) > rswap.dlocktime+777 )
{ {
flag = 0; flag = 0;
if ( bob->electrum == 0 ) if ( bob->electrum == 0 )
@ -1179,12 +1251,30 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
{ {
if ( rswap.Dredeemlen != 0 ) if ( rswap.Dredeemlen != 0 )
redeemlen = rswap.Dredeemlen, memcpy(redeemscript,rswap.Dredeemscript,rswap.Dredeemlen); redeemlen = rswap.Dredeemlen, memcpy(redeemscript,rswap.Dredeemscript,rswap.Dredeemlen);
else redeemlen = basilisk_swap_bobredeemscript(1,&secretstart,redeemscript,rswap.dlocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,rswap.privAm,zero,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256); else
redeemlen = basilisk_swap_bobredeemscript(1,&secretstart,redeemscript,rswap.dlocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,rswap.privAm,zero,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256);
/*if ( rswap.Dredeemlen != 0 )
{
if ( rswap.Dredeemlen != redeemlen || memcmp(redeemscript,rswap.Dredeemscript,redeemlen) != 0 )
printf("Dredeemscript error len %d vs %d, cmp.%d\n",rswap.Dredeemlen,redeemlen,memcmp(redeemscript,rswap.Dredeemscript,redeemlen));
} else printf("%p Dredeemscript missing\n",rswap.Dredeemscript);*/
if ( redeemlen > 0 ) if ( redeemlen > 0 )
{ {
len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[0],redeemscript,redeemlen); memset(revAm.bytes,0,sizeof(revAm));
if ( (rswap.txbytes[BASILISK_ALICECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"aliceclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,0,claimtime,&rswap.values[BASILISK_ALICECLAIM],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 ) for (i=0; i<32; i++)
printf("claimtime.%u aliceclaim.(%s)\n",claimtime,rswap.txbytes[BASILISK_ALICECLAIM]); revAm.bytes[i] = rswap.privAm.bytes[31-i];
len = basilisk_swapuserdata(userdata,revAm,1,rswap.myprivs[0],redeemscript,redeemlen);
if ( (rswap.txbytes[BASILISK_ALICECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"aliceclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,0,rswap.dlocktime+777,&rswap.values[BASILISK_ALICECLAIM],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 )
{
//printf("dlocktime.%u claimtime.%u aliceclaim.(%s)\n",rswap.dlocktime,claimtime,rswap.txbytes[BASILISK_ALICECLAIM]);
#ifndef NOTETOMIC
if ( rswap.bobtomic[0] != 0 )
{
char *aliceClaimsEthTxId = LP_etomicalice_claims_bob_deposit(&rswap);
free(aliceClaimsEthTxId);
}
#endif
}
} }
LP_txbytes_update("aliceclaim",rswap.bobcoin,rswap.txbytes[BASILISK_ALICECLAIM],&rswap.txids[BASILISK_ALICECLAIM],&rswap.depositspent,&rswap.sentflags[BASILISK_ALICECLAIM]); LP_txbytes_update("aliceclaim",rswap.bobcoin,rswap.txbytes[BASILISK_ALICECLAIM],&rswap.txids[BASILISK_ALICECLAIM],&rswap.depositspent,&rswap.sentflags[BASILISK_ALICECLAIM]);
} }
@ -1204,8 +1294,16 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
rswap.privBn = basilisk_swap_privBn_extract(&rswap.txids[BASILISK_BOBREFUND],rswap.bobcoin,rswap.txids[BASILISK_BOBDEPOSIT],rswap.privBn); rswap.privBn = basilisk_swap_privBn_extract(&rswap.txids[BASILISK_BOBREFUND],rswap.bobcoin,rswap.txids[BASILISK_BOBDEPOSIT],rswap.privBn);
if ( bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) != 0 && bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 ) if ( bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) != 0 && bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 )
{ {
if ( (rswap.txbytes[BASILISK_ALICERECLAIM]= basilisk_swap_Aspend("alicereclaim",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_ALICERECLAIM],rswap.alicepaymentaddr,alice->zcash)) != 0 ) if ( (rswap.txbytes[BASILISK_ALICERECLAIM]= basilisk_swap_Aspend("alicereclaim",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_ALICERECLAIM],rswap.alicepaymentaddr,alice->zcash)) != 0 ) {
printf("alicereclaim.(%s)\n",rswap.txbytes[BASILISK_ALICERECLAIM]); printf("alicereclaim.(%s)\n", rswap.txbytes[BASILISK_ALICERECLAIM]);
#ifndef NOTETOMIC
if ( rswap.alicetomic[0] != 0 )
{
char *aliceReclaimEthTx = LP_etomicalice_reclaims_payment(&rswap);
free(aliceReclaimEthTx);
}
#endif
}
} }
LP_txbytes_update("alicereclaim",rswap.alicecoin,rswap.txbytes[BASILISK_ALICERECLAIM],&rswap.txids[BASILISK_ALICERECLAIM],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_ALICERECLAIM]); LP_txbytes_update("alicereclaim",rswap.alicecoin,rswap.txbytes[BASILISK_ALICERECLAIM],&rswap.txids[BASILISK_ALICERECLAIM],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_ALICERECLAIM]);
} }
@ -1216,7 +1314,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
if ( rswap.sentflags[BASILISK_BOBSPEND] == 0 && bits256_nonz(rswap.Apaymentspent) == 0 ) if ( rswap.sentflags[BASILISK_BOBSPEND] == 0 && bits256_nonz(rswap.Apaymentspent) == 0 )
{ {
//printf("try to bobspend aspend.%s have privAm.%d aspent.%d\n",bits256_str(str,rswap.txids[BASILISK_ALICESPEND]),bits256_nonz(rswap.privAm),rswap.sentflags[BASILISK_ALICESPEND]); //printf("try to bobspend aspend.%s have privAm.%d aspent.%d\n",bits256_str(str,rswap.txids[BASILISK_ALICESPEND]),bits256_nonz(rswap.privAm),rswap.sentflags[BASILISK_ALICESPEND]);
if ( rswap.sentflags[BASILISK_ALICESPEND] != 0 || bits256_nonz(rswap.paymentspent) != 0 || bits256_nonz(rswap.privAm) != 0 ) if ( rswap.sentflags[BASILISK_ALICESPEND] != 0 || bits256_nonz(rswap.paymentspent) != 0 || bits256_nonz(rswap.privAm) != 0 || bits256_nonz(rswap.depositspent) != 0 )
{ {
flag = 0; flag = 0;
if ( alice->electrum == 0 ) if ( alice->electrum == 0 )
@ -1231,12 +1329,23 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
if ( bits256_nonz(rswap.privAm) == 0 ) if ( bits256_nonz(rswap.privAm) == 0 )
{ {
rswap.privAm = basilisk_swap_privbob_extract(rswap.bobcoin,rswap.paymentspent,0,1); rswap.privAm = basilisk_swap_privbob_extract(rswap.bobcoin,rswap.paymentspent,0,1);
//printf("try to bobspend aspend.%s have privAm.%d\n",bits256_str(str,rswap.paymentspent),bits256_nonz(rswap.privAm)); if ( bits256_nonz(rswap.privAm) == 0 && bits256_nonz(rswap.depositspent) != 0 )
{
rswap.privAm = basilisk_swap_privbob_extract(rswap.bobcoin,rswap.depositspent,0,1);
//printf("try to bobspend aspend.%s have privAm.%d\n",bits256_str(str,rswap.depositspent),bits256_nonz(rswap.privAm));
}
} }
if ( bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 ) if ( bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 )
{ {
if ( (rswap.txbytes[BASILISK_BOBSPEND]= basilisk_swap_Aspend("bobspend",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_BOBSPEND],rswap.alicepaymentaddr,alice->zcash)) != 0 ) if ( (rswap.txbytes[BASILISK_BOBSPEND]= basilisk_swap_Aspend("bobspend",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_BOBSPEND],rswap.alicepaymentaddr,alice->zcash)) != 0 )
{ {
#ifndef NOTETOMIC
if ( rswap.alicetomic[0] != 0 )
{
char *bobSpendEthTx = LP_etomicbob_spends_alice_payment(&rswap);
free(bobSpendEthTx);
}
#endif
//printf("bobspend.(%s)\n",rswap.txbytes[BASILISK_BOBSPEND]); //printf("bobspend.(%s)\n",rswap.txbytes[BASILISK_BOBSPEND]);
} }
} }
@ -1260,8 +1369,15 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
if ( redeemlen > 0 ) if ( redeemlen > 0 )
{ {
len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[1],redeemscript,redeemlen); len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[1],redeemscript,redeemlen);
if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobreclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,claimtime,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobreclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,rswap.plocktime+777,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 )
{ {
#ifndef NOTETOMIC
if ( rswap.bobtomic[0] != 0 )
{
char *bobReclaimEthTx = LP_etomicbob_reclaims_payment(&rswap);
free(bobReclaimEthTx);
}
#endif
//int32_t z; //int32_t z;
//for (z=0; z<20; z++) //for (z=0; z<20; z++)
// printf("%02x",rswap.secretAm[z]); // printf("%02x",rswap.secretAm[z]);
@ -1296,6 +1412,13 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
len = basilisk_swapuserdata(userdata,rswap.privBn,0,rswap.myprivs[0],redeemscript,redeemlen); len = basilisk_swapuserdata(userdata,rswap.privBn,0,rswap.myprivs[0],redeemscript,redeemlen);
if ( (rswap.txbytes[BASILISK_BOBREFUND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_BOBREFUND],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 ) if ( (rswap.txbytes[BASILISK_BOBREFUND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_BOBREFUND],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 )
{ {
#ifndef NOTETOMIC
if ( rswap.bobtomic[0] != 0 )
{
char *bobRefundsEthTx = LP_etomicbob_refunds_deposit(&rswap);
free(bobRefundsEthTx);
}
#endif
//printf("pubB1.(%s) bobrefund.(%s)\n",bits256_str(str,rswap.pubB1),rswap.txbytes[BASILISK_BOBREFUND]); //printf("pubB1.(%s) bobrefund.(%s)\n",bits256_str(str,rswap.pubB1),rswap.txbytes[BASILISK_BOBREFUND]);
} }
} }
@ -1688,7 +1811,7 @@ char *basilisk_swapentries(char *refbase,char *refrel,int32_t limit)
if ( ridqid == 0 || j == count ) if ( ridqid == 0 || j == count )
{ {
if ( basilisk_swap_addarray(pending,refbase,refrel) > 0 ) if ( basilisk_swap_addarray(pending,refbase,refrel) > 0 )
jaddi(retarray,pending); jaddi(retarray,jduplicate(pending));
else free_json(pending); else free_json(pending);
} else free_json(pending); } else free_json(pending);
} }

9
iguana/exchanges/LP_rpc.c

@ -332,7 +332,7 @@ cJSON *LP_validateaddress(char *symbol,char *address)
strcat(script,"88ac"); strcat(script,"88ac");
jaddstr(retjson,"scriptPubKey",script); jaddstr(retjson,"scriptPubKey",script);
} }
bitcoin_address(symbol,coinaddr,coin->taddr,coin->pubtype,G.LP_myrmd160,20); bitcoin_address(symbol,coinaddr,coin->taddr,coin->pubtype,G.LP_pubsecp,33);
jadd(retjson,"ismine",strcmp(coinaddr,coin->smartaddr) == 0 ? cJSON_CreateTrue() : cJSON_CreateFalse()); jadd(retjson,"ismine",strcmp(coinaddr,coin->smartaddr) == 0 ? cJSON_CreateTrue() : cJSON_CreateFalse());
jadd(retjson,"iswatchonly",cJSON_CreateTrue()); jadd(retjson,"iswatchonly",cJSON_CreateTrue());
jadd(retjson,"isscript",addrtype == coin->p2shtype ? cJSON_CreateTrue() : cJSON_CreateFalse()); jadd(retjson,"isscript",addrtype == coin->p2shtype ? cJSON_CreateTrue() : cJSON_CreateFalse());
@ -589,13 +589,12 @@ cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag)
ctx = bitcoin_ctx(); ctx = bitcoin_ctx();
bitcoin_wif2addr(ctx,symbol,coin->wiftaddr,coin->taddr,coin->pubtype,address,wifstr); bitcoin_wif2addr(ctx,symbol,coin->wiftaddr,coin->taddr,coin->pubtype,address,wifstr);
#ifdef LP_DONT_IMPORTPRIVKEY #ifdef LP_DONT_IMPORTPRIVKEY
bitcoin_wif2addr(ctx,symbol,coin->wiftaddr,coin->taddr,coin->pubtype,address,wifstr); //bitcoin_wif2addr(ctx,symbol,coin->wiftaddr,coin->taddr,coin->pubtype,address,wifstr);
if ( LP_importaddress(symbol,address) < 0 ) if ( LP_importaddress(symbol,address) < 0 )
{ {
printf("%s importaddress %s from %s failed, isvalid.%d\n",symbol,address,wifstr,bitcoin_validaddress(symbol,coin->taddr,coin->pubtype,coin->p2shtype,address)); printf("%s importaddress %s from %s failed, isvalid.%d\n",symbol,address,wifstr,bitcoin_validaddress(symbol,coin->taddr,coin->pubtype,coin->p2shtype,address));
return(cJSON_Parse("{\"error\":\"couldnt import\"}")); return(cJSON_Parse("{\"error\":\"couldnt import\"}"));
} } else return(cJSON_Parse("{\"result\":\"success\"}"));
else return(cJSON_Parse("{\"result\":\"success\"}"));
#endif #endif
if ( (retjson= LP_validateaddress(symbol,address)) != 0 ) if ( (retjson= LP_validateaddress(symbol,address)) != 0 )
{ {
@ -657,7 +656,7 @@ again:
best = fastest; best = fastest;
retstr = calloc(1,16); retstr = calloc(1,16);
sprintf(retstr,"%0.8f",((double)best * 1024)/SATOSHIDEN); sprintf(retstr,"%0.8f",((double)best * 1024)/SATOSHIDEN);
printf("LP_getestimatedrate (%s) -> %s\n",jprint(retjson,0),retstr); //printf("LP_getestimatedrate (%s) -> %s\n",jprint(retjson,0),retstr);
free(retjson); free(retjson);
} }
/*if ( (retjson= electrum_estimatefee(coin->symbol,coin->electrum,&retjson,numblocks)) != 0 ) /*if ( (retjson= electrum_estimatefee(coin->symbol,coin->electrum,&retjson,numblocks)) != 0 )

17
iguana/exchanges/LP_secp.c

@ -191,3 +191,20 @@ int32_t bitcoin_verify(void *ctx,uint8_t *sig,int32_t siglen,bits256 txhash2,uin
} }
return(retval); return(retval);
} }
int32_t bitcoin_expandcompressed(void *ctx,uint8_t *bigpubkey,uint8_t *pub33)
{
int32_t retval = -1; secp256k1_pubkey PUB; size_t plen = 65;
SECP_ENSURE_CTX
{
if ( secp256k1_ec_pubkey_parse(ctx,&PUB,pub33,33) != 0 )
{
secp256k1_ec_pubkey_serialize(ctx,bigpubkey,&plen,&PUB,SECP256K1_EC_UNCOMPRESSED);
retval = 0;
}
ENDSECP_ENSURE_CTX
}
return(retval);
}

29
iguana/exchanges/LP_signatures.c

@ -41,13 +41,19 @@ struct basilisk_request *LP_requestinit(struct basilisk_request *rp,bits256 srch
cJSON *LP_quotejson(struct LP_quoteinfo *qp) cJSON *LP_quotejson(struct LP_quoteinfo *qp)
{ {
double price; cJSON *retjson = cJSON_CreateObject(); double price; char etomic[64],activesymbol[65]; cJSON *retjson = cJSON_CreateObject();
if ( jobj(retjson,"gui") == 0 ) if ( jobj(retjson,"gui") == 0 )
jaddstr(retjson,"gui",qp->gui[0] != 0 ? qp->gui : LP_gui); jaddstr(retjson,"gui",qp->gui[0] != 0 ? qp->gui : LP_gui);
jadd64bits(retjson,"aliceid",qp->aliceid); jadd64bits(retjson,"aliceid",qp->aliceid);
jaddnum(retjson,"tradeid",qp->tradeid); jaddnum(retjson,"tradeid",qp->tradeid);
jaddstr(retjson,"base",qp->srccoin); jaddstr(retjson,"base",qp->srccoin);
if ( LP_etomicsymbol(activesymbol,etomic,qp->srccoin) != 0 )
jaddstr(retjson,"bobtomic",etomic);
jaddstr(retjson,"etomicsrc",qp->etomicsrc);
jaddstr(retjson,"rel",qp->destcoin); jaddstr(retjson,"rel",qp->destcoin);
if ( LP_etomicsymbol(activesymbol,etomic,qp->destcoin) != 0 )
jaddstr(retjson,"alicetomic",etomic);
jaddstr(retjson,"etomicdest",qp->etomicdest);
if ( qp->coinaddr[0] != 0 ) if ( qp->coinaddr[0] != 0 )
jaddstr(retjson,"address",qp->coinaddr); jaddstr(retjson,"address",qp->coinaddr);
if ( qp->timestamp != 0 ) if ( qp->timestamp != 0 )
@ -104,13 +110,31 @@ cJSON *LP_quotejson(struct LP_quoteinfo *qp)
int32_t LP_quoteparse(struct LP_quoteinfo *qp,cJSON *argjson) int32_t LP_quoteparse(struct LP_quoteinfo *qp,cJSON *argjson)
{ {
uint32_t rid,qid; uint32_t rid,qid; char etomic[64],activesymbol[65],*etomicstr;
memset(qp,0,sizeof(*qp)); memset(qp,0,sizeof(*qp));
safecopy(qp->gui,LP_gui,sizeof(qp->gui)); safecopy(qp->gui,LP_gui,sizeof(qp->gui));
safecopy(qp->srccoin,jstr(argjson,"base"),sizeof(qp->srccoin)); safecopy(qp->srccoin,jstr(argjson,"base"),sizeof(qp->srccoin));
if ( LP_etomicsymbol(activesymbol,etomic,qp->srccoin) != 0 )
{
if ( (etomicstr= jstr(argjson,"bobtomic")) == 0 || strcmp(etomicstr,etomic) != 0 )
{
printf("etomic src mismatch (%s) vs (%s)\n",etomicstr!=0?etomicstr:"",etomic);
return(-1);
}
}
safecopy(qp->coinaddr,jstr(argjson,"address"),sizeof(qp->coinaddr)); safecopy(qp->coinaddr,jstr(argjson,"address"),sizeof(qp->coinaddr));
safecopy(qp->etomicsrc,jstr(argjson,"etomicsrc"),sizeof(qp->etomicsrc));
safecopy(qp->destcoin,jstr(argjson,"rel"),sizeof(qp->destcoin)); safecopy(qp->destcoin,jstr(argjson,"rel"),sizeof(qp->destcoin));
if ( LP_etomicsymbol(activesymbol,etomic,qp->destcoin) != 0 )
{
if ( (etomicstr= jstr(argjson,"alicetomic")) == 0 || strcmp(etomicstr,etomic) != 0 )
{
printf("etomic dest mismatch (%s) vs (%s)\n",etomicstr!=0?etomicstr:"",etomic);
return(-1);
}
}
safecopy(qp->destaddr,jstr(argjson,"destaddr"),sizeof(qp->destaddr)); safecopy(qp->destaddr,jstr(argjson,"destaddr"),sizeof(qp->destaddr));
safecopy(qp->etomicdest,jstr(argjson,"etomicdest"),sizeof(qp->etomicdest));
qp->aliceid = j64bits(argjson,"aliceid"); qp->aliceid = j64bits(argjson,"aliceid");
qp->tradeid = juint(argjson,"tradeid"); qp->tradeid = juint(argjson,"tradeid");
qp->timestamp = juint(argjson,"timestamp"); qp->timestamp = juint(argjson,"timestamp");
@ -674,6 +698,7 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_
jadd(reqjson,"proof",LP_instantdex_txids(0,coin->smartaddr)); jadd(reqjson,"proof",LP_instantdex_txids(0,coin->smartaddr));
} }
msg = jprint(reqjson,1); msg = jprint(reqjson,1);
//printf("etomicdest.(%s) QUERY.(%s)\n",qp->etomicdest,msg);
memset(&zero,0,sizeof(zero)); memset(&zero,0,sizeof(zero));
if ( bits256_nonz(qp->srchash) != 0 ) if ( bits256_nonz(qp->srchash) != 0 )
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->srchash,clonestr(msg)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->srchash,clonestr(msg));

194
iguana/exchanges/LP_swap.c

@ -34,23 +34,22 @@
e) BEFORE Bob broadcasts deposit, Alice broadcasts BTC denominated fee in cltv so if trade isnt done fee is reclaimed e) BEFORE Bob broadcasts deposit, Alice broadcasts BTC denominated fee in cltv so if trade isnt done fee is reclaimed
*/ */
//#define DISABLE_CHECKSIG // unsolved MITM (evil peer)
/* /*
both fees are standard payments: OP_DUP OP_HASH160 FEE_RMD160 OP_EQUALVERIFY OP_CHECKSIG both fees are standard payments: OP_DUP OP_HASH160 FEE_RMD160 OP_EQUALVERIFY OP_CHECKSIG
Alice altpayment: OP_2 <alice_pubM> <bob_pubN> OP_2 OP_CHECKMULTISIG
Bob deposit: Bob deposit:
OP_IF OP_IF
<now + INSTANTDEX_LOCKTIME*2> OP_CLTV OP_DROP <alice_pubA0> OP_CHECKSIG <now + LOCKTIME*2> OP_CLTV OP_DROP <alice_pubA0> OP_CHECKSIG
OP_ELSE OP_ELSE
OP_HASH160 <hash(bob_privN)> OP_EQUALVERIFY <bob_pubB0> OP_CHECKSIG OP_HASH160 <hash(bob_privN)> OP_EQUALVERIFY <bob_pubB0> OP_CHECKSIG
OP_ENDIF OP_ENDIF
Alice altpayment: OP_2 <alice_pubM> <bob_pubN> OP_2 OP_CHECKMULTISIG
Bob paytx: Bob paytx:
OP_IF OP_IF
<now + INSTANTDEX_LOCKTIME> OP_CLTV OP_DROP <bob_pubB1> OP_CHECKSIG <now + LOCKTIME> OP_CLTV OP_DROP <bob_pubB1> OP_CHECKSIG
OP_ELSE OP_ELSE
OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <alice_pubA0> OP_CHECKSIG OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <alice_pubA0> OP_CHECKSIG
OP_ENDIF OP_ENDIF
@ -63,6 +62,23 @@
pubN and pubM are the corresponding pubkeys for these chosen privkeys pubN and pubM are the corresponding pubkeys for these chosen privkeys
Alice timeout event is triggered if INSTANTDEX_LOCKTIME elapses from the start of a FSM instance. Bob timeout event is triggered after INSTANTDEX_LOCKTIME*2 Alice timeout event is triggered if INSTANTDEX_LOCKTIME elapses from the start of a FSM instance. Bob timeout event is triggered after INSTANTDEX_LOCKTIME*2
Based on https://gist.github.com/markblundeberg/7a932c98179de2190049f5823907c016 and to enable bob to spend alicepayment when alice does a claim for bob deposit, the scripts are changed to the following:
Bob deposit:
OP_IF
OP_SIZE 32 OP_EQUALVERIFY OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <now + INSTANTDEX_LOCKTIME*2> OP_CLTV OP_DROP <alice_pubA0> OP_CHECKSIG
OP_ELSE
OP_SIZE 32 OP_EQUALVERIFY OP_HASH160 <hash(bob_privN)> OP_EQUALVERIFY <bob_pubB0> OP_CHECKSIG
OP_ENDIF
Bob paytx:
OP_IF
<now + INSTANTDEX_LOCKTIME> OP_CLTV OP_DROP <bob_pubB1> OP_CHECKSIG
OP_ELSE
OP_SIZE 32 OP_EQUALVERIFY OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <alice_pubA0> OP_CHECKSIG
OP_ENDIF
*/ */
/* /*
@ -571,7 +587,9 @@ struct basilisk_rawtx *LP_swapdata_rawtx(struct basilisk_swap *swap,uint8_t *dat
int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *recvbuf,int32_t recvlen,int32_t suppress_pubkeys) int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *recvbuf,int32_t recvlen,int32_t suppress_pubkeys)
{ {
bits256 otherhash,myhash,txid; int64_t txfee,val; int32_t i,offset=0,datalen=0,retval=-1,hexlen,n; uint8_t *data; cJSON *txobj,*skey,*vouts,*vout; char *hexstr,redeemaddr[64],checkaddr[64]; uint32_t quoteid,msgbits; struct iguana_info *coin; bits256 otherhash,myhash,txid; int64_t txfee,val; int32_t i,offset=0,datalen=0,retval=-1,hexlen,n; uint8_t *data; cJSON *txobj,*skey,*vouts,*vout; char *hexstr,bobstr[65],alicestr[65],redeemaddr[64],checkaddr[64]; uint32_t quoteid,msgbits; struct iguana_info *coin;
LP_etomicsymbol(bobstr,swap->I.bobtomic,swap->I.bobstr);
LP_etomicsymbol(alicestr,swap->I.alicetomic,swap->I.alicestr);
if ( (coin= LP_coinfind(rawtx->symbol)) == 0 ) if ( (coin= LP_coinfind(rawtx->symbol)) == 0 )
{ {
printf("LP_rawtx_spendscript couldnt find coin.(%s)\n",rawtx->symbol); printf("LP_rawtx_spendscript couldnt find coin.(%s)\n",rawtx->symbol);
@ -581,6 +599,7 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
otherhash.bytes[i] = recvbuf[offset++]; otherhash.bytes[i] = recvbuf[offset++];
for (i=0; i<32; i++) for (i=0; i<32; i++)
myhash.bytes[i] = recvbuf[offset++]; myhash.bytes[i] = recvbuf[offset++];
offset += iguana_rwnum(0,&recvbuf[offset],sizeof(quoteid),&quoteid); offset += iguana_rwnum(0,&recvbuf[offset],sizeof(quoteid),&quoteid);
offset += iguana_rwnum(0,&recvbuf[offset],sizeof(msgbits),&msgbits); offset += iguana_rwnum(0,&recvbuf[offset],sizeof(msgbits),&msgbits);
datalen = recvbuf[offset++]; datalen = recvbuf[offset++];
@ -591,6 +610,11 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
return(-1); return(-1);
} }
rawtx->I.redeemlen = recvbuf[offset++]; rawtx->I.redeemlen = recvbuf[offset++];
#ifndef NOTETOMIC
uint8arrayToHex(rawtx->I.ethTxid, &recvbuf[offset], 32);
printf("ETH txid received: %s\n", rawtx->I.ethTxid);
#endif
offset += 32;
data = &recvbuf[offset]; data = &recvbuf[offset];
if ( rawtx->I.redeemlen > 0 && rawtx->I.redeemlen < 0x100 ) if ( rawtx->I.redeemlen > 0 && rawtx->I.redeemlen < 0x100 )
{ {
@ -623,7 +647,9 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
printf("%s rawtx data compare error, len %d vs %d <<<<<<<<<< warning\n",rawtx->name,rawtx->I.datalen,datalen); printf("%s rawtx data compare error, len %d vs %d <<<<<<<<<< warning\n",rawtx->name,rawtx->I.datalen,datalen);
return(-1); return(-1);
} }
if ( recvlen != datalen+rawtx->I.redeemlen+75 )
if ( recvlen != datalen+rawtx->I.redeemlen + 107 )
printf("RECVLEN %d != %d + %d\n",recvlen,datalen,rawtx->I.redeemlen); printf("RECVLEN %d != %d + %d\n",recvlen,datalen,rawtx->I.redeemlen);
txid = bits256_calctxid(coin->symbol,data,datalen); txid = bits256_calctxid(coin->symbol,data,datalen);
//char str[65]; printf("rawtx.%s txid %s\n",rawtx->name,bits256_str(str,txid)); //char str[65]; printf("rawtx.%s txid %s\n",rawtx->name,bits256_str(str,txid));
@ -640,9 +666,9 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
txfee = LP_MIN_TXFEE; txfee = LP_MIN_TXFEE;
else else
{ {
if ( strcmp(coin->symbol,swap->I.bobstr) == 0 ) if ( strcmp(coin->symbol,bobstr) == 0 )
txfee = swap->I.Btxfee; txfee = swap->I.Btxfee;
else if ( strcmp(coin->symbol,swap->I.alicestr) == 0 ) else if ( strcmp(coin->symbol,alicestr) == 0 )
txfee = swap->I.Atxfee; txfee = swap->I.Atxfee;
else txfee = LP_MIN_TXFEE; else txfee = LP_MIN_TXFEE;
} }
@ -689,10 +715,31 @@ uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint3
} }
if ( bits256_nonz(rawtx->I.actualtxid) != 0 && msgbits != 0 ) if ( bits256_nonz(rawtx->I.actualtxid) != 0 && msgbits != 0 )
{ {
#ifndef NOTETOMIC
if ( swap->I.bobtomic[0] != 0 || swap->I.alicetomic[0] != 0 )
{
char *ethTxId = sendEthTx(swap, rawtx);
strcpy(rawtx->I.ethTxid, ethTxId);
free(ethTxId);
}
#endif
sendlen = 0; sendlen = 0;
sendbuf[sendlen++] = rawtx->I.datalen & 0xff; sendbuf[sendlen++] = rawtx->I.datalen & 0xff;
sendbuf[sendlen++] = (rawtx->I.datalen >> 8) & 0xff; sendbuf[sendlen++] = (rawtx->I.datalen >> 8) & 0xff;
sendbuf[sendlen++] = rawtx->I.redeemlen; sendbuf[sendlen++] = rawtx->I.redeemlen;
if ( rawtx->I.ethTxid[0] != 0 && strlen(rawtx->I.ethTxid) == 66 )
{
uint8_t ethTxidBytes[32];
// ETH txid always starts with 0x
decode_hex(ethTxidBytes, 32, rawtx->I.ethTxid + 2);
memcpy(&sendbuf[sendlen], ethTxidBytes, 32);
}
else
{
// fill with zero bytes to always have fixed message size
memset(&sendbuf[sendlen], 0, 32);
}
sendlen += 32;
//int32_t z; for (z=0; z<rawtx->I.datalen; z++) printf("%02x",rawtx->txbytes[z]); printf(" >>>>>>> send.%d %s\n",rawtx->I.datalen,rawtx->name); //int32_t z; for (z=0; z<rawtx->I.datalen; z++) printf("%02x",rawtx->txbytes[z]); printf(" >>>>>>> send.%d %s\n",rawtx->I.datalen,rawtx->name);
//printf("datalen.%d redeemlen.%d\n",rawtx->I.datalen,rawtx->I.redeemlen); //printf("datalen.%d redeemlen.%d\n",rawtx->I.datalen,rawtx->I.redeemlen);
memcpy(&sendbuf[sendlen],rawtx->txbytes,rawtx->I.datalen), sendlen += rawtx->I.datalen; memcpy(&sendbuf[sendlen],rawtx->txbytes,rawtx->I.datalen), sendlen += rawtx->I.datalen;
@ -701,6 +748,7 @@ uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint3
memcpy(&sendbuf[sendlen],rawtx->redeemscript,rawtx->I.redeemlen); memcpy(&sendbuf[sendlen],rawtx->redeemscript,rawtx->I.redeemlen);
sendlen += rawtx->I.redeemlen; sendlen += rawtx->I.redeemlen;
} }
basilisk_dontforget_update(swap,rawtx); basilisk_dontforget_update(swap,rawtx);
//printf("sendlen.%d datalen.%d redeemlen.%d\n",sendlen,rawtx->datalen,rawtx->redeemlen); //printf("sendlen.%d datalen.%d redeemlen.%d\n",sendlen,rawtx->datalen,rawtx->redeemlen);
if ( suppress_swapsend == 0 ) if ( suppress_swapsend == 0 )
@ -780,9 +828,11 @@ uint32_t LP_swapwait(uint32_t expiration,uint32_t requestid,uint32_t quoteid,int
void LP_bobloop(void *_swap) void LP_bobloop(void *_swap)
{ {
uint8_t *data; int32_t maxlen,m,n; uint32_t expiration; struct basilisk_swap *swap = _swap; uint8_t *data; char bobstr[65],alicestr[65]; int32_t maxlen,m,n; uint32_t expiration; struct basilisk_swap *swap = _swap;
G.LP_pendingswaps++; G.LP_pendingswaps++;
printf("start swap iambob\n"); printf("start swap iambob\n");
LP_etomicsymbol(bobstr,swap->I.bobtomic,swap->I.bobstr);
LP_etomicsymbol(alicestr,swap->I.alicetomic,swap->I.alicestr);
maxlen = 1024*1024 + sizeof(*swap); maxlen = 1024*1024 + sizeof(*swap);
data = malloc(maxlen); data = malloc(maxlen);
expiration = (uint32_t)time(NULL) + LP_SWAPSTEP_TIMEOUT; expiration = (uint32_t)time(NULL) + LP_SWAPSTEP_TIMEOUT;
@ -798,6 +848,7 @@ void LP_bobloop(void *_swap)
printf("error bobscripts deposit\n"); printf("error bobscripts deposit\n");
else else
{ {
uint8_t error = 0;
swap->bobrefund.utxovout = 0; swap->bobrefund.utxovout = 0;
swap->bobrefund.utxotxid = swap->bobdeposit.I.signedtxid; swap->bobrefund.utxotxid = swap->bobdeposit.I.signedtxid;
basilisk_bobdeposit_refund(swap,swap->I.putduration); basilisk_bobdeposit_refund(swap,swap->I.putduration);
@ -805,30 +856,43 @@ void LP_bobloop(void *_swap)
LP_swapsfp_update(&swap->I.req); LP_swapsfp_update(&swap->I.req);
LP_swap_critical = (uint32_t)time(NULL); LP_swap_critical = (uint32_t)time(NULL);
if ( LP_waitfor(swap->N.pair,swap,LP_SWAPSTEP_TIMEOUT*10,LP_verify_otherfee) < 0 ) if ( LP_waitfor(swap->N.pair,swap,LP_SWAPSTEP_TIMEOUT*10,LP_verify_otherfee) < 0 )
{
error = 1;
printf("error waiting for alicefee\n"); printf("error waiting for alicefee\n");
else if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x200,data,maxlen,&swap->bobdeposit,0x100,0) == 0 ) }
printf("error sending bobdeposit\n");
else if ( LP_waitfor(swap->N.pair,swap,1800,LP_verify_alicepayment) < 0 ) if ( error == 0 ) {
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x200,data,maxlen,&swap->bobdeposit,0x100,0) == 0 ) {
error = 1;
printf("error sending bobdeposit\n");
}
}
if ( error == 0 && LP_waitfor(swap->N.pair,swap,1800,LP_verify_alicepayment) < 0 )
{
error = 1;
printf("error waiting for alicepayment\n"); printf("error waiting for alicepayment\n");
else }
if (error == 0)
{ {
LP_swap_critical = (uint32_t)time(NULL); LP_swap_critical = (uint32_t)time(NULL);
if ( basilisk_bobscripts_set(swap,0,1) < 0 ) if ( basilisk_bobscripts_set(swap,0,1) < 0 )
printf("error bobscripts payment\n"); printf("error bobscripts payment\n");
else else
{ {
/*if ( strcmp(swap->I.alicestr,"BTC") == 0 ) m = swap->I.aliceconfirms;
m = 0; while ( (n= LP_numconfirms(alicestr,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) // sync with alice
else*/ m = swap->I.aliceconfirms;
while ( (n= LP_numconfirms(swap->I.alicestr,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) // sync with alice
{ {
LP_swap_critical = (uint32_t)time(NULL); LP_swap_critical = (uint32_t)time(NULL);
char str[65];printf("%d wait for alicepayment %s numconfs.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,swap->I.alicestr,bits256_str(str,swap->alicepayment.I.signedtxid)); char str[65];printf("%d wait for alicepayment %s numconfs.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,alicestr,bits256_str(str,swap->alicepayment.I.signedtxid));
sleep(10); sleep(10);
} }
LP_swap_critical = (uint32_t)time(NULL); LP_swap_critical = (uint32_t)time(NULL);
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0) == 0 )
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0) == 0 ) {
printf("error sending bobpayment\n"); printf("error sending bobpayment\n");
}
//if ( LP_waitfor(swap->N.pair,swap,10,LP_verify_alicespend) < 0 ) //if ( LP_waitfor(swap->N.pair,swap,10,LP_verify_alicespend) < 0 )
// printf("error waiting for alicespend\n"); // printf("error waiting for alicespend\n");
//swap->sentflag = 1; //swap->sentflag = 1;
@ -852,8 +916,10 @@ void LP_bobloop(void *_swap)
void LP_aliceloop(void *_swap) void LP_aliceloop(void *_swap)
{ {
uint8_t *data; int32_t maxlen,n,m; uint32_t expiration; struct basilisk_swap *swap = _swap; uint8_t *data; char bobstr[65],alicestr[65]; int32_t maxlen,n,m; uint32_t expiration; struct basilisk_swap *swap = _swap;
G.LP_pendingswaps++; G.LP_pendingswaps++;
LP_etomicsymbol(bobstr,swap->I.bobtomic,swap->I.bobstr);
LP_etomicsymbol(alicestr,swap->I.alicetomic,swap->I.alicestr);
maxlen = 1024*1024 + sizeof(*swap); maxlen = 1024*1024 + sizeof(*swap);
data = malloc(maxlen); data = malloc(maxlen);
expiration = (uint32_t)time(NULL) + LP_SWAPSTEP_TIMEOUT; expiration = (uint32_t)time(NULL) + LP_SWAPSTEP_TIMEOUT;
@ -878,26 +944,22 @@ void LP_aliceloop(void *_swap)
printf("error waiting for bobdeposit\n"); printf("error waiting for bobdeposit\n");
else else
{ {
/*if ( strcmp(swap->I.bobstr,"BTC") == 0 ) m = swap->I.bobconfirms;
m = 0; while ( (n= LP_numconfirms(bobstr,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,0,1)) < m )
else*/ m = swap->I.bobconfirms;
while ( (n= LP_numconfirms(swap->I.bobstr,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,0,1)) < m )
{ {
LP_swap_critical = (uint32_t)time(NULL); LP_swap_critical = (uint32_t)time(NULL);
char str[65];printf("%d wait for bobdeposit %s numconfs.%d %s %s\n",n,swap->bobdeposit.I.destaddr,m,swap->I.bobstr,bits256_str(str,swap->bobdeposit.I.signedtxid)); char str[65];printf("%d wait for bobdeposit %s numconfs.%d %s %s\n",n,swap->bobdeposit.I.destaddr,m,bobstr,bits256_str(str,swap->bobdeposit.I.signedtxid));
sleep(10); sleep(10);
} }
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x1000,data,maxlen,&swap->alicepayment,0x800,0) == 0 ) if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x1000,data,maxlen,&swap->alicepayment,0x800,0) == 0 )
printf("error sending alicepayment\n"); printf("error sending alicepayment\n");
else else
{ {
/*if ( strcmp(swap->I.alicestr,"BTC") == 0 ) m = swap->I.aliceconfirms;
m = 0; while ( (n= LP_numconfirms(alicestr,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m )
else*/ m = swap->I.aliceconfirms;
while ( (n= LP_numconfirms(swap->I.alicestr,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m )
{ {
LP_swap_critical = (uint32_t)time(NULL); LP_swap_critical = (uint32_t)time(NULL);
char str[65];printf("%d wait for alicepayment %s numconfs.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,swap->I.alicestr,bits256_str(str,swap->alicepayment.I.signedtxid)); char str[65];printf("%d wait for alicepayment %s numconfs.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,alicestr,bits256_str(str,swap->alicepayment.I.signedtxid));
sleep(10); sleep(10);
} }
//swap->sentflag = 1; //swap->sentflag = 1;
@ -906,19 +968,16 @@ void LP_aliceloop(void *_swap)
printf("error waiting for bobpayment\n"); printf("error waiting for bobpayment\n");
else else
{ {
if ( swap->I.alicetomic[0] != 0 )
{
// artem: do stuff alice needs to do after bobpayment comes in
}
LP_swap_endcritical = (uint32_t)time(NULL); LP_swap_endcritical = (uint32_t)time(NULL);
while ( (n= LP_numconfirms(swap->I.bobstr,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,1)) < swap->I.bobconfirms ) while ( (n= LP_numconfirms(bobstr,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,1)) < swap->I.bobconfirms )
{ {
char str[65];printf("%d wait for bobpayment %s numconfs.%d %s %s\n",n,swap->bobpayment.I.destaddr,swap->I.bobconfirms,swap->I.bobstr,bits256_str(str,swap->bobpayment.I.signedtxid)); char str[65];printf("%d wait for bobpayment %s numconfs.%d %s %s\n",n,swap->bobpayment.I.destaddr,swap->I.bobconfirms,bobstr,bits256_str(str,swap->bobpayment.I.signedtxid));
sleep(10); sleep(10);
} }
/*if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x20000,data,maxlen,&swap->alicespend,0x40000,0) == 0 )
printf("error sending alicespend\n");
while ( (n= LP_numconfirms(swap->I.alicestr,swap->alicespend.I.destaddr,swap->alicespend.I.signedtxid,0,1)) < swap->I.aliceconfirms )
{
char str[65];printf("%d wait for alicespend %s numconfs.%d %s %s\n",n,swap->alicespend.I.destaddr,swap->I.aliceconfirms,swap->I.bobstr,bits256_str(str,swap->alicespend.I.signedtxid));
sleep(LP_SWAPSTEP_TIMEOUT);
}*/
if ( swap->N.pair >= 0 ) if ( swap->N.pair >= 0 )
nn_close(swap->N.pair), swap->N.pair = -1; nn_close(swap->N.pair), swap->N.pair = -1;
} }
@ -945,15 +1004,7 @@ bits256 instantdex_derivekeypair(void *ctx,bits256 *newprivp,uint8_t pubkey[33],
bits256 basilisk_revealkey(bits256 privkey,bits256 pubkey) bits256 basilisk_revealkey(bits256 privkey,bits256 pubkey)
{ {
bits256 reveal; return(pubkey);
#ifdef DISABLE_CHECKSIG
vcalc_sha256(0,reveal.bytes,privkey.bytes,sizeof(privkey));
//reveal = revcalc_sha256(privkey);
char str[65],str2[65]; printf("priv.(%s) -> reveal.(%s)\n",bits256_str(str,privkey),bits256_str(str2,reveal));
#else
reveal = pubkey;
#endif
return(reveal);
} }
int32_t instantdex_pubkeyargs(struct basilisk_swap *swap,int32_t numpubs,bits256 privkey,bits256 hash,int32_t firstbyte) int32_t instantdex_pubkeyargs(struct basilisk_swap *swap,int32_t numpubs,bits256 privkey,bits256 hash,int32_t firstbyte)
@ -1049,32 +1100,44 @@ void basilisk_rawtx_setparms(char *name,uint32_t quoteid,struct basilisk_rawtx *
struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 pubkey25519,struct basilisk_swap *swap,int32_t optionduration,uint32_t statebits,struct LP_quoteinfo *qp,int32_t dynamictrust) struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 pubkey25519,struct basilisk_swap *swap,int32_t optionduration,uint32_t statebits,struct LP_quoteinfo *qp,int32_t dynamictrust)
{ {
//FILE *fp; char fname[512]; //FILE *fp; char fname[512];
uint8_t *alicepub33=0,*bobpub33=0; int32_t jumblrflag=-2,x = -1; struct iguana_info *bobcoin,*alicecoin; uint8_t *alicepub33=0,*bobpub33=0; int32_t jumblrflag=-2,x = -1; struct iguana_info *bobcoin,*alicecoin; char bobstr[65],alicestr[65];
strcpy(swap->I.etomicsrc,qp->etomicsrc);
strcpy(swap->I.etomicdest,qp->etomicdest);
strcpy(swap->I.bobstr,swap->I.req.src); strcpy(swap->I.bobstr,swap->I.req.src);
strcpy(swap->I.alicestr,swap->I.req.dest); strcpy(swap->I.alicestr,swap->I.req.dest);
if ( (alicecoin= LP_coinfind(swap->I.alicestr)) == 0 ) LP_etomicsymbol(bobstr,swap->I.bobtomic,swap->I.bobstr);
LP_etomicsymbol(alicestr,swap->I.alicetomic,swap->I.alicestr);
if ( (alicecoin= LP_coinfind(alicestr)) == 0 )
{ {
printf("missing alicecoin src.%p dest.%p\n",LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest)); printf("missing alicecoin src.%p dest.%p\n",LP_coinfind(alicestr),LP_coinfind(bobstr));
free(swap); free(swap);
return(0); return(0);
} }
if ( (bobcoin= LP_coinfind(swap->I.bobstr)) == 0 ) if ( (bobcoin= LP_coinfind(bobstr)) == 0 )
{ {
printf("missing bobcoin src.%p dest.%p\n",LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest)); printf("missing bobcoin src.%p dest.%p\n",LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest));
free(swap); free(swap);
return(0); return(0);
} }
if ( alicecoin == 0 || bobcoin == 0 )
{
printf("couldnt find ETOMIC\n");
free(swap);
return(0);
}
if ( (swap->I.Atxfee= qp->desttxfee) < 0 ) if ( (swap->I.Atxfee= qp->desttxfee) < 0 )
{ {
printf("bitcoin_swapinit %s Atxfee %.8f rejected\n",swap->I.req.dest,dstr(swap->I.Atxfee)); printf("bitcoin_swapinit %s Atxfee %.8f rejected\n",swap->I.req.dest,dstr(swap->I.Atxfee));
free(swap);
return(0); return(0);
} }
if ( (swap->I.Btxfee= qp->txfee) < 0 ) if ( (swap->I.Btxfee= qp->txfee) < 0 )
{ {
printf("bitcoin_swapinit %s Btxfee %.8f rejected\n",swap->I.req.src,dstr(swap->I.Btxfee)); printf("bitcoin_swapinit %s Btxfee %.8f rejected\n",swap->I.req.src,dstr(swap->I.Btxfee));
free(swap);
return(0); return(0);
} }
swap->I.putduration = swap->I.callduration = LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr); swap->I.putduration = swap->I.callduration = LP_atomic_locktime(bobstr,alicestr);
if ( optionduration < 0 ) if ( optionduration < 0 )
swap->I.putduration -= optionduration; swap->I.putduration -= optionduration;
else if ( optionduration > 0 ) else if ( optionduration > 0 )
@ -1082,11 +1145,13 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256
if ( (swap->I.bobsatoshis= swap->I.req.srcamount) <= 0 ) if ( (swap->I.bobsatoshis= swap->I.req.srcamount) <= 0 )
{ {
printf("bitcoin_swapinit %s bobsatoshis %.8f rejected\n",swap->I.req.src,dstr(swap->I.bobsatoshis)); printf("bitcoin_swapinit %s bobsatoshis %.8f rejected\n",swap->I.req.src,dstr(swap->I.bobsatoshis));
free(swap);
return(0); return(0);
} }
if ( (swap->I.alicesatoshis= swap->I.req.destamount) <= 0 ) if ( (swap->I.alicesatoshis= swap->I.req.destamount) <= 0 )
{ {
printf("bitcoin_swapinit %s alicesatoshis %.8f rejected\n",swap->I.req.dest,dstr(swap->I.alicesatoshis)); printf("bitcoin_swapinit %s alicesatoshis %.8f rejected\n",swap->I.req.dest,dstr(swap->I.alicesatoshis));
free(swap);
return(0); return(0);
} }
if ( (swap->I.bobinsurance= (swap->I.bobsatoshis / INSTANTDEX_INSURANCEDIV)) < LP_MIN_TXFEE ) if ( (swap->I.bobinsurance= (swap->I.bobsatoshis / INSTANTDEX_INSURANCEDIV)) < LP_MIN_TXFEE )
@ -1122,14 +1187,15 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256
if ( bits256_nonz(privkey) == 0 || (x= instantdex_pubkeyargs(swap,2 + INSTANTDEX_DECKSIZE,privkey,swap->I.orderhash,0x02+swap->I.iambob)) != 2 + INSTANTDEX_DECKSIZE ) if ( bits256_nonz(privkey) == 0 || (x= instantdex_pubkeyargs(swap,2 + INSTANTDEX_DECKSIZE,privkey,swap->I.orderhash,0x02+swap->I.iambob)) != 2 + INSTANTDEX_DECKSIZE )
{ {
char str[65]; printf("couldnt generate privkeys %d %s\n",x,bits256_str(str,privkey)); char str[65]; printf("couldnt generate privkeys %d %s\n",x,bits256_str(str,privkey));
free(swap);
return(0); return(0);
} }
if ( strcmp("BTC",swap->I.bobstr) == 0 ) if ( strcmp("BTC",bobstr) == 0 )
{ {
swap->I.bobconfirms = 1;//(1 + sqrt(dstr(swap->I.bobsatoshis) * .1)); swap->I.bobconfirms = 1;//(1 + sqrt(dstr(swap->I.bobsatoshis) * .1));
swap->I.aliceconfirms = BASILISK_DEFAULT_NUMCONFIRMS; swap->I.aliceconfirms = BASILISK_DEFAULT_NUMCONFIRMS;
} }
else if ( strcmp("BTC",swap->I.alicestr) == 0 ) else if ( strcmp("BTC",alicestr) == 0 )
{ {
swap->I.aliceconfirms = 1;//(1 + sqrt(dstr(swap->I.alicesatoshis) * .1)); swap->I.aliceconfirms = 1;//(1 + sqrt(dstr(swap->I.alicesatoshis) * .1));
swap->I.bobconfirms = BASILISK_DEFAULT_NUMCONFIRMS; swap->I.bobconfirms = BASILISK_DEFAULT_NUMCONFIRMS;
@ -1155,9 +1221,13 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256
swap->I.bobconfirms = swap->I.bobmaxconfirms; swap->I.bobconfirms = swap->I.bobmaxconfirms;
if ( swap->I.aliceconfirms > swap->I.alicemaxconfirms ) if ( swap->I.aliceconfirms > swap->I.alicemaxconfirms )
swap->I.aliceconfirms = swap->I.alicemaxconfirms; swap->I.aliceconfirms = swap->I.alicemaxconfirms;
swap->I.bobconfirms *= !swap->I.bobistrusted; if ( strcmp("BAY",swap->I.req.src) != 0 && strcmp("BAY",swap->I.req.dest) != 0 )
swap->I.aliceconfirms *= !swap->I.aliceistrusted; {
swap->I.bobconfirms *= !swap->I.bobistrusted;
swap->I.aliceconfirms *= !swap->I.aliceistrusted;
}
printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< r.%u q.%u, %.8f bobconfs.%d, %.8f aliceconfs.%d taddr.%d %d\n",jumblrflag,swap->I.req.requestid,swap->I.req.quoteid,dstr(swap->I.bobsatoshis),swap->I.bobconfirms,dstr(swap->I.alicesatoshis),swap->I.aliceconfirms,bobcoin->taddr,alicecoin->taddr); printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< r.%u q.%u, %.8f bobconfs.%d, %.8f aliceconfs.%d taddr.%d %d\n",jumblrflag,swap->I.req.requestid,swap->I.req.quoteid,dstr(swap->I.bobsatoshis),swap->I.bobconfirms,dstr(swap->I.alicesatoshis),swap->I.aliceconfirms,bobcoin->taddr,alicecoin->taddr);
printf("etomic src (%s %s) dest (%s %s)\n",swap->I.bobtomic,swap->I.etomicsrc,swap->I.alicetomic,swap->I.etomicdest);
if ( swap->I.iambob != 0 ) if ( swap->I.iambob != 0 )
{ {
basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,bobcoin,0,0,LP_DEXFEE(swap->I.bobsatoshis) + 0*bobcoin->txfee,0,0,jumblrflag); basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,bobcoin,0,0,LP_DEXFEE(swap->I.bobsatoshis) + 0*bobcoin->txfee,0,0,jumblrflag);
@ -1193,9 +1263,9 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256
swap->bobpayment.utxotxid = qp->txid, swap->bobpayment.utxovout = qp->vout; swap->bobpayment.utxotxid = qp->txid, swap->bobpayment.utxovout = qp->vout;
swap->bobdeposit.utxotxid = qp->txid2, swap->bobdeposit.utxovout = qp->vout2; swap->bobdeposit.utxotxid = qp->txid2, swap->bobdeposit.utxovout = qp->vout2;
swap->alicepayment.utxotxid = qp->desttxid, swap->alicepayment.utxovout = qp->destvout; swap->alicepayment.utxotxid = qp->desttxid, swap->alicepayment.utxovout = qp->destvout;
LP_mark_spent(swap->I.bobstr,qp->txid,qp->vout); LP_mark_spent(bobstr,qp->txid,qp->vout);
LP_mark_spent(swap->I.bobstr,qp->txid2,qp->vout2); LP_mark_spent(bobstr,qp->txid2,qp->vout2);
LP_mark_spent(swap->I.alicestr,qp->desttxid,qp->destvout); LP_mark_spent(alicestr,qp->desttxid,qp->destvout);
if ( swap->I.iambob != 0 ) if ( swap->I.iambob != 0 )
swap->otherfee.utxotxid = qp->feetxid, swap->otherfee.utxovout = qp->feevout; swap->otherfee.utxotxid = qp->feetxid, swap->otherfee.utxovout = qp->feevout;
else else
@ -1203,7 +1273,7 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256
swap->myfee.utxotxid = qp->feetxid, swap->myfee.utxovout = qp->feevout; swap->myfee.utxotxid = qp->feetxid, swap->myfee.utxovout = qp->feevout;
LP_mark_spent(swap->I.alicestr,qp->feetxid,qp->feevout); LP_mark_spent(swap->I.alicestr,qp->feetxid,qp->feevout);
} }
//char str[65],str2[65],str3[65]; printf("IAMBOB.%d %s %s %s [%s %s]\n",swap->I.iambob,bits256_str(str,qp->txid),bits256_str(str2,qp->txid2),bits256_str(str3,qp->feetxid),swap->I.bobstr,swap->I.alicestr); //char str[65],str2[65],str3[65]; printf("IAMBOB.%d %s %s %s [%s %s]\n",swap->I.iambob,bits256_str(str,qp->txid),bits256_str(str2,qp->txid2),bits256_str(str3,qp->feetxid),bobstr,alicestr);
return(swap); return(swap);
} }

300
iguana/exchanges/LP_transaction.c

@ -755,6 +755,12 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
value = 0; value = 0;
if ( (coin= LP_coinfind(symbol)) != 0 ) if ( (coin= LP_coinfind(symbol)) != 0 )
{ {
if ( coin->etomic[0] != 0 )
{
if ( (coin= LP_coinfind("ETOMIC")) == 0 )
return(0);
symbol = coin->symbol;
}
if ( txfee > 0 && txfee < coin->txfee ) if ( txfee > 0 && txfee < coin->txfee )
txfee = coin->txfee; txfee = coin->txfee;
#ifndef BASILISK_DISABLESENDTX #ifndef BASILISK_DISABLESENDTX
@ -1193,10 +1199,10 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_
return(n); return(n);
} }
char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_info *coin,struct vin_info *V,int32_t max,bits256 privkey,cJSON *outputs,cJSON *vins,cJSON *privkeys,int64_t txfee,bits256 utxotxid,int32_t utxovout,uint32_t locktime) char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_info *coin,struct vin_info *V,int32_t max,bits256 privkey,cJSON *outputs,cJSON *vins,cJSON *privkeys,int64_t txfee,bits256 utxotxid,int32_t utxovout,uint32_t locktime,char *opretstr)
{ {
static void *ctx; static void *ctx;
cJSON *txobj,*item; uint8_t addrtype,rmd160[20],script[64],spendscript[256]; char *coinaddr,*rawtxbytes; bits256 txid; uint32_t timestamp; int64_t change=0,adjust=0,total,value,amount = 0; int32_t i,dustcombine,scriptlen,spendlen,suppress_pubkeys,ignore_cltverr,numvouts=0,numvins=0,numutxos=0; struct LP_address_utxo *utxos[LP_MAXVINS*256]; struct LP_address *ap; cJSON *txobj,*item; uint8_t addrtype,rmd160[20],script[8192],spendscript[256]; char *coinaddr,*rawtxbytes,*scriptstr; bits256 txid; uint32_t timestamp; int64_t change=0,adjust=0,total,value,amount = 0; int32_t i,len,dustcombine,scriptlen,spendlen,suppress_pubkeys,ignore_cltverr,numvouts=0,numvins=0,numutxos=0; struct LP_address_utxo *utxos[LP_MAXVINS*256]; struct LP_address *ap;
if ( ctx == 0 ) if ( ctx == 0 )
ctx = bitcoin_ctx(); ctx = bitcoin_ctx();
*numvinsp = 0; *numvinsp = 0;
@ -1291,15 +1297,32 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
free_json(txobj); free_json(txobj);
return(0); return(0);
} }
bitcoin_addr2rmd160(coin->symbol,coin->taddr,&addrtype,rmd160,coinaddr); if ( (scriptstr= jstr(item,"script")) != 0 )
if ( addrtype == coin->pubtype )
spendlen = bitcoin_standardspend(spendscript,0,rmd160);
else spendlen = bitcoin_p2shspend(spendscript,0,rmd160);
if ( i == numvouts-1 && strcmp(coinaddr,coin->smartaddr) == 0 && change != 0 )
{ {
printf("combine last vout %.8f with change %.8f\n",dstr(value+adjust),dstr(change)); spendlen = (int32_t)strlen(scriptstr) >> 1;
value += change; if ( spendlen < sizeof(script) )
change = 0; {
decode_hex(script,spendlen,scriptstr);
printf("i.%d using external script.(%s)\n",i,scriptstr);
}
else
{
printf("custom script.%d too long %d\n",i,spendlen);
return(0);
}
}
else
{
bitcoin_addr2rmd160(coin->symbol,coin->taddr,&addrtype,rmd160,coinaddr);
if ( addrtype == coin->pubtype )
spendlen = bitcoin_standardspend(spendscript,0,rmd160);
else spendlen = bitcoin_p2shspend(spendscript,0,rmd160);
if ( i == numvouts-1 && strcmp(coinaddr,coin->smartaddr) == 0 && change != 0 )
{
printf("combine last vout %.8f with change %.8f\n",dstr(value+adjust),dstr(change));
value += change;
change = 0;
}
} }
txobj = bitcoin_txoutput(txobj,spendscript,spendlen,value + adjust); txobj = bitcoin_txoutput(txobj,spendscript,spendlen,value + adjust);
} }
@ -1317,6 +1340,36 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
} }
if ( change != 0 ) if ( change != 0 )
txobj = bitcoin_txoutput(txobj,script,scriptlen,change); txobj = bitcoin_txoutput(txobj,script,scriptlen,change);
if ( opretstr != 0 )
{
spendlen = (int32_t)strlen(opretstr) >> 1;
if ( spendlen < sizeof(script) )
{
len = 0;
script[len++] = SCRIPT_OP_RETURN;
if ( spendlen < 76 )
script[len++] = spendlen;
else if ( spendlen <= 0xff )
{
script[len++] = 0x4c;
script[len++] = spendlen;
}
else if ( spendlen <= 0xffff )
{
script[len++] = 0x4d;
script[len++] = (spendlen & 0xff);
script[len++] = ((spendlen >> 8) & 0xff);
}
decode_hex(&script[len],spendlen,opretstr);
txobj = bitcoin_txoutput(txobj,script,len + spendlen,0);
printf("OP_RETURN.[%d, %d] script.(%s)\n",len,spendlen,opretstr);
}
else
{
printf("custom script.%d too long %d\n",i,spendlen);
return(0);
}
}
if ( (rawtxbytes= bitcoin_json2hex(coin->symbol,coin->isPoS,&txid,txobj,V)) != 0 ) if ( (rawtxbytes= bitcoin_json2hex(coin->symbol,coin->isPoS,&txid,txobj,V)) != 0 )
{ {
} else printf("error making rawtx suppress.%d\n",suppress_pubkeys); } else printf("error making rawtx suppress.%d\n",suppress_pubkeys);
@ -1329,6 +1382,11 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
{ {
static void *ctx; static void *ctx;
int32_t iter,i,utxovout,autofee,completed=0,maxV,numvins,numvouts,datalen,suppress_pubkeys; bits256 privkey; struct LP_address *ap; char changeaddr[64],vinaddr[64],str[65],*signedtx=0,*rawtx=0; struct vin_info *V; uint32_t locktime; cJSON *retjson,*item,*outputs,*vins=0,*txobj=0,*privkeys=0; struct iguana_msgtx msgtx; bits256 utxotxid,signedtxid; uint64_t txfee,newtxfee=10000; int32_t iter,i,utxovout,autofee,completed=0,maxV,numvins,numvouts,datalen,suppress_pubkeys; bits256 privkey; struct LP_address *ap; char changeaddr[64],vinaddr[64],str[65],*signedtx=0,*rawtx=0; struct vin_info *V; uint32_t locktime; cJSON *retjson,*item,*outputs,*vins=0,*txobj=0,*privkeys=0; struct iguana_msgtx msgtx; bits256 utxotxid,signedtxid; uint64_t txfee,newtxfee=10000;
if ( coin->etomic[0] != 0 )
{
if ( (coin= LP_coinfind("ETOMIC")) == 0 )
return(0);
}
if ( ctx == 0 ) if ( ctx == 0 )
ctx = bitcoin_ctx(); ctx = bitcoin_ctx();
if ( (outputs= jarray(&numvouts,argjson,"outputs")) == 0 ) if ( (outputs= jarray(&numvouts,argjson,"outputs")) == 0 )
@ -1367,7 +1425,7 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
vins = cJSON_CreateArray(); vins = cJSON_CreateArray();
memset(V,0,sizeof(*V) * maxV); memset(V,0,sizeof(*V) * maxV);
numvins = 0; numvins = 0;
if ( (rawtx= LP_createrawtransaction(&txobj,&numvins,coin,V,maxV,privkey,outputs,vins,privkeys,iter == 0 ? txfee : newtxfee,utxotxid,utxovout,locktime)) != 0 ) if ( (rawtx= LP_createrawtransaction(&txobj,&numvins,coin,V,maxV,privkey,outputs,vins,privkeys,iter == 0 ? txfee : newtxfee,utxotxid,utxovout,locktime,jstr(argjson,"opreturn"))) != 0 )
{ {
completed = 0; completed = 0;
memset(&msgtx,0,sizeof(msgtx)); memset(&msgtx,0,sizeof(msgtx));
@ -1436,6 +1494,11 @@ int32_t basilisk_rawtx_gen(void *ctx,char *str,uint32_t swapstarted,uint8_t *pub
struct iguana_info *coin; int32_t len,retval=-1; char *retstr,*hexstr; cJSON *argjson,*outputs,*item,*retjson,*obj; struct iguana_info *coin; int32_t len,retval=-1; char *retstr,*hexstr; cJSON *argjson,*outputs,*item,*retjson,*obj;
if ( (coin= LP_coinfind(rawtx->symbol)) == 0 ) if ( (coin= LP_coinfind(rawtx->symbol)) == 0 )
return(-1); return(-1);
if ( coin->etomic[0] != 0 )
{
if ( (coin= LP_coinfind("ETOMIC")) == 0 )
return(-1);
}
if ( strcmp(coin->smartaddr,vinaddr) != 0 ) if ( strcmp(coin->smartaddr,vinaddr) != 0 )
{ {
printf("???????????????????????? basilisk_rawtx_gen mismatched %s %s vinaddr.%s != (%s)\n",rawtx->symbol,coin->symbol,vinaddr,coin->smartaddr); printf("???????????????????????? basilisk_rawtx_gen mismatched %s %s vinaddr.%s != (%s)\n",rawtx->symbol,coin->symbol,vinaddr,coin->smartaddr);
@ -1563,8 +1626,10 @@ int32_t LP_swap_getcoinaddr(char *symbol,char *coinaddr,bits256 txid,int32_t vou
int32_t basilisk_swap_getsigscript(char *symbol,uint8_t *script,int32_t maxlen,bits256 txid,int32_t vini) int32_t basilisk_swap_getsigscript(char *symbol,uint8_t *script,int32_t maxlen,bits256 txid,int32_t vini)
{ {
cJSON *retjson,*vins,*item,*skey; int32_t n,scriptlen = 0; char *hexstr; cJSON *retjson,*vins,*item,*skey; int32_t n,scriptlen = 0; char *hexstr;
if ( (retjson= LP_gettx(symbol,txid,0)) != 0 ) //char str[65]; printf("getsigscript %s %s/v%d\n",symbol,bits256_str(str,txid),vini);
if ( bits256_nonz(txid) != 0 && (retjson= LP_gettx(symbol,txid,0)) != 0 )
{ {
//printf("gettx.(%s)\n",jprint(retjson,0));
if ( (vins= jarray(&n,retjson,"vin")) != 0 && vini < n ) if ( (vins= jarray(&n,retjson,"vin")) != 0 && vini < n )
{ {
item = jitem(vins,vini); item = jitem(vins,vini);
@ -1572,7 +1637,7 @@ int32_t basilisk_swap_getsigscript(char *symbol,uint8_t *script,int32_t maxlen,b
{ {
scriptlen >>= 1; scriptlen >>= 1;
decode_hex(script,scriptlen,hexstr); decode_hex(script,scriptlen,hexstr);
//char str[65]; printf("%s/v%d sigscript.(%s)\n",bits256_str(str,txid),vini,hexstr); //char str[65]; printf("%s %s/v%d sigscript.(%s)\n",symbol,bits256_str(str,txid),vini,hexstr);
} }
} }
free_json(retjson); free_json(retjson);
@ -1709,9 +1774,6 @@ int32_t basilisk_swap_bobredeemscript(int32_t depositflag,int32_t *secretstartp,
memcpy(secret160,secretAm,20); memcpy(secret160,secretAm,20);
memcpy(secret256,secretAm256,32); memcpy(secret256,secretAm256,32);
} }
//for (i=0; i<32; i++)
// printf("%02x",secret256[i]);
//printf(" <- secret256 depositflag.%d nonz.%d\n",depositflag,bits256_nonz(privkey));
if ( bits256_nonz(cltvpub) == 0 || bits256_nonz(destpub) == 0 ) if ( bits256_nonz(cltvpub) == 0 || bits256_nonz(destpub) == 0 )
return(-1); return(-1);
for (i=0; i<20; i++) for (i=0; i<20; i++)
@ -1723,48 +1785,37 @@ int32_t basilisk_swap_bobredeemscript(int32_t depositflag,int32_t *secretstartp,
memcpy(pubkeyB+1,destpub.bytes,sizeof(destpub)); memcpy(pubkeyB+1,destpub.bytes,sizeof(destpub));
redeemscript[n++] = SCRIPT_OP_IF; redeemscript[n++] = SCRIPT_OP_IF;
n = bitcoin_checklocktimeverify(redeemscript,n,locktime); n = bitcoin_checklocktimeverify(redeemscript,n,locktime);
#ifdef DISABLE_CHECKSIG if ( depositflag != 0 )
n = bitcoin_secret256spend(redeemscript,n,cltvpub); {
#else //for (i=0; i<20; i++)
// printf("%02x",secretAm[i]);
//printf(" <- secretAm depositflag.%d nonz.%d\n",depositflag,bits256_nonz(privkey));
n = bitcoin_secret160verify(redeemscript,n,secretAm);
}
n = bitcoin_pubkeyspend(redeemscript,n,pubkeyA); n = bitcoin_pubkeyspend(redeemscript,n,pubkeyA);
#endif
redeemscript[n++] = SCRIPT_OP_ELSE; redeemscript[n++] = SCRIPT_OP_ELSE;
if ( secretstartp != 0 ) if ( secretstartp != 0 )
*secretstartp = n + 2; *secretstartp = n + 2;
if ( 1 ) if ( bits256_nonz(privkey) != 0 )
{
if ( 1 && bits256_nonz(privkey) != 0 )
{
uint8_t bufA[20],bufB[20];
revcalc_rmd160_sha256(bufA,privkey);
calc_rmd160_sha256(bufB,privkey.bytes,sizeof(privkey));
/*if ( memcmp(bufA,secret160,sizeof(bufA)) == 0 )
printf("MATCHES BUFA\n");
else if ( memcmp(bufB,secret160,sizeof(bufB)) == 0 )
printf("MATCHES BUFB\n");
else printf("secret160 matches neither\n");
for (i=0; i<20; i++)
printf("%02x",bufA[i]);
printf(" <- revcalc\n");
for (i=0; i<20; i++)
printf("%02x",bufB[i]);
printf(" <- calc\n");*/
memcpy(secret160,bufB,20);
}
n = bitcoin_secret160verify(redeemscript,n,secret160);
}
else
{ {
redeemscript[n++] = 0xa8;//IGUANA_OP_SHA256; uint8_t bufA[20],bufB[20];
redeemscript[n++] = 0x20; revcalc_rmd160_sha256(bufA,privkey);
memcpy(&redeemscript[n],secret256,0x20), n += 0x20; calc_rmd160_sha256(bufB,privkey.bytes,sizeof(privkey));
redeemscript[n++] = 0x88; //SCRIPT_OP_EQUALVERIFY; /*if ( memcmp(bufA,secret160,sizeof(bufA)) == 0 )
printf("MATCHES BUFA\n");
else if ( memcmp(bufB,secret160,sizeof(bufB)) == 0 )
printf("MATCHES BUFB\n");
else printf("secret160 matches neither\n");
for (i=0; i<20; i++)
printf("%02x",bufA[i]);
printf(" <- revcalc\n");
for (i=0; i<20; i++)
printf("%02x",bufB[i]);
printf(" <- calc\n");*/
memcpy(secret160,bufB,20);
} }
#ifdef DISABLE_CHECKSIG n = bitcoin_secret160verify(redeemscript,n,secret160);
n = bitcoin_secret256spend(redeemscript,n,destpub);
#else
n = bitcoin_pubkeyspend(redeemscript,n,pubkeyB); n = bitcoin_pubkeyspend(redeemscript,n,pubkeyB);
#endif
redeemscript[n++] = SCRIPT_OP_ENDIF; redeemscript[n++] = SCRIPT_OP_ENDIF;
return(n); return(n);
} }
@ -1779,8 +1830,8 @@ int32_t basilisk_bobscript(uint8_t *rmd160,uint8_t *redeemscript,int32_t *redeem
{ {
calc_rmd160_sha256(rmd160,redeemscript,n); calc_rmd160_sha256(rmd160,redeemscript,n);
n = bitcoin_p2shspend(script,0,rmd160); n = bitcoin_p2shspend(script,0,rmd160);
//int32_t i; for (i=0; i<n; i++) //int32_t i; for (i=0; i<*redeemlenp; i++)
// printf("%02x",script[i]); // printf("%02x",redeemscript[i]);
//printf(" <- redeem.%d bobtx dflag.%d spendscript.[%d]\n",*redeemlenp,depositflag,n); //printf(" <- redeem.%d bobtx dflag.%d spendscript.[%d]\n",*redeemlenp,depositflag,n);
} }
return(n); return(n);
@ -1789,11 +1840,6 @@ int32_t basilisk_bobscript(uint8_t *rmd160,uint8_t *redeemscript,int32_t *redeem
int32_t basilisk_swapuserdata(uint8_t *userdata,bits256 privkey,int32_t ifpath,bits256 signpriv,uint8_t *redeemscript,int32_t redeemlen) int32_t basilisk_swapuserdata(uint8_t *userdata,bits256 privkey,int32_t ifpath,bits256 signpriv,uint8_t *redeemscript,int32_t redeemlen)
{ {
int32_t i,len = 0; int32_t i,len = 0;
#ifdef DISABLE_CHECKSIG
userdata[len++] = sizeof(signpriv);
for (i=0; i<sizeof(privkey); i++)
userdata[len++] = signpriv.bytes[i];
#endif
if ( bits256_nonz(privkey) != 0 ) if ( bits256_nonz(privkey) != 0 )
{ {
userdata[len++] = sizeof(privkey); userdata[len++] = sizeof(privkey);
@ -1811,11 +1857,26 @@ int32_t basilisk_swapuserdata(uint8_t *userdata,bits256 privkey,int32_t ifpath,b
OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <alice_pubA0> OP_CHECKSIG OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <alice_pubA0> OP_CHECKSIG
OP_ENDIF*/ OP_ENDIF*/
int32_t LP_etomicsymbol(char *activesymbol,char *etomic,char *symbol)
{
struct iguana_info *coin;
etomic[0] = activesymbol[0] = 0;
if ( (coin= LP_coinfind(symbol)) != 0 )
{
strcpy(etomic,coin->etomic);
if ( etomic[0] != 0 )
strcpy(activesymbol,"ETOMIC");
else strcpy(activesymbol,symbol);
}
return(etomic[0] != 0);
}
int32_t basilisk_bobpayment_reclaim(struct basilisk_swap *swap,int32_t delay) int32_t basilisk_bobpayment_reclaim(struct basilisk_swap *swap,int32_t delay)
{ {
static bits256 zero; static bits256 zero;
uint8_t userdata[512]; int32_t retval,len = 0; struct iguana_info *coin; uint8_t userdata[512]; char bobstr[65],bobtomic[128]; int32_t retval,len = 0; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 ) LP_etomicsymbol(bobstr,bobtomic,swap->I.bobstr);
if ( (coin= LP_coinfind(bobstr)) != 0 )
{ {
//printf("basilisk_bobpayment_reclaim\n"); //printf("basilisk_bobpayment_reclaim\n");
len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[1],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[1],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen);
@ -1829,14 +1890,15 @@ int32_t basilisk_bobpayment_reclaim(struct basilisk_swap *swap,int32_t delay)
//basilisk_txlog(swap,&swap->bobreclaim,delay); //basilisk_txlog(swap,&swap->bobreclaim,delay);
return(retval); return(retval);
} }
} else printf("basilisk_bobpayment_reclaim cant find (%s)\n",swap->I.bobstr); } else printf("basilisk_bobpayment_reclaim cant find (%s)\n",bobstr);
return(-1); return(-1);
} }
int32_t basilisk_bobdeposit_refund(struct basilisk_swap *swap,int32_t delay) int32_t basilisk_bobdeposit_refund(struct basilisk_swap *swap,int32_t delay)
{ {
uint8_t userdata[512]; int32_t i,retval,len = 0; char str[65]; struct iguana_info *coin; uint8_t userdata[512]; int32_t i,retval,len = 0; char str[65],bobstr[65],bobtomic[128]; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 ) LP_etomicsymbol(bobstr,bobtomic,swap->I.bobstr);
if ( (coin= LP_coinfind(bobstr)) != 0 )
{ {
len = basilisk_swapuserdata(userdata,swap->I.privBn,0,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); len = basilisk_swapuserdata(userdata,swap->I.privBn,0,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen);
memcpy(swap->I.userdata_bobrefund,userdata,len); memcpy(swap->I.userdata_bobrefund,userdata,len);
@ -1849,7 +1911,7 @@ int32_t basilisk_bobdeposit_refund(struct basilisk_swap *swap,int32_t delay)
//basilisk_txlog(swap,&swap->bobrefund,delay); //basilisk_txlog(swap,&swap->bobrefund,delay);
return(retval); return(retval);
} }
} else printf("basilisk_bobdeposit_refund cant find (%s)\n",swap->I.bobstr); } else printf("basilisk_bobdeposit_refund cant find (%s)\n",bobstr);
return(-1); return(-1);
} }
@ -1875,8 +1937,9 @@ void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,u
int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,int32_t genflag) int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,int32_t genflag)
{ {
char coinaddr[64],checkaddr[64]; struct iguana_info *coin; char coinaddr[64],checkaddr[64],bobstr[65],bobtomic[128]; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 ) LP_etomicsymbol(bobstr,bobtomic,swap->I.bobstr);
if ( (coin= LP_coinfind(bobstr)) != 0 )
{ {
bitcoin_address(coin->symbol,coinaddr,coin->taddr,coin->pubtype,swap->changermd160,20); bitcoin_address(coin->symbol,coinaddr,coin->taddr,coin->pubtype,swap->changermd160,20);
if ( genflag != 0 && swap->I.iambob == 0 ) if ( genflag != 0 && swap->I.iambob == 0 )
@ -1887,9 +1950,9 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i
bitcoin_address(coin->symbol,swap->bobpayment.p2shaddr,coin->taddr,coin->p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); bitcoin_address(coin->symbol,swap->bobpayment.p2shaddr,coin->taddr,coin->p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen);
strcpy(swap->bobpayment.I.destaddr,swap->bobpayment.p2shaddr); strcpy(swap->bobpayment.I.destaddr,swap->bobpayment.p2shaddr);
//LP_importaddress(coin->symbol,swap->bobpayment.I.destaddr); //LP_importaddress(coin->symbol,swap->bobpayment.I.destaddr);
//int32_t i; for (i=0; i<swap->bobpayment.I.redeemlen; i++) int32_t i; for (i=0; i<swap->bobpayment.I.redeemlen; i++)
// printf("%02x",swap->bobpayment.redeemscript[i]); printf("%02x",swap->bobpayment.redeemscript[i]);
//printf(" <- bobpayment redeem %d %s\n",i,swap->bobpayment.I.destaddr); printf(" <- bobpayment redeem %d %s\n",i,swap->bobpayment.I.destaddr);
if ( genflag != 0 && bits256_nonz(*(bits256 *)swap->I.secretBn256) != 0 && swap->bobpayment.I.datalen == 0 ) if ( genflag != 0 && bits256_nonz(*(bits256 *)swap->I.secretBn256) != 0 && swap->bobpayment.I.datalen == 0 )
{ {
basilisk_rawtx_gen(swap->ctx,"payment",swap->I.started,swap->persistent_pubkey33,1,1,&swap->bobpayment,swap->bobpayment.I.locktime,swap->bobpayment.spendscript,swap->bobpayment.I.spendlen,coin->txfee,1,0,swap->persistent_privkey,swap->changermd160,coinaddr); basilisk_rawtx_gen(swap->ctx,"payment",swap->I.started,swap->persistent_pubkey33,1,1,&swap->bobpayment,swap->bobpayment.I.locktime,swap->bobpayment.spendscript,swap->bobpayment.I.spendlen,coin->txfee,1,0,swap->persistent_privkey,swap->changermd160,coinaddr);
@ -1952,43 +2015,10 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i
} }
} }
} }
} else printf("bobscripts set cant find (%s)\n",swap->I.bobstr); } else printf("bobscripts set cant find (%s)\n",bobstr);
return(0); return(0);
} }
/*
#ifdef old
int32_t basilisk_alicepayment_spend(struct basilisk_swap *swap,struct basilisk_rawtx *dest)
{
int32_t i,retval;
printf("alicepayment_spend\n");
swap->alicepayment.I.spendlen = basilisk_alicescript(swap->alicepayment.redeemscript,&swap->alicepayment.I.redeemlen,swap->alicepayment.spendscript,0,swap->alicepayment.I.destaddr,coin->p2shtype,swap->I.pubAm,swap->I.pubBn);
printf("alicepayment_spend len.%d\n",swap->alicepayment.I.spendlen);
if ( swap->I.iambob == 0 )
{
memcpy(swap->I.userdata_alicereclaim,swap->alicepayment.redeemscript,swap->alicepayment.I.spendlen);
swap->I.userdata_alicereclaimlen = swap->alicepayment.I.spendlen;
}
else
{
memcpy(swap->I.userdata_bobspend,swap->alicepayment.redeemscript,swap->alicepayment.I.spendlen);
swap->I.userdata_bobspendlen = swap->alicepayment.I.spendlen;
}
if ( (retval= basilisk_rawtx_sign(coin->symbol,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,swap,dest,&swap->alicepayment,swap->I.privAm,&swap->I.privBn,0,0,1,swap->changermd160)) == 0 )
{
for (i=0; i<dest->I.datalen; i++)
printf("%02x",dest->txbytes[i]);
printf(" <- msigspend\n\n");
if ( dest == &swap->bobspend )
swap->I.bobspent = 1;
//basilisk_txlog(swap,dest,0); // bobspend or alicereclaim
return(retval);
}
return(-1);
}
#endif*/
void basilisk_alicepayment(struct basilisk_swap *swap,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn) void basilisk_alicepayment(struct basilisk_swap *swap,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn)
{ {
char coinaddr[64]; char coinaddr[64];
@ -2000,8 +2030,9 @@ void basilisk_alicepayment(struct basilisk_swap *swap,struct iguana_info *coin,s
int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
{ {
char coinaddr[64]; int32_t retval = -1; struct iguana_info *coin; char coinaddr[64],alicestr[65],alicetomic[128]; int32_t retval = -1; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.alicestr)) != 0 ) LP_etomicsymbol(alicestr,alicetomic,swap->I.alicestr);
if ( (coin= LP_coinfind(alicestr)) != 0 )
{ {
if ( swap->alicepayment.I.datalen == 0 ) if ( swap->alicepayment.I.datalen == 0 )
basilisk_alicepayment(swap,coin,&swap->alicepayment,swap->I.pubAm,swap->I.pubBn); basilisk_alicepayment(swap,coin,&swap->alicepayment,swap->I.pubAm,swap->I.pubBn);
@ -2046,14 +2077,16 @@ int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *d
//printf("fee sent\n"); //printf("fee sent\n");
return(0); return(0);
} }
} else printf("basilisk alicetx cant find (%s)\n",swap->I.alicestr); } else printf("basilisk alicetx cant find (%s)\n",alicestr);
return(-1); return(-1);
} }
int32_t LP_verify_otherfee(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) int32_t LP_verify_otherfee(struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{ {
int32_t diff; struct iguana_info *coin; int32_t diff; char bobstr[65],bobtomic[128],alicestr[65],alicetomic[128]; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.iambob != 0 ? swap->I.alicestr : swap->I.bobstr)) != 0 ) LP_etomicsymbol(bobstr,bobtomic,swap->I.bobstr);
LP_etomicsymbol(alicestr,alicetomic,swap->I.alicestr);
if ( (coin= LP_coinfind(swap->I.iambob != 0 ? alicestr : bobstr)) != 0 )
{ {
if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->otherfee,0,data,datalen,0) == 0 ) if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->otherfee,0,data,datalen,0) == 0 )
{ {
@ -2077,8 +2110,9 @@ int32_t LP_verify_otherfee(struct basilisk_swap *swap,uint8_t *data,int32_t data
int32_t LP_verify_alicespend(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) int32_t LP_verify_alicespend(struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{ {
struct iguana_info *coin; struct iguana_info *coin; char alicestr[65],alicetomic[128];
if ( (coin= LP_coinfind(swap->I.alicestr)) != 0 ) LP_etomicsymbol(alicestr,alicetomic,swap->I.alicestr);
if ( (coin= LP_coinfind(alicestr)) != 0 )
{ {
if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->alicespend,0,data,datalen,0) == 0 ) if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->alicespend,0,data,datalen,0) == 0 )
{ {
@ -2089,22 +2123,23 @@ int32_t LP_verify_alicespend(struct basilisk_swap *swap,uint8_t *data,int32_t da
return(0); return(0);
} }
} }
} else printf("verify alicespend cant find (%s)\n",swap->I.alicestr); } else printf("verify alicespend cant find (%s)\n",alicestr);
return(-1); return(-1);
} }
/* Bob deposit: /* Bob deposit:
OP_IF OP_IF
<now + INSTANTDEX_LOCKTIME*2> OP_CLTV OP_DROP <alice_pubA0> OP_CHECKSIG OP_SIZE 32 OP_EQUALVERIFY OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <now + INSTANTDEX_LOCKTIME*2> OP_CLTV OP_DROP <alice_pubA0> OP_CHECKSIG
OP_ELSE OP_ELSE
OP_HASH160 <hash(bob_privN)> OP_EQUALVERIFY <bob_pubB0> OP_CHECKSIG OP_SIZE 32 OP_EQUALVERIFY OP_HASH160 <hash(bob_privN)> OP_EQUALVERIFY <bob_pubB0> OP_CHECKSIG
OP_ENDIF*/ OP_ENDIF
*/
int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{ {
static bits256 zero; uint8_t userdata[512]; char bobstr[65],bobtomic[128]; int32_t i,retval=-1,len = 0; struct iguana_info *coin; bits256 revAm;
uint8_t userdata[512]; int32_t retval=-1,len = 0; struct iguana_info *coin; LP_etomicsymbol(bobstr,bobtomic,swap->I.bobstr);
if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 ) if ( (coin= LP_coinfind(bobstr)) != 0 )
{ {
if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->bobdeposit,0,data,datalen,0) == 0 ) if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->bobdeposit,0,data,datalen,0) == 0 )
{ {
@ -2113,7 +2148,10 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da
if ( bits256_nonz(swap->bobdeposit.I.signedtxid) != 0 ) if ( bits256_nonz(swap->bobdeposit.I.signedtxid) != 0 )
swap->depositunconf = 1; swap->depositunconf = 1;
else swap->bobdeposit.I.signedtxid = swap->bobdeposit.I.actualtxid; else swap->bobdeposit.I.signedtxid = swap->bobdeposit.I.actualtxid;
len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); memset(revAm.bytes,0,sizeof(revAm));
for (i=0; i<32; i++)
revAm.bytes[i] = swap->I.privAm.bytes[31-i];
len = basilisk_swapuserdata(userdata,revAm,1,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen);
swap->aliceclaim.utxotxid = swap->bobdeposit.I.signedtxid; swap->aliceclaim.utxotxid = swap->bobdeposit.I.signedtxid;
memcpy(swap->I.userdata_aliceclaim,userdata,len); memcpy(swap->I.userdata_aliceclaim,userdata,len);
swap->I.userdata_aliceclaimlen = len; swap->I.userdata_aliceclaimlen = len;
@ -2143,15 +2181,16 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da
return(LP_waitmempool(coin->symbol,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,0,60)); return(LP_waitmempool(coin->symbol,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,0,60));
} else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->aliceclaim.I.suppress_pubkeys,swap->bobdeposit.I.destaddr); } else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->aliceclaim.I.suppress_pubkeys,swap->bobdeposit.I.destaddr);
} }
} else printf("verify bob depositcant find bob coin (%s)\n",swap->I.bobstr); } else printf("verify bob depositcant find bob coin (%s)\n",bobstr);
printf("error with bobdeposit\n"); printf("error with bobdeposit\n");
return(retval); return(retval);
} }
int32_t LP_verify_alicepayment(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) int32_t LP_verify_alicepayment(struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{ {
struct iguana_info *coin; struct iguana_info *coin; char alicestr[65],alicetomic[128];
if ( (coin= LP_coinfind(swap->I.alicestr)) != 0 ) LP_etomicsymbol(alicestr,alicetomic,swap->I.alicestr);
if ( (coin= LP_coinfind(alicestr)) != 0 )
{ {
if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->alicepayment,0,data,datalen,0) == 0 ) if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->alicepayment,0,data,datalen,0) == 0 )
{ {
@ -2167,15 +2206,25 @@ int32_t LP_verify_alicepayment(struct basilisk_swap *swap,uint8_t *data,int32_t
//LP_importaddress(coin->symbol,swap->alicepayment.p2shaddr); //LP_importaddress(coin->symbol,swap->alicepayment.p2shaddr);
return(0); return(0);
} }
} else printf("verify alicepayment couldnt find coin.(%s)\n",swap->I.alicestr); } else printf("verify alicepayment couldnt find coin.(%s)\n",alicestr);
printf("error validating alicepayment\n"); printf("error validating alicepayment\n");
return(-1); return(-1);
} }
/*
Bob paytx:
OP_IF
<now + INSTANTDEX_LOCKTIME> OP_CLTV OP_DROP <bob_pubB1> OP_CHECKSIG
OP_ELSE
OP_SIZE 32 OP_EQUALVERIFY OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <alice_pubA0> OP_CHECKSIG
OP_ENDIF
*/
int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{ {
uint8_t userdata[512]; int32_t i,retval=-1,len = 0; bits256 revAm; struct iguana_info *coin; uint8_t userdata[512]; char bobstr[65],bobtomic[128]; int32_t i,retval=-1,len = 0; bits256 revAm; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 ) LP_etomicsymbol(bobstr,bobtomic,swap->I.bobstr);
if ( (coin= LP_coinfind(bobstr)) != 0 )
{ {
memset(revAm.bytes,0,sizeof(revAm)); memset(revAm.bytes,0,sizeof(revAm));
if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->bobpayment,0,data,datalen,0) == 0 ) if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->bobpayment,0,data,datalen,0) == 0 )
@ -2184,6 +2233,7 @@ int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t da
swap->alicespend.utxotxid = swap->bobpayment.I.signedtxid = LP_broadcast_tx(swap->bobpayment.name,coin->symbol,swap->bobpayment.txbytes,swap->bobpayment.I.datalen); swap->alicespend.utxotxid = swap->bobpayment.I.signedtxid = LP_broadcast_tx(swap->bobpayment.name,coin->symbol,swap->bobpayment.txbytes,swap->bobpayment.I.datalen);
if ( bits256_nonz(swap->bobpayment.I.signedtxid) != 0 ) if ( bits256_nonz(swap->bobpayment.I.signedtxid) != 0 )
swap->paymentunconf = 1; swap->paymentunconf = 1;
memset(revAm.bytes,0,sizeof(revAm));
for (i=0; i<32; i++) for (i=0; i<32; i++)
revAm.bytes[i] = swap->I.privAm.bytes[31-i]; revAm.bytes[i] = swap->I.privAm.bytes[31-i];
len = basilisk_swapuserdata(userdata,revAm,0,swap->I.myprivs[0],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); len = basilisk_swapuserdata(userdata,revAm,0,swap->I.myprivs[0],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen);
@ -2215,7 +2265,7 @@ int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t da
return(LP_waitmempool(coin->symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,60)); return(LP_waitmempool(coin->symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,60));
} else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->alicespend.I.suppress_pubkeys,swap->bobpayment.I.destaddr); } else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->alicespend.I.suppress_pubkeys,swap->bobpayment.I.destaddr);
} }
} else printf("verify bobpayment cant find (%s)\n",swap->I.bobstr); } else printf("verify bobpayment cant find (%s)\n",bobstr);
printf("error validating bobpayment\n"); printf("error validating bobpayment\n");
return(-1); return(-1);
} }

6
iguana/exchanges/LP_utxo.c

@ -135,14 +135,16 @@ int32_t LP_reservation_check(bits256 txid,int32_t vout,bits256 pubkey)
struct LP_inuse_info *lp; int32_t retval = -1; struct LP_inuse_info *lp; int32_t retval = -1;
if ( bits256_nonz(pubkey) != 0 ) if ( bits256_nonz(pubkey) != 0 )
{ {
char str[65],str2[65];
portable_mutex_lock(&LP_inusemutex); portable_mutex_lock(&LP_inusemutex);
if ( (lp= _LP_inuse_find(txid,vout)) != 0 ) if ( (lp= _LP_inuse_find(txid,vout)) != 0 )
{ {
if ( bits256_cmp(lp->otherpub,pubkey) == 0 ) if ( bits256_cmp(lp->otherpub,pubkey) == 0 )
retval = 0; retval = 0;
} else printf("otherpub.%s != %s\n",bits256_str(str,lp->otherpub),bits256_str(str2,pubkey));
} else printf("couldnt find %s/v%d\n",bits256_str(str,txid),vout);
portable_mutex_unlock(&LP_inusemutex); portable_mutex_unlock(&LP_inusemutex);
} } else printf("LP_reservation_check null pubkey\n");
return(retval); return(retval);
} }

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

10
iguana/exchanges/etomicswap/CMakeLists.txt

@ -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)

106
iguana/exchanges/etomicswap/alice.c

@ -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;
}

218
iguana/exchanges/etomicswap/bob.c

@ -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;
}

196
iguana/exchanges/etomicswap/etomiccurl.c

@ -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;
}

28
iguana/exchanges/etomicswap/etomiccurl.h

@ -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

375
iguana/exchanges/etomicswap/etomiclib.cpp

@ -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");
}

151
iguana/exchanges/etomicswap/etomiclib.h

@ -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

1
iguana/exchanges/mm.c

@ -28,6 +28,7 @@ void PNACL_message(char *arg,...)
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
// #include "lib.h"
#ifndef NATIVE_WINDOWS #ifndef NATIVE_WINDOWS
#include "OS_portable.h" #include "OS_portable.h"
#else #else

13
iguana/exchanges/prices/autoprice

@ -1,11 +1,18 @@
#!/bin/bash #!/bin/bash
margin=0.05 margin=0.05
source userpass source userpass
./auto_chipskmd
./auto_chipsbtc # KMD/BTC must be first as other prices depend on it
#curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"BTC\",\"margin\":$margin,\"refbase\":\"komodo\",\"refrel\":\"coinmarketcap\"}" #curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"BTC\",\"margin\":$margin,\"refbase\":\"komodo\",\"refrel\":\"coinmarketcap\"}"
#curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BTC\",\"rel\":\"KMD\",\"fixed\":0.00025,\"margin\":$margin}" #curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BTC\",\"rel\":\"KMD\",\"fixed\":0.00025,\"margin\":$margin}"
#curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"BTC\",\"fixed\":4000,\"margin\":$margin}" #curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"BTC\",\"fixed\":4000,\"margin\":$margin}"
curl --url "http://127.0.0.1:7783" --data "{\"minprice\":0.0003,\"maxprice\":0.001,\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"BTC\",\"margin\":0.05,\"refbase\":\"komodo\",\"refrel\":\"coinmarketcap\"}"
./auto_chipskmd
./auto_chipsbtc
#curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"MNZ\",\"offset\":0.0,\"refbase\":\"KMD\",\"refrel\":\"BTC\",\"factor\":15000,\"margin\":-0.2}" #curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"MNZ\",\"offset\":0.0,\"refbase\":\"KMD\",\"refrel\":\"BTC\",\"factor\":15000,\"margin\":-0.2}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"HUSH\",\"rel\":\"KMD\",\"margin\":$margin,\"refbase\":\"hush\",\"refrel\":\"coinmarketcap\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"HUSH\",\"rel\":\"KMD\",\"margin\":$margin,\"refbase\":\"hush\",\"refrel\":\"coinmarketcap\"}"
@ -38,7 +45,7 @@ curl --url "http://127.0.0.1:7783" --data "{\"margin\":$margin,\"base\":\"SUPERN
curl --url "http://127.0.0.1:7783" --data "{\"margin\":$margin,\"base\":\"HODL\",\"rel\":\"KMD\",\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"address\":\"RNcUaMUEFLxVwtTo7rgruhwYanGk1jTkeU\",\"holdings\":[{\"coin\":\"siacoin\",\"balance\":185000000,\"comment\":\"using siafunds equal to million siacoin\"}],\"divisor\":10000000}" curl --url "http://127.0.0.1:7783" --data "{\"margin\":$margin,\"base\":\"HODL\",\"rel\":\"KMD\",\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"address\":\"RNcUaMUEFLxVwtTo7rgruhwYanGk1jTkeU\",\"holdings\":[{\"coin\":\"siacoin\",\"balance\":185000000,\"comment\":\"using siafunds equal to million siacoin\"}],\"divisor\":10000000}"
dexholdings="{\"coin\":\"blocknet\",\"balance\":4975836}" dexholdings="{\"coin\":\"blocknet\",\"balance\":4000000}"
curl --url "http://127.0.0.1:7783" --data "{\"base\":\"DEX\",\"rel\":\"KMD\",\"margin\":$margin,\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"address\":\"RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf\",\"holdings\":[$dexholdings],\"divisor\":1000000}" curl --url "http://127.0.0.1:7783" --data "{\"base\":\"DEX\",\"rel\":\"KMD\",\"margin\":$margin,\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"address\":\"RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf\",\"holdings\":[$dexholdings],\"divisor\":1000000}"
curl --url "http://127.0.0.1:7783" --data "{\"base\":\"BOTS\",\"rel\":\"KMD\",\"margin\":$margin,\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"address\":\"RNdqHx26GWy9bk8MtmH1UiXjQcXE4RKK2P\",\"holdings\":[$dexholdings],\"divisor\":3333333}" curl --url "http://127.0.0.1:7783" --data "{\"base\":\"BOTS\",\"rel\":\"KMD\",\"margin\":$margin,\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"address\":\"RNdqHx26GWy9bk8MtmH1UiXjQcXE4RKK2P\",\"holdings\":[$dexholdings],\"divisor\":3333333}"

3
iguana/exchanges/timelock

@ -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}"

3
iguana/exchanges/unlockedspend

@ -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\"}"

2
iguana/iguana_notary.c

@ -570,7 +570,7 @@ STRING_ARG(iguana,addnotary,ipaddr)
} }
char NOTARY_CURRENCIES[][16] = { char NOTARY_CURRENCIES[][16] = {
"REVS", "SUPERNET", "DEX", "PANGEA", "JUMBLR", "BET", "CRYPTO", "HODL", "BOTS", "MGW", "COQUI", "WLC", "KV", "CEAL", "MESH", "MNZ", "CHIPS", "MSHARK", "AXO", "ETOMIC", "BTCH", "VOTE2018", "CHAIN" }; // "LTC", "USD", "EUR", "JPY", "GBP", "AUD", "CAD", "CHF", "NZD", "CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK", "REVS", "SUPERNET", "DEX", "PANGEA", "JUMBLR", "BET", "CRYPTO", "HODL", "BOTS", "MGW", "COQUI", "WLC", "KV", "CEAL", "MESH", "MNZ", "CHIPS", "MSHARK", "AXO", "ETOMIC", "BTCH", "VOTE2018", "NINJA", "CHAIN" }; // "LTC", "USD", "EUR", "JPY", "GBP", "AUD", "CAD", "CHF", "NZD", "CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK",
void _iguana_notarystats(char *fname,int32_t totals[64],int32_t dispflag) void _iguana_notarystats(char *fname,int32_t totals[64],int32_t dispflag)
{ {

4
iguana/m_LP_StaticNanoMsg

@ -6,8 +6,8 @@ git pull
cd secp256k1; ./m_unix; cd .. cd secp256k1; ./m_unix; cd ..
cd ../crypto777; make -f m_LP_StaticNanoMsg all; make -f m_LP_StaticNanoMsg clean; cd ../iguana cd ../crypto777; make -f m_LP_StaticNanoMsg all; make -f m_LP_StaticNanoMsg clean; cd ../iguana
clang -g -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 -DUSE_STATIC_NANOMSG *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c clang -g -DNOTETOMIC -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 -DUSE_STATIC_NANOMSG *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c
clang -g -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 -DUSE_STATIC_NANOMSG main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c iguana_ramchain.c clang -g -DNOTETOMIC -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 -DUSE_STATIC_NANOMSG main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c iguana_ramchain.c
clang -g -o ../agents/iguana *.o ../agents/libcrypto777.a ../OSlibs/linux/$(uname -m)/libnanomsg-static.a -lcurl -lssl -lcrypto -lpthread -lz -lm -lanl -lrt -lnsl clang -g -o ../agents/iguana *.o ../agents/libcrypto777.a ../OSlibs/linux/$(uname -m)/libnanomsg-static.a -lcurl -lssl -lcrypto -lpthread -lz -lm -lanl -lrt -lnsl

2
iguana/m_mm

@ -10,4 +10,4 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
nanomsg_lib="../OSlibs/osx/$(uname -m)/libnanomsg-static.a" nanomsg_lib="../OSlibs/osx/$(uname -m)/libnanomsg-static.a"
fi fi
gcc -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a $nanomsg_lib -lcurl -lpthread -lm gcc -g -o marketmaker -DNOTETOMIC -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a $nanomsg_lib -lcurl -lpthread -lm

2
iguana/m_mm_StaticNanoMsg

@ -19,7 +19,7 @@ all:
+$(MAKE) -C secp256k1 -f m_unix_Makefile all +$(MAKE) -C secp256k1 -f m_unix_Makefile all
+$(MAKE) -C ../crypto777 -f m_LP_StaticNanoMsg all +$(MAKE) -C ../crypto777 -f m_LP_StaticNanoMsg all
+$(MAKE) -C ../crypto777 -f m_LP_StaticNanoMsg clean +$(MAKE) -C ../crypto777 -f m_LP_StaticNanoMsg clean
$(CC) -o ../agents/marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a ../OSlibs/linux/$(shell uname -m)/libnanomsg-static.a -lcurl -lpthread -lm -lanl $(CC) -DNOTETOMIC -o ../agents/marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a ../OSlibs/linux/$(shell uname -m)/libnanomsg-static.a -lcurl -lpthread -lm -lanl
@echo "===========================" @echo "==========================="
@echo " marketmaker -> `pwd`/../agents/marketmaker" @echo " marketmaker -> `pwd`/../agents/marketmaker"
@echo "===========================" @echo "==========================="

1
iguana/m_splitfund

@ -27,3 +27,4 @@ curl --url "http://127.0.0.1:7776" --data "{\"coin\":\"BTCH\",\"agent\":\"iguana
curl --url "http://127.0.0.1:7776" --data "{\"coin\":\"ETOMIC\",\"agent\":\"iguana\",\"method\":\"splitfunds\",\"satoshis\":\"50000\",\"sendflag\":1,\"duplicates\":10}" curl --url "http://127.0.0.1:7776" --data "{\"coin\":\"ETOMIC\",\"agent\":\"iguana\",\"method\":\"splitfunds\",\"satoshis\":\"50000\",\"sendflag\":1,\"duplicates\":10}"
curl --url "http://127.0.0.1:7776" --data "{\"coin\":\"VOTE2018\",\"agent\":\"iguana\",\"method\":\"splitfunds\",\"satoshis\":\"50000\",\"sendflag\":1,\"duplicates\":10}" curl --url "http://127.0.0.1:7776" --data "{\"coin\":\"VOTE2018\",\"agent\":\"iguana\",\"method\":\"splitfunds\",\"satoshis\":\"50000\",\"sendflag\":1,\"duplicates\":10}"
curl --url "http://127.0.0.1:7776" --data "{\"coin\":\"CHIPS\",\"agent\":\"iguana\",\"method\":\"splitfunds\",\"satoshis\":\"50000\",\"sendflag\":1,\"duplicates\":10}" curl --url "http://127.0.0.1:7776" --data "{\"coin\":\"CHIPS\",\"agent\":\"iguana\",\"method\":\"splitfunds\",\"satoshis\":\"50000\",\"sendflag\":1,\"duplicates\":10}"
curl --url "http://127.0.0.1:7776" --data "{\"coin\":\"NINJA\",\"agent\":\"iguana\",\"method\":\"splitfunds\",\"satoshis\":\"50000\",\"sendflag\":1,\"duplicates\":10}"

2
iguana/m_unix

@ -9,4 +9,4 @@ cd secp256k1; ./m_unix; cd ..
cd ../crypto777; ./m_unix; cd ../iguana cd ../crypto777; ./m_unix; cd ../iguana
gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c
gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c
gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lpthread -lm -lnanomsg gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lpthread -lm -lnanomsg -lcurl

1
iguana/mini-gmp.c

@ -4402,6 +4402,7 @@ int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr)
p++; p++;
if ( *p != '\0' ) if ( *p != '\0' )
{ {
int32_t zeroval();
printf("bitcoin_base58decode error: p %02x != 0x00\n",*p); printf("bitcoin_base58decode error: p %02x != 0x00\n",*p);
mpz_clear(bn), mpz_clear(bn58); mpz_clear(bn), mpz_clear(bn58);
return(-1); return(-1);

5
iguana/secp256k1/CMakeLists.txt

@ -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})

1
iguana/secp256k1/include/secp256k1_recovery.h

@ -2,6 +2,7 @@
# define _SECP256K1_RECOVERY_ # define _SECP256K1_RECOVERY_
# include "secp256k1.h" # include "secp256k1.h"
# include "stdint.h"
# ifdef __cplusplus # ifdef __cplusplus
extern "C" { extern "C" {

8
marketmaker.vcxproj

@ -86,7 +86,7 @@
</PrecompiledHeader> </PrecompiledHeader>
<WarningLevel>Level2</WarningLevel> <WarningLevel>Level2</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_DEBUG;_CONSOLE;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_DEBUG;_CONSOLE;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;NOTETOMIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>8Bytes</StructMemberAlignment> <StructMemberAlignment>8Bytes</StructMemberAlignment>
<AdditionalIncludeDirectories>.\iguana;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>.\iguana;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
@ -103,7 +103,7 @@
</PrecompiledHeader> </PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;NATIVE_WINDOWS;WIN32;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;NATIVE_WINDOWS;WIN32;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;NOTETOMIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>8Bytes</StructMemberAlignment> <StructMemberAlignment>8Bytes</StructMemberAlignment>
</ClCompile> </ClCompile>
<Link> <Link>
@ -121,7 +121,7 @@
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_CONSOLE;NDEBUG;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_CONSOLE;NDEBUG;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;NOTETOMIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>8Bytes</StructMemberAlignment> <StructMemberAlignment>8Bytes</StructMemberAlignment>
</ClCompile> </ClCompile>
<Link> <Link>
@ -141,7 +141,7 @@
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN64;_WIN64;_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;WIN32_LEAN_AND_MEAN;_CONSOLE;NDEBUG;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN64;_WIN64;_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;WIN32_LEAN_AND_MEAN;_CONSOLE;NDEBUG;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;NOTETOMIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>8Bytes</StructMemberAlignment> <StructMemberAlignment>8Bytes</StructMemberAlignment>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile> </ClCompile>

4
marketmaker_build_32_64.cmd

@ -72,10 +72,14 @@ IF "%host%"=="VM-81" (
mkdir package_content\win64 mkdir package_content\win64
copy /y Release\marketmaker.exe package_content\win32 copy /y Release\marketmaker.exe package_content\win32
copy /y x64\Release\marketmaker.exe package_content\win64 copy /y x64\Release\marketmaker.exe package_content\win64
copy /y x64\Release\libcurl.dll package_content\win64
copy /y x64\Release\nanomsg.dll package_content\win64
echo Marketmaker_%LP_MAJOR_VERSION%.%LP_MINOR_VERSION%_%LP_BUILD_NUMBER%%GIT_COMMIT% > package_content\version.txt echo Marketmaker_%LP_MAJOR_VERSION%.%LP_MINOR_VERSION%_%LP_BUILD_NUMBER%%GIT_COMMIT% > package_content\version.txt
cd package_content cd package_content
"C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z win32\marketmaker.exe "C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z win32\marketmaker.exe
"C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z win64\marketmaker.exe "C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z win64\marketmaker.exe
"C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z win64\libcurl.dll
"C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z win64\nanomsg.dll
"C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z version.txt "C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z version.txt
cd .. cd ..
rd package_content /s /q rd package_content /s /q

15
marketmaker_build_cpp-ethereum.cmd

@ -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…
Cancel
Save