From d8eedc3afc48b27e228d5529349db605577d0ce8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Jun 2016 12:56:08 -0300 Subject: [PATCH] new apis --- basilisk/basilisk.c | 4 +- basilisk/basilisk.h | 1 + datachain/datachain.c | 302 ++--- datachain/datachain.h | 18 +- datachain/datachain_BTC.c | 22 + datachain/datachain_KOMODO.c | 189 +++ datachain/datachain_events.c | 174 +++ gecko/gecko.c | 28 +- gecko/gecko.h | 2 +- gecko/gecko_miner.c | 8 +- iguana/css/custom.css | 60 + iguana/iguana777.c | 5 +- iguana/iguana_chains.c | 6 +- iguana/iguana_instantdex.c | 30 + iguana/iguana_msg.c | 4 +- iguana/iguana_ramchain.c | 11 +- iguana/iguana_unspents.c | 18 +- iguana/index copy.html | 842 +++++++++++++ iguana/index.html | 1855 ++++++++++++++++------------- iguana/tests/DEXtx | 2 +- iguana/tests/HOT | 2 + iguana/tests/HOTtx | 2 + iguana/tests/decoderawtransaction | 2 +- includes/iguana_apideclares.h | 11 +- includes/iguana_funcs.h | 6 +- includes/iguana_structs.h | 6 +- 26 files changed, 2577 insertions(+), 1033 deletions(-) create mode 100755 datachain/datachain_BTC.c create mode 100755 datachain/datachain_KOMODO.c create mode 100755 datachain/datachain_events.c create mode 100755 iguana/css/custom.css create mode 100755 iguana/index copy.html create mode 100755 iguana/tests/HOT create mode 100755 iguana/tests/HOTtx diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 3a22c550a..ab3f54be7 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -575,8 +575,8 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende { (void *)"BYE", &basilisk_respond_goodbye }, // disconnect // gecko chains - { (void *)"NEW", &basilisk_respond_newgeckochain }, // creates new virtual gecko chain - { (void *)"GEN", &basilisk_respond_geckogenesis }, // returns genesis list + //{ (void *)"NEW", &basilisk_respond_newgeckochain }, // creates new virtual gecko chain + ///{ (void *)"GEN", &basilisk_respond_geckogenesis }, // returns genesis list { (void *)"GET", &basilisk_respond_geckoget }, // requests headers, block or tx { (void *)"HDR", &basilisk_respond_geckoheaders }, // reports headers { (void *)"BLK", &basilisk_respond_geckoblock }, // reports block diff --git a/basilisk/basilisk.h b/basilisk/basilisk.h index 7ee5ecc69..0bb37ee7b 100755 --- a/basilisk/basilisk.h +++ b/basilisk/basilisk.h @@ -69,5 +69,6 @@ char *basilisk_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint void basilisk_request_goodbye(struct supernet_info *myinfo); int32_t basilisk_update(char *symbol,uint32_t reftimestamp); void basilisk_seqresult(struct supernet_info *myinfo,char *retstr); +struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbol,char *chainname,cJSON *valsobj); #endif diff --git a/datachain/datachain.c b/datachain/datachain.c index d72a7534d..06db691eb 100755 --- a/datachain/datachain.c +++ b/datachain/datachain.c @@ -14,93 +14,139 @@ ******************************************************************************/ #include "../iguana/iguana777.h" +#include "datachain_events.c" -int32_t datachain_rwgenesis(int32_t rwflag,uint8_t *serialized,struct gecko_genesis_opreturn *opret) +uint32_t datachain_checkpoint(struct supernet_info *myinfo,struct iguana_info *coin,uint32_t lastcheckpoint,uint32_t timestamp,bits256 merkle,int32_t lastheight,bits256 lasthash2) { - int32_t len = 0; - if ( rwflag == 0 ) + char str[65],str2[65]; struct iguana_info *btc = iguana_coinfind("BTC"); + printf("datachain_checkpoint.%s for %s.%u to %u lastheight.%d %s\n",bits256_str(str,merkle),coin->symbol,lastcheckpoint,timestamp,lastheight,bits256_str(str2,lasthash2)); + if ( (lastheight % myinfo->numrelays) == myinfo->RELAYID ) { - memcpy(opret->type,&serialized[len],sizeof(opret->type)), len += sizeof(opret->type); - memcpy(opret->symbol,&serialized[len],sizeof(opret->symbol)), len += sizeof(opret->symbol); - memcpy(opret->name,&serialized[len],sizeof(opret->name)), len += sizeof(opret->name); + // if designated relay, submit checkpoint -> add ip/relayid to opreturn + // + if ( strcmp(coin->symbol,"BTCD") == 0 ) + { + if ( btc != 0 ) + { + + } + } + else + { + } } - else + return(timestamp); +} + +int32_t datachain_events_rewind(struct supernet_info *myinfo,int32_t ordered,struct datachain_info *dPoW,int32_t height,uint32_t hdrsi,uint32_t unspentind) +{ + uint64_t hdrsi_unspentind; int32_t i; + if ( dPoW->numevents > 0 ) { - memcpy(&serialized[len],opret->type,sizeof(opret->type)), len += sizeof(opret->type); - memcpy(&serialized[len],opret->symbol,sizeof(opret->symbol)), len += sizeof(opret->symbol); - memcpy(&serialized[len],opret->name,sizeof(opret->name)), len += sizeof(opret->name); + datachain_events_sort(dPoW); + hdrsi_unspentind = ((uint64_t)hdrsi << 32) | unspentind; + for (i=dPoW->numevents-1; i>=0; i--) + if ( hdrsi_unspentind > dPoW->events[i]->hdrsi_unspentind ) + break; + printf("dPoW rewind %d to %d\n",dPoW->numevents,i+1); + dPoW->numevents = i+1; } - len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->PoSvalue),&opret->PoSvalue); - //len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->flags),&opret->flags); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->netmagic),&opret->netmagic); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->timestamp),&opret->timestamp); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->nBits),&opret->nBits); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->nonce),&opret->nonce); - //len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->extra),&opret->extra); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->blocktime),&opret->blocktime); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->port),&opret->port); - if ( rwflag == 0 ) + return(dPoW->numevents); +} + +int32_t datachain_checkpoint_update(struct supernet_info *myinfo,struct iguana_info *coin,uint32_t timestamp) +{ + int32_t i,num,n,lastheight; bits256 *tree,hash2,lasthash2,merkle; struct iguana_block *block; + if ( coin->lastcheckpoint <= coin->blocks.hwmchain.height ) { - opret->version = serialized[len++]; - opret->pubval = serialized[len++]; - opret->p2shval = serialized[len++]; - opret->wifval = serialized[len++]; - memcpy(opret->rmd160,&serialized[len],20), len += 20; + num = (coin->blocks.hwmchain.height - coin->lastcheckpoint) + 1; + tree = (bits256 *)coin->blockspace; + if ( num <= IGUANA_MAXPACKETSIZE/(sizeof(bits256) * 2) ) + { + lastheight = -1; + memset(lasthash2.bytes,0,sizeof(lasthash2)); + for (i=n=0; ilastcheckpoint + i); + if ( bits256_nonz(hash2) != 0 ) + { + if ( (block= iguana_blockfind("datachain",coin,hash2)) != 0 && block->height == coin->lastcheckpoint + i && block->mainchain != 0 && block->RO.timestamp < timestamp ) + { + tree[n++] = hash2; + lastheight = block->height; + lasthash2 = hash2; + } + else break; + } + else + { + printf("got zero blockhash for %s.[%d]\n",coin->symbol,coin->lastcheckpoint + i); + break; + } + } + if ( n > 0 && lastheight >= 0 && bits256_nonz(lasthash2) != 0 ) + { + merkle = iguana_merkle(tree,num); + coin->lastcheckpoint = datachain_checkpoint(myinfo,coin,coin->lastcheckpoint,timestamp,merkle,lastheight,lasthash2); + } + } } - else + return(coin->lastcheckpoint); +} + +void datachain_BTC_clock(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *btc,int32_t height,uint32_t hdrsi,uint32_t unspentind,uint32_t timestamp) +{ + int32_t retval; struct iguana_info *btcd = iguana_coinfind("BTCD"); + if ( (retval= datachain_eventadd(myinfo,ordered,&myinfo->dPoW.BTC,DATACHAIN_ISBTC,0)) < 0 ) + { + myinfo->dPoW.BTC.numevents = datachain_events_rewind(myinfo,ordered,&myinfo->dPoW.BTC,height,hdrsi,unspentind); + } + else if ( retval > 0 ) { - serialized[len++] = opret->version; - serialized[len++] = opret->pubval; - serialized[len++] = opret->p2shval; - serialized[len++] = opret->wifval; - memcpy(&serialized[len],opret->rmd160,20), len += 20; + if ( ordered != 0 && btcd != 0 && btcd->started != 0 && btcd->active != 0 ) + { + // new BTC block actions, ie gather BTCD hashes for checkpoint + btcd->lastcheckpoint = datachain_checkpoint_update(myinfo,btcd,timestamp); + printf("NEWBLOCK.%s ht.%d\n",btc->symbol,height); + } } - printf("opreturn len.%d\n",len); - return(len); } -int32_t datachain_opreturn_create(uint8_t *serialized,char *symbol,char *name,char *coinaddr,int64_t PoSvalue,uint32_t nBits,uint16_t blocktime,uint16_t port,uint8_t p2shval,uint8_t wifval) +void datachain_KOMODO_newblock(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *btcd,int32_t height,uint32_t hdrsi,uint32_t unspentind,uint32_t timestamp) { - uint8_t txidbytes[1024],minerpayment[512]; int32_t i,len,datalen,minerpaymentlen=0,txlen; struct gecko_genesis_opreturn opret; bits256 txid,zero,threshold,hash2; struct iguana_info *btcd; char coinbasestr[512]; struct iguana_msgblock msg; - btcd = iguana_coinfind("BTCD"); - memset(&opret,0,sizeof(opret)); - opret.type[0] = 'N', opret.type[1] = 'E', opret.type[2] = 'W'; - memcpy(opret.symbol,symbol,sizeof(opret.symbol)); - memcpy(opret.name,name,sizeof(opret.name)); - opret.version = 1; - opret.PoSvalue = PoSvalue; - opret.nBits = nBits; - opret.p2shval = p2shval; - opret.wifval = wifval; - opret.blocktime = blocktime; - opret.port = port; - opret.timestamp = (uint32_t)time(NULL); - OS_randombytes((void *)&opret.netmagic,sizeof(opret.netmagic)); - bitcoin_addr2rmd160(&opret.pubval,opret.rmd160,coinaddr); - if ( PoSvalue > 0 ) - minerpaymentlen = bitcoin_standardspend(minerpayment,0,opret.rmd160); - memset(zero.bytes,0,sizeof(zero)); - sprintf(coinbasestr,"%s_%s",symbol,name); - txlen = iguana_coinbase(btcd,txidbytes,opret.timestamp,zero,(uint8_t *)coinbasestr,(int32_t)strlen(coinbasestr)+1,minerpayment,minerpaymentlen,PoSvalue,&txid); - memset(&msg,0,sizeof(msg)); - msg.H.version = opret.version; - msg.H.merkle_root = txid; - msg.H.timestamp = opret.timestamp; - msg.H.bits = opret.nBits; - threshold = bits256_from_compact(nBits); - for (i=0; i<100000000; i++) + int32_t retval; struct iguana_info *virt,*tmp; + if ( (retval= datachain_eventadd(myinfo,ordered,&myinfo->dPoW.BTCD,DATACHAIN_ISKOMODO,0)) < 0 ) { - msg.H.nonce = i; - datalen = iguana_rwblockhdr(1,0,serialized,&msg); - hash2 = iguana_calcblockhash(symbol,btcd->chain->hashalgo,serialized,datalen); - if ( bits256_cmp(threshold,hash2) > 0 ) - break; + myinfo->dPoW.BTCD.numevents = datachain_events_rewind(myinfo,ordered,&myinfo->dPoW.BTCD,height,hdrsi,unspentind); + } + else if ( retval > 0 ) + { + // new BTCD block actions, ie gather all virtual hashes for checkpoint + if ( ordered != 0 ) + { + HASH_ITER(hh,myinfo->allcoins,virt,tmp) + { + if ( virt->started != 0 && virt->active != 0 && virt->virtualchain != 0 ) + virt->lastcheckpoint = datachain_checkpoint_update(myinfo,virt,timestamp); + } + //printf("NEWBLOCK.%s ht.%d\n",btcd->symbol,height); + } + } +} + +void datachain_virt_newblock(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *virt,int32_t height,uint32_t hdrsi,uint32_t unspentind,uint32_t timestamp) +{ + int32_t retval; + if ( (retval= datachain_eventadd(myinfo,ordered,&virt->dPoW,0,0)) < 0 ) + { + virt->dPoW.numevents = datachain_events_rewind(myinfo,ordered,&virt->dPoW,height,hdrsi,unspentind); + } + else if ( retval > 0 ) + { + // new virt block actions, maybe nothing to do? + if ( ordered != 0 ) + printf("NEWBLOCK.%s ht.%d\n",virt->symbol,height); } - len = datachain_rwgenesis(1,serialized,&opret); - //for (i=0; iN; i++) { if ( (plen= bitcoin_pubkeylen(vp->signers[i].pubkey)) > 32 ) @@ -171,103 +220,57 @@ int32_t datachain_opreturn_decode(uint8_t *opreturn,uint8_t *script,int32_t scri else return(-1); } -int32_t datachain_events_rewind(struct supernet_info *myinfo,struct datachain_event *events,int32_t numevents,int32_t height,uint32_t hdrsi,uint32_t unspentind) +void datachain_opreturn(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,int32_t btc_or_btcd,int64_t crypto777_payment,int64_t burned,int32_t height,uint64_t hdrsi_unspentind,uint8_t *opreturn,int32_t oplen) { - return(numevents); -} - -void datachain_BTC_clock(struct supernet_info *myinfo,struct iguana_info *btc,int32_t height,uint32_t hdrsi,uint32_t unspentind) -{ - if ( hdrsi < myinfo->dPOW.BTC.lasthdrsi || (hdrsi == myinfo->dPOW.BTC.lasthdrsi && unspentind < myinfo->dPOW.BTC.lastunspentind) ) - { - myinfo->dPOW.BTC.numevents = datachain_events_rewind(myinfo,myinfo->dPOW.BTC.events,myinfo->dPOW.BTC.numevents,height,hdrsi,unspentind); - } - else - { - printf("NEWBLOCK.%s ht.%d\n",btc->symbol,height); - } - myinfo->dPOW.BTC.lasthdrsi = hdrsi; - myinfo->dPOW.BTC.lastunspentind = unspentind; -} - -void datachain_BTCD_newblock(struct supernet_info *myinfo,struct iguana_info *btcd,int32_t height,uint32_t hdrsi,uint32_t unspentind) -{ - if ( hdrsi < myinfo->dPOW.BTCD.lasthdrsi || (hdrsi == myinfo->dPOW.BTCD.lasthdrsi && unspentind < myinfo->dPOW.BTCD.lastunspentind) ) - { - myinfo->dPOW.BTCD.numevents = datachain_events_rewind(myinfo,myinfo->dPOW.BTCD.events,myinfo->dPOW.BTCD.numevents,height,hdrsi,unspentind); - } - else - { - // new BTCD block actions - printf("NEWBLOCK.%s ht.%d\n",btcd->symbol,height); - } - myinfo->dPOW.BTCD.lasthdrsi = hdrsi; - myinfo->dPOW.BTCD.lastunspentind = unspentind; -} - -void datachain_virt_newblock(struct supernet_info *myinfo,struct iguana_info *virt,int32_t height,uint32_t hdrsi,uint32_t unspentind) -{ - if ( hdrsi < virt->dPOW.lasthdrsi || (hdrsi == virt->dPOW.lasthdrsi && unspentind < virt->dPOW.lastunspentind) ) - { - virt->dPOW.numevents = datachain_events_rewind(myinfo,virt->dPOW.events,virt->dPOW.numevents,height,hdrsi,unspentind); - } - else - { - // new virt block actions - printf("NEWBLOCK.%s ht.%d\n",virt->symbol,height); - } - virt->dPOW.lasthdrsi = hdrsi; - virt->dPOW.lastunspentind = unspentind; -} - -void datachain_opreturn(struct supernet_info *myinfo,struct iguana_info *coin,int32_t btc_or_btcd,int64_t crypto777_payment,int64_t burned,int32_t height,uint64_t hdrsi_unspentind,uint8_t *opreturn,int32_t oplen) -{ - uint32_t hdrsi,unspentind; + uint32_t hdrsi,unspentind; struct datachain_event *event; hdrsi = (uint32_t)(hdrsi_unspentind >> 32); unspentind = (uint32_t)hdrsi_unspentind; - if ( btc_or_btcd == 1 ) // BTC + if ( btc_or_btcd == DATACHAIN_ISBTC ) // BTC { if ( opreturn == 0 ) - datachain_BTC_clock(myinfo,coin,height,hdrsi,unspentind); + datachain_BTC_clock(myinfo,ordered,coin,height,hdrsi,unspentind,timestamp); else { - + if ( (event= datachain_event_create(coin,crypto777_payment,burned,height,hdrsi,unspentind,opreturn,oplen)) != 0 ) + datachain_eventadd(myinfo,ordered,&myinfo->dPoW.BTC,btc_or_btcd,event); } } - else if ( btc_or_btcd == 2 ) // BTCD + else if ( btc_or_btcd == DATACHAIN_ISKOMODO ) // BTCD { if ( opreturn == 0 ) - datachain_BTCD_newblock(myinfo,coin,height,hdrsi,unspentind); + datachain_KOMODO_newblock(myinfo,ordered,coin,height,hdrsi,unspentind,timestamp); else { - + if ( (event= datachain_event_create(coin,crypto777_payment,burned,height,hdrsi,unspentind,opreturn,oplen)) != 0 ) + datachain_eventadd(myinfo,ordered,&myinfo->dPoW.BTCD,btc_or_btcd,event); } } else { if ( opreturn == 0 ) - datachain_virt_newblock(myinfo,coin,height,hdrsi,unspentind); + datachain_virt_newblock(myinfo,ordered,coin,height,hdrsi,unspentind,timestamp); else { - + if ( (event= datachain_event_create(coin,crypto777_payment,burned,height,hdrsi,unspentind,opreturn,oplen)) != 0 ) + datachain_eventadd(myinfo,ordered,&coin->dPoW,btc_or_btcd,event); } } if ( opreturn != 0 ) { int32_t i; for (i=0; isymbol,oplen); + printf("%02x",opreturn[i]); + printf(" <- opreturn.%s len.%d ht.%d [%d] u.%u 777 %.8f burn %.8f\n",coin->symbol,oplen,height,hdrsi,unspentind,dstr(crypto777_payment),dstr(burned)); } } -int32_t iguana_opreturn(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int64_t crypto777_payment,int32_t height,uint64_t hdrsi_unspentind,int64_t burned,uint32_t fileid,uint64_t scriptpos,uint32_t scriptlen) +int32_t iguana_opreturn(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,int64_t crypto777_payment,int32_t height,uint64_t hdrsi_unspentind,int64_t burned,uint32_t fileid,uint64_t scriptpos,uint32_t scriptlen) { - uint8_t type,scriptspace[IGUANA_MAXSCRIPTSIZE],opreturn[8192]; char fname[1024]; uint32_t sigsize,pubkeysize,p2shsize,suffix,oplen=0; int32_t btc_or_btcd=0,len = -1; struct vin_info V; + uint8_t type,scriptspace[IGUANA_MAXSCRIPTSIZE],opreturn[8192]; char fname[1024]; uint32_t oplen=0; int32_t btc_or_btcd=0,len = -1; struct vin_info V; if ( strcmp("BTC",coin->symbol) == 0 ) - btc_or_btcd = 1; + btc_or_btcd = DATACHAIN_ISBTC; else if ( strcmp("BTCD",coin->symbol) == 0 ) - btc_or_btcd = 2; + btc_or_btcd = DATACHAIN_ISKOMODO; else if ( coin->virtualchain == 0 ) return(-1); if ( height < bp->bundleheight || height >= bp->bundleheight+coin->chain->bundlesize ) @@ -277,7 +280,7 @@ int32_t iguana_opreturn(struct supernet_info *myinfo,struct iguana_info *coin,st } if ( crypto777_payment == 0 && burned == 0 && scriptlen == 0 && fileid == 0 && scriptpos == 0 ) { - datachain_opreturn(myinfo,coin,btc_or_btcd,crypto777_payment,burned,height,hdrsi_unspentind,0,0); + datachain_opreturn(myinfo,ordered,coin,timestamp,btc_or_btcd,crypto777_payment,burned,height,hdrsi_unspentind,0,0); return(0); } if ( scriptpos > 0 && scriptlen > 0 ) @@ -286,24 +289,35 @@ int32_t iguana_opreturn(struct supernet_info *myinfo,struct iguana_info *coin,st if ( (len= iguana_scriptdata(coin,scriptspace,coin->voutptrs[fileid],fname,scriptpos,scriptlen)) == scriptlen ) { memset(&V,0,sizeof(V)); - type = iguana_vinscriptparse(coin,&V,&sigsize,&pubkeysize,&p2shsize,&suffix,scriptspace,scriptlen); + V.spendlen = scriptlen; + memcpy(V.spendscript,scriptspace,scriptlen); + type = _iguana_calcrmd160(coin,&V); if ( type == IGUANA_SCRIPT_OPRETURN ) oplen = datachain_opreturn_decode(opreturn,scriptspace,scriptlen); else oplen = datachain_datascript_decode(opreturn,scriptspace,scriptlen,&V,type); - datachain_opreturn(myinfo,coin,btc_or_btcd,crypto777_payment,burned,height,hdrsi_unspentind,opreturn,oplen); + datachain_opreturn(myinfo,ordered,coin,timestamp,btc_or_btcd,crypto777_payment,burned,height,hdrsi_unspentind,opreturn,oplen); return(oplen); } else printf("iguana_opreturn error: %d bytes from fileid.%d[%d] %s for scriptlen.%d\n",len,fileid,(uint32_t)scriptpos,fname,scriptlen); } return(-1); } -int64_t datachain_update(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,uint8_t rmd160[20],int64_t crypto777_payment,uint8_t type,int32_t height,uint64_t hdrsi_unspentind,int64_t value,uint32_t fileid,uint64_t scriptpos,int32_t scriptlen) +void datachain_update_spend(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,int32_t height,bits256 txid,int32_t vout,uint8_t rmd160[20],int64_t value) +{ + if ( strcmp("BTC",coin->symbol) == 0 ) + datachain_update_txidvout(myinfo,ordered,coin,&myinfo->dPoW.BTC,DATACHAIN_ISBTC,height,txid,vout,rmd160,value); + else if ( strcmp("BTCD",coin->symbol) == 0 ) + datachain_update_txidvout(myinfo,ordered,coin,&myinfo->dPoW.BTCD,DATACHAIN_ISKOMODO,height,txid,vout,rmd160,value); + else datachain_update_txidvout(myinfo,ordered,coin,&coin->dPoW,0,height,txid,vout,rmd160,value); +} + +int64_t datachain_update(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,uint8_t rmd160[20],int64_t crypto777_payment,uint8_t type,int32_t height,uint64_t hdrsi_unspentind,int64_t value,uint32_t fileid,uint64_t scriptpos,int32_t scriptlen,bits256 txid,int32_t vout) { if ( memcmp(rmd160,CRYPTO777_RMD160,20) == 0 ) crypto777_payment += value; else if ( crypto777_payment != 0 && (type == IGUANA_SCRIPT_OPRETURN || type == IGUANA_SCRIPT_3of3 || type == IGUANA_SCRIPT_2of2 || type == IGUANA_SCRIPT_1of1) ) { - iguana_opreturn(myinfo,coin,bp,crypto777_payment,height,hdrsi_unspentind,value,fileid,scriptpos,scriptlen); - } + iguana_opreturn(myinfo,ordered,coin,timestamp,bp,crypto777_payment,height,hdrsi_unspentind,value,fileid,scriptpos,scriptlen); + } else datachain_update_spend(myinfo,ordered,coin,timestamp,bp,height,txid,vout,rmd160,value); return(crypto777_payment); -} \ No newline at end of file +} diff --git a/datachain/datachain.h b/datachain/datachain.h index c227ea4ab..d44732f98 100755 --- a/datachain/datachain.h +++ b/datachain/datachain.h @@ -69,6 +69,9 @@ #define DATACHAIN_ACTION_QUOTE 10004 #define DATACHAIN_ACTION_SENDGROUP 10005 +#define DATACHAIN_ISBTC 1 +#define DATACHAIN_ISKOMODO 2 + struct datachain_itemexclusive { uint8_t ownerpub[33]; }; struct datachain_item @@ -85,13 +88,22 @@ struct datachain_item struct datachain_event { - + uint64_t hdrsi_unspentind,crypto777_payment,burned; + int32_t height,btc_or_btcd,oplen; + char symbol[16]; + uint8_t opreturn[]; +}; + +struct datachain_state +{ + int32_t numprocessed,lasthdrsi,lastunspentind; }; struct datachain_info { - uint32_t lasthdrsi,lastunspentind,numevents,maxevents; - struct datachain_event *events; + struct datachain_state state; + uint32_t numevents,maxevents,ordered; + struct datachain_event **events; }; struct delayedPoW_info diff --git a/datachain/datachain_BTC.c b/datachain/datachain_BTC.c new file mode 100755 index 000000000..0e05d796a --- /dev/null +++ b/datachain/datachain_BTC.c @@ -0,0 +1,22 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +// included from datachain.c + +void datachain_events_processBTC(struct supernet_info *myinfo,struct datachain_info *dPoW,struct datachain_event *event) +{ + +} + diff --git a/datachain/datachain_KOMODO.c b/datachain/datachain_KOMODO.c new file mode 100755 index 000000000..7d08369f1 --- /dev/null +++ b/datachain/datachain_KOMODO.c @@ -0,0 +1,189 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +// included from datachain.c + +int32_t datachain_rwgenesis(int32_t rwflag,uint8_t *serialized,struct gecko_genesis_opreturn *opret) +{ + int32_t len = 0; + if ( rwflag == 0 ) + { + memcpy(opret->type,&serialized[len],sizeof(opret->type)), len += sizeof(opret->type); + memcpy(opret->symbol,&serialized[len],sizeof(opret->symbol)), len += sizeof(opret->symbol); + memcpy(opret->name,&serialized[len],sizeof(opret->name)), len += sizeof(opret->name); + } + else + { + memcpy(&serialized[len],opret->type,sizeof(opret->type)), len += sizeof(opret->type); + memcpy(&serialized[len],opret->symbol,sizeof(opret->symbol)), len += sizeof(opret->symbol); + memcpy(&serialized[len],opret->name,sizeof(opret->name)), len += sizeof(opret->name); + } + len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->PoSvalue),&opret->PoSvalue); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->netmagic),&opret->netmagic); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->timestamp),&opret->timestamp); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->nBits),&opret->nBits); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->nonce),&opret->nonce); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->blocktime),&opret->blocktime); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(opret->port),&opret->port); + if ( rwflag == 0 ) + { + opret->version = serialized[len++]; + opret->pubval = serialized[len++]; + opret->p2shval = serialized[len++]; + opret->wifval = serialized[len++]; + memcpy(opret->rmd160,&serialized[len],20), len += 20; + } + else + { + serialized[len++] = opret->version; + serialized[len++] = opret->pubval; + serialized[len++] = opret->p2shval; + serialized[len++] = opret->wifval; + memcpy(&serialized[len],opret->rmd160,20), len += 20; + } + //printf("opreturn len.%d\n",len); + return(len); +} + +bits256 datachain_opreturn_convert(uint8_t *txidbytes,int32_t *txlenp,struct iguana_msgblock *msg,struct gecko_genesis_opreturn *opret) +{ + bits256 txid,zero; int32_t minerpaymentlen=0; uint8_t minerpayment[512]; char coinbasestr[128],name[64],symbol[64]; + if ( opret->PoSvalue > 0 ) + minerpaymentlen = bitcoin_standardspend(minerpayment,0,opret->rmd160); + memset(zero.bytes,0,sizeof(zero)); + memset(symbol,0,sizeof(symbol)), memcpy(symbol,opret->symbol,sizeof(opret->symbol)); + memset(name,0,sizeof(name)), memcpy(name,opret->name,sizeof(opret->name)); + sprintf(coinbasestr,"%s_%s",symbol,name); + *txlenp = iguana_coinbase(1,GECKO_DEFAULTVERSION,txidbytes,opret->timestamp,zero,(uint8_t *)coinbasestr,(int32_t)strlen(coinbasestr)+1,minerpayment,minerpaymentlen,opret->PoSvalue,&txid); + memset(msg,0,sizeof(*msg)); + msg->H.version = opret->version; + msg->H.merkle_root = txid; + msg->H.timestamp = opret->timestamp; + msg->H.bits = opret->nBits; + msg->H.nonce = opret->nonce; + return(txid); +} + +int32_t datachain_genesis_verify(struct gecko_genesis_opreturn *opret) +{ + int32_t txlen,datalen; bits256 txid,threshold,hash2; uint8_t serialized[1024],txidbytes[1024]; struct iguana_msgblock msg; char str[65],str2[65]; + txid = datachain_opreturn_convert(txidbytes,&txlen,&msg,opret); + threshold = bits256_from_compact(opret->nBits); + datalen = iguana_rwblockhdr(1,0,serialized,&msg); + hash2 = iguana_calcblockhash("virtual",blockhash_sha256,serialized,datalen); + //for (i=0; i 0 ) + { + //printf(" valid blockhash!\n"); + return(0); + } + else + { + printf(" ERROR invalid blockhash! txid.%s %s\n",bits256_str(str2,txid),bits256_str(str,hash2)); + return(-1); + } +} + +int32_t datachain_opreturn_create(uint8_t *serialized,char *symbol,char *name,char *coinaddr,int64_t PoSvalue,uint32_t nBits,uint16_t blocktime,uint16_t port,uint8_t p2shval,uint8_t wifval) +{ + int32_t i,len,datalen,txlen; struct gecko_genesis_opreturn opret; bits256 threshold,txid,hash2; struct iguana_info *btcd; struct iguana_msgblock msg; uint8_t txidbytes[1024]; + btcd = iguana_coinfind("BTCD"); + memset(&opret,0,sizeof(opret)); + opret.type[0] = 'N', opret.type[1] = 'E', opret.type[2] = 'W'; + memcpy(opret.symbol,symbol,sizeof(opret.symbol)); + memcpy(opret.name,name,sizeof(opret.name)); + opret.version = GECKO_DEFAULTVERSION; + opret.PoSvalue = PoSvalue; + opret.nBits = nBits; + opret.p2shval = p2shval; + opret.wifval = wifval; + opret.blocktime = blocktime; + opret.port = port; + opret.timestamp = (uint32_t)time(NULL); + OS_randombytes((void *)&opret.netmagic,sizeof(opret.netmagic)); + bitcoin_addr2rmd160(&opret.pubval,opret.rmd160,coinaddr); + txid = datachain_opreturn_convert(txidbytes,&txlen,&msg,&opret); + threshold = bits256_from_compact(nBits); + for (i=0; i<100000000; i++) + { + opret.nonce = msg.H.nonce = i; + datalen = iguana_rwblockhdr(1,0,serialized,&msg); + hash2 = iguana_calcblockhash(symbol,btcd->chain->hashalgo,serialized,datalen); + if ( bits256_cmp(threshold,hash2) > 0 ) + break; + } + //char str[65],str2[65]; + //for (i=0; iopreturn,"NEW",3) == 0 ) + { + //int32_t i; for (i=0; i<76; i++) + // printf("%02x",event->opreturn[i]); + //printf(" <- event\n"); + if ( (len= datachain_rwgenesis(0,event->opreturn,&opret)) <= event->oplen ) + { + datachain_genesis_verify(&opret); + memset(symbol,0,sizeof(symbol)), memcpy(symbol,opret.symbol,sizeof(opret.symbol)); + memset(name,0,sizeof(name)), memcpy(name,opret.name,sizeof(opret.name)); + hash2 = datachain_opreturn_convert(txidbytes,&txlen,&msg,&opret); + threshold = bits256_from_compact(opret.nBits); + msg.txn_count = 1; + //n = iguana_serialize_block(virt->chain,&hash2,serialized,newblock); + datalen = iguana_rwblockhdr(1,0,serialized,&msg); + hash2 = iguana_calcblockhash(symbol,btcd->chain->hashalgo,serialized,datalen); + for (i=0; i 0 ) + { + bitcoin_address(issuer,60,opret.rmd160,20); + bits256_str(hashstr,hash2); + for (j=0,i=3; i>=0; i--,j++) + buf[i] = (opret.netmagic >> (j*8)); + init_hexbytes_noT(magicstr,buf,4); + for (j=0,i=3; i>=0; i--,j++) + buf[i] = (opret.nBits >> (j*8)); + init_hexbytes_noT(nbitstr,buf,4); + init_hexbytes_noT(blockstr,serialized,datalen); + strcat(blockstr,"01"), datalen++; + init_hexbytes_noT(&blockstr[datalen << 1],txidbytes,txlen); + sprintf(argbuf,"{\"name\":\"%s\",\"symbol\":\"%s\",\"netmagic\":\"%s\",\"port\":%u,\"blocktime\":%u,\"pubval\":\"%02x\",\"p2shval\":\"%02x\",\"wifval\":\"%02x\",\"unitval\":\"%02x\",\"genesishash\":\"%s\",\"genesis\":{\"version\":1,\"timestamp\":%u,\"nBits\":\"%s\",\"nonce\":%d,\"merkle_root\":\"%s\"},\"genesisblock\":\"%s\"}",name,symbol,magicstr,opret.port,opret.blocktime,opret.pubval,opret.p2shval,opret.wifval,(opret.nBits >> 24) & 0xff,hashstr,opret.timestamp,nbitstr,opret.nonce,bits256_str(str2,msg.H.merkle_root),blockstr); + if ( (valsobj= cJSON_Parse(argbuf)) != 0 ) + { + printf("datachain.NEW (%s/%s port.%u blocktime.%d) issuer.%s (%s)\n",opret.symbol,opret.name,opret.port,opret.blocktime,issuer,jprint(valsobj,0)); + if ( (chain= gecko_chain(myinfo,chainname,valsobj)) != 0 && (virt= chain->info) != 0 ) + printf("duplicate chain.%s rejected\n",opret.symbol); + else if ( (virt= basilisk_geckochain(myinfo,symbol,chainname,valsobj)) != 0 ) + chain->info = virt; + free_json(valsobj); + } + } else printf("failed PoW test for genesis.%s\n",opret.symbol); + } else printf("opret unexpected len.%d vs %d\n",len,event->oplen); + } +} diff --git a/datachain/datachain_events.c b/datachain/datachain_events.c new file mode 100755 index 000000000..b6e2105d2 --- /dev/null +++ b/datachain/datachain_events.c @@ -0,0 +1,174 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +// included from datachain.c +#include "datachain_KOMODO.c" +#include "datachain_BTC.c" + +void datachain_events_process_virt(struct supernet_info *myinfo,struct datachain_info *dPoW,struct datachain_event *event) +{ + +} + +int _increasing_events(const void *a,const void *b) +{ +#define uint64_a (*(struct datachain_event **)a)->hdrsi_unspentind +#define uint64_b (*(struct datachain_event **)b)->hdrsi_unspentind + if ( uint64_b > uint64_a ) + return(-1); + else if ( uint64_b < uint64_a ) + return(1); + return(0); +#undef uint64_a +#undef uint64_b +} + +void datachain_events_sort(struct datachain_info *dPoW) +{ + if ( dPoW->numevents > 0 ) + { + qsort(dPoW->events,dPoW->numevents,sizeof(dPoW->events),_increasing_events); + printf("sorted %d events\n",dPoW->numevents); + } +} + +struct datachain_event *datachain_event_create(struct iguana_info *coin,int64_t crypto777_payment,int64_t burned,int32_t height,uint32_t hdrsi,uint32_t unspentind,uint8_t *opreturn,int32_t oplen) +{ + struct datachain_event *event; + event = calloc(1,sizeof(*event) + oplen); + event->hdrsi_unspentind = ((uint64_t)hdrsi << 32) | unspentind; + event->crypto777_payment = crypto777_payment; + event->burned = burned; + event->height = height; + safecopy(event->symbol,coin->symbol,sizeof(event->symbol)); + if ( strcmp(event->symbol,"BTC") == 0 ) + event->btc_or_btcd = DATACHAIN_ISBTC; + else if ( strcmp(event->symbol,"BTCD") == 0 ) + event->btc_or_btcd = DATACHAIN_ISKOMODO; + event->oplen = oplen; + memcpy(event->opreturn,opreturn,oplen); + return(event); +} + +void datachain_events_process(struct supernet_info *myinfo,int32_t btc_or_btcd,struct datachain_info *dPoW,int32_t firsti,int32_t lasti) +{ + int32_t i; struct datachain_event *event; + if ( firsti >= 0 && lasti <= dPoW->numevents ) + { + for (i=0; i<=lasti; i++) + if ( (event= dPoW->events[i]) != 0 ) + { + if ( btc_or_btcd == DATACHAIN_ISBTC ) + datachain_events_processBTC(myinfo,dPoW,event); + else if ( btc_or_btcd == DATACHAIN_ISKOMODO ) + datachain_events_processKOMODO(myinfo,dPoW,event); + else datachain_events_process_virt(myinfo,dPoW,event); + dPoW->state.numprocessed++; + } + } else printf("illegal datachain_events_process.[%d, %d] numevents.%d\n",firsti,lasti,dPoW->numevents); +} + +void datachain_state_reset(struct supernet_info *myinfo,int32_t btc_or_btcd,struct datachain_info *dPoW) +{ + struct datachain_state *state = &dPoW->state; + memset(state,0,sizeof(*state)); +} + +void datachain_reset(struct supernet_info *myinfo,int32_t btc_or_btcd,struct datachain_info *dPoW) +{ + struct iguana_info *virt,*tmp; + if ( btc_or_btcd == DATACHAIN_ISBTC ) // all needs to be reset on BTC reorg + datachain_reset(myinfo,DATACHAIN_ISKOMODO,&myinfo->dPoW.BTCD); + else if ( btc_or_btcd == DATACHAIN_ISKOMODO ) + { + HASH_ITER(hh,myinfo->allcoins,virt,tmp) + { + if ( virt->started != 0 && virt->active != 0 && virt->virtualchain != 0 ) + datachain_reset(myinfo,0,&virt->dPoW); + } + } + datachain_events_sort(dPoW); + datachain_state_reset(myinfo,btc_or_btcd,dPoW); +} + +int32_t datachain_eventadd(struct supernet_info *myinfo,int32_t ordered,struct datachain_info *dPoW,int32_t btc_or_btcd,struct datachain_event *event) +{ + uint64_t hdrsi_unspentind; int32_t retval = 0; + if ( ordered != 0 ) + { + if ( dPoW->ordered == 0 ) + datachain_events_sort(dPoW); + } else dPoW->ordered = 0; + hdrsi_unspentind = ((uint64_t)dPoW->state.lasthdrsi << 32) | dPoW->state.lastunspentind; + if ( ordered != 0 ) + { + if ( dPoW->ordered != dPoW->numevents ) + { + printf("trigger reset and process.%d ordered.%d numevents.%d\n",btc_or_btcd,dPoW->ordered,dPoW->numevents); + datachain_reset(myinfo,btc_or_btcd,dPoW); + if ( dPoW->numevents > 0 ) + datachain_events_process(myinfo,btc_or_btcd,dPoW,0,dPoW->numevents-1); + if ( btc_or_btcd == DATACHAIN_ISBTC ) // all needs to be reprocessed on BTC reorg + { + if ( myinfo->dPoW.BTCD.numevents > 0 ) + datachain_events_process(myinfo,DATACHAIN_ISKOMODO,&myinfo->dPoW.BTCD,0,myinfo->dPoW.BTCD.numevents - 1); + } + else if ( btc_or_btcd == DATACHAIN_ISKOMODO ) + { + struct iguana_info *virt,*tmp; + HASH_ITER(hh,myinfo->allcoins,virt,tmp) + { + if ( virt->started != 0 && virt->active != 0 && virt->virtualchain != 0 ) + if ( virt->dPoW.numevents > 0 ) + datachain_events_process(myinfo,0,&virt->dPoW,0,virt->dPoW.numevents-1); + } + } + dPoW->ordered = dPoW->numevents; + } + } + if ( event != 0 ) + { + if ( dPoW->numevents >= dPoW->maxevents ) + { + dPoW->maxevents += 1024; + dPoW->events = realloc(dPoW->events,sizeof(*dPoW->events) * dPoW->maxevents); + } + if ( event->hdrsi_unspentind > hdrsi_unspentind ) + { + dPoW->state.lasthdrsi = (uint32_t)(event->hdrsi_unspentind >> 32); + dPoW->state.lastunspentind = (uint32_t)event->hdrsi_unspentind; + retval = 1; + } + if ( ordered != 0 ) + { + if ( retval != 1 && dPoW->ordered != 0 ) + { + printf("datachain_eventadd unexpected ordered event that is not at the end\n"); + retval = -1; + } + dPoW->events[dPoW->numevents] = event; + if ( dPoW->ordered == dPoW->numevents ) + datachain_events_process(myinfo,btc_or_btcd,dPoW,dPoW->numevents,dPoW->numevents); + dPoW->numevents++; + dPoW->ordered = dPoW->numevents; + } else dPoW->events[dPoW->numevents++] = event; + } + return(dPoW->numevents); +} + +void datachain_update_txidvout(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,struct datachain_info *dPoW,int32_t btc_or_btcd,int32_t spentheight,bits256 txid,int32_t vout,uint8_t rmd160[20],int64_t value) +{ + // MGW via deposit events +} diff --git a/gecko/gecko.c b/gecko/gecko.c index 7b931637e..7fcd9cdf2 100755 --- a/gecko/gecko.c +++ b/gecko/gecko.c @@ -13,6 +13,8 @@ * * ******************************************************************************/ +// are nbits and magicstr endian dependent? + // code mempool and tx (payment and opreturn protocol) // debug genesis balances @@ -121,7 +123,7 @@ void *category_subscribe(struct supernet_info *myinfo,bits256 chainhash,bits256 { chain = mycalloc('c',1,sizeof(*chain)); chain->hash = hash = chainhash; - char str[65]; printf("ADD cat.(%s)\n",bits256_str(str,chainhash)); + //char str[65]; printf("ADD cat.(%s)\n",bits256_str(str,chainhash)); HASH_ADD(hh,Categories,hash,sizeof(hash),chain); } if ( bits256_nonz(keyhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,keyhash.bytes,sizeof(keyhash)) != 0 && chain != 0 ) @@ -131,7 +133,7 @@ void *category_subscribe(struct supernet_info *myinfo,bits256 chainhash,bits256 { subchain = mycalloc('c',1,sizeof(*subchain)); subchain->hash = hash = keyhash; - char str[65],str2[65]; printf("subadd.(%s) -> (%s)\n",bits256_str(str,keyhash),bits256_str(str2,chainhash)); + //char str[65],str2[65]; printf("subadd.(%s) -> (%s)\n",bits256_str(str,keyhash),bits256_str(str2,chainhash)); HASH_ADD(hh,chain->subchains,hash,sizeof(hash),subchain); } } @@ -143,9 +145,9 @@ struct gecko_chain *gecko_chain(struct supernet_info *myinfo,char chainname[GECK { char *chainstr,*keystr; bits256 keyhash,chainhash; struct gecko_chain *chain; chainname[0] = 0; - if ( (chainstr= jstr(valsobj,"chain")) == 0 ) + if ( (chainstr= jstr(valsobj,"symbol")) == 0 ) return(0); - if ( (keystr= jstr(valsobj,"key")) != 0 ) + if ( (keystr= jstr(valsobj,"name")) != 0 ) vcalc_sha256(0,keyhash.bytes,(uint8_t *)keystr,(int32_t)strlen(keystr)); else keyhash = GENESIS_PUBKEY; vcalc_sha256(0,chainhash.bytes,(uint8_t *)chainstr,(int32_t)strlen(chainstr)); @@ -186,7 +188,7 @@ struct gecko_chain *gecko_chain(struct supernet_info *myinfo,char chainname[GECK return(0); } return(-1); -}*/ +} cJSON *gecko_genesisargs(char *symbol,char *chainname,char *chain,char *keystr,char *genesishash,char *genesisblock,char *magicstr,uint16_t port,uint16_t blocktime,char *nbitstr,char *pubval,char *p2shval,char *wifval,uint32_t isPoS) { @@ -281,7 +283,7 @@ cJSON *gecko_genesisissue(char *symbol,char *chainname,char *chainstr,cJSON *val { printf("issue blocktime.%d\n",juint(valsobj,"blocktime")); return(gecko_genesisargs(symbol,chainname,chainstr,jstr(valsobj,"key"),jstr(valsobj,"genesishash"),jstr(valsobj,"genesisblock"),jstr(valsobj,"netmagic"),juint(valsobj,"port"),juint(valsobj,"blocktime"),jstr(valsobj,"nBits"),jstr(valsobj,"pubval"),jstr(valsobj,"p2shval"),jstr(valsobj,"wifval"),juint(valsobj,"isPoS"))); -} +}*/ struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbol,char *chainname,cJSON *valsobj) { @@ -295,6 +297,7 @@ struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbo virt->enableCACHE = 1; serialized = get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr); iguana_chaininit(virt->chain,1,valsobj); + virt->chain->isPoS = 1; hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr); if ( gecko_blocknonce_verify(virt,serialized,hdrsize,virt->chain->nBits,0,0) > 0 ) { @@ -333,13 +336,14 @@ struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbo } virt->started = virt; virt->active = (uint32_t)time(NULL); + iguana_datachain_scan(myinfo,virt,CRYPTO777_RMD160); } else printf("error validating nonce\n"); } portable_mutex_unlock(&myinfo->gecko_mutex); return(virt); } -char *basilisk_respond_newgeckochain(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk) +/*char *basilisk_respond_newgeckochain(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk) { struct iguana_info *virt,*btcd; struct gecko_chain *chain; char fname[512],*symbol,*retstr,*chainstr,chainname[GECKO_MAXNAMELEN],*genesises; cJSON *chainjson,*retjson,*genesisjson; long filesize; FILE *fp; if ( (chain= gecko_chain(myinfo,chainname,valsobj)) != 0 && (virt= chain->info) != 0 ) @@ -431,7 +435,7 @@ char *basilisk_respond_geckogenesis(struct supernet_info *myinfo,char *CMD,void { long filesize; return(OS_filestr(&filesize,"genesis/list")); -} +}*/ char *basilisk_standardreturn(char *CMD,char *type,struct iguana_info *virt,uint8_t *serialized,int32_t datalen,bits256 hash) { @@ -480,7 +484,7 @@ char *basilisk_respond_geckoget(struct supernet_info *myinfo,char *CMD,void *add #include "../includes/iguana_apidefs.h" #include "../includes/iguana_apideclares.h" -HASH_ARRAY_STRING(basilisk,sequence,hash,vals,hexstr) +/*HASH_ARRAY_STRING(basilisk,sequence,hash,vals,hexstr) { return(basilisk_standardservice("SEQ",myinfo,hash,vals,hexstr,1)); } @@ -533,7 +537,7 @@ HASH_ARRAY_STRING(basilisk,newgeckochain,hash,vals,hexstr) } else return(clonestr("{\"error\":\"couldnt create genesis_block\"}")); } return(clonestr("{\"error\":\"need symbol and chain and BTCD to create new gecko chain\"}")); -} +}*/ char *gecko_sendrawtransaction(struct supernet_info *myinfo,char *symbol,uint8_t *data,int32_t datalen,bits256 txid,cJSON *vals,char *signedtx) { @@ -591,7 +595,7 @@ HASH_ARRAY_STRING(basilisk,geckoget,hash,vals,hexstr) return(clonestr("{\"error\":\"geckoget needs BTCD\"}")); } -HASH_ARRAY_STRING(basilisk,geckogenesis,hash,vals,hexstr) +/*HASH_ARRAY_STRING(basilisk,geckogenesis,hash,vals,hexstr) { long filesize; int32_t i,j,n,m; struct iguana_info *btcd; char *ref,*symbol,*retstr=0; cJSON *item,*array = 0,*arrayB = 0; FILE *fp; if ( (btcd= iguana_coinfind("BTCD")) != 0 ) @@ -653,7 +657,7 @@ HASH_ARRAY_STRING(basilisk,geckogenesis,hash,vals,hexstr) } } return(clonestr("{\"error\":\"need BTCD to get geckogenesis list\"}")); -} +}*/ #include "../includes/iguana_apiundefs.h" diff --git a/gecko/gecko.h b/gecko/gecko.h index d4be2272c..ce1d5159d 100755 --- a/gecko/gecko.h +++ b/gecko/gecko.h @@ -92,6 +92,6 @@ char *gecko_sendrawtransaction(struct supernet_info *myinfo,char *symbol,uint8_t struct gecko_mempool *gecko_mempoolfind(struct supernet_info *myinfo,struct iguana_info *virt,int32_t *numotherp,uint32_t ipbits); void gecko_iteration(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,int32_t maxmillis); -int32_t iguana_coinbase(struct iguana_info *virt,uint8_t *serialized,uint32_t timestamp,bits256 prev_hash,uint8_t *coinbasescript,uint32_t coinbaselen,uint8_t *minerpayment,uint32_t minerpaymentlen,int64_t blockreward,bits256 *txidp); +int32_t iguana_coinbase(int32_t isPoS,uint32_t txversion,uint8_t *serialized,uint32_t timestamp,bits256 prev_hash,uint8_t *coinbasescript,uint32_t coinbaselen,uint8_t *minerpayment,uint32_t minerpaymentlen,int64_t blockreward,bits256 *txidp); #endif diff --git a/gecko/gecko_miner.c b/gecko/gecko_miner.c index 9563833c3..bc9f9429a 100755 --- a/gecko/gecko_miner.c +++ b/gecko/gecko_miner.c @@ -113,7 +113,7 @@ int32_t gecko_delayedPoW(struct supernet_info *myinfo,struct iguana_info *btcd,i return(len); } -int32_t iguana_coinbase(struct iguana_info *virt,uint8_t *serialized,uint32_t timestamp,bits256 prev_hash,uint8_t *coinbasescript,uint32_t coinbaselen,uint8_t *minerpayment,uint32_t minerpaymentlen,int64_t blockreward,bits256 *txidp) +int32_t iguana_coinbase(int32_t isPoS,uint32_t txversion,uint8_t *serialized,uint32_t timestamp,bits256 prev_hash,uint8_t *coinbasescript,uint32_t coinbaselen,uint8_t *minerpayment,uint32_t minerpaymentlen,int64_t blockreward,bits256 *txidp) { int32_t len = 0,rwflag=1; uint32_t prev_vout,sequence,lock_time; char txidstr[65]; struct iguana_msgtx msg; memset(&msg,0,sizeof(msg)); @@ -121,10 +121,10 @@ int32_t iguana_coinbase(struct iguana_info *virt,uint8_t *serialized,uint32_t ti msg.tx_in = 1; sequence = prev_vout = -1; lock_time = 0; - msg.version = virt->chain->normal_txversion; + msg.version = txversion; msg.timestamp = timestamp; len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg.version),&msg.version); - if ( virt->chain->isPoS != 0 ) + if ( isPoS != 0 ) len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg.timestamp),&msg.timestamp); { len += iguana_rwvarint32(rwflag,&serialized[len],&msg.tx_in); @@ -155,7 +155,7 @@ char *gecko_coinbasestr(struct supernet_info *myinfo,struct iguana_info *virt,bi char *rawtx=0; uint8_t minerpayment[512],serialized[8192]; int32_t minerpaymentlen=0,len=0; if ( blockreward > 0 ) minerpaymentlen = bitcoin_pubkeyspend(minerpayment,0,minerpubkey); - len = iguana_coinbase(virt,serialized,timestamp,coinbasespend,data,datalen,minerpayment,minerpaymentlen,blockreward,txidp); + len = iguana_coinbase(virt->chain->isPoS,virt->chain->normal_txversion,serialized,timestamp,coinbasespend,data,datalen,minerpayment,minerpaymentlen,blockreward,txidp); if ( len > 0 ) { rawtx = malloc(len*2 + 1); diff --git a/iguana/css/custom.css b/iguana/css/custom.css new file mode 100755 index 000000000..e87d2a4a1 --- /dev/null +++ b/iguana/css/custom.css @@ -0,0 +1,60 @@ +.exchangecontainer{ + margin:30px; + + background-color:#FFF; + color:#000; + + } +.innersection{ + background-color:#EEE; + margin:20px 0; + padding:10px; + } +.innersection h4{ + padding:7px; + font-weight:bolder; + } +.coin1, .coin2{ + float:left; + color:#000; + background-color:#EEE; + width:50%; + padding: 10px 10px; + + } + +.exchangecontainer label, #exchange_model #frmexchange label{ + color:#000; + + } +#frmexchange label{ + text-align:left !important; + } +.innersection .exchange{ + text-align:center; + width: 120px; + background-color: #009688; + + } +.button{ + width: 20%; + margin: 0 auto; +} +.shape{ + font-family: inherit; + font-size: inherit; + line-height: inherit; + height: 33px; + border-radius: 6px; + box-shadow: 0 0 0; + border: 1px solid #ccc; + width: 166px; + text-align: center; +} +.innersection table td{ padding:10px;} + +#address_to, #address_from{ + + width:100% !important; + height:45px !important; + } \ No newline at end of file diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 75396f863..fc47299b8 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -572,8 +572,8 @@ void iguana_helper(void *arg) flag = 0; if ( (btcd= iguana_coinfind("BTCD")) != 0 ) { - if ( helperid == 0 && myinfo->numrelays > 0 && myinfo->genesisresults == 0 ) - basilisk_geckogenesis(myinfo,btcd,0,0,GENESIS_PUBKEY,0,0); + //if ( helperid == 0 && myinfo->numrelays > 0 && myinfo->genesisresults == 0 ) + // basilisk_geckogenesis(myinfo,btcd,0,0,GENESIS_PUBKEY,0,0); if ( myinfo->allcoins_numvirts > 0 ) { maxmillis = (10000 / myinfo->allcoins_numvirts) + 1; @@ -704,6 +704,7 @@ void iguana_callcoinstart(struct supernet_info *myinfo,struct iguana_info *coin) memset(zero.bytes,0,sizeof(zero)); if ( (bp= iguana_bundlecreate(coin,&bundlei,0,*(bits256 *)coin->chain->genesis_hashdata,zero,1)) != 0 ) bp->bundleheight = 0; + iguana_datachain_scan(myinfo,coin,CRYPTO777_RMD160); } void iguana_coinloop(void *arg) diff --git a/iguana/iguana_chains.c b/iguana/iguana_chains.c index 372a21fe3..c282876e5 100755 --- a/iguana/iguana_chains.c +++ b/iguana/iguana_chains.c @@ -162,7 +162,7 @@ bits256 iguana_calcblockhash(char *symbol,int32_t (*hashalgo)(uint8_t *blockhash bits256 iguana_chaingenesis(char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),bits256 genesishash,char *genesisblock,char *hashalgostr,int32_t version,uint32_t timestamp,uint32_t nBits,uint32_t nonce,bits256 merkle_root) { - struct iguana_msgblock msg; int32_t len; bits256 hash2; char blockhashstr[256],str3[65]; uint8_t serialized[8192]; + struct iguana_msgblock msg; int32_t len; bits256 hash2; char blockhashstr[256]; uint8_t serialized[8192]; memset(&msg,0,sizeof(msg)); msg.H.version = version; msg.H.merkle_root = merkle_root; @@ -181,7 +181,7 @@ bits256 iguana_chaingenesis(char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (* if ( bits256_cmp(genesishash,hash2) != 0 ) printf("WARNING: genesishash.(%s) mismatch vs calc.(%s)\n",bits256_str(str,genesishash),bits256_str(str2,hash2)); init_hexbytes_noT(genesisblock,serialized,len); - printf("v.%d t.%u %s nBits.%08x nonce.%u merkle.(%s) genesis.(%s) hash2.(%s) blockhash.(%s) size.%d\n",version,timestamp,utc_str(str3,timestamp),nBits,nonce,bits256_str(str2,merkle_root),genesisblock,bits256_str(str,hash2),blockhashstr,(int32_t)strlen(genesisblock)/2); + //printf("v.%d t.%u %s nBits.%08x nonce.%u merkle.(%s) genesis.(%s) hash2.(%s) blockhash.(%s) size.%d\n",version,timestamp,utc_str(str3,timestamp),nBits,nonce,bits256_str(str2,merkle_root),genesisblock,bits256_str(str,hash2),blockhashstr,(int32_t)strlen(genesisblock)/2); return(hash2); } @@ -287,7 +287,7 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson) { extern char Userhome[]; char *path,conf[512],*hexstr,genesisblock[1024]; uint16_t port; cJSON *rpair,*genesis,*rewards,*item; int32_t i,n,m; uint32_t nBits; uint8_t tmp[4]; - printf("chainparams.(%s)\n",jprint(argjson,0)); + //printf("chainparams.(%s)\n",jprint(argjson,0)); if ( strcmp(chain->symbol,"NXT") != 0 ) { if ( strcmp(chain->symbol,"BTCD") == 0 ) diff --git a/iguana/iguana_instantdex.c b/iguana/iguana_instantdex.c index 4a041aab2..fae073023 100755 --- a/iguana/iguana_instantdex.c +++ b/iguana/iguana_instantdex.c @@ -1718,5 +1718,35 @@ TWO_STRINGS(InstantDEX,events,base,rel) //return(clonestr("[{\"h\":14,\"m\":44,\"s\":32,\"date\":1407877200000,\"bid\":30,\"ask\":35},{\"date\":1407877200000,\"bid\":40,\"ask\":44},{\"date\":1407877200000,\"bid\":49,\"ask\":45},{\"date\":1407877200000,\"ask\":28},{\"date\":1407877200000,\"ask\":52}]")); } +ZERO_ARGS(InstantDEX,allcoins) +{ + return(clonestr("{\"result\":\"this will return array of available coins\"}")); +} + +STRING_ARG(InstantDEX,available,source) +{ + return(clonestr("{\"result\":\"this will return available balance for source\"}")); +} + +THREE_STRINGS_AND_DOUBLE(InstantDEX,request,message,dest,source,amount) +{ + return(clonestr("{\"result\":\"this will request converting amount worth of source into dest\"}")); +} + +INT_ARG(InstantDEX,incoming,requestid) +{ + return(clonestr("{\"result\":\"this will return array of incoming request objects\"}")); +} + +INT_ARG(InstantDEX,choose,quoteid) +{ + return(clonestr("{\"result\":\"this will choose one of the incoming requests and cancel the rest\"}")); +} + +INT_ARG(InstantDEX,qstatus,quoteid) +{ + return(clonestr("{\"result\":\"this will return status of pending quote\"}")); +} + #include "../includes/iguana_apiundefs.h" diff --git a/iguana/iguana_msg.c b/iguana/iguana_msg.c index c953bf7cd..d25e3937f 100755 --- a/iguana/iguana_msg.c +++ b/iguana/iguana_msg.c @@ -688,12 +688,12 @@ int32_t iguana_gentxarray(struct iguana_info *coin,struct OS_memspace *mem,struc { if ( len > recvlen ) { - printf("gentxarray error len.%d > recvlen.%d\n",len,recvlen); + printf("gentxarrayB error len.%d > recvlen.%d\n",len,recvlen); break; } if ( (n= iguana_rwtx(coin->chain->zcash,0,mem,&data[len],&tx[i],recvlen - len,&tx[i].txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0)) < 0 ) { - printf("gentxarray error len.%d > recvlen.%d\n",len,recvlen); + printf("gentxarrayC error len.%d > recvlen.%d, n.%d\n",len,recvlen,n); break; } numvouts += tx[i].tx_out; diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index 8fccd9601..1a172bdf2 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -1626,7 +1626,7 @@ int32_t iguana_ramchain_cmp(struct iguana_ramchain *A,struct iguana_ramchain *B, int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int16_t bundlei) { RAMCHAIN_DECLARE; RAMCHAIN_DESTDECLARE; - int32_t j,hdrsi,prevout,scriptlen; uint32_t unspentind,sequenceid,destspendind=0,desttxidind=0; uint16_t fileid; uint64_t scriptpos; int64_t crypto777_payment = 0; + int32_t j,hdrsi,prevout,scriptlen; uint32_t timestamp=0,unspentind,sequenceid,destspendind=0,desttxidind=0; uint16_t fileid; uint64_t scriptpos; int64_t crypto777_payment = 0; bits256 prevhash; uint64_t value; uint8_t type; struct iguana_unspent *u; struct iguana_txid *tx; struct iguana_ramchaindata *rdata; uint8_t rmd160[20]; //if ( dest != 0 ) @@ -1638,9 +1638,8 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info } if ( dest != 0 ) { + // required to do one block at a time, all vins/vouts the same height are assumed to happen simultaneously with vouts before vins _iguana_ramchain_setptrs(RAMCHAIN_DESTPTRS,dest->H.data); - if ( dest->expanded != 0 ) - iguana_opreturn(myinfo,coin,bp,0,bp->bundleheight + bundlei,(((uint64_t)bp->hdrsi << 32) | dest->H.unspentind),0,0,0,0); } //fprintf(stderr,"iterate %d/%d dest.%p ramchain.%p rdata.%p\n",bp->bundleheight,bp->n,dest,ramchain,rdata); _iguana_ramchain_setptrs(RAMCHAIN_PTRS,rdata); @@ -1665,6 +1664,8 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info //printf("txidind.%u firstvout.%u firstvin.%u bundlei.%d n.%d\n",tx->txidind,tx->firstvout,tx->firstvin,bundlei,bp->n); if ( dest != 0 ) { + if ( dest->expanded != 0 ) + iguana_opreturn(myinfo,1,coin,tx->timestamp,bp,0,bp->bundleheight + bundlei,(((uint64_t)bp->hdrsi << 32) | dest->H.unspentind),0,0,0,0); //char str[65]; if ( 0 && ramchain->expanded == 0 ) printf("ITER [%d] TXID.%d -> dest.%p desttxid.%d dest->hashmem.%p numtxids.%d\n",rdata->height,ramchain->H.txidind,dest,dest!=0?dest->H.txidind:0,dest!=0?dest->hashmem:0,rdata->numtxids); @@ -1737,7 +1738,7 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info } if ( dest != 0 ) { - crypto777_payment = datachain_update(myinfo,coin,bp,rmd160,crypto777_payment,type,bp->bundleheight + bundlei,(((uint64_t)bp->hdrsi << 32) | unspentind),value,fileid,scriptpos,scriptlen); + crypto777_payment = datachain_update(myinfo,1,coin,timestamp,bp,rmd160,crypto777_payment,type,bp->bundleheight + bundlei,(((uint64_t)bp->hdrsi << 32) | unspentind),value,fileid,scriptpos,scriptlen,tx->txid,j); if ( iguana_ramchain_addunspent(coin,RAMCHAIN_DESTARG,value,hdrsi,rmd160,j,type,fileid,(uint32_t)scriptpos,scriptlen,ramchain->H.txidind-rdata->firsti) == 0 ) return(-5); } //else printf("addunspent20 done\n"); @@ -1759,6 +1760,7 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info for (ramchain->H.txidind=rdata->firsti; ramchain->H.txidindnumtxids; ramchain->H.txidind++) { tx = &T[ramchain->H.txidind]; + timestamp = tx->timestamp; for (j=0; jnumvins; j++) { if ( coin->active == 0 ) @@ -1811,6 +1813,7 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info } if ( dest != 0 ) { + datachain_update_spend(myinfo,1,coin,timestamp,bp,bp->bundleheight + bundlei,tx->txid,j,0,-1); if ( iguana_ramchain_addspend(coin,RAMCHAIN_DESTARG,prevhash,prevout,sequenceid,bp->hdrsi,fileid,scriptpos,scriptlen) == 0 ) return(-9); //printf("from dest iter scriptspace.%d\n",dest->H.stacksize); diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 5ac8bab8b..066aa0d2d 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -200,24 +200,32 @@ int32_t iguana_uheight(struct iguana_info *coin,int32_t bundleheight,struct igua int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t rmd160[20]) { - int64_t deposits,crypto777_payment; uint32_t lastunspentind,unspentind; int32_t i,num,uheight; struct iguana_bundle *bp; struct iguana_ramchain *ramchain; struct iguana_ramchaindata *rdata; struct iguana_pkhash P; struct iguana_unspent *U; struct iguana_txid *T; + int64_t deposits,crypto777_payment; uint32_t lastunspentind,unspentind; int32_t i,j,num,uheight; struct iguana_bundle *bp; struct iguana_ramchain *ramchain; struct iguana_ramchaindata *rdata; struct iguana_pkhash *P,p; struct iguana_unspent *U,*u; struct iguana_txid *T,*tx; for (i=num=0; ibundlescount; i++) { if ( (bp= coin->bundles[i]) != 0 ) { ramchain = 0; - if ( iguana_pkhashfind(coin,&ramchain,&deposits,&lastunspentind,&P,rmd160,i,i) != 0 ) + if ( iguana_pkhashfind(coin,&ramchain,&deposits,&lastunspentind,&p,rmd160,i,i) != 0 ) { if ( ramchain != 0 && (rdata= ramchain->H.data) != 0 ) { unspentind = lastunspentind; U = RAMCHAIN_PTR(rdata,Uoffset); T = RAMCHAIN_PTR(rdata,Toffset); + P = RAMCHAIN_PTR(rdata,Poffset); while ( unspentind > 0 ) { - uheight = iguana_uheight(coin,ramchain->height,T,rdata->numtxids,&U[unspentind]); - - crypto777_payment = datachain_update(myinfo,coin,bp,rmd160,crypto777_payment,U[unspentind].type,uheight,(((uint64_t)bp->hdrsi << 32) | unspentind),U[unspentind].value,U[unspentind].fileid,U[unspentind].scriptpos,U[unspentind].scriptlen); + tx = &T[U[unspentind].txidind]; + u = &U[tx->firstvout]; + uheight = iguana_uheight(coin,ramchain->height,T,rdata->numtxids,u); + for (crypto777_payment=j=0; jnumvouts; j++,u++) + { + //u = &U[tx->firstvout + j]; + crypto777_payment = datachain_update(myinfo,0,coin,tx->timestamp,bp,P[u->pkind].rmd160,crypto777_payment,u->type,uheight,(((uint64_t)bp->hdrsi << 32) | unspentind),u->value,u->fileid,u->scriptpos,u->scriptlen,tx->txid,j); + } + num++; + unspentind = U[unspentind].prevunspentind; } } } diff --git a/iguana/index copy.html b/iguana/index copy.html new file mode 100755 index 000000000..28d3217f1 --- /dev/null +++ b/iguana/index copy.html @@ -0,0 +1,842 @@ + + + + + + + iguana + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + +
+
+
+
+
+
+
+ + + +
+
+
+

Json posting form

+
+ +
+
+
+
+
+
+ +
+
+ + +
+
+
+
+
+
+ +
JSON response
+ +
+
+
+
+

+ List of games + +

+
+
+ + + + +
+ +
+
+
+ +
+
+
+
+
+ + + +
+
+
+

Coin Management

+
+
+ +
+ + + +
+ + + + + + + + + + + + +
SymbolDescriptionStatusAction
+ + + + +
+
+
+
+
+ +
+
+ + +
+
+
+
+
+
+ +
JSON response
+ +
+
+
+
+
+
+ + + + +
+
+
+
+

+ Peer Management +

+
+
+ + + + +
+ +
+ + + + + + + + + + + + + + +
IP AddressCoin TypeHeightRankBlockFavourite Actions
+
+
+
+
+ +
+
+
+
+

+ Tradebot +

+
+
+ + + + + + + + + + + + + + +
+
+ + + + +
+ + + +
+
+
+
+
+ + +
+
+
+

Settings

+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+ +
+
+
+
+
+
+ + +
+
+
+

+ Encrypt/decrypt JSON +

+
+
+
+
+
+
+ +
+ + +
+
+
+ +
+
+ + +
+
+
+
+ +
+ + +
+
+
+ + +
+ +
+
+
+ +
JSON response
+ + +
encrypted file content
+ + +
+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + +
+
+
+
+ +
+ +
+ +
+
+ +
+
+ + +
+
+ +
+

Block Explorer tab

+
+
+
+ +
+

Set Active coin

+
+ +
+
+
+
+
+ + + +
+
+ + + + +
+
+
+ +
+ + +
+
+ +
+

InstantDEX

+
+ + + + + + + + + + + + + + +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+
+
+ + +
+
+ +
+ +
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iguana/index.html b/iguana/index.html index 28d3217f1..923281680 100755 --- a/iguana/index.html +++ b/iguana/index.html @@ -1,842 +1,1013 @@ - - - - - - - iguana - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - -
-
-
-
-
-
-
- - - -
-
-
-

Json posting form

-
- -
-
-
-
-
-
- -
-
- - -
-
-
-
-
-
- -
JSON response
- -
-
-
-
-

- List of games - -

-
-
- - - - -
- -
-
-
- -
-
-
-
-
- - - -
-
-
-

Coin Management

-
-
- -
- - - -
- - - - - - - - - - - - -
SymbolDescriptionStatusAction
- - - - -
-
-
-
-
- -
-
- - -
-
-
-
-
-
- -
JSON response
- -
-
-
-
-
-
- - - - -
-
-
-
-

- Peer Management -

-
-
- - - - -
- -
- - - - - - - - - - - - - - -
IP AddressCoin TypeHeightRankBlockFavourite Actions
-
-
-
-
- -
-
-
-
-

- Tradebot -

-
-
- - - - - - - - - - - - - - -
-
- - - - -
- - - -
-
-
-
-
- - -
-
-
-

Settings

-
-
-
-
-
-
-
-
-
- - -
-
-
-
-
- -
-
-
-
-
-
- - -
-
-
-

- Encrypt/decrypt JSON -

-
-
-
-
-
-
- -
- - -
-
-
- -
-
- - -
-
-
-
- -
- - -
-
-
- - -
- -
-
-
- -
JSON response
- - -
encrypted file content
- - -
-
- -
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - -
-
-
-
- -
- -
- -
-
- -
-
- - -
-
- -
-

Block Explorer tab

-
-
-
- -
-

Set Active coin

-
- -
-
-
-
-
- - - -
-
- - - - -
-
-
- -
- - -
-
- -
-

InstantDEX

-
- - - - - - - - - - - - - - -
-
- -
-
- - - - - - - - - - - - - - - - - - - - -
- -
- -
-
-
- - -
-
- -
- -
- - -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + iguana + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + +
+
+
+
+
+
+
+ + + +
+
+
+

Json posting form

+
+ +
+
+
+
+
+
+ +
+
+ + +
+
+
+
+
+
+ +
JSON response
+ +
+
+
+
+

+ List of games + +

+
+
+ + + + +
+ +
+
+
+ +
+
+
+
+
+ + + +
+
+
+

Coin Management

+
+
+ +
+ + + +
+ + + + + + + + + + + + +
SymbolDescriptionStatusAction
+ + + + +
+
+
+
+
+ +
+
+ + +
+
+
+
+
+
+ +
JSON response
+ +
+
+
+
+
+
+ + + + +
+
+
+
+

+ Peer Management +

+
+
+ + + + +
+ +
+ + + + + + + + + + + + + + +
IP AddressCoin TypeHeightRankBlockFavourite Actions
+
+
+
+
+ +
+
+
+
+

+ Tradebot +

+
+
+ + + + + + + + + + + + + + +
+
+ + + + +
+ + + +
+
+
+
+
+ + +
+
+
+

Settings

+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+ +
+
+
+
+
+
+ + +
+
+
+

+ Encrypt/decrypt JSON +

+
+
+
+
+
+
+ +
+ + +
+
+
+ +
+
+ + +
+
+
+
+ +
+ + +
+
+
+ + +
+ +
+
+
+ +
JSON response
+ + +
encrypted file content
+ + +
+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + +
+
+
+
+ +
+ +
+ +
+
+ +
+
+ + +
+
+ +
+

Block Explorer tab

+
+
+
+ +
+

Set Active coin

+
+ +
+
+
+
+
+ + + +
+
+ + + + +
+
+ + + + + + +
+
+

Choose Which Coins to Exchange

+
+ + + + + + + + +
+
+
+ + + + + + +
+ + +
+
+
+
+ +
+ + + + + + + + + + + +
+ + +
+
+ +
+

InstantDEX

+
+ + + + + + + + + + + + + + +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+
+
+ + +
+
+ +
+ +
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iguana/tests/DEXtx b/iguana/tests/DEXtx index 2b1aa93cb..302997a86 100755 --- a/iguana/tests/DEXtx +++ b/iguana/tests/DEXtx @@ -1,2 +1,2 @@ -curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"sendtoaddress\",\"params\":[\"RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA\", 0.0001, \"4e4557444558000000496e7374616e744445580000407a10f35a0000e1526b5aab0b6b57ffffff1e000000000100013c0580f1dce4182fce875748c4986b240ff7d7bc3fffb0\", \"sendcomment\"]}" +curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"sendtoaddress\",\"params\":[\"RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA\", 0.0001, \"4e4557444558000000496e7374616e74444558000000000000407a10f35a0000dffc6993a2216d57ffffff1e1f4e010001000cba013c0580f1dce4182fce875748c4986b240ff7d7bc3fffb0\", \"sendcomment\"]}" diff --git a/iguana/tests/HOT b/iguana/tests/HOT new file mode 100755 index 000000000..261ef44ce --- /dev/null +++ b/iguana/tests/HOT @@ -0,0 +1,2 @@ +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"basilisk\",\"method\":\"genesis_opreturn\",\"vals\":{\"issuer\":\"RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA\",\"stake\":1000000,\"blocktime\":1,\"name\":\"HOT ICO\",\"symbol\":\"HOT\",\"p2sh\":5,\"wif\":128,\"nBits\":\"1effffff\"}}" + diff --git a/iguana/tests/HOTtx b/iguana/tests/HOTtx new file mode 100755 index 000000000..f84d2d4b9 --- /dev/null +++ b/iguana/tests/HOTtx @@ -0,0 +1,2 @@ +curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"sendtoaddress\",\"params\":[\"RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA\", 0.0001, \"4e4557484f54000000484f542049434f000000000000000000407a10f35a00007f53009145d46b57ffffff1e0000000001009577013c0580f1dce4182fce875748c4986b240ff7d7bc3fffb0\", \"sendcomment\"]}" + diff --git a/iguana/tests/decoderawtransaction b/iguana/tests/decoderawtransaction index aeaa479a6..44e6ddf9c 100755 --- a/iguana/tests/decoderawtransaction +++ b/iguana/tests/decoderawtransaction @@ -1 +1 @@ -curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"decoderawtransaction\",\"params\":[\"0100000071d46a5701df62e7985792f07682f565e9496d9358398839f6d7154f531c481d872fb74fcd010000006b483045022100ba971715e5084c71a4239d57af05dc8cf8c9ba478e50949e55accc8345a5388502206da445b50c927ff1b69901c60c97cd01e488c9a865efa5cb724bfc24a05d863d012103377aea6f477582332f128acb197b9f463b5262571d23afaa113dfab48753e3cdffffffff0310270000000000001976a914f1dce4182fce875748c4986b240ff7d7bc3fffb088acc02d9a3b000000001976a914c210f6711e98fe9971757ede2b2dcb0507f3f25e88ac00000000000000004c6a4a00407a10f35a00007ed8874d63a66a57ffffff1e000000000100010005800000000000000000000000000000000000000000444558000000496e7374616e74444558000000000000000000000000\"]}" +curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"decoderawtransaction\",\"params\":[\"01000000a2216d57010000000000000000000000000000000000000000000000000000000000000000ffffffff0f4445585f496e7374616e7444455800ffffffff0100407a10f35a00001976a914f1dce4182fce875748c4986b240ff7d7bc3fffb088ac00000000\"]}" diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index 9165869fa..930e3b6c5 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -13,15 +13,22 @@ * * ******************************************************************************/ +ZERO_ARGS(InstantDEX,allcoins); +STRING_ARG(InstantDEX,available,source); +THREE_STRINGS_AND_DOUBLE(InstantDEX,request,message,dest,source,amount); +INT_ARG(InstantDEX,incoming,requestid); +INT_ARG(InstantDEX,choose,quoteid); +INT_ARG(InstantDEX,qstatus,quoteid); + HASH_ARRAY_STRING(basilisk,genesis_opreturn,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr); //INT_AND_ARRAY(basilisk,result,basilisktag,vals); -HASH_ARRAY_STRING(basilisk,geckogenesis,hash,vals,hexstr); +//HASH_ARRAY_STRING(basilisk,geckogenesis,hash,vals,hexstr); -HASH_ARRAY_STRING(basilisk,newgeckochain,hash,vals,hexstr); +//HASH_ARRAY_STRING(basilisk,newgeckochain,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,geckoheaders,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,geckoblock,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,geckotx,hash,vals,hexstr); diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index 1de86ab12..bd7ce8199 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -464,7 +464,8 @@ struct iguana_bundlereq *iguana_bundlereq(struct iguana_info *coin,struct iguana void instantdex_FSMinit(); void iguana_unspentslock(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins); char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t satoshis,char *changeaddr,int64_t txfee,cJSON *addresses,int32_t minconf,uint8_t *opreturn,int32_t oplen,int64_t burnamount); -int64_t datachain_update(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,uint8_t rmd160[20],int64_t crypto777_payment,uint8_t type,int32_t height,uint64_t hdrsi_unspentind,int64_t burned,uint32_t fileid,uint64_t scriptpos,int32_t scriptlen); +int64_t datachain_update(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,uint8_t rmd160[20],int64_t crypto777_payment,uint8_t type,int32_t height,uint64_t hdrsi_unspentind,int64_t burned,uint32_t fileid,uint64_t scriptpos,int32_t scriptlen,bits256 txid,int32_t vout); +void datachain_update_spend(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,int32_t height,bits256 txid,int32_t vout,uint8_t rmd160[20],int64_t value); char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx,cJSON *privkey); bits256 scrypt_blockhash(const void *input); @@ -521,9 +522,10 @@ struct iguana_peer *iguana_peerfindipaddr(struct iguana_info *coin,char *ipaddr, struct iguana_peer *iguana_peerfindipbits(struct iguana_info *coin,uint32_t ipbits,int32_t needalive); int32_t basilisk_relays_send(struct supernet_info *myinfo,struct iguana_peer *addr); int32_t basilisk_hashes_send(struct supernet_info *myinfo,struct iguana_info *virt,struct iguana_peer *addr,char *CMD,bits256 *txids,int32_t num); -int32_t iguana_opreturn(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int64_t crypto777_payment,int32_t height,uint64_t hdrsi_unspentind,int64_t payment,uint32_t fileid,uint64_t scriptpos,uint32_t scriptlen); +int32_t iguana_opreturn(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,int64_t crypto777_payment,int32_t height,uint64_t hdrsi_unspentind,int64_t payment,uint32_t fileid,uint64_t scriptpos,uint32_t scriptlen); int32_t iguana_scriptdata(struct iguana_info *coin,uint8_t *scriptspace,long fileptr[2],char *fname,uint64_t scriptpos,int32_t scriptlen); struct iguana_peer *basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *btcd,uint32_t ipbits); +int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t rmd160[20]); #include "../includes/iguana_api.h" diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index a55a7a1fe..d368f4339 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -403,7 +403,7 @@ struct iguana_info struct iguana_bundle *bundles[IGUANA_MAXBUNDLES],*current,*lastpending; struct iguana_ramchain RTramchain; struct OS_memspace RTmem,RThashmem; bits256 RThash1; int32_t numremain,numpendings,zcount,recvcount,bcount,pcount,lastbundle,numsaved,pendbalances,numverified,blockdepth; - uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis,firstRTgenesis,RTstarti,idletime,stucktime,stuckmonitor,maxstuck,lastreqtime,RThdrstime,nextchecked; + uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis,firstRTgenesis,RTstarti,idletime,stucktime,stuckmonitor,maxstuck,lastreqtime,RThdrstime,nextchecked,lastcheckpoint; double bandwidth,maxbandwidth,backstopmillis; bits256 backstophash2; int64_t spaceused; int32_t initialheight,mapflags,minconfirms,numrecv,bindsock,isRT,backstop,blocksrecv,merging,polltimeout,numreqtxids,allhashes,balanceflush,basilisk_busy; bits256 reqtxids[64]; void *launched,*started,*rpcloop; @@ -413,7 +413,7 @@ struct iguana_info struct iguana_hhutxo *utxotable; struct iguana_hhaccount *accountstable; char lastdispstr[2048]; double txidfind_totalmillis,txidfind_num,spendtxid_totalmillis,spendtxid_num; struct iguana_monitorinfo monitoring[256]; - struct datachain_info dPOW; + struct datachain_info dPoW; struct iguana_zblock newblock; char *newblockstr; struct iguana_blocks blocks; void *mempool; void *mempools[IGUANA_MAXRELAYS]; }; @@ -467,7 +467,7 @@ struct supernet_info struct iguana_info *allcoins; int32_t allcoins_being_added,allcoins_numvirts; portable_mutex_t allcoins_mutex,gecko_mutex,basilisk_mutex; void *ctx; - struct delayedPoW_info dPOW; + struct delayedPoW_info dPoW; uint32_t relaybits[IGUANA_MAXRELAYS]; struct basilisk_relay relays[IGUANA_MAXRELAYS]; int32_t numrelays,RELAYID; // compatibility