Browse Source

test

release/v0.1
jl777 8 years ago
parent
commit
bc08f90574
  1. 6
      basilisk/basilisk_bitcoin.c
  2. 10
      basilisk/basilisk_swap.c
  3. 86
      iguana/iguana_unspents.c
  4. 2
      iguana/main.c
  5. 25
      iguana/ramchain_api.c
  6. 1
      iguana/tests/PoS
  7. 1
      includes/iguana_apideclares.h
  8. 1
      includes/iguana_funcs.h

6
basilisk/basilisk_bitcoin.c

@ -343,7 +343,7 @@ char *basilisk_valuestr(struct iguana_info *coin,char *coinaddr,uint64_t value,i
jadd64bits(retjson,"satoshis",value);
jaddnum(retjson,"value",dstr(value));
jaddnum(retjson,"height",height);
jaddnum(retjson,"numconfirms",coin->blocks.hwmchain.height - height);
jaddnum(retjson,"numconfirms",coin->blocks.hwmchain.height - height + 1);
jaddbits256(retjson,"txid",txid);
jaddnum(retjson,"vout",vout);
jaddstr(retjson,"coin",coin->symbol);
@ -497,10 +497,10 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
jadd(valsobj,"addresses",addresses);
}
//printf("use addresses.(%s)\n",jprint(addresses,0));
//printf("vals.(%s) change.(%s) spend.%s\n",jprint(valsobj,0),changeaddr,spendscriptstr);
printf("(%s) vals.(%s) change.(%s) spend.%s\n",coin->symbol,jprint(valsobj,0),changeaddr,spendscriptstr);
if ( changeaddr == 0 || changeaddr[0] == 0 || spendscriptstr == 0 || spendscriptstr[0] == 0 )
return(clonestr("{\"error\":\"invalid changeaddr or spendscript or addresses\"}"));
if ( coin != 0 && basilisk_bitcoinavail(coin) != 0 )
if ( coin != 0 )//&& basilisk_bitcoinavail(coin) != 0 )
{
if ( (txobj= bitcoin_txcreate(coin->chain->isPoS,locktime,locktime==0?coin->chain->normal_txversion:coin->chain->locktime_txversion)) != 0 )
{

10
basilisk/basilisk_swap.c

@ -137,18 +137,18 @@ int32_t basilisk_numconfirms(struct supernet_info *myinfo,struct basilisk_rawtx
for (i=0; i<n; i++)
{
item = jitem(valuearray,i);
height = jint(valuearray,"height");
numconfirms = jint(valuearray,"numconfirms");
height = jint(item,"height");
numconfirms = jint(item,"numconfirms");
printf("i.%d of %d: %s height.%d -> numconfirms.%d\n",i,n,bits256_str(str,rawtx->actualtxid),height,numconfirms);
if ( height > 0 && numconfirms >= 0 )
{
free_json(argjson);
free_json(valuearray);
free(valstr);
printf("%s height.%d -> numconfirms.%d\n",bits256_str(str,rawtx->actualtxid),height,numconfirms);
}
}
}
}
} else printf("valstr not array\n");
} else printf("parse error\n");
}
free_json(argjson);
if ( valuearray != 0 )

86
iguana/iguana_unspents.c

@ -340,9 +340,88 @@ int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *c
return(num);
}
int64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *supplyp,int32_t *numacctsp,int32_t *nonzp,int32_t *errsp,int32_t lastheight)
{
int64_t deposits,RTspend,total,supply,spent,*weights=0; uint32_t lastunspentind,unspentind,pkind; int32_t spentheight,i,neg,nonz,num=0; struct iguana_bundle *bp; struct iguana_ramchain *ramchain; struct iguana_ramchaindata *rdata; struct iguana_pkhash *refP,p; struct iguana_unspent *U; struct iguana_txid *T; uint8_t rmd160[20]; char coinaddr[64]; //struct iguana_account *A2; struct iguana_utxo *U2;
*supplyp = 0;
*numacctsp = *nonzp = 0;
*errsp = 1;
if ( (bp= coin->bundles[lastheight / coin->chain->bundlesize]) == 0 )
return(0);
if ( (rdata= bp->ramchain.H.data) == 0 )
return(0);
refP = RAMCHAIN_PTR(rdata,Poffset);
if ( (num= rdata->numpkinds) > 0 )
{
weights = calloc(num,sizeof(*weights));
for (pkind=1; pkind<num; pkind++)
{
total = 0;
memcpy(rmd160,refP[pkind].rmd160,sizeof(rmd160));
bitcoin_address(coinaddr,coin->chain->pubtype,rmd160,sizeof(rmd160));
//printf("PKIND.%d %s\n",pkind,coinaddr);
for (i=bp->hdrsi; i>=0; i--)
{
if ( (bp= coin->bundles[i]) != 0 )
{
ramchain = 0;
if ( iguana_pkhashfind(coin,&ramchain,&deposits,&lastunspentind,&p,rmd160,i,i) != 0 && (rdata= ramchain->H.data) != 0 )
{
spent = 0;
deposits = 0;
unspentind = lastunspentind;
U = RAMCHAIN_PTR(rdata,Uoffset);
T = RAMCHAIN_PTR(rdata,Toffset);
while ( unspentind > 0 )
{
if ( iguana_spentflag(myinfo,coin,&RTspend,&spentheight,ramchain,i,unspentind,lastheight,0,1<<31,U[unspentind].value) == 0 )
deposits += U[unspentind].value;
else spent += U[unspentind].value;
unspentind = U[unspentind].prevunspentind;
}
weights[pkind] += (deposits - spent);
/*if ( (A2= ramchain->A2) != 0 && p.pkind > 0 && p.pkind < rdata->numpkinds && (U2= ramchain->Uextras) != 0 )
{
T = RAMCHAIN_PTR(rdata,Toffset);
U = RAMCHAIN_PTR(rdata,Uoffset);
unspentind = A2[p.pkind].lastunspentind;
while ( unspentind > 0 )
{
uheight = iguana_uheight(coin,ramchain->height,T,rdata->numtxids,&U[unspentind]);
if ( uheight < lastheight )
spent += U[unspentind].value;
unspentind = U2[unspentind].prevunspentind;
}
weights[pkind] -= spent;
} else printf("PoS.[%d] rdata.%p or A2.%p error [%d] pkind.%d\n",pkind,rdata,A2,i,p.pkind);*/
if ( weights[pkind] != 0 )
printf("wt %.8f P.%d -> [%d] pkind.%d deposits %.8f spent %.8f\n",dstr(weights[pkind]),pkind,i,p.pkind,dstr(deposits),dstr(spent));
}
}
}
}
}
nonz = neg = 0;
supply = 0;
for (pkind=1; pkind<num; pkind++)
if ( weights[pkind] != 0 )
{
nonz++;
if ( weights[pkind] < 0 )
neg++, weights[pkind] = 0;
else supply += weights[pkind];
}
*numacctsp = num;
*errsp = neg;
*nonzp = nonz;
*supplyp = supply;
printf("ht.%d [%d] numaddrs.%d nonz.%d neg.%d supply %.8f\n",lastheight,lastheight/coin->chain->bundlesize,num,nonz,neg,dstr(supply));
return(weights);
}
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,char *remoteaddr)
{
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;
struct iguana_unspent *U; struct iguana_utxo *U2; 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; //struct iguana_spend *S;
max = *nump;
*spentp = *nump = 0;
if ( 0 && coin->RTramchain_busy != 0 )
@ -392,8 +471,7 @@ int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *co
}
if ( lastheight > 0 && (A2= ramchain->A2) != 0 && (U2= ramchain->Uextras) != 0 )
{
S = RAMCHAIN_PTR(rdata,Soffset);
//S = (void *)(long)((long)rdata + rdata->Soffset);
//S = RAMCHAIN_PTR(rdata,Soffset);
unspentind = A2[pkind].lastunspentind;
checkval = 0;
while ( unspentind > 0 )
@ -601,7 +679,7 @@ int32_t iguana_unspentslists(struct supernet_info *myinfo,struct iguana_info *co
}
else
{
if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 )
if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 && waddr->numunspents > 0 )
{
r = (rand() % waddr->numunspents);
for (j=0; j<waddr->numunspents; j++)

2
iguana/main.c

@ -501,7 +501,7 @@ void iguana_appletests(struct supernet_info *myinfo)
bitcoin_sharedsecret(myinfo->ctx,hash2,pubkey,33);
printf("secp256k1 elapsed %.3f for %d iterations\n",OS_milliseconds() - startmillis,i);
getchar();**/
if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"protover\":70002,\"RELAY\":0,\"VALIDATE\":0,\"portp2p\":14631,\"rpc\":14632,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":64,\"endpend\":64,\"services\":129,\"maxpeers\":8,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":1,\"poll\":1}"),0,myinfo->rpcport)) != 0 )
if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"protover\":70002,\"RELAY\":1,\"VALIDATE\":0,\"portp2p\":14631,\"rpc\":14632,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":64,\"endpend\":64,\"services\":129,\"maxpeers\":8,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":1,\"poll\":1}"),0,myinfo->rpcport)) != 0 )
{
free(str);
if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"portp2p\":8333,\"RELAY\":0,\"VALIDATE\":0,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":1,\"endpend\":1,\"services\":128,\"maxpeers\":8,\"newcoin\":\"BTC\",\"active\":0,\"numhelpers\":1,\"poll\":100}"),0,myinfo->rpcport)) != 0 )

25
iguana/ramchain_api.c

@ -184,6 +184,31 @@ STRING_AND_INT(iguana,bundleaddresses,activecoin,height)
else return(clonestr("{\"error\":\"activecoin is not active\"}"));
}
STRING_AND_INT(iguana,PoSweights,activecoin,height)
{
struct iguana_info *ptr; int32_t num,nonz,errs,bundleheight; int64_t *weights,supply; cJSON *retjson;
if ( (ptr= iguana_coinfind(activecoin)) != 0 )
{
for (bundleheight=coin->chain->bundlesize; bundleheight<height; bundleheight+=coin->chain->bundlesize)
{
//bundleheight = (height / coin->chain->bundlesize) * coin->chain->bundlesize;
if ( (weights= iguana_PoS_weights(myinfo,ptr,&supply,&num,&nonz,&errs,bundleheight)) != 0 )
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",errs == 0 ? "success" : "error");
jaddnum(retjson,"bundleheight",bundleheight);
jaddnum(retjson,"numaddresses",num);
jaddnum(retjson,"nonzero",nonz);
jaddnum(retjson,"errors",errs);
jaddnum(retjson,"supply",dstr(supply));
free(weights);
//return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"iguana_PoS_weights returned null\"}"));
}
}
return(clonestr("{\"error\":\"activecoin is not active\"}"));
}
STRING_AND_INT(iguana,bundlehashes,activecoin,height)
{
struct iguana_info *ptr; struct iguana_bundle *bp; int32_t i,hdrsi; cJSON *retjson,*array; struct iguana_ramchaindata *rdata;

1
iguana/tests/PoS

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"PoSweights\",\"activecoin\":\"BTCD\",\"height\":1200000}"

1
includes/iguana_apideclares.h

@ -141,6 +141,7 @@ TWO_STRINGS_AND_TWO_DOUBLES(iguana,balance,activecoin,address,heightd,minconfd);
P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount,destaddress2,destamount2,M,N,pubA,wifA,pubB,wifB,pubC,wifC);
STRING_AND_INT(iguana,bundleaddresses,activecoin,height);
STRING_AND_INT(iguana,bundlehashes,activecoin,height);
STRING_AND_INT(iguana,PoSweights,activecoin,height);
//TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,minaccept,base,rel,minprice,basevolume);
//TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,maxaccept,base,rel,maxprice,basevolume);

1
includes/iguana_funcs.h

@ -542,6 +542,7 @@ void iguana_RTspendvectors(struct supernet_info *myinfo,struct iguana_info *coin
double instantdex_avehbla(struct supernet_info *myinfo,double retvals[4],char *base,char *rel,double basevolume);
int32_t bitcoin_revealsecret160(uint8_t *script,int32_t n,uint8_t secret160[20]);
int64_t iguana_lockval(int32_t finalized,int64_t locktime);
int64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *supplyp,int32_t *numacctsp,int32_t *nonzp,int32_t *errsp,int32_t lastheight);
// ------------------------------------------------------[ Preparation ]----
// Initialise a gfshare context for producing shares

Loading…
Cancel
Save