@ -112,28 +112,53 @@ void LP_main(void *ptr)
}
}
void ETH_test ( )
int32_t ensure_writable ( char * dirname )
{
BasicTxData txData ; char * ethSignedTx ;
strcpy ( txData . amount , " 1000000000000000000 " ) ;
strcpy ( txData . from , " 0xA7EF3f65714AE266414C9E58bB4bAa4E6FB82B41 " ) ;
strcpy ( txData . to , " 0x9387Fd3a016bB0205e4e131Dde886B9d2BC000A2 " ) ;
strcpy ( txData . secretKey , getenv ( " BOB_PK " ) ) ;
BobSendsEthDepositInput input = {
. aliceAddress = " 0x485d2cc2d13a9e12E4b53D606DB1c8adc884fB8a " ,
. depositId = " 0x28c5a7c25911ef59a577ddf811d0e58edb827efb0646a8a38df6e921ba53f431 " ,
. bobHash = " 0xd66ca5295806fb95ead3f2be1d193a206a376371 "
} ;
ethSignedTx = bobSendsEthDeposit ( input , txData ) ;
printf ( " ETH_test (%s) \n " , ethSignedTx ) ;
free ( ethSignedTx ) ;
char fname [ 512 ] , str [ 65 ] , str2 [ 65 ] ; bits256 r , check ; FILE * fp ;
OS_randombytes ( r . bytes , sizeof ( r ) ) ;
sprintf ( fname , " %s/checkval " , dirname ) , OS_compatible_path ( fname ) ;
if ( ( fp = fopen ( fname , " wb " ) ) = = 0 )
{
printf ( " FATAL ERROR cant create %s \n " , fname ) ;
fprintf ( stderr , " FATAL ERROR cant create %s \n " , fname ) ;
return ( - 1 ) ;
}
else if ( fwrite ( r . bytes , 1 , sizeof ( r ) , fp ) ! = sizeof ( r ) )
{
printf ( " FATAL ERROR error writing %s \n " , fname ) ;
fprintf ( stderr , " FATAL ERROR writing %s \n " , fname ) ;
return ( - 1 ) ;
}
else
{
fclose ( fp ) ;
if ( ( fp = fopen ( fname , " rb " ) ) = = 0 )
{
printf ( " FATAL ERROR cant open %s \n " , fname ) ;
fprintf ( stderr , " FATAL ERROR cant open %s \n " , fname ) ;
return ( - 1 ) ;
}
else if ( fread ( check . bytes , 1 , sizeof ( check ) , fp ) ! = sizeof ( check ) )
{
printf ( " FATAL ERROR error reading %s \n " , fname ) ;
fprintf ( stderr , " FATAL ERROR reading %s \n " , fname ) ;
return ( - 1 ) ;
}
else if ( memcmp ( check . bytes , r . bytes , sizeof ( r ) ) ! = 0 )
{
printf ( " FATAL ERROR error comparint %s %s vs %s \n " , fname , bits256_str ( str , r ) , bits256_str ( str2 , check ) ) ;
fprintf ( stderr , " FATAL ERROR error comparint %s %s vs %s \n " , fname , bits256_str ( str , r ) , bits256_str ( str2 , check ) ) ;
return ( - 1 ) ;
}
fclose ( fp ) ;
}
return ( 0 ) ;
}
int main ( int argc , const char * argv [ ] )
{
char dirname [ 512 ] , * passphrase ; double incr ; cJSON * retjson ;
char dirname [ 512 ] ; double incr ; cJSON * retjson ;
OS_init ( ) ;
//ETH_test();
if ( strstr ( argv [ 0 ] , " btc2kmd " ) ! = 0 & & argv [ 1 ] ! = 0 )
{
uint8_t addrtype , rmd160 [ 20 ] , rmd160b [ 20 ] ; char coinaddr [ 64 ] , coinaddr2 [ 64 ] ;
@ -211,7 +236,7 @@ int main(int argc, const char * argv[])
}
else if ( argv [ 1 ] ! = 0 & & strcmp ( argv [ 1 ] , " airdropH " ) = = 0 & & argv [ 2 ] ! = 0 )
{
FILE * fp ; double val , total = 0. ; uint8_t checktype , addrtype , rmd160 [ 21 ] , checkrmd160 [ 21 ] ; char buf [ 256 ] , checkaddr [ 64 ] , coinaddr [ 64 ] , manystrs [ 64 ] [ 128 ] , cmd [ 64 * 128 ] ; int32_t n , i , num ; char * flag ;
FILE * fp ; double val , total = 0. ; uint8_t checktype , addrtype , rmd160 [ 21 ] , checkrmd160 [ 21 ] ; char * floatstr , * addrstr , buf [ 256 ] , checkaddr [ 64 ] , coinaddr [ 64 ] , manystrs [ 64 ] [ 128 ] , cmd [ 64 * 128 ] ; int32_t n , i , num ; char * flag ;
if ( ( fp = fopen ( argv [ 2 ] , " rb " ) ) ! = 0 )
{
num = 0 ;
@ -231,24 +256,26 @@ int main(int argc, const char * argv[])
}
if ( flag ! = 0 )
{
addrstr = flag , floatstr = buf ;
//addrstr = buf, floatstr = flag;
//bitcoin_addr2rmd160("HUSH",28,&addrtype,rmd160,buf);
bitcoin_addr2rmd160 ( " BTC " , 0 , & addrtype , rmd160 , buf ) ;
bitcoin_address ( " KMD " , coinaddr , 0 , addrtype = = 184 ? 60 : 85 , rmd160 , 20 ) ;
bitcoin_addr2rmd160 ( " BTC " , 0 , & addrtype , rmd160 , addrstr ) ;
bitcoin_address ( " KMD " , coinaddr , 0 , addrtype = = 0 ? 60 : 85 , rmd160 , 20 ) ;
bitcoin_addr2rmd160 ( " KMD " , 0 , & checktype , checkrmd160 , coinaddr ) ;
//bitcoin_address("HUSH",checkaddr,28,checktype == 60 ? 184 : 189,checkrmd160,20);
bitcoin_address ( " BTC " , checkaddr , 0 , checktype = = 60 ? 0 : 5 , checkrmd160 , 20 ) ;
if ( memcmp ( rmd160 , checkrmd160 , 20 ) ! = 0 | | strcmp ( buf , checkaddr ) ! = 0 )
if ( memcmp ( rmd160 , checkrmd160 , 20 ) ! = 0 | | strcmp ( addrstr , checkaddr ) ! = 0 )
{
for ( i = 0 ; i < 20 ; i + + )
printf ( " %02x " , rmd160 [ i ] ) ;
printf ( " vs. " ) ;
for ( i = 0 ; i < 20 ; i + + )
printf ( " %02x " , checkrmd160 [ i ] ) ;
printf ( " address calc error (%s).%d -> (%s).%d -> (%s) %.8f? \n " , buf , addrtype , coinaddr , checktype , checkaddr , atof ( flag ) ) ;
printf ( " address calc error (%s).%d -> (%s).%d -> (%s) %.8f? \n " , addrstr , addrtype , coinaddr , checktype , checkaddr , atof ( floatstr ) ) ;
}
else
{
val = atof ( flag ) ;
val = atof ( floatstr ) ;
sprintf ( manystrs [ num + + ] , " \\ \" %s \\ \" :%0.8f " , coinaddr , val ) ;
if ( num > = sizeof ( manystrs ) / sizeof ( * manystrs ) )
{
@ -256,12 +283,12 @@ int main(int argc, const char * argv[])
for ( i = 0 ; i < num ; i + + )
sprintf ( cmd + strlen ( cmd ) , " %s%s " , manystrs [ i ] , i < num - 1 ? " , " : " " ) ;
strcat ( cmd , " } \" 0 " ) ;
printf ( " %s \n " , cmd ) ;
printf ( " %s \n sleep 3 \n " , cmd ) ;
num = 0 ;
memset ( manystrs , 0 , sizeof ( manystrs ) ) ;
}
total + = val ;
//printf("(%s).%d (%s) <- %.8f total %.8f\n",buf,addrtype,coinaddr,val ,total);
//printf("(%s).%d (%s) <- %.8f (%s) total %.8f\n",addrstr,addrtype,coinaddr,val,floatstr ,total);
}
} else printf ( " parse error for (%s) \n " , buf ) ;
}
@ -281,9 +308,17 @@ int main(int argc, const char * argv[])
exit ( 0 ) ;
}
sprintf ( dirname , " %s " , GLOBAL_DBDIR ) , OS_ensure_directory ( dirname ) ;
if ( ensure_writable ( dirname ) < 0 )
exit ( 0 ) ;
sprintf ( dirname , " %s/SWAPS " , GLOBAL_DBDIR ) , OS_ensure_directory ( dirname ) ;
if ( ensure_writable ( dirname ) < 0 )
exit ( 0 ) ;
sprintf ( dirname , " %s/PRICES " , GLOBAL_DBDIR ) , OS_ensure_directory ( dirname ) ;
if ( ensure_writable ( dirname ) < 0 )
exit ( 0 ) ;
sprintf ( dirname , " %s/UNSPENTS " , GLOBAL_DBDIR ) , OS_ensure_directory ( dirname ) ;
if ( ensure_writable ( dirname ) < 0 )
exit ( 0 ) ;
# ifdef FROM_JS
argc = 2 ;
retjson = cJSON_Parse ( " { \" client \" :1, \" passphrase \" : \" test \" } " ) ;
@ -304,10 +339,10 @@ int main(int argc, const char * argv[])
DOCKERFLAG = 1 ;
else if ( jstr ( retjson , " docker " ) ! = 0 )
DOCKERFLAG = ( uint32_t ) calc_ipbits ( jstr ( retjson , " docker " ) ) ;
if ( jobj ( retjson , " passphrase " ) ! = 0 )
jdelete ( retjson , " passphrase " ) ;
if ( ( passphrase = jstr ( retjson , " passphrase " ) ) = = 0 )
jaddstr ( retjson , " passphrase " , " default " ) ;
//if ( jobj(retjson,"passphrase") != 0 )
// jdelete(retjson,"passphrase");
//if ( (passphrase= jstr(retjson,"passphrase")) == 0 )
// jaddstr(retjson,"passphrase","default");
if ( OS_thread_create ( malloc ( sizeof ( pthread_t ) ) , NULL , ( void * ) LP_main , ( void * ) retjson ) ! = 0 )
{
printf ( " error launching LP_main (%s) \n " , jprint ( retjson , 0 ) ) ;