Browse Source

Merge branch 'dev' into jl777

jl777
jl777 7 years ago
parent
commit
83b482bbfa
  1. 2
      CMakeLists.txt
  2. 7
      Dockerfile
  3. 3
      crypto777/CMakeLists.txt
  4. 24
      crypto777/iguana_utils.c
  5. 2
      iguana/exchanges/CMakeLists.txt
  6. 20
      iguana/exchanges/LP_etomic.c
  7. 10
      iguana/exchanges/etomicswap/bob.c
  8. 2
      iguana/exchanges/etomicswap/etomiclib.cpp
  9. 1
      iguana/exchanges/etomicswap/etomiclib.h

2
CMakeLists.txt

@ -19,7 +19,7 @@ download_project(PROJ nanomsg
GIT_TAG 1.1.2 GIT_TAG 1.1.2
GIT_SHALLOW 1 GIT_SHALLOW 1
GIT_PROGRESS 1 GIT_PROGRESS 1
CMAKE_ARGS "-DNN_STATIC_LIB=ON -DNN_ENABLE_DOC=OFF -DNN_TESTS=OFF -DNN_TOOLS=OFF -DNN_ENABLE_NANOCAT=OFF -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_PREFIX}" CMAKE_ARGS "-DNN_STATIC_LIB=ON -DNN_ENABLE_GETADDRINFO_A=OFF -DNN_ENABLE_DOC=OFF -DNN_TESTS=OFF -DNN_TOOLS=OFF -DNN_ENABLE_NANOCAT=OFF -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_PREFIX}"
UPDATE_DISCONNECTED 1 UPDATE_DISCONNECTED 1
) )

7
Dockerfile

@ -0,0 +1,7 @@
FROM ubuntu:17.10
RUN apt-get update && apt-get install -y git libcurl4-openssl-dev build-essential wget pax libleveldb-dev && apt-get clean
RUN wget https://cmake.org/files/v3.10/cmake-3.10.3-Linux-x86_64.sh && \
chmod +x cmake-3.10.3-Linux-x86_64.sh && \
./cmake-3.10.3-Linux-x86_64.sh --skip-license --exclude-subdir --prefix=/usr && \
rm -rf cmake-3.10.3-Linux-x86_64.sh
CMD rm -rf build && mkdir build && cd build && cmake .. && cmake --build . --target marketmaker-testnet

3
crypto777/CMakeLists.txt

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

24
crypto777/iguana_utils.c

@ -799,23 +799,23 @@ int32_t nn_base64_decode (const char *in, size_t in_len,uint8_t *out, size_t out
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
for (io = 0, ii = 0, v = 0, rem = 0; ii < in_len; ii++) { for (io = 0, ii = 0, v = 0, rem = 0; ii < in_len; ii++) {
if (isspace ((uint32_t)in [ii])) if (isspace ((uint32_t)in [ii]))
continue; continue;
if (in [ii] == '=') if (in [ii] == '=')
break; break;
ch = DECODEMAP [(uint32_t)in [ii]]; ch = DECODEMAP [(uint32_t)in [ii]];
// Discard invalid characters as per RFC 2045. // Discard invalid characters as per RFC 2045.
if (ch == 0xFF) if (ch == 0xFF)
break; break;
v = (v << 6) | ch; v = (v << 6) | ch;
rem += 6; rem += 6;
if (rem >= 8) { if (rem >= 8) {
rem -= 8; rem -= 8;
if (io >= out_len) if (io >= out_len)
@ -839,7 +839,7 @@ int32_t nn_base64_encode (const uint8_t *in, size_t in_len,char *out, size_t out
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz"
"0123456789+/"; "0123456789+/";
for (io = 0, ii = 0, v = 0, rem = 0; ii < in_len; ii++) { for (io = 0, ii = 0, v = 0, rem = 0; ii < in_len; ii++) {
ch = in [ii]; ch = in [ii];
v = (v << 8) | ch; v = (v << 8) | ch;
@ -851,26 +851,26 @@ int32_t nn_base64_encode (const uint8_t *in, size_t in_len,char *out, size_t out
out [io++] = ENCODEMAP [(v >> rem) & 63]; out [io++] = ENCODEMAP [(v >> rem) & 63];
} }
} }
if (rem) { if (rem) {
v <<= (6 - rem); v <<= (6 - rem);
if (io >= out_len) if (io >= out_len)
return -ENOBUFS; return -ENOBUFS;
out [io++] = ENCODEMAP [v & 63]; out [io++] = ENCODEMAP [v & 63];
} }
// Pad to a multiple of 3 // Pad to a multiple of 3
while (io & 3) { while (io & 3) {
if (io >= out_len) if (io >= out_len)
return -ENOBUFS; return -ENOBUFS;
out [io++] = '='; out [io++] = '=';
} }
if (io >= out_len) if (io >= out_len)
return -ENOBUFS; return -ENOBUFS;
out [io] = '\0'; out [io] = '\0';
return io; return io;
} }

2
iguana/exchanges/CMakeLists.txt

@ -1,6 +1,6 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(MM_SOURCES mm.c ../mini-gmp.c ../groestl.c ../segwit_addr.c ../keccak.c LP_etomic.c) set(MM_SOURCES mm.c ../mini-gmp.c ../groestl.c ../segwit_addr.c ../keccak.c LP_etomic.c)
set(MM_LIBS ${NANOMSG_LIBRARY} curl pthread libcrypto777 libjpeg libsecp256k1) set(MM_LIBS curl pthread libcrypto777 libjpeg libsecp256k1)
add_executable(marketmaker-testnet ${MM_SOURCES}) add_executable(marketmaker-testnet ${MM_SOURCES})
add_executable(marketmaker-mainnet ${MM_SOURCES}) add_executable(marketmaker-mainnet ${MM_SOURCES})
include_directories(../../crypto777) include_directories(../../crypto777)

20
iguana/exchanges/LP_etomic.c

@ -28,15 +28,23 @@ int32_t LP_etomic_wait_for_confirmation(char *txId)
return(waitForConfirmation(txId)); return(waitForConfirmation(txId));
} }
void LP_etomic_pubkeystr_to_addr(char *pubkey, char *output)
{
char *address = pubKey2Addr(pubkey);
strcpy(output, address);
free(address);
}
char *LP_etomicalice_send_fee(struct basilisk_swap *swap) char *LP_etomicalice_send_fee(struct basilisk_swap *swap)
{ {
char amount[100], secretKey[70]; char amount[100], secretKey[70], dexaddr[50];
satoshisToWei(amount, swap->myfee.I.amount); satoshisToWei(amount, swap->myfee.I.amount);
uint8arrayToHex(secretKey, swap->persistent_privkey.bytes, 32); uint8arrayToHex(secretKey, swap->persistent_privkey.bytes, 32);
LP_etomic_pubkeystr_to_addr(INSTANTDEX_PUBKEY, dexaddr);
if (strcmp(swap->I.alicestr,"ETH") == 0 ) { if (strcmp(swap->I.alicestr,"ETH") == 0 ) {
return(sendEth(ETH_FEE_ACCEPTOR, amount, secretKey, 1)); return(sendEth(dexaddr, amount, secretKey, 1));
} else { } else {
return(sendErc20(swap->I.alicetomic, ETH_FEE_ACCEPTOR, amount, secretKey, 1)); return(sendErc20(swap->I.alicetomic, dexaddr, amount, secretKey, 1));
} }
} }
@ -52,8 +60,10 @@ uint8_t LP_etomic_verify_alice_fee(struct basilisk_swap *swap)
return(0); return(0);
} }
char dexaddr[50];
LP_etomic_pubkeystr_to_addr(INSTANTDEX_PUBKEY, dexaddr);
if ( strcmp(swap->I.alicestr,"ETH") == 0 ) { if ( strcmp(swap->I.alicestr,"ETH") == 0 ) {
if (strcmp(data.to, ETH_FEE_ACCEPTOR) != 0) { if (strcmp(data.to, dexaddr) != 0) {
printf("Alice fee %s was sent to wrong address %s\n", swap->otherfee.I.ethTxid, data.to); printf("Alice fee %s was sent to wrong address %s\n", swap->otherfee.I.ethTxid, data.to);
return(0); return(0);
} }
@ -70,7 +80,7 @@ uint8_t LP_etomic_verify_alice_fee(struct basilisk_swap *swap)
} }
char weiAmount[70]; char weiAmount[70];
satoshisToWei(weiAmount, swap->otherfee.I.amount); satoshisToWei(weiAmount, swap->otherfee.I.amount);
return(verifyAliceErc20FeeData(swap->I.alicetomic, ETH_FEE_ACCEPTOR, weiAmount, data.input)); return(verifyAliceErc20FeeData(swap->I.alicetomic, dexaddr, weiAmount, data.input));
} }
} }

10
iguana/exchanges/etomicswap/bob.c

@ -330,11 +330,14 @@ int main(int argc, char** argv)
default: default:
return 1; return 1;
} }
/*
char *pubkey = getPubKeyFromPriv(getenv("BOB_PK")); char *pubkey = getPubKeyFromPriv(getenv("BOB_PK"));
printf("pubkey: %s\n", pubkey); printf("pubkey: %s\n", pubkey);
free(pubkey); free(pubkey);
char *address = pubKey2Addr("03bc2c7ba671bae4a6fc835244c9762b41647b9827d4780a89a949b984a8ddcc06");
printf("address: %s\n", address);
free(address);
uint64_t satoshis = 100000000; uint64_t satoshis = 100000000;
char weiBuffer[100]; char weiBuffer[100];
satoshisToWei(weiBuffer, satoshis); satoshisToWei(weiBuffer, satoshis);
@ -346,16 +349,15 @@ int main(int argc, char** argv)
uint64_t tokenAllowance = getErc20Allowance(bobAddress, bobContractAddress, tokenAddress); uint64_t tokenAllowance = getErc20Allowance(bobAddress, bobContractAddress, tokenAddress);
printf("allowance: %" PRIu64 "\n", tokenAllowance); printf("allowance: %" PRIu64 "\n", tokenAllowance);
char *sendEthTx = sendEth(bobAddress, "100000000000000", getenv("BOB_PK")); char *sendEthTx = sendEth(bobAddress, "100000000000000", getenv("BOB_PK"), 0);
printf("sent ETH: %s\n", sendEthTx); printf("sent ETH: %s\n", sendEthTx);
free(sendEthTx); free(sendEthTx);
char *sendErc20Tx = sendErc20(tokenAddress, bobAddress, "100000000000000", getenv("BOB_PK")); char *sendErc20Tx = sendErc20(tokenAddress, bobAddress, "100000000000000", getenv("BOB_PK"), 0);
printf("sent Erc20: %s\n", sendErc20Tx); printf("sent Erc20: %s\n", sendErc20Tx);
free(sendErc20Tx); free(sendErc20Tx);
uint64_t gasPrice = getGasPriceFromStation(); uint64_t gasPrice = getGasPriceFromStation();
printf("gasPrice: %" PRIu64 "\n", gasPrice); printf("gasPrice: %" PRIu64 "\n", gasPrice);
*/
return 0; return 0;
} }

2
iguana/exchanges/etomicswap/etomiclib.cpp

@ -26,7 +26,7 @@ TransactionSkeleton txDataToSkeleton(BasicTxData txData)
tx.from = jsToAddress(txData.from); tx.from = jsToAddress(txData.from);
tx.to = jsToAddress(txData.to); tx.to = jsToAddress(txData.to);
tx.value = jsToU256(txData.amount); tx.value = jsToU256(txData.amount);
tx.gas = 100000; tx.gas = 200000;
tx.gasPrice = getGasPriceFromStation() * boost::multiprecision::pow(u256(10), 9); tx.gasPrice = getGasPriceFromStation() * boost::multiprecision::pow(u256(10), 9);
tx.nonce = getNonce(txData.from); tx.nonce = getNonce(txData.from);
return tx; return tx;

1
iguana/exchanges/etomicswap/etomiclib.h

@ -16,7 +16,6 @@ extern "C" {
#endif #endif
#define EMPTY_ETH_TX_ID "0x0000000000000000000000000000000000000000000000000000000000000000" #define EMPTY_ETH_TX_ID "0x0000000000000000000000000000000000000000000000000000000000000000"
#define ETH_FEE_ACCEPTOR "0x485d2cc2d13a9e12e4b53d606db1c8adc884fb8a"
typedef struct { typedef struct {
char from[65]; char from[65];

Loading…
Cancel
Save