Browse Source

test

release/v0.1
jl777 8 years ago
parent
commit
0aed185cd4
  1. 22
      basilisk/basilisk_CMD.c
  2. 28
      basilisk/basilisk_bitcoin.c
  3. 216
      datachain/datachain.c
  4. 3
      datachain/datachain.h
  5. 71
      gecko/gecko.c
  6. 7
      gecko/gecko.h
  7. 17
      iguana/exchanges/bitcoin.h
  8. 2
      iguana/iguana_chains.c
  9. 5
      iguana/iguana_payments.c
  10. 8
      iguana/iguana_ramchain.c
  11. 30
      iguana/iguana_unspents.c
  12. 2
      iguana/tests/DEX
  13. 2
      iguana/tests/DEXtx
  14. 2
      iguana/tests/decoderawtransaction
  15. 2
      iguana/tests/gettransaction
  16. 19
      includes/iguana_defines.h
  17. 2
      includes/iguana_funcs.h

22
basilisk/basilisk_CMD.c

@ -308,6 +308,8 @@ HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr)
if ( (coin= iguana_coinfind(symbol)) != 0 )
{
basilisktag = juint(vals,"basilisktag");
if ( juint(vals,"burn") == 0 )
jaddnum(vals,"burn",0.0001);
if ( (timeoutmillis= juint(vals,"timeout")) <= 0 )
timeoutmillis = BASILISK_TIMEOUT;
if ( (ptr= basilisk_bitcoinrawtx(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 )
@ -400,9 +402,22 @@ HASH_ARRAY_STRING(basilisk,VPNlogout,hash,vals,hexstr)
return(basilisk_standardservice("END",myinfo,hash,vals,hexstr,0));
}
uint16_t basilisk_portavailable(struct supernet_info *myinfo,uint16_t port)
{
struct iguana_info *coin,*tmp;
if ( port < 10000 )
return(0);
HASH_ITER(hh,myinfo->allcoins,coin,tmp)
{
if ( port == coin->chain->portp2p || port == coin->chain->rpcport )
return(0);
}
return(port);
}
HASH_ARRAY_STRING(basilisk,genesis_opreturn,hash,vals,hexstr)
{
int32_t len; uint16_t blocktime; uint8_t p2shval,wifval; uint8_t serialized[4096],tmp[4]; char hex[8192],*symbol,*name,*destaddr; uint64_t PoSvalue; uint32_t nBits;
int32_t len; uint16_t blocktime,port; uint8_t p2shval,wifval; uint8_t serialized[4096],tmp[4]; char hex[8192],*symbol,*name,*destaddr; uint64_t PoSvalue; uint32_t nBits;
symbol = jstr(vals,"symbol");
name = jstr(vals,"name");
destaddr = jstr(vals,"issuer");
@ -411,6 +426,9 @@ HASH_ARRAY_STRING(basilisk,genesis_opreturn,hash,vals,hexstr)
blocktime = 1;
p2shval = juint(vals,"p2sh");
wifval = juint(vals,"wif");
if ( (port= juint(vals,"port")) == 0 )
while ( (port= basilisk_portavailable(myinfo,(rand() % 50000) + 10000)) == 0 )
;
if ( jstr(vals,"nBits") != 0 )
{
decode_hex((void *)&tmp,sizeof(tmp),jstr(vals,"nBits"));
@ -419,7 +437,7 @@ HASH_ARRAY_STRING(basilisk,genesis_opreturn,hash,vals,hexstr)
((uint8_t *)&nBits)[2] = tmp[1];
((uint8_t *)&nBits)[3] = tmp[0];
} else nBits = 0x1e00ffff;
len = gecko_opreturn_create(serialized,symbol,name,destaddr,PoSvalue,nBits,blocktime,p2shval,wifval);
len = datachain_opreturn_create(serialized,symbol,name,destaddr,PoSvalue,nBits,blocktime,port,p2shval,wifval);
init_hexbytes_noT(hex,serialized,len);
return(clonestr(hex));
}

28
basilisk/basilisk_bitcoin.c

@ -604,25 +604,15 @@ void *basilisk_bitcoinrawtx(struct basilisk_item *Lptr,struct supernet_info *myi
if ( (opreturn= jstr(valsobj,"opreturn")) != 0 && (oplen= is_hexstr(opreturn,0)) > 0 )
{
oplen >>= 1;
offset = 0;
buf[offset++] = 0x6a;
if ( oplen >= 0x4c )
{
if ( oplen > 0xff )
{
buf[offset++] = 0x4d;
buf[offset++] = oplen & 0xff;
buf[offset++] = (oplen >> 8) & 0xff;
}
else
{
buf[offset++] = 0x4c;
buf[offset++] = oplen;
}
} else buf[offset++] = oplen;
decode_hex(&buf[offset],oplen,opreturn);
burnamount = SATOSHIDEN * jdouble(valsobj,"burn");
bitcoin_txoutput(txobj,buf,oplen+offset,burnamount);
if ( (strcmp("BTC",coin->symbol) == 0 && oplen < 77) || coin->chain->do_opreturn == 0 )
{
decode_hex(&buf[sizeof(buf) - oplen],oplen,opreturn);
spendlen = datachain_datascript(coin,buf,&buf[sizeof(buf) - oplen],oplen);
if ( (burnamount= SATOSHIDEN * jdouble(valsobj,"burn")) < 10000 )
burnamount = 10000;
bitcoin_txoutput(txobj,buf,spendlen,burnamount);
oplen = 0;
} else oplen = datachain_opreturnscript(coin,buf,opreturn,oplen);
}
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf,oplen!=0?buf:0,oplen+offset,burnamount);
//printf("generated.(%s) vins.(%s)\n",rawtx,vins!=0?jprint(vins,0):"");

216
datachain/datachain.c

@ -15,6 +15,162 @@
#include "../iguana/iguana777.h"
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->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 )
{
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);
}
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)
{
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++)
{
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;
}
len = datachain_rwgenesis(1,serialized,&opret);
//for (i=0; i<len; i++)
// printf("%02x",serialized[i]);
//printf(" <- opreturn\n");
return(len);
}
int32_t datachain_datascript(struct iguana_info *coin,uint8_t *script,uint8_t *data,int32_t datalen)
{
int32_t i,pkey0,plen,len = 0; uint8_t p2sh_rmd160[20]; struct vin_info V;
memset(&V,0,sizeof(V));
if ( len < 32*3 )
pkey0 = 2, plen = 32;
else pkey0 = 4, plen = 64;
V.M = V.N = (datalen / plen) + ((datalen % plen) != 0);
for (i=0; i<V.N; i++)
{
V.signers[i].pubkey[0] = pkey0;
memcpy(V.signers[i].pubkey+1,&data[len],plen), len += plen;
}
return(bitcoin_MofNspendscript(p2sh_rmd160,script,0,&V));
}
int32_t datachain_datascript_decode(uint8_t *opreturn,uint8_t *script,int32_t scriptlen,struct vin_info *vp,int32_t type)
{
int32_t plen,i,oplen=0;
for (i=0; i<vp->N; i++)
{
if ( (plen= bitcoin_pubkeylen(vp->signers[i].pubkey)) > 32 )
memcpy(&opreturn[oplen],vp->signers[i].pubkey+1,plen-1), oplen += (plen - 1);
}
return(oplen);
}
int32_t datachain_opreturnscript(struct iguana_info *coin,uint8_t *script,char *datastr,int32_t datalen)
{
int32_t offset = 0;
script[offset++] = 0x6a;
if ( datalen >= 0x4c )
{
if ( datalen > 0xff )
{
script[offset++] = 0x4d;
script[offset++] = datalen & 0xff;
script[offset++] = (datalen >> 8) & 0xff;
}
else
{
script[offset++] = 0x4c;
script[offset++] = datalen;
}
} else script[offset++] = datalen;
decode_hex(&script[offset],datalen,datastr);
return(datalen + offset);
}
int32_t datachain_opreturn_decode(uint8_t *opreturn,uint8_t *script,int32_t scriptlen)
{
int32_t datalen,len = 1;
if ( (datalen= script[len++]) >= 76 )
{
if ( datalen == 0x4c )
datalen = script[len++];
else if ( datalen == 0x4d )
{
datalen = script[len++];
datalen = (datalen << 8) | script[len++];
}
}
memcpy(opreturn,&script[len],datalen);
if ( len+datalen == scriptlen )
return(datalen);
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)
{
return(numevents);
@ -38,7 +194,7 @@ void datachain_BTCD_newblock(struct supernet_info *myinfo,struct iguana_info *bt
{
if ( hdrsi < myinfo->dPOW.BTCD.lasthdrsi || (hdrsi == myinfo->dPOW.BTCD.lasthdrsi && unspentind < myinfo->dPOW.BTCD.lastunspentind) )
{
datachain_events_rewind(myinfo,myinfo->dPOW.BTCD.events,myinfo->dPOW.BTCD.numevents,height,hdrsi,unspentind);
myinfo->dPOW.BTCD.numevents = datachain_events_rewind(myinfo,myinfo->dPOW.BTCD.events,myinfo->dPOW.BTCD.numevents,height,hdrsi,unspentind);
}
else
{
@ -53,7 +209,7 @@ void datachain_virt_newblock(struct supernet_info *myinfo,struct iguana_info *vi
{
if ( hdrsi < virt->dPOW.lasthdrsi || (hdrsi == virt->dPOW.lasthdrsi && unspentind < virt->dPOW.lastunspentind) )
{
datachain_events_rewind(myinfo,virt->dPOW.events,virt->dPOW.numevents,height,hdrsi,unspentind);
virt->dPOW.numevents = datachain_events_rewind(myinfo,virt->dPOW.events,virt->dPOW.numevents,height,hdrsi,unspentind);
}
else
{
@ -64,14 +220,14 @@ void datachain_virt_newblock(struct supernet_info *myinfo,struct iguana_info *vi
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 *data,int32_t datalen)
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;
hdrsi = (uint32_t)(hdrsi_unspentind >> 32);
unspentind = (uint32_t)hdrsi_unspentind;
if ( btc_or_btcd == 1 ) // BTC
{
if ( data == 0 )
if ( opreturn == 0 )
datachain_BTC_clock(myinfo,coin,height,hdrsi,unspentind);
else
{
@ -80,7 +236,7 @@ void datachain_opreturn(struct supernet_info *myinfo,struct iguana_info *coin,in
}
else if ( btc_or_btcd == 2 ) // BTCD
{
if ( data == 0 )
if ( opreturn == 0 )
datachain_BTCD_newblock(myinfo,coin,height,hdrsi,unspentind);
else
{
@ -89,18 +245,25 @@ void datachain_opreturn(struct supernet_info *myinfo,struct iguana_info *coin,in
}
else
{
if ( data == 0 )
if ( opreturn == 0 )
datachain_virt_newblock(myinfo,coin,height,hdrsi,unspentind);
else
{
}
}
if ( opreturn != 0 )
{
int32_t i;
for (i=0; i<oplen; i++)
printf("%02x",opreturn[oplen]);
printf(" <- opreturn.%s len.%d\n",coin->symbol,oplen);
}
}
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)
{
uint8_t scriptspace[IGUANA_MAXSCRIPTSIZE]; char fname[1024]; uint32_t datalen=0; int32_t btc_or_btcd=0,len = -1;
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;
if ( strcmp("BTC",coin->symbol) == 0 )
btc_or_btcd = 1;
else if ( strcmp("BTCD",coin->symbol) == 0 )
@ -120,28 +283,27 @@ int32_t iguana_opreturn(struct supernet_info *myinfo,struct iguana_info *coin,st
if ( scriptpos > 0 && scriptlen > 0 )
{
iguana_voutsfname(coin,bp->ramchain.from_ro,fname,fileid);
if ( (len= iguana_scriptdata(coin,scriptspace,coin->voutptrs[fileid],fname,scriptpos,len)) == scriptlen )
{
if ( scriptspace[0] == 0x6a )
{
len = 1;
if ( (datalen= scriptspace[len++]) >= 76 )
{
if ( datalen == 0x4c )
datalen = scriptspace[len++];
else if ( datalen == 0x4d )
{
datalen = scriptspace[len++];
datalen = (datalen << 8) | scriptspace[len++];
}
}
if ( len+datalen == scriptlen )
if ( (len= iguana_scriptdata(coin,scriptspace,coin->voutptrs[fileid],fname,scriptpos,scriptlen)) == scriptlen )
{
datachain_opreturn(myinfo,coin,btc_or_btcd,crypto777_payment,burned,height,hdrsi_unspentind,&scriptspace[len],datalen);
return(datalen);
} else printf("len.%d + datalen.%d != scriptlen.%d\n",len,datalen,scriptlen);
} else printf("not OP_RETURN.%02x scriptlen.%d\n",scriptspace[0],scriptlen);
memset(&V,0,sizeof(V));
type = iguana_vinscriptparse(coin,&V,&sigsize,&pubkeysize,&p2shsize,&suffix,scriptspace,scriptlen);
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);
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)
{
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);
}
return(crypto777_payment);
}

3
datachain/datachain.h

@ -100,5 +100,8 @@ struct delayedPoW_info
struct datachain_info BTC,BTCD;
};
int32_t datachain_datascript(struct iguana_info *coin,uint8_t *script,uint8_t *data,int32_t datalen);
int32_t datachain_opreturnscript(struct iguana_info *coin,uint8_t *script,char *datastr,int32_t datalen);
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);
#endif

71
gecko/gecko.c

@ -339,77 +339,6 @@ struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbo
return(virt);
}
int32_t gecko_rwgenesis(int32_t rwflag,uint8_t *serialized,struct gecko_genesis_opreturn *opret)
{
int32_t len = 0;
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);
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;
memcpy(opret->symbol,&serialized[len],6), len += 6;
memcpy(opret->name,&serialized[len],18), len += 18;
}
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;
memcpy(&serialized[len],opret->symbol,6), len += 6;
memcpy(&serialized[len],opret->name,18), len += 18;
}
return(len);
}
int32_t gecko_opreturn_create(uint8_t *serialized,char *symbol,char *name,char *coinaddr,int64_t PoSvalue,uint32_t nBits,uint16_t blocktime,uint8_t p2shval,uint8_t wifval)
{
uint8_t txidbytes[1024],minerpayment[512]; int32_t i,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));
strncpy(opret.symbol,symbol,sizeof(opret.symbol));
strncpy(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.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++)
{
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;
}
printf("gecko nonce.%d\n",i);
return(gecko_rwgenesis(1,serialized,&opret));
}
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;

7
gecko/gecko.h

@ -37,14 +37,13 @@ struct iguana_peer;
struct gecko_sequence { struct hashstamp *stamps; int32_t lastupdate,maxstamps,numstamps,lasti,longestchain; };
struct gecko_sequences { struct gecko_sequence BTC,BTCD; };*/
//{"genesishash":"633edf349442dea79aa308b286f5368d34f887c898e3c1b4c728679891160000","genesisblock":"010000000000000000000000000000000000000000000000000000000000000000000000413d9e3a8f530415b548973af6545e7a8902d005782478d061295d795f29d68054766a57ffff001f091c070b010100000054766a57011be5d2440c9fb34410947ed9e378478b66d9809f60d17c8d89301ad321ec5912ffffffff050000000000ffffffff0000000000","netmagic":"a1faaa90","symbol":"DEX","name":"InstantDEX","pubval":"00","p2shval":"05","wifval":"80","nBits":"1f00ffff","chain":"InstantDEX","isPoS":1,"geckochain":"InstantDEX","services":128,"blocktime":10,"targetspacing":10,"targettimespan":2450,"result":"success","tag":"10215666446676071864"}
struct gecko_genesis_opreturn
{
char symbol[6],name[16];
char type[3],symbol[6],name[15];
uint64_t PoSvalue;
uint32_t netmagic,timestamp,nBits,nonce;
uint16_t blocktime;
uint16_t blocktime,port;
uint8_t version,pubval,p2shval,wifval,rmd160[20];
};
@ -93,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 gecko_opreturn_create(uint8_t *serialized,char *symbol,char *name,char *coinaddr,int64_t PoSvalue,uint32_t nBits,uint16_t blocktime,uint8_t p2shval,uint8_t wifval);
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);
#endif

17
iguana/exchanges/bitcoin.h

@ -39,23 +39,6 @@
#define SCRIPT_OP_CHECKSEQUENCEVERIFY 0xb2
#define SCRIPT_OP_CHECKLOCKTIMEVERIFY 0xb1
#define IGUANA_SCRIPT_NULL 0
#define IGUANA_SCRIPT_76AC 1
#define IGUANA_SCRIPT_76A988AC 2
#define IGUANA_SCRIPT_P2SH 3
#define IGUANA_SCRIPT_OPRETURN 4
#define IGUANA_SCRIPT_3of3 5
#define IGUANA_SCRIPT_2of3 6
#define IGUANA_SCRIPT_1of3 7
#define IGUANA_SCRIPT_2of2 8
#define IGUANA_SCRIPT_1of2 9
#define IGUANA_SCRIPT_MSIG 10
#define IGUANA_SCRIPT_DATA 11
#define IGUANA_SCRIPT_AC 12
#define IGUANA_SCRIPT_1of1 13
#define IGUANA_SCRIPT_STRANGE 15
#define IGUANA_MAXSCRIPTSIZE 10001
int32_t bitcoin_validaddress(struct iguana_info *coin,char *coinaddr);
int32_t bitcoin_cltvscript(uint8_t p2shtype,char *ps2h_coinaddr,uint8_t p2sh_rmd160[20],uint8_t *script,int32_t n,char *senderaddr,char *otheraddr,uint8_t secret160[20],uint32_t locktime);

2
iguana/iguana_chains.c

@ -292,6 +292,7 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
{
if ( strcmp(chain->symbol,"BTCD") == 0 )
chain->pubtype = 60, chain->p2shtype = 85;
else chain->do_opreturn = juint(argjson,"do_opreturn");
if ( (chain->minoutput= j64bits(argjson,"minoutput")) == 0 )
chain->minoutput = 10000;
chain->minconfirms = juint(argjson,"minconfirms");
@ -312,7 +313,6 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
if ( chain->txfee == 0 )
chain->txfee = (uint64_t)(SATOSHIDEN * jdouble(argjson,"txfee"));
chain->use_addmultisig = juint(argjson,"useaddmultisig");
chain->do_opreturn = juint(argjson,"do_opreturn");
if ( juint(argjson,"p2p") != 0 )
chain->portp2p = juint(argjson,"p2p");
else chain->portp2p = juint(argjson,"portp2p");

5
iguana/iguana_payments.c

@ -369,8 +369,13 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS
spendlen = bitcoin_standardspend(spendscript,0,rmd160);
bitcoin_txoutput(txobj,spendscript,spendlen,change);
if ( opreturn != 0 )
{
int32_t i; for (i=0; i<oplen; i++)
printf("%02x",opreturn[i]);
printf(" <- got opret\n");
bitcoin_txoutput(txobj,opreturn,oplen,burnamount);
}
}
if ( vins != 0 )
V = calloc(cJSON_GetArraySize(vins),sizeof(*V));
rawtx = bitcoin_json2hex(myinfo,coin,&txid,txobj,V);

8
iguana/iguana_ramchain.c

@ -1671,6 +1671,7 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info
if ( iguana_ramchain_addtxid(coin,RAMCHAIN_DESTARG,tx->txid,tx->numvouts,tx->numvins,tx->locktime,tx->version,tx->timestamp,bundlei) == 0 )
return(-2);
}
crypto777_payment = 0;
for (j=0; j<tx->numvouts; j++)
{
if ( coin->active == 0 )
@ -1702,12 +1703,6 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info
//fprintf(stderr,"iter add %p[%d] type.%d\n",scriptdata,scriptlen,type);
if ( (unspentind= iguana_ramchain_addunspent(coin,RAMCHAIN_ARG,value,hdrsi,rmd160,j,type,fileid,(uint32_t)scriptpos,scriptlen,ramchain->H.txidind-rdata->firsti)) == 0 )
return(-3);
if ( memcmp(rmd160,CRYPTO777_RMD160,sizeof(rmd160)) == 0 )
crypto777_payment += value;
else if ( type == IGUANA_SCRIPT_OPRETURN )
{
iguana_opreturn(myinfo,coin,bp,crypto777_payment,bp->bundleheight + bundlei,(((uint64_t)bp->hdrsi << 32) | unspentind),0,fileid,scriptpos,scriptlen);
}
}
}
else
@ -1742,6 +1737,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);
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");

30
iguana/iguana_unspents.c

@ -198,6 +198,34 @@ int32_t iguana_uheight(struct iguana_info *coin,int32_t bundleheight,struct igua
else return(bundleheight);
}
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;
for (i=num=0; i<coin->bundlescount; i++)
{
if ( (bp= coin->bundles[i]) != 0 )
{
ramchain = 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);
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);
}
}
}
}
}
return(num);
}
int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int64_t *spentp,int64_t *unspents,int32_t *nump,struct iguana_ramchain *ramchain,struct iguana_pkhash *p,uint32_t lastunspentind,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t hdrsi,int32_t lastheight,int32_t minconf,int32_t maxconf)
{
struct iguana_unspent *U; struct iguana_utxo *U2; struct iguana_spend *S; int32_t max,uheight,spentheight; uint32_t pkind=0,unspentind; int64_t spent = 0,checkval,deposits = 0; struct iguana_txid *T; struct iguana_account *A2; struct iguana_ramchaindata *rdata = 0; int64_t RTspend = 0;
@ -216,8 +244,6 @@ int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *co
unspentind = lastunspentind;
U = RAMCHAIN_PTR(rdata,Uoffset);
T = RAMCHAIN_PTR(rdata,Toffset);
//U = (void *)(long)((long)rdata + rdata->Uoffset);
//T = (void *)(long)((long)rdata + rdata->Toffset);
RTspend = 0;
if ( lastheight == 0 )
lastheight = IGUANA_MAXHEIGHT;

2
iguana/tests/DEX

@ -1,2 +1,2 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"basilisk\",\"method\":\"genesis_opreturn\",\"vals\":{\"issuer\":\"\",\"stake\":1000000,\"blocktime\":1,\"name\":\"InstantDEX\",\"symbol\":\"DEX\",\"p2sh\":5,\"wif\":128,\"nBits\":\"1effffff\"}}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"basilisk\",\"method\":\"genesis_opreturn\",\"vals\":{\"issuer\":\"RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA\",\"stake\":1000000,\"blocktime\":1,\"name\":\"InstantDEX\",\"symbol\":\"DEX\",\"p2sh\":5,\"wif\":128,\"nBits\":\"1effffff\"}}"

2
iguana/tests/DEXtx

@ -1,2 +1,2 @@
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"sendtoaddress\",\"params\":[\"RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA\", 0.0001, \"00407a10f35a00007ed8874d63a66a57ffffff1e000000000100010005800000000000000000000000000000000000000000444558000000496e7374616e744445580000000000000000\", \"sendcomment\"]}"
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"sendtoaddress\",\"params\":[\"RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA\", 0.0001, \"4e4557444558000000496e7374616e744445580000407a10f35a0000e1526b5aab0b6b57ffffff1e000000000100013c0580f1dce4182fce875748c4986b240ff7d7bc3fffb0\", \"sendcomment\"]}"

2
iguana/tests/decoderawtransaction

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"decoderawtransaction\",\"params\":[\"01000000f7c56a57010252b9534fe0186625e3075606f9b547e223830af04b3fb9dab2aaadc7cad530010000006a4730440220766730766796d2182bf8acd563ba0d594646de179394a657729a133dad9c845702204cb317220cea9d3cdc0ee418ee3b7e3b3387d0850e106e55971f949dc3ebfc730121020e0f6fe6e0fcdcac541eb728d6fe538a12adff20412b3c8a7fa892b223a47c2fffffffff0410270000000000001976a914f1dce4182fce875748c4986b240ff7d7bc3fffb088ac00000000000000004c6a4a00407a10f35a00007ed8874d63a66a57ffffff1e000000000100010005800000000000000000000000000000000000000000444558000000496e7374616e744445580000000000000000e07b9a3b000000001976a914c210f6711e98fe9971757ede2b2dcb0507f3f25e88ac00000000000000004c6a4a00407a10f35a00007ed8874d63a66a57ffffff1e000000000100010005800000000000000000000000000000000000000000444558000000496e7374616e74444558000000000000000000000000\"]}"
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"decoderawtransaction\",\"params\":[\"0100000071d46a5701df62e7985792f07682f565e9496d9358398839f6d7154f531c481d872fb74fcd010000006b483045022100ba971715e5084c71a4239d57af05dc8cf8c9ba478e50949e55accc8345a5388502206da445b50c927ff1b69901c60c97cd01e488c9a865efa5cb724bfc24a05d863d012103377aea6f477582332f128acb197b9f463b5262571d23afaa113dfab48753e3cdffffffff0310270000000000001976a914f1dce4182fce875748c4986b240ff7d7bc3fffb088acc02d9a3b000000001976a914c210f6711e98fe9971757ede2b2dcb0507f3f25e88ac00000000000000004c6a4a00407a10f35a00007ed8874d63a66a57ffffff1e000000000100010005800000000000000000000000000000000000000000444558000000496e7374616e74444558000000000000000000000000\"]}"

2
iguana/tests/gettransaction

@ -1,2 +1,2 @@
curl --url "http://127.0.0.1:7778" --data "{\"method\":\"gettransaction\",\"params\":[\"4b5ba0f755c7bc322e32cdd957546bfa586e828eaeff9181cc72fe3fa0944f51\"]}"
curl --url "http://127.0.0.1:7778" --data "{\"method\":\"gettransaction\",\"coin\":\"BTCD\",\"params\":[\"9825a57222b1f8d2e0072e547865c84d29cd356c0d9078b9cdcd52cf3b320378\"]}"

19
includes/iguana_defines.h

@ -189,5 +189,24 @@ extern int32_t IGUANA_NUMHELPERS;
#define SUPERNET_MAXEXCHANGES 64
#define SUPERNET_APIVERSION 0
#define IGUANA_SCRIPT_NULL 0
#define IGUANA_SCRIPT_76AC 1
#define IGUANA_SCRIPT_76A988AC 2
#define IGUANA_SCRIPT_P2SH 3
#define IGUANA_SCRIPT_OPRETURN 4
#define IGUANA_SCRIPT_3of3 5
#define IGUANA_SCRIPT_2of3 6
#define IGUANA_SCRIPT_1of3 7
#define IGUANA_SCRIPT_2of2 8
#define IGUANA_SCRIPT_1of2 9
#define IGUANA_SCRIPT_MSIG 10
#define IGUANA_SCRIPT_DATA 11
#define IGUANA_SCRIPT_AC 12
#define IGUANA_SCRIPT_1of1 13
#define IGUANA_SCRIPT_STRANGE 15
#define IGUANA_MAXSCRIPTSIZE 10001
#endif

2
includes/iguana_funcs.h

@ -464,6 +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);
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);
bits256 iguana_calcblockhash(char *symbol,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),uint8_t *serialized,int32_t len);

Loading…
Cancel
Save