Browse Source

Test

etomic
jl777 8 years ago
parent
commit
56aa3712bb
  1. 3
      iguana/exchanges/LP_commands.c
  2. 16
      iguana/exchanges/LP_nativeDEX.c
  3. 2
      iguana/exchanges/LP_rpc.c
  4. 96
      iguana/exchanges/LP_utxos.c

3
iguana/exchanges/LP_commands.c

@ -309,8 +309,7 @@ forward(pubkey,hexstr)\n\
{
privkey = LP_privkeycalc(pubkey33,&pubkey,ptr,"",USERPASS_WIFSTR);
LP_utxopurge(0);
LP_privkey_init(-1,ptr,privkey,pubkey,pubkey33,0);
LP_privkey_init(-1,ptr,privkey,pubkey,pubkey33,1);
LP_privkey_init(-1,ptr,privkey,pubkey,pubkey33);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jadd(retjson,"alice",LP_inventory(coin,0));

16
iguana/exchanges/LP_nativeDEX.c

@ -167,16 +167,8 @@ void LP_utxo_spentcheck(int32_t pubsock,struct LP_utxoinfo *utxo,double profitma
void LP_utxo_updates(int32_t pubsock,char *passphrase,double profitmargin)
{
int32_t iambob; struct LP_utxoinfo *utxo,*tmp;
LP_utxopurge(0);
for (iambob=0; iambob<=1; iambob++)
{
LP_privkey_updates(pubsock,passphrase,iambob);
HASH_ITER(hh,LP_utxoinfos[iambob],utxo,tmp)
{
LP_utxo_spentcheck(pubsock,utxo,profitmargin);
}
}
LP_privkey_updates(pubsock,passphrase);
}
void LP_mainloop(char *myipaddr,struct LP_peerinfo *mypeer,uint16_t mypubport,int32_t pubsock,char *pushaddr,int32_t pullsock,uint16_t myport,char *passphrase,double profitmargin,cJSON *coins)
@ -219,10 +211,8 @@ void LP_mainloop(char *myipaddr,struct LP_peerinfo *mypeer,uint16_t mypubport,in
LP_priceinfoadd(jstr(item,"coin"));
}
}
printf("update alice\n");
LP_privkey_updates(pubsock,passphrase,0);
printf("update bob\n");
LP_privkey_updates(pubsock,passphrase,1);
printf("update utxos\n");
LP_privkey_updates(pubsock,passphrase);
printf("update swaps\n");
if ( (retstr= basilisk_swaplist()) != 0 )
free(retstr);

2
iguana/exchanges/LP_rpc.c

@ -83,7 +83,7 @@ cJSON *bitcoin_json(struct iguana_info *coin,char *method,char *params)
retstr = bitcoind_passthru(coin->symbol,coin->serverport,coin->userpass,method,params);
if ( retstr != 0 && retstr[0] != 0 )
{
printf("%s: %s.%s -> (%s)\n",coin->symbol,method,params,retstr);
//printf("%s: %s.%s -> (%s)\n",coin->symbol,method,params,retstr);
retjson = cJSON_Parse(retstr);
free(retstr);
}

96
iguana/exchanges/LP_utxos.c

@ -527,73 +527,79 @@ int32_t LP_nearestvalue(uint64_t *values,int32_t n,uint64_t targetval)
return(mini);
}
uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub,uint8_t *pubkey33,int32_t iambob)
uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub,uint8_t *pubkey33)
{
char *script; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,n,vout,depositvout; uint64_t *values,satoshis,depositval,targetval,value,total = 0;
char *script; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,n,iambob,vout,depositvout; uint64_t *values=0,satoshis,depositval,targetval,value,total = 0;
if ( coin == 0 )
{
printf("coin not active\n");
return(0);
}
//printf("privkey init.(%s) %s\n",symbol,coin->symbol);
printf("privkey init.(%s)\n",coin->symbol);
if ( coin->inactive == 0 && (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 )
{
if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 )
{
values = calloc(n,sizeof(*values));
for (i=0; i<n; i++)
for (iambob=0; iambob<=1; iambob++)
{
item = jitem(array,i);
satoshis = SATOSHIDEN * jdouble(item,"amount");
values[i] = satoshis;
//printf("%.8f ",dstr(satoshis));
}
//printf("array.%d\n",n);
used = 0;
while ( used < n-1 )
{
//printf("used.%d of n.%d\n",used,n);
if ( (i= LP_maxvalue(values,n)) >= 0 )
if ( iambob == 0 )
values = calloc(n,sizeof(*values));
else memset(values,0,n * sizeof(*values));
for (i=0; i<n; i++)
{
item = jitem(array,i);
deposittxid = jbits256(item,"txid");
depositvout = juint(item,"vout");
script = jstr(item,"scriptPubKey");
depositval = values[i];
values[i] = 0, used++;
if ( iambob == 0 )
targetval = (depositval / 776) + 100000;
else targetval = (depositval / 9) * 8 + 100000;
//printf("i.%d %.8f target %.8f\n",i,dstr(depositval),dstr(targetval));
if ( (i= LP_nearestvalue(values,n,targetval)) >= 0 )
satoshis = SATOSHIDEN * jdouble(item,"amount");
values[i] = satoshis;
//printf("%.8f ",dstr(satoshis));
}
//printf("array.%d\n",n);
used = 0;
while ( used < n-1 )
{
//printf("used.%d of n.%d\n",used,n);
if ( (i= LP_maxvalue(values,n)) >= 0 )
{
item = jitem(array,i);
txid = jbits256(item,"txid");
vout = juint(item,"vout");
if ( jstr(item,"scriptPubKey") != 0 && strcmp(script,jstr(item,"scriptPubKey")) == 0 )
deposittxid = jbits256(item,"txid");
depositvout = juint(item,"vout");
script = jstr(item,"scriptPubKey");
depositval = values[i];
values[i] = 0, used++;
if ( iambob == 0 )
targetval = (depositval / 776) + 100000;
else targetval = (depositval / 9) * 8 + 100000;
//printf("i.%d %.8f target %.8f\n",i,dstr(depositval),dstr(targetval));
if ( (i= LP_nearestvalue(values,n,targetval)) >= 0 )
{
value = values[i];
values[i] = 0, used++;
if ( iambob != 0 )
item = jitem(array,i);
txid = jbits256(item,"txid");
vout = juint(item,"vout");
if ( jstr(item,"scriptPubKey") != 0 && strcmp(script,jstr(item,"scriptPubKey")) == 0 )
{
if ( (utxo= LP_addutxo(1,mypubsock,coin->symbol,txid,vout,value,deposittxid,depositvout,depositval,script,coin->smartaddr,mypub,LP_peerinfos[0].profitmargin)) != 0 )
value = values[i];
values[i] = 0, used++;
if ( iambob != 0 )
{
//utxo->S.mypub = curve25519(privkey,curve25519_basepoint9());
if ( (utxo= LP_addutxo(1,mypubsock,coin->symbol,txid,vout,value,deposittxid,depositvout,depositval,script,coin->smartaddr,mypub,LP_peerinfos[0].profitmargin)) != 0 )
{
//utxo->S.mypub = curve25519(privkey,curve25519_basepoint9());
}
}
}
else
{
if ( (utxo= LP_addutxo(0,mypubsock,coin->symbol,deposittxid,depositvout,depositval,txid,vout,value,script,coin->smartaddr,mypub,0)) != 0 )
else
{
//utxo->S.mypub = curve25519(privkey,curve25519_basepoint9());
if ( (utxo= LP_addutxo(0,mypubsock,coin->symbol,deposittxid,depositvout,depositval,txid,vout,value,script,coin->smartaddr,mypub,0)) != 0 )
{
//utxo->S.mypub = curve25519(privkey,curve25519_basepoint9());
}
}
total += value;
}
total += value;
}
}
} else break;
} else break;
}
if ( iambob == 1 )
free(values);
}
free(values);
}
free_json(array);
}
@ -630,7 +636,7 @@ bits256 LP_privkeycalc(uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *co
return(privkey);
}
void LP_privkey_updates(int32_t pubsock,char *passphrase,int32_t iambob)
void LP_privkey_updates(int32_t pubsock,char *passphrase)
{
int32_t i; struct iguana_info *coin; bits256 pubkey,privkey; uint8_t pubkey33[33];
memset(privkey.bytes,0,sizeof(privkey));
@ -643,7 +649,7 @@ void LP_privkey_updates(int32_t pubsock,char *passphrase,int32_t iambob)
if ( bits256_nonz(privkey) == 0 || coin->smartaddr[0] == 0 )
privkey = LP_privkeycalc(pubkey33,&pubkey,coin,passphrase,"");
if ( coin->inactive == 0 )
LP_privkey_init(pubsock,coin,privkey,pubkey,pubkey33,iambob);
LP_privkey_init(pubsock,coin,privkey,pubkey,pubkey33);
}
}
}

Loading…
Cancel
Save