|
|
@ -20,7 +20,7 @@ |
|
|
|
|
|
|
|
int32_t LP_ismine(struct LP_utxoinfo *utxo) |
|
|
|
{ |
|
|
|
if ( utxo != 0 && bits256_cmp(utxo->pubkey,LP_mypub25519) == 0 ) |
|
|
|
if ( utxo != 0 && bits256_cmp(utxo->pubkey,G.LP_mypub25519) == 0 ) |
|
|
|
return(1); |
|
|
|
else return(0); |
|
|
|
} |
|
|
@ -154,42 +154,6 @@ void LP_availableset(struct LP_utxoinfo *utxo) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int32_t LP_utxopurge(int32_t allutxos) |
|
|
|
{ |
|
|
|
char str[65]; struct LP_utxoinfo *utxo,*tmp; int32_t iambob,n = 0; |
|
|
|
printf("LP_utxopurge mypub.(%s)\n",bits256_str(str,LP_mypub25519)); |
|
|
|
portable_mutex_lock(&LP_utxomutex); |
|
|
|
for (iambob=0; iambob<=1; iambob++) |
|
|
|
{ |
|
|
|
HASH_ITER(hh,LP_utxoinfos[iambob],utxo,tmp) |
|
|
|
{ |
|
|
|
if ( LP_isavailable(utxo) > 0 ) |
|
|
|
{ |
|
|
|
if ( allutxos != 0 || LP_ismine(utxo) > 0 ) |
|
|
|
{ |
|
|
|
printf("iambob.%d delete.(%s)\n",iambob,bits256_str(str,utxo->payment.txid)); |
|
|
|
HASH_DELETE(hh,LP_utxoinfos[iambob],utxo); |
|
|
|
//free(utxo); let the LP_utxoinfos2 free the utxo, should be 1:1
|
|
|
|
} else n++; |
|
|
|
} else n++; |
|
|
|
} |
|
|
|
HASH_ITER(hh,LP_utxoinfos2[iambob],utxo,tmp) |
|
|
|
{ |
|
|
|
if ( LP_isavailable(utxo) > 0 ) |
|
|
|
{ |
|
|
|
if ( allutxos != 0 || LP_ismine(utxo) > 0 ) |
|
|
|
{ |
|
|
|
printf("iambob.%d delete2.(%s)\n",iambob,bits256_str(str,utxo->payment.txid)); |
|
|
|
HASH_DELETE(hh2,LP_utxoinfos2[iambob],utxo); |
|
|
|
free(utxo); |
|
|
|
} else n++; |
|
|
|
} else n++; |
|
|
|
} |
|
|
|
} |
|
|
|
portable_mutex_unlock(&LP_utxomutex); |
|
|
|
return(n); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *LP_inventoryjson(cJSON *item,struct LP_utxoinfo *utxo) |
|
|
|
{ |
|
|
|
struct _LP_utxoinfo u; |
|
|
@ -246,35 +210,6 @@ cJSON *LP_utxojson(struct LP_utxoinfo *utxo) |
|
|
|
return(item); |
|
|
|
} |
|
|
|
|
|
|
|
char *LP_utxos(int32_t iambob,struct LP_peerinfo *mypeer,char *symbol,int32_t lastn) |
|
|
|
{ |
|
|
|
int32_t i,n,m; uint64_t val,val2; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo,*tmp; cJSON *utxosjson = cJSON_CreateArray(); |
|
|
|
printf("deprecated! LP_utxos\n"); |
|
|
|
//n = mypeer != 0 ? mypeer->numutxos : 0;
|
|
|
|
if ( lastn <= 0 ) |
|
|
|
lastn = LP_PROPAGATION_SLACK * 2; |
|
|
|
HASH_ITER(hh,LP_utxoinfos[iambob],utxo,tmp) |
|
|
|
{ |
|
|
|
//char str[65]; printf("check %s.%s\n",utxo->coin,bits256_str(str,utxo->payment.txid));
|
|
|
|
if ( (symbol == 0 || symbol[0] == 0 || strcmp(symbol,utxo->coin) == 0) && utxo->T.spentflag == 0 ) |
|
|
|
{ |
|
|
|
u = (iambob != 0) ? utxo->deposit : utxo->fee; |
|
|
|
if ( LP_iseligible(&val,&val2,utxo->iambob,utxo->coin,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,u.txid,u.vout) == 0 ) |
|
|
|
{ |
|
|
|
char str[65]; printf("iambob.%d not eligible (%.8f %.8f) %s %s/v%d\n",iambob,dstr(val),dstr(val2),utxo->coin,bits256_str(str,utxo->payment.txid),utxo->payment.vout); |
|
|
|
continue; |
|
|
|
} else jaddi(utxosjson,LP_utxojson(utxo)); |
|
|
|
} |
|
|
|
} |
|
|
|
if ( (n= cJSON_GetArraySize(utxosjson)) > lastn ) |
|
|
|
{ |
|
|
|
m = n - lastn; |
|
|
|
for (i=0; i<m; i++) |
|
|
|
cJSON_DeleteItemFromArray(utxosjson,0); |
|
|
|
} |
|
|
|
return(jprint(utxosjson,1)); |
|
|
|
} |
|
|
|
|
|
|
|
struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) |
|
|
|
{ |
|
|
|
uint64_t srcvalue,srcvalue2; struct LP_utxoinfo *utxo,*tmp,*bestutxo = 0; |
|
|
@ -283,7 +218,7 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) |
|
|
|
printf("LP_utxo_bestfit error symbol.%p %.8f\n",symbol,dstr(destsatoshis)); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
HASH_ITER(hh,LP_utxoinfos[0],utxo,tmp) |
|
|
|
HASH_ITER(hh,G.LP_utxoinfos,utxo,tmp) |
|
|
|
{ |
|
|
|
//char str[65]; printf("s%u %d [%.8f vs %.8f] check %s.%s avail.%d ismine.%d >= %d\n",utxo->T.spentflag,LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout),dstr(destsatoshis),dstr(utxo->S.satoshis),utxo->coin,bits256_str(str,utxo->payment.txid),LP_isavailable(utxo) > 0,LP_ismine(utxo) > 0,utxo->S.satoshis >= destsatoshis);
|
|
|
|
if ( strcmp(symbol,utxo->coin) != 0 ) |
|
|
@ -307,29 +242,9 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) |
|
|
|
|
|
|
|
void LP_spentnotify(struct LP_utxoinfo *utxo,int32_t selector) |
|
|
|
{ |
|
|
|
//cJSON *argjson; struct _LP_utxoinfo u; char *msg;
|
|
|
|
if ( utxo == 0 ) |
|
|
|
return; |
|
|
|
utxo->T.spentflag = (uint32_t)time(NULL); |
|
|
|
if ( LP_mypeer != 0 && LP_mypeer->numutxos > 0 ) |
|
|
|
LP_mypeer->numutxos--; |
|
|
|
/*if ( LP_mypubsock >= 0 )
|
|
|
|
{ |
|
|
|
argjson = cJSON_CreateObject(); |
|
|
|
jaddstr(argjson,"method","checktxid"); |
|
|
|
jaddbits256(argjson,"txid",utxo->payment.txid); |
|
|
|
jaddnum(argjson,"vout",utxo->payment.vout); |
|
|
|
if ( selector != 0 ) |
|
|
|
{ |
|
|
|
if ( bits256_nonz(utxo->deposit.txid) != 0 ) |
|
|
|
u = utxo->deposit; |
|
|
|
else u = utxo->fee; |
|
|
|
jaddbits256(argjson,"checktxid",u.txid); |
|
|
|
jaddnum(argjson,"checkvout",u.vout); |
|
|
|
} |
|
|
|
msg = jprint(argjson,1); |
|
|
|
/LP_send(LP_mypubsock,msg,(int32_t)strlen(msg)+1,1); |
|
|
|
}*/ |
|
|
|
} |
|
|
|
|
|
|
|
char *LP_spentcheck(cJSON *argjson) |
|
|
@ -350,8 +265,8 @@ char *LP_spentcheck(cJSON *argjson) |
|
|
|
} |
|
|
|
if ( LP_txvalue(0,utxo->coin,checktxid,checkvout) == 0 ) |
|
|
|
{ |
|
|
|
if ( LP_mypeer != 0 && LP_mypeer->numutxos > 0 ) |
|
|
|
LP_mypeer->numutxos--; |
|
|
|
//if ( LP_mypeer != 0 && LP_mypeer->numutxos > 0 )
|
|
|
|
// LP_mypeer->numutxos--;
|
|
|
|
utxo->T.spentflag = (uint32_t)time(NULL); |
|
|
|
retval++; |
|
|
|
printf("indeed txid was spent\n"); |
|
|
@ -363,17 +278,6 @@ char *LP_spentcheck(cJSON *argjson) |
|
|
|
return(clonestr("{\"error\":\"cant find txid to check spent status\"}")); |
|
|
|
} |
|
|
|
|
|
|
|
void LP_utxo_clientpublish(struct LP_utxoinfo *utxo) |
|
|
|
{ |
|
|
|
bits256 zero; char *msg; |
|
|
|
if ( 0 && LP_isunspent(utxo) > 0 ) |
|
|
|
{ |
|
|
|
memset(zero.bytes,0,sizeof(zero)); |
|
|
|
msg = jprint(LP_utxojson(utxo),1); |
|
|
|
LP_broadcast_message(LP_mypubsock,utxo->coin,"",zero,msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bits256 txid,int32_t vout,int64_t value,bits256 txid2,int32_t vout2,int64_t value2,char *spendscript,char *coinaddr,bits256 pubkey,char *gui,uint32_t sessionid) |
|
|
|
{ |
|
|
|
uint64_t val,val2=0,tmpsatoshis,txfee; int32_t spendvini,numconfirms,selector; bits256 spendtxid; struct iguana_info *coin; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo = 0; |
|
|
@ -382,6 +286,11 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit |
|
|
|
printf("session.%u malformed addutxo %d %d %d %d %d %d %d %d %d\n",sessionid,symbol == 0,spendscript == 0,coinaddr == 0,bits256_nonz(txid) == 0,bits256_nonz(txid2) == 0,vout < 0,vout2 < 0,value <= 0,value2 <= 0); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
if ( iambob != 0 ) |
|
|
|
{ |
|
|
|
printf("deprecated bob utxos\n"); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
if ( (coin= LP_coinfind(symbol)) == 0 || (IAMLP == 0 && coin->inactive != 0) ) |
|
|
|
{ |
|
|
|
printf("LP_utxoadd reject inactive %s\n",symbol); |
|
|
@ -395,7 +304,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit |
|
|
|
else return(0); |
|
|
|
} else tmpsatoshis = (value - txfee); |
|
|
|
char str[65],str2[65],dispflag = 0;//(iambob == 0);
|
|
|
|
if ( iambob == 0 && bits256_cmp(pubkey,LP_mypub25519) != 0 ) |
|
|
|
if ( iambob == 0 && bits256_cmp(pubkey,G.LP_mypub25519) != 0 ) |
|
|
|
{ |
|
|
|
printf("trying to add Alice utxo when not mine? %s/v%d\n",bits256_str(str,txid),vout); |
|
|
|
return(0); |
|
|
@ -484,26 +393,24 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit |
|
|
|
LP_utxosetkey(utxo->key,txid,vout); |
|
|
|
LP_utxosetkey(utxo->key2,txid2,vout2); |
|
|
|
if ( LP_ismine(utxo) > 0 ) |
|
|
|
utxo->T.sessionid = LP_sessionid; |
|
|
|
utxo->T.sessionid = G.LP_sessionid; |
|
|
|
else utxo->T.sessionid = sessionid; |
|
|
|
if ( coin->inactive == 0 && (selector= LP_mempool_vinscan(&spendtxid,&spendvini,symbol,coinaddr,txid,vout,txid2,vout2)) >= 0 ) |
|
|
|
{ |
|
|
|
printf("utxoadd selector.%d spent in mempool %s vini.%d",selector,bits256_str(str,spendtxid),spendvini); |
|
|
|
utxo->T.spentflag = (uint32_t)time(NULL); |
|
|
|
} |
|
|
|
printf("U.%d %s %.8f %.8f addutxo.%d pubkey.%s session.%u\n",LP_mypeer!=0?LP_mypeer->numutxos:-1,symbol,dstr(value),dstr(value2),LP_ismine(utxo) > 0,bits256_str(str,utxo->pubkey),utxo->T.sessionid); |
|
|
|
printf(" %s %.8f %.8f addutxo.%d pubkey.%s session.%u\n",symbol,dstr(value),dstr(value2),LP_ismine(utxo) > 0,bits256_str(str,utxo->pubkey),utxo->T.sessionid); |
|
|
|
portable_mutex_lock(&LP_utxomutex); |
|
|
|
HASH_ADD_KEYPTR(hh,LP_utxoinfos[iambob],utxo->key,sizeof(utxo->key),utxo); |
|
|
|
HASH_ADD_KEYPTR(hh,G.LP_utxoinfos,utxo->key,sizeof(utxo->key),utxo); |
|
|
|
if ( _LP_utxo2find(iambob,txid2,vout2) == 0 ) |
|
|
|
HASH_ADD_KEYPTR(hh2,LP_utxoinfos2[iambob],utxo->key2,sizeof(utxo->key2),utxo); |
|
|
|
HASH_ADD_KEYPTR(hh2,G.LP_utxoinfos2,utxo->key2,sizeof(utxo->key2),utxo); |
|
|
|
portable_mutex_unlock(&LP_utxomutex); |
|
|
|
if ( iambob != 0 ) |
|
|
|
{ |
|
|
|
if ( LP_mypeer != 0 ) |
|
|
|
LP_mypeer->numutxos++; |
|
|
|
if ( LP_ismine(utxo) > 0 ) |
|
|
|
{ |
|
|
|
LP_utxo_clientpublish(utxo); |
|
|
|
//LP_utxo_clientpublish(utxo);
|
|
|
|
if ( LP_mypeer != 0 ) |
|
|
|
utxo->T.lasttime = (uint32_t)time(NULL); |
|
|
|
} |
|
|
@ -530,75 +437,14 @@ struct LP_utxoinfo *LP_utxoaddjson(int32_t iambob,int32_t pubsock,cJSON *argjson |
|
|
|
return(utxo); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t LP_utxosparse(char *destipaddr,uint16_t destport,char *retstr,uint32_t now) |
|
|
|
cJSON *LP_inventory(char *symbol) |
|
|
|
{ |
|
|
|
struct LP_peerinfo *destpeer,*peer; uint32_t argipbits; char *argipaddr; uint16_t argport,pushport,subport; cJSON *array,*item; int32_t i,n=0; bits256 txid; struct LP_utxoinfo *utxo; |
|
|
|
//printf("parse.(%s)\n",retstr);
|
|
|
|
if ( (array= cJSON_Parse(retstr)) != 0 ) |
|
|
|
{ |
|
|
|
if ( (n= cJSON_GetArraySize(array)) > 0 ) |
|
|
|
{ |
|
|
|
for (i=0; i<n; i++) |
|
|
|
{ |
|
|
|
item = jitem(array,i); |
|
|
|
if ( (argipaddr= jstr(item,"ipaddr")) != 0 && (argport= juint(item,"port")) != 0 ) |
|
|
|
{ |
|
|
|
if ( (pushport= juint(item,"push")) == 0 ) |
|
|
|
pushport = argport + 1; |
|
|
|
if ( (subport= juint(item,"sub")) == 0 ) |
|
|
|
subport = argport + 2; |
|
|
|
argipbits = (uint32_t)calc_ipbits(argipaddr); |
|
|
|
if ( (peer= LP_peerfind(argipbits,argport)) == 0 ) |
|
|
|
peer = LP_addpeer(0,-1,argipaddr,argport,pushport,subport,jint(item,"numpeers"),jint(item,"numutxos"),juint(item,"session")); |
|
|
|
} |
|
|
|
if ( jobj(item,"txid") != 0 ) |
|
|
|
{ |
|
|
|
txid = jbits256(item,"txid"); |
|
|
|
//printf("parse.(%s)\n",jprint(item,0));
|
|
|
|
if ( (utxo= LP_utxoaddjson(1,-1,item)) != 0 ) |
|
|
|
utxo->T.lasttime = now; |
|
|
|
} |
|
|
|
} |
|
|
|
if ( (destpeer= LP_peerfind((uint32_t)calc_ipbits(destipaddr),destport)) != 0 ) |
|
|
|
{ |
|
|
|
destpeer->numutxos = n; |
|
|
|
} |
|
|
|
} |
|
|
|
free_json(array); |
|
|
|
} |
|
|
|
return(n); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t LP_utxosquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr,uint16_t destport,char *coin,int32_t lastn,char *myipaddr,uint16_t myport,int32_t maxentries) |
|
|
|
{ |
|
|
|
char *retstr; struct LP_peerinfo *peer; uint32_t now; int32_t retval = -1; |
|
|
|
printf("deprecated LP_utxosquery\n"); |
|
|
|
return(-1); |
|
|
|
peer = LP_peerfind((uint32_t)calc_ipbits(destipaddr),destport); |
|
|
|
if ( coin == 0 ) |
|
|
|
coin = ""; |
|
|
|
//printf("utxo query.(%s)\n",destipaddr);
|
|
|
|
if ( IAMLP != 0 ) |
|
|
|
retstr = issue_LP_getutxos(destipaddr,destport,coin,lastn,myipaddr,myport,mypeer != 0 ? mypeer->numpeers : 0,maxentries); |
|
|
|
else retstr = issue_LP_clientgetutxos(destipaddr,destport,coin,maxentries); |
|
|
|
if ( retstr != 0 ) |
|
|
|
{ |
|
|
|
now = (uint32_t)time(NULL); |
|
|
|
retval = LP_utxosparse(destipaddr,destport,retstr,now); |
|
|
|
//printf("got.(%s)\n",retstr);
|
|
|
|
free(retstr); |
|
|
|
} |
|
|
|
return(retval); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *LP_inventory(char *symbol,int32_t iambob) |
|
|
|
{ |
|
|
|
struct LP_utxoinfo *utxo,*tmp; struct _LP_utxoinfo u; char *myipaddr; cJSON *array; uint64_t val,val2; |
|
|
|
struct LP_utxoinfo *utxo,*tmp; struct _LP_utxoinfo u; char *myipaddr; cJSON *array; uint64_t val,val2; int32_t iambob = 0; |
|
|
|
array = cJSON_CreateArray(); |
|
|
|
if ( LP_mypeer != 0 ) |
|
|
|
myipaddr = LP_mypeer->ipaddr; |
|
|
|
else myipaddr = "127.0.0.1"; |
|
|
|
HASH_ITER(hh,LP_utxoinfos[iambob],utxo,tmp) |
|
|
|
HASH_ITER(hh,G.LP_utxoinfos,utxo,tmp) |
|
|
|
{ |
|
|
|
char str[65]; |
|
|
|
//printf("iambob.%d iterate %s\n",iambob,bits256_str(str,LP_mypub25519));
|
|
|
@ -612,8 +458,8 @@ cJSON *LP_inventory(char *symbol,int32_t iambob) |
|
|
|
printf("%s %s ineligible %.8f %.8f\n",utxo->coin,bits256_str(str,u.txid),dstr(val),dstr(val2)); |
|
|
|
continue; |
|
|
|
} |
|
|
|
if ( iambob != 0 ) |
|
|
|
LP_utxo_clientpublish(utxo); |
|
|
|
//if ( iambob != 0 )
|
|
|
|
// LP_utxo_clientpublish(utxo);
|
|
|
|
jaddi(array,LP_inventoryjson(cJSON_CreateObject(),utxo)); |
|
|
|
} |
|
|
|
else if ( LP_ismine(utxo) > 0 && strcmp(symbol,utxo->coin) == 0 ) |
|
|
@ -764,14 +610,14 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri |
|
|
|
portable_mutex_lock(&LP_UTXOmutex); |
|
|
|
if ( iambob != 0 ) |
|
|
|
{ |
|
|
|
if ( (utxo= LP_utxoadd(1,mypubsock,coin->symbol,txid,vout,value,deposittxid,depositvout,depositval,script,coin->smartaddr,mypub,LP_gui,LP_sessionid)) != 0 ) |
|
|
|
if ( (utxo= LP_utxoadd(1,mypubsock,coin->symbol,txid,vout,value,deposittxid,depositvout,depositval,script,coin->smartaddr,mypub,LP_gui,G.LP_sessionid)) != 0 ) |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
//printf("call utxoadd\n");
|
|
|
|
if ( (utxo= LP_utxoadd(0,mypubsock,coin->symbol,deposittxid,depositvout,depositval,txid,vout,value,script,coin->smartaddr,mypub,LP_gui,LP_sessionid)) != 0 ) |
|
|
|
if ( (utxo= LP_utxoadd(0,mypubsock,coin->symbol,deposittxid,depositvout,depositval,txid,vout,value,script,coin->smartaddr,mypub,LP_gui,G.LP_sessionid)) != 0 ) |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
@ -839,7 +685,7 @@ char *LP_secretaddresses(void *ctx,char *passphrase,int32_t n,uint8_t taddr,uint |
|
|
|
|
|
|
|
bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *coin,char *passphrase,char *wifstr) |
|
|
|
{ |
|
|
|
static uint32_t counter; |
|
|
|
//static uint32_t counter;
|
|
|
|
bits256 privkey,userpub,userpass,checkkey; char tmpstr[128]; cJSON *retjson; uint8_t tmptype; |
|
|
|
if ( passphrase != 0 && passphrase[0] != 0 ) |
|
|
|
{ |
|
|
@ -864,23 +710,23 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan |
|
|
|
{ |
|
|
|
coin->counter++; |
|
|
|
bitcoin_priv2wif(coin->wiftaddr,tmpstr,privkey,coin->wiftype); |
|
|
|
bitcoin_addr2rmd160(coin->taddr,&tmptype,LP_myrmd160,coin->smartaddr); |
|
|
|
LP_privkeyadd(privkey,LP_myrmd160); |
|
|
|
bitcoin_addr2rmd160(coin->taddr,&tmptype,G.LP_myrmd160,coin->smartaddr); |
|
|
|
LP_privkeyadd(privkey,G.LP_myrmd160); |
|
|
|
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 ( counter++ == 0 ) |
|
|
|
if ( G.counter++ == 0 ) |
|
|
|
{ |
|
|
|
bitcoin_priv2wif(coin->wiftaddr,USERPASS_WIFSTR,privkey,188); |
|
|
|
bitcoin_wif2priv(coin->wiftaddr,&tmptype,&checkkey,USERPASS_WIFSTR); |
|
|
|
bitcoin_priv2wif(coin->wiftaddr,G.USERPASS_WIFSTR,privkey,188); |
|
|
|
bitcoin_wif2priv(coin->wiftaddr,&tmptype,&checkkey,G.USERPASS_WIFSTR); |
|
|
|
if ( bits256_cmp(checkkey,privkey) != 0 ) |
|
|
|
{ |
|
|
|
char str[65],str2[65]; |
|
|
|
printf("FATAL ERROR converting USERPASS_WIFSTR %s -> %s != %s\n",USERPASS_WIFSTR,bits256_str(str,checkkey),bits256_str(str2,privkey)); |
|
|
|
printf("FATAL ERROR converting USERPASS_WIFSTR %s -> %s != %s\n",G.USERPASS_WIFSTR,bits256_str(str,checkkey),bits256_str(str2,privkey)); |
|
|
|
exit(-1); |
|
|
|
} |
|
|
|
conv_NXTpassword(userpass.bytes,pubkeyp->bytes,(uint8_t *)USERPASS_WIFSTR,(int32_t)strlen(USERPASS_WIFSTR)); |
|
|
|
conv_NXTpassword(userpass.bytes,pubkeyp->bytes,(uint8_t *)G.USERPASS_WIFSTR,(int32_t)strlen(G.USERPASS_WIFSTR)); |
|
|
|
userpub = curve25519(userpass,curve25519_basepoint9()); |
|
|
|
printf("userpass.(%s)\n",bits256_str(USERPASS,userpub)); |
|
|
|
printf("userpass.(%s)\n",bits256_str(G.USERPASS,userpub)); |
|
|
|
} |
|
|
|
if ( coin->electrum == 0 ) |
|
|
|
{ |
|
|
@ -895,23 +741,29 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan |
|
|
|
} else free_json(retjson); |
|
|
|
} |
|
|
|
} |
|
|
|
LP_mypub25519 = *pubkeyp = curve25519(privkey,curve25519_basepoint9()); |
|
|
|
LP_mypriv25519 = privkey; |
|
|
|
G.LP_mypub25519 = *pubkeyp = curve25519(privkey,curve25519_basepoint9()); |
|
|
|
G.LP_mypriv25519 = privkey; |
|
|
|
//printf("privkey.(%s) -> LP_mypub25519.(%s)\n",bits256_str(str,privkey),bits256_str(str2,LP_mypub25519));
|
|
|
|
return(privkey); |
|
|
|
} |
|
|
|
|
|
|
|
void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase,int32_t initonly) |
|
|
|
void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase) |
|
|
|
{ |
|
|
|
struct iguana_info *coin,*tmp; bits256 pubkey,privkey; uint8_t pubkey33[33]; |
|
|
|
struct iguana_info *coin,*tmp; bits256 pubkey,privkey; uint8_t pubkey33[33]; int32_t initonly; |
|
|
|
initonly = (passphrase != 0); |
|
|
|
memset(privkey.bytes,0,sizeof(privkey)); |
|
|
|
pubkey = privkey; |
|
|
|
memset(pubkey.bytes,0,sizeof(pubkey)); |
|
|
|
HASH_ITER(hh,LP_coins,coin,tmp) |
|
|
|
{ |
|
|
|
//printf("i.%d of %d\n",i,LP_numcoins);
|
|
|
|
if ( initonly != 0 ) |
|
|
|
{ |
|
|
|
coin->counter = 0; |
|
|
|
memset(coin->smartaddr,0,sizeof(coin->smartaddr)); |
|
|
|
if ( bits256_nonz(privkey) == 0 || coin->smartaddr[0] == 0 ) |
|
|
|
privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,coin,passphrase,""); |
|
|
|
if ( coin->inactive == 0 && initonly == 0 ) |
|
|
|
} |
|
|
|
//printf("i.%d of %d\n",i,LP_numcoins);
|
|
|
|
else if ( coin->inactive == 0 ) |
|
|
|
{ |
|
|
|
if ( LP_privkey_init(pubsock,coin,privkey,pubkey) == 0 && (rand() % 10) == 0 ) |
|
|
|
LP_postutxos(coin->symbol,coin->smartaddr); |
|
|
@ -919,4 +771,40 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase,int32_t inito |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int32_t LP_passphrase_init(char *passphrase) |
|
|
|
{ |
|
|
|
static void *ctx; struct LP_utxoinfo *utxo,*tmp; |
|
|
|
if ( ctx == 0 ) |
|
|
|
ctx = bitcoin_ctx(); |
|
|
|
if ( G.LP_pendingswaps != 0 ) |
|
|
|
return(-1); |
|
|
|
G.initializing = 1; |
|
|
|
while ( G.waiting == 0 ) |
|
|
|
{ |
|
|
|
printf("waiting for G.waiting\n"); |
|
|
|
sleep(5); |
|
|
|
} |
|
|
|
if ( G.LP_utxoinfos != 0 ) |
|
|
|
{ |
|
|
|
HASH_ITER(hh,G.LP_utxoinfos,utxo,tmp) |
|
|
|
{ |
|
|
|
HASH_DELETE(hh,G.LP_utxoinfos,utxo); |
|
|
|
free(utxo); |
|
|
|
} |
|
|
|
} |
|
|
|
if ( G.LP_utxoinfos2 != 0 ) |
|
|
|
{ |
|
|
|
HASH_ITER(hh,G.LP_utxoinfos2,utxo,tmp) |
|
|
|
{ |
|
|
|
HASH_DELETE(hh,G.LP_utxoinfos2,utxo); |
|
|
|
free(utxo); |
|
|
|
} |
|
|
|
} |
|
|
|
memset(&G,0,sizeof(G)); |
|
|
|
LP_privkey_updates(ctx,LP_mypubsock,passphrase); |
|
|
|
init_hexbytes_noT(G.LP_myrmd160str,G.LP_myrmd160,20); |
|
|
|
G.LP_sessionid = (uint32_t)time(NULL); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|