Browse Source

Test

etomic
jl777 7 years ago
parent
commit
b25f229bba
  1. 5
      iguana/exchanges/LP_coins.c
  2. 18
      iguana/exchanges/LP_commands.c
  3. 5
      iguana/exchanges/LP_include.h
  4. 2
      iguana/exchanges/LP_nativeDEX.c
  5. 39
      iguana/exchanges/LP_swap.c
  6. 3
      iguana/exchanges/setconfirms
  7. 4
      iguana/exchanges/trust

5
iguana/exchanges/LP_coins.c

@ -299,6 +299,11 @@ uint16_t LP_coininit(struct iguana_info *coin,char *symbol,char *name,char *asse
coin->inactive = (uint32_t)time(NULL); coin->inactive = (uint32_t)time(NULL);
coin->bussock = LP_coinbus(busport); coin->bussock = LP_coinbus(busport);
coin->ctx = bitcoin_ctx(); coin->ctx = bitcoin_ctx();
if ( assetname != 0 && strcmp(name,assetname) == 0 )
{
printf("%s is assetchain\n",symbol);
coin->isassetchain = 1;
}
if ( strcmp(symbol,"KMD") == 0 || (assetname != 0 && assetname[0] != 0) ) if ( strcmp(symbol,"KMD") == 0 || (assetname != 0 && assetname[0] != 0) )
name2 = 0; name2 = 0;
else name2 = name; else name2 = name;

18
iguana/exchanges/LP_commands.c

@ -114,6 +114,8 @@ portfolio()\n\
getpeers()\n\ getpeers()\n\
passphrase(passphrase, gui)\n\ passphrase(passphrase, gui)\n\
listunspent(coin, address)\n\ listunspent(coin, address)\n\
setconfirms(coin, numconfirms, maxconfirms=6)\n\
trust(pubkey, trust)\n\
balance(coin, address)\n\ balance(coin, address)\n\
orderbook(base, rel, duration=3600)\n\ orderbook(base, rel, duration=3600)\n\
getprices(base, rel)\n\ getprices(base, rel)\n\
@ -275,6 +277,22 @@ dividends(coin, height, <args>)\n\
return(jprint(LP_electrumserver(ptr,jstr(argjson,"ipaddr"),juint(argjson,"port")),1)); return(jprint(LP_electrumserver(ptr,jstr(argjson,"ipaddr"),juint(argjson,"port")),1));
} else return(clonestr("{\"error\":\"cant find coind\"}")); } else return(clonestr("{\"error\":\"cant find coind\"}"));
} }
else if ( strcmp(method,"setconfirms") == 0 )
{
int32_t n;
n = jint(argjson,"numconfirms");
if ( n < 0 )
return(clonestr("{\"error\":\"illegal numconfirms\"}"));
if ( (ptr= LP_coinsearch(coin)) != 0 )
{
ptr->userconfirms = n;
if ( (n= jint(argjson,"maxconfirms")) > 0 )
ptr->maxconfirms = n;
if ( ptr->maxconfirms > 0 && ptr->userconfirms > ptr->maxconfirms )
ptr->userconfirms = ptr->maxconfirms;
return(clonestr("{\"result\":\"success\"}"));
} else return(clonestr("{\"error\":\"cant find coind\"}"));
}
else if ( strcmp(method,"snapshot") == 0 ) else if ( strcmp(method,"snapshot") == 0 )
{ {
if ( (ptr= LP_coinsearch(coin)) != 0 ) if ( (ptr= LP_coinsearch(coin)) != 0 )

5
iguana/exchanges/LP_include.h

@ -72,6 +72,7 @@
#define LP_AVETXSIZE 256 #define LP_AVETXSIZE 256
#define LP_CACHEDURATION 60 #define LP_CACHEDURATION 60
#define BASILISK_DEFAULT_NUMCONFIRMS 3 #define BASILISK_DEFAULT_NUMCONFIRMS 3
#define BASILISK_DEFAULT_MAXCONFIRMS 6
#define DEX_SLEEP 3 #define DEX_SLEEP 3
#define BASILISK_KEYSIZE ((int32_t)(2*sizeof(bits256)+sizeof(uint32_t)*2)) #define BASILISK_KEYSIZE ((int32_t)(2*sizeof(bits256)+sizeof(uint32_t)*2))
@ -151,7 +152,7 @@ struct basilisk_swapinfo
char bobstr[64],alicestr[64]; char bobstr[64],alicestr[64];
bits256 myhash,otherhash,orderhash; bits256 myhash,otherhash,orderhash;
uint32_t statebits,otherstatebits,started,expiration,finished,dead,reftime,putduration,callduration; uint32_t statebits,otherstatebits,started,expiration,finished,dead,reftime,putduration,callduration;
int32_t bobconfirms,aliceconfirms,iambob,reclaimed,bobspent,alicespent,pad,aliceistrusted,bobistrusted,otheristrusted,otherstrust; int32_t bobconfirms,aliceconfirms,iambob,reclaimed,bobspent,alicespent,pad,aliceistrusted,bobistrusted,otheristrusted,otherstrust,alicemaxconfirms,bobmaxconfirms;
uint64_t alicesatoshis,bobsatoshis,bobinsurance,aliceinsurance,Atxfee,Btxfee; uint64_t alicesatoshis,bobsatoshis,bobinsurance,aliceinsurance,Atxfee,Btxfee;
bits256 myprivs[2],mypubs[2],otherpubs[2],pubA0,pubA1,pubB0,pubB1,privAm,pubAm,privBn,pubBn; bits256 myprivs[2],mypubs[2],otherpubs[2],pubA0,pubA1,pubB0,pubB1,privAm,pubAm,privBn,pubBn;
@ -184,7 +185,7 @@ struct iguana_info
uint64_t txfee; uint64_t txfee;
int32_t longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport; int32_t longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport;
uint32_t addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,unspenttime,obooktime; uint32_t addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,unspenttime,obooktime;
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag; uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms;
char symbol[16],smartaddr[64],userpass[1024],serverport[128],lastunspent[64]; char symbol[16],smartaddr[64],userpass[1024],serverport[128],lastunspent[64];
// portfolio // portfolio
double price_kmd,force,perc,goal,goalperc,relvolume,rate; double price_kmd,force,perc,goal,goalperc,relvolume,rate;

2
iguana/exchanges/LP_nativeDEX.c

@ -338,7 +338,7 @@ void LP_smartutxos_push(struct iguana_info *coin)
memset(zero.bytes,0,sizeof(zero)); memset(zero.bytes,0,sizeof(zero));
if ( (n= cJSON_GetArraySize(array)) > 0 ) if ( (n= cJSON_GetArraySize(array)) > 0 )
{ {
printf("PUSH %s %s\n",coin->symbol,coin->smartaddr); //printf("PUSH %s %s\n",coin->symbol,coin->smartaddr);
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
item = jitem(array,i); item = jitem(array,i);

39
iguana/exchanges/LP_swap.c

@ -179,6 +179,8 @@ int32_t LP_pubkeys_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
int32_t i,datalen = 0; int32_t i,datalen = 0;
data[datalen++] = swap->I.aliceconfirms; data[datalen++] = swap->I.aliceconfirms;
data[datalen++] = swap->I.bobconfirms; data[datalen++] = swap->I.bobconfirms;
data[datalen++] = swap->I.alicemaxconfirms;
data[datalen++] = swap->I.bobmaxconfirms;
data[datalen++] = swap->I.otheristrusted; data[datalen++] = swap->I.otheristrusted;
for (i=0; i<33; i++) for (i=0; i<33; i++)
data[datalen++] = swap->persistent_pubkey33[i]; data[datalen++] = swap->persistent_pubkey33[i];
@ -189,18 +191,29 @@ int32_t LP_pubkeys_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
int32_t LP_pubkeys_verify(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) int32_t LP_pubkeys_verify(struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{ {
int32_t i,nonz=0,aliceconfirms,bobconfirms,len = 0; uint8_t other33[33]; int32_t i,nonz=0,alicemaxconfirms,bobmaxconfirms,aliceconfirms,bobconfirms,len = 0; uint8_t other33[33];
if ( datalen == sizeof(swap->otherdeck)+36 ) if ( datalen == sizeof(swap->otherdeck)+38 )
{ {
aliceconfirms = data[len++]; aliceconfirms = data[len++];
bobconfirms = data[len++]; bobconfirms = data[len++];
alicemaxconfirms = data[len++];
bobmaxconfirms = data[len++];
if ( aliceconfirms != swap->I.aliceconfirms || bobconfirms != swap->I.bobconfirms ) if ( aliceconfirms != swap->I.aliceconfirms || bobconfirms != swap->I.bobconfirms )
{ {
printf("MISMATCHED required confirms me.(%d %d) vs (%d %d)\n",swap->I.aliceconfirms,swap->I.bobconfirms,aliceconfirms,bobconfirms); printf("MISMATCHED required confirms me.(%d %d) vs (%d %d) max.(%d %d) othermax.(%d %d)\n",swap->I.aliceconfirms,swap->I.bobconfirms,aliceconfirms,bobconfirms,swap->I.alicemaxconfirms,swap->I.bobmaxconfirms,alicemaxconfirms,bobmaxconfirms);
if ( alicemaxconfirms > swap->I.alicemaxconfirms )
alicemaxconfirms = swap->I.alicemaxconfirms;
if ( bobmaxconfirms > swap->I.bobmaxconfirms )
bobmaxconfirms = swap->I.bobmaxconfirms;
if ( swap->I.aliceconfirms < aliceconfirms ) if ( swap->I.aliceconfirms < aliceconfirms )
swap->I.aliceconfirms = aliceconfirms; swap->I.aliceconfirms = aliceconfirms;
if ( swap->I.bobconfirms < bobconfirms ) if ( swap->I.bobconfirms < bobconfirms )
swap->I.bobconfirms = bobconfirms; swap->I.bobconfirms = bobconfirms;
if ( swap->I.aliceconfirms > swap->I.alicemaxconfirms || swap->I.bobconfirms > swap->I.bobmaxconfirms )
{
printf("numconfirms (%d %d) exceeds max (%d %d)\n",swap->I.aliceconfirms,swap->I.bobconfirms,swap->I.alicemaxconfirms,swap->I.bobmaxconfirms);
return(-1);
}
} }
if ( (swap->I.otherstrust= data[len++]) != 0 ) if ( (swap->I.otherstrust= data[len++]) != 0 )
{ {
@ -771,7 +784,7 @@ void LP_bobloop(void *_swap)
else m = swap->I.aliceconfirms; else m = swap->I.aliceconfirms;
while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) // sync with alice while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) // sync with alice
{ {
char str[65];printf("%d waiting for alicepayment %s to be confirmed.%d %s %s\n",n,swap->alicepayment.I.destaddr,1,swap->alicecoin.symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); char str[65];printf("%d waiting for alicepayment %s to be confirmed.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,swap->alicecoin.symbol,bits256_str(str,swap->alicepayment.I.signedtxid));
sleep(3); sleep(3);
} }
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0) == 0 ) if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0) == 0 )
@ -826,7 +839,7 @@ void LP_aliceloop(void *_swap)
else m = swap->I.aliceconfirms; else m = swap->I.aliceconfirms;
while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m )
{ {
char str[65];printf("%d waiting for alicepayment %s to be confirmed.%d %s %s\n",n,swap->alicepayment.I.destaddr,1,swap->alicecoin.symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); char str[65];printf("%d waiting for alicepayment %s to be confirmed.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,swap->alicecoin.symbol,bits256_str(str,swap->alicepayment.I.signedtxid));
sleep(10); sleep(10);
} }
swap->sentflag = 1; swap->sentflag = 1;
@ -1053,6 +1066,22 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256
swap->I.bobconfirms = BASILISK_DEFAULT_NUMCONFIRMS; swap->I.bobconfirms = BASILISK_DEFAULT_NUMCONFIRMS;
swap->I.aliceconfirms = BASILISK_DEFAULT_NUMCONFIRMS; swap->I.aliceconfirms = BASILISK_DEFAULT_NUMCONFIRMS;
} }
if ( swap->bobcoin.isassetchain != 0 )
swap->I.bobconfirms = 1;
if ( swap->alicecoin.isassetchain != 0 )
swap->I.aliceconfirms = 1;
if ( swap->bobcoin.userconfirms > 0 )
swap->I.bobconfirms = swap->bobcoin.userconfirms;
if ( swap->alicecoin.userconfirms > 0 )
swap->I.aliceconfirms = swap->alicecoin.userconfirms;
if ( (swap->I.bobmaxconfirms= swap->bobcoin.maxconfirms) == 0 )
swap->I.bobmaxconfirms = BASILISK_DEFAULT_MAXCONFIRMS;
if ( (swap->I.alicemaxconfirms= swap->alicecoin.maxconfirms) == 0 )
swap->I.alicemaxconfirms = BASILISK_DEFAULT_MAXCONFIRMS;
if ( swap->I.bobconfirms > swap->I.bobmaxconfirms )
swap->I.bobconfirms = swap->I.bobmaxconfirms;
if ( swap->I.aliceconfirms > swap->I.alicemaxconfirms )
swap->I.aliceconfirms = swap->I.alicemaxconfirms;
swap->I.bobconfirms *= !swap->I.bobistrusted; swap->I.bobconfirms *= !swap->I.bobistrusted;
swap->I.aliceconfirms *= !swap->I.aliceistrusted; swap->I.aliceconfirms *= !swap->I.aliceistrusted;
printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< use smart address, %.8f bobconfs.%d, %.8f aliceconfs.%d taddr.%d %d\n",jumblrflag,dstr(swap->I.bobsatoshis),swap->I.bobconfirms,dstr(swap->I.alicesatoshis),swap->I.aliceconfirms,swap->bobcoin.taddr,swap->alicecoin.taddr); printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< use smart address, %.8f bobconfs.%d, %.8f aliceconfs.%d taddr.%d %d\n",jumblrflag,dstr(swap->I.bobsatoshis),swap->I.bobconfirms,dstr(swap->I.alicesatoshis),swap->I.aliceconfirms,swap->bobcoin.taddr,swap->alicecoin.taddr);

3
iguana/exchanges/setconfirms

@ -0,0 +1,3 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"setconfirms\",\"coin\":\"REVS\",\"numconfirms\":1}"

4
iguana/exchanges/trust

@ -0,0 +1,4 @@
#!/bin/bash
echo "usage: ./trust <pubkey>"
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"pubkey\":\"$1\",\"method\":\"trust\",\"trust\":1}"
Loading…
Cancel
Save