Browse Source

Merge pull request #391 from jl777/spvdex

signature enforcement of pubkey25519 and rmd160
etomic
jl777 7 years ago
committed by GitHub
parent
commit
3b2d18b3ba
  1. 4
      iguana/exchanges/LP_coins.c
  2. 16
      iguana/exchanges/LP_commands.c
  3. 16
      iguana/exchanges/LP_include.h
  4. 151
      iguana/exchanges/LP_nativeDEX.c
  5. 15
      iguana/exchanges/LP_network.c
  6. 11
      iguana/exchanges/LP_ordermatch.c
  7. 11
      iguana/exchanges/LP_portfolio.c
  8. 82
      iguana/exchanges/LP_prices.c
  9. 2
      iguana/exchanges/LP_secp.c
  10. 171
      iguana/exchanges/LP_signatures.c
  11. 8
      iguana/exchanges/LP_utxo.c
  12. 5
      iguana/exchanges/LP_utxos.c

4
iguana/exchanges/LP_coins.c

@ -188,9 +188,9 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif)
jaddstr(item,"coin",coin->symbol);
if ( showwif != 0 )
{
bitcoin_priv2wif(coin->wiftaddr,wifstr,G.LP_mypriv25519,coin->wiftype);
bitcoin_priv2wif(coin->wiftaddr,wifstr,G.LP_privkey,coin->wiftype);
bitcoin_wif2priv(coin->wiftaddr,&tmptype,&checkkey,wifstr);
if ( bits256_cmp(G.LP_mypriv25519,checkkey) == 0 )
if ( bits256_cmp(G.LP_privkey,checkkey) == 0 )
jaddstr(item,"wif",wifstr);
else jaddstr(item,"wif","error creating wif");
}

16
iguana/exchanges/LP_commands.c

@ -382,9 +382,9 @@ stop()\n\
{
//privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,ptr,"",USERPASS_WIFSTR);
//LP_utxopurge(0);
if ( bits256_nonz(G.LP_mypriv25519) != 0 )
LP_privkey_init(-1,ptr,G.LP_mypriv25519,G.LP_mypub25519);
else printf("no LP_mypriv25519\n");
if ( bits256_nonz(G.LP_privkey) != 0 )
LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519);
else printf("no LP_privkey\n");
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"coin",coin);
@ -483,9 +483,9 @@ stop()\n\
{
LP_address(ptr,coinaddr);
LP_listunspent_issue(coin,coinaddr,1);
if ( strcmp(coinaddr,ptr->smartaddr) == 0 && bits256_nonz(G.LP_mypriv25519) != 0 )
if ( strcmp(coinaddr,ptr->smartaddr) == 0 && bits256_nonz(G.LP_privkey) != 0 )
{
LP_privkey_init(-1,ptr,G.LP_mypriv25519,G.LP_mypub25519);
LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519);
//LP_smartutxos_push(ptr);
}
else
@ -508,7 +508,7 @@ stop()\n\
if ( coinaddr[0] != 0 )
{
LP_address(ptr,coinaddr);
if ( strcmp(coinaddr,ptr->smartaddr) == 0 && bits256_nonz(G.LP_mypriv25519) != 0 )
if ( strcmp(coinaddr,ptr->smartaddr) == 0 && bits256_nonz(G.LP_privkey) != 0 )
{
//printf("ADDR_UNSPENTS %s %s is my address being asked for!\n",ptr->symbol,coinaddr);
ptr->addr_listunspent_requested = (uint32_t)time(NULL);
@ -530,7 +530,7 @@ stop()\n\
{
if ( IAMLP != 0 )
{
if ( strcmp(method,"broadcast") == 0 )
/*if ( strcmp(method,"broadcast") == 0 )
{
bits256 zero; char *cipherstr; int32_t cipherlen; uint8_t cipher[LP_ENCRYPTED_MAXSIZE];
if ( (reqjson= LP_dereference(argjson,"broadcast")) != 0 )
@ -554,7 +554,7 @@ stop()\n\
retstr = clonestr("{\"result\":\"success\"}");
} else retstr = clonestr("{\"error\":\"couldnt dereference sendmessage\"}");
}
else if ( strcmp(method,"psock") == 0 )
else*/ if ( strcmp(method,"psock") == 0 )
{
if ( myipaddr == 0 || myipaddr[0] == 0 || strcmp(myipaddr,"127.0.0.1") == 0 )
{

16
iguana/exchanges/LP_include.h

@ -44,7 +44,7 @@
#define LP_PEERGOOD_ERRORDECAY 0.9
#define LP_SWAPSTEP_TIMEOUT 30
#define LP_AUTOTRADE_TIMEOUT 20
#define LP_AUTOTRADE_TIMEOUT 30
#define LP_MIN_TXFEE 10000
#define LP_MINVOL 20
#define LP_MINCLIENTVOL 50
@ -252,7 +252,7 @@ struct LP_quoteinfo
bits256 srchash,desthash,txid,txid2,desttxid,feetxid,privkey;
uint64_t satoshis,txfee,destsatoshis,desttxfee;
uint32_t timestamp,quotetime; int32_t vout,vout2,destvout,feevout,pair;
char srccoin[16],coinaddr[64],destcoin[16],destaddr[64];
char srccoin[16],coinaddr[64],destcoin[16],destaddr[64],gui[64];
};
struct LP_endpoint { int32_t pair; char ipaddr[64]; uint16_t port; };
@ -275,6 +275,18 @@ struct basilisk_swap
};
#define LP_MAXPRICEINFOS 256
struct LP_pubkeyinfo
{
UT_hash_handle hh;
bits256 pubkey;
double matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS];
uint32_t timestamp,istrusted,numerrors;
uint8_t rmd160[20],sig[65],pubsecp[33],siglen;
};
int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item);
int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp);
void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,uint8_t *data,int32_t datalen,int32_t vout);
void basilisk_dontforget_update(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx);
uint32_t basilisk_requestid(struct basilisk_request *rp);

151
iguana/exchanges/LP_nativeDEX.c

@ -37,6 +37,7 @@ int32_t num_Reserved_msgs,max_Reserved_msgs;
struct LP_peerinfo *LP_peerinfos,*LP_mypeer;
struct LP_forwardinfo *LP_forwardinfos;
struct iguana_info *LP_coins;
struct LP_pubkeyinfo *LP_pubkeyinfos;
#include "LP_network.c"
char *activecoins[] = { "BTC", "KMD" };
@ -54,14 +55,13 @@ int32_t LP_mypubsock = -1;
int32_t LP_mypullsock = -1;
int32_t LP_showwif,IAMLP = 0;
double LP_profitratio = 1.;
char *LP_lastcommand;
struct LP_privkey { bits256 privkey; uint8_t rmd160[20]; };
struct LP_globals
{
struct LP_utxoinfo *LP_utxoinfos[2],*LP_utxoinfos2[2];
bits256 LP_mypub25519,LP_mypriv25519;
bits256 LP_mypub25519,LP_privkey,LP_mypriv25519;
uint64_t LP_skipstatus[10000];
uint8_t LP_myrmd160[20],LP_pubsecp[33];
uint32_t LP_sessionid,counter;
@ -117,6 +117,7 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson
char *retstr=0;
if ( jobj(argjson,"result") != 0 || jobj(argjson,"error") != 0 )
return(0);
//double millis = OS_milliseconds();
if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 )
{
if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 0 )
@ -126,6 +127,8 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson
//LP_send(pubsock,retstr,(int32_t)strlen(retstr)+1,0);
}
} //else printf("finished tradecommand (%s)\n",jprint(argjson,0));
//if ( OS_milliseconds()-millis > 100 )
// printf("%.3f %s\n",OS_milliseconds()-millis,jprint(argjson,0));
return(retstr);
}
@ -156,10 +159,10 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
{
static uint32_t dup,uniq;
int32_t i,len,cipherlen,datalen=0,duplicate=0,encrypted=0; char *method,*method2,*tmp,*cipherstr,*retstr=0,*jsonstr=0; cJSON *argjson; uint32_t crc32;
//double millis = OS_milliseconds();
crc32 = calc_crc32(0,&ptr[2],recvlen-2);
if ( (crc32 & 0xff) == ptr[0] && ((crc32>>8) & 0xff) == ptr[1] )
encrypted = 1;
portable_mutex_lock(&LP_commandmutex);
i = LP_crc32find(&duplicate,-1,crc32);
if ( duplicate != 0 )
dup++;
@ -216,14 +219,45 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
if ( jsonstr != 0 && argjson != 0 )
{
len = (int32_t)strlen(jsonstr) + 1;
if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 )
if ( (method= jstr(argjson,"method")) != 0 && strcmp(method,"broadcast") == 0 )
{
bits256 zero; cJSON *reqjson; char *cipherstr; int32_t cipherlen; uint8_t cipher[LP_ENCRYPTED_MAXSIZE];
if ( (reqjson= LP_dereference(argjson,"broadcast")) != 0 )
{
Broadcaststr = jprint(reqjson,0);
if ( (cipherstr= jstr(reqjson,"cipher")) != 0 )
{
cipherlen = (int32_t)strlen(cipherstr) >> 1;
if ( cipherlen <= sizeof(cipher) )
{
decode_hex(cipher,cipherlen,cipherstr);
LP_queuesend(calc_crc32(0,&cipher[2],cipherlen-2),LP_mypubsock,"","",cipher,cipherlen);
} else retstr = clonestr("{\"error\":\"cipher too big\"}");
}
else
{
memset(zero.bytes,0,sizeof(zero));
if ( (method= jstr(reqjson,"method")) != 0 && (strcmp(method,"request") == 0 || strcmp(method,"requested") == 0 || strcmp(method,"connect") == 0 || strcmp(method,"connected") == 0) )
printf("broadcast.(%s)\n",Broadcaststr);
LP_reserved_msg("","",zero,jprint(reqjson,0));
}
retstr = clonestr("{\"result\":\"success\"}");
free_json(reqjson);
} else retstr = clonestr("{\"error\":\"couldnt dereference sendmessage\"}");
}
else
{
portable_mutex_lock(&LP_commandmutex);
if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 )
{
}
portable_mutex_unlock(&LP_commandmutex);
//printf("%.3f %s LP_command_process\n",OS_milliseconds()-millis,jstr(argjson,"method"));
}
free_json(argjson);
}
}
} //else printf("DUPLICATE.(%s)\n",(char *)ptr);
portable_mutex_unlock(&LP_commandmutex);
if ( jsonstr != 0 && (void *)jsonstr != (void *)ptr && encrypted == 0 )
free(jsonstr);
if ( ptr != 0 )
@ -233,11 +267,12 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int32_t sock,char *remoteaddr,int32_t maxdepth)
{
int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr; char *retstr,*str; struct nn_pollfd pfd;
int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr; char methodstr[64],*retstr,*str; struct nn_pollfd pfd;
if ( sock >= 0 )
{
while ( nonz < maxdepth && recvlen > 0 )
{
nonz++;
memset(&pfd,0,sizeof(pfd));
pfd.fd = sock;
pfd.events = NN_POLLIN;
@ -245,23 +280,22 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
break;
if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 )
{
if ( 0 )
methodstr[0] = 0;
if ( 1 )
{
cJSON *recvjson; char *mstr,*cstr;
cJSON *recvjson; //char *mstr,*cstr;
if ( (recvjson= cJSON_Parse((char *)ptr)) != 0 )
{
if ( (mstr= jstr(recvjson,"method")) != 0 && strcmp(mstr,"uitem") == 0 &&
/*if ( (mstr= jstr(recvjson,"method")) != 0 && strcmp(mstr,"uitem") == 0 &&
(cstr= jstr(recvjson,"coin")) != 0 && strcmp(cstr,"REVS") == 0 )
{
printf("%s RECV.(%s)\n",typestr,(char *)ptr);
}
}*/
safecopy(methodstr,jstr(recvjson,"method"),sizeof(methodstr));
free_json(recvjson);
}
}
nonz++;
if ( LP_lastcommand != 0 )
free(LP_lastcommand);
LP_lastcommand = clonestr((char *)ptr);
double millis = OS_milliseconds();
if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 )
free(retstr);
if ( Broadcaststr != 0 )
@ -273,9 +307,6 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
{
if ( jobj(argjson,"method") != 0 && strcmp("connect",jstr(argjson,"method")) == 0 )
printf("self.(%s)\n",str);
if ( LP_lastcommand != 0 )
free(LP_lastcommand);
LP_lastcommand = clonestr(str);
if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0) <= 0 )
{
portable_mutex_lock(&LP_commandmutex);
@ -287,6 +318,8 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
}
free(str);
}
if ( OS_milliseconds()-millis > 1000 )
printf("%.3f LP_process_message (%s)\n",OS_milliseconds()-millis,methodstr);
}
}
}
@ -295,14 +328,9 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
int32_t LP_nanomsg_recvs(void *ctx)
{
static double lastmilli;
int32_t nonz = 0; char *origipaddr; struct LP_peerinfo *peer,*tmp; double milli;
int32_t nonz = 0; char *origipaddr; struct LP_peerinfo *peer,*tmp;
if ( (origipaddr= LP_myipaddr) == 0 )
origipaddr = "127.0.0.1";
milli = OS_milliseconds();
if ( lastmilli > 0. && milli > lastmilli+3000 )
fprintf(stderr,">>>>>>>>>>>>>>>>> BIG latency lag %.3f milliseconds: (%s)\n",milli-lastmilli,LP_lastcommand!=0?LP_lastcommand:"");
lastmilli = milli;
//portable_mutex_lock(&LP_nanorecvsmutex);
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
@ -327,7 +355,9 @@ int32_t LP_nanomsg_recvs(void *ctx)
nonz += LP_sock_check(coin->symbol,ctx,origipaddr,-1,coin->bussock,LP_profitratio - 1.);
}*/
if ( LP_mypullsock >= 0 )
{
nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1);
}
//portable_mutex_unlock(&LP_nanorecvsmutex);
return(nonz);
}
@ -348,8 +378,7 @@ void command_rpcloop(void *myipaddr)
else usleep(10000);
}
else if ( IAMLP == 0 )
usleep(1000);
else usleep(10);
usleep(100);
}
}
@ -504,28 +533,24 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
nonz++;
LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,myipaddr,myport);
peer->diduquery = 0;
LP_peer_pricesquery(peer);
LP_utxos_sync(peer);
needpings++;
}
peer->lastpeers = now;
}
if ( peer->diduquery == 0 )
if ( peer->needping != 0 )
{
nonz++;
needpings++;
LP_peer_pricesquery(peer);
LP_utxos_sync(peer);
peer->diduquery = now;
}
if ( peer->needping != 0 )
{
nonz++;
needpings++;
if ( (retstr= issue_LP_notify(peer->ipaddr,peer->port,"127.0.0.1",0,numpeers,G.LP_sessionid,G.LP_myrmd160str,G.LP_mypub25519)) != 0 )
free(retstr);
peer->needping = 0;
needpings++;
}
}
if ( needpings != 0 || (counter % 6000) == 5 )
if ( needpings != 0 || (counter % 10000) == 5 )
{
nonz++;
//printf("needpings.%d send notify\n",needpings);
@ -602,7 +627,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
//LP_getestimatedrate(coin);
break;
}
if ( (counter % 6000) == 60 )
if ( (counter % 100000) == 90000 )
{
if ( (retstr= basilisk_swapentry(0,0)) != 0 )
{
@ -679,32 +704,35 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint
int32_t LP_reserved_msgs()
{
bits256 zero; int32_t n = 0; //struct nn_pollfd pfd;
bits256 zero; int32_t flag,n = 0; struct nn_pollfd pfd;
memset(zero.bytes,0,sizeof(zero));
portable_mutex_lock(&LP_reservedmutex);
while ( num_Reserved_msgs > 0 )
{
/*memset(&pfd,0,sizeof(pfd));
pfd.fd = LP_mypubsock;
pfd.events = NN_POLLOUT;
if ( nn_poll(&pfd,1,1) != 1 )
break;*/
num_Reserved_msgs--;
#ifdef __APPLE__
// printf("%d BROADCASTING RESERVED.(%s)\n",num_Reserved_msgs,Reserved_msgs[num_Reserved_msgs]);
#endif
LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]);
Reserved_msgs[num_Reserved_msgs] = 0;
#ifdef __APPLE__
usleep(5000);
#else
usleep(1000);
#endif
n++;
if ( n > 0 )
while ( 1 )
{
if ( num_Reserved_msgs > 0 )
{
flag = 0;
if ( LP_mypubsock >= 0 )
{
memset(&pfd,0,sizeof(pfd));
pfd.fd = LP_mypubsock;
pfd.events = NN_POLLOUT;
if ( nn_poll(&pfd,1,1) == 1 )
flag = 1;
} else flag = 1;
if ( flag == 1 )
{
portable_mutex_lock(&LP_reservedmutex);
num_Reserved_msgs--;
//printf("%d BROADCASTING RESERVED.(%s)\n",num_Reserved_msgs,Reserved_msgs[num_Reserved_msgs]);
LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]);
Reserved_msgs[num_Reserved_msgs] = 0;
portable_mutex_unlock(&LP_reservedmutex);
usleep(3000);
} else break;
} else break;
if ( ++n > 1 )
break;
}
portable_mutex_unlock(&LP_reservedmutex);
return(n);
}
@ -895,10 +923,9 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 )
nonz++;
if ( nonz == 0 )
usleep(10000);
else if ( IAMLP != 0 )
usleep(10);
else usleep(10000);
usleep(1000);
else if ( IAMLP == 0 )
usleep(1000);
}
}

15
iguana/exchanges/LP_network.c

@ -87,7 +87,7 @@ void _LP_sendqueueadd(uint32_t crc32,int32_t sock,uint8_t *msg,int32_t msglen,in
int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32)
{
static uint32_t crcs[64]; static unsigned long dup,total;
static uint32_t crcs[1024]; static unsigned long dup,total;
int32_t i;
*duplicatep = 0;
if ( ind < 0 )
@ -158,16 +158,13 @@ void queue_loop(void *ignore)
{
if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen )
printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen);
#ifdef __APPLE__
//else printf("%d %p qsent %u msglen.%d peerind.%d (%s)\n",n,ptr,ptr->crc32,ptr->msglen,ptr->peerind,ptr->msg);
#endif
ptr->sock = -1;
if ( ptr->peerind > 0 )
ptr->starttime = (uint32_t)time(NULL);
else flag = 1;
} //else printf("sock not ready to send.%d\n",ptr->msglen);
}
else if ( time(NULL) > ptr->starttime+13 )
else if ( 0 && time(NULL) > ptr->starttime+13 )
{
LP_crc32find(&duplicate,-1,ptr->crc32);
if ( duplicate > 0 )
@ -239,9 +236,13 @@ printf("Q sent1 %u msglen.%d (%s)\n",crc32,msglen,msg);
else
{
if ( (maxind= LP_numpeers()) > 0 )
peerind = (rand() % maxind);
else peerind = 0;
peerind = (rand() % maxind) + 1;
else peerind = 1;
sock0 = LP_peerindsock(&peerind);
if ( (maxind= LP_numpeers()) > 0 )
peerind = (rand() % maxind) + 1;
else peerind = 1;
sock1 = LP_peerindsock(&peerind);
}
if ( sock0 >= 0 )
_LP_sendqueueadd(crc32,sock0,msg,msglen,needack * peerind);

11
iguana/exchanges/LP_ordermatch.c

@ -295,7 +295,7 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo **
} else printf("failed ratio test %.8f\n",(double)up->U.value/targetval);
} else if ( targetval != 0 && mini >= 0 )
printf("targetval %.8f mini.%d\n",dstr(targetval),mini);
} else printf("no %s utxos pass LP_address_utxo_ptrs filter\n",coinaddr);
} //else printf("no %s utxos pass LP_address_utxo_ptrs filter\n",coinaddr);
} else printf("couldnt find %s %s\n",coin->symbol,coinaddr);
return(0);
}
@ -363,7 +363,9 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ
jaddnum(retjson,"quoteid",qp->R.quoteid);
// LP_addsig
char str[65]; printf("BOB pubsock.%d binds to %d (%s)\n",pubsock,pair,bits256_str(str,utxo->S.otherpubkey));
LP_reserved_msg(base,rel,utxo->S.otherpubkey,jprint(retjson,1));
LP_reserved_msg(base,rel,utxo->S.otherpubkey,jprint(retjson,0));
LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->desthash,jprint(retjson,0));
free_json(retjson);
retval = 0;
} else printf("error launching swaploop\n");
} else printf("couldnt bind to any port %s\n",pairstr);
@ -722,11 +724,14 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
jaddbits256(retjson,"desthash",butxo->S.otherpubkey);
jaddbits256(retjson,"pubkey",butxo->S.otherpubkey);
jaddstr(retjson,"method","reserved");
msg = jprint(retjson,1);
msg = jprint(retjson,0);
butxo->T.lasttime = (uint32_t)time(NULL);
printf("return after queued RESERVED: set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",butxo->T.swappending,qprice,price,msg);
// LP_addsig
//msg2 = clonestr(msg);
LP_reserved_msg(Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg);
LP_broadcast_message(LP_mypubsock,Q.srccoin,Q.destcoin,Q.desthash,jprint(retjson,0));
free_json(retjson);
return(retval);
} else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap);
}

11
iguana/exchanges/LP_portfolio.c

@ -93,7 +93,7 @@ char *LP_portfolio()
continue;
if ( iter == 0 )
{
LP_privkey_init(-1,coin,G.LP_mypriv25519,G.LP_mypub25519);
LP_privkey_init(-1,coin,G.LP_privkey,G.LP_mypub25519);
coin->balanceA = LP_balance(&coin->valuesumA,0,coin->symbol,coin->smartaddr);
coin->balanceB = LP_balance(&coin->valuesumB,1,coin->symbol,coin->smartaddr);
if ( strcmp(coin->symbol,"KMD") != 0 )
@ -596,7 +596,7 @@ int32_t LP_portfolio_order(struct LP_portfoliotrade *trades,int32_t max,cJSON *a
void prices_loop(void *ignore)
{
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; void *ctx = bitcoin_ctx();
char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; uint32_t expiration; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp; void *ctx = bitcoin_ctx();
while ( 1 )
{
if ( (btcpp= LP_priceinfofind("BTC")) == 0 )
@ -634,7 +634,12 @@ void prices_loop(void *ignore)
}
free(retstr);
}
sleep(60);
expiration = (uint32_t)time(NULL) + 60;
while ( time(NULL) < expiration )
{
if ( LP_utxosQ_process() == 0 )
usleep(10000);
}
}
}

82
iguana/exchanges/LP_prices.c

@ -20,7 +20,6 @@
struct LP_orderbookentry { bits256 pubkey; double price; uint64_t minsatoshis,maxsatoshis; uint32_t timestamp; int32_t numutxos; char coinaddr[64]; };
#define LP_MAXPRICEINFOS 256
struct LP_priceinfo
{
char symbol[16];
@ -48,15 +47,6 @@ struct LP_cacheinfo
uint32_t timestamp;
} *LP_cacheinfos;
struct LP_pubkeyinfo
{
UT_hash_handle hh;
bits256 pubkey;
double matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS];
uint32_t timestamp,istrusted,numerrors;
uint8_t rmd160[20],pubsecp[33];
} *LP_pubkeyinfos;
int32_t LP_pricevalid(double price)
{
if ( price > SMALLVAL && isnan(price) == 0 && price < SATOSHIDEN )
@ -186,9 +176,10 @@ struct LP_pubkeyinfo *LP_pubkeyfind(bits256 pubkey)
struct LP_pubkeyinfo *LP_pubkeyadd(bits256 pubkey)
{
struct LP_pubkeyinfo *pubp=0;
if ( (pubp= LP_pubkeyfind(pubkey)) == 0 )
portable_mutex_lock(&LP_pubkeymutex);
HASH_FIND(hh,LP_pubkeyinfos,&pubkey,sizeof(pubkey),pubp);
if ( pubp == 0 )
{
portable_mutex_lock(&LP_pubkeymutex);
pubp = calloc(1,sizeof(*pubp));
pubp->pubkey = pubkey;
if ( bits256_cmp(G.LP_mypub25519,pubkey) == 0 )
@ -197,17 +188,18 @@ struct LP_pubkeyinfo *LP_pubkeyadd(bits256 pubkey)
memcpy(pubp->pubsecp,G.LP_pubsecp,sizeof(pubp->pubsecp));
}
HASH_ADD_KEYPTR(hh,LP_pubkeyinfos,&pubp->pubkey,sizeof(pubp->pubkey),pubp);
portable_mutex_unlock(&LP_pubkeymutex);
if ( (pubp= LP_pubkeyfind(pubkey)) == 0 )
HASH_FIND(hh,LP_pubkeyinfos,&pubkey,sizeof(pubkey),pubp);
if ( pubp == 0 )
printf("pubkeyadd find error after add\n");
}
portable_mutex_unlock(&LP_pubkeymutex);
return(pubp);
}
int32_t LP_pubkey_istrusted(bits256 pubkey)
{
struct LP_pubkeyinfo *pubp;
if ( (pubp= LP_pubkeyfind(pubkey)) != 0 )
if ( (pubp= LP_pubkeyadd(pubkey)) != 0 )
return(pubp->istrusted != 0);
return(0);
}
@ -215,7 +207,7 @@ int32_t LP_pubkey_istrusted(bits256 pubkey)
char *LP_pubkey_trustset(bits256 pubkey,uint32_t trustval)
{
struct LP_pubkeyinfo *pubp;
if ( (pubp= LP_pubkeyfind(pubkey)) != 0 )
if ( (pubp= LP_pubkeyadd(pubkey)) != 0 )
{
pubp->istrusted = trustval;
return(clonestr("{\"result\":\"success\"}"));
@ -256,7 +248,7 @@ uint64_t LP_unspents_metric(struct iguana_info *coin,char *coinaddr)
cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp)
{
int32_t baseid,relid,i,j; char *base,hexstr[67],hexstr2[67]; double price; cJSON *item,*array,*obj;
int32_t baseid,relid; char *base,hexstr[67],hexstr2[67],sigstr[256]; double price; cJSON *item,*array,*obj;
obj = cJSON_CreateObject();
array = cJSON_CreateArray();
for (baseid=0; baseid<LP_numpriceinfos; baseid++)
@ -276,25 +268,12 @@ cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp)
}
}
jaddbits256(obj,"pubkey",pubp->pubkey);
for (i=0; i<sizeof(pubp->rmd160); i++)
{
if ( pubp->rmd160[i] != 0 )
{
init_hexbytes_noT(hexstr,pubp->rmd160,sizeof(pubp->rmd160));
jaddstr(obj,"rmd160",hexstr);
for (j=0; i<sizeof(pubp->pubsecp); i++)
{
if ( pubp->pubsecp[i] != 0 )
{
init_hexbytes_noT(hexstr2,pubp->pubsecp,sizeof(pubp->pubsecp));
jaddstr(obj,"pubsecp",hexstr2);
//printf("nonz rmd160 (%s %s)\n",hexstr,hexstr2);
break;
}
}
break;
}
}
init_hexbytes_noT(hexstr,pubp->rmd160,sizeof(pubp->rmd160));
jaddstr(obj,"rmd160",hexstr);
init_hexbytes_noT(hexstr2,pubp->pubsecp,sizeof(pubp->pubsecp));
jaddstr(obj,"pubsecp",hexstr2);
init_hexbytes_noT(sigstr,pubp->sig,pubp->siglen);
jaddstr(obj,"sig",sigstr);
jaddnum(obj,"timestamp",pubp->timestamp);
jadd(obj,"asks",array);
if ( pubp->istrusted != 0 )
@ -314,36 +293,23 @@ char *LP_prices()
void LP_prices_parse(struct LP_peerinfo *peer,cJSON *obj)
{
static uint8_t zeroes[20];
struct LP_pubkeyinfo *pubp; struct LP_priceinfo *basepp,*relpp; uint32_t timestamp; bits256 pubkey; cJSON *asks,*item; uint8_t rmd160[20]; int32_t i,n,relid,mismatch; char *base,*rel,*hexstr,*pubsecpstr; double askprice; uint32_t now;
struct LP_pubkeyinfo *pubp; struct LP_priceinfo *basepp,*relpp; uint32_t timestamp; bits256 pubkey; cJSON *asks,*item; uint8_t rmd160[20]; int32_t i,n,relid,mismatch; char *base,*rel,*hexstr; double askprice; uint32_t now;
now = (uint32_t)time(NULL);
pubkey = jbits256(obj,"pubkey");
if ( bits256_nonz(pubkey) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 )
{
if ( (hexstr= jstr(obj,"rmd160")) != 0 && strlen(hexstr) == 2*sizeof(rmd160) )
{
decode_hex(rmd160,sizeof(rmd160),hexstr);
if ( memcmp(pubp->rmd160,rmd160,sizeof(rmd160)) != 0 )
mismatch = 1;
else mismatch = 0;
if ( bits256_cmp(pubkey,G.LP_mypub25519) == 0 && mismatch == 0 )
peer->needping = 0;
if ( mismatch != 0 && memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 )
{
for (i=0; i<20; i++)
printf("%02x",pubp->rmd160[i]);
memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160));
if ( (pubsecpstr= jstr(obj,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 )
{
decode_hex(pubp->pubsecp,sizeof(pubp->pubsecp),pubsecpstr);
char str[65]; printf(" -> rmd160.(%s) for %s (%s)\n",hexstr,bits256_str(str,pubkey),pubsecpstr);
}
}
}
if ( memcmp(pubp->rmd160,rmd160,sizeof(rmd160)) != 0 )
mismatch = 1;
else mismatch = 0;
if ( bits256_cmp(pubkey,G.LP_mypub25519) == 0 && mismatch == 0 )
peer->needping = 0;
LP_pubkey_sigcheck(pubp,obj);
timestamp = juint(obj,"timestamp");
if ( timestamp > now )
timestamp = now;
if ( timestamp > pubp->timestamp && (asks= jarray(&n,obj,"asks")) != 0 )
if ( timestamp >= pubp->timestamp && (asks= jarray(&n,obj,"asks")) != 0 )
{
pubp->timestamp = timestamp;
for (i=0; i<n; i++)
@ -1072,7 +1038,7 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price)
dxblend(&relpp->relvals[basepp->ind],1. / price,0.9);
}
pubp->timestamp = (uint32_t)time(NULL);
} else printf("error creating pubkey entry\n");
} else printf("error finding pubkey entry %s, ok if rare\n",bits256_str(str,pubkey));
}
//else if ( (rand() % 100) == 0 )
// printf("error finding %s/%s %.8f\n",base,rel,price);

2
iguana/exchanges/LP_secp.c

@ -179,7 +179,7 @@ int32_t bitcoin_verify(void *ctx,uint8_t *sig,int32_t siglen,bits256 txhash2,uin
secp256k1_ecdsa_signature_parse_der(ctx,&SIG,sig,siglen);
if ( secp256k1_ecdsa_verify(ctx,&SIG,txhash2.bytes,&PUB) != 0 )
retval = 0;
}
} else printf("error parsing pubkey\n");
ENDSECP_ENSURE_CTX
}
return(retval);

171
iguana/exchanges/LP_signatures.c

@ -42,6 +42,7 @@ struct basilisk_request *LP_requestinit(struct basilisk_request *rp,bits256 srch
cJSON *LP_quotejson(struct LP_quoteinfo *qp)
{
double price; cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"gui",qp->gui[0] != 0 ? qp->gui : LP_gui);
jaddstr(retjson,"base",qp->srccoin);
jaddstr(retjson,"rel",qp->destcoin);
if ( qp->coinaddr[0] != 0 )
@ -96,6 +97,7 @@ cJSON *LP_quotejson(struct LP_quoteinfo *qp)
int32_t LP_quoteparse(struct LP_quoteinfo *qp,cJSON *argjson)
{
safecopy(qp->gui,LP_gui,sizeof(qp->gui));
safecopy(qp->srccoin,jstr(argjson,"base"),sizeof(qp->srccoin));
safecopy(qp->coinaddr,jstr(argjson,"address"),sizeof(qp->coinaddr));
safecopy(qp->destcoin,jstr(argjson,"rel"),sizeof(qp->destcoin));
@ -258,21 +260,39 @@ void LP_postutxos(char *symbol,char *coinaddr)
}
}
queue_t utxosQ;
struct LP_utxos_qitem { struct queueitem DL; cJSON *argjson; };
char *LP_postutxos_recv(cJSON *argjson)
{
int32_t n; char *symbol,*coinaddr; struct LP_address *ap; struct iguana_info *coin; cJSON *array;
//printf("posted.(%s)\n",jprint(argjson,0));
if ( (coinaddr= jstr(argjson,"coinaddr")) != 0 && (symbol= jstr(argjson,"coin")) != 0 && (coin= LP_coinfind(symbol)) != 0 ) // addsig
struct LP_utxos_qitem *uitem;
uitem = calloc(1,sizeof(*uitem));
uitem->argjson = jduplicate(argjson);
queue_enqueue("utxosQ",&utxosQ,&uitem->DL);
return(clonestr("{\"result\":\"success\"}"));
}
int32_t LP_utxosQ_process()
{
struct LP_utxos_qitem *uitem; int32_t n; char *symbol,*coinaddr; struct LP_address *ap; struct iguana_info *coin; cJSON *array;
if ( (uitem= queue_dequeue(&utxosQ)) != 0 )
{
if ( coin->electrum == 0 || (ap= LP_addressfind(coin,coinaddr)) != 0 )
//printf("LP_utxosQ_process.(%s)\n",jprint(uitem->argjson,0));
if ( (coinaddr= jstr(uitem->argjson,"coinaddr")) != 0 && (symbol= jstr(uitem->argjson,"coin")) != 0 && (coin= LP_coinfind(symbol)) != 0 ) // addsig
{
if ( (array= jarray(&n,argjson,"utxos")) != 0 )
LP_unspents_array(coin,coinaddr,array);
if ( coin->electrum == 0 || (ap= LP_addressfind(coin,coinaddr)) != 0 )
{
if ( (array= jarray(&n,uitem->argjson,"utxos")) != 0 )
LP_unspents_array(coin,coinaddr,array);
}
else if ( (array= electrum_address_listunspent(symbol,coin->electrum,&array,coinaddr,1)) != 0 )
free_json(array);
}
else if ( (array= electrum_address_listunspent(symbol,coin->electrum,&array,coinaddr,1)) != 0 )
free_json(array);
free_json(uitem->argjson);
free(uitem);
return(1);
}
return(clonestr("{\"result\":\"success\"}"));
return(0);
}
char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price)
@ -308,6 +328,108 @@ char *LP_postprice_recv(cJSON *argjson)
return(clonestr("{\"error\":\"missing fields in posted price\"}"));
}
bits256 LP_pubkey_sighash(bits256 pub,uint8_t *rmd160,uint8_t *pubsecp)
{
uint8_t buf[sizeof(pub) + 20 + 33]; bits256 sighash;
memcpy(buf,pub.bytes,sizeof(pub));
memcpy(&buf[sizeof(pub)],rmd160,20);
memcpy(&buf[sizeof(pub)+20],pubsecp,33);
vcalc_sha256(0,sighash.bytes,buf,sizeof(buf));
return(sighash);
}
int32_t _LP_pubkey_sigcheck(uint8_t *sig,int32_t siglen,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp)
{
static void *ctx;
uint8_t pub33[33]; bits256 sighash = LP_pubkey_sighash(pub,rmd160,pubsecp);
if ( ctx == 0 )
ctx = bitcoin_ctx();
return(bitcoin_recoververify(ctx,"sigcheck",sig,sighash,pub33,0));
}
int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp)
{
static void *ctx;
uint8_t sig[128],pub33[33]; int32_t i,j,siglen=0; bits256 sighash; char sigstr[256];
sighash = LP_pubkey_sighash(pub,rmd160,pubsecp);
if ( ctx == 0 )
ctx = bitcoin_ctx();
for (j=0; j<100; j++)
{
if ( (siglen= bitcoin_sign(ctx,"sigadd",sig,sighash,priv,1)) > 0 && siglen == 65 )
{
memset(pub33,0,33);
if ( bitcoin_recoververify(ctx,"test",sig,sighash,pub33,0) == 0 && memcmp(pub33,pubsecp,33) == 0 )
{
init_hexbytes_noT(sigstr,sig,siglen);
jaddstr(item,"sig",sigstr);
return(siglen);
}
if ( 0 )
{
for (i=0; i<33; i++)
printf("%02x",pubsecp[i]);
printf(" pubsecp -> ");
for (i=0; i<33; i++)
printf("%02x",pub33[i]);
printf(" mismatched recovered pubkey.%d of %d\n",j,100);
}
}
}
return(0);
}
int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item)
{
int32_t i,len,siglen,retval=-1; uint8_t rmd160[20],checkrmd160[20],pubsecp[33],sig[65],zeroes[20]; char *sigstr,*hexstr,*pubsecpstr;
if ( (hexstr= jstr(item,"rmd160")) != 0 && strlen(hexstr) == 2*sizeof(rmd160) )
{
decode_hex(rmd160,sizeof(rmd160),hexstr);
memset(zeroes,0,sizeof(zeroes));
if ( memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 )
{
if ( memcmp(rmd160,pubp->rmd160,20) != 0 )
{
if ( (pubsecpstr= jstr(item,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 )
{
decode_hex(pubsecp,sizeof(pubsecp),pubsecpstr);
calc_rmd160_sha256(checkrmd160,pubsecp,33);
if ( memcmp(checkrmd160,rmd160,20) == 0 )
{
if ( (sigstr= jstr(item,"sig")) != 0 && (len= is_hexstr(sigstr,0)) == 65*2 )
{
siglen = len >> 1;
decode_hex(sig,siglen,sigstr);
if ( _LP_pubkey_sigcheck(sig,siglen,pubp->pubkey,rmd160,pubsecp) == 0 )
{
for (i=0; i<20; i++)
printf("%02x",pubp->rmd160[i]);
memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160));
memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp));
memcpy(pubp->sig,sig,sizeof(pubp->sig));
pubp->siglen = siglen;
char str[65]; printf(" -> rmd160.(%s) for %s (%s) sig.%s\n",hexstr,bits256_str(str,pubp->pubkey),pubsecpstr,sigstr);
retval = 0;
pubp->timestamp = (uint32_t)time(NULL);
} //else printf("sig %s error pub33.%s\n",sigstr,pubsecpstr);
}
}
else
{
for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
printf(" rmd160 vs ");
for (i=0; i<20; i++)
printf("%02x",checkrmd160[i]);
printf(" for %s\n",pubsecpstr);
}
}
} else pubp->timestamp = (uint32_t)time(NULL);
}
}
return(retval);
}
void LP_notify_pubkeys(void *ctx,int32_t pubsock)
{
bits256 zero; char secpstr[67]; cJSON *reqjson = cJSON_CreateObject();
@ -318,26 +440,19 @@ void LP_notify_pubkeys(void *ctx,int32_t pubsock)
jaddbits256(reqjson,"pub",G.LP_mypub25519);
init_hexbytes_noT(secpstr,G.LP_pubsecp,33);
jaddstr(reqjson,"pubsecp",secpstr);
LP_pubkey_sigadd(reqjson,G.LP_privkey,G.LP_mypub25519,G.LP_myrmd160,G.LP_pubsecp);
LP_reserved_msg("","",zero,jprint(reqjson,1));
}
char *LP_notify_recv(cJSON *argjson)
{
char *rmd160str,*secpstr; bits256 pub; struct LP_pubkeyinfo *pubp;
bits256 pub; struct LP_pubkeyinfo *pubp;
pub = jbits256(argjson,"pub");
// LP_checksig
if ( bits256_nonz(pub) != 0 && (rmd160str= jstr(argjson,"rmd160")) != 0 && strlen(rmd160str) == 40 )
if ( bits256_nonz(pub) != 0 )
{
if ( (pubp= LP_pubkeyadd(pub)) != 0 )
{
decode_hex(pubp->rmd160,20,rmd160str);
if ( (secpstr= jstr(argjson,"pubsecp")) != 0 )
{
decode_hex(pubp->pubsecp,sizeof(pubp->pubsecp),secpstr);
//printf("got pubkey.(%s)\n",secpstr);
}
}
//printf("NOTIFIED pub %s rmd160 %s\n",bits256_str(str,pub),rmd160str);
LP_pubkey_sigcheck(pubp,argjson);
//char str[65]; printf("%.3f NOTIFIED pub %s rmd160 %s\n",OS_milliseconds()-millis,bits256_str(str,pub),rmd160str);
}
return(clonestr("{\"result\":\"success\",\"notify\":\"received\"}"));
}
@ -354,7 +469,7 @@ void LP_listunspent_query(char *symbol,char *coinaddr)
void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp)
{
cJSON *reqjson; bits256 zero; char *msg; int32_t flag = 0; struct LP_utxoinfo *utxo;
cJSON *reqjson; bits256 zero; char *msg,*msg2; int32_t flag = 0; struct LP_utxoinfo *utxo;
if ( strcmp(method,"request") == 0 )
{
if ( (utxo= LP_utxofind(0,qp->desttxid,qp->destvout)) != 0 && LP_ismine(utxo) > 0 && LP_isavailable(utxo) > 0 )
@ -370,19 +485,19 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_
flag = 1;
jaddbits256(reqjson,"pubkey",qp->srchash);
jaddstr(reqjson,"method",method);
jaddnum(reqjson,"timestamp",time(NULL));
msg = jprint(reqjson,1);
msg2 = clonestr(msg);
// LP_addsig
printf("QUERY.(%s)\n",msg);
memset(&zero,0,sizeof(zero));
portable_mutex_lock(&LP_reservedmutex);
if ( num_Reserved_msgs < sizeof(Reserved_msgs)/sizeof(*Reserved_msgs) )
Reserved_msgs[num_Reserved_msgs++] = msg;
else
if ( num_Reserved_msgs < sizeof(Reserved_msgs)/sizeof(*Reserved_msgs)-2 )
{
//if ( 1 && strcmp(method,"request") == 0 )
LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,zero,msg);
//else LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->srchash,msg);
Reserved_msgs[num_Reserved_msgs++] = msg;
//Reserved_msgs[num_Reserved_msgs++] = msg2;
}
LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,zero,msg2);
portable_mutex_unlock(&LP_reservedmutex);
}

8
iguana/exchanges/LP_utxo.c

@ -787,8 +787,8 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout)
int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2)
{
//struct LP_utxoinfo *utxo;
struct LP_address_utxo *up; uint64_t val,val2=0,txfee,threshold=0; int32_t bypass = 0; char destaddr[64],destaddr2[64],str[65]; struct iguana_info *coin = LP_coinfind(symbol);
//struct LP_utxoinfo *utxo; struct LP_address_utxo *up;
uint64_t val,val2=0,txfee,threshold=0; int32_t bypass = 0; char destaddr[64],destaddr2[64],str[65]; struct iguana_info *coin = LP_coinfind(symbol);
if ( bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 )
{
printf("null txid not eligible\n");
@ -800,7 +800,7 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol
if ( bypass != 0 )
val = satoshis;
else val = LP_txvalue(destaddr,symbol,txid,vout);
if ( (up= LP_address_utxofind(coin,destaddr,txid,vout)) != 0 && up->spendheight > 0 )
/*if ( (up= LP_address_utxofind(coin,destaddr,txid,vout)) != 0 && up->spendheight > 0 )
{
//printf("%s/v%d spent %d\n",bits256_str(str,txid),vout,up->spendheight);
return(-2);
@ -809,7 +809,7 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol
{
//printf("%s/v%d spent %d\n",bits256_str(str,txid2),vout2,up->spendheight);
return(-3);
}
}*/
txfee = LP_txfeecalc(LP_coinfind(symbol),0,0);
if ( val >= satoshis && val > (1+LP_MINSIZE_TXFEEMULT)*txfee )
{

5
iguana/exchanges/LP_utxos.c

@ -721,6 +721,7 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan
printf("WIF.(%s) -> %s or %s?\n",wifstr,bits256_str(str,privkey),bits256_str(str2,checkkey));
}
}
privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64;
bitcoin_priv2pub(ctx,coin->pubkey33,coin->smartaddr,privkey,coin->taddr,coin->pubtype);
if ( coin->counter == 0 )
{
@ -729,6 +730,7 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan
bitcoin_priv2wif(coin->wiftaddr,tmpstr,privkey,coin->wiftype);
bitcoin_addr2rmd160(coin->taddr,&tmptype,G.LP_myrmd160,coin->smartaddr);
LP_privkeyadd(privkey,G.LP_myrmd160);
G.LP_privkey = privkey;
if ( 0 && (coin->pubtype != 60 || strcmp(coin->symbol,"KMD") == 0) )
printf("%s (%s) %d wif.(%s) (%s)\n",coin->symbol,coin->smartaddr,coin->pubtype,tmpstr,passphrase);
if ( G.counter++ == 0 )
@ -762,6 +764,7 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan
checkkey.bytes[0] &= 248, checkkey.bytes[31] &= 127, checkkey.bytes[31] |= 64;
G.LP_mypub25519 = *pubkeyp = curve25519(checkkey,curve25519_basepoint9());
G.LP_mypriv25519 = checkkey;
LP_pubkeyadd(G.LP_mypub25519);
return(privkey);
}
@ -786,7 +789,7 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase)
//printf("i.%d of %d\n",i,LP_numcoins);
else if ( IAMLP == 0 || coin->inactive == 0 )
{
if ( LP_privkey_init(pubsock,coin,G.LP_mypriv25519,G.LP_mypub25519) == 0 && (rand() % 10) == 0 )
if ( LP_privkey_init(pubsock,coin,G.LP_privkey,G.LP_mypub25519) == 0 && (rand() % 10) == 0 )
LP_postutxos(coin->symbol,coin->smartaddr);
}
}

Loading…
Cancel
Save