Browse Source

Merge pull request #624 from jl777/jl777

Jl777
patch-3
jl777 7 years ago
committed by GitHub
parent
commit
acfcd18652
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      iguana/exchanges/LP_bitcoin.c
  2. 5
      iguana/exchanges/LP_coins.c
  3. 7
      iguana/exchanges/LP_commands.c
  4. 2
      iguana/exchanges/LP_include.h
  5. 36
      iguana/exchanges/LP_instantdex.c
  6. 4
      iguana/exchanges/LP_nativeDEX.c
  7. 14
      iguana/exchanges/LP_ordermatch.c
  8. 37
      iguana/exchanges/LP_privkey.c
  9. 20
      iguana/exchanges/LP_remember.c
  10. 14
      iguana/exchanges/LP_rpc.c
  11. 6
      iguana/exchanges/LP_scan.c
  12. 14
      iguana/exchanges/LP_swap.c
  13. 44
      iguana/exchanges/LP_transaction.c
  14. 41
      iguana/exchanges/LP_utxo.c
  15. 2
      iguana/exchanges/coins
  16. 3
      iguana/exchanges/convaddress
  17. 24
      iguana/exchanges/mm.c

8
iguana/exchanges/LP_bitcoin.c

@ -3391,7 +3391,7 @@ int32_t iguana_rwmsgtx(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shty
bits256 bitcoin_sigtxid(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,uint8_t *serialized,int32_t maxlen,struct iguana_msgtx *msgtx,int32_t vini,uint8_t *spendscript,int32_t spendlen,uint64_t spendamount,uint32_t hashtype,char *vpnstr,int32_t suppress_pubkeys,int32_t zcash)
{
int32_t i,len,sbtcflag = 0; bits256 sigtxid,txid,revsigtxid; struct iguana_msgtx dest;
int32_t i,len,sbtcflag = 0,btcpflag=0; bits256 sigtxid,txid,revsigtxid; struct iguana_msgtx dest;
dest = *msgtx;
dest.vins = calloc(dest.tx_in,sizeof(*dest.vins));
dest.vouts = calloc(dest.tx_out,sizeof(*dest.vouts));
@ -3400,6 +3400,8 @@ bits256 bitcoin_sigtxid(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2sht
memset(sigtxid.bytes,0,sizeof(sigtxid));
if ( strcmp(symbol,"SBTC") == 0 )
sbtcflag = 1;
else if ( strcmp(symbol,"BTCP") == 0 )
btcpflag = 1;
if ( ((hashtype & ~SIGHASH_FORKID) & 0xff) != SIGHASH_ALL )
{
printf("currently only SIGHASH_ALL supported, not %d\n",hashtype);
@ -3434,6 +3436,8 @@ bits256 bitcoin_sigtxid(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2sht
if ( height >= BTC2_HARDFORK_HEIGHT )
hashtype |= (0x777 << 20);
#endif
if ( btcpflag != 0 )
hashtype = 0x2a41;
len += iguana_rwnum(1,&serialized[len],sizeof(hashtype),&hashtype);
if ( sbtcflag != 0 )
{
@ -3610,7 +3614,7 @@ uint32_t LP_sighash(char *symbol,int32_t zcash)
sighash |= SIGHASH_FORKID;
sighash |= (LP_IS_BITCOINGOLD << 8);
}
else if ( strcmp(symbol,"SBTC") == 0 )
else if ( strcmp(symbol,"SBTC") == 0 || strcmp(symbol,"BTCP") == 0 )
sighash |= SIGHASH_FORKID;
return(sighash);
}

5
iguana/exchanges/LP_coins.c

@ -309,7 +309,7 @@ char *LP_getcoin(char *symbol)
HASH_ITER(hh,LP_coins,coin,tmp)
{
if ( strcmp(symbol,coin->symbol) == 0 )
item = LP_coinjson(coin,0);
item = LP_coinjson(coin,LP_showwif);
if ( coin->inactive == 0 )
numenabled++;
else numdisabled++;
@ -376,7 +376,8 @@ uint16_t LP_coininit(struct iguana_info *coin,char *symbol,char *name,char *asse
if ( assetname != 0 && strcmp(name,assetname) == 0 )
{
//printf("%s is assetchain\n",symbol);
coin->isassetchain = 1;
if ( strcmp(name,"BEER") != 0 && strcmp("PIZZA",name) != 0 )
coin->isassetchain = 1;
}
if ( strcmp(symbol,"KMD") == 0 || (assetname != 0 && assetname[0] != 0) )
name2 = 0;

7
iguana/exchanges/LP_commands.c

@ -161,6 +161,7 @@ bot_status(botid)\n\
bot_stop(botid)\n\
bot_pause(botid)\n\
calcaddress(passphrase)\n\
convaddress(coin, address, destcoin)\n\
instantdex_deposit(weeks, amount, broadcast=1)\n\
instantdex_claim()\n\
timelock(coin, duration, destaddr=(tradeaddr), amount)\n\
@ -513,6 +514,10 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
{
return(LP_sendrawtransaction(coin,jstr(argjson,"signedtx")));
}
else if ( strcmp(method,"convaddress") == 0 )
{
return(LP_convaddress(coin,jstr(argjson,"address"),jstr(argjson,"destcoin")));
}
else if ( strcmp(method,"timelock") == 0 )
{
return(LP_timelock(coin,juint(argjson,"duration"),jstr(argjson,"destaddr"),jdouble(argjson,"amount")*SATOSHIDEN));
@ -523,7 +528,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
}
else if ( strcmp(method,"getrawtransaction") == 0 )
{
return(jprint(LP_gettx(coin,jbits256(argjson,"txid"),0),1));
return(jprint(LP_gettx("stats_JSON",coin,jbits256(argjson,"txid"),0),1));
}
else if ( strcmp(method,"withdraw") == 0 )
{

2
iguana/exchanges/LP_include.h

@ -559,7 +559,7 @@ char *LP_unspents_filestr(char *symbol,char *addr);
cJSON *bitcoin_data2json(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,bits256 *txidp,struct iguana_msgtx *msgtx,uint8_t *extraspace,int32_t extralen,uint8_t *serialized,int32_t len,cJSON *vins,int32_t suppress_pubkeys,int32_t zcash);
//int32_t LP_butxo_findeither(bits256 txid,int32_t vout);
cJSON *LP_listunspent(char *symbol,char *coinaddr,bits256 reftxid,bits256 reftxid2);
int32_t LP_gettx_presence(char *symbol,bits256 expectedtxid);
int32_t LP_gettx_presence(int32_t *numconfirmsp,char *symbol,bits256 expectedtxid,char *coinaddr);
double LP_getestimatedrate(struct iguana_info *coin);
struct LP_utxoinfo *_LP_utxofind(int32_t iambob,bits256 txid,int32_t vout);
struct LP_utxoinfo *_LP_utxo2find(int32_t iambob,bits256 txid,int32_t vout);

36
iguana/exchanges/LP_instantdex.c

@ -155,6 +155,19 @@ void LP_instantdex_depositadd(char *coinaddr,bits256 txid)
LP_instantdex_filescreate(coinaddr);
}
uint32_t LP_claimtime(struct iguana_info *coin,uint32_t expiration)
{
uint32_t heighttime,now = (uint32_t)time(NULL);
if ( coin->height > 8 )
{
heighttime = LP_heighttime(coin->symbol,coin->height-8);
printf("claimtime: now %u height.%d heighttime.%u expiration.%u\n",now,coin->height,heighttime,expiration);
if ( heighttime >= expiration )
return(heighttime + 1);
}
return(0);
}
int32_t LP_deposit_addr(char *symbol,char *p2shaddr,uint8_t *script,uint8_t taddr,uint8_t p2shtype,uint32_t timestamp,uint8_t *pubsecp33)
{
uint8_t elsepub33[33],p2sh_rmd160[20]; int32_t n;
@ -285,16 +298,6 @@ int64_t LP_claimtx(void *ctx,struct iguana_info *coin,bits256 *claimtxidp,bits25
return(sum);
}
uint32_t LP_claimtime(struct iguana_info *coin,uint32_t expiration)
{
uint32_t heighttime,now = (uint32_t)time(NULL);
heighttime = LP_heighttime(coin->symbol,coin->height);
printf("claimtime: now %u height.%d heighttime.%u expiration.%u\n",now,coin->height,heighttime,expiration);
if ( heighttime >= expiration )
return(heighttime + 1);
return(0);
}
char *LP_unlockedspend(void *ctx,char *symbol,bits256 utxotxid)
{
cJSON *txjson,*vouts,*vout0,*opret,*sobj,*retjson; uint16_t utxovout; char *signedtx,*opretstr,vinaddr[64],destaddr[64]; uint32_t expiration,claimtime; uint8_t redeemscript[128]; bits256 signedtxid,sendtxid; int32_t numvouts,redeemlen; int64_t satoshis,destamount; struct iguana_info *coin;
@ -303,7 +306,7 @@ char *LP_unlockedspend(void *ctx,char *symbol,bits256 utxotxid)
retjson = cJSON_CreateObject();
utxovout = 0;
memset(&sendtxid,0,sizeof(sendtxid));
if ( (txjson= LP_gettx(coin->symbol,utxotxid,1)) != 0 )
if ( (txjson= LP_gettx("LP_unlockedspend",coin->symbol,utxotxid,1)) != 0 )
{
if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && numvouts >= 2 )
{
@ -335,12 +338,12 @@ char *LP_unlockedspend(void *ctx,char *symbol,bits256 utxotxid)
jaddnum(retjson,"expiration",expiration);
claimtime = LP_claimtime(coin,expiration);
jaddnum(retjson,"claimtime",claimtime);
if ( claimtime != 0 && strcmp(destaddr,coin->smartaddr) == 0 && time(NULL) > expiration )
if ( claimtime > expiration && strcmp(destaddr,coin->smartaddr) == 0 )
{
char str[65]; printf("LP_timespend satoshis %.8f %s/v%d\n",dstr(satoshis - coin->txfee),bits256_str(str,utxotxid),utxovout);
char str[65]; //printf("LP_timespend satoshis %.8f %s/v%d\n",dstr(satoshis - coin->txfee),bits256_str(str,utxotxid),utxovout);
if ( (signedtx= basilisk_swap_bobtxspend(&signedtxid,coin->txfee,"timespend",coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,ctx,G.LP_privkey,0,redeemscript+2,redeemlen-2,0,0,utxotxid,utxovout,coin->smartaddr,G.LP_pubsecp,0,claimtime,&destamount,0,0,vinaddr,0,coin->zcash)) != 0 )
{
//sendtxid = LP_broadcast("timespend",symbol,signedtx,signedtxid);
sendtxid = LP_broadcast("timespend",symbol,signedtx,signedtxid);
jaddstr(retjson,"signedtx",signedtx);
jaddbits256(retjson,"txid",signedtxid);
if ( bits256_cmp(sendtxid,signedtxid) == 0 )
@ -394,7 +397,7 @@ char *LP_timelock(char *symbol,uint32_t duration,char *destaddr,uint64_t satoshi
int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info *coin,bits256 utxotxid)
{
uint8_t redeemscript[512]; bits256 claimtxid; cJSON *txjson,*vout0,*vout1,*vout2,*vouts,*item; int32_t numvouts; char str[65],vinaddr[64],destaddr[64],checkaddr[64]; int32_t j,utxovout,flagi = 0,redeemlen,weeki,iter; int64_t weeksatoshis,satoshis; uint32_t expiration,claimtime;
if ( (txjson= LP_gettx(coin->symbol,utxotxid,1)) != 0 )
if ( (txjson= LP_gettx("LP_claim_submit",coin->symbol,utxotxid,1)) != 0 )
{
if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && numvouts >= 3 )
{
@ -419,6 +422,7 @@ int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info
{
flagi = 1;
claimtime = (uint32_t)time(NULL)-777;
//claimtime = LP_claimtime(coin,expiration);
item = cJSON_CreateObject();
jaddbits256(item,"txid",utxotxid);
jaddnum(item,"deposit",dstr(LP_value_extract(vout0,0)));
@ -511,7 +515,7 @@ int64_t LP_instantdex_credit(int32_t dispflag,char *coinaddr,int64_t satoshis,in
int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr,char *origcoinaddr)
{
cJSON *txjson,*vouts,*txobj,*item; int64_t satoshis=0,amount64; int32_t weeki,numvouts; char destaddr[64],p2shaddr[64];
if ( (txjson= LP_gettx(coin->symbol,txid,0)) != 0 )
if ( (txjson= LP_gettx("LP_instantdex_creditcalc",coin->symbol,txid,0)) != 0 )
{
// vout0 deposit, vout1 botsfee, vout2 smartaddress
if ( (vouts= jarray(&numvouts,txjson,"vout")) > 0 && numvouts >= 3 && LP_destaddr(destaddr,jitem(vouts,2)) == 0 )

4
iguana/exchanges/LP_nativeDEX.c

@ -651,7 +651,7 @@ void LP_coinsloop(void *_coins)
nonz++;
if ( strcmp("BTC",coins) == 0 )//&& coin->lastscanht < coin->longestchain-3 )
printf("[%s]: %s ref.%d scan.%d to %d, longest.%d\n",coins,coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain);
for (j=0; j<1000; j++)
for (j=0; j<100; j++)
{
if ( LP_blockinit(coin,coin->lastscanht) < 0 )
{
@ -1266,13 +1266,13 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
char *myipaddr=0,version[64]; long filesize,n; int32_t valid,timeout; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx();
sprintf(version,"Marketmaker %s.%s %s rsize.%ld",LP_MAJOR_VERSION,LP_MINOR_VERSION,LP_BUILD_NUMBER,sizeof(struct basilisk_request));
bitcoind_RPC_inittime = 1;
printf("%s %u\n",version,calc_crc32(0,version,(int32_t)strlen(version)));
if ( LP_MAXPRICEINFOS > 256 )
{
printf("LP_MAXPRICEINFOS %d wont fit in a uint8_t, need to increase the width of the baseind and relind for struct LP_pubkey_quote\n",LP_MAXPRICEINFOS);
exit(-1);
}
LP_showwif = juint(argjson,"wif");
printf("showwif.%d %s %u\n",LP_showwif,version,calc_crc32(0,version,(int32_t)strlen(version)));
if ( passphrase == 0 || passphrase[0] == 0 )
{
printf("jeezy says we cant use the nullstring as passphrase and I agree\n");

14
iguana/exchanges/LP_ordermatch.c

@ -965,9 +965,17 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
p = (double)qp->destsatoshis / (qp->satoshis - qp->txfee);
if ( LP_trades_pricevalidate(qp,coin,p) < 0. )
return(0);
if ( p >= qprice )
break;
price /= 0.99;
if ( i == 0 && p < myprice )
{
price = qprice;
printf("reset price <- qprice %.8f\n",qprice);
}
else
{
if ( qprice >= p )
break;
price *= 0.995;
}
i++;
}
printf("i.%d qprice %.8f myprice %.8f price %.8f [%.8f]\n",i,qprice,myprice,price,p);

37
iguana/exchanges/LP_privkey.c

@ -251,6 +251,43 @@ int32_t LP_wifstr_valid(char *symbol,char *wifstr)
return(0);
}
char *LP_convaddress(char *symbol,char *address,char *dest)
{
struct iguana_info *coin,*destcoin; cJSON *retjson; char destaddress[64],coinaddr2[64]; uint8_t addrtype,rmd160[20],rmd160b[20];
if ( (coin= LP_coinfind(symbol)) == 0 || (destcoin= LP_coinfind(dest)) == 0 )
return(clonestr("{\"error\":\"both coins must be present\"}"));
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"coin",symbol);
jaddstr(retjson,"address",address);
jaddstr(retjson,"destcoin",dest);
bitcoin_addr2rmd160(symbol,coin->taddr,&addrtype,rmd160,address);
if ( addrtype == coin->pubtype )
{
bitcoin_address(destcoin->symbol,destaddress,destcoin->taddr,destcoin->pubtype,rmd160,20);
bitcoin_addr2rmd160(destcoin->symbol,destcoin->taddr,&addrtype,rmd160b,destaddress);
bitcoin_address(coin->symbol,coinaddr2,coin->taddr,coin->pubtype,rmd160b,20);
}
else if ( addrtype == coin->p2shtype )
{
bitcoin_address(destcoin->symbol,destaddress,destcoin->taddr,destcoin->p2shtype,rmd160,20);
bitcoin_addr2rmd160(symbol,coin->taddr,&addrtype,rmd160b,destaddress);
bitcoin_address(destcoin->symbol,coinaddr2,coin->taddr,coin->p2shtype,rmd160b,20);
}
else
{
jaddstr(retjson,"error","invalid base58 prefix");
jaddnum(retjson,"invalid",addrtype);
}
if ( strcmp(address,coinaddr2) != 0 )
{
jaddstr(retjson,"error","checkaddress mismatch");
jaddstr(retjson,"checkaddress",coinaddr2);
}
jaddstr(retjson,"destaddress",destaddress);
return(jprint(retjson,1));
}
bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *coin,char *passphrase,char *wifstr)
{
//static uint32_t counter;

20
iguana/exchanges/LP_remember.c

@ -290,7 +290,7 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in
printf("i.%d of %d: %s\n",i,n,bits256_str(str,txid));
if ( bits256_cmp(txid,txids[utxoind]) != 0 )
{
if ( (txobj= LP_gettx(symbol,txid,1)) != 0 )
if ( (txobj= LP_gettx("basilisk_swap_spendupdate",symbol,txid,1)) != 0 )
{
if ( (vins= jarray(&numvins,txobj,"vin")) != 0 )
{
@ -934,7 +934,7 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap,int32_t forceflag)
safecopy(rswap->alicecoin,symbol,sizeof(rswap->alicecoin));
if ( rswap->finishedflag == 0 )
{
if ( (sentobj= LP_gettx(symbol,txid,1)) == 0 )
if ( (sentobj= LP_gettx("LP_remember",symbol,txid,1)) == 0 )
{
//char str2[65]; printf("%s %s ready to broadcast %s r%u q%u\n",symbol,bits256_str(str2,txid),txnames[i],rswap->requestid,rswap->quoteid);
}
@ -1162,6 +1162,12 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
printf("Bob.%p is null or Alice.%p is null\n",bob,alice);
return(cJSON_Parse("{\"error\":\"null bob or alice coin\"}"));
}
if ( alice->inactive != 0 || bob->inactive != 0 )
{
printf("Alice.%s inactive.%u or Bob.%s inactive.%u\n",rswap.alicecoin,alice->inactive,rswap.bobcoin,bob->inactive);
return(cJSON_Parse("{\"error\":\"inactive bob or alice coin\"}"));
}
portable_mutex_lock(&LP_swaplistmutex);
//printf("src.(Adest %s, Bdest %s), dest.(Adest %s, Bdest %s)\n",srcAdest,srcBdest,destAdest,destBdest);
//printf("iambob.%d finishedflag.%d %s %.8f txfee, %s %.8f txfee\n",rswap.iambob,rswap.finishedflag,rswap.alicecoin,dstr(rswap.Atxfee),rswap.bobcoin,dstr(rswap.Btxfee));
//printf("privAm.(%s) %p/%p\n",bits256_str(str,rswap.privAm),Adest,AAdest);
@ -1170,11 +1176,6 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
{
//printf("ALICE.(%s) 1st refht %s <- %d, scan %d %d\n",rswap.Adestaddr,alice->symbol,alice->firstrefht,alice->firstscanht,alice->lastscanht);
//printf("BOB.(%s) 1st refht %s <- %d, scan %d %d\n",rswap.destaddr,bob->symbol,bob->firstrefht,bob->firstscanht,bob->lastscanht);
if ( alice->inactive != 0 || bob->inactive != 0 )
{
printf("Alice.%s inactive.%u or Bob.%s inactive.%u\n",rswap.alicecoin,alice->inactive,rswap.bobcoin,bob->inactive);
return(cJSON_Parse("{\"error\":\"inactive bob or alice coin\"}"));
}
LP_rswap_checktx(&rswap,rswap.alicecoin,BASILISK_ALICEPAYMENT);
LP_rswap_checktx(&rswap,rswap.bobcoin,BASILISK_BOBPAYMENT);
LP_rswap_checktx(&rswap,rswap.bobcoin,BASILISK_BOBDEPOSIT);
@ -1486,6 +1487,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
free_json(item);
item = 0;
}
portable_mutex_unlock(&LP_swaplistmutex);
return(item);
}
@ -1514,7 +1516,7 @@ void for_satinder()
char *basilisk_swaplist(uint32_t origrequestid,uint32_t origquoteid,int32_t forceflag,int32_t pendingonly)
{
uint64_t ridqids[4096],ridqid; char fname[512]; FILE *fp; cJSON *item,*retjson,*array,*totalsobj; uint32_t r,q,quoteid,requestid; int64_t KMDtotals[LP_MAXPRICEINFOS],BTCtotals[LP_MAXPRICEINFOS],Btotal,Ktotal; int32_t i,j,count=0;
portable_mutex_lock(&LP_swaplistmutex);
//portable_mutex_lock(&LP_swaplistmutex);
memset(ridqids,0,sizeof(ridqids));
memset(KMDtotals,0,sizeof(KMDtotals));
memset(BTCtotals,0,sizeof(BTCtotals));
@ -1595,7 +1597,7 @@ char *basilisk_swaplist(uint32_t origrequestid,uint32_t origquoteid,int32_t forc
else if ( Ktotal < 0 && Btotal > 0 )
jaddnum(retjson,"avesell",(double)-Btotal/Ktotal);
}
portable_mutex_unlock(&LP_swaplistmutex);
//portable_mutex_unlock(&LP_swaplistmutex);
return(jprint(retjson,1));
}

14
iguana/exchanges/LP_rpc.c

@ -179,10 +179,10 @@ cJSON *LP_paxprice(char *fiat)
return(bitcoin_json(coin,"paxprice",buf));
}
cJSON *LP_gettx(char *symbol,bits256 txid,int32_t suppress_errors)
cJSON *LP_gettx(char *debug,char *symbol,bits256 txid,int32_t suppress_errors)
{
struct iguana_info *coin; char buf[512],str[65]; int32_t height; cJSON *retjson;
//printf("LP_gettx %s %s\n",symbol,bits256_str(str,txid));
//printf("%s LP_gettx %s %s\n",debug,symbol,bits256_str(str,txid));
if ( symbol == 0 || symbol[0] == 0 )
return(cJSON_Parse("{\"error\":\"null symbol\"}"));
coin = LP_coinfind(symbol);
@ -209,7 +209,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid,int32_t suppress_errors)
uint32_t LP_locktime(char *symbol,bits256 txid)
{
cJSON *txobj; uint32_t locktime = 0;
if ( (txobj= LP_gettx(symbol,txid,0)) != 0 )
if ( (txobj= LP_gettx("LP_locktime",symbol,txid,0)) != 0 )
{
locktime = juint(txobj,"locktime");
free_json(txobj);
@ -926,9 +926,9 @@ uint32_t LP_heighttime(char *symbol,int32_t height)
{
if ( (blockhashstr= LP_blockhashstr(symbol,height)) != 0 )
{
if ( (retjson= cJSON_Parse(blockhashstr)) != 0 )
if ( (retjson= LP_getblockhashstr(symbol,blockhashstr)) != 0 )
{
//printf("height.(%s)\n",jprint(retjson,0));
//printf("%s -> height.(%s)\n",blockhashstr,jprint(retjson,0));
timestamp = juint(retjson,"time");
free_json(retjson);
}
@ -1055,7 +1055,7 @@ int32_t LP_txhasnotarization(bits256 *notarizedhashp,struct iguana_info *coin,bi
{
cJSON *txobj,*vins,*vin,*vouts,*vout,*spentobj,*sobj; char *hexstr; uint8_t script[1024]; bits256 spenttxid; uint64_t notarymask; int32_t i,j,numnotaries,len,spentvout,numvins,numvouts,hasnotarization = 0;
memset(notarizedhashp,0,sizeof(*notarizedhashp));
if ( (txobj= LP_gettx(coin->symbol,txid,0)) != 0 )
if ( (txobj= LP_gettx("LP_txhasnotarization",coin->symbol,txid,0)) != 0 )
{
if ( (vins= jarray(&numvins,txobj,"vin")) != 0 )
{
@ -1067,7 +1067,7 @@ int32_t LP_txhasnotarization(bits256 *notarizedhashp,struct iguana_info *coin,bi
vin = jitem(vins,i);
spenttxid = jbits256(vin,"txid");
spentvout = jint(vin,"vout");
if ( (spentobj= LP_gettx(coin->symbol,spenttxid,0)) != 0 )
if ( (spentobj= LP_gettx("LP_txhasnotarization",coin->symbol,spenttxid,0)) != 0 )
{
if ( (vouts= jarray(&numvouts,spentobj,"vout")) != 0 )
{

6
iguana/exchanges/LP_scan.c

@ -448,7 +448,7 @@ int32_t LP_mempoolscan(char *symbol,bits256 searchtxid)
int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration)
{
struct iguana_info *coin; bits256 zero; cJSON *array,*item; uint32_t expiration,i,n; int32_t numconfirms = -1;
struct iguana_info *coin; bits256 zero; cJSON *array,*item; uint32_t expiration,i,n; int32_t num,numconfirms = -1;
if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 )
{
printf("LP_waitmempool missing coin.%p or inactive\n",coin);
@ -457,8 +457,8 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int
expiration = (uint32_t)time(NULL) + duration;
while ( LP_STOP_RECEIVED == 0 )
{
if ( LP_gettx_presence(symbol,txid) != 0 )
numconfirms = 0;
if ( LP_gettx_presence(&num,symbol,txid,coinaddr) != 0 )
numconfirms = num;
else
{
if ( coin->electrum == 0 )

14
iguana/exchanges/LP_swap.c

@ -906,6 +906,7 @@ void LP_bobloop(void *_swap)
}
} else printf("swap timed out\n");
LP_swap_endcritical = (uint32_t)time(NULL);
sleep(13);
LP_pendswap_add(swap->I.expiration,swap->I.req.requestid,swap->I.req.quoteid);
//swap->I.finished = LP_swapwait(swap->I.expiration,swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*3,swap->I.aliceconfirms == 0 ? 3 : 30);
basilisk_swap_finished(swap);
@ -968,10 +969,6 @@ void LP_aliceloop(void *_swap)
printf("error waiting for bobpayment\n");
else
{
if ( swap->I.alicetomic[0] != 0 )
{
// artem: do stuff alice needs to do after bobpayment comes in
}
LP_swap_endcritical = (uint32_t)time(NULL);
while ( (n= LP_numconfirms(bobstr,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,1)) < swap->I.bobconfirms )
{
@ -986,6 +983,7 @@ void LP_aliceloop(void *_swap)
}
}
LP_swap_endcritical = (uint32_t)time(NULL);
sleep(13);
LP_pendswap_add(swap->I.expiration,swap->I.req.requestid,swap->I.req.quoteid);
//swap->I.finished = LP_swapwait(swap->I.expiration,swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*3,swap->I.aliceconfirms == 0 ? 3 : 30);
basilisk_swap_finished(swap);
@ -1205,10 +1203,6 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256
swap->I.bobconfirms = BASILISK_DEFAULT_NUMCONFIRMS;
swap->I.aliceconfirms = BASILISK_DEFAULT_NUMCONFIRMS;
}
if ( bobcoin->isassetchain != 0 )
swap->I.bobconfirms = 1;
if ( alicecoin->isassetchain != 0 )
swap->I.aliceconfirms = 1;
if ( bobcoin->userconfirms > 0 )
swap->I.bobconfirms = bobcoin->userconfirms;
if ( alicecoin->userconfirms > 0 )
@ -1221,6 +1215,10 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256
swap->I.bobconfirms = swap->I.bobmaxconfirms;
if ( swap->I.aliceconfirms > swap->I.alicemaxconfirms )
swap->I.aliceconfirms = swap->I.alicemaxconfirms;
if ( bobcoin->isassetchain != 0 )
swap->I.bobconfirms = BASILISK_DEFAULT_MAXCONFIRMS;
if ( alicecoin->isassetchain != 0 )
swap->I.aliceconfirms = BASILISK_DEFAULT_MAXCONFIRMS;
if ( strcmp("BAY",swap->I.req.src) != 0 && strcmp("BAY",swap->I.req.dest) != 0 )
{
swap->I.bobconfirms *= !swap->I.bobistrusted;

44
iguana/exchanges/LP_transaction.c

@ -60,15 +60,41 @@ bits256 LP_pubkey(bits256 privkey)
return(pubkey);
}
int32_t LP_gettx_presence(char *symbol,bits256 expectedtxid)
int32_t LP_gettx_presence(int32_t *numconfirmsp,char *symbol,bits256 expectedtxid,char *coinaddr)
{
cJSON *txobj; bits256 txid; int32_t flag = 0;
if ( (txobj= LP_gettx(symbol,expectedtxid,0)) != 0 )
cJSON *txobj,*retjson,*item; bits256 txid; struct iguana_info *coin; int32_t height=-1,i,n,flag = 0;
if ( numconfirmsp != 0 )
*numconfirmsp = -1;
if ( (txobj= LP_gettx("LP_gettx_presence",symbol,expectedtxid,0)) != 0 )
{
txid = jbits256(txobj,"txid");
if ( jobj(txobj,"error") == 0 && bits256_cmp(txid,expectedtxid) == 0 )
{
//char str[65]; printf("%s already in gettx (%s)\n",bits256_str(str,txid),jprint(txobj,0));
*numconfirmsp = 0;
if ( numconfirmsp != 0 && coinaddr != 0 && (coin= LP_coinfind(symbol)) != 0 && coin->electrum != 0 )
{
//char str[65]; printf("%s %s already in gettx (%s)\n",coinaddr,bits256_str(str,txid),jprint(txobj,0));
if ( (retjson= electrum_address_gethistory(symbol,coin->electrum,&retjson,coinaddr,expectedtxid)) != 0 )
{
if ( (n= cJSON_GetArraySize(retjson)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(retjson,i);
if ( bits256_cmp(txid,jbits256(item,"tx_hash")) == 0 )
{
height = jint(item,"height");
//printf("found txid at height.%d\n",height);
if ( height <= coin->height )
*numconfirmsp = (coin->height - height + 1);
break;
}
}
}
free_json(retjson);
//printf("got %s history height.%d vs coin.%d -> numconfirms.%d\n",coin->symbol,height,coin->height,*numconfirmsp);
}
}
flag = 1;
}
free_json(txobj);
@ -94,7 +120,7 @@ bits256 LP_broadcast(char *txname,char *symbol,char *txbytes,bits256 expectedtxi
for (i=0; i<2; i++)
{
//char str[65]; printf("LP_broadcast.%d (%s) %s i.%d sentflag.%d\n",i,symbol,bits256_str(str,expectedtxid),i,sentflag);
if ( sentflag == 0 && LP_gettx_presence(symbol,expectedtxid) != 0 )
if ( sentflag == 0 && LP_gettx_presence(0,symbol,expectedtxid,0) != 0 )
sentflag = 1;
if ( sentflag == 0 && (retstr= LP_sendrawtransaction(symbol,txbytes)) != 0 )
{
@ -764,7 +790,7 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
if ( txfee > 0 && txfee < coin->txfee )
txfee = coin->txfee;
#ifndef BASILISK_DISABLESENDTX
if ( (txobj= LP_gettx(symbol,utxotxid,0)) != 0 )
if ( (txobj= LP_gettx("basilisk_swap_bobtxspend",symbol,utxotxid,0)) != 0 )
{
if ( (vouts= jarray(&n,txobj,"vout")) != 0 && utxovout < n )
{
@ -1615,7 +1641,7 @@ int32_t LP_swap_getcoinaddr(char *symbol,char *coinaddr,bits256 txid,int32_t vou
{
cJSON *retjson;
coinaddr[0] = 0;
if ( (retjson= LP_gettx(symbol,txid,0)) != 0 )
if ( (retjson= LP_gettx("LP_swap_getcoinaddr",symbol,txid,0)) != 0 )
{
LP_txdestaddr(coinaddr,txid,vout,retjson);
free_json(retjson);
@ -1627,7 +1653,7 @@ int32_t basilisk_swap_getsigscript(char *symbol,uint8_t *script,int32_t maxlen,b
{
cJSON *retjson,*vins,*item,*skey; int32_t n,scriptlen = 0; char *hexstr;
//char str[65]; printf("getsigscript %s %s/v%d\n",symbol,bits256_str(str,txid),vini);
if ( bits256_nonz(txid) != 0 && (retjson= LP_gettx(symbol,txid,0)) != 0 )
if ( bits256_nonz(txid) != 0 && (retjson= LP_gettx("basilisk_swap_getsigscript",symbol,txid,0)) != 0 )
{
//printf("gettx.(%s)\n",jprint(retjson,0));
if ( (vins= jarray(&n,retjson,"vin")) != 0 && vini < n )
@ -1720,7 +1746,7 @@ bits256 LP_swap_spendtxid(char *symbol,char *destaddr,bits256 utxotxid,int32_t u
for (i=0; i<n; i++)
{
txid = jbits256i(array,i);
if ( (txobj= LP_gettx(symbol,txid,1)) != 0 )
if ( (txobj= LP_gettx("LP_swap_spendtxid",symbol,txid,1)) != 0 )
{
if ( (vins= jarray(&m,txobj,"vin")) != 0 )
{

41
iguana/exchanges/LP_utxo.c

@ -811,7 +811,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS
struct LP_transaction *tx; int32_t i,height,numvouts,numvins,spentvout; cJSON *vins,*vouts,*vout,*vin; bits256 spenttxid; char str[65];
if ( coin->inactive != 0 )
return(0);
if ( txobj != 0 || (txobj= LP_gettx(coin->symbol,txid,0)) != 0 )
if ( txobj != 0 || (txobj= LP_gettx("LP_transactioninit",coin->symbol,txid,0)) != 0 )
{
if ( coin->electrum == 0 )
height = LP_txheight(coin,txid);
@ -868,12 +868,16 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS
int32_t LP_txheight(struct iguana_info *coin,bits256 txid)
{
bits256 blockhash; struct LP_transaction *tx; cJSON *blockobj,*retjson,*txobj; int32_t height = 0;
bits256 blockhash; struct LP_transaction *tx=0; cJSON *blockobj,*retjson,*txobj,*txobj2; int32_t height = 0;
if ( coin == 0 )
return(-1);
if ( (tx= LP_transactionfind(coin,txid)) != 0 )
height = tx->height;
if ( height > 0 )
return(height);
if ( coin->electrum == 0 )
{
if ( (txobj= LP_gettx(coin->symbol,txid,0)) != 0 )
if ( (txobj= LP_gettx("LP_txheight",coin->symbol,txid,0)) != 0 )
{
//*timestampp = juint(txobj,"locktime");
//*blocktimep = juint(txobj,"blocktime");
@ -881,6 +885,17 @@ int32_t LP_txheight(struct iguana_info *coin,bits256 txid)
if ( bits256_nonz(blockhash) != 0 && (blockobj= LP_getblock(coin->symbol,blockhash)) != 0 )
{
height = jint(blockobj,"height");
if ( tx != 0 )
tx->height = height;
else if ( 0 )
{
txobj2 = LP_transactioninit(coin,txid,0,0);
txobj2 = LP_transactioninit(coin,txid,1,txobj2);
if ( txobj2 != 0 )
free_json(txobj2);
if ( (tx= LP_transactionfind(coin,txid)) != 0 )
tx->height = height;
}
//char str[65];
//if ( strcmp(coin->symbol,"CHIPS") != 0 && strcmp(coin->symbol,"BTC") != 0 )
// printf("%s %s LP_txheight.%d\n",coin->symbol,bits256_str(str,txid),height);
@ -891,8 +906,8 @@ int32_t LP_txheight(struct iguana_info *coin,bits256 txid)
}
else
{
if ( (tx= LP_transactionfind(coin,txid)) != 0 )
height = tx->height;
//if ( (tx= LP_transactionfind(coin,txid)) != 0 )
// height = tx->height;
if ( height == 0 )
{
if ( (retjson= electrum_transaction(&height,coin->symbol,coin->electrum,&retjson,txid,0)) != 0 )
@ -923,7 +938,7 @@ int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int
}
else if ( mempool != 0 && LP_mempoolscan(symbol,txid) >= 0 )
numconfirms = 0;
else if ( (txobj= LP_gettx(symbol,txid,1)) != 0 )
else if ( (txobj= LP_gettx("LP_numconfirms",symbol,txid,1)) != 0 )
{
numconfirms = jint(txobj,"confirmations");
free_json(txobj);
@ -941,6 +956,18 @@ int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int
numconfirms = 0;
}
}
/*if ( numconfirms == BASILISK_DEFAULT_MAXCONFIRMS )
{
if ( coin->isassetchain != 0 || strcmp(coin->symbol,"KMD") == 0 )
{
numconfirms--;
if ( coin->notarized >= coin->height-numconfirms )
{
printf("%s notarized.%d current ht.%d - numconfirms.%d -> txheight.%d\n",coin->symbol,coin->notarized,coin->height,numconfirms,coin->height - numconfirms);
numconfirms = BASILISK_DEFAULT_MAXCONFIRMS;
}
}
}*/
return(numconfirms);
}
@ -1052,7 +1079,7 @@ int64_t LP_outpoint_amount(char *symbol,bits256 txid,int32_t vout)
return(amount);
else
{
if ( (txjson= LP_gettx(symbol,txid,1)) != 0 )
if ( (txjson= LP_gettx("LP_outpoint_amount",symbol,txid,1)) != 0 )
{
if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && vout < numvouts )
amount = LP_value_extract(jitem(vouts,vout),0);

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

3
iguana/exchanges/convaddress

@ -0,0 +1,3 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"convaddress\",\"coin\":\"BTC\",\"address\":\"1KPctPk4Zs4Qbe1x32A5bC1roAnmpvi9Fy\",\"destcoin\":\"KMD\"}"

24
iguana/exchanges/mm.c

@ -161,23 +161,21 @@ int main(int argc, const char * argv[])
OS_init();
if ( strstr(argv[0],"btc2kmd") != 0 && argv[1] != 0 )
{
uint8_t addrtype,rmd160[20],rmd160b[20]; char coinaddr[64],coinaddr2[64];
bitcoin_addr2rmd160("BTC",0,&addrtype,rmd160,(char *)argv[1]);
if ( addrtype == 0 )
bits256 privkey,checkkey; uint8_t tmptype; char kmdwif[64],str[65],str2[65],*retstr;
if ( LP_wifstr_valid("BTC",(char *)argv[1]) > 0 )
{
bitcoin_address("KMD",coinaddr,0,60,rmd160,20);
bitcoin_addr2rmd160("KMD",0,&addrtype,rmd160b,coinaddr);
bitcoin_address("BTC",coinaddr2,0,0,rmd160b,20);
bitcoin_wif2priv("BTC",0,&tmptype,&privkey,(char *)argv[1]);
bitcoin_priv2wif("KMD",0,kmdwif,privkey,188);
bitcoin_wif2priv("KMD",0,&tmptype,&checkkey,kmdwif);
if ( bits256_cmp(privkey,checkkey) == 0 )
printf("BTC %s -> KMD %s: privkey %s\n",argv[1],kmdwif,bits256_str(str,privkey));
else printf("ERROR BTC %s %s != KMD %s %s\n",argv[1],bits256_str(str,privkey),kmdwif,bits256_str(str2,checkkey));
}
else if ( addrtype == 60 )
else
{
bitcoin_address("BTC",coinaddr,0,0,rmd160,20);
bitcoin_addr2rmd160("BTC",0,&addrtype,rmd160b,coinaddr);
bitcoin_address("KMD",coinaddr2,0,60,rmd160b,20);
if ( (retstr= LP_convaddress("BTC",(char *)argv[1],"KMD")) != 0 )
printf("%s\n",retstr);
}
printf("(%s) -> %s -> %s\n",(char *)argv[1],coinaddr,coinaddr2);
if ( strcmp((char *)argv[1],coinaddr2) != 0 )
printf("ERROR\n");
exit(0);
}
else if ( argv[1] != 0 && strcmp(argv[1],"hush") == 0 )

Loading…
Cancel
Save