diff --git a/basilisk/basilisk.h b/basilisk/basilisk.h index a7bb6be4d..b15b9032f 100755 --- a/basilisk/basilisk.h +++ b/basilisk/basilisk.h @@ -46,7 +46,7 @@ struct basilisk_swap; struct basilisk_rawtxinfo { - char destaddr[64]; + char destaddr[64],coinstr[16]; bits256 txid,signedtxid,actualtxid; uint64_t amount,change,inputsum; int32_t redeemlen,datalen,completed,vintype,vouttype,numconfirms,spendlen,secretstart,suppress_pubkeys; @@ -60,8 +60,9 @@ struct basilisk_rawtx struct iguana_msgtx msgtx; struct basilisk_rawtxinfo I; struct iguana_info *coin; + char vinstr[8192]; cJSON *vins; - uint8_t *txbytes,spendscript[512],redeemscript[1024],extraspace[1024]; + uint8_t txbytes[16384],spendscript[512],redeemscript[1024],extraspace[4096]; }; struct basilisk_swapinfo diff --git a/basilisk/basilisk_swap.c b/basilisk/basilisk_swap.c index 18e41e56f..e8ee6438a 100755 --- a/basilisk/basilisk_swap.c +++ b/basilisk/basilisk_swap.c @@ -320,7 +320,7 @@ bits256 basilisk_swap_broadcast(char *name,struct supernet_info *myinfo,struct b int32_t _basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,uint32_t timestamp,uint32_t locktime,uint32_t sequenceid,struct basilisk_rawtx *dest,struct basilisk_rawtx *rawtx,bits256 privkey,bits256 *privkey2,uint8_t *userdata,int32_t userdatalen,int32_t ignore_cltverr) { char *rawtxbytes=0,*signedtx=0,hexstr[999],wifstr[128]; cJSON *txobj,*vins,*item,*sobj,*privkeys; int32_t needsig=1,retval = -1; struct vin_info *V; - V = calloc(16,sizeof(*V)); + V = calloc(256,sizeof(*V)); V[0].signers[0].privkey = privkey; bitcoin_pubkey33(myinfo->ctx,V[0].signers[0].pubkey,privkey); privkeys = cJSON_CreateArray(); @@ -352,7 +352,7 @@ int32_t _basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,uint32_ needsig = 0; #endif } - printf("rawtx B\n"); + //printf("rawtx B\n"); if ( bits256_nonz(rawtx->I.actualtxid) != 0 ) jaddbits256(item,"txid",rawtx->I.actualtxid); else jaddbits256(item,"txid",rawtx->I.signedtxid); @@ -382,8 +382,9 @@ int32_t _basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,uint32_ if ( signedtx != 0 || (signedtx= iguana_signrawtx(myinfo,rawtx->coin,height,&dest->I.signedtxid,&dest->I.completed,vins,rawtxbytes,privkeys,V)) != 0 ) { dest->I.datalen = (int32_t)strlen(signedtx) >> 1; - dest->txbytes = calloc(1,dest->I.datalen); - decode_hex(dest->txbytes,dest->I.datalen,signedtx); + if ( dest->I.datalen <= sizeof(dest->txbytes) ) + decode_hex(dest->txbytes,dest->I.datalen,signedtx); + else printf("DEX tx is too big %d vs %d\n",dest->I.datalen,(int32_t)sizeof(dest->txbytes)); if ( signedtx != rawtxbytes ) free(signedtx); if ( dest->I.completed != 0 ) @@ -394,6 +395,7 @@ int32_t _basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,uint32_ } else printf("error making rawtx\n"); free_json(privkeys); free_json(txobj); + free(V); return(retval); } @@ -477,7 +479,7 @@ int32_t basilisk_rawtx_return(struct supernet_info *myinfo,int32_t height,struct } } rawtx->I.datalen = (int32_t)strlen(signedtx) >> 1; - rawtx->txbytes = calloc(1,rawtx->I.datalen); + //rawtx->txbytes = calloc(1,rawtx->I.datalen); decode_hex(rawtx->txbytes,rawtx->I.datalen,signedtx); printf("%s SIGNEDTX.(%s)\n",rawtx->name,signedtx); free(signedtx); @@ -490,7 +492,7 @@ int32_t basilisk_rawtx_return(struct supernet_info *myinfo,int32_t height,struct int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,uint32_t swapstarted,uint8_t *pubkey33,int32_t iambob,int32_t lockinputs,struct basilisk_rawtx *rawtx,uint32_t locktime,uint8_t *script,int32_t scriptlen,int64_t txfee,int32_t minconf,int32_t delay) { - char *retstr,scriptstr[1024],coinaddr[64]; uint32_t basilisktag; int32_t flag,i,n,retval = -1; cJSON *addresses,*valsobj,*retarray=0; struct vin_info *V; + char *retstr,*jsonstr,scriptstr[1024],coinaddr[64]; uint32_t basilisktag; int32_t flag,i,n,retval = -1; cJSON *addresses,*valsobj,*retarray=0; struct vin_info *V; //bitcoin_address(coinaddr,rawtx->coin->chain->pubtype,myinfo->persistent_pubkey33,33); if ( rawtx->coin->changeaddr[0] == 0 ) { @@ -531,7 +533,10 @@ int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,uint32_t swaps { if ( (retval= basilisk_rawtx_return(myinfo,rawtx->coin->longestchain,rawtx,jitem(retarray,i),lockinputs,V)) == 0 ) { - rawtx->vins = jobj(jitem(retarray,i),"vins"); + rawtx->vins = jduplicate(jobj(jitem(retarray,i),"vins")); + jsonstr = jprint(rawtx->vins,0); + safecopy(rawtx->vinstr,jsonstr,sizeof(rawtx->vinstr)); + free(jsonstr); break; } } @@ -539,7 +544,10 @@ int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,uint32_t swaps else { retval = basilisk_rawtx_return(myinfo,rawtx->coin->longestchain,rawtx,retarray,lockinputs,V); - rawtx->vins = jobj(retarray,"vins"); + rawtx->vins = jduplicate(jobj(retarray,"vins")); + jsonstr = jprint(rawtx->vins,0); + safecopy(rawtx->vinstr,jsonstr,sizeof(rawtx->vinstr)); + free(jsonstr); } free(retarray); } else printf("error parsing.(%s)\n",retstr); @@ -552,7 +560,7 @@ int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,uint32_t swaps struct basilisk_rawtx *basilisk_swapdata_rawtx(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen,struct basilisk_rawtx *rawtx) { - if ( rawtx->txbytes != 0 && rawtx->I.datalen <= maxlen ) + if ( rawtx->I.datalen != 0 && rawtx->I.datalen <= maxlen ) { memcpy(data,rawtx->txbytes,rawtx->I.datalen); return(rawtx); @@ -564,8 +572,9 @@ int32_t basilisk_verify_otherfee(struct supernet_info *myinfo,void *ptr,uint8_t { struct basilisk_swap *swap = ptr; // add verification and broadcast - swap->otherfee.txbytes = calloc(1,datalen); + //swap->otherfee.txbytes = calloc(1,datalen); memcpy(swap->otherfee.txbytes,data,datalen); + swap->otherfee.I.datalen = datalen; swap->otherfee.I.actualtxid = swap->otherfee.I.signedtxid = bits256_doublesha256(0,data,datalen); basilisk_txlog(myinfo,swap,&swap->otherfee,-1); return(0); @@ -583,9 +592,9 @@ int32_t basilisk_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,str if ( rawtx->I.redeemlen > 0 && rawtx->I.redeemlen < 0x100 ) memcpy(rawtx->redeemscript,&data[datalen],rawtx->I.redeemlen); //printf("recvlen.%d datalen.%d redeemlen.%d\n",recvlen,datalen,rawtx->redeemlen); - if ( rawtx->txbytes == 0 ) + if ( rawtx->I.datalen == 0 ) { - rawtx->txbytes = calloc(1,datalen); + //rawtx->txbytes = calloc(1,datalen); memcpy(rawtx->txbytes,data,datalen); rawtx->I.datalen = datalen; } @@ -891,14 +900,14 @@ int32_t basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swa //for (i=0; ibobpayment.redeemlen; i++) // printf("%02x",swap->bobpayment.redeemscript[i]); //printf(" <- bobpayment.%d\n",i); - if ( genflag != 0 && bits256_nonz(*(bits256 *)swap->I.secretBn256) != 0 && swap->bobpayment.txbytes == 0 ) + if ( genflag != 0 && bits256_nonz(*(bits256 *)swap->I.secretBn256) != 0 && swap->bobpayment.I.datalen == 0 ) { for (i=0; i<3; i++) { //if ( swap->bobpayment.txbytes != 0 && swap->bobpayment.I.spendlen != 0 ) // break; basilisk_rawtx_gen("payment",myinfo,swap->I.started,swap->persistent_pubkey33,1,1,&swap->bobpayment,swap->bobpayment.I.locktime,swap->bobpayment.spendscript,swap->bobpayment.I.spendlen,swap->bobpayment.coin->chain->txfee,1,0); - if ( swap->bobpayment.txbytes == 0 || swap->bobpayment.I.spendlen == 0 ) + if ( swap->bobpayment.I.spendlen == 0 || swap->bobpayment.I.datalen == 0 ) { printf("error bob generating %p payment.%d\n",swap->bobpayment.txbytes,swap->bobpayment.I.spendlen); sleep(DEX_SLEEP); @@ -924,14 +933,14 @@ int32_t basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swa else { swap->bobdeposit.I.spendlen = basilisk_bobscript(swap->bobdeposit.I.rmd160,swap->bobdeposit.redeemscript,&swap->bobdeposit.I.redeemlen,swap->bobdeposit.spendscript,0,&swap->bobdeposit.I.locktime,&swap->bobdeposit.I.secretstart,&swap->I,1); - if ( genflag != 0 && (swap->bobdeposit.txbytes == 0 || swap->bobrefund.txbytes == 0) ) + if ( genflag != 0 && (swap->bobdeposit.I.datalen == 0 || swap->bobrefund.I.datalen == 0) ) { for (i=0; i<3; i++) { //if ( swap->bobdeposit.txbytes != 0 && swap->bobdeposit.I.spendlen != 0 ) // break; basilisk_rawtx_gen("deposit",myinfo,swap->I.started,swap->persistent_pubkey33,1,1,&swap->bobdeposit,swap->bobdeposit.I.locktime,swap->bobdeposit.spendscript,swap->bobdeposit.I.spendlen,swap->bobdeposit.coin->chain->txfee,1,0); - if ( swap->bobdeposit.txbytes == 0 || swap->bobdeposit.I.spendlen == 0 ) + if ( swap->bobdeposit.I.datalen == 0 || swap->bobdeposit.I.spendlen == 0 ) { printf("error bob generating %p deposit.%d\n",swap->bobdeposit.txbytes,swap->bobdeposit.I.spendlen); sleep(DEX_SLEEP); @@ -1028,9 +1037,9 @@ void basilisk_swapgotdata(struct supernet_info *myinfo,struct basilisk_swap *swa FILE *basilisk_swap_save(struct supernet_info *myinfo,struct basilisk_swap *swap,bits256 privkey,struct basilisk_request *rp,uint32_t statebits,int32_t optionduration,int32_t reinit) { - FILE *fp; char fname[512]; + FILE *fp=0; char fname[512]; sprintf(fname,"%s/SWAPS/%u-%u",GLOBAL_DBDIR,rp->requestid,rp->quoteid), OS_compatible_path(fname); - if ( (fp= fopen(fname,"rb+")) == 0 ) + if ( 0 && (fp= fopen(fname,"rb+")) == 0 ) { if ( (fp= fopen(fname,"wb+")) != 0 ) { @@ -1073,7 +1082,7 @@ void basilisk_swaps_init(struct supernet_info *myinfo) while ( fread(&M,1,sizeof(M),fp) == sizeof(M) ) { M.data = 0; - printf("entry iter.%d crc32.%x datalen.%d\n",iter,M.crc32,M.datalen); + //printf("entry iter.%d crc32.%x datalen.%d\n",iter,M.crc32,M.datalen); if ( M.datalen < 100000 ) { M.data = malloc(M.datalen); @@ -1220,7 +1229,7 @@ int32_t basilisk_privBn_extract(struct supernet_info *myinfo,struct basilisk_swa } if ( basilisk_swapget(myinfo,swap,0x40000000,data,maxlen,basilisk_verify_privi) == 0 ) { - if ( bits256_nonz(swap->I.privBn) != 0 && swap->alicereclaim.txbytes == 0 ) + if ( bits256_nonz(swap->I.privBn) != 0 && swap->alicereclaim.I.datalen == 0 ) { char str[65]; printf("have privBn.%s\n",bits256_str(str,swap->I.privBn)); return(basilisk_alicepayment_spend(myinfo,swap,&swap->alicereclaim)); @@ -1235,7 +1244,7 @@ int32_t basilisk_privAm_extract(struct supernet_info *myinfo,struct basilisk_swa { } - if ( bits256_nonz(swap->I.privAm) != 0 && swap->bobspend.txbytes == 0 ) + if ( bits256_nonz(swap->I.privAm) != 0 && swap->bobspend.I.datalen == 0 ) { char str[65]; printf("have privAm.%s\n",bits256_str(str,swap->I.privAm)); return(basilisk_alicepayment_spend(myinfo,swap,&swap->bobspend)); @@ -1312,6 +1321,7 @@ void basilisk_rawtx_setparms(char *name,uint32_t quoteid,struct basilisk_rawtx * { strcpy(rawtx->name,name); rawtx->coin = coin; + strcpy(rawtx->I.coinstr,coin->symbol); rawtx->I.numconfirms = numconfirms; if ( (rawtx->I.amount= satoshis) < 10000 ) rawtx->I.amount = 10000; @@ -1367,20 +1377,82 @@ int32_t bitcoin_coinptrs(bits256 pubkey,struct iguana_info **bobcoinp,struct igu return(0); } +void basilisk_swap_saveupdate(struct supernet_info *myinfo,struct basilisk_swap *swap) +{ + FILE *fp; char fname[512]; + sprintf(fname,"%s/SWAPS/%u-%u.swap",GLOBAL_DBDIR,swap->I.req.requestid,swap->I.req.quoteid); + if ( 0 && (fp= fopen(fname,"wb")) != 0 ) + { + fwrite(&swap->I,1,sizeof(swap->I),fp); + /*fwrite(&swap->bobdeposit,1,sizeof(swap->bobdeposit),fp); + fwrite(&swap->bobpayment,1,sizeof(swap->bobpayment),fp); + fwrite(&swap->alicepayment,1,sizeof(swap->alicepayment),fp); + fwrite(&swap->myfee,1,sizeof(swap->myfee),fp); + fwrite(&swap->otherfee,1,sizeof(swap->otherfee),fp); + fwrite(&swap->aliceclaim,1,sizeof(swap->aliceclaim),fp); + fwrite(&swap->alicespend,1,sizeof(swap->alicespend),fp); + fwrite(&swap->bobreclaim,1,sizeof(swap->bobreclaim),fp); + fwrite(&swap->bobspend,1,sizeof(swap->bobspend),fp); + fwrite(&swap->bobrefund,1,sizeof(swap->bobrefund),fp); + fwrite(&swap->alicereclaim,1,sizeof(swap->alicereclaim),fp);*/ + fwrite(swap->privkeys,1,sizeof(swap->privkeys),fp); + fwrite(swap->otherdeck,1,sizeof(swap->otherdeck),fp); + fwrite(swap->deck,1,sizeof(swap->deck),fp); + fclose(fp); + } +} + +int32_t basilisk_swap_loadtx(struct basilisk_rawtx *rawtx,FILE *fp,char *bobcoinstr,char *alicecoinstr) +{ + if ( fread(rawtx,1,sizeof(*rawtx),fp) == sizeof(*rawtx) ) + { + rawtx->coin = 0; + rawtx->vins = 0; + if ( strcmp(rawtx->I.coinstr,bobcoinstr) == 0 || strcmp(rawtx->I.coinstr,alicecoinstr) == 0 ) + { + rawtx->coin = iguana_coinfind(rawtx->I.coinstr); + if ( rawtx->vinstr[0] != 0 ) + rawtx->vins = cJSON_Parse(rawtx->vinstr); + printf("loaded.%s len.%d\n",rawtx->name,rawtx->I.datalen); + return(0); + } + } + return(-1); +} + struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,bits256 privkey,uint8_t *pubkey33,bits256 pubkey25519,struct basilisk_swap *swap,int32_t optionduration,uint32_t statebits,int32_t reinit) { FILE *fp; char fname[512]; uint8_t *alicepub33=0,*bobpub33=0; int32_t jumblrflag,x = -1; if ( reinit != 0 ) { sprintf(fname,"%s/SWAPS/%u-%u.swap",GLOBAL_DBDIR,swap->I.req.requestid,swap->I.req.quoteid); + printf("reinit.(%s)\n",fname); if ( (fp= fopen(fname,"rb")) != 0 ) { fread(&swap->I,1,sizeof(swap->I),fp); + if ( swap->bobcoin == 0 ) + swap->bobcoin = iguana_coinfind(swap->I.req.dest); + if ( swap->alicecoin == 0 ) + swap->alicecoin = iguana_coinfind(swap->I.req.src); + if ( swap->alicecoin != 0 && swap->bobcoin != 0 ) + { + /*basilisk_swap_loadtx(&swap->bobdeposit,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->bobpayment,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->alicepayment,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->myfee,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->otherfee,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->aliceclaim,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->alicespend,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->bobreclaim,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->bobspend,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->bobrefund,fp,swap->bobcoin->symbol,swap->alicecoin->symbol); + basilisk_swap_loadtx(&swap->alicereclaim,fp,swap->bobcoin->symbol,swap->alicecoin->symbol);*/ + } else printf("missing coins (%p %p)\n",swap->bobcoin,swap->alicecoin); fread(swap->privkeys,1,sizeof(swap->privkeys),fp); fread(swap->otherdeck,1,sizeof(swap->otherdeck),fp); fread(swap->deck,1,sizeof(swap->deck),fp); fclose(fp); - } + } else printf("cant find.(%s)\n",fname); } else { @@ -1474,8 +1546,10 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,bits256 priv void basilisk_rawtx_purge(struct basilisk_rawtx *rawtx) { - if ( rawtx->txbytes != 0 ) - free(rawtx->txbytes), rawtx->txbytes = 0; + if ( rawtx->vins != 0 ) + free_json(rawtx->vins); + //if ( rawtx->txbytes != 0 ) + // free(rawtx->txbytes), rawtx->txbytes = 0; } void basilisk_swap_finished(struct supernet_info *myinfo,struct basilisk_swap *swap) @@ -1488,11 +1562,12 @@ void basilisk_swap_finished(struct supernet_info *myinfo,struct basilisk_swap *s basilisk_rawtx_purge(&swap->alicepayment); basilisk_rawtx_purge(&swap->myfee); basilisk_rawtx_purge(&swap->otherfee); - basilisk_rawtx_purge(&swap->alicereclaim); + basilisk_rawtx_purge(&swap->aliceclaim); basilisk_rawtx_purge(&swap->alicespend); basilisk_rawtx_purge(&swap->bobreclaim); basilisk_rawtx_purge(&swap->bobspend); basilisk_rawtx_purge(&swap->bobrefund); + basilisk_rawtx_purge(&swap->alicereclaim); for (i=0; inummessages; i++) if ( swap->messages[i].data != 0 ) free(swap->messages[i].data), swap->messages[i].data = 0; @@ -1658,7 +1733,7 @@ uint32_t basilisk_swapdata_rawtxsend(struct supernet_info *myinfo,struct basilis } } return(nextbits); - } else printf("error from basilisk_swapdata_rawtx %p len.%d\n",rawtx->txbytes,rawtx->I.datalen); + } else printf("error from basilisk_swapdata_rawtx.%s %p len.%d\n",rawtx->name,rawtx->txbytes,rawtx->I.datalen); return(0); } @@ -1806,8 +1881,10 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap if ( (swap->I.otherstatebits & 0x80) == 0 ) basilisk_swapdata_rawtxsend(myinfo,swap,0x80,data,maxlen,&swap->myfee,0x40,0); } + basilisk_swap_saveupdate(myinfo,swap); while ( retval == 0 && time(NULL) < swap->I.expiration ) // both sides have setup required data and paid txfee { + basilisk_swap_saveupdate(myinfo,swap); if ( swap->connected == 0 ) basilisk_psockinit(myinfo,swap,swap->I.iambob != 0); //if ( (rand() % 30) == 0 ) @@ -1845,7 +1922,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0); } // [BLOCKING: privM] Bob waits for privAm either from Alice or alice blockchain - else if ( (swap->I.statebits & 0x40000) == 0 ) + else if ( (swap->I.statebits & 0xc0000) != 0xc0000 ) { if ( basilisk_swapget(myinfo,swap,0x40000,data,maxlen,basilisk_verify_privi) == 0 || basilisk_privAm_extract(myinfo,swap) == 0 ) // divulges privAm { @@ -2087,7 +2164,7 @@ void basilisk_psockinit(struct supernet_info *myinfo,struct basilisk_swap *swap, void basilisk_swaploop(void *_swap) { - uint8_t *data; uint32_t expiration; char fname[512]; uint32_t channel; int32_t retval=0,i,j,datalen,maxlen; FILE *fp; struct supernet_info *myinfo; struct basilisk_swap *swap = _swap; + uint8_t *data; uint32_t expiration; uint32_t channel; int32_t retval=0,i,j,datalen,maxlen; struct supernet_info *myinfo; struct basilisk_swap *swap = _swap; myinfo = swap->myinfoptr; fprintf(stderr,"start swap\n"); maxlen = 1024*1024 + sizeof(*swap); @@ -2112,8 +2189,6 @@ void basilisk_swaploop(void *_swap) break; } sleep(DEX_SLEEP); - //dpow_nanomsg_update(myinfo); - //dex_updateclient(myinfo); } if ( swap->connected == 0 ) { @@ -2134,8 +2209,6 @@ void basilisk_swaploop(void *_swap) break; } sleep(DEX_SLEEP + (swap->I.iambob == 0)*1); - //dpow_nanomsg_update(myinfo); - //dex_updateclient(myinfo); } myinfo->DEXactive = swap->I.expiration; if ( time(NULL) >= expiration ) @@ -2144,27 +2217,16 @@ void basilisk_swaploop(void *_swap) myinfo->DEXactive = 0; } printf("C r%u/q%u swapstate.%x retval.%d\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits,retval); - sprintf(fname,"%s/SWAPS/%u-%u.swap",GLOBAL_DBDIR,swap->I.req.requestid,swap->I.req.quoteid); - if ( (fp= fopen(fname,"wb")) != 0 ) - { - fwrite(&swap->I,1,sizeof(swap->I),fp); - fwrite(swap->privkeys,1,sizeof(swap->privkeys),fp); - fwrite(swap->otherdeck,1,sizeof(swap->otherdeck),fp); - fwrite(swap->deck,1,sizeof(swap->deck),fp); - fclose(fp); - } while ( retval == 0 && (swap->I.statebits & 0x40) == 0 ) // send fee { if ( swap->connected == 0 ) basilisk_psockinit(myinfo,swap,swap->I.iambob != 0); - //dpow_nanomsg_update(myinfo); - //dex_updateclient(myinfo); //printf("sendstate.%x\n",swap->I.statebits); basilisk_sendstate(myinfo,swap,data,maxlen); //printf("swapget\n"); basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); //printf("after swapget\n"); - if ( swap->myfee.txbytes == 0 ) + if ( swap->myfee.I.datalen == 0 ) { /*for (i=0; i<20; i++) printf("%02x",swap->secretAm[i]); @@ -2214,7 +2276,7 @@ void basilisk_swaploop(void *_swap) //if ( swap->alicepayment.txbytes != 0 && swap->alicepayment.I.spendlen != 0 ) // break; basilisk_alicepayment(myinfo,swap,swap->alicepayment.coin,&swap->alicepayment,swap->I.pubAm,swap->I.pubBn); - if ( swap->alicepayment.txbytes == 0 || swap->alicepayment.I.spendlen == 0 ) + if ( swap->alicepayment.I.datalen == 0 || swap->alicepayment.I.spendlen == 0 ) { printf("error alice generating payment.%d\n",swap->alicepayment.I.spendlen); sleep(DEX_SLEEP); @@ -2242,7 +2304,7 @@ void basilisk_swaploop(void *_swap) printf("%02x",swap->myfee.txbytes[i]); printf(" fee %p %x\n",swap->myfee.txbytes,swap->I.statebits); swap->I.statebits |= 0x40; - if ( swap->alicepayment.txbytes != 0 && swap->alicepayment.I.spendlen > 0 ) + if ( swap->alicepayment.I.datalen != 0 && swap->alicepayment.I.spendlen > 0 ) break; } else @@ -2257,15 +2319,14 @@ void basilisk_swaploop(void *_swap) sleep(DEX_SLEEP); basilisk_sendstate(myinfo,swap,data,maxlen); basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); + basilisk_swap_saveupdate(myinfo,swap); if ( time(NULL) > swap->I.expiration ) break; - //dpow_nanomsg_update(myinfo); - //dex_updateclient(myinfo); } - printf("end of atomic swap\n"); - if ( swap->I.iambob != 0 && swap->bobdeposit.txbytes != 0 ) + if ( swap->I.iambob != 0 && swap->bobdeposit.I.datalen != 0 ) { - sleep(300); // wait for confirm of msig + printf("BOB waiting for confirm\n"); + sleep(60); // wait for confirm/propagation of msig printf("BOB reclaims refund\n"); basilisk_bobdeposit_refund(myinfo,swap,0); if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobrefund,0x40000000,0) == 0 ) // use secretBn @@ -2279,7 +2340,9 @@ void basilisk_swaploop(void *_swap) data[datalen++] = swap->I.privBn.bytes[j]; basilisk_swapsend(myinfo,swap,0x40000000,data,datalen,0x40000000,swap->I.crcs_mypriv); } + basilisk_swap_saveupdate(myinfo,swap); } + printf("end of atomic swap\n"); if ( swapcompleted(myinfo,swap) > 0 ) // only if swap completed { if ( swap->I.iambob != 0 ) @@ -2334,8 +2397,6 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,bits256 while ( statebits == 0 && m <= n/2 && time(NULL) < starttime+BASILISK_MSGDURATION ) { m = n = 0; - //dpow_nanomsg_update(myinfo); - //dex_updateclient(myinfo); sleep(DEX_SLEEP); printf("waiting for offer to be accepted\n"); channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); diff --git a/basilisk/basilisk_tradebot.c b/basilisk/basilisk_tradebot.c index 8b66ee5a8..5d16548dc 100755 --- a/basilisk/basilisk_tradebot.c +++ b/basilisk/basilisk_tradebot.c @@ -69,12 +69,12 @@ int32_t basilisk_txitem(struct supernet_info *myinfo,struct basilisk_swap *swap, decode_hex((void *)&rawtx->I,sizeof(rawtx->I),hexstr); if ( (hexstr= jstr(obj,"txbytes")) != 0 && strlen(hexstr) == rawtx->I.datalen*2 ) { - if ( rawtx->txbytes == 0 ) + /*if ( rawtx->txbytes == 0 ) { printf("free (%s) txbytes\n",name); free(rawtx->txbytes); } - rawtx->txbytes = calloc(1,rawtx->I.datalen); + rawtx->txbytes = calloc(1,rawtx->I.datalen);*/ decode_hex((void *)rawtx->txbytes,rawtx->I.datalen,hexstr); } printf("PROCESS.(%s)\n",jprint(obj,0)); diff --git a/basilisk/tradebots_liquidity.c b/basilisk/tradebots_liquidity.c index 3c4a9075f..7e21127aa 100755 --- a/basilisk/tradebots_liquidity.c +++ b/basilisk/tradebots_liquidity.c @@ -110,7 +110,7 @@ int32_t tradebots_calcrawfeatures(struct tradebot_arbpair *pair) } if ( n > sizeof(pair->rawfeatures)/sizeof(*pair->rawfeatures) ) { - printf("n.%d too many for rawfeatures %ld\n",n,sizeof(pair->rawfeatures)/sizeof(*pair->rawfeatures)); + printf("n.%d too many for rawfeatures %d\n",n,(int32_t)(sizeof(pair->rawfeatures)/sizeof(*pair->rawfeatures))); exit(-1); } return(n); @@ -160,7 +160,7 @@ struct tradebot_arbpair *tradebots_arbpair_create(char *base,char *rel) pair->fp = OS_appendfile(fname); if ( (ftell(pair->fp) % sizeof(pair->rawfeatures)) != 0 ) { - printf("misalinged rawfeatures %ld %ld\n",ftell(pair->fp),(ftell(pair->fp) % sizeof(pair->rawfeatures))); + printf("misalinged rawfeatures %d %d\n",(uint32_t)ftell(pair->fp),(uint32_t)(ftell(pair->fp) % sizeof(pair->rawfeatures))); } fseek(pair->fp,(ftell(pair->fp) / sizeof(pair->rawfeatures)) * sizeof(pair->rawfeatures) - sizeof(pair->rawfeatures),SEEK_SET); if ( fread(pair->rawfeatures,1,sizeof(pair->rawfeatures),pair->fp) == sizeof(pair->rawfeatures) ) diff --git a/crypto777/curve25519.c b/crypto777/curve25519.c index 5d2c24930..264d59952 100755 --- a/crypto777/curve25519.c +++ b/crypto777/curve25519.c @@ -1792,7 +1792,7 @@ void acct777_rwsig(int32_t rwflag,uint8_t *serialized,struct acct777_sig *sig) int32_t acct777_sigcheck(struct acct777_sig *sig) { #define IGUANA_GENESIS 1453075200 -#define IGUANA_MAXPACKETSIZE (1024 * 1024 * 2) +#define IGUANA_MAXPACKETSIZE (1024 * 1024 * 4) #define TEN_YEARS (10 * 365 * 24 * 3600) if ( sig->allocsize < sizeof(*sig) || sig->allocsize > IGUANA_MAXPACKETSIZE ) { diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 0bd18acf1..cadc11faa 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -256,7 +256,7 @@ void dpow_psockloop(void *_ptr) ptr->lasttime = now; if ( (sentbytes= nn_send(ptr->pubsock,buf,size,0)) > 0 ) { - printf("PSOCKS[%d] of %d (%u %u) -> %d/%d bytes\n",i,myinfo->numpsocks,ptr->pushport,ptr->subport,size,sentbytes); + //printf("PSOCKS[%d] of %d (%u %u) -> %d/%d bytes\n",i,myinfo->numpsocks,ptr->pushport,ptr->subport,size,sentbytes); nonz++; } } diff --git a/iguana/iguana777.h b/iguana/iguana777.h index d39f498b5..682d3da13 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -21,13 +21,17 @@ #define iguana777_net_h #if defined(_WIN32) || defined(_WIN64) +#ifndef WIN32 #define WIN32 #endif +#endif #if (defined(_WIN32) || defined(__WIN32__)) && \ !defined(WIN32) && !defined(__SYMBIAN32__) +#ifndef WIN32 #define WIN32 #endif +#endif #ifdef WIN32 #define __MINGW diff --git a/iguana/iguana_json.c b/iguana/iguana_json.c index 38c6c5b98..8002aa331 100755 --- a/iguana/iguana_json.c +++ b/iguana/iguana_json.c @@ -86,6 +86,7 @@ cJSON *SuperNET_helpjson() cJSON *array=0,*json,*agents; json = cJSON_CreateObject(); agents = cJSON_CreateArray(); +#ifndef WIN32 #define IGUANA_ARGS json,array,agents #define IGUANA_HELP0(agent,name) array = helpjson(IGUANA_ARGS,#agent,#name,0) #define IGUANA_HELP_S(agent,name,str) array = helpjson(IGUANA_ARGS,#agent,#name,helparray(cJSON_CreateArray(),helpitem(#str,"string"))) @@ -194,7 +195,8 @@ cJSON *SuperNET_helpjson() #undef IGUANA_ARGS #undef _IGUANA_APIDEC_H_ #include "../includes/iguana_apiundefs.h" - +#endif + if ( array != 0 ) jadd(json,"API",array); jadd(json,"agents",agents); @@ -496,423 +498,6 @@ char *SuperNET_htmlstr(char *fname,char *htmlstr,int32_t maxsize,char *agentstr) return(OS_filestr(&filesize,"index7778.html")); } -cJSON *iguana_peerjson(struct iguana_info *coin,struct iguana_peer *addr) -{ - cJSON *array,*json = cJSON_CreateObject(); - jaddstr(json,"ipaddr",addr->ipaddr); - if ( addr->supernet != 0 ) - jaddstr(json,"ipaddr",addr->ipaddr); - jaddstr(json,"supernet","yes"); - jaddnum(json,"protover",addr->protover); - jaddnum(json,"relay",addr->relayflag); - jaddnum(json,"height",addr->height); - jaddnum(json,"rank",addr->rank); - jaddnum(json,"usock",addr->usock); - if ( addr->dead != 0 ) - jaddnum(json,"dead",addr->dead); - jaddnum(json,"ready",addr->ready); - jaddnum(json,"recvblocks",addr->recvblocks); - jaddnum(json,"recvtotal",addr->recvtotal); - jaddnum(json,"lastcontact",addr->lastcontact); - if ( addr->numpings > 0 ) - jaddnum(json,"aveping",addr->pingsum/addr->numpings); - array = cJSON_CreateObject(); - jaddnum(array,"version",addr->msgcounts.version); - jaddnum(array,"verack",addr->msgcounts.verack); - jaddnum(array,"getaddr",addr->msgcounts.getaddr); - jaddnum(array,"addr",addr->msgcounts.addr); - jaddnum(array,"inv",addr->msgcounts.inv); - jaddnum(array,"getdata",addr->msgcounts.getdata); - jaddnum(array,"notfound",addr->msgcounts.notfound); - jaddnum(array,"getblocks",addr->msgcounts.getblocks); - jaddnum(array,"getheaders",addr->msgcounts.getheaders); - jaddnum(array,"headers",addr->msgcounts.headers); - jaddnum(array,"tx",addr->msgcounts.tx); - jaddnum(array,"block",addr->msgcounts.block); - jaddnum(array,"mempool",addr->msgcounts.mempool); - jaddnum(array,"ping",addr->msgcounts.ping); - jaddnum(array,"pong",addr->msgcounts.pong); - jaddnum(array,"reject",addr->msgcounts.reject); - jaddnum(array,"filterload",addr->msgcounts.filterload); - jaddnum(array,"filteradd",addr->msgcounts.filteradd); - jaddnum(array,"filterclear",addr->msgcounts.filterclear); - jaddnum(array,"merkleblock",addr->msgcounts.merkleblock); - jaddnum(array,"alert",addr->msgcounts.alert); - jadd(json,"msgcounts",array); - return(json); -} - -cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly) -{ - cJSON *retjson,*array; int32_t i; struct iguana_peer *addr; - if ( coin == 0 || coin->peers == 0 ) - return(0); - array = cJSON_CreateArray(); - for (i=0; iMAXPEERS; i++) - { - addr = &coin->peers->active[i]; - if ( addr->usock >= 0 && addr->ipbits != 0 && addr->ipaddr[0] != 0 ) - { - if ( addronly != 0 ) - jaddistr(array,addr->ipaddr); - else jaddi(array,iguana_peerjson(coin,addr)); - } - } - if ( addronly == 0 ) - { - retjson = cJSON_CreateObject(); - jadd(retjson,"peers",array); - jaddnum(retjson,"maxpeers",coin->MAXPEERS); - jaddstr(retjson,"coin",coin->symbol); - return(retjson); - } - else return(array); -} - -#include "../includes/iguana_apidefs.h" -#include "../includes/iguana_apideclares.h" - -STRING_ARG(iguana,peers,activecoin) -{ - if ( coin != 0 ) - return(jprint(iguana_peersjson(coin,0),1)); - else return(clonestr("{\"error\":\"peers needs coin\"}")); -} - -STRING_ARG(iguana,getconnectioncount,activecoin) -{ - int32_t i,num = 0; char buf[512]; - if ( coin != 0 && coin->peers != 0 ) - { - for (i=0; ipeers->active)/sizeof(*coin->peers->active); i++) - if ( coin->peers->active[i].usock >= 0 ) - num++; - sprintf(buf,"{\"result\":\"%d\"}",num); - return(clonestr(buf)); - } else return(clonestr("{\"error\":\"getconnectioncount needs coin\"}")); -} - -ZERO_ARGS(bitcoinrpc,getdifficulty) -{ - char buf[512]; - if ( coin != 0 ) - { - sprintf(buf,"{\"result\":\"success\",\"proof-of-work\":\"%.8f\",\"search-interval\": 0}",PoW_from_compact(coin->blocks.hwmchain.RO.bits,coin->chain->unitval)); - return(clonestr(buf)); - } else return(clonestr("{\"error\":\"getdifficulty needs coin\"}")); -} - -STRING_ARG(iguana,addcoin,newcoin) -{ - char *symbol,*seedip; int32_t retval; - if ( (symbol= newcoin) == 0 && coin != 0 ) - symbol = coin->symbol; - if ( symbol != 0 ) - { - if ( (seedip= jstr(json,"seedipaddr")) != 0 ) - safecopy(myinfo->seedipaddr,seedip,sizeof(myinfo->seedipaddr)); - printf(">> addcoin.%s seedipaddr.%s\n",symbol,myinfo->seedipaddr); -#ifdef __PNACL__ -// if ( strcmp(symbol,"BTC") == 0 ) -// return(clonestr("{\"result\":\"BTC for chrome app is not yet\"}")); -#endif - if ( (retval= iguana_launchcoin(myinfo,symbol,json,0)) > 0 ) - { - if ( myinfo->rpcsymbol[0] == 0 ) - safecopy(myinfo->rpcsymbol,symbol,sizeof(myinfo->rpcsymbol)); - return(clonestr("{\"result\":\"coin added\"}")); - } - else if ( retval == 0 ) - return(clonestr("{\"result\":\"coin already there\"}")); - else return(clonestr("{\"error\":\"error adding coin\"}")); - } else return(clonestr("{\"error\":\"addcoin needs newcoin\"}")); -} - -STRING_ARG(iguana,startcoin,activecoin) -{ - if ( coin != 0 ) - { - coin->active = 1; - return(clonestr("{\"result\":\"coin started\"}")); - } else return(clonestr("{\"error\":\"startcoin needs coin\"}")); -} - -STRING_ARG(iguana,stopcoin,activecoin) -{ - if ( activecoin[0] != 0 ) - coin = iguana_coinfind(activecoin); - if ( coin != 0 ) - { - coin->active = 0; - //iguana_coinpurge(coin); - return(clonestr("{\"result\":\"coin stopped\"}")); - } else return(clonestr("{\"error\":\"stopcoin needs coin\"}")); -} - -STRING_ARG(iguana,pausecoin,activecoin) -{ - if ( coin != 0 ) - { - coin->active = 0; - return(clonestr("{\"result\":\"coin paused\"}")); - } else return(clonestr("{\"error\":\"pausecoin needs coin\"}")); -} - -TWO_STRINGS(iguana,addnode,activecoin,ipaddr) -{ - struct iguana_peer *addr; int32_t i,n; - if ( coin == 0 ) - coin = iguana_coinfind(activecoin); - if ( coin != 0 && strcmp(coin->symbol,"RELAY") == 0 ) - basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(ipaddr),GENESIS_PUBKEY); - printf("coin.%p.[%s] addnode.%s -> %s\n",coin,coin!=0?coin->symbol:"",activecoin,ipaddr); - if ( coin != 0 && coin->peers != 0 && ipaddr != 0 && is_ipaddr(ipaddr) != 0 ) - { - //iguana_possible_peer(coin,ipaddr); - if ( (addr= iguana_peerslot(coin,(uint32_t)calc_ipbits(ipaddr),1)) != 0 ) - { - addr->supernet = 1; - if ( addr->usock >= 0 ) - { - if ( (n= coin->peers->numranked) != 0 ) - { - for (i=0; ipeers->ranked[i] ) - break; - } - if ( i == n ) - { - if ( i == IGUANA_MAXPEERS ) - i--; - else coin->peers->numranked = n+1; - coin->peers->ranked[i] = addr; - addr->recvblocks = coin->peers->ranked[0]->recvblocks + 100; - addr->recvtotal = coin->peers->ranked[0]->recvtotal*1.1 + 100; - printf("set (%s) -> slot.%d numranked.%d\n",ipaddr,i,coin->peers->numranked); - } else printf("(%s) is already peer.%d\n",ipaddr,i); - } - return(clonestr("{\"result\":\"peer was already connected\"}")); - } - if ( addr->pending == 0 ) - { - addr->pending = (uint32_t)time(NULL); - iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); - return(clonestr("{\"result\":\"addnode submitted\"}")); - } else return(clonestr("{\"result\":\"addnode connection was already pending\"}")); - } else return(clonestr("{\"result\":\"addnode cant find peer slot\"}")); - } - else if ( coin == 0 ) - return(clonestr("{\"error\":\"addnode needs active coin, do an addcoin first\"}")); - else return(clonestr("{\"error\":\"addnode needs ipaddr\"}")); -} - -TWO_STRINGS(iguana,persistent,activecoin,ipaddr) -{ - int32_t i; - if ( coin != 0 && coin->peers != 0 && ipaddr != 0 ) - { - for (i=0; ipeers->active[i].ipaddr,ipaddr) == 0 ) - { - coin->peers->active[i].persistent_peer = juint(json,"interval")+3; - return(clonestr("{\"result\":\"node marked as persistent\"}")); - } - } - return(clonestr("{\"result\":\"node wasnt active\"}")); - } else return(clonestr("{\"error\":\"persistent needs coin and ipaddr\"}")); -} - -TWO_STRINGS(iguana,removenode,activecoin,ipaddr) -{ - int32_t i; - if ( coin != 0 && coin->peers != 0 && ipaddr != 0 ) - { - for (i=0; ipeers->active[i].ipaddr,ipaddr) == 0 ) - { - coin->peers->active[i].rank = 0; - coin->peers->active[i].dead = (uint32_t)time(NULL); - return(clonestr("{\"result\":\"node marked as dead\"}")); - } - } - return(clonestr("{\"result\":\"node wasnt active\"}")); - } else return(clonestr("{\"error\":\"removenode needs coin and ipaddr\"}")); -} - -TWO_STRINGS(iguana,oneshot,activecoin,ipaddr) -{ - if ( coin != 0 && ipaddr != 0 ) - { - iguana_possible_peer(coin,ipaddr); - return(clonestr("{\"result\":\"addnode submitted\"}")); - } else return(clonestr("{\"error\":\"addnode needs coin and ipaddr\"}")); -} - -TWO_STRINGS(iguana,nodestatus,activecoin,ipaddr) -{ - int32_t i; struct iguana_peer *addr; - if ( coin != 0 && coin->peers != 0 && ipaddr != 0 ) - { - for (i=0; iMAXPEERS; i++) - { - addr = &coin->peers->active[i]; - if ( strcmp(addr->ipaddr,ipaddr) == 0 ) - return(jprint(iguana_peerjson(coin,addr),1)); - } - return(clonestr("{\"result\":\"nodestatus couldnt find ipaddr\"}")); - } else return(clonestr("{\"error\":\"nodestatus needs ipaddr\"}")); -} - -STRING_AND_INT(iguana,maxpeers,activecoin,max) -{ - cJSON *retjson; int32_t i; struct iguana_peer *addr; - if ( coin != 0 && coin->peers != 0 ) - { - retjson = cJSON_CreateObject(); - if ( max > IGUANA_MAXPEERS ) - max = IGUANA_MAXPEERS; - if ( max > coin->MAXPEERS ) - { - for (i=max; iMAXPEERS; i++) - if ( (addr= coin->peers->ranked[i]) != 0 ) - addr->dead = 1; - } - coin->MAXPEERS = max; - jaddnum(retjson,"maxpeers",coin->MAXPEERS); - jaddstr(retjson,"coin",coin->symbol); - return(jprint(retjson,1)); - } else return(clonestr("{\"error\":\"maxpeers needs coin\"}")); -} - -char *hmac_dispatch(char *(*hmacfunc)(char *dest,char *key,int32_t key_size,char *message),char *name,char *message,char *password) -{ - char hexstr[1025]; cJSON *json; - if ( message != 0 && password != 0 && message[0] != 0 && password[0] != 0 ) - { - memset(hexstr,0,sizeof(hexstr)); - (*hmacfunc)(hexstr,password,password==0?0:(int32_t)strlen(password),message); - json = cJSON_CreateObject(); - jaddstr(json,"result","hmac calculated"); - jaddstr(json,"message",message); - jaddstr(json,name,hexstr); - return(jprint(json,1)); - } else return(clonestr("{\"error\":\"hmac needs message and passphrase\"}")); -} - -char *hash_dispatch(void (*hashfunc)(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len),char *name,char *message) -{ - char hexstr[65537]; uint8_t databuf[32768]; cJSON *json; - if ( message != 0 && message[0] != 0 ) - { - memset(hexstr,0,sizeof(hexstr)); - (*hashfunc)(hexstr,databuf,(uint8_t *)message,(int32_t)strlen(message)); - json = cJSON_CreateObject(); - jaddstr(json,"result","hash calculated"); - jaddstr(json,"message",message); - jaddstr(json,name,hexstr); - return(jprint(json,1)); - } else return(clonestr("{\"error\":\"hash needs message\"}")); -} - -TWO_HASHES(hash,curve25519_pair,element,scalar) -{ - cJSON *retjson = cJSON_CreateObject(); - jaddbits256(retjson,"result",curve25519(element,scalar)); - return(jprint(retjson,1)); -} - -STRING_ARG(hash,NXT,passphrase) { return(hash_dispatch(calc_NXTaddr,"NXT",passphrase)); } -STRING_ARG(hash,curve25519,pubkey) { return(hash_dispatch(calc_curve25519_str,"curve25519",pubkey)); } -STRING_ARG(hash,crc32,message) { return(hash_dispatch(calc_crc32str,"crc32",message)); } -STRING_ARG(hash,base64_encode,message) { return(hash_dispatch(calc_base64_encodestr,"base64_encode",message)); } -STRING_ARG(hash,base64_decode,message) { return(hash_dispatch(calc_base64_decodestr,"base64_decode",message)); } -STRING_ARG(hash,rmd160_sha256,message) { return(hash_dispatch(rmd160ofsha256,"rmd160_sha256",message)); } -STRING_ARG(hash,sha256_sha256,message) { return(hash_dispatch(sha256_sha256,"sha256_sha256",message)); } -STRING_ARG(hash,hex,message) { return(hash_dispatch(calc_hexstr,"hex",message)); } -STRING_ARG(hash,unhex,message) { return(hash_dispatch(calc_unhexstr,"unhex",message)); } - -STRING_ARG(hash,sha224,message) { return(hash_dispatch(calc_sha224,"sha224",message)); } -STRING_ARG(hash,sha256,message) { return(hash_dispatch(vcalc_sha256,"sha256",message)); } -STRING_ARG(hash,sha384,message) { return(hash_dispatch(calc_sha384,"sha384",message)); } -STRING_ARG(hash,sha512,message) { return(hash_dispatch(calc_sha512,"sha512",message)); } -STRING_ARG(hash,rmd128,message) { return(hash_dispatch(calc_rmd128,"rmd128",message)); } -STRING_ARG(hash,rmd160,message) { return(hash_dispatch(calc_rmd160,"rmd160",message)); } -STRING_ARG(hash,rmd256,message) { return(hash_dispatch(calc_rmd256,"rmd256",message)); } -STRING_ARG(hash,rmd320,message) { return(hash_dispatch(calc_rmd320,"rmd320",message)); } -STRING_ARG(hash,sha1,message) { return(hash_dispatch(calc_sha1,"sha1",message)); } -STRING_ARG(hash,md2,message) { return(hash_dispatch(calc_md2str,"md2",message)); } -STRING_ARG(hash,md4,message) { return(hash_dispatch(calc_md4str,"md4",message)); } -STRING_ARG(hash,md5,message) { return(hash_dispatch(calc_md5str,"md5",message)); } -STRING_ARG(hash,tiger192_3,message) { return(hash_dispatch(calc_tiger,"tiger",message)); } -STRING_ARG(hash,whirlpool,message) { return(hash_dispatch(calc_whirlpool,"whirlpool",message)); } -TWO_STRINGS(hmac,sha224,message,passphrase) { return(hmac_dispatch(hmac_sha224_str,"sha224",message,passphrase)); } -TWO_STRINGS(hmac,sha256,message,passphrase) { return(hmac_dispatch(hmac_sha256_str,"sha256",message,passphrase)); } -TWO_STRINGS(hmac,sha384,message,passphrase) { return(hmac_dispatch(hmac_sha384_str,"sha384",message,passphrase)); } -TWO_STRINGS(hmac,sha512,message,passphrase) { return(hmac_dispatch(hmac_sha512_str,"sha512",message,passphrase)); } -TWO_STRINGS(hmac,rmd128,message,passphrase) { return(hmac_dispatch(hmac_rmd128_str,"rmd128",message,passphrase)); } -TWO_STRINGS(hmac,rmd160,message,passphrase) { return(hmac_dispatch(hmac_rmd160_str,"rmd160",message,passphrase)); } -TWO_STRINGS(hmac,rmd256,message,passphrase) { return(hmac_dispatch(hmac_rmd256_str,"rmd256",message,passphrase)); } -TWO_STRINGS(hmac,rmd320,message,passphrase) { return(hmac_dispatch(hmac_rmd320_str,"rmd320",message,passphrase)); } -TWO_STRINGS(hmac,sha1,message,passphrase) { return(hmac_dispatch(hmac_sha1_str,"sha1",message,passphrase)); } -TWO_STRINGS(hmac,md2,message,passphrase) { return(hmac_dispatch(hmac_md2_str,"md2",message,passphrase)); } -TWO_STRINGS(hmac,md4,message,passphrase) { return(hmac_dispatch(hmac_md4_str,"md4",message,passphrase)); } -TWO_STRINGS(hmac,md5,message,passphrase) { return(hmac_dispatch(hmac_md5_str,"md5",message,passphrase)); } -TWO_STRINGS(hmac,tiger192_3,message,passphrase) { return(hmac_dispatch(hmac_tiger_str,"tiger",message,passphrase)); } -TWO_STRINGS(hmac,whirlpool,message,passphrase) { return(hmac_dispatch(hmac_whirlpool_str,"whirlpool",message,passphrase)); } - -STRING_ARG(SuperNET,bitcoinrpc,setcoin) -{ - char buf[1024]; - if ( setcoin != 0 && setcoin[0] != 0 ) - { - strcpy(myinfo->rpcsymbol,setcoin); - touppercase(myinfo->rpcsymbol); - printf("bitcoinrpc.%s\n",myinfo->rpcsymbol); - if ( iguana_launchcoin(myinfo,myinfo->rpcsymbol,json,0) < 0 ) - return(clonestr("{\"error\":\"error creating coin\"}")); - else - { - sprintf(buf,"{\"result\":\"success\",\"setcoin\":\"%s\"}",setcoin); - return(clonestr(buf)); - } - } else return(clonestr("{\"error\":\"bitcoinrpc needs setcoin value\"}")); -} - -ZERO_ARGS(SuperNET,help) -{ - cJSON *helpjson,*retjson; - if ( (helpjson= SuperNET_helpjson()) != 0 ) - { - retjson = cJSON_CreateObject(); - jadd(retjson,"result",helpjson); - return(jprint(retjson,1)); - } else return(clonestr("{\"error\":\"cant get helpjson\"}")); -} - -TWO_STRINGS(SuperNET,html,agentform,htmlfile) -{ - char *htmlstr; cJSON *retjson; int32_t max = 4*1024*1024; - if ( htmlfile == 0 || htmlfile[0] == 0 ) - htmlfile = "forms.html"; - //if ( (fp= fopen(htmlfile,"w")) == 0 ) - // printf("error opening htmlfile.(%s)\n",htmlfile); - htmlstr = malloc(max); - htmlstr = SuperNET_htmlstr(htmlfile,htmlstr,max,agentform); - retjson = cJSON_CreateObject(); - jaddstr(retjson,"result",htmlstr); - free(htmlstr); - //if ( fp != 0 ) - // fclose(fp); - return(jprint(retjson,1)); -} - -#undef IGUANA_ARGS -#undef _IGUANA_APIDEC_H_ -#include "../includes/iguana_apiundefs.h" - char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,cJSON *json,char *remoteaddr) { char *coinstr; struct iguana_info *coin = 0; diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index 8e7aacf20..196c3a313 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -175,7 +175,7 @@ int32_t iguana_RTbestunspent(struct supernet_info *myinfo,struct iguana_info *co } if ( iguana_RTunspent_check(myinfo,coin,unspents[i]) != 0 ) { - printf("(%d u%d) %.8f already used\n",unspents[i].hdrsi,unspents[i].unspentind,dstr(atx_value)); + //printf("(%d u%d) %.8f already used\n",unspents[i].hdrsi,unspents[i].unspentind,dstr(atx_value)); continue; } if ( maxmode == 0 ) @@ -289,7 +289,7 @@ char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,int if ( flag != 0 ) free_json(privkeys); } - char str[65]; printf("completed.%d %s signed.(%s)\n",*completedp,bits256_str(str,*signedtxidp),signedtx!=0?signedtx:""); + //char str[65]; printf("completed.%d %s signed.(%s)\n",*completedp,bits256_str(str,*signedtxidp),signedtx!=0?signedtx:""); return(signedtx); } diff --git a/iguana/iguana_sign.c b/iguana/iguana_sign.c index c502e1465..43afba477 100755 --- a/iguana/iguana_sign.c +++ b/iguana/iguana_sign.c @@ -687,7 +687,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ { iguana_vinobjset(&msg->vins[i],jitem(vins,i),spendscript,sizeof(spendscript)); sigtxid = bitcoin_sigtxid(coin,height,sigser,maxsize*2,msg,i,msg->vins[i].spendscript,msg->vins[i].spendlen,SIGHASH_ALL,vpnstr,suppress_pubkeys); - printf("after vini.%d vinscript.%p spendscript.%p spendlen.%d (%s)\n",i,msg->vins[i].vinscript,msg->vins[i].spendscript,msg->vins[i].spendlen,jprint(jitem(vins,i),0)); + //printf("after vini.%d vinscript.%p spendscript.%p spendlen.%d (%s)\n",i,msg->vins[i].vinscript,msg->vins[i].spendscript,msg->vins[i].spendlen,jprint(jitem(vins,i),0)); jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid)); if ( msg->vins[i].spendscript == spendscript ) msg->vins[i].spendscript = 0; @@ -1013,13 +1013,13 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *sign { flag++; numsigs++; - int32_t z; + /*int32_t z; for (z=0; zsigners[j].pubkey[z]); - printf(" <- pub, SIG.%d.%d VERIFIED numsigs.%d vs M.%d\n",vini,j,numsigs,vp->M); + printf(" <- pub, SIG.%d.%d VERIFIED numsigs.%d vs M.%d\n",vini,j,numsigs,vp->M);*/ } } if ( numsigs >= vp->M ) @@ -1435,7 +1435,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf } } } - printf("type.%d p2sh.[%d] -> %s M.%d N.%d\n",type,i,mvin.coinaddr,mvin.M,mvin.N); + //printf("type.%d p2sh.[%d] -> %s M.%d N.%d\n",type,i,mvin.coinaddr,mvin.M,mvin.N); } } if ( i < V->N ) diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 19db61d54..773f6f431 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -913,7 +913,7 @@ void iguana_unspents_mark(struct supernet_info *myinfo,struct iguana_info *coin, { if ( firstslot >= 0 ) { - printf("slot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,txid),vout); + //printf("slot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,txid),vout); coin->markedunspents[firstslot] = txid; coin->markedunspents[firstslot].ushorts[15] = vout; if ( (0) && coin->utxofp == 0 ) @@ -949,7 +949,7 @@ return; { if ( firstslot >= 0 ) { - char str[65]; printf("%s slot.[%d] <- %s/v%d\n",fname,firstslot,bits256_str(str,filetxid),filevout); + //char str[65]; printf("%s slot.[%d] <- %s/v%d\n",fname,firstslot,bits256_str(str,filetxid),filevout); coin->markedunspents[firstslot] = filetxid; coin->markedunspents[firstslot].ushorts[15] = filevout; } @@ -975,7 +975,7 @@ return; { if ( firstslot >= 0 ) { - char str[65]; printf("slot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,filetxid),filevout); + //char str[65]; printf("slot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,filetxid),filevout); coin->markedunspents[firstslot] = filetxid; coin->markedunspents[firstslot].ushorts[15] = filevout; } diff --git a/iguana/ramchain_api.c b/iguana/ramchain_api.c index 9c5c4cd2b..267f17ffd 100755 --- a/iguana/ramchain_api.c +++ b/iguana/ramchain_api.c @@ -14,3 +14,423 @@ ******************************************************************************/ // deprecated +#include "iguana777.h" + +#include "../includes/iguana_apidefs.h" +#include "../includes/iguana_apideclares.h" + + +STRING_ARG(iguana,peers,activecoin) +{ + if ( coin != 0 ) + return(jprint(iguana_peersjson(coin,0),1)); + else return(clonestr("{\"error\":\"peers needs coin\"}")); +} + +STRING_ARG(iguana,getconnectioncount,activecoin) +{ + int32_t i,num = 0; char buf[512]; + if ( coin != 0 && coin->peers != 0 ) + { + for (i=0; ipeers->active)/sizeof(*coin->peers->active); i++) + if ( coin->peers->active[i].usock >= 0 ) + num++; + sprintf(buf,"{\"result\":\"%d\"}",num); + return(clonestr(buf)); + } else return(clonestr("{\"error\":\"getconnectioncount needs coin\"}")); +} + +ZERO_ARGS(bitcoinrpc,getdifficulty) +{ + char buf[512]; + if ( coin != 0 ) + { + sprintf(buf,"{\"result\":\"success\",\"proof-of-work\":\"%.8f\",\"search-interval\": 0}",PoW_from_compact(coin->blocks.hwmchain.RO.bits,coin->chain->unitval)); + return(clonestr(buf)); + } else return(clonestr("{\"error\":\"getdifficulty needs coin\"}")); +} + +STRING_ARG(iguana,addcoin,newcoin) +{ + char *symbol,*seedip; int32_t retval; + if ( (symbol= newcoin) == 0 && coin != 0 ) + symbol = coin->symbol; + if ( symbol != 0 ) + { + if ( (seedip= jstr(json,"seedipaddr")) != 0 ) + safecopy(myinfo->seedipaddr,seedip,sizeof(myinfo->seedipaddr)); + printf(">> addcoin.%s seedipaddr.%s\n",symbol,myinfo->seedipaddr); +#ifdef __PNACL__ + // if ( strcmp(symbol,"BTC") == 0 ) + // return(clonestr("{\"result\":\"BTC for chrome app is not yet\"}")); +#endif + if ( (retval= iguana_launchcoin(myinfo,symbol,json,0)) > 0 ) + { + if ( myinfo->rpcsymbol[0] == 0 ) + safecopy(myinfo->rpcsymbol,symbol,sizeof(myinfo->rpcsymbol)); + return(clonestr("{\"result\":\"coin added\"}")); + } + else if ( retval == 0 ) + return(clonestr("{\"result\":\"coin already there\"}")); + else return(clonestr("{\"error\":\"error adding coin\"}")); + } else return(clonestr("{\"error\":\"addcoin needs newcoin\"}")); +} + +STRING_ARG(iguana,startcoin,activecoin) +{ + if ( coin != 0 ) + { + coin->active = 1; + return(clonestr("{\"result\":\"coin started\"}")); + } else return(clonestr("{\"error\":\"startcoin needs coin\"}")); +} + +STRING_ARG(iguana,stopcoin,activecoin) +{ + if ( activecoin[0] != 0 ) + coin = iguana_coinfind(activecoin); + if ( coin != 0 ) + { + coin->active = 0; + //iguana_coinpurge(coin); + return(clonestr("{\"result\":\"coin stopped\"}")); + } else return(clonestr("{\"error\":\"stopcoin needs coin\"}")); +} + +STRING_ARG(iguana,pausecoin,activecoin) +{ + if ( coin != 0 ) + { + coin->active = 0; + return(clonestr("{\"result\":\"coin paused\"}")); + } else return(clonestr("{\"error\":\"pausecoin needs coin\"}")); +} + +TWO_STRINGS(iguana,addnode,activecoin,ipaddr) +{ + struct iguana_peer *addr; int32_t i,n; + if ( coin == 0 ) + coin = iguana_coinfind(activecoin); + if ( coin != 0 && strcmp(coin->symbol,"RELAY") == 0 ) + basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(ipaddr),GENESIS_PUBKEY); + printf("coin.%p.[%s] addnode.%s -> %s\n",coin,coin!=0?coin->symbol:"",activecoin,ipaddr); + if ( coin != 0 && coin->peers != 0 && ipaddr != 0 && is_ipaddr(ipaddr) != 0 ) + { + //iguana_possible_peer(coin,ipaddr); + if ( (addr= iguana_peerslot(coin,(uint32_t)calc_ipbits(ipaddr),1)) != 0 ) + { + addr->supernet = 1; + if ( addr->usock >= 0 ) + { + if ( (n= coin->peers->numranked) != 0 ) + { + for (i=0; ipeers->ranked[i] ) + break; + } + if ( i == n ) + { + if ( i == IGUANA_MAXPEERS ) + i--; + else coin->peers->numranked = n+1; + coin->peers->ranked[i] = addr; + addr->recvblocks = coin->peers->ranked[0]->recvblocks + 100; + addr->recvtotal = coin->peers->ranked[0]->recvtotal*1.1 + 100; + printf("set (%s) -> slot.%d numranked.%d\n",ipaddr,i,coin->peers->numranked); + } else printf("(%s) is already peer.%d\n",ipaddr,i); + } + return(clonestr("{\"result\":\"peer was already connected\"}")); + } + if ( addr->pending == 0 ) + { + addr->pending = (uint32_t)time(NULL); + iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); + return(clonestr("{\"result\":\"addnode submitted\"}")); + } else return(clonestr("{\"result\":\"addnode connection was already pending\"}")); + } else return(clonestr("{\"result\":\"addnode cant find peer slot\"}")); + } + else if ( coin == 0 ) + return(clonestr("{\"error\":\"addnode needs active coin, do an addcoin first\"}")); + else return(clonestr("{\"error\":\"addnode needs ipaddr\"}")); +} + +TWO_STRINGS(iguana,persistent,activecoin,ipaddr) +{ + int32_t i; + if ( coin != 0 && coin->peers != 0 && ipaddr != 0 ) + { + for (i=0; ipeers->active[i].ipaddr,ipaddr) == 0 ) + { + coin->peers->active[i].persistent_peer = juint(json,"interval")+3; + return(clonestr("{\"result\":\"node marked as persistent\"}")); + } + } + return(clonestr("{\"result\":\"node wasnt active\"}")); + } else return(clonestr("{\"error\":\"persistent needs coin and ipaddr\"}")); +} + +TWO_STRINGS(iguana,removenode,activecoin,ipaddr) +{ + int32_t i; + if ( coin != 0 && coin->peers != 0 && ipaddr != 0 ) + { + for (i=0; ipeers->active[i].ipaddr,ipaddr) == 0 ) + { + coin->peers->active[i].rank = 0; + coin->peers->active[i].dead = (uint32_t)time(NULL); + return(clonestr("{\"result\":\"node marked as dead\"}")); + } + } + return(clonestr("{\"result\":\"node wasnt active\"}")); + } else return(clonestr("{\"error\":\"removenode needs coin and ipaddr\"}")); +} + +TWO_STRINGS(iguana,oneshot,activecoin,ipaddr) +{ + if ( coin != 0 && ipaddr != 0 ) + { + iguana_possible_peer(coin,ipaddr); + return(clonestr("{\"result\":\"addnode submitted\"}")); + } else return(clonestr("{\"error\":\"addnode needs coin and ipaddr\"}")); +} + +cJSON *iguana_peerjson(struct iguana_info *coin,struct iguana_peer *addr) +{ + cJSON *array,*json = cJSON_CreateObject(); + jaddstr(json,"ipaddr",addr->ipaddr); + if ( addr->supernet != 0 ) + jaddstr(json,"ipaddr",addr->ipaddr); + jaddstr(json,"supernet","yes"); + jaddnum(json,"protover",addr->protover); + jaddnum(json,"relay",addr->relayflag); + jaddnum(json,"height",addr->height); + jaddnum(json,"rank",addr->rank); + jaddnum(json,"usock",addr->usock); + if ( addr->dead != 0 ) + jaddnum(json,"dead",addr->dead); + jaddnum(json,"ready",addr->ready); + jaddnum(json,"recvblocks",addr->recvblocks); + jaddnum(json,"recvtotal",addr->recvtotal); + jaddnum(json,"lastcontact",addr->lastcontact); + if ( addr->numpings > 0 ) + jaddnum(json,"aveping",addr->pingsum/addr->numpings); + array = cJSON_CreateObject(); + jaddnum(array,"version",addr->msgcounts.version); + jaddnum(array,"verack",addr->msgcounts.verack); + jaddnum(array,"getaddr",addr->msgcounts.getaddr); + jaddnum(array,"addr",addr->msgcounts.addr); + jaddnum(array,"inv",addr->msgcounts.inv); + jaddnum(array,"getdata",addr->msgcounts.getdata); + jaddnum(array,"notfound",addr->msgcounts.notfound); + jaddnum(array,"getblocks",addr->msgcounts.getblocks); + jaddnum(array,"getheaders",addr->msgcounts.getheaders); + jaddnum(array,"headers",addr->msgcounts.headers); + jaddnum(array,"tx",addr->msgcounts.tx); + jaddnum(array,"block",addr->msgcounts.block); + jaddnum(array,"mempool",addr->msgcounts.mempool); + jaddnum(array,"ping",addr->msgcounts.ping); + jaddnum(array,"pong",addr->msgcounts.pong); + jaddnum(array,"reject",addr->msgcounts.reject); + jaddnum(array,"filterload",addr->msgcounts.filterload); + jaddnum(array,"filteradd",addr->msgcounts.filteradd); + jaddnum(array,"filterclear",addr->msgcounts.filterclear); + jaddnum(array,"merkleblock",addr->msgcounts.merkleblock); + jaddnum(array,"alert",addr->msgcounts.alert); + jadd(json,"msgcounts",array); + return(json); +} + +cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly) +{ + cJSON *retjson,*array; int32_t i; struct iguana_peer *addr; + if ( coin == 0 || coin->peers == 0 ) + return(0); + array = cJSON_CreateArray(); + for (i=0; iMAXPEERS; i++) + { + addr = &coin->peers->active[i]; + if ( addr->usock >= 0 && addr->ipbits != 0 && addr->ipaddr[0] != 0 ) + { + if ( addronly != 0 ) + jaddistr(array,addr->ipaddr); + else jaddi(array,iguana_peerjson(coin,addr)); + } + } + if ( addronly == 0 ) + { + retjson = cJSON_CreateObject(); + jadd(retjson,"peers",array); + jaddnum(retjson,"maxpeers",coin->MAXPEERS); + jaddstr(retjson,"coin",coin->symbol); + return(retjson); + } + else return(array); +} + +TWO_STRINGS(iguana,nodestatus,activecoin,ipaddr) +{ + int32_t i; struct iguana_peer *addr; + if ( coin != 0 && coin->peers != 0 && ipaddr != 0 ) + { + for (i=0; iMAXPEERS; i++) + { + addr = &coin->peers->active[i]; + if ( strcmp(addr->ipaddr,ipaddr) == 0 ) + return(jprint(iguana_peerjson(coin,addr),1)); + } + return(clonestr("{\"result\":\"nodestatus couldnt find ipaddr\"}")); + } else return(clonestr("{\"error\":\"nodestatus needs ipaddr\"}")); +} + +STRING_AND_INT(iguana,maxpeers,activecoin,max) +{ + cJSON *retjson; int32_t i; struct iguana_peer *addr; + if ( coin != 0 && coin->peers != 0 ) + { + retjson = cJSON_CreateObject(); + if ( max > IGUANA_MAXPEERS ) + max = IGUANA_MAXPEERS; + if ( max > coin->MAXPEERS ) + { + for (i=max; iMAXPEERS; i++) + if ( (addr= coin->peers->ranked[i]) != 0 ) + addr->dead = 1; + } + coin->MAXPEERS = max; + jaddnum(retjson,"maxpeers",coin->MAXPEERS); + jaddstr(retjson,"coin",coin->symbol); + return(jprint(retjson,1)); + } else return(clonestr("{\"error\":\"maxpeers needs coin\"}")); +} + +char *hmac_dispatch(char *(*hmacfunc)(char *dest,char *key,int32_t key_size,char *message),char *name,char *message,char *password) +{ + char hexstr[1025]; cJSON *json; + if ( message != 0 && password != 0 && message[0] != 0 && password[0] != 0 ) + { + memset(hexstr,0,sizeof(hexstr)); + (*hmacfunc)(hexstr,password,password==0?0:(int32_t)strlen(password),message); + json = cJSON_CreateObject(); + jaddstr(json,"result","hmac calculated"); + jaddstr(json,"message",message); + jaddstr(json,name,hexstr); + return(jprint(json,1)); + } else return(clonestr("{\"error\":\"hmac needs message and passphrase\"}")); +} + +char *hash_dispatch(void (*hashfunc)(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len),char *name,char *message) +{ + char hexstr[65537]; uint8_t databuf[32768]; cJSON *json; + if ( message != 0 && message[0] != 0 ) + { + memset(hexstr,0,sizeof(hexstr)); + (*hashfunc)(hexstr,databuf,(uint8_t *)message,(int32_t)strlen(message)); + json = cJSON_CreateObject(); + jaddstr(json,"result","hash calculated"); + jaddstr(json,"message",message); + jaddstr(json,name,hexstr); + return(jprint(json,1)); + } else return(clonestr("{\"error\":\"hash needs message\"}")); +} + +TWO_HASHES(hash,curve25519_pair,element,scalar) +{ + cJSON *retjson = cJSON_CreateObject(); + jaddbits256(retjson,"result",curve25519(element,scalar)); + return(jprint(retjson,1)); +} + +STRING_ARG(hash,NXT,passphrase) { return(hash_dispatch(calc_NXTaddr,"NXT",passphrase)); } +STRING_ARG(hash,curve25519,pubkey) { return(hash_dispatch(calc_curve25519_str,"curve25519",pubkey)); } +STRING_ARG(hash,crc32,message) { return(hash_dispatch(calc_crc32str,"crc32",message)); } +STRING_ARG(hash,base64_encode,message) { return(hash_dispatch(calc_base64_encodestr,"base64_encode",message)); } +STRING_ARG(hash,base64_decode,message) { return(hash_dispatch(calc_base64_decodestr,"base64_decode",message)); } +STRING_ARG(hash,rmd160_sha256,message) { return(hash_dispatch(rmd160ofsha256,"rmd160_sha256",message)); } +STRING_ARG(hash,sha256_sha256,message) { return(hash_dispatch(sha256_sha256,"sha256_sha256",message)); } +STRING_ARG(hash,hex,message) { return(hash_dispatch(calc_hexstr,"hex",message)); } +STRING_ARG(hash,unhex,message) { return(hash_dispatch(calc_unhexstr,"unhex",message)); } + +STRING_ARG(hash,sha224,message) { return(hash_dispatch(calc_sha224,"sha224",message)); } +STRING_ARG(hash,sha256,message) { return(hash_dispatch(vcalc_sha256,"sha256",message)); } +STRING_ARG(hash,sha384,message) { return(hash_dispatch(calc_sha384,"sha384",message)); } +STRING_ARG(hash,sha512,message) { return(hash_dispatch(calc_sha512,"sha512",message)); } +STRING_ARG(hash,rmd128,message) { return(hash_dispatch(calc_rmd128,"rmd128",message)); } +STRING_ARG(hash,rmd160,message) { return(hash_dispatch(calc_rmd160,"rmd160",message)); } +STRING_ARG(hash,rmd256,message) { return(hash_dispatch(calc_rmd256,"rmd256",message)); } +STRING_ARG(hash,rmd320,message) { return(hash_dispatch(calc_rmd320,"rmd320",message)); } +STRING_ARG(hash,sha1,message) { return(hash_dispatch(calc_sha1,"sha1",message)); } +STRING_ARG(hash,md2,message) { return(hash_dispatch(calc_md2str,"md2",message)); } +STRING_ARG(hash,md4,message) { return(hash_dispatch(calc_md4str,"md4",message)); } +STRING_ARG(hash,md5,message) { return(hash_dispatch(calc_md5str,"md5",message)); } +STRING_ARG(hash,tiger192_3,message) { return(hash_dispatch(calc_tiger,"tiger",message)); } +STRING_ARG(hash,whirlpool,message) { return(hash_dispatch(calc_whirlpool,"whirlpool",message)); } +TWO_STRINGS(hmac,sha224,message,passphrase) { return(hmac_dispatch(hmac_sha224_str,"sha224",message,passphrase)); } +TWO_STRINGS(hmac,sha256,message,passphrase) { return(hmac_dispatch(hmac_sha256_str,"sha256",message,passphrase)); } +TWO_STRINGS(hmac,sha384,message,passphrase) { return(hmac_dispatch(hmac_sha384_str,"sha384",message,passphrase)); } +TWO_STRINGS(hmac,sha512,message,passphrase) { return(hmac_dispatch(hmac_sha512_str,"sha512",message,passphrase)); } +TWO_STRINGS(hmac,rmd128,message,passphrase) { return(hmac_dispatch(hmac_rmd128_str,"rmd128",message,passphrase)); } +TWO_STRINGS(hmac,rmd160,message,passphrase) { return(hmac_dispatch(hmac_rmd160_str,"rmd160",message,passphrase)); } +TWO_STRINGS(hmac,rmd256,message,passphrase) { return(hmac_dispatch(hmac_rmd256_str,"rmd256",message,passphrase)); } +TWO_STRINGS(hmac,rmd320,message,passphrase) { return(hmac_dispatch(hmac_rmd320_str,"rmd320",message,passphrase)); } +TWO_STRINGS(hmac,sha1,message,passphrase) { return(hmac_dispatch(hmac_sha1_str,"sha1",message,passphrase)); } +TWO_STRINGS(hmac,md2,message,passphrase) { return(hmac_dispatch(hmac_md2_str,"md2",message,passphrase)); } +TWO_STRINGS(hmac,md4,message,passphrase) { return(hmac_dispatch(hmac_md4_str,"md4",message,passphrase)); } +TWO_STRINGS(hmac,md5,message,passphrase) { return(hmac_dispatch(hmac_md5_str,"md5",message,passphrase)); } +TWO_STRINGS(hmac,tiger192_3,message,passphrase) { return(hmac_dispatch(hmac_tiger_str,"tiger",message,passphrase)); } +TWO_STRINGS(hmac,whirlpool,message,passphrase) { return(hmac_dispatch(hmac_whirlpool_str,"whirlpool",message,passphrase)); } + +STRING_ARG(SuperNET,bitcoinrpc,setcoin) +{ + char buf[1024]; + if ( setcoin != 0 && setcoin[0] != 0 ) + { + strcpy(myinfo->rpcsymbol,setcoin); + touppercase(myinfo->rpcsymbol); + printf("bitcoinrpc.%s\n",myinfo->rpcsymbol); + if ( iguana_launchcoin(myinfo,myinfo->rpcsymbol,json,0) < 0 ) + return(clonestr("{\"error\":\"error creating coin\"}")); + else + { + sprintf(buf,"{\"result\":\"success\",\"setcoin\":\"%s\"}",setcoin); + return(clonestr(buf)); + } + } else return(clonestr("{\"error\":\"bitcoinrpc needs setcoin value\"}")); +} + +ZERO_ARGS(SuperNET,help) +{ + cJSON *helpjson,*retjson; + if ( (helpjson= SuperNET_helpjson()) != 0 ) + { + retjson = cJSON_CreateObject(); + jadd(retjson,"result",helpjson); + return(jprint(retjson,1)); + } else return(clonestr("{\"error\":\"cant get helpjson\"}")); +} + +TWO_STRINGS(SuperNET,html,agentform,htmlfile) +{ + char *htmlstr; cJSON *retjson; int32_t max = 4*1024*1024; + if ( htmlfile == 0 || htmlfile[0] == 0 ) + htmlfile = "forms.html"; + //if ( (fp= fopen(htmlfile,"w")) == 0 ) + // printf("error opening htmlfile.(%s)\n",htmlfile); + htmlstr = malloc(max); + htmlstr = SuperNET_htmlstr(htmlfile,htmlstr,max,agentform); + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result",htmlstr); + free(htmlstr); + //if ( fp != 0 ) + // fclose(fp); + return(jprint(retjson,1)); +} + +#undef IGUANA_ARGS +#undef _IGUANA_APIDEC_H_ +#include "../includes/iguana_apiundefs.h" + diff --git a/iguana/tests/cancelrefresh b/iguana/tests/cancelrefresh new file mode 100755 index 000000000..35c27504d --- /dev/null +++ b/iguana/tests/cancelrefresh @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"basilisk\",\"method\":\"cancelrefresh\"}" diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index 0dec6a079..7496ccd4b 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -17,6 +17,8 @@ #define H_IGUANAFUNCS_H #define SIGHASH_ALL 1 +cJSON *SuperNET_helpjson(); + // peers int32_t iguana_verifypeer(struct iguana_info *coin,void *key,void *value,int32_t itemind,int32_t itemsize); int32_t iguana_peermetrics(struct supernet_info *myinfo,struct iguana_info *coin);