1- /* cheatcoin main, T13.654-T13.855 $DVS:time$ */
1+ /* cheatcoin main, T13.654-T13.865 $DVS:time$ */
22
33#include <stdio.h>
44#include <stdlib.h>
1616#include <sys/socket.h>
1717#include <sys/un.h>
1818#include <errno.h>
19+ #elif defined(_WIN64 )
20+ #define poll WSAPoll
21+ #else
22+ #define poll (a ,b ,c ) ((a)->revents = (a)->events, (b))
1923#endif
24+ #include "system.h"
2025#include "address.h"
2126#include "block.h"
2227#include "crypt.h"
@@ -60,13 +65,7 @@ struct cheatcoin_ext_stats g_cheatcoin_extstats;
6065int (* g_cheatcoin_show_state )(const char * state , const char * balance , const char * address ) = 0 ;
6166
6267static long double amount2cheatcoins (cheatcoin_amount_t amount ) {
63- long double res = 0 , d = 1 ;
64- int i ;
65- for (i = 0 ; i < 32 || (amount && i < 64 ); ++ i , amount >>= 1 ) {
66- if (amount & 1 ) res += d ;
67- if (i < 32 ) res /= 2 ; else d *= 2 ;
68- }
69- return floorl (res * 1000000000 ) / 1000000000 ;
68+ return xdag_amount2xdag (amount ) + (long double )xdag_amount2cheato (amount ) / 1000000000 ;
7069}
7170
7271static long double diff2log (cheatcoin_diff_t diff ) {
@@ -88,16 +87,13 @@ static long double hashrate(cheatcoin_diff_t *diff) {
8887static cheatcoin_amount_t cheatcoins2amount (const char * str ) {
8988 long double sum , flr ;
9089 cheatcoin_amount_t res ;
91- int i ;
9290 if (sscanf (str , "%Lf" , & sum ) != 1 || sum <= 0 ) return 0 ;
9391 flr = floorl (sum );
9492 res = (cheatcoin_amount_t )flr << 32 ;
9593 sum -= flr ;
96- for (i = 31 ; i >= 0 ; -- i ) {
97- sum *= 2 ;
98- if (sum >= 1 ) res |= 1ll << i , sum -- ;
99- }
100- return res ;
94+ sum = ldexpl (sum , 32 );
95+ flr = ceill (sum );
96+ return res + (cheatcoin_amount_t )flr ;
10197}
10298
10399static int account_callback (void * data , cheatcoin_hash_t hash , cheatcoin_amount_t amount , cheatcoin_time_t time , int n_our_key ) {
@@ -391,7 +387,6 @@ static int out_balances(void) {
391387
392388static int terminal (void ) {
393389#if !defined(_WIN32 ) && !defined(_WIN64 )
394- // char cmd[CHEATCOIN_COMMAND_MAX], cmd2[CHEATCOIN_COMMAND_MAX], *ptr, *lasts;
395390 char * cmd , * cmd2 , * ptr , * lasts ;
396391 int s ;
397392 struct sockaddr_un addr ;
@@ -424,12 +419,16 @@ static int terminal(void) {
424419 while (read (s , & c , 1 ) == 1 && c ) putchar (c );
425420 close (s );
426421 }
422+
423+ free (cmd );
424+ free (cmd2 );
425+
427426#endif
428427 return 0 ;
429428}
430429
431- static void * terminal_thread (void * arg ) {
432430#if !defined(_WIN32 ) && !defined(_WIN64 )
431+ static void * terminal_thread (void * arg ) {
433432 struct sockaddr_un addr ;
434433 int s ;
435434 if ( (s = socket (AF_UNIX , SOCK_STREAM , 0 )) == -1 ) { cheatcoin_err ("Can't create unix domain socket errno:%d" , errno ); return 0 ; }
@@ -459,11 +458,9 @@ static void *terminal_thread(void *arg) {
459458 if (res < 0 ) exit (0 );
460459 }
461460 }
462- #else
463461 return 0 ;
464- #endif /* WIN */
465462}
466-
463+ #endif /* WIN */
467464
468465#ifdef CHEATCOINWALLET
469466int cheatcoin_main (int argc , char * * argv ) {
@@ -609,14 +606,14 @@ int main(int argc, char **argv) {
609606 cheatcoin_mess ("Starting pool engine..." );
610607 if (cheatcoin_pool_start (is_pool , pool_arg , miner_address )) return -1 ;
611608#ifndef CHEATCOINWALLET
609+ #if !defined(_WIN32 ) && !defined(_WIN64 )
612610 cheatcoin_mess ("Starting terminal server..." );
613611 if (pthread_create (& th , 0 , & terminal_thread , 0 )) return -1 ;
614-
612+ #endif
615613 if (!(transport_flags & CHEATCOIN_DAEMON )) printf ("Type command, help for example.\n" );
616614 for (;;) {
617615 if (transport_flags & CHEATCOIN_DAEMON ) sleep (100 );
618616 else {
619- // char cmd[CHEATCOIN_COMMAND_MAX];
620617 char * cmd ;
621618 cmd = malloc (CHEATCOIN_COMMAND_MAX );
622619 printf ("%s> " , g_progname ); fflush (stdout );
0 commit comments